Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1856 lines
68 KiB

  1. <%@ CODEPAGE=65001 'UTF-8%>
  2. <%' certrqma.asp - (CERT)srv web - (R)e(Q)uest, (M)ore (A)dvanced
  3. ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <!-- #include FILE=certsbrt.inc -->
  5. <!-- #include FILE=certdat.inc -->
  6. <%
  7. On Error Resume Next
  8. ' Exporting keys to a pvk file is only used by old code signing tools.
  9. ' (This is different from exporting both cert and keys in a pfx file.)
  10. ' Set this flag to true if you really need this functionality
  11. bEnableExportKeyToFile = True
  12. Const CR_OUT_BASE64 =&H00000001
  13. Const CR_PROP_CAEXCHGCERT=15
  14. Const PROPTYPE_BINARY=3
  15. ' get CA exchange cert and save into this page
  16. Dim bFailed, nError
  17. Set ICertRequest2=Server.CreateObject("CertificateAuthority.Request")
  18. bFailed=False
  19. If "IE"=sBrowser Then
  20. Public sCAExchangeCert
  21. Dim sCertificate
  22. sCertificate=ICertRequest2.GetCAProperty(sServerConfig, CR_PROP_CAEXCHGCERT, 0, PROPTYPE_BINARY, CR_OUT_BASE64)
  23. sCAExchangeCert=FormatBigString(sCertificate, " sCAExchange=sCAExchange & ")
  24. End If
  25. If Err.Number<>0 Then
  26. ' CA may be down.
  27. bFailed=True
  28. nError=Err.Number
  29. End If
  30. '-----------------------------------------------------------------
  31. ' Format the big string as a concatenated VB string, breaking at the embedded newlines
  32. Function FormatBigString(sSource, sLinePrefix)
  33. Dim sResult, bCharsLeft, nStartChar, nStopChar, chQuote
  34. sResult=""
  35. chQuote=chr(34)
  36. bCharsLeft=True
  37. nStopChar=1
  38. While (bCharsLeft)
  39. nStartChar=nStopChar
  40. nStopChar=InStr(nStopChar, sSource, vbNewLine)
  41. If (nStopChar>0) Then
  42. sResult=sResult & sLinePrefix & chQuote & Mid(sSource, nStartChar, nStopChar-nStartChar) & chQuote & " & vbNewLine"
  43. If (nStopChar>=Len(sSource)-Len(vbNewLine)) Then
  44. bCharsLeft=False
  45. End If
  46. Else
  47. bCharsLeft=False
  48. End if
  49. sResult=sResult & vbNewLine
  50. nStopChar=nStopChar+Len(vbNewLine)
  51. Wend
  52. FormatBigString=sResult
  53. End Function
  54. %>
  55. <HTML>
  56. <Head>
  57. <Meta HTTP-Equiv="Content-Type" Content="text/html; charset=UTF-8">
  58. <Title>Microsoft Certificate Services</Title>
  59. </Head>
  60. <%If True=bFailed Then %>
  61. <Body BgColor=#FFFFFF Link=#0000FF VLink=#0000FF ALink=#0000FF><Font ID=locPageFont Face="Arial">
  62. <%Else%>
  63. <Body BgColor=#FFFFFF Link=#0000FF VLink=#0000FF ALink=#0000FF OnLoad="postLoad();"><Font ID=locPageFont Face="Arial">
  64. <%End If%>
  65. <Table Border=0 CellSpacing=0 CellPadding=4 Width=100% BgColor=#008080>
  66. <TR>
  67. <TD><Font Color=#FFFFFF><LocID ID=locMSCertSrv><Font Face="Arial" Size=-1><B><I>Microsoft</I></B> Certificate Services &nbsp;--&nbsp; <%=sServerDisplayName%> &nbsp;</Font></LocID></Font></TD>
  68. <TD ID=locHomeAlign Align=Right><A Href="/certsrv"><Font Color=#FFFFFF><LocID ID=locHomeLink><Font Face="Arial" Size=-1><B>Home</B></Font></LocID></Font></A></TD>
  69. </TR>
  70. </Table>
  71. <%If True=bFailed Then %>
  72. <P ID=locPageTitle1><Font Color=#FF0000><B>Error</B></Font>
  73. <!-- Green HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#008080><Img Src="certspc.gif" Alt="" Height=2 Width=1></TD></TR></Table>
  74. <P ID=locErrorMsg> An unexpected error has occurred:
  75. <%If nError=&H800706BA Or nError=&H80070005 Then%>
  76. <LocID ID=locSvcNotStarted>The Certification Authority Service has not been started.</LocID>
  77. <%Else%>
  78. <%=ICertRequest.GetErrorMessageText(nError, CR_GEMT_HRESULT_STRING)%>
  79. <%End If%>
  80. <%Else 'True<>bFailed%>
  81. <Form Name=UIForm OnSubmit="goNext();return false;" Action="certlynx.asp" Method=Post>
  82. <Input Type=Hidden Name=SourcePage Value="certrqma">
  83. <P ID=locPageTitle> <B> Advanced Certificate Request </B>
  84. <!-- Green HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#008080><Img Src="certspc.gif" Alt="" Height=2 Width=></TD></TR></Table>
  85. <Span ID=spnFixTxt Style="display:none">
  86. <Table Border=0 CellSpacing=0 CellPadding=4 Style="Color:#FF0000"><TR><TD ID=locBadCharError>
  87. <I>Please correct the fields marked in <B>RED</B>.</I>
  88. The e-mail address may contain the characters A-Z, a-z, 0-9, and some common symbols, but no extended characters.
  89. The country/region field must be a two letter ISO 3166 country/region code.
  90. </TD></TR></Table>
  91. </Span>
  92. <Span ID=spnErrorTxt Style="display:none">
  93. <Table Border=0 CellSpacing=0 CellPadding=4 Style="Color:#FF0000">
  94. <TR><TD ID=locErrMsgBasic>
  95. <B>An error occurred</B> while creating the certificate request.
  96. Please verify that your CSP supports any settings you have made
  97. and that your input is valid.
  98. </TD></TR><TR><TD>
  99. <LocID ID=locErrorCause><B>Suggested cause:</B></LocID><BR>
  100. <Span ID=spnErrorMsg></Span>
  101. </TD></TR><TR>
  102. <TD ID=locErrorNumber><Font Size=-2>Error: <Span ID=spnErrorNum></Span></Font></TD>
  103. </TR>
  104. </Table>
  105. </Span>
  106. <Table Border=0 CellSpacing=0 CellPadding=0>
  107. <TR> <!-- establish column widths. -->
  108. <TD Width=<%=L_LabelColWidth_Number%>></TD> <!-- label column, top border -->
  109. <TD RowSpan=59 Width=4></TD> <!-- label spacing column -->
  110. <TD></TD> <!-- field column -->
  111. </TR>
  112. <%If "Enterprise"=sServerType Then%> <!-- Enterprise Options -->
  113. <TR>
  114. <TD ID=locTemplateHead ColSpan=3><Font Size=-1><BR><B>Certificate Template:</B></Font></TD>
  115. </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  116. </TR><TR><TD ColSpan=3 Height=6></TD>
  117. </TR><TR><TD></TD>
  118. <TD><Select Name=lbCertTemplate OnChange="handleTemplateChange();">
  119. <%
  120. Dim nWriteTemplateResult
  121. nWriteTemplateResult=WriteTemplateList()
  122. %>
  123. </Select></TD>
  124. </TR>
  125. <%End If '"Enterprise"=sServerType%>
  126. <TR><TD ColSpan=3>
  127. <%If "Enterprise"=sServerType Then%> <!-- Enterprise Options -->
  128. <Span ID=spnIDInfo Style="display:none">
  129. <%End If '"Enterprise"=sServerType%>
  130. <Table Border=0 CellSpacing=0 CellPadding=0>
  131. <TR> <!-- establish column widths. -->
  132. <TD Width=<%=L_LabelColWidth_Number%>></TD> <!-- label column, top border -->
  133. <TD RowSpan=59 Width=4></TD> <!-- label spacing column -->
  134. <TD></TD> <!-- field column -->
  135. </TR>
  136. <TR>
  137. <%If "StandAlone"=sServerType Then%>
  138. <TD ID=locIdentHeadStandAlone ColSpan=3><Font Size=-1><BR><B>Identifying Information:</B></Font></TD>
  139. </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  140. <%Else%>
  141. <TD ID=locIdentHeadEnterprise ColSpan=3><Font Size=-1><BR><B>Identifying Information For Offline Template:</B></Font></TD>
  142. </TR><!--<TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>-->
  143. <%End If%>
  144. </TR><TR><TD ColSpan=3 Height=6></TD>
  145. </TR><TR>
  146. <TD ID=locNameAlign Align=Right><Span ID=spnNameLabel><LocID ID=locNameLabel><Font Size=-1>Name:</Font></LocID></Span></TD>
  147. <TD><Input ID=locTbCommonName Type=Text MaxLength=64 Size=42 Name=tbCommonName></TD>
  148. </TR><TR>
  149. <TD ID=locEmailAlign Align=Right><Span ID=spnEmailLabel><LocID ID=locEmailLabel><Font Size=-1>E-Mail:</Font></LocID></Span></TD>
  150. <TD><Input ID=locTbEmail Type=Text MaxLength=128 Size=42 Name=tbEmail></TD>
  151. </TR><TR>
  152. <TD Height=8></TD> <TD></TD>
  153. </TR><TR>
  154. <TD ID=locCompanyAlign Align=Right><Span ID=spnCompanyLabel><LocID ID=locOrgLabel><Font Size=-1>Company:</Font></LocID></Span></TD>
  155. <TD><Input ID=locTbOrg Type=Text MaxLength=64 Size=42 Name=tbOrg Value="<%=sDefaultCompany%>"></TD>
  156. </TR><TR>
  157. <TD ID=locDepartmentAlign Align=Right><Span ID=spnDepartmentLabel><LocID ID=locOrgUnitLabel><Font Size=-1>Department:</Font></LocID></Span></TD>
  158. <TD><Input ID=locTbOrgUnit Type=Text MaxLength=64 Size=42 Name=tbOrgUnit Value="<%=sDefaultOrgUnit%>"></TD>
  159. </TR><TR>
  160. <TD Height=8></TD> <TD></TD>
  161. </TR><TR>
  162. <TD ID=locCityAlign Align=Right><Span ID=spnCityLabel><LocID ID=locLocalityLabel><Font Size=-1>City:</Font></LocID></Span></TD>
  163. <TD><Input ID=locTbLocality Type=Text MaxLength=128 Size=42 Name=tbLocality Value="<%=sDefaultLocality%>"></TD>
  164. </TR><TR>
  165. <TD ID=locStateAlign Align=Right><Span ID=spnStateLabel><LocID ID=locStateLabel><Font Size=-1>State:</Font></LocID></Span></TD>
  166. <TD><Input ID=locTbState Type=Text MaxLength=128 Size=42 Name=tbState Value="<%=sDefaultState%>"></TD>
  167. </TR><TR>
  168. <TD ID=locCountryAlign Align=Right><Span ID=spnCountryLabel><LocID ID=locCountryLabel><Font Size=-1>Country/Region:</Font></LocID></Span></TD>
  169. <TD><Input ID=locTbCountry Type=Text MaxLength=2 Size=2 Name=tbCountry Value="<%=sDefaultCountry%>"></TD>
  170. </TR>
  171. </Table>
  172. <%If "Enterprise"=sServerType Then%>
  173. </Span>
  174. <%End If '"Enterprise"=sServerType%>
  175. </TD></TR>
  176. <%If "StandAlone"=sServerType Then%> <!-- Stand-Alone Options -->
  177. <TR>
  178. <TD ID=locEKUHead ColSpan=3><Font Size=-1><BR><B>Type of Certificate Needed:</B></Font></TD>
  179. </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  180. </TR><TR><TD ColSpan=3 Height=6></TD>
  181. </TR><TR><TD></TD>
  182. <TD><Select Name=lbUsageOID OnChange="handleUsageOID(true);">
  183. <Option ID=locCliAuthCert Selected Value="1.3.6.1.5.5.7.3.2"> Client Authentication Certificate
  184. <Option ID=locEmailCert Value="1.3.6.1.5.5.7.3.4"> E-Mail Protection Certificate
  185. <Option ID=locSrvAuthCert Value="1.3.6.1.5.5.7.3.1"> Server Authentication Certificate
  186. <Option ID=locCodeSgnCert Value="1.3.6.1.5.5.7.3.3"> Code Signing Certificate
  187. <Option ID=locTimStmpCert Value="1.3.6.1.5.5.7.3.8"> Time Stamp Signing Certificate
  188. <Option ID=locIPSecCert Value="1.3.6.1.5.5.8.2.2"> IPSec Certificate
  189. <Option ID=locUserEKUCert Value="**"> Other...
  190. </Select></TD>
  191. </TR>
  192. <TR><TD ID=locEkuAlign Align=Right><Span ID=spnEKUOther1 Style="display:none"><LocID ID=locUserEKULabel><Font Size=-1>OID:</Font></LocID></Span></TD>
  193. <TD><Span ID=spnEKUOther2 Style="display:none"><Input ID=locTbEKUOther Type=Text Name=tbEKUOther Value="1.3.6.1.5.5.7.3."></Span></TD>
  194. </TR>
  195. <%End If%> <!-- common -->
  196. <TR>
  197. <TD ID=locKeyOptHead ColSpan=3><Font Size=-1><BR><B>Key Options:</B></Font></TD>
  198. </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  199. </TR><TR><TD ColSpan=3 Height=6></TD>
  200. </TR>
  201. <TR>
  202. <TD></TD>
  203. <TD><Font Size=-1>
  204. <Input Type=Radio ID=rbKG1 Name=rbKeyGen Value="0" OnClick="handleKeyGen();" Checked><Label For=rbKG1 ID=locNewKeyLabel>Create new key set</Label>
  205. <LocID ID=locSpc3>&nbsp;&nbsp;&nbsp;<LocID>
  206. <Input Type=Radio ID=rbKG2 Name=rbKeyGen Value="1" OnClick="handleKeyGen();"><Label For=rbKG2 ID=locExistKeyLabel>Use existing key set</Label>
  207. </Font></TD>
  208. </TR>
  209. <TR><TD ColSpan=3 Height=4></TD></TR>
  210. <TR>
  211. <TD ID=locCSPLabel Align=Right><Font Size=-1>CSP:</Font></TD>
  212. <TD><Select Name=lbCSP OnChange="handleCSPChange();">
  213. <Option ID=locLoading>Loading...</Option>
  214. </Select></TD>
  215. </TR>
  216. <TR ID=trBadCSPForKeySpec Style="display:none">
  217. <TD></TD>
  218. <TD BgColor=#FFFFE0><LocID ID=locBadCSPForKeySpec><Font Size=-1><Span ID=spnBadCSPForKeySpecMsg></Span></Font></LocID></TD>
  219. </TR>
  220. <TR><TD ColSpan=3 Height=4></TD></TR>
  221. <TR>
  222. <TD ID=locKeyUsageLabel Align=Right><Font Size=-1>Key Usage:</Font></TD>
  223. <TD><Font Size=-1>
  224. <Span ID=spnKeyUsageKeyExchange><Input Type=Radio ID=rbKU1 Name=rbKeyUsage Value="0" Checked OnClick="handleKeyUsageChange(false);"><Label For=rbKU1 ID=locKUExch>Exchange</Label><LocID ID=locSpc1>&nbsp;&nbsp;&nbsp;<LocID></Span>
  225. <Span ID=spnKeyUsageSignature><Input Type=Radio ID=rbKU2 Name=rbKeyUsage Value="1" OnClick="handleKeyUsageChange(false);"><Label For=rbKU2 ID=locKUSig>Signature</Label><LocID ID=locSpc2>&nbsp;&nbsp;&nbsp;<LocID></Span>
  226. <Span ID=spnKeyUsageBoth><Input Type=Radio ID=rbKU3 Name=rbKeyUsage Value="2" OnClick="handleKeyUsageChange(false);"><Label For=rbKU3 ID=locKUBoth>Both</Label></Span></Font></TD>
  227. </TR>
  228. <TR><TD ColSpan=3 Height=4></TD></TR>
  229. <TR>
  230. <TD ID=locKeySizeLabel Align=Right ><Font Size=-1>Key Size:</Font></TD>
  231. <TD><Table Border=0 CellPadding=0 CellSpacing=0>
  232. <TR>
  233. <TD RowSpan=2><Input ID=locTbKeySize Type=Text Name=tbKeySize Value="0" MaxLength=5 Size=4 OnPropertyChange="handleKeySizeChange();">&nbsp;</TD>
  234. <TD ID=locKeySizeMinLabel Align=Right><Font Size=-2>Min:</Font></TD>
  235. <TD ID=locKeySizeMin Align=Right><Font Size=-2><Span ID=spnKeySizeMin></Span></Font></TD>
  236. <TD ID=locKeySizeCommon RowSpan=2><Font Size=-2>&nbsp;&nbsp;(common key sizes: <Span ID=spnKeySizeCommon></Span>)</Font></TD>
  237. </TR><TR>
  238. <TD ID=locKeySizeMaxLabel Align=Right><Font Size=-2>Max:</Font></TD>
  239. <TD ID=locKeySizeMax Align=Right><Font Size=-2><Span ID=spnKeySizeMax></Span></Font></TD>
  240. </TR>
  241. </Table></TD>
  242. </TR>
  243. <TR ID=trKeySizeBad Style="display:none">
  244. <TD></TD>
  245. <TD BgColor=#FFFFE0><LocID ID=locKeySizeBad><Font Size=-1><Span ID=spnKeySizeBadMsg></Span></Font></LocID></TD>
  246. </TR>
  247. <TR ID=trKeySizeBadSpc Style="display:none"><TD ColSpan=3 Height=4></TD></TR>
  248. <TR ID=trKeySizeWarn Style="display:none">
  249. <TD></TD>
  250. <TD BgColor=#FFFFE0><LocID ID=locKeySizeWarning><Font Size=-1><I>Warning: Large keys can take many hours to generate!</I></Font></LocID></TD>
  251. </TR>
  252. <TR ID=trKeyGenWarn Style="display:none">
  253. <TD></TD>
  254. <TD><LocID ID=locKeyGenWarning><Font Size=-1><I>A key of this size will be generated
  255. </I>only<I> if a key for the <BR> specified usage does not already exist in the specified
  256. container.</I></Font></LocID></TD>
  257. </TR>
  258. <TR ID=trGenContNameSpc><TD ColSpan=3 Height=4></TD></TR>
  259. <TR ID=trGenContName>
  260. <TD></TD>
  261. <TD><Font Size=-1>
  262. <Input Type=Radio ID=rbGCN1 Name=rbGenContName Value="0" OnClick="handleGenContName();" Checked><Label For=rbGCN1 ID=locAutoContNameLabel>Automatic key container name</Label>
  263. <LocID ID=locSpc4>&nbsp;&nbsp;&nbsp;<LocID>
  264. <Input Type=Radio ID=rbGCN2 Name=rbGenContName Value="1" OnClick="handleGenContName();"><Label For=rbGCN2 ID=locUserContNameLabel>User specified key container name</Label>
  265. </Font></TD>
  266. </TR>
  267. <TR ID=trContNameSpc><TD ColSpan=3 Height=4></TD></TR>
  268. <TR ID=trContName Style="display:none">
  269. <TD ID=locContainerNameLabel Align=Right><Font Size=-1>Container Name:</Font></TD>
  270. <TD><Font Size=-1><Input ID=locTbContainerName Type=Text Name=tbContainerName Size=20></Font></TD>
  271. </TR>
  272. <TR ID=trMarkExportSpc><TD ColSpan=3 Height=4></TD></TR>
  273. <TR ID=trMarkExport><TD></TD>
  274. <TD><Font Size=-1><Input Type=Checkbox Name=cbMarkKeyExportable ID=cbMarkKeyExportable OnClick="handleMarkExport();"><Label For=cbMarkKeyExportable ID=locMarkExportLabel>Mark keys as exportable</Label>
  275. <%If bEnableExportKeyToFile Then%>
  276. <Span ID=spnMarkKeyExportable Style="display:none">
  277. <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><Input Type=Checkbox Name=cbExportKeys ID=cbExportKeys OnClick="handleExportKeys();"><Label For=cbExportKeys ID=locExportToFileLabel>Export keys to file</Label>
  278. <Span ID=spnExportKeys Style="display:none">
  279. <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locExpFileNameLabel>Full path name:</LocID> <Input ID=locTbExportKeyFile Type=Text Name=tbExportKeyFile Size=20 Value="*.pvk">
  280. </Span>
  281. </Span>
  282. <%End If%>
  283. </Font></TD>
  284. </TR>
  285. <TR ID=trStrongKeySpc><TD ColSpan=3 Height=4></TD></TR>
  286. <TR ID=trStrongKey>
  287. <TD></TD>
  288. <TD><Font Size=-1><Input Type=Checkbox ID=cbStrongKey Name=cbStrongKey OnClick="handleStrongKeyAndLMStore();"><Label For=cbStrongKey ID=locStrongKeyLabel>Enable strong private key protection</Label></Font></TD>
  289. </TR>
  290. <TR ID=trLMStoreSpc><TD ColSpan=3 Height=4></TD></TR>
  291. <TR ID=trLMStore><TD></TD>
  292. <TD><Font Size=-1><Input Type=Checkbox Name=cbLocalMachineStore ID=cbLocalMachineStore OnClick="handleStrongKeyAndLMStore();"><Label For=cbLocalMachineStore ID=locLMStoreLabel>Use local machine store</Label><BR>
  293. <LocID ID=locAdminWarning><Img Src="certspc.gif" Alt="" Height=1 Width=25><I>You must be an administrator to generate or use<BR>
  294. <Img Src="certspc.gif" Alt="" Height=1 Width=25> a key in the local machine store.</I></Font></LocID></TD>
  295. </TR>
  296. <TR>
  297. <TD ID=locAddOptHead ColSpan=3><Font Size=-1><BR><B>Additional Options:</B></Font></TD>
  298. </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  299. </TR><TR><TD ColSpan=3 Height=3></TD>
  300. </TR>
  301. <TR><TD ColSpan=3 Height=6></TD></TR>
  302. <TR>
  303. <TD ID=locRequestFormatLabel Align=Right><Font Size=-1>Request Format:</Font></TD>
  304. <TD>
  305. <Input Type=Radio ID=rbFormatCMC Name=rbRequestFormat Value="0" Checked><Label For=rbFormatCMC ID=locFormatCMCLabel>CMC</Label>
  306. <LocID ID=locSpc5>&nbsp;&nbsp;&nbsp;<LocID>
  307. <Input Type=Radio ID=rbFormatPKCS10 Name=rbRequestFormat Value="1"><Label For=rbFormatPKCS10 ID=locFormatPKCS10Label>PKCS10</Label>
  308. </TD>
  309. </TR>
  310. <TR><TD ColSpan=3 Height=4></TD></TR>
  311. <TR><TD ColSpan=3 Height=4></TD></TR>
  312. <TR>
  313. <TD ID=locHashAlgLabel Align=Right><Font Size=-1>Hash Algorithm:</Font></TD>
  314. <TD><Select Name=lbHashAlgorithm></Select></TD>
  315. </TR>
  316. <TR><TD></TD><TD ID=locHashAlgWarning><Font Size=-1><I>Only used to sign request.</I></Font></TD></TR>
  317. <TR><TD ColSpan=3 Height=8></TD></TR>
  318. <TR><TD></TD>
  319. <TD><Font Size=-1><Input Type=Checkbox Name=cbSaveRequest ID=cbSaveRequest OnClick="handleSaveReq();"><Label For=cbSaveRequest ID=locSaveReqLabel>Save request to a file</Label>
  320. <Span ID=spnSaveRequest Style="display:none">
  321. <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locReqFileNameLabel>Full path name:</LocID> <Input ID=locTbSaveReqFile Type=Text Name=tbSaveReqFile Size=20>
  322. <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locSaveReqWarning><B>This request will be saved and not submitted.</B></LocID>
  323. </Span>
  324. </Font></TD>
  325. </TR>
  326. <TR><TD ColSpan=3 Height=6></TD>
  327. </TR><TR>
  328. <TD ID=locAttribLabel Align=Right><Font Size=-1><Span ID=spnSubmitAttrLable>Attributes:</Span></Font></TD>
  329. <TD><Span ID=spnSubmitAttrBox><TextArea ID=locTaAttrib Name=taAttrib Wrap=Off Rows=2 Cols=30></TextArea></SPan></TD>
  330. </TR>
  331. <TR><TD ColSpan=3 Height=6></TD>
  332. </TR><TR>
  333. <TD ID=locFriendlyNameLabel Align=Right><Font Size=-1>Friendly Name:</Font></TD>
  334. <TD><Font Size=-1><Input ID=locTbFriendlyName Type=Text Name=tbFriendlyName Size=20></Font></TD>
  335. </TR>
  336. <TR><TD ColSpan=3><Font Size=-1><BR></Font></TD></TR>
  337. <TR><TD ColSpan=3 Height=2 BgColor=#008080></TD></TR>
  338. <TR><TD ColSpan=3 Height=3></TD></TR>
  339. <TR>
  340. <TD></TD>
  341. <TD ID=locSubmitAlign Align=Right>
  342. <Input ID=locBtnSubmit Type=Submit Name=btnSubmit Value="Submit &gt;" Style="width:.75in">
  343. <Input ID=locBtnSave Type=Submit Name=btnSave Value="Save" Style="width:.75in; display:none">
  344. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  345. </TD>
  346. </TR>
  347. <TR><TD ColSpan=3 Height=20></TD></TR>
  348. </Table>
  349. </P>
  350. <!-- Green HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#008080><Img Src="certspc.gif" Alt="" Height=2 Width=1></TD></TR></Table>
  351. <!-- White HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#FFFFFF><Img Src="certspc.gif" Alt="" Height=5 Width=1></TD></TR></Table>
  352. </Form>
  353. </Font>
  354. <!-- ############################################################ -->
  355. <!-- End of standard text. Scripts follow -->
  356. <%bIncludeXEnroll=True%>
  357. <%bIncludeGetCspList=True%>
  358. <%bIncludeTemplateCode=True%>
  359. <%bIncludeCheckClientCode=True%>
  360. <!-- #include FILE=certsgcl.inc -->
  361. <!-- This form we fill in and submit 'by hand'-->
  362. <Span Style="display:none">
  363. <Form Name=SubmittedData Action="certfnsh.asp" Method=Post>
  364. <Input Type=Hidden Name=Mode> <!-- used in request ('newreq'|'chkpnd') -->
  365. <Input Type=Hidden Name=CertRequest> <!-- used in request -->
  366. <Input Type=Hidden Name=CertAttrib> <!-- used in request -->
  367. <Input Type=Hidden Name=FriendlyType> <!-- used on pending -->
  368. <Input Type=Hidden Name=ThumbPrint> <!-- used on pending -->
  369. <Input Type=Hidden Name=TargetStoreFlags> <!-- used on install ('0'|CSSLM)-->
  370. <Input Type=Hidden Name=SaveCert> <!-- used on install ('no'|'yes')-->
  371. </FORM>
  372. </Span>
  373. <Script Language="JavaScript">
  374. //================================================================
  375. // PAGE GLOBAL VARIABLES
  376. //----------------------------------------------------------------
  377. // Strings to be localized
  378. var L_CspLoadErrNoneFound_ErrorMessage="An unexpected error occurred while getting the CSP list:\nNo CSPs could be found!";
  379. var L_CspLoadErrUnexpected_ErrorMessage="\"An unexpected error (\"+sErrorNumber+\") occurred while getting the CSP list.\"";
  380. var L_SetKeySize_Message="\"Set key size to \"+nKeySize";
  381. var L_WarningTemplateKeySize_Message="\"You may have selected a certificate type that requires a minimum key size of \" + nKeySize + \" which is larger than the current maximum.\\nPlease select a different CSP or key usage.\"";
  382. var L_RecommendOneKeySize_Message="\"\"+nKeySize+\" is a bad key size. The closest valid key size is \"+sCloseBelow+\".\"";
  383. var L_RecommendTwoKeySizes_Message="\"\"+nKeySize+\" is a bad key size. The closest valid key sizes are \"+sCloseBelow+\" and \"+sCloseAbove+\".\"";
  384. var L_StillLoading_ErrorMessage="This page has not finished loading yet. Please wait a few seconds and try again.";
  385. var L_KeySizeNotNumber_ErrorMessage="Please enter a number for the key size.";
  386. var L_KeySizeBadNumber_ErrorMessage="\"Please enter a valid number for the key size. The key size must be\\nbetween \"+g_nCurKeySizeMin+\" and \"+g_nCurKeySizeMax+\", and be a multiple of \"+g_nCurKeySizeInc+\".\"";
  387. var L_CSPNotSupportTemplateKeySpec_Message="\"You may have selected a CSP that does not support the certificate key type. Please select either different CSP or certificate template.\"";
  388. var L_TemplateKeySizeTooBig_ErrorMessage = "\"The certificate type you selected requires minimum key size of \" + g_nCurTemplateKeySizeMin + \".\\nIt is bigger than the maximum size of \" + g_nCurKeySizeMax + \".\\nPlease change the number or select a different CSP.\"";
  389. var L_NoCntnrName_ErrorMessage="Please enter a key container name.";
  390. var L_BadOid_ErrorMessage="Please enter a valid OID, or choose a predefined certificate type.\nMultiple OIDs must be separated with a comma.";
  391. var L_NoExportFileName_ErrorMessage="Please enter a file name for exporting the keys.";
  392. var L_NoSaveReqFileName_ErrorMessage="Please enter a file name for saving the request.";
  393. var L_Generating_Message="Generating request...";
  394. var L_UserEKUCert_Text="\"User-EKU (\"+sCertUsage+\") Certificate\"";
  395. var L_RequestSaved_Message="Request saved to file.";
  396. var L_Waiting_Message="Waiting for server response...";
  397. var L_ErrNameUnknown_ErrorMessage="(unknown)";
  398. var L_SugCauseNone_ErrorMessage="No suggestion.";
  399. var L_SugCauseBadCSP_ErrorMessage="The CSP you chose was unable to process the request. Try a different CSP.";
  400. var L_SugCauseBadSetting2_ErrorMessage="The CSP you chose does not support one or more of the settings you have made, such as key size, key spec, hash algorithm, etc. Try using different settings or a different CSP.";
  401. var L_SugCauseBadKeyContainer_ErrorMessage="Either the key container you specified does not exist, or the CSP you chose was unable to process the request. Enter the name of an existing key container; choose 'Create new keyset'; or try a different CSP.";
  402. var L_SugCauseExistKeyContainer_ErrorMessage="The container you named already exists. When creating a new key, you must use a new container name.";
  403. var L_SugCauseBadChar_ErrorMessage="You entered an invalid character. Report a bug, because this should have been caught in validation.";
  404. var L_SugCauseBadHash_ErrorMessage="The hash algorithm you selected cannot be used for signing. Please select a different hash algorithm.";
  405. var L_SugCauseNoFileName_ErrorMessage="You did not enter a file name.";
  406. var L_ErrNameNoFileName_ErrorMessage="(no file name)";
  407. var L_SugCauseNotAdmin_ErrorMessage="You must be an administrator to generate a key in the local machine store.";
  408. var L_ErrNamePermissionDenied_ErrorMessage="Permission Denied";
  409. var L_SugCausePermissionToWrite_ErrorMessage = "You do not have write permission to save the file to the path";
  410. var L_SugCauseBadFileName_ErrorMessage="The file name you specified is not a valid file name. Try a different file name.";
  411. var L_SugCauseBadDrive_ErrorMessage="The drive you specified is not ready. Insert a disk in the drive or try a different file name.";
  412. var L_DownLevelClients_ErrorMessage="This error can be caused by requesting Key Archival for the new private key, which may not be supported on this platform.";
  413. var L_SCARD_E_NO_MEMORY_MSG="Not enough memory available to complete this command.";
  414. var L_SCARD_F_WAITED_TOO_LONG="An internal consistency timer has expired.";
  415. var L_SCARD_E_INSUFFICIENT_BUFFER="The data buffer to receive returned data is too small for the returned data.";
  416. var L_SCARD_E_UNKNOWN_READER="The specified reader name is not recognized.";
  417. var L_SCARD_E_NO_SMARTCARD="The operation requires a Smart Card, but no Smart Card is currently in the device.";
  418. var L_SCARD_E_UNKNOWN_CARD="The specified smart card name is not recognized.";
  419. var L_SCARD_E_NOT_READY="The reader or smart card is not ready to accept commands.";
  420. var L_SCARD_F_COMM_ERROR="An internal communications error has been detected.";
  421. var L_SCARD_E_NO_SERVICE="The Smart card resource manager is not running.";
  422. var L_SCARD_E_SERVICE_STOPPED="The Smart card resource manager has shut down.";
  423. var L_SCARD_E_NO_READERS_AVAILABLE="Cannot find a smart card reader.";
  424. var L_SCARD_E_COMM_DATA_LOST="A communications error with the smart card has been detected. Retry the operation.";
  425. var L_SCARD_E_NO_KEY_CONTAINER="The requested key container does not exist on the smart card.";
  426. var L_SCARD_W_UNPOWERED_CARD="Power has been removed from the smart card, so that further communication is not possible.";
  427. var L_SCARD_W_REMOVED_CARD="The smart card has been removed, so that further communication is not possible.";
  428. var L_SCARD_W_WRONG_CHV="The card cannot be accessed because the wrong PIN was presented.";
  429. var L_SCARD_W_CHV_BLOCKED="The card cannot be accessed because the maximum number of PIN entry attempts has been reached.";
  430. var L_SCARD_W_EOF="The end of the smart card file has been reached.";
  431. var L_SCARD_W_CANCELLED_BY_USER="The action was cancelled by the user.";
  432. var L_SCARD_W_CARD_NOT_AUTHENTICATED="No PIN was presented to the smart card.";
  433. <%If "Enterprise"=sServerType Then%>
  434. ;
  435. var L_TemplateLoadErrNoneFound_ErrorMessage="No certificate templates could be found. You do not have permission to request a certificate from this CA, or an error occurred while accessing the Active Directory.";
  436. var L_TemplateLoadErrUnexpected_ErrorMessage="\"An unexpected error (\"+sErrorNumber+\") occurred while getting the certificate template list.\"";
  437. var L_TemplateCert_Text="sRealName+\" Certificate\"";
  438. <%End If%>
  439. // IE is not ready until XEnroll has been loaded
  440. var g_bOkToSubmit=false;
  441. var g_bSubmitPending=false;
  442. // some constants defined in wincrypt.h:
  443. var CRYPT_EXPORTABLE=1;
  444. var CRYPT_USER_PROTECTED=2;
  445. var CRYPT_MACHINE_KEYSET=0x20;
  446. var AT_KEYEXCHANGE=1;
  447. var AT_SIGNATURE=2;
  448. var CERT_SYSTEM_STORE_LOCATION_SHIFT=16;
  449. var CERT_SYSTEM_STORE_LOCAL_MACHINE_ID=2;
  450. var CERT_SYSTEM_STORE_LOCAL_MACHINE=CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT;
  451. var ALG_CLASS_ANY=0
  452. var ALG_CLASS_SIGNATURE=1<<13;
  453. var ALG_CLASS_HASH=4<<13;
  454. var PROV_DSS=3;
  455. var PROV_DSS_DH=13;
  456. var PROV_DH_SCHANNEL=18;
  457. // convenience constants, for readability
  458. var KEY_USAGE_EXCH=0;
  459. var KEY_USAGE_SIG=1;
  460. var KEY_USAGE_BOTH=2;
  461. var XEKL_KEYSIZE_MIN=1;
  462. var XEKL_KEYSIZE_MAX=2;
  463. var XEKL_KEYSIZE_INC=3;
  464. var XEKL_KEYSIZE_DEFAULT=4;
  465. var XEKL_KEYSPEC_KEYX=1;
  466. var XEKL_KEYSPEC_SIG=2;
  467. // defaults
  468. var KEY_LEN_MIN_DEFAULT=384;
  469. var KEY_LEN_MAX_DEFAULT=16384;
  470. var KEY_LEN_MY_DEFAULT=1024;
  471. var KEY_LEN_INC_DEFAULT=8;
  472. // for key size
  473. var g_nCurKeySizeMax;
  474. var g_nCurKeySizeMin;
  475. var g_nCurKeySizeDefault;
  476. var g_nCurKeySizeInc;
  477. var g_bCSPUpdate;
  478. var g_nCurTemplateKeySizeMin = 0; //init to 0
  479. var XECR_PKCS10_V2_0=1;
  480. var XECR_PKCS7=2;
  481. var XECR_CMC=3;
  482. var XECT_EXTENSION_V1=1;
  483. var XECT_EXTENSION_V2=2;
  484. //================================================================
  485. // INITIALIZATION ROUTINES
  486. function removeV2KATemplate()
  487. {
  488. var CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL=0x00000001;
  489. //downlevel machines, no V2 templates with KA
  490. var nTemplateCount = document.UIForm.lbCertTemplate.length;
  491. var n, sTemplate, sCTEOID;
  492. for (n = nTemplateCount - 1; n > -1 ; --n)
  493. {
  494. sTemplate = document.UIForm.lbCertTemplate.options[n].value;
  495. sCTEOID = getTemplateStringInfo(CTINFO_INDEX_EXTOID, sTemplate);
  496. var lFlags=getTemplateValueInfo(CTINFO_INDEX_PRIVATEKEYFLAG, sTemplate);
  497. if ("" != sCTEOID && 0x0 != (lFlags & CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL))
  498. {
  499. //v2 template with KA
  500. document.UIForm.lbCertTemplate.options.remove(n);
  501. }
  502. }
  503. }
  504. //----------------------------------------------------------------
  505. // This contains the functions we want executed immediately after load completes
  506. function postLoad() {
  507. // Load an XEnroll object into the page
  508. loadXEnroll("postLoadPhase2()");
  509. handleSaveReq();
  510. handleCMCFormat();
  511. <%If "Enterprise"=sServerType Then%>
  512. if (!isClientAbleToCreateCMC())
  513. {
  514. //downlevel machines
  515. removeV2KATemplate();
  516. }
  517. <%End If%>
  518. }
  519. function postLoadPhase2() {
  520. // continued from above
  521. var nResult;
  522. // get the CSP list
  523. nResult=GetCSPList();
  524. if (0!=nResult) {
  525. handleLoadError(nResult, L_CspLoadErrNoneFound_ErrorMessage, L_CspLoadErrUnexpected_ErrorMessage);
  526. return;
  527. }
  528. <%If "StandAlone"<>sServerType And 0<>nWriteTemplateResult Then%>
  529. handleLoadError(<%=nWriteTemplateResult%>, L_TemplateLoadErrNoneFound_ErrorMessage, L_TemplateLoadErrUnexpected_ErrorMessage);
  530. return;
  531. <%End If%>
  532. // Now we're ready to go
  533. g_bOkToSubmit=true;
  534. <%If "Enterprise"=sServerType Then%>
  535. handleTemplateChange();
  536. <%Else%>
  537. handleCSPChange();
  538. <%End If%>
  539. // dynamic styles are not preserved so
  540. // make sure dynamic UI is updated after 'back'
  541. handleKeyGen();
  542. handleMarkExport();
  543. handleExportKeys();
  544. <%If "StandAlone"=sServerType Then%>
  545. handleUsageOID(false);
  546. <%End If%>
  547. }
  548. //----------------------------------------------------------------
  549. // handle errors from GetCSPList() and GetTemplateList()
  550. function handleLoadError(nResult, sNoneFound, sUnexpected) {
  551. if (-1==nResult) {
  552. alert(sNoneFound);
  553. } else {
  554. var sErrorNumber="0x"+toHex(nResult);
  555. alert(eval(sUnexpected));
  556. }
  557. disableAllControls();
  558. }
  559. //================================================================
  560. // PAGE MANAGEMENT ROUTINES
  561. <%If "StandAlone"=sServerType Then%>
  562. //----------------------------------------------------------------
  563. // handle the appearance of the text box when 'other...' is selected
  564. function handleUsageOID(bFocus) {
  565. if ("**"==document.UIForm.lbUsageOID.options[document.UIForm.lbUsageOID.selectedIndex].value) {
  566. spnEKUOther1.style.display='';
  567. spnEKUOther2.style.display='';
  568. if (bFocus) {
  569. document.UIForm.lbUsageOID.blur();
  570. document.UIForm.tbEKUOther.select();
  571. document.UIForm.tbEKUOther.focus();
  572. }
  573. } else {
  574. spnEKUOther1.style.display='none';
  575. spnEKUOther2.style.display='none';
  576. }
  577. }
  578. <%End If%>
  579. <%If "Enterprise"=sServerType Then%>
  580. //----------------------------------------------------------------
  581. function getTemplateValueInfo(nIndex, sTemplate)
  582. {
  583. var sValue=getTemplateStringInfo(nIndex, sTemplate);
  584. return parseInt(sValue);
  585. }
  586. // handle a change in the current template
  587. function isDNNeeded() {
  588. var sValue=getTemplateStringInfo(CTINFO_INDEX_OFFLINE, null);
  589. if ("O"==sValue)
  590. {
  591. //offline template needs DN
  592. return true;
  593. }
  594. //check template subject flag
  595. var lSubjectFlag = getTemplateValueInfo(CTINFO_INDEX_SUBJECTFLAG, null);
  596. var CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT=0x00000001;
  597. return (0x0 != (lSubjectFlag & CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT));
  598. }
  599. function isTemplateKeyArchival()
  600. {
  601. var CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL=0x00000001;
  602. var lFlags=getTemplateValueInfo(CTINFO_INDEX_PRIVATEKEYFLAG, null);
  603. return (0x0 != (lFlags & CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL));
  604. }
  605. function isSMimeCapabilities()
  606. {
  607. var CT_FLAG_INCLUDE_SYMMETRIC_ALGORITHMS=0x00000001;
  608. var lFlags=getTemplateValueInfo(CTINFO_INDEX_ENROLLFLAG, null);
  609. return (0x0 != (lFlags & CT_FLAG_INCLUDE_SYMMETRIC_ALGORITHMS));
  610. }
  611. function getTemplateMinKeySize()
  612. {
  613. var lKeyFlags = getTemplateValueInfo(CTINFO_INDEX_KEYFLAG, null);
  614. return (lKeyFlags & 0xFFFF0000) >> 16;
  615. }
  616. function updateCSPList()
  617. {
  618. //get csp list separated from template data
  619. var sCSPList = getTemplateStringInfo(CTINFO_INDEX_CSPLIST, null);
  620. if ("" != sCSPList)
  621. {
  622. updateCSPListFromStrings(sCSPList);
  623. }
  624. else
  625. {
  626. //remove current csps from list
  627. //strange reasons this remove code can't be in GetCSPList
  628. var n;
  629. var nCSP = document.UIForm.lbCSP.length;
  630. for (n = 0; n < nCSP-1; ++n)
  631. {
  632. document.UIForm.lbCSP.remove(0);
  633. }
  634. GetCSPList();
  635. }
  636. }
  637. //----------------------------------------------------------------
  638. // handle a change in the current template
  639. function handleTemplateChange()
  640. {
  641. if (false==isDNNeeded()) {
  642. spnIDInfo.style.display="none";
  643. } else {
  644. spnIDInfo.style.display="";
  645. }
  646. //update csp list from the template
  647. updateCSPList();
  648. handleCSPChange();
  649. //handle key spec
  650. var lKeySpec = getTemplateValueInfo(CTINFO_INDEX_KEYSPEC, null);
  651. var fDisabled = true;
  652. if ((0x0 != (AT_KEYEXCHANGE & lKeySpec)) &&
  653. (0x0 != (AT_SIGNATURE & lKeySpec)) )
  654. {
  655. document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  656. }
  657. else if (0x0 != (AT_KEYEXCHANGE & lKeySpec))
  658. {
  659. document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked=true;
  660. }
  661. else if (0x0 != (AT_SIGNATURE & lKeySpec))
  662. {
  663. document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked=true;
  664. }
  665. else
  666. {
  667. document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  668. fDisabled = false;
  669. }
  670. document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].disabled=fDisabled;
  671. document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].disabled=fDisabled;
  672. document.UIForm.rbKeyUsage[KEY_USAGE_SIG].disabled=fDisabled;
  673. //update exportable control
  674. var lPrivateKeyFlags = getTemplateValueInfo(CTINFO_INDEX_PRIVATEKEYFLAG, null);
  675. var CT_FLAG_EXPORTABLE_KEY = 0x10;
  676. document.UIForm.cbMarkKeyExportable.checked = (0x0 != (lPrivateKeyFlags & CT_FLAG_EXPORTABLE_KEY));
  677. handleMarkExport();
  678. //update template min key size
  679. g_nCurTemplateKeySizeMin = getTemplateMinKeySize();
  680. //update key size
  681. handleKeyUsageChange(false);
  682. //update CMC related
  683. handleCMCFormat();
  684. var lRASignatures = getTemplateValueInfo(CTINFO_INDEX_RASIGNATURE, null);
  685. var fSave = 0 < lRASignatures;
  686. //enforce save to file, can't submit if signing
  687. document.UIForm.cbSaveRequest.checked = fSave;
  688. document.UIForm.cbSaveRequest.disabled = fSave;
  689. handleSaveReq();
  690. }
  691. <%End If%>
  692. //----------------------------------------------------------------
  693. // handle a change in the current CSP
  694. function handleCSPChange() {
  695. if (0 == document.UIForm.lbCSP.length)
  696. {
  697. //no csp, disable submit button
  698. document.UIForm.btnSubmit.disabled = true;
  699. return;
  700. }
  701. else
  702. {
  703. document.UIForm.btnSubmit.disabled = false;
  704. }
  705. var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  706. XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  707. var nProvType=document.UIForm.lbCSP.options[nCSPIndex].value;
  708. XEnroll.ProviderType=nProvType;
  709. <%If "Enterprise"=sServerType Then%>
  710. var nTemplateKeySpec = getTemplateValueInfo(CTINFO_INDEX_KEYSPEC, null);
  711. <%End If%>
  712. // update the key spec options. If we support both, default to key exchange
  713. var nSupportedKeyUsages=XEnroll.GetSupportedKeySpec();
  714. if (0==nSupportedKeyUsages) {
  715. nSupportedKeyUsages=AT_SIGNATURE | AT_KEYEXCHANGE;
  716. }
  717. if (PROV_DSS==nProvType || PROV_DSS_DH==nProvType || PROV_DH_SCHANNEL==nProvType) {
  718. nSupportedKeyUsages=AT_SIGNATURE;
  719. }
  720. <%If "Enterprise"=sServerType Then%>
  721. if (0==nTemplateKeySpec) {
  722. nTemplateKeySpec=AT_SIGNATURE | AT_KEYEXCHANGE;
  723. }
  724. nSupportedKeyUsages = nTemplateKeySpec & nSupportedKeyUsages;
  725. <%End If%>
  726. if (0 == nSupportedKeyUsages)
  727. {
  728. spnBadCSPForKeySpecMsg.innerHTML=eval(L_CSPNotSupportTemplateKeySpec_Message);
  729. trBadCSPForKeySpec.style.display="";
  730. } else {
  731. trBadCSPForKeySpec.style.display="none";
  732. }
  733. if (nSupportedKeyUsages&AT_SIGNATURE) {
  734. spnKeyUsageSignature.style.display="";
  735. document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked=true;
  736. } else {
  737. spnKeyUsageSignature.style.display="none";
  738. }
  739. if (nSupportedKeyUsages&AT_KEYEXCHANGE) {
  740. spnKeyUsageKeyExchange.style.display="";
  741. document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked=true;
  742. } else {
  743. spnKeyUsageKeyExchange.style.display="none";
  744. }
  745. if ((AT_SIGNATURE|AT_KEYEXCHANGE)==nSupportedKeyUsages) {
  746. spnKeyUsageBoth.style.display="";
  747. document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  748. } else {
  749. spnKeyUsageBoth.style.display="none";
  750. }
  751. handleKeyUsageChange(true);
  752. UpdateHashAlgList(nProvType);
  753. }
  754. //----------------------------------------------------------------
  755. // two cases invoke handleKeyUsageChange:
  756. // 1) csp selection change
  757. // 2) exchange vs. signature change
  758. function handleKeyUsageChange(bCSPChange) {
  759. // get the min, max, and default length from the CSP
  760. var bExchange=document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked || document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked ;
  761. g_nCurKeySizeMax=MyGetKeyLen(XEKL_KEYSIZE_MAX, bExchange);
  762. g_nCurKeySizeMin=MyGetKeyLen(XEKL_KEYSIZE_MIN, bExchange);
  763. <%If "Enterprise"=sServerType Then%>
  764. if (0 != g_nCurTemplateKeySizeMin)
  765. {
  766. g_nCurKeySizeMin=Math.max(g_nCurKeySizeMin, g_nCurTemplateKeySizeMin);
  767. }
  768. <%End If%>
  769. g_nCurKeySizeDefault=MyGetKeyLen(XEKL_KEYSIZE_DEFAULT, bExchange);
  770. g_nCurKeySizeInc=MyGetKeyLen(XEKL_KEYSIZE_INC, bExchange);
  771. // set to default lenth
  772. if ("0"==document.UIForm.tbKeySize.value || true == bCSPChange)
  773. {
  774. //"0" likely init load or typed in, not bad go default
  775. // or csp changed, set to default length
  776. document.UIForm.tbKeySize.value = g_nCurKeySizeDefault;
  777. }
  778. // show the min and max
  779. spnKeySizeMin.innerText=g_nCurKeySizeMin;
  780. spnKeySizeMax.innerText=g_nCurKeySizeMax;
  781. // keep the key size in bounds
  782. var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  783. if (isNaN(nKeySize) || nKeySize>g_nCurKeySizeMax) {
  784. document.UIForm.tbKeySize.value=g_nCurKeySizeMax;
  785. } else if (nKeySize<g_nCurKeySizeMin) { //>
  786. document.UIForm.tbKeySize.value=g_nCurKeySizeMin;
  787. }
  788. // update list of valid common key sizes
  789. var nPowerSize=128;
  790. var sCommonKeys="";
  791. while (nPowerSize<g_nCurKeySizeMin) { //>
  792. nPowerSize*=2;
  793. }
  794. while (nPowerSize<=g_nCurKeySizeMax) {
  795. sCommonKeys+=getKeySizeLinkHtmlString(nPowerSize)+" ";
  796. nPowerSize*=2;
  797. }
  798. spnKeySizeCommon.innerHTML=sCommonKeys;
  799. handleKeySizeChange();
  800. }
  801. //----------------------------------------------------------------
  802. function getKeySizeLinkHtmlString(nKeySize) {
  803. return "<Span tabindex=0 Style=\"cursor:hand; color:#0000FF; text-decoration:underline;\""
  804. +" OnContextMenu=\"return false;\""
  805. +" OnMouseOver=\"window.status='"+eval(L_SetKeySize_Message)+"';return true;\""
  806. +" OnMouseOut=\"window.status='';return true;\""
  807. +" OnMouseUp=\"window.status='"+eval(L_SetKeySize_Message)+"';return true;\""
  808. +" OnKeyDown=\"if (13==event.keyCode) {document.UIForm.tbKeySize.value='"+nKeySize+"';blur();return false;} else if (9==event.keyCode) {return true;};return false;\""
  809. +" OnClick=\"document.UIForm.tbKeySize.value='"+nKeySize+"';blur();return false;\">"
  810. +nKeySize+"</Span>";
  811. }
  812. //----------------------------------------------------------------
  813. // morphing routine
  814. function handleSaveReq() {
  815. if (document.UIForm.cbSaveRequest.checked) {
  816. spnSaveRequest.style.display='';
  817. document.UIForm.btnSubmit.style.display='none';
  818. document.UIForm.btnSave.style.display='';
  819. spnSubmitAttrLable.style.display='none';
  820. spnSubmitAttrBox.style.display='none';
  821. } else {
  822. spnSaveRequest.style.display='none';
  823. document.UIForm.btnSubmit.style.display='';
  824. document.UIForm.btnSave.style.display='none';
  825. spnSubmitAttrLable.style.display='';
  826. spnSubmitAttrBox.style.display='';
  827. }
  828. }
  829. //----------------------------------------------------------------
  830. // morphing routine
  831. function handleMarkExport() {
  832. <%If bEnableExportKeyToFile Then%>
  833. if (document.UIForm.cbMarkKeyExportable.checked) {
  834. spnMarkKeyExportable.style.display='';
  835. } else {
  836. spnMarkKeyExportable.style.display='none';
  837. }
  838. <%End If%>
  839. }
  840. //----------------------------------------------------------------
  841. // morphing routine
  842. function handleExportKeys() {
  843. <%If bEnableExportKeyToFile Then%>
  844. if (document.UIForm.cbExportKeys.checked) {
  845. spnExportKeys.style.display='';
  846. } else {
  847. spnExportKeys.style.display='none';
  848. }
  849. <%End If%>
  850. }
  851. //----------------------------------------------------------------
  852. // morphing routine
  853. function handleKeyGen() {
  854. if (document.UIForm.rbKeyGen[0].checked) {
  855. // create new keyset
  856. trGenContName.style.display='';
  857. trGenContNameSpc.style.display='';
  858. trKeyGenWarn.style.display='none';
  859. handleGenContName();
  860. handleStrongKeyAndLMStore();
  861. trMarkExport.style.display='';
  862. trMarkExportSpc.style.display='';
  863. } else {
  864. // Use existing key set
  865. trGenContName.style.display='none';
  866. trGenContNameSpc.style.display='none';
  867. trKeyGenWarn.style.display='';
  868. handleGenContName();
  869. handleStrongKeyAndLMStore();
  870. document.UIForm.cbMarkKeyExportable.checked=false;
  871. trMarkExport.style.display='none';
  872. trMarkExportSpc.style.display='none';
  873. }
  874. }
  875. //----------------------------------------------------------------
  876. // morphing routine
  877. function handleGenContName() {
  878. if (document.UIForm.rbGenContName[0].checked && document.UIForm.rbKeyGen[0].checked) {
  879. trContName.style.display='none';
  880. trContNameSpc.style.display='none';
  881. } else {
  882. trContName.style.display='';
  883. trContNameSpc.style.display='';
  884. }
  885. }
  886. //----------------------------------------------------------------
  887. // morphing routine
  888. function handleSetContainer() {
  889. if (document.UIForm.cbSetContainer.checked) {
  890. spnNewContainer.style.display='';
  891. } else {
  892. spnNewContainer.style.display='none';
  893. }
  894. }
  895. //----------------------------------------------------------------
  896. // morphing routine
  897. function handleKeySizeChange() {
  898. var sKeySize = document.UIForm.tbKeySize.value;
  899. if (0 == sKeySize.indexOf("0"))
  900. {
  901. //first digit is 0, wipe it out
  902. document.UIForm.tbKeySize.value = "";
  903. return;
  904. }
  905. var nKeySize=parseInt(sKeySize);
  906. if (isNaN(nKeySize)) {
  907. nKeySize=0;
  908. }
  909. if (nKeySize>2048) {
  910. trKeySizeWarn.style.display='';
  911. } else {
  912. trKeySizeWarn.style.display='none';
  913. }
  914. if (nKeySize<g_nCurKeySizeMin || nKeySize>g_nCurKeySizeMax || 0!=nKeySize%g_nCurKeySizeInc) {
  915. // clamp the current key size to be within the range
  916. var nCloseBelow=nKeySize;
  917. if (nCloseBelow<g_nCurKeySizeMin) { //>
  918. nCloseBelow=g_nCurKeySizeMin;
  919. } else if (nCloseBelow>g_nCurKeySizeMax) {
  920. nCloseBelow=g_nCurKeySizeMax;
  921. }
  922. var nCloseAbove=nCloseBelow;
  923. // find closest values above and below
  924. nCloseBelow-=nCloseBelow%g_nCurKeySizeInc;
  925. nCloseAbove+=(g_nCurKeySizeInc-nCloseAbove%g_nCurKeySizeInc)%g_nCurKeySizeInc;
  926. var sCloseAbove=getKeySizeLinkHtmlString(nCloseAbove);
  927. var sCloseBelow=getKeySizeLinkHtmlString(nCloseBelow);
  928. if (g_nCurKeySizeMax < g_nCurTemplateKeySizeMin) {
  929. spnKeySizeBadMsg.innerHTML=eval(L_WarningTemplateKeySize_Message);
  930. } else if (nCloseAbove==nCloseBelow) {
  931. spnKeySizeBadMsg.innerHTML=eval(L_RecommendOneKeySize_Message);
  932. } else {
  933. spnKeySizeBadMsg.innerHTML=eval(L_RecommendTwoKeySizes_Message);
  934. }
  935. trKeySizeBad.style.display="";
  936. trKeySizeBadSpc.style.display="";
  937. } else {
  938. trKeySizeBad.style.display="none";
  939. trKeySizeBadSpc.style.display="none";
  940. }
  941. }
  942. //----------------------------------------------------------------
  943. // morphing routine
  944. function handleStrongKeyAndLMStore() {
  945. if (document.UIForm.cbStrongKey.checked && document.UIForm.rbKeyGen[0].checked) {
  946. trLMStoreSpc.style.display='none';
  947. trLMStore.style.display='none';
  948. document.UIForm.cbLocalMachineStore.checked=false;
  949. } else {
  950. trLMStoreSpc.style.display='';
  951. trLMStore.style.display='';
  952. }
  953. if (document.UIForm.cbLocalMachineStore.checked || !document.UIForm.rbKeyGen[0].checked) {
  954. trStrongKeySpc.style.display='none';
  955. trStrongKey.style.display='none';
  956. document.UIForm.cbStrongKey.checked=false;
  957. } else {
  958. trStrongKeySpc.style.display='';
  959. trStrongKey.style.display='';
  960. }
  961. }
  962. //----------------------------------------------------------------
  963. // handle CMC Format
  964. function handleCMCFormat() {
  965. if (isClientAbleToCreateCMC())
  966. {
  967. <%If "Enterprise"=sServerType Then%>
  968. //change request format controls
  969. if (isTemplateKeyArchival())
  970. {
  971. //enforce CMC
  972. document.UIForm.rbRequestFormat[0].disabled=true;
  973. document.UIForm.rbRequestFormat[0].checked=true;
  974. document.UIForm.rbRequestFormat[1].disabled=true;
  975. }
  976. else
  977. {
  978. document.UIForm.rbRequestFormat[0].disabled=false;
  979. document.UIForm.rbRequestFormat[1].disabled=false;
  980. }
  981. <%End If%>
  982. }
  983. else
  984. {
  985. //no cmc, disable it, only pkcs10
  986. document.UIForm.rbRequestFormat[0].disabled=true;
  987. document.UIForm.rbRequestFormat[1].disabled=true;
  988. document.UIForm.rbRequestFormat[1].checked=true;
  989. }
  990. }
  991. //================================================================
  992. // SUBMIT ROUTINES
  993. //----------------------------------------------------------------
  994. // determine what to do when the submit button is pressed
  995. function goNext() {
  996. if (false==g_bOkToSubmit) {
  997. alert(L_StillLoading_ErrorMessage);
  998. } else if (true==g_bSubmitPending) {
  999. // ignore, because we are already prcessing a request.
  1000. } else {
  1001. SubmitRequest();
  1002. }
  1003. }
  1004. //----------------------------------------------------------------
  1005. // check for invalid characters and empty strings
  1006. function isValidIA5String(sSource) {
  1007. var nIndex;
  1008. for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  1009. if (sSource.charCodeAt(nIndex)>127) { // NOTE: this is better, but not compatible with old browsers.
  1010. return false;
  1011. }
  1012. };
  1013. return true;
  1014. }
  1015. //----------------------------------------------------------------
  1016. // check for invalid characters
  1017. function isValidCountryField(tbCountry) {
  1018. tbCountry.value=tbCountry.value.toUpperCase();
  1019. var sSource=tbCountry.value;
  1020. var nIndex, ch;
  1021. if (0!=sSource.length && 2!=sSource.length) {
  1022. return false;
  1023. }
  1024. for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  1025. ch=sSource.charAt(nIndex)
  1026. if (ch<"A" || ch>"Z") {
  1027. return false;
  1028. }
  1029. };
  1030. return true;
  1031. }
  1032. //----------------------------------------------------------------
  1033. // check for invalid characters in an OID
  1034. function isValidOid(sSource) {
  1035. var nIndex, ch;
  1036. if (0==sSource.length) {
  1037. return true;
  1038. }
  1039. for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  1040. ch=sSource.charAt(nIndex)
  1041. if (ch!="." && ch!="," && (ch<"0" || ch>"9")) {
  1042. return false;
  1043. }
  1044. }
  1045. return true;
  1046. }
  1047. //----------------------------------------------------------------
  1048. // set a label to normal style
  1049. function markLabelNormal(spn) {
  1050. spn.style.color="#000000";
  1051. spn.style.fontWeight='normal';
  1052. }
  1053. //----------------------------------------------------------------
  1054. // set a label to error state
  1055. function markLabelError(spn) {
  1056. spn.style.color='#FF0000';
  1057. spn.style.fontWeight='bold';
  1058. }
  1059. //----------------------------------------------------------------
  1060. // check that the form has data in it
  1061. function validateRequest() {
  1062. markLabelNormal(spnNameLabel);
  1063. markLabelNormal(spnEmailLabel);
  1064. markLabelNormal(spnCompanyLabel);
  1065. markLabelNormal(spnDepartmentLabel);
  1066. markLabelNormal(spnCityLabel);
  1067. markLabelNormal(spnStateLabel);
  1068. markLabelNormal(spnCountryLabel);
  1069. var bOK=true;
  1070. <%If "Enterprise"=sServerType Then%>
  1071. if (true==isDNNeeded()) {
  1072. <%End If%>
  1073. var fldFocusMe=null;
  1074. if (false==isValidCountryField(document.UIForm.tbCountry)) {
  1075. bOK=false;
  1076. fldFocusMe=document.UIForm.tbCountry;
  1077. markLabelError(spnCountryLabel);
  1078. }
  1079. // document.UIForm.tbState.value OK
  1080. // document.UIForm.tbLocality.value OK
  1081. // document.UIForm.tbOrgUnit.value OK
  1082. // document.UIForm.tbOrg.value OK
  1083. if (false==isValidIA5String(document.UIForm.tbEmail.value)) {
  1084. bOK=false;
  1085. fldFocusMe=document.UIForm.tbEmail;
  1086. markLabelError(spnEmailLabel);
  1087. }
  1088. // document.UIForm.tbCommonName.value OK
  1089. if (false==bOK) {
  1090. spnFixTxt.style.display='';
  1091. window.scrollTo(0,0);
  1092. fldFocusMe.focus();
  1093. }
  1094. <%If "Enterprise"=sServerType Then%>
  1095. } // <- End if offline template
  1096. <%End If%>
  1097. <%If "StandAlone"=sServerType Then%>
  1098. // Check the OID field
  1099. if (true==bOK) {
  1100. if ("**"==document.UIForm.lbUsageOID.options[document.UIForm.lbUsageOID.selectedIndex].value
  1101. && false==isValidOid(document.UIForm.tbEKUOther.value)) {
  1102. alert(L_BadOid_ErrorMessage);
  1103. document.UIForm.tbEKUOther.focus();
  1104. bOK=false;
  1105. }
  1106. }
  1107. <%End If%>
  1108. // Check the keysize field
  1109. if (true==bOK) {
  1110. var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  1111. var sMessage;
  1112. if (isNaN(nKeySize)) {
  1113. sMessage=L_KeySizeNotNumber_ErrorMessage;
  1114. bOK=false;
  1115. } else if (g_nCurTemplateKeySizeMin > g_nCurKeySizeMax) {
  1116. sMessage=eval(L_TemplateKeySizeTooBig_ErrorMessage);
  1117. bOK = false;
  1118. } else if (nKeySize < g_nCurKeySizeMin || nKeySize > g_nCurKeySizeMax || 0!=nKeySize%g_nCurKeySizeInc) {
  1119. sMessage=eval(L_KeySizeBadNumber_ErrorMessage);
  1120. bOK=false;
  1121. }
  1122. if (false==bOK) {
  1123. alert (sMessage);
  1124. document.UIForm.tbKeySize.focus();
  1125. }
  1126. }
  1127. // Check the container name
  1128. if (true==bOK) {
  1129. if (document.UIForm.rbKeyGen[1].checked
  1130. || (document.UIForm.rbKeyGen[0].checked && document.UIForm.rbGenContName[1].checked)) {
  1131. if (""==document.UIForm.tbContainerName.value) {
  1132. bOK=false;
  1133. alert(L_NoCntnrName_ErrorMessage);
  1134. document.UIForm.tbContainerName.focus();
  1135. }
  1136. }
  1137. }
  1138. <%If bEnableExportKeyToFile Then%>
  1139. // Check the exported private key file name
  1140. if (true==bOK) {
  1141. if (document.UIForm.rbKeyGen[0].checked
  1142. && document.UIForm.cbMarkKeyExportable.checked
  1143. && document.UIForm.cbExportKeys.checked) {
  1144. if (""==document.UIForm.tbExportKeyFile.value) {
  1145. bOK=false;
  1146. alert(L_NoExportFileName_ErrorMessage);
  1147. document.UIForm.tbExportKeyFile.focus();
  1148. }
  1149. }
  1150. }
  1151. <%End If%>
  1152. // Check the saved-request file name
  1153. if (true==bOK) {
  1154. if (document.UIForm.cbSaveRequest.checked) {
  1155. if (""==document.UIForm.tbSaveReqFile.value) {
  1156. bOK=false;
  1157. alert(L_NoSaveReqFileName_ErrorMessage);
  1158. document.UIForm.tbSaveReqFile.focus();
  1159. }
  1160. }
  1161. }
  1162. return bOK;
  1163. }
  1164. //----------------------------------------------------------------
  1165. function SubmitRequest() {
  1166. g_bSubmitPending=true;
  1167. // check that the form is filled in
  1168. spnErrorTxt.style.display='none';
  1169. spnFixTxt.style.display='none';
  1170. if (false==validateRequest()) {
  1171. g_bSubmitPending=false;
  1172. return;
  1173. }
  1174. // show a nice message since request creation can take a while
  1175. ShowTransientMessage(L_Generating_Message);
  1176. // Make the message show up on the screen,
  1177. // then continue with 'SubmitRequest':
  1178. // Pause 10 mS before executing phase 2,
  1179. // so screen will have time to repaint.
  1180. setTimeout("SubmitRequestPhase2();", 10);
  1181. }
  1182. function SubmitRequestPhase2() {
  1183. // continued from above
  1184. <%If "StandAlone"=sServerType Then%>
  1185. //
  1186. // Stand-Alone Options
  1187. //
  1188. // set the extended key usage and certificate request 'friendly type'
  1189. var nUsageIndex=document.UIForm.lbUsageOID.selectedIndex;
  1190. var sCertUsage;
  1191. if ("**"==document.UIForm.lbUsageOID.options[nUsageIndex].value) {
  1192. sCertUsage=document.UIForm.tbEKUOther.value;
  1193. document.SubmittedData.FriendlyType.value=eval(L_UserEKUCert_Text);
  1194. } else {
  1195. sCertUsage=document.UIForm.lbUsageOID.options[nUsageIndex].value;
  1196. document.SubmittedData.FriendlyType.value=document.UIForm.lbUsageOID.options[nUsageIndex].text;
  1197. }
  1198. <%Else 'Enterprise%>
  1199. //
  1200. // Enterprise Options
  1201. //
  1202. // get cert template info
  1203. var lCTEVer = XECT_EXTENSION_V1;
  1204. var lCTEMajor = 0;
  1205. var bCTEfMinor = false;
  1206. var lCTEMinor = 0;
  1207. var sRealName = getTemplateStringInfo(CTINFO_INDEX_REALNAME, null);
  1208. var sCTEOID = getTemplateStringInfo(CTINFO_INDEX_EXTOID, null);
  1209. if ("" == sCTEOID) {
  1210. //must v1 template, get template name
  1211. sCTEOID = sRealName;
  1212. } else {
  1213. // v2 template
  1214. lCTEVer = XECT_EXTENSION_V2;
  1215. lCTEMajor = getTemplateValueInfo(CTINFO_INDEX_EXTMAJ, null);
  1216. bCTEfMinor = getTemplateValueInfo(CTINFO_INDEX_EXTFMIN, null);
  1217. lCTEMinor = getTemplateValueInfo(CTINFO_INDEX_EXTMIN, null);
  1218. }
  1219. // set the cert template
  1220. vbAddCertTypeToRequestEx(lCTEVer, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor);
  1221. document.SubmittedData.FriendlyType.value=eval(L_TemplateCert_Text);
  1222. var sCertUsage=""; // ignored
  1223. <%End If 'StandAlone or Enterprise%>
  1224. //
  1225. // Common
  1226. //
  1227. // set the identifying info
  1228. var sDistinguishedName="";
  1229. if (""!=document.UIForm.tbCountry.value) {
  1230. sDistinguishedName+="C=\""+document.UIForm.tbCountry.value.replace(/"/g, "\"\"") +"\";";
  1231. }
  1232. if (""!=document.UIForm.tbState.value) {
  1233. sDistinguishedName+="S=\""+document.UIForm.tbState.value.replace(/"/g, "\"\"") +"\";";
  1234. }
  1235. if (""!=document.UIForm.tbLocality.value) {
  1236. sDistinguishedName+="L=\""+document.UIForm.tbLocality.value.replace(/"/g, "\"\"") +"\";";
  1237. }
  1238. if (""!=document.UIForm.tbOrg.value) {
  1239. sDistinguishedName+="O=\""+document.UIForm.tbOrg.value.replace(/"/g, "\"\"") +"\";";
  1240. }
  1241. if (""!=document.UIForm.tbOrgUnit.value) {
  1242. sDistinguishedName+="OU=\""+document.UIForm.tbOrgUnit.value.replace(/"/g, "\"\"") +"\";";
  1243. }
  1244. if (""!=document.UIForm.tbEmail.value) {
  1245. sDistinguishedName+="E=\""+document.UIForm.tbEmail.value.replace(/"/g, "\"\"") +"\";";
  1246. }
  1247. if (""!=document.UIForm.tbCommonName.value) {
  1248. sDistinguishedName+="CN=\""+document.UIForm.tbCommonName.value.replace(/"/g, "\"\"")+"\";";
  1249. }
  1250. <%If "Enterprise"=sServerType Then%>
  1251. if (false==isDNNeeded()) {
  1252. sDistinguishedName="";
  1253. }
  1254. <%End If%>
  1255. // append the local date to the type
  1256. document.SubmittedData.FriendlyType.value+=" ("+(new Date()).toLocaleString()+")";
  1257. //
  1258. // Key Options subheading:
  1259. //
  1260. // set the 'SaveCert' flag to install the cert instead of saving
  1261. document.SubmittedData.SaveCert.value="no";
  1262. // set the CSP
  1263. var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  1264. XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  1265. XEnroll.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  1266. // set the key size (the upper 16 bits of GenKeyFlags)
  1267. // note: this value has already been validated
  1268. var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  1269. XEnroll.GenKeyFlags=nKeySize<<16;
  1270. // set the KeyUsage
  1271. if (document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked) {
  1272. XEnroll.KeySpec=AT_KEYEXCHANGE;
  1273. XEnroll.LimitExchangeKeyToEncipherment=true;
  1274. } else if (document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked) {
  1275. XEnroll.KeySpec=AT_SIGNATURE;
  1276. XEnroll.LimitExchangeKeyToEncipherment=false;
  1277. } else { // KEY_USAGE_BOTH
  1278. XEnroll.KeySpec=AT_KEYEXCHANGE;
  1279. XEnroll.LimitExchangeKeyToEncipherment=false;
  1280. }
  1281. // set the 'use existing key set' flag
  1282. if (document.UIForm.rbKeyGen[0].checked) {
  1283. XEnroll.UseExistingKeySet=false;
  1284. if (document.UIForm.rbGenContName[1].checked) {
  1285. XEnroll.ContainerName=document.UIForm.tbContainerName.value;
  1286. }
  1287. // set 'Strong private key protection'
  1288. // note: upper 16 bits already set as key size
  1289. if (document.UIForm.cbStrongKey.checked) {
  1290. XEnroll.GenKeyFlags|=CRYPT_USER_PROTECTED;
  1291. }
  1292. // mark the keys as exportable
  1293. if (document.UIForm.cbMarkKeyExportable.checked) {
  1294. XEnroll.GenKeyFlags|=CRYPT_EXPORTABLE;
  1295. <%If bEnableExportKeyToFile Then%>
  1296. // set the key export file (.pvk) and save the cert instead of installing
  1297. if (document.UIForm.cbExportKeys.checked) {
  1298. XEnroll.PVKFileName=document.UIForm.tbExportKeyFile.value;
  1299. document.SubmittedData.SaveCert.value="yes";
  1300. }
  1301. <%End If%>
  1302. }
  1303. } else {
  1304. // set the 'use existing key set' flag
  1305. XEnroll.UseExistingKeySet=true;
  1306. XEnroll.ContainerName=document.UIForm.tbContainerName.value;
  1307. }
  1308. // place the keys in the local machine store
  1309. if (document.UIForm.cbLocalMachineStore.checked) {
  1310. // the keys attached to the dummy request cert go in the local machine store
  1311. XEnroll.RequestStoreFlags=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  1312. // used in CryptAcquireContext
  1313. XEnroll.ProviderFlags=CRYPT_MACHINE_KEYSET;
  1314. // the keys attached to the final cert also go in the local machine store
  1315. document.SubmittedData.TargetStoreFlags.value=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  1316. } else {
  1317. // the keys attached to the final cert also go in the user store
  1318. document.SubmittedData.TargetStoreFlags.value=0; // 0=Use default (=user store)
  1319. }
  1320. var dwCreateRequestFlag = XECR_CMC;
  1321. if (document.UIForm.rbRequestFormat[1].checked)
  1322. {
  1323. dwCreateRequestFlag = XECR_PKCS10_V2_0;
  1324. }
  1325. <%If "Enterprise"=sServerType Then%>
  1326. //SMIME capabilities
  1327. XEnroll.EnableSMIMECapabilities = isSMimeCapabilities();
  1328. //Key archival
  1329. if (isTemplateKeyArchival())
  1330. {
  1331. var nResult = SetPrivateKeyArchiveCertificate(); //call VB
  1332. if (0 != nResult)
  1333. {
  1334. handleError(nResult);
  1335. return;
  1336. }
  1337. }
  1338. <%End If%>
  1339. if ("" != document.UIForm.tbFriendlyName.value)
  1340. {
  1341. //set friendly name property
  1342. var CERT_FRIENDLY_NAME_PROP_ID=11;
  1343. var XECP_STRING_PROPERTY=1;
  1344. XEnroll.addBlobPropertyToCertificate(CERT_FRIENDLY_NAME_PROP_ID, XECP_STRING_PROPERTY, document.UIForm.tbFriendlyName.value);
  1345. }
  1346. //
  1347. // Additional Options subheading:
  1348. //
  1349. // set the hash algorithm
  1350. var nHashIndex=document.UIForm.lbHashAlgorithm.selectedIndex;
  1351. XEnroll.HashAlgID=document.UIForm.lbHashAlgorithm.options[nHashIndex].value;
  1352. // set any extra attributes
  1353. var sAttrib=document.UIForm.taAttrib.value;
  1354. if (sAttrib.lastIndexOf("\r\n")!=sAttrib.length-2 && sAttrib.length>0) {
  1355. sAttrib=sAttrib+"\r\n";
  1356. }
  1357. // for interop debug purposes
  1358. sAttrib+="UserAgent:<%=Request.ServerVariables("HTTP_USER_AGENT")%>\r\n";
  1359. document.SubmittedData.CertAttrib.value=sAttrib;
  1360. // we are submitting a new request
  1361. document.SubmittedData.Mode.value='newreq';
  1362. //
  1363. // Create the request
  1364. //
  1365. var nResult;
  1366. if (document.UIForm.cbSaveRequest.checked) {
  1367. // build and save the certificate request
  1368. var sSaveReqFile=document.UIForm.tbSaveReqFile.value;
  1369. nResult=CreateAndSaveRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage, sSaveReqFile); // ask VB to do it, since it can handle errors
  1370. } else {
  1371. // build the certificate request
  1372. nResult=CreateRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage); // ask VB to do it, since it can handle errors
  1373. }
  1374. if (0 == nResult)
  1375. {
  1376. //always get thumbprint in case of pending
  1377. document.SubmittedData.ThumbPrint.value=XEnroll.ThumbPrint;
  1378. }
  1379. // hide the message box
  1380. HideTransientMessage();
  1381. // reset XEnroll so the user can select a different CSP, etc.
  1382. XEnroll.reset();
  1383. // however, make sure it still matches the UI.
  1384. XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  1385. XEnroll.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  1386. // deal with an error if there was one
  1387. if (0!=nResult) {
  1388. g_bSubmitPending=false;
  1389. if (document.UIForm.cbSaveRequest.checked && 0==(0x800704c7^nResult)) {
  1390. //cancelled
  1391. nResult=0;
  1392. return;
  1393. }
  1394. handleError(nResult);
  1395. return;
  1396. }
  1397. // check for special "no submit" case
  1398. if (document.UIForm.cbSaveRequest.checked) {
  1399. // just inform the user that it went OK, but don't submit
  1400. alert(L_RequestSaved_Message);
  1401. g_bSubmitPending=false;
  1402. } else {
  1403. // put up a new wait message
  1404. ShowTransientMessage(L_Waiting_Message);
  1405. // Submit the cert request and move forward in the wizard
  1406. document.SubmittedData.submit();
  1407. }
  1408. }
  1409. //----------------------------------------------------------------
  1410. function handleError(nResult) {
  1411. var sSugCause=L_SugCauseNone_ErrorMessage;
  1412. var sErrorName=L_ErrNameUnknown_ErrorMessage;
  1413. // analyze the error - funny use of XOR ('^') because obvious choice '==' doesn't work
  1414. if (0==(0x80090008^nResult)) {
  1415. sErrorName="NTE_BAD_ALGID";
  1416. sSugCause=L_SugCauseBadSetting2_ErrorMessage;
  1417. } else if (0==(0x80090016^nResult)) {
  1418. sErrorName="NTE_BAD_KEYSET";
  1419. if (document.UIForm.rbKeyGen[0].checked) {
  1420. sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1421. } else {
  1422. sSugCause=L_SugCauseBadKeyContainer_ErrorMessage;
  1423. }
  1424. } else if (0==(0x80090019^nResult)) {
  1425. sErrorName="NTE_KEYSET_NOT_DEF";
  1426. sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1427. } else if (0==(0x80090020^nResult)) {
  1428. sErrorName="NTE_FAIL";
  1429. sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1430. } else if (0==(0x80090009^nResult)) {
  1431. sErrorName="NTE_BAD_FLAGS";
  1432. sSugCause=L_SugCauseBadSetting2_ErrorMessage;
  1433. } else if (0==(0x8009000F^nResult)) {
  1434. sErrorName="NTE_EXISTS";
  1435. sSugCause=L_SugCauseExistKeyContainer_ErrorMessage;
  1436. } else if (0==(0x80092002^nResult)) {
  1437. sErrorName="CRYPT_E_BAD_ENCODE";
  1438. //sSugCause="";
  1439. } else if (0==(0x80092022^nResult)) {
  1440. sErrorName="CRYPT_E_INVALID_IA5_STRING";
  1441. sSugCause=L_SugCauseBadChar_ErrorMessage;
  1442. } else if (0==(0x80092023^nResult)) {
  1443. sErrorName="CRYPT_E_INVALID_X500_STRING";
  1444. sSugCause=L_SugCauseBadChar_ErrorMessage;
  1445. } else if (0==(0x80070003^nResult)) {
  1446. sErrorName="ERROR_PATH_NOT_FOUND";
  1447. sSugCause=L_SugCauseBadFileName_ErrorMessage;
  1448. } else if (0==(0x80070103^nResult)) {
  1449. sErrorName="ERROR_NO_MORE_ITEMS";
  1450. sSugCause=L_SugCauseBadHash_ErrorMessage;
  1451. } else if (0==(0x8007007B^nResult)) {
  1452. sErrorName="ERROR_INVALID_NAME";
  1453. sSugCause=L_SugCauseBadFileName_ErrorMessage;
  1454. } else if (0==(0x80070015^nResult)) {
  1455. sErrorName="ERROR_NOT_READY";
  1456. sSugCause=L_SugCauseBadDrive_ErrorMessage;
  1457. } else if (0==(0x8007007F^nResult)) {
  1458. sErrorName="ERROR_PROC_NOT_FOUND";
  1459. sSugCause=L_DownLevelClients_ErrorMessage;
  1460. } else if (0==(0x80100006^nResult)) {
  1461. sErrorName = "SCARD_E_NO_MEMORY";
  1462. sSugCause = L_SCARD_E_NO_MEMORY_MSG;
  1463. } else if (0==(0x80100007^nResult)) {
  1464. sErrorName = "SCARD_F_WAITED_TOO_LONG";
  1465. sSugCause = L_SCARD_F_WAITED_TOO_LONG;
  1466. } else if (0==(0x80100008^nResult)) {
  1467. sErrorName = "SCARD_E_INSUFFICIENT_BUFFER";
  1468. sSugCause = L_SCARD_E_INSUFFICIENT_BUFFER;
  1469. } else if (0==(0x80100009^nResult)) {
  1470. sErrorName = "SCARD_E_UNKNOWN_READER";
  1471. sSugCause = L_SCARD_E_UNKNOWN_READER;
  1472. } else if (0==(0x8010000C^nResult)) {
  1473. sErrorName = "SCARD_E_NO_SMARTCARD";
  1474. sSugCause = L_SCARD_E_NO_SMARTCARD;
  1475. } else if (0==(0x8010000D^nResult)) {
  1476. sErrorName = "SCARD_E_UNKNOWN_CARD";
  1477. sSugCause = L_SCARD_E_UNKNOWN_CARD;
  1478. } else if (0==(0x80100010^nResult)) {
  1479. sErrorName = "SCARD_E_NOT_READY";
  1480. sSugCause = L_SCARD_E_NOT_READY;
  1481. } else if (0==(0x80100013^nResult)) {
  1482. sErrorName = "SCARD_F_COMM_ERROR";
  1483. sSugCause = L_SCARD_F_COMM_ERROR;
  1484. } else if (0==(0x8010001D^nResult)) {
  1485. sErrorName = "SCARD_E_NO_SERVICE";
  1486. sSugCause = L_SCARD_E_NO_SERVICE;
  1487. } else if (0==(0x8010001E^nResult)) {
  1488. sErrorName = "SCARD_E_SERVICE_STOPPED";
  1489. sSugCause = L_SCARD_E_SERVICE_STOPPED;
  1490. } else if (0==(0x8010002E^nResult)) {
  1491. sErrorName = "SCARD_E_NO_READERS_AVAILABLE";
  1492. sSugCause = L_SCARD_E_NO_READERS_AVAILABLE;
  1493. } else if (0==(0x8010002F^nResult)) {
  1494. sErrorName = "SCARD_E_COMM_DATA_LOST";
  1495. sSugCause = L_SCARD_E_COMM_DATA_LOST;
  1496. } else if (0==(0x80100030^nResult)) {
  1497. sErrorName = "SCARD_E_NO_KEY_CONTAINER";
  1498. sSugCause = L_SCARD_E_NO_KEY_CONTAINER;
  1499. } else if (0==(0x80100067^nResult)) {
  1500. sErrorName = "SCARD_W_UNPOWERED_CARD";
  1501. sSugCause = L_SCARD_W_UNPOWERED_CARD;
  1502. } else if (0==(0x80100069^nResult)) {
  1503. sErrorName = "SCARD_W_REMOVED_CARD";
  1504. sSugCause = L_SCARD_W_REMOVED_CARD;
  1505. } else if (0==(0x8010006B^nResult)) {
  1506. sErrorName = "SCARD_W_WRONG_CHV";
  1507. sSugCause = L_SCARD_W_WRONG_CHV;
  1508. } else if (0==(0x8010006C^nResult)) {
  1509. sErrorName = "SCARD_W_CHV_BLOCKED";
  1510. sSugCause = L_SCARD_W_CHV_BLOCKED;
  1511. } else if (0==(0x8010006D^nResult)) {
  1512. sErrorName = "SCARD_W_EOF";
  1513. sSugCause = L_SCARD_W_EOF;
  1514. } else if (0==(0x8010006E^nResult)) {
  1515. sErrorName = "SCARD_W_CANCELLED_BY_USER";
  1516. sSugCause = L_SCARD_W_CANCELLED_BY_USER;
  1517. } else if (0==(0x8010006F^nResult)) {
  1518. sErrorName = "SCARD_W_CARD_NOT_AUTHENTICATED";
  1519. sSugCause = L_SCARD_W_CARD_NOT_AUTHENTICATED;
  1520. } else if (0==(0xFFFFFFFF^nResult)) {
  1521. sErrorName=L_ErrNameNoFileName_ErrorMessage;
  1522. sSugCause=L_SugCauseNoFileName_ErrorMessage;
  1523. } else if (0==(0x8000FFFF^nResult)) {
  1524. sErrorName="E_UNEXPECTED";
  1525. } else if (0==(0x00000046^nResult)) {
  1526. sErrorName=L_ErrNamePermissionDenied_ErrorMessage;
  1527. if (document.UIForm.cbSaveRequest.checked) {
  1528. sSugCause=L_SugCausePermissionToWrite_ErrorMessage;
  1529. }
  1530. else {
  1531. sSugCause=L_SugCausePermissionToWrite_ErrorMessage;
  1532. }
  1533. }
  1534. // modify the document text and appearance to show the error message
  1535. spnErrorNum.innerText="0x"+toHex(nResult)+" - "+sErrorName;
  1536. spnErrorMsg.innerText=sSugCause;
  1537. spnFixTxt.style.display='none';
  1538. spnErrorTxt.style.display='';
  1539. // back to the top so the messages show
  1540. window.scrollTo(0,0);
  1541. }
  1542. </Script>
  1543. <Script Language="VBScript">
  1544. ' The current CA exchange certificate
  1545. Public sCAExchangeCert
  1546. sCAExchange=""
  1547. <%=sCAExchangeCert%>
  1548. '-----------------------------------------------------------------
  1549. ' call XEnroll to create a request, since javascript has no error handling
  1550. Function CreateRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage)
  1551. On Error Resume Next
  1552. document.SubmittedData.CertRequest.value= _
  1553. XEnroll.CreateRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage)
  1554. CreateRequest=Err.Number
  1555. End Function
  1556. '-----------------------------------------------------------------
  1557. ' call XEnroll to create and save a request, since javascript has no error handling
  1558. Function CreateAndSaveRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage, sSaveReqFile)
  1559. On Error Resume Next
  1560. XEnroll.createFileRequest dwCreateRequestFlag, sDistinguishedName, sCertUsage, sSaveReqFile
  1561. CreateAndSaveRequest=Err.Number
  1562. End Function
  1563. '----------------------------------------------------------------
  1564. ' handle a change in the current CSP, since javascript has no error handling
  1565. Sub UpdateHashAlgList(nProvType)
  1566. On Error Resume Next
  1567. Dim nIndex, nAlgID, oElem
  1568. ' clear the list
  1569. While document.UIForm.lbHashAlgorithm.length>0
  1570. document.UIForm.lbHashAlgorithm.options.remove(0)
  1571. Wend
  1572. ' retrieve the list from XEnroll
  1573. nIndex=0
  1574. Do
  1575. ' get the next AlgID
  1576. nAlgID=XEnroll.EnumAlgs(nIndex, ALG_CLASS_HASH)
  1577. If 0<>Err.Number Then
  1578. ' no more algs
  1579. Err.Clear
  1580. Exit Do
  1581. End If
  1582. ' get the corresponding name and create an option in the list box
  1583. sName=XEnroll.GetAlgName(nAlgID)
  1584. If "MAC"<>sName And "HMAC"<>sName And "SSL3 SHAMD5"<>sName And "MD5"<>sName Or "MAC"<>sName And "HMAC"<>sName And "SSL3 SHAMD5"<>sName And 3<>nProvType Then 'skip some one we know don't work
  1585. Set oElem=document.createElement("Option")
  1586. oElem.text=sName
  1587. oElem.value=nAlgID
  1588. document.UIForm.lbHashAlgorithm.options.add(oElem)
  1589. End If
  1590. nIndex=nIndex+1
  1591. Loop ' <- End alg enumeration loop
  1592. ' make sure the first one is selectd
  1593. document.UIForm.lbHashAlgorithm.selectedIndex=0
  1594. End Sub
  1595. '----------------------------------------------------------------
  1596. ' call XEnroll to get the key length, since javascript has no error handling
  1597. Function MyGetKeyLen(nSizeSpec, bExchange)
  1598. On Error Resume Next
  1599. Dim nKeySpec
  1600. If True=bExchange Then
  1601. nKeySpec=XEKL_KEYSPEC_KEYX
  1602. Else
  1603. nKeySpec=XEKL_KEYSPEC_SIG
  1604. End If
  1605. MyGetKeyLen=XEnroll.GetKeyLenEx(nSizeSpec, nKeySpec)
  1606. If 0<>Err.Number Then
  1607. If XEKL_KEYSIZE_MIN=nSizeSpec Then
  1608. MyGetKeyLen=KEY_LEN_MIN_DEFAULT
  1609. ElseIf XEKL_KEYSIZE_MAX=nSizeSpec Then
  1610. MyGetKeyLen=KEY_LEN_MAX_DEFAULT
  1611. ElseIf XEKL_KEYSIZE_DEFAULT=nSizeSpec Then
  1612. MyGetKeyLen=KEY_LEN_MY_DEFAULT 'try 1024
  1613. Else 'assume XEKL_KEYSIZE_INC=nSizeSpec
  1614. MyGetKeyLen=KEY_LEN_INC_DEFAULT
  1615. End If
  1616. End If
  1617. If XEKL_KEYSIZE_INC=nSizeSpec And 0=MyGetKeyLen Then
  1618. MyGetKeyLen=KEY_LEN_INC_DEFAULT
  1619. End If
  1620. End Function
  1621. '----------------------------------------------------
  1622. ' set a certificate for key archive
  1623. Function SetPrivateKeyArchiveCertificate()
  1624. On Error Resume Next
  1625. XEnroll.PrivateKeyArchiveCertificate=sCAExchange
  1626. SetPrivateKeyArchiveCertificate = Err.Number
  1627. End Function
  1628. '----------------------------------------------------
  1629. ' set request template extension
  1630. Function vbAddCertTypeToRequestEx(lCTEVer, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor)
  1631. On Error Resume Next
  1632. XEnroll.addCertTypeToRequestEx lCTEVer, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor
  1633. If 0 <> Err.Number Then
  1634. 'possible on downlevel not supporting v2 encoding, change to v1
  1635. XEnroll.addCertTypeToRequestEx XECT_EXTENSION_V1, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor
  1636. End If
  1637. vbAddCertTypeToRequestEx=Err.Number
  1638. End Function
  1639. </Script>
  1640. <%End If 'bFailed%>
  1641. </Body>
  1642. </HTML>