Leaked source code of windows server 2003
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.

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