home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 July / PCWorld_2001-07_cd.bin / Software / Topware / w2ksp2en / w2ksp2.exe / i386 / certrqma.as_ / certrqma.asp
Encoding:
Text File  |  2001-05-04  |  44.0 KB  |  1,172 lines

  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. <HTML>
  7. <Head>
  8.     <Meta HTTP-Equiv="Content-Type" Content="text/html; charset=UTF-8">
  9.     <Title>Microsoft Certificate Services</Title>
  10. </Head>
  11. <Body BgColor=#FFFFFF OnLoad="postLoad();"><Font ID=locPageFont Face="Arial">
  12.  
  13. <Table Border=0 CellSpacing=0 CellPadding=4 Width=100% BgColor=#008080>
  14. <TR>
  15.     <TD><Font Color=#FFFFFF><LocID ID=locMSCertSrv><Font Face="Arial" Size=-1><B><I>Microsoft</I></B> Certificate Services  --  <%=sServerDisplayName%>  </Font></LocID></Font></TD>
  16.     <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>
  17. </TR>
  18. </Table>
  19.  
  20. <Form Name=UIForm OnSubmit="goNext();return false;" Action="certlynx.asp" Method=Post>
  21. <Input Type=Hidden Name=SourcePage Value="certrqma">
  22.  
  23. <P ID=locPageTitle> <B> Advanced Certificate Request </B>
  24. <!-- 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>
  25.  
  26. <Span ID=spnFixTxt Style="display:none">
  27.     <Table Border=0 CellSpacing=0 CellPadding=4 Style="Color:#FF0000"><TR><TD ID=locBadCharError>
  28.         <I>Please correct the fields marked in <B>RED</B>.</I>
  29.         No field may contain the characters (, ; " +).
  30.         The e-mail address may contain the characters A-Z, a-z, 0-9, and some common symbols, but no extended characters.
  31.         The country/region field must be a two letter ISO 3166 country/region code.
  32.     </TD></TR></Table>
  33. </Span>
  34. <Span ID=spnErrorTxt Style="display:none">
  35.     <Table Border=0 CellSpacing=0 CellPadding=4 Style="Color:#FF0000">
  36.     <TR><TD ID=locErrMsgBasic>
  37.         <B>An error occurred</B> while creating the certificate request. 
  38.         Please verify that your CSP supports any settings you have made 
  39.         and that your input is valid.
  40.     </TD></TR><TR><TD>
  41.         <LocID ID=locErrorCause><B>Suggested cause:</B></LocID><BR>
  42.         <Span ID=spnErrorMsg></Span>
  43.     </TD></TR><TR>
  44.         <TD ID=locErrorNumber><Font Size=-2>Error: <Span ID=spnErrorNum></Span></Font></TD>
  45.     </TR>
  46.     </Table>
  47. </Span>
  48.  
  49.  
  50. <Table Border=0 CellSpacing=0 CellPadding=0>
  51.     <TR> <!-- establish column widths. -->
  52.         <TD Width=<%=L_LabelColWidth_Number%>></TD> <!-- label column, top border -->
  53.         <TD RowSpan=59 Width=4></TD>                <!-- label spacing column -->
  54.         <TD></TD>                                   <!-- field column -->
  55.     </TR>
  56.     
  57. <%If "Enterprise"=sServerType Then%>    <!-- Enterprise Options -->
  58.  
  59.     <TR>
  60.         <TD ID=locTemplateHead ColSpan=3><Font Size=-1><BR><B>Certificate Template:</B></Font></TD>
  61.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  62.     </TR><TR><TD ColSpan=3 Height=6></TD>
  63.     </TR><TR><TD></TD>
  64.         <TD><Select Name=lbCertTemplate OnChange="handleTemplateChange();">
  65. <%
  66.     Dim nWriteTemplateResult
  67.     nWriteTemplateResult=WriteTemplateList() 
  68. %>
  69.         </Select></TD>
  70.     </TR>
  71.  
  72.     <TR><TD ColSpan=3>
  73. <Span ID=spnIDInfo Style="display:none">
  74. <Table Border=0 CellSpacing=0 CellPadding=0>
  75.     <TR> <!-- establish column widths. -->
  76.         <TD Width=<%=L_LabelColWidth_Number%>></TD> <!-- label column, top border -->
  77.         <TD RowSpan=59 Width=4></TD>                <!-- label spacing column -->
  78.         <TD></TD>                                   <!-- field column -->
  79.     </TR>
  80. <%End If '"Enterprise"=sServerType%>
  81.  
  82.     <TR>
  83. <%If "StandAlone"=sServerType Then%>
  84.         <TD ID=locIdentHeadStandAlone ColSpan=3><Font Size=-1><BR><B>Identifying Information:</B></Font></TD>
  85.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  86. <%Else%>
  87.         <TD ID=locIdentHeadEnterprise ColSpan=3><Font Size=-1><BR><B>Identifying Information For Offline Template:</B></Font></TD>
  88.     </TR><!--<TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>-->
  89. <%End If%>
  90.     </TR><TR><TD ColSpan=3 Height=6></TD>
  91.     </TR><TR>
  92.         <TD ID=locNameAlign Align=Right><Span ID=spnNameLabel><LocID ID=locNameLabel><Font Size=-1>Name:</Font></LocID></Span></TD>
  93.         <TD><Input ID=locTbCommonName Type=Text MaxLength=64 Size=42 Name=tbCommonName></TD>
  94.     </TR><TR>
  95.         <TD ID=locEmailAlign Align=Right><Span ID=spnEmailLabel><LocID ID=locEmailLabel><Font Size=-1>E-Mail:</Font></LocID></Span></TD>
  96.         <TD><Input ID=locTbEmail Type=Text MaxLength=128 Size=42 Name=tbEmail></TD>
  97.     </TR><TR>
  98.         <TD Height=8></TD> <TD></TD>
  99.     </TR><TR>
  100.         <TD ID=locCompanyAlign Align=Right><Span ID=spnCompanyLabel><LocID ID=locOrgLabel><Font Size=-1>Company:</Font></LocID></Span></TD>
  101.         <TD><Input ID=locTbOrg Type=Text MaxLength=64 Size=42 Name=tbOrg Value="<%=sDefaultCompany%>"></TD>
  102.     </TR><TR>
  103.         <TD ID=locDepartmentAlign Align=Right><Span ID=spnDepartmentLabel><LocID ID=locOrgUnitLabel><Font Size=-1>Department:</Font></LocID></Span></TD>
  104.         <TD><Input ID=locTbOrgUnit Type=Text MaxLength=64 Size=42 Name=tbOrgUnit Value="<%=sDefaultOrgUnit%>"></TD>
  105.     </TR><TR>
  106.         <TD Height=8></TD> <TD></TD>
  107.     </TR><TR>
  108.         <TD ID=locCityAlign Align=Right><Span ID=spnCityLabel><LocID ID=locLocalityLabel><Font Size=-1>City:</Font></LocID></Span></TD>
  109.         <TD><Input ID=locTbLocality Type=Text MaxLength=128 Size=42 Name=tbLocality Value="<%=sDefaultLocality%>"></TD>
  110.     </TR><TR>
  111.         <TD ID=locStateAlign Align=Right><Span ID=spnStateLabel><LocID ID=locStateLabel><Font Size=-1>State:</Font></LocID></Span></TD>
  112.         <TD><Input ID=locTbState Type=Text MaxLength=128 Size=42 Name=tbState Value="<%=sDefaultState%>"></TD>
  113.     </TR><TR>
  114.         <TD ID=locCountryAlign Align=Right><Span ID=spnCountryLabel><LocID ID=locCountryLabel><Font Size=-1>Country/Region:</Font></LocID></Span></TD>
  115.         <TD><Input ID=locTbCountry Type=Text MaxLength=2 Size=2 Name=tbCountry Value="<%=sDefaultCountry%>"></TD> 
  116.     </TR>
  117.  
  118. <%If "Enterprise"=sServerType Then%>
  119. </Table>
  120. </Span>
  121.     </TD></TR>
  122. <%End If '"Enterprise"=sServerType%>
  123. <%If "StandAlone"=sServerType Then%> <!-- Stand-Alone Options -->
  124.  
  125.     <TR>
  126.         <TD ID=locEKUHead ColSpan=3><Font Size=-1><BR><B>Intended Purpose:</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=lbUsageOID OnChange="handleUsageOID();">
  131.             <Option ID=locCliAuthCert Selected Value="1.3.6.1.5.5.7.3.2"> Client Authentication Certificate
  132.             <Option ID=locEmailCert   Value="1.3.6.1.5.5.7.3.4"> E-Mail Protection Certificate
  133.             <Option ID=locSrvAuthCert Value="1.3.6.1.5.5.7.3.1"> Server Authentication Certificate
  134.             <Option ID=locCodeSgnCert Value="1.3.6.1.5.5.7.3.3"> Code Signing Certificate
  135.             <Option ID=locTimStmpCert Value="1.3.6.1.5.5.7.3.8"> Time Stamp Signing Certificate
  136.             <Option ID=locIPSecCert   Value="1.3.6.1.5.5.8.2.2"> IPSec Certificate
  137.             <Option ID=locUserEKUCert Value="**"> Other...
  138.         </Select></TD>
  139.     </TR>
  140.  
  141.     <TR><TD ID=locEkuAlign Align=Right><Span ID=spnEKUOther1 Style="display:none"><LocID ID=locUserEKULabel><Font Size=-1>OID:</Font></LocID></Span></TD>
  142.         <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>
  143.     </TR>
  144.  
  145. <%End If%> <!-- common -->
  146.  
  147.     <TR>
  148.         <TD ID=locKeyOptHead ColSpan=3><Font Size=-1><BR><B>Key Options:</B></Font></TD>
  149.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  150.     </TR><TR><TD ColSpan=3 Height=6></TD>
  151.     </TR>
  152.  
  153.     <TR>
  154.         <TD ID=locCSPLabel Align=Right><Font Size=-1>CSP:</Font></TD>
  155.         <TD><Select Name=lbCSP OnChange="handleCSPChange();">
  156.             <Option ID=locLoading>Loading...</Option>
  157.         </Select></TD>
  158.     </TR>
  159.  
  160.     <TR><TD ColSpan=3 Height=4></TD></TR>
  161.     <TR>
  162.         <TD ID=locKeyUsageLabel Align=Right><Font Size=-1>Key Usage:</Font></TD>
  163.         <TD><Font Size=-1>
  164.             <Span ID=spnKeyUsageKeyExchange><Input Type=Radio ID=rbKU1 Name=rbKeyUsage Value="0" Checked OnClick="handleKeyUsageChange();"><Label For=rbKU1 ID=locKUExch>Exchange</Label><LocID ID=locSpc1>   <LocID></Span>
  165.             <Span ID=spnKeyUsageSignature><Input Type=Radio ID=rbKU2 Name=rbKeyUsage Value="1" OnClick="handleKeyUsageChange();"><Label For=rbKU2 ID=locKUSig>Signature</Label><LocID ID=locSpc2>   <LocID></Span>
  166.             <Span ID=spnKeyUsageBoth><Input Type=Radio ID=rbKU3 Name=rbKeyUsage Value="2" OnClick="handleKeyUsageChange();"><Label For=rbKU3 ID=locKUBoth>Both</Label></Span></Font></TD>
  167.     </TR>
  168.  
  169.     <TR><TD ColSpan=3 Height=4></TD></TR>
  170.     <TR>
  171.         <TD ID=locKeySizeLabel Align=Right ><Font Size=-1>Key Size:</Font></TD>
  172.         <TD><Table Border=0 CellPadding=0 CellSpacing=0>
  173.             <TR>
  174.                 <TD RowSpan=2><Input ID=locTbKeySize Type=Text Name=tbKeySize Value="512" MaxLength=5 Size=4> </TD>
  175.                 <TD ID=locKeySizeMinLabel Align=Right><Font Size=-2>Min:</Font></TD>
  176.                 <TD ID=locKeySizeMin Align=Right><Font Size=-2><Span ID=spnKeySizeMin></Span></Font></TD>
  177.                 <TD ID=locKeySizeCommon RowSpan=2><Font Size=-2>  (common key sizes: <Span ID=spnKeySizeCommon></Span>)</Font></TD>
  178.             </TR><TR>
  179.                 <TD ID=locKeySizeMaxLabel Align=Right><Font Size=-2>Max:</Font></TD>
  180.                 <TD ID=locKeySizeMax Align=Right><Font Size=-2><Span ID=spnKeySizeMax></Span></Font></TD>
  181.             </TR>
  182.         </Table></TD>
  183.     </TR>
  184.  
  185.  
  186.     <TR><TD ColSpan=3 Height=12></TD></TR>
  187.     <TR><TD></TD>
  188.         <TD><Font Size=-1><Input Type=Radio ID=rbKG1 Name=rbKeyGen Value="0" OnClick="handleKeyGen();" Checked><Label For=rbKG1 ID=locNewKeyLabel>Create new key set</Label>
  189.         <Span ID=spnNewKeys>
  190.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><Input Type=Checkbox ID=cbSetContainer Name=cbSetContainer OnClick="handleSetContainer();"><Label For=cbSetContainer ID=locSetNameLabel>Set the container name</Label>
  191.             <Span ID=spnNewContainer Style="display:none">
  192.                 <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locCntnrNameLabel1>Container name:</LocID> <Input ID=locTbNewContainerName Type=Text Name=tbNewContainerName Size=20>
  193.             </Span>
  194.         </Span>
  195.         </Font></TD>
  196.     </TR><TR><TD></TD>
  197.         <TD><Font Size=-1><Input Type=Radio ID=rbKG2 Name=rbKeyGen Value="1" OnClick="handleKeyGen();"><Label For=rbKG2 ID=locExistKeyLabel>Use existing key set</Label>
  198.         <Span ID=spnExistingKeys Style="display:none">
  199.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locCntnrNameLabel2>Container name:</LocID> <Input ID=locTbOldContainerName Type=Text Name=tbOldContainerName Size=20>
  200.         </Span>
  201.         </Font></TD>
  202.     </TR>
  203.  
  204.     <TR><TD ColSpan=3 Height=4></TD></TR>
  205.     <TR>
  206.         <TD></TD>
  207.         <TD><Font Size=-1><Input Type=Checkbox ID=cbStrongKey Name=cbStrongKey><Label For=cbStrongKey ID=locStrongKeyLabel>Enable strong private key protection</Label></Font></TD>
  208.     </TR>
  209.  
  210.     <TR><TD ColSpan=3 Height=4></TD></TR>
  211.     <TR><TD></TD>
  212.         <TD><Font Size=-1><Input Type=Checkbox Name=cbMarkKeyExportable ID=cbMarkKeyExportable OnClick="handleMarkExport();"><Label For=cbMarkKeyExportable ID=locMarkExportLabel>Mark keys as exportable</Label>
  213.         <Span ID=spnMarkKeyExportable Style="display:none">
  214.             <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>
  215.             <Span ID=spnExportKeys Style="display:none">
  216.                 <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locExpFileNameLabel>File name:</LocID> <Input ID=locTbExportKeyFile Type=Text Name=tbExportKeyFile Size=20>
  217.             </Span>
  218.         </Span>
  219.         </Font></TD>
  220.     </TR>
  221.  
  222.     <TR><TD ColSpan=3 Height=4></TD></TR>
  223.     <TR><TD></TD>
  224.         <TD><Font Size=-1><Input Type=Checkbox Name=cbLocalMachineStore ID=cbLocalMachineStore><Label For=cbLocalMachineStore ID=locLMStoreLabel>Use local machine store</Label><BR>
  225.         <LocID ID=locAdminWarning><Img Src="certspc.gif" Alt="" Height=1 Width=25><I>You must be an administrator to generate<BR>
  226.         <Img Src="certspc.gif" Alt="" Height=1 Width=25> a key in the local machine store.</I></Font></LocID></TD>
  227.     </TR>
  228.  
  229.  
  230.     <TR>
  231.         <TD ID=locAddOptHead ColSpan=3><Font Size=-1><BR><B>Additional Options:</B></Font></TD>
  232.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  233.     </TR><TR><TD ColSpan=3 Height=3></TD>
  234.     </TR>
  235.  
  236.     <TR><TD ColSpan=3 Height=4></TD></TR>
  237.     <TR>
  238.         <TD ID=locHashAlgLabel Align=Right><Font Size=-1>Hash Algorithm:</Font></TD>
  239.         <TD><Select Name=lbHashAlgorithm></Select></TD>
  240.     </TR>
  241.     <TR><TD></TD><TD ID=locHashAlgWarning><Font Size=-1><I>Only used to sign request.</I></Font></TD></TR>
  242.  
  243.  
  244.     <TR><TD ColSpan=3 Height=8></TD></TR>
  245.     <TR><TD></TD>
  246.         <TD><Font Size=-1><Input Type=Checkbox Name=cbSaveRequest ID=cbSaveRequest OnClick="handleSaveReq();"><Label For=cbSaveRequest ID=locSaveReqLabel>Save request to a PKCS #10 file</Label>
  247.         <Span ID=spnSaveRequest Style="display:none">
  248.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locReqFileNameLabel>File name:</LocID> <Input ID=locTbSaveReqFile Type=Text Name=tbSaveReqFile Size=20>
  249.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locSaveReqWarning><B>This request will be saved and not submited.</B></LocID>
  250.         </Span>
  251.         </Font></TD>
  252.     </TR>
  253.  
  254.  
  255.     <TR><TD ColSpan=3 Height=6></TD>
  256.     </TR><TR>
  257.         <TD ID=locAttribLabel Align=Right><Font Size=-1>Attributes:</Font></TD>
  258.         <TD><TextArea ID=locTaAttrib Name=taAttrib Wrap=Off Rows=2 Cols=30></TextArea></TD>
  259.     </TR>
  260.  
  261.  
  262. </Table>
  263. </P>
  264.  
  265.  
  266. <!-- 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>
  267. <!-- 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>
  268.  
  269. <Table Width=100% Border=0 CellPadding=0 CellSpacing=0><TR><TD ID=locSubmitAlign Align=Right>
  270.     <Input ID=locBtnSubmit Type=Submit Name=btnSubmit Value="Submit >" Style="width:.75in">
  271.     <Input ID=locBtnSave Type=Submit Name=btnSave Value="Save" Style="width:.75in; display:none">
  272.          
  273. </TD></TR></Table>
  274.  
  275. </Form>
  276. </Font>
  277. <!-- ############################################################ -->
  278. <!-- End of standard text. Scripts follow  -->
  279.     
  280. <%bIncludeXEnroll=True%>
  281. <%bIncludeGetCspList=True%>
  282. <!-- #include FILE=certsgcl.inc -->
  283.  
  284. <!-- This form we fill in and submit 'by hand'-->
  285. <Span Style="display:none">
  286. <Form Name=SubmittedData Action="certfnsh.asp" Method=Post>
  287.     <Input Type=Hidden Name=Mode>             <!-- used in request ('newreq'|'chkpnd') -->
  288.     <Input Type=Hidden Name=CertRequest>      <!-- used in request -->
  289.     <Input Type=Hidden Name=CertAttrib>       <!-- used in request -->
  290.     <Input Type=Hidden Name=FriendlyType>     <!-- used on pending -->
  291.     <Input Type=Hidden Name=TargetStoreFlags> <!-- used on install ('0'|CSSLM)-->
  292.     <Input Type=Hidden Name=SaveCert>         <!-- used on install ('no'|'yes')-->
  293. </FORM>
  294. </Span>
  295.  
  296. <Script Language="JavaScript">
  297.  
  298.     //================================================================
  299.     // PAGE GLOBAL VARIABLES
  300.  
  301.     //----------------------------------------------------------------
  302.     // Strings to be localized
  303.     var L_CspLoadErrNoneFound_ErrorMessage="An unexpected error occurred while getting the CSP list:\nNo CSPs could be found!";
  304.     var L_CspLoadErrUnexpected_ErrorMessage="\"An unexpected error (\"+sErrorNumber+\") occurred while getting the CSP list.\"";
  305.     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 occured while accessing the Active Directory.";
  306.     var L_TemplateLoadErrUnexpected_ErrorMessage="\"An unexpected error (\"+sErrorNumber+\") occurred while getting the certificate template list.\"";
  307.     var L_SetKeySize_Message="\"Set key size to \"+nPowerSize";
  308.     var L_StillLoading_ErrorMessage="This page has not finished loading yet. Please wait a few seconds and try again.";
  309.     var L_KeySizeNotNumber_ErrorMessage="Please enter a number for the key size.";
  310.     var L_KeySizeBadNumber_ErrorMessage="\"Please enter a valid number for the key size. The key size must be between \"+nKeyMin+\" and \"+nKeyMax+\".\"";
  311.     var L_NoCntnrName_ErrorMessage="Please enter a key container name.";
  312.     var L_NoExportFileName_ErrorMessage="Please enter a file name for exporting the keys.";
  313.     var L_NoSaveReqFileName_ErrorMessage="Please enter a file name for saving the request.";
  314.     var L_Generating_Message="Generating request...";
  315.     var L_UserEKUCert_Text="\"User-EKU (\"+sCertUsage+\") Certificate\"";
  316.     var L_TemplateCert_Text="sTemplate+\" Certificate\"";
  317.     var L_RequestSaved_Message="Request saved to file.";
  318.     var L_Waiting_Message="Waiting for server response...";
  319.     var L_ErrNameUnknown_ErrorMessage="(unknown)";
  320.     var L_SugCauseNone_ErrorMessage="No suggestion.";
  321.     var L_SugCauseBadCSP_ErrorMessage="The CSP you chose was unable to process the request. Try a different CSP.";
  322.     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.";
  323.     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.";
  324.     var L_SugCauseExistKeyContainer_ErrorMessage="The container you named already exists. When creating a new key, you must use a new container name.";
  325.     var L_SugCauseBadChar_ErrorMessage="You entered an invalid character. Report a bug, because this should have been caught in validation.";
  326.     var L_SugCauseBadFileName_ErrorMessage="The file name you entered is invalid.";
  327.     var L_SugCauseBadHash_ErrorMessage="The hash algorithm you selected cannot be used for signing. Please select a different hash algorithm.";
  328.     var L_SugCauseNoFileName_ErrorMessage="You did not enter a file name.";
  329.     var L_ErrNameNoFileName_ErrorMessage="(no file name)";
  330.     var L_SugCauseNotAdmin_ErrorMessage="You must be an administrator to generate a key in the local machine store.";
  331.     var L_ErrNamePermissionDenied_ErrorMessage="Permission Denied";
  332.  
  333.     // IE is not ready until XEnroll has been loaded
  334.     var g_bOkToSubmit=false;
  335.  
  336.     // some constants defined in wincrypt.h:
  337.     var CRYPT_EXPORTABLE=1;
  338.     var CRYPT_USER_PROTECTED=2;
  339.     var CRYPT_MACHINE_KEYSET=0x20;
  340.     var AT_KEYEXCHANGE=1;
  341.     var AT_SIGNATURE=2;
  342.     var CERT_SYSTEM_STORE_LOCATION_SHIFT=16;
  343.     var CERT_SYSTEM_STORE_LOCAL_MACHINE_ID=2;
  344.     var CERT_SYSTEM_STORE_LOCAL_MACHINE=CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT;
  345.     var ALG_CLASS_ANY=0
  346.     var ALG_CLASS_SIGNATURE=1<<13;
  347.     var ALG_CLASS_HASH=4<<13;
  348.     var PROV_DSS=3;
  349.     var PROV_DSS_DH=13;
  350.  
  351.     // convenience constants, for readability
  352.     var KEY_LEN_MIN=true;
  353.     var KEY_LEN_MAX=false;
  354.     var KEY_USAGE_EXCH=0;
  355.     var KEY_USAGE_SIG=1;
  356.     var KEY_USAGE_BOTH=2;
  357.  
  358.     // defaults
  359.     var KEY_LEN_MIN_DEFAULT=384;
  360.     var KEY_LEN_MAX_DEFAULT=16384;
  361.  
  362.     //================================================================
  363.     // INITIALIZATION ROUTINES
  364.  
  365.     //----------------------------------------------------------------
  366.     // This contains the functions we want executed immediately after load completes
  367.     function postLoad() {
  368.         // Load an XEnroll object into the page
  369.         loadXEnroll("postLoadPhase2()"); 
  370.     }
  371.     function postLoadPhase2() {
  372.         // continued from above
  373.         var nResult;
  374.  
  375.         // get the CSP list
  376.         nResult=GetCSPList();
  377.         if (0!=nResult) {
  378.             handleLoadError(nResult, L_CspLoadErrNoneFound_ErrorMessage, L_CspLoadErrUnexpected_ErrorMessage);
  379.             return;
  380.         }
  381.  
  382.         <%If "StandAlone"<>sServerType And 0<>nWriteTemplateResult Then%>
  383.         handleLoadError(<%=nWriteTemplateResult%>, L_TemplateLoadErrNoneFound_ErrorMessage, L_TemplateLoadErrUnexpected_ErrorMessage);
  384.         return;
  385.         <%End If%>
  386.  
  387.         // Now we're ready to go
  388.         g_bOkToSubmit=true;
  389.  
  390.         handleCSPChange();
  391.         <%If "Enterprise"=sServerType Then%>
  392.         handleTemplateChange();
  393.         <%End If%>
  394.     }
  395.  
  396.     //----------------------------------------------------------------
  397.     // handle errors from GetCSPList() and GetTemplateList()
  398.     function handleLoadError(nResult, sNoneFound, sUnexpected) {
  399.         if (-1==nResult) {
  400.             alert(sNoneFound);
  401.         } else {
  402.             var sErrorNumber="0x"+toHex(nResult);
  403.             alert(eval(sUnexpected));
  404.         }
  405.         disableAllControls();
  406.     }
  407.  
  408.     //================================================================
  409.     // PAGE MANAGEMENT ROUTINES
  410.  
  411.     <%If "StandAlone"=sServerType Then%>
  412.     //----------------------------------------------------------------
  413.     // handle the appearance of the text box when 'other...' is selected
  414.     function handleUsageOID() {
  415.         if ("**"==document.UIForm.lbUsageOID.options[document.UIForm.lbUsageOID.selectedIndex].value) {
  416.             spnEKUOther1.style.display='';
  417.             spnEKUOther2.style.display='';
  418.             document.UIForm.lbUsageOID.blur();
  419.             document.UIForm.tbEKUOther.select();
  420.             document.UIForm.tbEKUOther.focus();
  421.         } else {
  422.             spnEKUOther1.style.display='none';
  423.             spnEKUOther2.style.display='none';
  424.         }
  425.     }
  426.     <%End If%>
  427.  
  428.     <%If "Enterprise"=sServerType Then%>
  429.     //----------------------------------------------------------------
  430.     // handle a change in the current template
  431.     function isOfflineTemplate() {
  432.         // extract the template type (the first char)
  433.         // X-bad, E-Enterprise, O-Offline
  434.         var nTemplateIndex=document.UIForm.lbCertTemplate.selectedIndex;
  435.         var sTemplate=document.UIForm.lbCertTemplate.options[nTemplateIndex].value;
  436.         var sTemplateType=sTemplate.substring(0,1);
  437.         return "O"==sTemplateType;
  438.     }
  439.  
  440.     //----------------------------------------------------------------
  441.     // handle a change in the current template
  442.     function handleTemplateChange() {
  443.         if (false==isOfflineTemplate()) {
  444.             spnIDInfo.style.display="none";
  445.         } else {
  446.             spnIDInfo.style.display="";
  447.         }
  448.     }
  449.     <%End If%>
  450.  
  451.     //----------------------------------------------------------------
  452.     // handle a change in the current CSP
  453.     function handleCSPChange() {
  454.  
  455.         var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  456.         XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  457.         var nProvType=document.UIForm.lbCSP.options[nCSPIndex].value;
  458.         XEnroll.ProviderType=nProvType;
  459.  
  460.         // update the key spec options. If we support both, default to key exchange
  461.         var nSupportedKeyUsages=XEnroll.GetSupportedKeySpec();
  462.         if (0==nSupportedKeyUsages) {
  463.             nSupportedKeyUsages=AT_SIGNATURE | AT_KEYEXCHANGE;
  464.         }
  465.         if (PROV_DSS==nProvType || PROV_DSS_DH==nProvType) {
  466.             nSupportedKeyUsages=AT_SIGNATURE;
  467.         }
  468.  
  469.         if (nSupportedKeyUsages&AT_SIGNATURE) {
  470.             spnKeyUsageSignature.style.display="";
  471.             document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked=true;
  472.         } else {
  473.             spnKeyUsageSignature.style.display="none";
  474.         }
  475.  
  476.         if (nSupportedKeyUsages&AT_KEYEXCHANGE) {
  477.             spnKeyUsageKeyExchange.style.display="";
  478.             document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked=true;
  479.         } else {
  480.             spnKeyUsageKeyExchange.style.display="none";
  481.         }
  482.  
  483.         if ((AT_SIGNATURE|AT_KEYEXCHANGE)==nSupportedKeyUsages) {
  484.             spnKeyUsageBoth.style.display="";
  485.             document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  486.         } else {
  487.             spnKeyUsageBoth.style.display="none";
  488.         }
  489.  
  490.         handleKeyUsageChange();
  491.         UpdateHashAlgList();
  492.     }
  493.  
  494.     //----------------------------------------------------------------
  495.     // handle a change in the current CSP
  496.     function handleKeyUsageChange() {
  497.         // get the min and max from the CSP
  498.         var bExchange=document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked || document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked ;
  499.         var nKeyMin=MyGetKeyLen(KEY_LEN_MIN, bExchange);
  500.         var nKeyMax=MyGetKeyLen(KEY_LEN_MAX, bExchange);
  501.  
  502.         // show the min and max
  503.         spnKeySizeMin.innerText=nKeyMin;
  504.         spnKeySizeMax.innerText=nKeyMax;
  505.  
  506.         // keep the key size in bounds
  507.         var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  508.         if (isNaN(nKeySize) || nKeySize>nKeyMax) {
  509.             document.UIForm.tbKeySize.value=nKeyMax;
  510.         } else if (nKeySize<nKeyMin) { //>
  511.             document.UIForm.tbKeySize.value=nKeyMin;
  512.         }
  513.  
  514.         // update list of valid common key sizes
  515.         var nPowerSize=128;
  516.         var sCommonKeys="";
  517.         while (nPowerSize<nKeyMin) { //>
  518.             nPowerSize*=2;
  519.         }
  520.         while (nPowerSize<=nKeyMax) {
  521.             sCommonKeys+="<A Href=\"\""
  522.                 +" OnMouseOver=\"window.status='"+eval(L_SetKeySize_Message)+"';return true;\""
  523.                 +" OnMouseOut=\"window.status='';return true;\""
  524.                 +" OnMouseUp=\"window.status='"+eval(L_SetKeySize_Message)+"';return true;\""
  525.                 +" OnClick=\"document.UIForm.tbKeySize.value='"+nPowerSize
  526.                 +"';blur();return false;\">"+nPowerSize+"</A> ";
  527.             nPowerSize*=2;
  528.         }
  529.         spnKeySizeCommon.innerHTML=sCommonKeys;
  530.  
  531.     }
  532.  
  533.     //----------------------------------------------------------------
  534.     // morphing routine
  535.     function handleSaveReq() {
  536.         if (document.UIForm.cbSaveRequest.checked) {
  537.             spnSaveRequest.style.display='';
  538.             document.UIForm.btnSubmit.style.display='none';
  539.             document.UIForm.btnSave.style.display='';
  540.         } else {
  541.             spnSaveRequest.style.display='none';
  542.             document.UIForm.btnSubmit.style.display='';
  543.             document.UIForm.btnSave.style.display='none';
  544.         }
  545.     }
  546.  
  547.     //----------------------------------------------------------------
  548.     // morphing routine
  549.     function handleMarkExport() {
  550.         if (document.UIForm.cbMarkKeyExportable.checked) {
  551.             spnMarkKeyExportable.style.display='';
  552.         } else {
  553.             spnMarkKeyExportable.style.display='none';
  554.         }
  555.     }
  556.  
  557.     //----------------------------------------------------------------
  558.     // morphing routine
  559.     function handleExportKeys() {
  560.         if (document.UIForm.cbExportKeys.checked) {
  561.             spnExportKeys.style.display='';
  562.         } else {
  563.             spnExportKeys.style.display='none';
  564.         }
  565.     }
  566.  
  567.     //----------------------------------------------------------------
  568.     // morphing routine
  569.     function handleKeyGen() {
  570.         if (document.UIForm.rbKeyGen[0].checked) {
  571.             spnNewKeys.style.display='';
  572.             spnExistingKeys.style.display='none';
  573.         } else {
  574.             spnNewKeys.style.display='none';
  575.             spnExistingKeys.style.display='';
  576.         }
  577.     }
  578.  
  579.     //----------------------------------------------------------------
  580.     // morphing routine
  581.     function handleSetContainer() {
  582.         if (document.UIForm.cbSetContainer.checked) {
  583.             spnNewContainer.style.display='';
  584.         } else {
  585.             spnNewContainer.style.display='none';
  586.         }
  587.     }
  588.  
  589.     //================================================================
  590.     // SUBMIT ROUTINES
  591.  
  592.     //----------------------------------------------------------------
  593.     // determine what to do when the submit button is pressed
  594.     function goNext() {
  595.         if (false==g_bOkToSubmit) {
  596.             alert(L_StillLoading_ErrorMessage);
  597.         } else {
  598.             SubmitRequest();
  599.         }
  600.     }
  601.         
  602.     //----------------------------------------------------------------
  603.     // check for invalid characters and empty strings
  604.     function isValidX500String(sSource) {
  605.         if (-1!=sSource.indexOf(",",0) ||
  606.             -1!=sSource.indexOf("\"",0) ||
  607.             -1!=sSource.indexOf("+",0) ||
  608.             -1!=sSource.indexOf(";",0)) {
  609.             return false;
  610.         } else {
  611.             return true;
  612.         }
  613.     }
  614.  
  615.     //----------------------------------------------------------------
  616.     // check for invalid characters and empty strings
  617.     function isValidIA5String(sSource) {
  618.         var nIndex;
  619.         for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  620.             if (sSource.charCodeAt(nIndex)>127) {  // NOTE: this is better, but not compatible with old browsers.
  621.                 return false;
  622.             }
  623.         };
  624.         return true;
  625.     }
  626.  
  627.     //----------------------------------------------------------------
  628.     // check for invalid characters
  629.     function isValidCountryField(tbCountry) {
  630.         tbCountry.value=tbCountry.value.toUpperCase();
  631.         var sSource=tbCountry.value;
  632.         var nIndex, ch;
  633.         if (0!=sSource.length && 2!=sSource.length) {
  634.             return false;
  635.         }
  636.         for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  637.             ch=sSource.charAt(nIndex)
  638.             if (ch<"A" || ch>"Z") {
  639.                 return false;
  640.             }
  641.         };
  642.         return true;
  643.     }
  644.  
  645.     //----------------------------------------------------------------
  646.     // set a label to normal style
  647.     function markLabelNormal(spn) {
  648.         spn.style.color="#000000";
  649.         spn.style.fontWeight='normal';
  650.     }
  651.  
  652.     //----------------------------------------------------------------
  653.     // set a label to error state
  654.     function markLabelError(spn) {
  655.         spn.style.color='#FF0000';
  656.         spn.style.fontWeight='bold';
  657.     }
  658.  
  659.     //----------------------------------------------------------------
  660.     // check that the form has data in it
  661.     function validateRequest() {
  662.         markLabelNormal(spnNameLabel);
  663.         markLabelNormal(spnEmailLabel);
  664.         markLabelNormal(spnCompanyLabel);
  665.         markLabelNormal(spnDepartmentLabel);
  666.         markLabelNormal(spnCityLabel);
  667.         markLabelNormal(spnStateLabel);
  668.         markLabelNormal(spnCountryLabel);
  669.         
  670.         var bOK=true;
  671.  
  672.         <%If "Enterprise"=sServerType Then%>    
  673.         if (true==isOfflineTemplate()) {
  674.         <%End If%>
  675.             var fldFocusMe=null;
  676.             if (false==isValidCountryField(document.UIForm.tbCountry)) {
  677.                 bOK=false;
  678.                 fldFocusMe=document.UIForm.tbCountry;
  679.                 markLabelError(spnCountryLabel);
  680.             }
  681.             if (false==isValidX500String(document.UIForm.tbState.value)) {
  682.                 bOK=false;
  683.                 fldFocusMe=document.UIForm.tbState;
  684.                 markLabelError(spnStateLabel);
  685.             }
  686.             if (false==isValidX500String(document.UIForm.tbLocality.value)) {
  687.                 bOK=false;
  688.                 fldFocusMe=document.UIForm.tbLocality;
  689.                 markLabelError(spnCityLabel);
  690.             }
  691.             if (false==isValidX500String(document.UIForm.tbOrgUnit.value)) {
  692.                 bOK=false;
  693.                 fldFocusMe=document.UIForm.tbOrgUnit;
  694.                 markLabelError(spnDepartmentLabel);
  695.             }
  696.             if (false==isValidX500String(document.UIForm.tbOrg.value)) {
  697.                 bOK=false;
  698.                 fldFocusMe=document.UIForm.tbOrg;
  699.                 markLabelError(spnCompanyLabel);
  700.             }
  701.             if (false==isValidX500String(document.UIForm.tbEmail.value) || false==isValidIA5String(document.UIForm.tbEmail.value)) {
  702.                 bOK=false;
  703.                 fldFocusMe=document.UIForm.tbEmail;
  704.                 markLabelError(spnEmailLabel);
  705.             }
  706.             if (false==isValidX500String(document.UIForm.tbCommonName.value)) {
  707.                 bOK=false;
  708.                 fldFocusMe=document.UIForm.tbCommonName;
  709.                 markLabelError(spnNameLabel);
  710.             }
  711.  
  712.             if (false==bOK) {
  713.                 spnFixTxt.style.display='';
  714.                 window.scrollTo(0,0);
  715.                 fldFocusMe.focus();
  716.             }
  717.         <%If "Enterprise"=sServerType Then%>    
  718.         } // <- End if offline template
  719.         <%End If%>
  720.  
  721.         // Check the keysize field
  722.         if (true==bOK) {
  723.             // get the min and max from the CSP
  724.             var bExchange=document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked || document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked;
  725.             var nKeyMin=MyGetKeyLen(KEY_LEN_MIN, bExchange);
  726.             var nKeyMax=MyGetKeyLen(KEY_LEN_MAX, bExchange);
  727.  
  728.             var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  729.             var sMessage;
  730.             if (isNaN(nKeySize)) {
  731.                 sMessage=L_KeySizeNotNumber_ErrorMessage;
  732.                 bOK=false;
  733.             } else if (nKeySize<nKeyMin || nKeySize>nKeyMax) {
  734.                 sMessage=eval(L_KeySizeBadNumber_ErrorMessage);
  735.                 bOK=false;
  736.             }
  737.             if (false==bOK) {
  738.                 alert (sMessage);
  739.                 document.UIForm.tbKeySize.focus();
  740.             }
  741.         }
  742.  
  743.         // Check the container name
  744.         if (true==bOK) {
  745.             if (document.UIForm.rbKeyGen[0].checked) {
  746.                 // new keyset
  747.                 if (document.UIForm.cbSetContainer.checked) {
  748.                     if (""==document.UIForm.tbNewContainerName.value) {
  749.                         bOK=false;
  750.                     }
  751.                 }
  752.             } else {
  753.                 // existing keyset
  754.                 if (""==document.UIForm.tbOldContainerName.value) {
  755.                     bOK=false;
  756.                 }
  757.             }
  758.             if (false==bOK) {
  759.                 alert(L_NoCntnrName_ErrorMessage);
  760.                 if (document.UIForm.rbKeyGen[0].checked) {
  761.                     document.UIForm.tbNewContainerName.focus();
  762.                 } else {
  763.                     document.UIForm.tbOldContainerName.focus();
  764.                 }
  765.             }
  766.         }
  767.  
  768.         // Check the exported private key file name
  769.         if (true==bOK) {
  770.             if (document.UIForm.cbMarkKeyExportable.checked && document.UIForm.cbExportKeys.checked) {
  771.                 if (""==document.UIForm.tbExportKeyFile.value) {
  772.                     bOK=false;
  773.                     alert(L_NoExportFileName_ErrorMessage);
  774.                     document.UIForm.tbExportKeyFile.focus();
  775.                 }
  776.             }
  777.         }
  778.  
  779.         // Check the saved-request file name
  780.         if (true==bOK) {
  781.             if (document.UIForm.cbSaveRequest.checked) {
  782.                 if (""==document.UIForm.tbSaveReqFile.value) {
  783.                     bOK=false;
  784.                     alert(L_NoSaveReqFileName_ErrorMessage);
  785.                     document.UIForm.tbSaveReqFile.focus();
  786.                 }
  787.             }
  788.         }
  789.  
  790.         return bOK;
  791.     }
  792.  
  793.     //----------------------------------------------------------------
  794.     function SubmitRequest() {
  795.  
  796.         // check that the form is filled in
  797.         spnErrorTxt.style.display='none';
  798.         spnFixTxt.style.display='none';
  799.         if (false==validateRequest()) {
  800.             return;
  801.         }
  802.  
  803.         // show a nice message since request creation can take a while
  804.         ShowTransientMessage(L_Generating_Message);
  805.  
  806.         // Make the message show up on the screen, 
  807.         // then continue with 'SubmitRequest':
  808.         // Pause 1 mS before executing phase 2, 
  809.         // so screen will have time to repaint.
  810.         setTimeout("SubmitRequestPhase2();",1); 
  811.     }
  812.     function SubmitRequestPhase2() {
  813.         // continued from above
  814.  
  815.         <%If "StandAlone"=sServerType Then%> 
  816.         //
  817.         // Stand-Alone Options
  818.         //
  819.  
  820.         // set the extended key usage and certificate request 'friendly type'
  821.         var nUsageIndex=document.UIForm.lbUsageOID.selectedIndex;
  822.         var sCertUsage;
  823.         if ("**"==document.UIForm.lbUsageOID.options[nUsageIndex].value) {
  824.             sCertUsage=document.UIForm.tbEKUOther.value;
  825.             document.SubmittedData.FriendlyType.value=eval(L_UserEKUCert_Text);
  826.         } else {
  827.             sCertUsage=document.UIForm.lbUsageOID.options[nUsageIndex].value;
  828.             document.SubmittedData.FriendlyType.value=document.UIForm.lbUsageOID.options[nUsageIndex].text;
  829.         }
  830.         DoEkuSpecificSettings(sCertUsage);
  831.  
  832.         <%Else 'Enterprise%>
  833.         //
  834.         // Enterprise Options
  835.         //
  836.  
  837.         // get the selected template
  838.         var nTemplateIndex=document.UIForm.lbCertTemplate.selectedIndex;
  839.         var sTemplate=document.UIForm.lbCertTemplate.options[nTemplateIndex].value;
  840.  
  841.         // Turn on SMIME capabilities if necessary
  842.         if ("Y"==sTemplate.substring(1,2)) {
  843.             XEnroll.EnableSMIMECapabilities=true;
  844.         }
  845.  
  846.         // extract the template name (skip the first two chars)
  847.         sTemplate=sTemplate.slice(2);
  848.  
  849.         // set the cert template
  850.         XEnroll.addCertTypeToRequest(sTemplate);
  851.         document.SubmittedData.FriendlyType.value=eval(L_TemplateCert_Text);
  852.  
  853.         var sCertUsage=""; // ignored
  854.  
  855.         <%End If 'StandAlone or Enterprise%> 
  856.         //
  857.         // Common
  858.         //
  859.  
  860.         // set the identifying info
  861.         var sDistinguishedName="";
  862.         if (""!=document.UIForm.tbCountry.value) {
  863.             sDistinguishedName+="C=\""+document.UIForm.tbCountry.value.replace(/"/g, "\"\"")   +"\";";
  864.         }
  865.         if (""!=document.UIForm.tbState.value) {
  866.             sDistinguishedName+="S=\""+document.UIForm.tbState.value.replace(/"/g, "\"\"")     +"\";";
  867.         }
  868.         if (""!=document.UIForm.tbLocality.value) {
  869.             sDistinguishedName+="L=\""+document.UIForm.tbLocality.value.replace(/"/g, "\"\"")  +"\";";
  870.         }
  871.         if (""!=document.UIForm.tbOrg.value) {
  872.             sDistinguishedName+="O=\""+document.UIForm.tbOrg.value.replace(/"/g, "\"\"")       +"\";";
  873.         }
  874.         if (""!=document.UIForm.tbOrgUnit.value) {
  875.             sDistinguishedName+="OU=\""+document.UIForm.tbOrgUnit.value.replace(/"/g, "\"\"")   +"\";";
  876.         }
  877.         if (""!=document.UIForm.tbEmail.value) {
  878.             sDistinguishedName+="E=\""+document.UIForm.tbEmail.value.replace(/"/g, "\"\"")     +"\";";
  879.         }
  880.         if (""!=document.UIForm.tbCommonName.value) {
  881.             sDistinguishedName+="CN=\""+document.UIForm.tbCommonName.value.replace(/"/g, "\"\"")+"\";";
  882.         }
  883.         <%If "Enterprise"=sServerType Then%> 
  884.         if (false==isOfflineTemplate()) {
  885.             sDistinguishedName="";
  886.         }
  887.         <%End If%>
  888.  
  889.         // append the local date to the type
  890.         document.SubmittedData.FriendlyType.value+=" ("+(new Date()).toLocaleString()+")";
  891.  
  892.         //
  893.         // Key Options subheading:
  894.         //
  895.  
  896.         // set the CSP
  897.         var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  898.         XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  899.         XEnroll.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  900.  
  901.         // set the key size (the upper 16 bits of GenKeyFlags)
  902.         //  note: this value has already been validated
  903.         var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  904.         XEnroll.GenKeyFlags=nKeySize<<16;
  905.  
  906.         // set the KeyUsage
  907.         if (document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked) {
  908.             XEnroll.KeySpec=AT_KEYEXCHANGE;
  909.             XEnroll.LimitExchangeKeyToEncipherment=true;
  910.         } else if (document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked) {
  911.             XEnroll.KeySpec=AT_SIGNATURE;
  912.             XEnroll.LimitExchangeKeyToEncipherment=false;
  913.         } else { // KEY_USAGE_BOTH
  914.             XEnroll.KeySpec=AT_KEYEXCHANGE;
  915.             XEnroll.LimitExchangeKeyToEncipherment=false;
  916.         }
  917.  
  918.         // set the 'use existing key set' flag
  919.         if (document.UIForm.rbKeyGen[0].checked) {
  920.             XEnroll.UseExistingKeySet=false;
  921.             if (document.UIForm.cbSetContainer.checked) {
  922.                 XEnroll.ContainerName=document.UIForm.tbNewContainerName.value;
  923.             }
  924.         } else {
  925.             XEnroll.UseExistingKeySet=true;
  926.             XEnroll.ContainerName=document.UIForm.tbOldContainerName.value;
  927.         }
  928.  
  929.         // set 'Strong private key protection'
  930.         //   note: upper 16 bits already set as key size
  931.         if (document.UIForm.cbStrongKey.checked) {
  932.             XEnroll.GenKeyFlags|=CRYPT_USER_PROTECTED;
  933.         }
  934.  
  935.         // set the 'SaveCert' flag to install the cert instead of saving
  936.         document.SubmittedData.SaveCert.value="no";
  937.              
  938.         // mark the keys as exportable
  939.         if (document.UIForm.cbMarkKeyExportable.checked) {
  940.             XEnroll.GenKeyFlags|=CRYPT_EXPORTABLE;
  941.  
  942.             // set the key export file (.pvk) and save the cert instead of installing
  943.             if (document.UIForm.cbExportKeys.checked) {
  944.                 XEnroll.PVKFileName=document.UIForm.tbExportKeyFile.value;
  945.                 document.SubmittedData.SaveCert.value="yes";
  946.             } 
  947.         }
  948.  
  949.         // place the keys in the local machine store
  950.         if (document.UIForm.cbLocalMachineStore.checked) {
  951.  
  952.             // the keys attached to the dummy request cert go in the local machine store
  953.             XEnroll.RequestStoreFlags=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  954.  
  955.             // used in CryptAcquireContext
  956.             XEnroll.ProviderFlags=CRYPT_MACHINE_KEYSET;
  957.  
  958.             // the keys attached to the final cert also go in the local machine store
  959.             document.SubmittedData.TargetStoreFlags.value=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  960.         } else {
  961.  
  962.             // the keys attached to the final cert also go in the user store
  963.             document.SubmittedData.TargetStoreFlags.value=0; // 0=Use default (=user store)
  964.         }
  965.  
  966.         //
  967.         // Additional Options subheading:
  968.         //
  969.  
  970.         // set the hash algorithm     
  971.         var nHashIndex=document.UIForm.lbHashAlgorithm.selectedIndex;
  972.         XEnroll.HashAlgID=document.UIForm.lbHashAlgorithm.options[nHashIndex].value;
  973.  
  974.         // set any extra attributes
  975.         var sAttrib=document.UIForm.taAttrib.value;
  976.         if (sAttrib.lastIndexOf("\r\n")!=sAttrib.length-2 && sAttrib.length>0) {
  977.             sAttrib=sAttrib+"\r\n";
  978.         }
  979.  
  980.         // for interop debug purposes
  981.         sAttrib+="UserAgent:<%=Request.ServerVariables("HTTP_USER_AGENT")%>\r\n";
  982.  
  983.         document.SubmittedData.CertAttrib.value=sAttrib;
  984.  
  985.         // we are submitting a new request
  986.         document.SubmittedData.Mode.value='newreq';
  987.  
  988.         // 
  989.         // Create the request
  990.         //
  991.  
  992.         if (document.UIForm.cbSaveRequest.checked) {
  993.  
  994.             // build and save the certificate request
  995.             var nResult;
  996.             var sSaveReqFile=document.UIForm.tbSaveReqFile.value;
  997.             nResult=CreateAndSaveRequest(sDistinguishedName, sCertUsage, sSaveReqFile); // ask VB to do it, since it can handle errors
  998.  
  999.         } else {
  1000.             // build the certificate request
  1001.             var nResult=CreateRequest(sDistinguishedName, sCertUsage); // ask VB to do it, since it can handle errors
  1002.         }
  1003.  
  1004.         // hide the message box
  1005.         HideTransientMessage();
  1006.  
  1007.         // reset XEnroll so the user can select a different CSP, etc.
  1008.         XEnroll.reset();
  1009.         // however, make sure it still matches the UI.
  1010.         XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  1011.         XEnroll.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  1012.  
  1013.         // deal with an error if there was one
  1014.         if (0!=nResult) {
  1015.             handleError(nResult);
  1016.             return;
  1017.         }
  1018.  
  1019.         // check for special "no submit" case
  1020.         if (document.UIForm.cbSaveRequest.checked) {
  1021.  
  1022.             // just inform the user that it went OK, but don't submit
  1023.             alert(L_RequestSaved_Message);
  1024.  
  1025.         } else {
  1026.  
  1027.             // put up a new wait message
  1028.             ShowTransientMessage(L_Waiting_Message);
  1029.  
  1030.             // Submit the cert request and move forward in the wizard
  1031.             document.SubmittedData.submit();
  1032.         }
  1033.     }
  1034.  
  1035.     //----------------------------------------------------------------
  1036.     function handleError(nResult) {
  1037.         var sSugCause=L_SugCauseNone_ErrorMessage;
  1038.         var sErrorName=L_ErrNameUnknown_ErrorMessage;
  1039.         // analyze the error - funny use of XOR ('^') because obvious choice '==' doesn't work
  1040.         if (0==(0x80090008^nResult)) {
  1041.             sErrorName="NTE_BAD_ALGID";
  1042.             sSugCause=L_SugCauseBadSetting2_ErrorMessage;
  1043.         } else if (0==(0x80090016^nResult)) {
  1044.             sErrorName="NTE_BAD_KEYSET";
  1045.             if (document.UIForm.rbKeyGen[0].checked) {
  1046.                 sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1047.             } else {
  1048.                 sSugCause=L_SugCauseBadKeyContainer_ErrorMessage;
  1049.             }
  1050.         } else if (0==(0x80090019^nResult)) {
  1051.             sErrorName="NTE_KEYSET_NOT_DEF";
  1052.             sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1053.         } else if (0==(0x80090020^nResult)) {
  1054.             sErrorName="NTE_FAIL";
  1055.             sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1056.         } else if (0==(0x80090009^nResult)) {
  1057.             sErrorName="NTE_BAD_FLAGS";
  1058.             sSugCause=L_SugCauseBadSetting2_ErrorMessage;
  1059.         } else if (0==(0x8009000F^nResult)) {
  1060.             sErrorName="NTE_EXISTS";
  1061.             sSugCause=L_SugCauseExistKeyContainer_ErrorMessage;
  1062.         } else if (0==(0x80092002^nResult)) {
  1063.             sErrorName="CRYPT_E_BAD_ENCODE";
  1064.             //sSugCause="";
  1065.         } else if (0==(0x80092022^nResult)) {
  1066.             sErrorName="CRYPT_E_INVALID_IA5_STRING";
  1067.             sSugCause=L_SugCauseBadChar_ErrorMessage;
  1068.         } else if (0==(0x80092023^nResult)) {
  1069.             sErrorName="CRYPT_E_INVALID_X500_STRING";
  1070.             sSugCause=L_SugCauseBadChar_ErrorMessage;
  1071.         } else if (0==(0x80070003^nResult)) {
  1072.             sErrorName="ERROR_PATH_NOT_FOUND";
  1073.             sSugCause=L_SugCauseBadFileName_ErrorMessage;
  1074.         } else if (0==(0x80070103^nResult)) {
  1075.             sErrorName="ERROR_NO_MORE_ITEMS";
  1076.             sSugCause=L_SugCauseBadHash_ErrorMessage;
  1077.         } else if (0==(0xFFFFFFFF^nResult)) {
  1078.             sErrorName=L_ErrNameNoFileName_ErrorMessage;
  1079.             sSugCause=L_SugCauseNoFileName_ErrorMessage;
  1080.         } else if (0==(0x8000FFFF^nResult)) {
  1081.             sErrorName="E_UNEXPECTED";
  1082.         } else if (0==(0x00000046^nResult)) {
  1083.             sErrorName=L_ErrNamePermissionDenied_ErrorMessage;
  1084.             sSugCause=L_SugCauseNotAdmin_ErrorMessage;
  1085.         }
  1086.         
  1087.         // modify the document text and appearance to show the error message
  1088.         spnErrorNum.innerText="0x"+toHex(nResult)+" - "+sErrorName;
  1089.         spnErrorMsg.innerText=sSugCause;
  1090.         spnFixTxt.style.display='none';
  1091.         spnErrorTxt.style.display='';
  1092.  
  1093.         // back to the top so the messages show
  1094.         window.scrollTo(0,0);
  1095.     }
  1096.  
  1097.  
  1098. </Script> 
  1099. <Script Language="VBScript">
  1100.     '-----------------------------------------------------------------
  1101.     ' call XEnroll to create a request, since javascript has no error handling
  1102.     Function CreateRequest(sDistinguishedName, sCertUsage)
  1103.         On Error Resume Next
  1104.         document.SubmittedData.CertRequest.value= _
  1105.             XEnroll.CreatePKCS10(sDistinguishedName, sCertUsage)
  1106.         CreateRequest=Err.Number
  1107.     End Function
  1108.  
  1109.     '-----------------------------------------------------------------
  1110.     ' call XEnroll to create and save a request, since javascript has no error handling
  1111.     Function CreateAndSaveRequest(sDistinguishedName, sCertUsage, sSaveReqFile)
  1112.         On Error Resume Next
  1113.         XEnroll.CreateFilePKCS10 sDistinguishedName, sCertUsage, sSaveReqFile
  1114.         CreateAndSaveRequest=Err.Number
  1115.     End Function
  1116.  
  1117.     '----------------------------------------------------------------
  1118.     ' handle a change in the current CSP, since javascript has no error handling
  1119.     Sub UpdateHashAlgList
  1120.         On Error Resume Next
  1121.         Dim nIndex, nAlgID, oElem
  1122.  
  1123.         ' clear the list
  1124.         While document.UIForm.lbHashAlgorithm.length>0
  1125.             document.UIForm.lbHashAlgorithm.options.remove(0)
  1126.         Wend
  1127.  
  1128.  
  1129.         ' retrieve the list from XEnroll
  1130.         nIndex=0
  1131.         Do 
  1132.             ' get the next AlgID
  1133.             nAlgID=XEnroll.EnumAlgs(nIndex, ALG_CLASS_HASH)
  1134.             If 0<>Err.Number Then 
  1135.                 ' no more algs
  1136.                 Err.Clear
  1137.                 Exit Do
  1138.             End If
  1139.  
  1140.             ' get the corresponding name and create an option in the list box
  1141.             sName=XEnroll.GetAlgName(nAlgID)
  1142.             Set oElem=document.createElement("Option")
  1143.             oElem.text=sName
  1144.             oElem.value=nAlgID
  1145.             document.UIForm.lbHashAlgorithm.options.add(oElem)
  1146.             nIndex=nIndex+1
  1147.  
  1148.         Loop ' <- End alg enumeration loop
  1149.  
  1150.         ' make sure the first one is selectd
  1151.         document.UIForm.lbHashAlgorithm.selectedIndex=0
  1152.  
  1153.     End Sub
  1154.  
  1155.     '----------------------------------------------------------------
  1156.     ' call XEnroll to get the key length, since javascript has no error handling
  1157.     Function MyGetKeyLen(bMinMax, bExchange)
  1158.         On Error Resume Next
  1159.         MyGetKeyLen=XEnroll.GetKeyLen(bMinMax, bExchange)
  1160.         If 0<>Err.Number Then
  1161.             If KEY_LEN_MIN=bMinMax Then
  1162.                 MyGetKeyLen=KEY_LEN_MIN_DEFAULT
  1163.             Else
  1164.                 MyGetKeyLen=KEY_LEN_MAX_DEFAULT
  1165.             End If
  1166.         End If
  1167.     End Function
  1168. </Script> 
  1169.  
  1170. </Body>
  1171. </HTML>
  1172.