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.

1359 lines
44 KiB

  1. <HTML>
  2. <!--
  3. certnoca.hta - (CERT)srv web - (NO) (CA) cert-request management
  4. This is an HTML application. We are assuming that we are running
  5. on IE 5 (or compatible), stand alone from any CA.
  6. -->
  7. <Head>
  8. <Title>No-CA Certificate Request Manager</Title>
  9. </Head>
  10. <Body BgColor=#FFFFFF OnLoad="postLoad();"><Font Face="Arial">
  11. <Table border=0 CellSpacing=0 CellPadding=4 width=100% BgColor=#008080>
  12. <TR>
  13. <TD><font color=#FFFFFF size=-1 Face="Arial"><B><I>Microsoft</I></B> Certificate Services</Font></TD>
  14. <TD Align=right><A href="" OnClick="goHome();return false;"><font color=#FFFFFF size=-1 Face="Arial"><B>Home</B></Font></A></TD>
  15. </TR>
  16. </Table>
  17. <Form name=UIForm>
  18. <!-- #################### PAGE 1 #################### -->
  19. <Span ID="spnPage1">
  20. <P> <B> Welcome </B>
  21. <!-- 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>
  22. <P> You use this application to generate PKCS #10 certificate requests and install PKCS #7 certificates.
  23. <P>
  24. <Table border=0 cellspacing=0 cellpadding=0>
  25. <TR>
  26. <TD Colspan=3><Font Face="Arial"><B>Select a task:</B></Font></TD>
  27. </TR><TR>
  28. <TD rowspan=2><IMG Src="certspc.gif" alt="" height=1 width=20></TD>
  29. <TD><INPUT type="radio" id=rbGenReq name=rbgrpAction checked value=1></TD>
  30. <TD><Font Face="Arial"><Label for=rbGenReq>Generate a PKCS #10 certificate request</Label></Font></TD>
  31. </TR> <TR>
  32. <TD><INPUT type="radio" id=rbInstall name=rbgrpAction value=2></TD>
  33. <TD><Font Face="Arial"><Label for=rbInstall>Install an PKCS #7 certificate</Label></Font></TD>
  34. </TR>
  35. </Table>
  36. <P>
  37. <!-- 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>
  38. <!-- 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>
  39. <Table width=100% border=0 cellpadding=0 cellspacing=0><TR><TD align=right>
  40. <INPUT type=button value="Next &gt;" Name=btnNext1 style="width:.75in" OnClick="goNext();">
  41. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  42. </TD></TR></Table>
  43. </Span>
  44. <!-- #################### PAGE 2 #################### -->
  45. <Span ID="spnPage2" Style="display:none">
  46. <P> <B> Generate A PKCS #10 Certificate Request </B>
  47. <!-- 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>
  48. <Span ID="spnFixTxt" style="display:none">
  49. <Table border=0 cellspacing=0 cellpadding=4 Style="Color:#FF0000"><TR><TD>
  50. <I>Please correct the fields marked in <B><Font color=#FF0000>RED</Font></B>.</I>
  51. One or more fields are contain the characters (, ; " or +)
  52. that cannot be processed, or the e-mail or country fields contain non-English characters.
  53. </TD></TR></Table>
  54. </Span>
  55. <Span ID="spnErrorTxt" style="display:none">
  56. <Table border=0 cellspacing=0 cellpadding=4 Style="Color:#FF0000">
  57. <TR><TD>
  58. <B>An error occurred</B> while creating the certificate request.
  59. Please verify that your CSP supports any settings you have made
  60. and that your input is valid.
  61. </TD></TR><TR><TD>
  62. <B>Suggested cause:</B><BR>
  63. <span ID="spnErrorMsg"></span>
  64. </TD></TR><TR>
  65. <TD><font size=-2>Error: <span ID="spnErrorNum"></span></font></TD>
  66. </TR>
  67. </Table>
  68. </Span>
  69. <P>
  70. <Table Border=0 CellSpacing=0 CellPadding=0>
  71. <TR> <!-- establish column widths. -->
  72. <TD width=100></TD> <!-- label column, top border -->
  73. <TD rowspan=59 width=4></TD> <!-- label spacing column -->
  74. <TD></TD> <!-- field column -->
  75. </TR>
  76. <TR>
  77. <TD colspan=3><Font Size=-1><B>Identifying Information:</B></Font></TD>
  78. </TR><TR><TD colspan=3 height=2 BgColor=#008080></TD>
  79. </TR><TR><TD colspan=3 height=6></TD>
  80. </TR><TR>
  81. <TD Align=right><Font size=-1><Span ID="spnNameLabel">Name:</Span></Font></TD>
  82. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbCommonName"></TD>
  83. </TR><TR>
  84. <TD Align=right><Font size=-1><Span ID="spnEmailLabel">E-Mail:</Span></Font></TD>
  85. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbEmail"></TD>
  86. </TR><TR><TD height=8></TD> <TD></TD>
  87. </TR><TR>
  88. <TD Align=right><Font size=-1><Span ID="spnCompanyLabel">Company:</Span></Font></TD>
  89. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbOrg"></TD>
  90. </TR><TR>
  91. <TD Align=right><Font size=-1><Span ID="spnDepartmentLabel">Department:</Span></Font></TD>
  92. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbOrgUnit"></TD>
  93. </TR><TR><TD height=8></TD> <TD></TD>
  94. </TR><TR>
  95. <TD Align=right><Font size=-1><Span ID="spnCityLabel">City:</Span></Font></TD>
  96. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbLocality"></TD>
  97. </TR><TR>
  98. <TD Align=right><Font size=-1><Span ID="spnStateLabel">State:</Span></Font></TD>
  99. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbState"></TD>
  100. </TR><TR>
  101. <TD Align=right><Font size=-1><Span ID="spnCountryLabel">Country:</Span></Font></TD>
  102. <TD><Input Type="text" MaxLength="2" Size=2 Name="tbCountry"></TD>
  103. </TR>
  104. <!-- Stand-Alone Options -->
  105. <TR>
  106. <TD colspan=3><Font Size=-1><B><BR>Extended Key Usage:</B></Font></TD>
  107. </TR><TR><TD colspan=3 height=2 BgColor=#008080></TD>
  108. </TR><TR><TD colspan=3 height=6></TD>
  109. </TR><TR><TD></TD>
  110. <TD><SELECT Name="lbUsageOID" OnChange="handleUsageOID();">
  111. <OPTION SELECTED Value="1.3.6.1.5.5.8.2.2"> IPSec
  112. <OPTION Value="1.3.6.1.5.5.7.3.2"> Client Authentication
  113. <OPTION Value="1.3.6.1.5.5.7.3.4"> E-Mail Protection
  114. <OPTION Value="1.3.6.1.5.5.7.3.1"> Server Authentication
  115. <OPTION Value="1.3.6.1.5.5.7.3.3"> Code Signing
  116. <OPTION Value="1.3.6.1.5.5.7.3.8"> Time Stamp Signing
  117. <OPTION Value="other"> other...
  118. </SELECT></TD>
  119. </TR>
  120. <TR><TD Align=Right><Span ID=spnEKUOther1 Style="display:none"><Font size=-1>Usage OID:</Font></Span></TD>
  121. <TD><Span ID=spnEKUOther2 Style="display:none"><Input Type="TEXT" Name="tbEKUOther" Value="1.3.6.1.5.5.7.3."></Span></TD>
  122. </TR>
  123. <!-- Enterprise Options -->
  124. <!--
  125. <TR>
  126. <TD colspan=3><Font Size=-1><B><BR>Certificate Template:</B></Font></TD>
  127. </TR><TR><TD colspan=3 height=2 BgColor=#008080></TD>
  128. </TR><TR><TD colspan=3 height=6></TD>
  129. </TR><TR><TD></TD>
  130. <TD><SELECT Name="lbCertTemplate">
  131. < %
  132. Dim nWriteTemplateResult
  133. nWriteTemplateResult=WriteTemplateList()
  134. % >
  135. </SELECT></TD>
  136. </TR>
  137. -->
  138. <!-- common -->
  139. <TR>
  140. <TD colspan=3><Font Size=-1><B><BR>Cryptographic Service Provider Options:</B></Font></TD>
  141. </TR><TR><TD colspan=3 height=2 BgColor=#008080></TD>
  142. </TR><TR><TD colspan=3 height=6></TD>
  143. </TR>
  144. <TR>
  145. <TD Align=right><Font size=-1>CSP:</Font></TD>
  146. <TD><SELECT Name="lbCSP">
  147. <option>Loading...</Option>
  148. </SELECT></TD>
  149. </TR>
  150. <TR><TD colspan=3 height=4></TD></TR>
  151. <TR>
  152. <TD Align=right ><Font size=-1>Key Size:</Font></TD>
  153. <TD><Font size=-2><Input Type="TEXT" Name="tbKeySize" Value="512" MaxLength=4 size=4>
  154. (common key sizes:
  155. <A Href="" OnClick="document.UIForm.tbKeySize.value='512';return false;">512</a>,
  156. <A Href="" OnClick="document.UIForm.tbKeySize.value='1024';return false;">1024</a>,
  157. <A Href="" OnClick="document.UIForm.tbKeySize.value='2048';return false;">2048</a>,
  158. <A Href="" OnClick="document.UIForm.tbKeySize.value='4096';return false;">4096</a>
  159. )</Font></TD>
  160. </TR>
  161. <TR><TD colspan=3 height=4></TD></TR>
  162. <TR>
  163. <TD Align=right><Font size=-1>Hash Algorithm:</Font></TD>
  164. <TD><Select Name="lbHashAlgorithm">
  165. <Option Selected Value="SHA1"> SHA/RSA
  166. <Option Value="1.3.14.3.2.13"> SHA/DSA
  167. <Option Value="MD2"> MD2
  168. <Option Value="MD5"> MD5
  169. </Select></TD>
  170. </TR>
  171. <TR><TD colspan=3 height=4></TD></TR>
  172. <TR>
  173. <TD Align=right><Font size=-1>Key Spec:</Font></TD>
  174. <TD><Font size=-1><Input Type="Radio" ID=rbKS1 Name="rbKeySpec" Value="1" CHECKED><Label for=rbKS1>Exchange</Label>
  175. &nbsp;&nbsp;&nbsp;<Input Type="Radio" ID=rbKS2 Name="rbKeySpec" Value="2"><Label for=rbKS2>Signature</Label></Font></TD>
  176. </TR>
  177. <TR>
  178. <TD colspan=3><Font Size=-1><B><BR>Key Generation Options:</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>
  182. <TR><TD></TD>
  183. <TD><Font size=-1><Input Type="Radio" ID=rbKG1 Name="rbKeyGen" Value="0" OnClick="handleKeyGen();" Checked><Label for=rbKG1>Create new key set</Label>
  184. <Span Id="spnNewKeys">
  185. <BR><IMG Src="certspc.gif" alt="" height=1 width=25><Input type="checkbox" Id=cbSetContainer name=cbSetContainer OnClick="handleSetContainer();"><Label for=cbSetContainer>Set the container name</Label>
  186. <Span Id="spnNewContainer" Style="display:none">
  187. <BR><IMG Src="certspc.gif" alt="" height=1 width=25>Container name:<Input Type="text" Name="tbNewContainerName" Size=20>
  188. </Span>
  189. </Span>
  190. </Font></TD>
  191. </TR><TR><TD></TD>
  192. <TD><Font size=-1><Input Type="Radio" ID=rbKG2 Name="rbKeyGen" Value="1" OnClick="handleKeyGen();"><Label for=rbKG2>Use existing key set</Label>
  193. <Span Id="spnExistingKeys" Style="display:none">
  194. <BR><IMG Src="certspc.gif" alt="" height=1 width=25>Container name:<Input Type="text" Name="tbOldContainerName" Size=20>
  195. </Span>
  196. </Font></TD>
  197. </TR>
  198. <TR><TD colspan=3 height=4></TD></TR>
  199. <TR>
  200. <TD></TD>
  201. <TD><Font size=-1><Input type="checkbox" Id=cbStrongKey name=cbStrongKey><Label for=cbStrongKey>Enable strong private key protection</Label></Font></TD>
  202. </TR>
  203. <TR><TD colspan=3 height=4></TD></TR>
  204. <TR><TD></TD>
  205. <TD><Font size=-1><Input Type="CHECKBOX" Name="cbMarkKeyExportable" ID=cbMarkKeyExportable OnClick="handleMarkExport();"><Label for=cbMarkKeyExportable>Mark keys as exportable</Label>
  206. <Span Id="spnMarkKeyExportable" Style="display:none">
  207. <BR><IMG Src="certspc.gif" alt="" height=1 width=25><Input Type="CHECKBOX" Name="cbExportKeys" ID=cbExportKeys OnClick="handleExportKeys();"><Label for=cbExportKeys>Export keys to file</Label>
  208. <Span Id="spnExportKeys" Style="display:none">
  209. <BR><IMG Src="certspc.gif" alt="" height=1 width=25>File name: <Input Type="text" Name="tbExportKeyFile" Size=20>
  210. </Span>
  211. </Span>
  212. </Font></TD>
  213. </TR>
  214. <TR><TD colspan=3 height=4></TD></TR>
  215. <TR><TD></TD>
  216. <TD><Font size=-1><Input Type="CHECKBOX" Name="cbLocalMachineStore" ID=cbLocalMachineStore><Label for=cbLocalMachineStore>Use local machine store</Label></Font></TD>
  217. </TR>
  218. <TR>
  219. <TD colspan=3><Font Size=-1><B><BR>Additional Options:</B></Font></TD>
  220. </TR><TR><TD colspan=3 height=2 BgColor=#008080></TD>
  221. </TR><TR><TD colspan=3 height=3></TD>
  222. </TR>
  223. <TR><TD colspan=3 height=6></TD>
  224. </TR><TR>
  225. <TD Align=right><Font size=-1>Attributes:</Font></TD>
  226. <TD><TextArea Name="taAttrib" Wrap=off rows=4 cols=30></TextArea></TD>
  227. </TR>
  228. <TR>
  229. <TD colspan=3><Font Size=-1><B><BR>Output File Name:</B></Font></TD>
  230. </TR><TR><TD colspan=3 height=2 BgColor=#008080></TD>
  231. </TR><TR><TD colspan=3 height=6></TD>
  232. </TR><TR>
  233. <TD Align=right></TD>
  234. <TD><Input Type="text" MaxLength="64" Size=42 Name="tbFileName"></TD>
  235. </TR>
  236. </Table>
  237. </P>
  238. <!-- 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>
  239. <!-- 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>
  240. <Table width=100% border=0 cellpadding=0 cellspacing=0><TR><TD align=right>
  241. <INPUT type=button value="Generate and Save" OnClick="generateRequest();return false;">
  242. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  243. </TD></TR></Table>
  244. </Span>
  245. <!-- #################### PAGE 3 #################### -->
  246. <Span ID="spnPage3" Style="display:none">
  247. <P> <B> Install An PKCS #7 Certificate </B>
  248. <!-- 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>
  249. <P>
  250. <Table Border=0 CellSpacing=0 CellPadding=0>
  251. <TR> <!-- establish column widths. -->
  252. <TD><IMG Src="certspc.gif" alt="" height=1 width=100></TD> <!-- label column, top border -->
  253. <TD rowspan=59><IMG Src="certspc.gif" alt="" height=1 width=4></TD> <!-- label spacing column -->
  254. <TD></TD> <!-- field column -->
  255. </TR>
  256. <TR>
  257. <TD colspan=3><Font Face="Arial" Size=-1><B>Saved Certificate:</B></Font></TD>
  258. </TR><TR><TD colspan=3 BgColor=#008080><IMG Src="certspc.gif" alt="" height=2 width=1></TD>
  259. </TR><TR><TD colspan=3><IMG Src="certspc.gif" alt="" height=3 width=1></TD></TR>
  260. <TR>
  261. <TD Align=right><Font Face="Arial" size=-1><Span id=spPaste>Base64 Encoded <BR>PKCS #7 Certificate:</Span></Font></TD>
  262. <TD><TEXTAREA rows=6 cols=40 name=taInstallCert wrap=off></TEXTAREA></TD>
  263. </TR><TR><TD colspan=3 height=3></TD>
  264. </TR><TR><TD></TD>
  265. <TD>
  266. <Font Face="Arial" Size=-1><A Href="#" onclick="BeginRead();blur();return false;"
  267. OnMouseOver="window.status='Read a file';return true;" OnMouseOut="window.status='';return true;">Browse</A>
  268. for a file to insert.</Font>
  269. <Span id=spRead style="display:none">
  270. <Table Border=0 CellSpacing=0 CellPadding=0>
  271. <TR><TD Height=5></TD>
  272. <TR>
  273. <TD Width=6></TD>
  274. <TD Width=3 BgColor=#008080></TD>
  275. <TD Width=4></TD>
  276. <TD>
  277. File name: <Input Type="file" size=40 name=flRequest><BR>
  278. <Input Type=Button Value="Read!" onClick="FinishRead();blur();" Style="font-weight:bold">
  279. <Input Type=Button Value="Cancel" onClick="spRead.style.display='none';blur();">
  280. </TD>
  281. </TR>
  282. </Table>
  283. </Span>
  284. </TD>
  285. </TR>
  286. <!-- Enterprise
  287. <TR>
  288. <TD colspan=3><Font Face="Arial" Size=-1><BR><B>Certificate Template:</B></Font></TD>
  289. </TR><TR><TD colspan=3 BgColor=#008080><IMG Src="certspc.gif" alt="" height=2 width=1></TD>
  290. </TR><TR><TD colspan=3><IMG Src="certspc.gif" alt="" height=3 width=1></TD>
  291. </TR><TR><TD></TD>
  292. <TD><SELECT Name="lbCertTemplate">
  293. < %
  294. Dim nWriteTemplateResult
  295. nWriteTemplateResult=WriteTemplateList()
  296. % >
  297. </SELECT></TD>
  298. </TR>
  299. -->
  300. <TR>
  301. <TD colspan=3><Font Face="Arial" Size=-1><BR><B>Additional Options:</B></Font></TD>
  302. </TR><TR><TD colspan=3 BgColor=#008080><IMG Src="certspc.gif" alt="" height=2 width=1></TD>
  303. </TR><TR><TD colspan=3><IMG Src="certspc.gif" alt="" height=6 width=1></TD>
  304. </TR>
  305. <TR><TD colspan=3 height=4></TD></TR>
  306. <TR><TD></TD>
  307. <TD><Font size=-1><Input Type="CHECKBOX" Name="cbInstLocalMachineStore" ID=cbInstLocalMachineStore><Label for=cbInstLocalMachineStore>Use local machine store</Label></Font></TD>
  308. </TR>
  309. </Table>
  310. <P>
  311. <!-- 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>
  312. <!-- 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>
  313. <Table width=100% border=0 cellpadding=0 cellspacing=0><TR><TD align=right>
  314. <INPUT type=Button id=btnInstall value="Install" style="width:.75in" OnClick="doInstall();return false;">
  315. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  316. </TD></TR></Table>
  317. </Span>
  318. <!-- #################### SCRIPTS #################### -->
  319. </Form>
  320. </Font>
  321. <Span id="spnIControl" style="display:none">
  322. <!-- XEnroll will be inserted here -->
  323. </Span>
  324. <!-- A DHTML alert box -->
  325. <Table border=0 cellspacing=0 cellpadding=0 ID="tblWorkingMsg" style="display:none; position:absolute;">
  326. <TR>
  327. <TD BgColor=#000040 height=3 colspan=3></TD>
  328. </TR> <TR>
  329. <TD BgColor=#000040 width=3></TD>
  330. <TD BgColor=#008080><font Color=#FFFFFF><B><BR>&nbsp;&nbsp;&nbsp;&nbsp;<Span ID="spnWorkingMsg"></Span>&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR></B></Font></TD>
  331. <TD BgColor=#000040 width=3></TD>
  332. </TR> <TR>
  333. <TD BgColor=#000040 height=3 colspan=3></TD>
  334. </TR>
  335. </Table>
  336. <Script Language=JavaScript>
  337. //================================================================
  338. // GLOBAL VARIABLES
  339. var g_bIControlReady=false; // true when XEnroll is loaded and ready to go
  340. // some constants defined in wincrypt.h:
  341. var CRYPT_EXPORTABLE=1;
  342. var CRYPT_USER_PROTECTED=2;
  343. var CRYPT_MACHINE_KEYSET=0x20;
  344. var AT_KEYEXCHANGE=1;
  345. var AT_SIGNATURE=2;
  346. var CERT_SYSTEM_STORE_LOCATION_SHIFT=16;
  347. var CERT_SYSTEM_STORE_LOCAL_MACHINE_ID=2;
  348. var CERT_SYSTEM_STORE_LOCAL_MACHINE=CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT;
  349. //================================================================
  350. // SCRIPTS COMMON TO ALL PAGES
  351. //----------------------------------------------------------------
  352. // reset the page to the begining
  353. function goHome() {
  354. spnPage1.style.display="";
  355. spnPage2.style.display="none";
  356. spnPage3.style.display="none";
  357. }
  358. //----------------------------------------------------------------
  359. // XEnroll only allows us to set the CSP once.
  360. // So, if something goes wrong in certificate creation,
  361. // we need a new XEnroll before we can try again
  362. // Thus, we use a script to reincarnate it.
  363. function recreateIControl() {
  364. g_bIControlReady=false;
  365. spnIControl.innerHTML="";
  366. spnIControl.innerHTML="<OBJECT"
  367. + " classid=\"clsid:43F8F289-7A20-11D0-8F06-00C04FC295E1\""
  368. //+ " codebase=\"/CertControl/xenroll.cab#Version=5,131,1837,1\""
  369. + " id=IControl"
  370. + "> </OBJECT>";
  371. g_bIControlReady=true;
  372. }
  373. //----------------------------------------------------------------
  374. // This contains the functions we want executed immediately after load completes
  375. function postLoad() {
  376. var nResult;
  377. // We're not ready to go yet
  378. g_bIControlReady=false;
  379. // Load an XEnroll object into the page
  380. recreateIControl();
  381. // get the CSP list
  382. showTransientMessage("Getting CSP list");
  383. setTimeout("postLoadPhase2();",1); } function postLoadPhase2() {
  384. nResult=GetCSPList();
  385. hideTransientMessage();
  386. if (0!=nResult) {
  387. handleLoadError(nResult, "CSP");
  388. return;
  389. }
  390. // enterprise stuff
  391. //< % If "StandAlone"<>sCSType And 0<>nWriteTemplateResult Then % >
  392. //handleLoadError(< % =nWriteTemplateResult % >, "certificate template");
  393. //< % End If % >
  394. // Now we're ready to go
  395. g_bIControlReady=true;
  396. }
  397. //----------------------------------------------------------------
  398. // handle errors from GetCSPList()
  399. function handleLoadError(nResult, sList) {
  400. if (-1==nResult) {
  401. alert("An unexpected error occurred while"
  402. +" getting the "+sList+" list:\nNo "+sList+"s could be found!");
  403. } else {
  404. alert("An unexpected error (0x"+toHex(nResult)+") occurred while"
  405. +" getting the "+sList+" list.");
  406. }
  407. document.UIForm.btnNext1.disabled=true;
  408. }
  409. //----------------------------------------------------------------
  410. // show the message in the status bar and in the middle of the screen
  411. function showTransientMessage(sMessage) {
  412. window.status=sMessage;
  413. spnWorkingMsg.innerText=sMessage;
  414. tblWorkingMsg.style.display='';
  415. tblWorkingMsg.style.pixelTop=
  416. (document.body.clientHeight/2)-(tblWorkingMsg.offsetHeight/2)+(document.body.scrollTop);
  417. //alert("w: d.b.cw:"+document.body.clientWidth+" m.ow:"+tblWorkingMsg.offsetWidth+" d.b.sl:"+document.body.scrollLeft);
  418. tblWorkingMsg.style.pixelLeft=
  419. (document.body.clientWidth/2)-(tblWorkingMsg.offsetWidth/2)+(document.body.scrollLeft);
  420. }
  421. //----------------------------------------------------------------
  422. // hide the message box
  423. function hideTransientMessage() {
  424. window.status="";
  425. tblWorkingMsg.style.display='none';
  426. }
  427. //----------------------------------------------------------------
  428. // throw up a confirmation dialog
  429. function myConfirm(sPrompt) {
  430. return confirm(sPrompt);
  431. }
  432. //================================================================
  433. // SCRIPTS FOR PAGE 1
  434. //----------------------------------------------------------------
  435. // this function is called from the first page to dispatch
  436. function goNext() {
  437. // make sure XEnroll is ready before continuing
  438. if (false==g_bIControlReady) {
  439. alert("This page has not finished loading yet. Please wait a few seconds and try again.");
  440. return;
  441. }
  442. // go to the page the user selected
  443. spnPage1.style.display="none";
  444. if (document.UIForm.rbgrpAction[0].checked) {
  445. spnPage2.style.display="";
  446. } else {
  447. spnPage3.style.display="";
  448. }
  449. }
  450. //================================================================
  451. // SCRIPTS FOR PAGE 2
  452. //----------------------------------------------------------------
  453. // Morph routine
  454. function handleUsageOID() {
  455. if ("other"==document.UIForm.lbUsageOID.options[document.UIForm.lbUsageOID.selectedIndex].value) {
  456. spnEKUOther1.style.display='';
  457. spnEKUOther2.style.display='';
  458. document.UIForm.lbUsageOID.blur();
  459. document.UIForm.tbEKUOther.select();
  460. document.UIForm.tbEKUOther.focus();
  461. } else {
  462. spnEKUOther1.style.display='none';
  463. spnEKUOther2.style.display='none';
  464. }
  465. }
  466. //----------------------------------------------------------------
  467. // Morph routine
  468. function handleSaveReq() {
  469. if (document.UIForm.cbSaveRequest.checked) {
  470. spnSaveRequest.style.display='';
  471. } else {
  472. spnSaveRequest.style.display='none';
  473. }
  474. }
  475. //----------------------------------------------------------------
  476. // Morph routine
  477. function handleMarkExport() {
  478. if (document.UIForm.cbMarkKeyExportable.checked) {
  479. spnMarkKeyExportable.style.display='';
  480. } else {
  481. spnMarkKeyExportable.style.display='none';
  482. }
  483. }
  484. //----------------------------------------------------------------
  485. // Morph routine
  486. function handleExportKeys() {
  487. if (document.UIForm.cbExportKeys.checked) {
  488. spnExportKeys.style.display='';
  489. } else {
  490. spnExportKeys.style.display='none';
  491. }
  492. }
  493. //----------------------------------------------------------------
  494. // Morph routine
  495. function handleKeyGen() {
  496. if (document.UIForm.rbKeyGen[0].checked) {
  497. spnNewKeys.style.display='';
  498. spnExistingKeys.style.display='none';
  499. } else {
  500. spnNewKeys.style.display='none';
  501. spnExistingKeys.style.display='';
  502. }
  503. }
  504. //----------------------------------------------------------------
  505. // Morph routine
  506. function handleSetContainer() {
  507. if (document.UIForm.cbSetContainer.checked) {
  508. spnNewContainer.style.display='';
  509. } else {
  510. spnNewContainer.style.display='none';
  511. }
  512. }
  513. //----------------------------------------------------------------
  514. // make sure the given string is valid
  515. function isValidX500String(sSource) {
  516. if (//""==sSource || //On advanced page, we allow blank entries
  517. -1!=sSource.indexOf(",",0) ||
  518. -1!=sSource.indexOf("\"",0) ||
  519. -1!=sSource.indexOf("+",0) ||
  520. -1!=sSource.indexOf(";",0)) {
  521. return false;
  522. } else {
  523. return true;
  524. }
  525. }
  526. //----------------------------------------------------------------
  527. // check for invalid characters and empty strings
  528. function isValidIA5String(sSource) {
  529. var nIndex;
  530. for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  531. if (sSource.charCodeAt(nIndex)>127) { // NOTE: this is better, but not compatible with old browsers.
  532. return false;
  533. }
  534. };
  535. return true;
  536. }
  537. //----------------------------------------------------------------
  538. // check for invalid characters
  539. function isValidCountryField(tbCountry) {
  540. tbCountry.value=tbCountry.value.toUpperCase();
  541. var sSource=tbCountry.value;
  542. var nIndex, ch;
  543. if (sSource.length!=2 && sSource.length!=0) {
  544. return false;
  545. }
  546. for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  547. ch=sSource.charAt(nIndex)
  548. if (ch<"A" || ch>"Z") {
  549. return false;
  550. }
  551. };
  552. return true;
  553. }
  554. //----------------------------------------------------------------
  555. // set a label to normal style
  556. function markLabelNormal(spn) {
  557. spn.style.color="#000000";
  558. spn.style.fontWeight='normal';
  559. }
  560. //----------------------------------------------------------------
  561. // set a label to error state
  562. function markLabelError(spn) {
  563. spn.style.color='#FF0000';
  564. spn.style.fontWeight='bold';
  565. }
  566. //----------------------------------------------------------------
  567. // check that the form has data in it
  568. function validateRequest() {
  569. markLabelNormal(spnNameLabel);
  570. markLabelNormal(spnEmailLabel);
  571. markLabelNormal(spnCompanyLabel);
  572. markLabelNormal(spnDepartmentLabel);
  573. markLabelNormal(spnCityLabel);
  574. markLabelNormal(spnStateLabel);
  575. markLabelNormal(spnCountryLabel);
  576. var bOK=true;
  577. var fldFocusMe=null;
  578. // check in 'reverse' order so that focus gets set to last item
  579. // don't set focus immediately because we'd get funny scrolling effects.
  580. if (false==isValidCountryField(document.UIForm.tbCountry)) {
  581. bOK=false;
  582. fldFocusMe=document.UIForm.tbCountry;
  583. markLabelError(spnCountryLabel);
  584. }
  585. if (false==isValidX500String(document.UIForm.tbState.value)) {
  586. bOK=false;
  587. fldFocusMe=document.UIForm.tbState;
  588. markLabelError(spnStateLabel);
  589. }
  590. if (false==isValidX500String(document.UIForm.tbLocality.value)) {
  591. bOK=false;
  592. fldFocusMe=document.UIForm.tbLocality;
  593. markLabelError(spnCityLabel);
  594. }
  595. if (false==isValidX500String(document.UIForm.tbOrgUnit.value)) {
  596. bOK=false;
  597. fldFocusMe=document.UIForm.tbOrgUnit;
  598. markLabelError(spnDepartmentLabel);
  599. }
  600. if (false==isValidX500String(document.UIForm.tbOrg.value)) {
  601. bOK=false;
  602. fldFocusMe=document.UIForm.tbOrg;
  603. markLabelError(spnCompanyLabel);
  604. }
  605. if (false==isValidX500String(document.UIForm.tbEmail.value) || false==isValidIA5String(document.UIForm.tbEmail.value)) {
  606. bOK=false;
  607. fldFocusMe=document.UIForm.tbEmail;
  608. markLabelError(spnEmailLabel);
  609. }
  610. if (false==isValidX500String(document.UIForm.tbCommonName.value)) {
  611. bOK=false;
  612. fldFocusMe=document.UIForm.tbCommonName;
  613. markLabelError(spnNameLabel);
  614. }
  615. if (false==bOK) {
  616. spnFixTxt.style.display='';
  617. window.scrollTo(0,0);
  618. fldFocusMe.focus();
  619. }
  620. // validity check on the key size
  621. if (true==bOK) {
  622. var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  623. var sMessage;
  624. if (isNaN(nKeySize)) {
  625. sMessage="Please enter a number for the key size.";
  626. bOK=false;
  627. } else if (nKeySize<512 || nKeySize>4096) {
  628. sMessage="Please enter a valid number for the key size. The key size must be between 512 and 4096.";
  629. bOK=false;
  630. }
  631. if (false==bOK) {
  632. alert (sMessage);
  633. document.UIForm.tbKeySize.focus();
  634. }
  635. }
  636. // Check the container name
  637. if (true==bOK) {
  638. if (document.UIForm.rbKeyGen[0].checked) {
  639. // new keyset
  640. if (document.UIForm.cbSetContainer.checked) {
  641. if (""==document.UIForm.tbNewContainerName.value) {
  642. bOK=false;
  643. }
  644. }
  645. } else {
  646. // existing keyset
  647. if (""==document.UIForm.tbOldContainerName.value) {
  648. bOK=false;
  649. }
  650. }
  651. if (false==bOK) {
  652. alert ("Please enter a key container name.");
  653. if (document.UIForm.rbKeyGen[0].checked) {
  654. document.UIForm.tbNewContainerName.focus();
  655. } else {
  656. document.UIForm.tbOldContainerName.focus();
  657. }
  658. }
  659. }
  660. // validity check on the file name
  661. if (true==bOK) {
  662. if (""==document.UIForm.tbFileName.value) {
  663. alert ("Please enter a file name.");
  664. document.UIForm.tbFileName.focus();
  665. bOK=false;
  666. }
  667. }
  668. return bOK;
  669. }
  670. //----------------------------------------------------------------
  671. function generateRequest() {
  672. // check that the form is filled in
  673. spnErrorTxt.style.display='none';
  674. spnFixTxt.style.display='none';
  675. if (false==validateRequest()) {
  676. return;
  677. }
  678. // show a nice message since request creation can take a while
  679. showTransientMessage("Generating Request...");
  680. // Make the message show up on the screen,
  681. // then continue with 'generateRequest':
  682. // Pause 1 mS before executing phase 2,
  683. // so screen will have time to repaint.
  684. setTimeout("generateRequestPhase2();",1); } function generateRequestPhase2() {
  685. // set the identifying info
  686. var sDistinguishedName=""
  687. + "C="+document.UIForm.tbCountry.value +";"
  688. + "S="+document.UIForm.tbState.value +";"
  689. + "L="+document.UIForm.tbLocality.value +";"
  690. + "O="+document.UIForm.tbOrg.value +";"
  691. +"OU="+document.UIForm.tbOrgUnit.value +";"
  692. + "E="+document.UIForm.tbEmail.value +";"
  693. +"CN="+document.UIForm.tbCommonName.value+";";
  694. //
  695. // Stand-Alone Options
  696. //
  697. // set the extended key usage and certificate request 'friendly type'
  698. var nUsageIndex=document.UIForm.lbUsageOID.selectedIndex;
  699. var sCertUsage;
  700. if ("other"==document.UIForm.lbUsageOID.options[nUsageIndex].value) {
  701. sCertUsage=document.UIForm.tbEKUOther.value;
  702. } else {
  703. sCertUsage=document.UIForm.lbUsageOID.options[nUsageIndex].value;
  704. }
  705. //
  706. // Enterprise Options
  707. //
  708. // get the selected template
  709. //var nTemplateIndex=document.UIForm.lbCertTemplate.selectedIndex;
  710. //var sTemplate=document.UIForm.lbCertTemplate.options[nTemplateIndex].value;
  711. // extract the template type (the first char)
  712. // X-bad, U-user, M-machine
  713. //var sTemplateType=sTemplate.substring(0,1);
  714. //sTemplate=sTemplate.slice(1);
  715. // set the cert template
  716. //IControl.addCertTypeToRequest(sTemplate);
  717. //var sCertUsage=""; // ignored
  718. //
  719. // CSP Options subheading:
  720. //
  721. // set the CSP
  722. var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  723. IControl.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  724. IControl.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  725. // set the key size (the upper 16 bits of GenKeyFlags)
  726. // note: this value has already been validated
  727. var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  728. IControl.GenKeyFlags=nKeySize<<16;
  729. // set the KeySpec
  730. if (document.UIForm.rbKeySpec[0].checked) {
  731. IControl.KeySpec=AT_KEYEXCHANGE;
  732. } else {
  733. IControl.KeySpec=AT_SIGNATURE;
  734. }
  735. // set the hash algorithm
  736. var nHashIndex=document.UIForm.lbHashAlgorithm.selectedIndex;
  737. IControl.HashAlgorithm=document.UIForm.lbHashAlgorithm.options[nHashIndex].value;
  738. //
  739. // Key Generation Options subheading:
  740. //
  741. // set the 'use existing key set' flag
  742. if (document.UIForm.rbKeyGen[0].checked) {
  743. IControl.UseExistingKeySet=false;
  744. if (document.UIForm.cbSetContainer.checked) {
  745. IControl.ContainerName=document.UIForm.tbNewContainerName.value;
  746. }
  747. } else {
  748. IControl.UseExistingKeySet=true;
  749. IControl.ContainerName=document.UIForm.tbOldContainerName.value;
  750. }
  751. // set 'Strong private key protection'
  752. // note: upper 16 bits already set as key size
  753. if (document.UIForm.cbStrongKey.checked) {
  754. IControl.GenKeyFlags|=CRYPT_USER_PROTECTED;
  755. }
  756. // mark the keys as exportable
  757. if (document.UIForm.cbMarkKeyExportable.checked) {
  758. IControl.GenKeyFlags|=CRYPT_EXPORTABLE;
  759. // set the key export file (.pvk)
  760. if (document.UIForm.cbExportKeys.checked) {
  761. IControl.PVKFileName=document.UIForm.tbExportKeyFile.value;
  762. }
  763. }
  764. // place the keys in the local machine store
  765. if (document.UIForm.cbLocalMachineStore.checked) {
  766. // the keys attached to the dummy request cert go in the local machine store
  767. IControl.RequestStoreFlags=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  768. // used in CryptAcquireContext
  769. IControl.ProviderFlags=CRYPT_MACHINE_KEYSET;
  770. }
  771. //
  772. // Additional Options subheading:
  773. // File Name subheading:
  774. //
  775. // get any extra attributes
  776. var sAttrib=document.UIForm.taAttrib.value;
  777. // get the file name
  778. var sFileName=document.UIForm.tbFileName.value;
  779. //
  780. // Build and save the certificate request
  781. //
  782. // build and save the certificate request
  783. // ask VB to do it, since it can handle errors
  784. nResult=CreateAndSaveRequest(sDistinguishedName, sCertUsage, sAttrib, sFileName);
  785. // hide the message box
  786. hideTransientMessage();
  787. // deal with an error if there was one
  788. if (0!=nResult) {
  789. handleError(nResult);
  790. } else {
  791. alert("The request was generated and saved.");
  792. goHome();
  793. }
  794. // reincarnate XEnroll
  795. recreateIControl();
  796. }
  797. //----------------------------------------------------------------
  798. function handleError(nResult) {
  799. var sSugCause="No suggestion.";
  800. var sErrorName="(unknown)";
  801. // analyze the error - funny use of XOR ('^') because obvious choice '==' doesn't work
  802. if (0==(0x80090008^nResult)) {
  803. sErrorName="NTE_BAD_ALGID";
  804. sSugCause="The CSP you chose was unable to process the request. Try a different CSP.";
  805. } else if (0==(0x80090016^nResult)) {
  806. sErrorName="NTE_BAD_KEYSET";
  807. if (document.UIForm.rbKeyGen[0].checked) {
  808. sSugCause="The CSP you chose was unable to process the request. Try a different CSP.";
  809. } else {
  810. sSugCause="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.";
  811. }
  812. } else if (0==(0x80090019^nResult)) {
  813. sErrorName="NTE_KEYSET_NOT_DEF";
  814. sSugCause="The CSP you chose was unable to process the request. Try a different CSP.";
  815. } else if (0==(0x80090020^nResult)) {
  816. sErrorName="NTE_FAIL";
  817. sSugCause="The CSP you chose was unable to process the request. Try a different CSP.";
  818. } else if (0==(0x80090009^nResult)) {
  819. sErrorName="NTE_BAD_FLAGS";
  820. sSugCause="The CSP you chose does not support one or more of the settings"
  821. + " you have made, such as key size, key spec, hash algorithm, etc."
  822. + " Try using different settings or a different CSP.";
  823. } else if (0==(0x8009000F^nResult)) {
  824. sErrorName="NTE_EXISTS";
  825. sSugCause="The container you named already exists. When creating a new key,"
  826. + " you must use a new container name.";
  827. } else if (0==(0x80092002^nResult)) {
  828. sErrorName="CRYPT_E_BAD_ENCODE";
  829. //sSugCause="";
  830. } else if (0==(0x80092022^nResult)) {
  831. sErrorName="CRYPT_E_INVALID_IA5_STRING";
  832. sSugCause="You entered an invalid character. Report a bug, because this"
  833. + " should have been caught in validation.";
  834. } else if (0==(0x80092023^nResult)) {
  835. sErrorName="CRYPT_E_INVALID_X500_STRING";
  836. sSugCause="You entered an invalid character. Report a bug, because this"
  837. + " should have been caught in validation.";
  838. } else if (0==(0x80070003^nResult)) {
  839. sErrorName="ERROR_PATH_NOT_FOUND";
  840. sSugCause="The file name you entered is invalid.";
  841. } else if (0==(0x8000FFFF^nResult)) {
  842. sErrorName="E_UNEXPECTED";
  843. } else if (58==nResult) {
  844. sErrorName="File already exists";
  845. sSugCause="The file already exists and you chose not to overwrite it. The certificate was not saved.";
  846. }
  847. // modify the document text and appearance to show the error message
  848. spnErrorNum.innerText="0x"+toHex(nResult)+" - "+sErrorName;
  849. spnErrorMsg.innerText=sSugCause;
  850. spnErrorTxt.style.display='';
  851. // back to the top so the messages show
  852. window.scrollTo(0,0);
  853. }
  854. //================================================================
  855. // SCRIPTS FOR PAGE 3
  856. //----------------------------------------------------------------
  857. function BeginRead() {
  858. spRead.style.display='';
  859. document.UIForm.flRequest.focus()
  860. }
  861. //----------------------------------------------------------------
  862. function FinishRead() {
  863. if (""==document.UIForm.flRequest.value) {
  864. handleReadError(5);
  865. return;
  866. }
  867. var nResult=GetFileData(); // use VBScript to read the file, since it can handle errors
  868. if (0!=nResult) {
  869. handleReadError(nResult);
  870. return;
  871. }
  872. spRead.style.display='none';
  873. document.UIForm.btnInstall.focus()
  874. }
  875. //----------------------------------------------------------------
  876. function handleReadError(nResult) {
  877. var sMessage="An unexpected error occured.";
  878. var sErrorName="(unknown)";
  879. var elemFocusMe=null;
  880. if (429==nResult) {
  881. sMessage="Your web browser security settings prohibit this page"
  882. + "from accessing your disk. The file cannot be read.\n"
  883. + "Possible solutions:\n"
  884. + " - Paste the data in yourself.\n"
  885. + " - Add this page to your browser's list of trusted sites.";
  886. sErrorName="ActiveX component can't create object"
  887. elemFocusMe=document.UIForm.flRequest;
  888. } else if (53==nResult) {
  889. sMessage="The file you specified was not found. Please enter a valid file name.";
  890. sErrorName="File not found"
  891. elemFocusMe=document.UIForm.flRequest;
  892. } else if (5==nResult) {
  893. sMessage="Please enter a file name.";
  894. sErrorName="Invalid argument"
  895. elemFocusMe=document.UIForm.flRequest;
  896. } else if (0!=nResult) {
  897. sMessage="An unexpected error occurred while trying to read the file.\n\nError: "+nResult;
  898. }
  899. alert(sMessage);
  900. // place focus on offending control
  901. if (null!=elemFocusMe) {
  902. elemFocusMe.focus();
  903. }
  904. }
  905. //----------------------------------------------------------------
  906. function doInstall() {
  907. // get the cert, and make sure it's not empty
  908. var sPKCS7=document.UIForm.taInstallCert.value;
  909. if (""==sPKCS7) {
  910. alert("Please place a base64-encoded certificate in the field.");
  911. return;
  912. }
  913. // check for the begin/end tags
  914. if (-1==sPKCS7.indexOf("-----BEGIN CERTIFICATE-----") ||
  915. -1==sPKCS7.indexOf("-----END CERTIFICATE-----")) {
  916. if (false==confirm("The PKCS #7 certificate should contain\na 'BEGIN' and"
  917. +" an 'END' tag, but it does not.\n\n"
  918. +"Are you sure you want to install this certificate?")) {
  919. return;
  920. }
  921. }
  922. // place the keys in the local machine store?
  923. if (document.UIForm.cbInstLocalMachineStore.checked) {
  924. // the keys attached to the final cert also go in the local machine store
  925. IControl.MyStoreFlags=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  926. IControl.RequestStoreFlags=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  927. }
  928. // install the cert
  929. var nResult=InstallCert(sPKCS7);
  930. // check for errors
  931. if(0==nResult) {
  932. alert("Your new certificate has been successfully installed.");
  933. goHome();
  934. } else {
  935. var sMessage="Unable to install the certificate:\n"
  936. +"Please verify that your CSP supports any settings you have made "
  937. +"and that your input is valid.\n\n"
  938. +"Error: 0x"+toHex(nResult);
  939. // funny use of XOR ('^') because obvious choice '==' doesn't work
  940. if (0==(0x80092004^nResult)) {
  941. sMessage="Unable to install the certificate:\n"
  942. +"The system could not find the keyset associated with this certificate."
  943. +" This cert may have already been installed,"
  944. +" or the keyset may be in a different store from the one you selected.\n\n"
  945. +"Error: 0x80092004 - CRYPT_E_NOT_FOUND";
  946. }
  947. alert(sMessage);
  948. }
  949. // reincarnate XEnroll
  950. recreateIControl();
  951. }
  952. </Script>
  953. <Script Language=VBScript>
  954. Option Explicit
  955. '/================================================================
  956. '/ SCRIPTS COMMON TO ALL PAGES
  957. '/----------------------------------------------------------------
  958. '/ Get the list of CSPs from XEnroll
  959. '/ returns error number
  960. '/ assumes XEnroll is named 'IControl' and the list box is 'document.UIForm.lbCSP'
  961. Function GetCSPList()
  962. On Error Resume Next
  963. Dim nProvType, nOrigProvType, nTotCSPs, nDefaultCSP
  964. Const nMaxProvType=25 ' should be >= the number of providers defined in wincrypt.h (~line 431)
  965. nTotCSPs=0
  966. nDefaultCSP=-1
  967. ' save the original provider type
  968. nOrigProvType=IControl.ProviderType
  969. If 0<>Err.number Then
  970. ' something wrong with IControl
  971. GetCSPList=Err.Number
  972. Exit Function
  973. End If
  974. ' enumerate through each of the provider types
  975. For nProvType=0 To nMaxProvType
  976. Dim nCSPIndex
  977. nCSPIndex=0
  978. IControl.ProviderType=nProvType
  979. ' enumerate through each of the providers for this type
  980. Do
  981. Dim sProviderName
  982. 'get the name
  983. sProviderName=IControl.enumProviders(nCSPIndex, 0)
  984. If &H80070103=Err.number Then
  985. ' no more providers
  986. Err.Clear
  987. Exit Do
  988. End If
  989. ' For each provider, add an element to the list box.
  990. Dim oOption
  991. Set oOption=document.createElement("OPTION")
  992. oOption.text=sProviderName
  993. oOption.Value=nProvType
  994. document.UIForm.lbCSP.add(oOption)
  995. If InStr(sProviderName, "Microsoft Base Cryptographic Provider") <> 0 Then
  996. oOption.selected=True
  997. nDefaultCSP=nTotCSPs
  998. End If
  999. nTotCSPs=nTotCSPs+1
  1000. ' get the next provider
  1001. nCSPIndex=nCSPIndex+1
  1002. Loop
  1003. Next
  1004. ' if there are no CSPs, we're kinda stuck
  1005. If 0=nTotCSPs Then
  1006. Set oElement=document.createElement("OPTION")
  1007. oElement.text="(no CSPs found)"
  1008. document.UIForm.lbCSP.Options.Add oElement
  1009. End If
  1010. ' remove the 'loading' text
  1011. document.UIForm.lbCSP.remove(0)
  1012. ' select the default provider
  1013. If -1<>nDefaultCSP Then
  1014. document.UIForm.lbCSP.selectedIndex=nDefaultCSP
  1015. End If
  1016. ' restore the original provider type
  1017. IControl.ProviderType=nOrigProvType
  1018. ' set the return value and exit
  1019. If 0<>Err.Number Then
  1020. GetCSPList=Err.Number
  1021. ElseIf 0=nTotCSPs Then
  1022. ' signal no elements with -1
  1023. GetCSPList=-1
  1024. Else
  1025. GetCSPList=0
  1026. End If
  1027. End Function
  1028. '/----------------------------------------------------------------
  1029. '/ Convert a number to a hex string (JavaScript doesn't have this)
  1030. Function toHex(number)
  1031. toHex=Hex(number)
  1032. End Function
  1033. '/================================================================
  1034. '/ SCRIPTS FOR PAGE 2
  1035. '/----------------------------------------------------------------
  1036. Function CreateRequest(sDistinguishedName, sCertUsage)
  1037. On Error Resume Next
  1038. document.SubmittedData.CertRequest.value = _
  1039. IControl.CreatePKCS10(sDistinguishedName, sCertUsage)
  1040. CreateRequest=Err.number
  1041. End Function
  1042. '/----------------------------------------------------------------
  1043. Function CreateAndSaveRequest(sDistinguishedName, sCertUsage, sAttrib, sFileName)
  1044. On Error Resume Next
  1045. Dim sPKCS10
  1046. ' first, create the PKCS10
  1047. sPKCS10=IControl.CreatePKCS10(sDistinguishedName, sCertUsage)
  1048. If 0<>Err.Number Then
  1049. CreateAndSaveRequest=Err.number
  1050. Exit Function
  1051. End If
  1052. ' prepend the attribs and wrap in begin/end tags
  1053. sPKCS10=sAttrib & vbNewLine & "-----BEGIN NEW CERTIFICATE REQUEST-----" & vbNewLine & _
  1054. sPKCS10 & "-----END NEW CERTIFICATE REQUEST-----" & vbNewLine
  1055. showTransientMessage("Saving request...")
  1056. ' save the file
  1057. CreateAndSaveRequest=WriteFileData(sFileName, sPKCS10)
  1058. If 0<>Err.Number Then
  1059. CreateAndSaveRequest=Err.number
  1060. End If
  1061. End Function
  1062. '/----------------------------------------------------------------
  1063. '/ Write the give strign to the given file,
  1064. '/ prompting to overwrite if necessary
  1065. Function WriteFileData(sFileName, sData)
  1066. Dim filesystem, file
  1067. On Error Resume Next
  1068. ' First, create the FileSystem object
  1069. Set filesystem = CreateObject("Scripting.FileSystemObject")
  1070. ' Security may not allow this
  1071. If Err.number<>0 Then
  1072. WriteFileData=Err.number
  1073. Exit Function
  1074. End If
  1075. ' check for existing file
  1076. Dim bExists
  1077. bExists=filesystem.FileExists(sFileName)
  1078. If 0<>Err.Number Then
  1079. WriteFileData=Err.number
  1080. Exit Function
  1081. End If
  1082. If True=bExists Then
  1083. 'file exists. Overwrite?
  1084. If False=myConfirm("The file '" & sFileName & "' already exists. Overwrite?") Then
  1085. WriteFileData=58 'File Already Exists
  1086. Exit Function
  1087. End If
  1088. End If
  1089. ' open the specified file
  1090. Set file=filesystem.OpenTextFile(sFileName, 2, true) '2->ForWriting, true->create
  1091. If Err.Number<>0 Then
  1092. WriteFileData=Err.number
  1093. Exit Function
  1094. End If
  1095. ' read the data and stash it into the form
  1096. file.Write sData
  1097. ' catch any read errors
  1098. If Err.Number<>0 Then
  1099. WriteFileData=Err.number
  1100. Exit Function
  1101. End If
  1102. ' clean up
  1103. file.Close
  1104. Set file=Nothing
  1105. Set filesystem=Nothing
  1106. WriteFileData=0
  1107. End Function
  1108. '/================================================================
  1109. '/ SCRIPTS FOR PAGE 3
  1110. '/----------------------------------------------------------------
  1111. '/ Read the data from the file listed in UIForm.flRequest and place
  1112. '/ it in UIForm.taInstallCert
  1113. Function GetFileData()
  1114. Dim filesystem, file
  1115. On Error Resume Next
  1116. ' First, create the FileSystem object
  1117. Set filesystem = CreateObject("Scripting.FileSystemObject")
  1118. ' Security may not allow this
  1119. If Err.number<>0 Then
  1120. GetFileData=Err.number
  1121. Exit Function
  1122. End If
  1123. ' open the specified file
  1124. Set file=filesystem.OpenTextFile(document.UIForm.flRequest.value, 1 , false) '1->ForReading, false->don't create
  1125. ' file may not exist
  1126. If Err.number<>0 Then
  1127. GetFileData=Err.number
  1128. Exit Function
  1129. End If
  1130. ' read the data and stash it into the form
  1131. document.UIForm.taInstallCert.value=file.ReadAll
  1132. ' catch any read errors
  1133. If Err.number<>0 Then
  1134. GetFileData=Err.number
  1135. Exit Function
  1136. End If
  1137. ' clean up
  1138. file.Close
  1139. Set file=Nothing
  1140. Set filesystem=Nothing
  1141. GetFileData=0
  1142. End Function
  1143. '/----------------------------------------------------------------
  1144. '/ Call XEnroll to install the given cert
  1145. Function InstallCert(sPKCS7)
  1146. On Error Resume Next
  1147. IControl.AcceptPKCS7(sPKCS7)
  1148. InstallCert=Err.Number
  1149. End Function
  1150. </SCRIPT>
  1151. </Script>
  1152. <!-- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ -->
  1153. </Body>
  1154. </HTML>