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.

718 lines
21 KiB

  1. <%' CODEPAGE=65001 'UTF-8%>
  2. <%' certsgcl.inc - (CERT)srv web - (S)cript: (G)et (C)sp (L)ist
  3. ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <Script Language="JavaScript">
  5. //----------------------------------------------------------------
  6. // convert a (signed) number into a (unsigned) hex string
  7. function toHex(number) {
  8. var sRight=(number&0x0FFFFFFF).toString(16).toUpperCase();
  9. sRight="0000000".substring(0, 7-sRight.length)+sRight;
  10. return ((number>>28)&0x0000000F).toString(16).toUpperCase()+sRight;
  11. }
  12. </Script>
  13. <%If True=bIncludeXEnroll Then%>
  14. <%If "IE"=sBrowser Then%>
  15. <!-- IE SPECIFIC: -->
  16. <Span ID=spnXEnroll Style="display:none">
  17. <!-- XEnroll will be inserted here -->
  18. </Span>
  19. <!-- A DHTML alert box, for the transient message routines -->
  20. <Table Border=0 CellSpacing=0 CellPadding=0 ID=tblWorkingMsg Style="display:none; position:absolute;">
  21. <TR>
  22. <TD BgColor=#000040 Height=3 ColSpan=3></TD>
  23. </TR> <TR>
  24. <TD BgColor=#000040 Width=3></TD>
  25. <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>
  26. <TD BgColor=#000040 Width=3></TD>
  27. </TR> <TR>
  28. <TD BgColor=#000040 Height=3 ColSpan=3></TD>
  29. </TR>
  30. </Table>
  31. <%End If%>
  32. <%If "Text"<>sBrowser Then%>
  33. <Script Language="JavaScript">
  34. //----------------------------------------------------------------
  35. // Show the message in the status bar and in the middle of the screen (DHTML only)
  36. function ShowTransientMessage(sMessage) {
  37. window.status=sMessage;
  38. <%If "IE"=sBrowser Then%>
  39. spnWorkingMsg.innerText=sMessage;
  40. tblWorkingMsg.style.display='';
  41. tblWorkingMsg.style.pixelTop=
  42. (document.body.clientHeight/2)-(tblWorkingMsg.offsetHeight/2)+(document.body.scrollTop);
  43. tblWorkingMsg.style.pixelLeft=
  44. (document.body.clientWidth/2)-(tblWorkingMsg.offsetWidth/2)+(document.body.scrollLeft);
  45. <%End If%>
  46. }
  47. //----------------------------------------------------------------
  48. // hide the message box
  49. function HideTransientMessage() {
  50. window.status="";
  51. <%If "IE"=sBrowser Then%>
  52. tblWorkingMsg.style.display='none';
  53. <%End If%>
  54. }
  55. </Script>
  56. <%End If%>
  57. <%If "IE"=sBrowser Then%>
  58. <Script Language="JavaScript">
  59. //----------------------------------------------------------------
  60. // IE SPECIFIC:
  61. // Download the appropriate version of XEnroll if the local
  62. // version is too old, and wait for the control to finish downloading.
  63. // sContinueCmd will be executed when the control is ready
  64. function loadXEnroll(sContinueCmd) {
  65. // clear the current control, if there is one
  66. spnXEnroll.innerHTML="";
  67. // determine the file name from the CPU type.
  68. var sCPU=navigator.cpuClass.toLowerCase();
  69. if ("x86"!=sCPU && "ia64"!=sCPU) {
  70. alert(eval(L_BadCPU_ErrorMessage));
  71. g_fnOnLoadFail();
  72. return;
  73. }
  74. // load the control
  75. var sControl="<Object \n"
  76. + " ClassID=\"clsid:43F8F289-7A20-11D0-8F06-00C04FC295E1\"\n"
  77. + " Codebase=\"/CertControl/xenrlinf.cab#Version=<%=sXEnrollVersion%>\"\n"
  78. + " ID=XEnroll\n"
  79. + "></Object>";
  80. // alert("About to create:\n" + sControl);
  81. spnXEnroll.innerHTML=sControl;
  82. // begin polling to see if the control is loaded
  83. setTimeout("loadXEnrollPhase2(\""+sContinueCmd+"\")", 1);
  84. }
  85. function loadXEnrollPhase2(sContinueCmd) {
  86. // continued from above
  87. // is the control loaded?
  88. if (4!=XEnroll.readyState) { // 4=READYSTATE_COMPLETE
  89. // no, show a message and wait a while
  90. ShowTransientMessage(L_DownloadingControl_Message);
  91. setTimeout("loadXEnrollPhase2(\""+sContinueCmd+"\")", 500);
  92. } else {
  93. // yes, hide the message
  94. HideTransientMessage();
  95. // smoke test the control
  96. var nResult=ConfirmXEnrollLoaded();
  97. if (0!=nResult) {
  98. if (438==nResult) {
  99. alert(L_ControlLoadFailed_ErrorMessage);
  100. } else {
  101. var sErrorNumber="0x"+toHex(nResult);
  102. alert(eval(L_ControlLoadFailedEx_ErrorMessage));
  103. }
  104. g_fnOnLoadFail();
  105. return;
  106. }
  107. // Continue with what the caller wanted us to do
  108. execScript(sContinueCmd, "JavaScript");
  109. }
  110. }
  111. //----------------------------------------------------------------
  112. // IE SPECIFIC:
  113. // disable all the controls on this page so the user can't do anything
  114. function disableAllControls() {
  115. // some pages do not have any controls
  116. if (null==document.UIForm) {
  117. return;
  118. }
  119. // disable every control on the page
  120. var nCount=document.UIForm.elements.length;
  121. var nIndex;
  122. for (nIndex=0; nIndex<nCount; nIndex++) { //>
  123. document.UIForm.elements(nIndex).disabled=true;
  124. }
  125. }
  126. //----------------------------------------------------------------
  127. // If XEnroll fails to load, this function will be called.
  128. // By default, disable all controls.
  129. var g_fnOnLoadFail=disableAllControls;
  130. </Script>
  131. <Script Language="VBScript">
  132. '-----------------------------------------------------------------
  133. ' Strings to be localized
  134. Const L_BadCPU_ErrorMessage="""Your CPU (""+sCPU+"") is not supported."""
  135. Const L_DownloadingControl_Message="Downloading ActiveX control..."
  136. Const L_ControlLoadFailed_ErrorMessage="The proper version of the ActiveX control failed to download and install. You may not have sufficient permissions. Please ask your system administrator for assistance."
  137. Const L_ControlLoadFailedEx_ErrorMessage="""An unexpected error (""+sErrorNumber+"") occurred while downloading and installing the proper version of the ActiveX control. Please ask your system administrator for assistance."""
  138. '-----------------------------------------------------------------
  139. ' IE SPECIFIC:
  140. ' Test to make sure XEnroll loaded properly by calling a method on it.
  141. ' For best results, the method we call should only be available in the
  142. ' most recent version of the control, however any method will detect
  143. ' failure to create the object.
  144. Function ConfirmXEnrollLoaded()
  145. On Error Resume Next
  146. Dim nTest
  147. nTest=XEnroll.HashAlgID
  148. ConfirmXEnrollLoaded=Err.Number
  149. End Function
  150. </Script>
  151. <%End If '"IE"=sBrowser%>
  152. <%End If 'True=bIncludeXEnroll%>
  153. <%If True=bIncludeGetCspList Then%>
  154. <%If "IE"=sBrowser Then%>
  155. <Script Language="VBScript">
  156. Option Explicit
  157. '-----------------------------------------------------------------
  158. ' Strings to be localized
  159. Const L_NoCSPs_ErrorMessage="(No CSPs found!)"
  160. Const EnhancedCSPString="Microsoft Enhanced Cryptographic Provider"
  161. Const BaseCSPString="Microsoft Base Cryptographic Provider"
  162. '-----------------------------------------------------------------
  163. ' IE SPECIFIC:
  164. ' Get the list of CSPs from XEnroll
  165. ' returns error number
  166. ' assumes XEnroll is named 'XEnroll' and the list box is 'document.UIForm.lbCSP'
  167. Function GetCSPList()
  168. On Error Resume Next
  169. Dim nProvType, nOrigProvType, nTotCSPs, nDefaultCSP, nBaseCSP, bNoDssBase, bNoDssDh, sUserAgent
  170. Const nMaxProvType=25 ' should be >= the number of providers defined in wincrypt.h (~line 431)
  171. nTotCSPs=0
  172. nDefaultCSP=-1
  173. nBaseCSP=-1
  174. ' Special case stuff for DSS CSPs
  175. ' We know we are an IE browser to get here.
  176. sUserAgent=navigator.userAgent
  177. If CInt(Mid(sUserAgent, InStr(sUserAgent, "MSIE")+5, 1))<=4 Then
  178. ' IE 4 or below
  179. bNoDssDh=True
  180. bNoDssBase=True
  181. If 0<>InStr(sUserAgent, "NT)") Then 'NT 4 does not include version num in string.
  182. ' except on NT4, which can
  183. bNoDssDh=False
  184. End If
  185. Else
  186. ' IE 5 or above
  187. bNoDssDh=False
  188. If 0<>InStr(sUserAgent, "95") Then
  189. ' Win95 can't
  190. bNoDssBase=True
  191. ElseIf 0<>InStr(sUserAgent, "NT)") Then 'NT 4 does not include version num in string.
  192. ' NT4 can't
  193. bNoDssBase=True
  194. Else
  195. ' Win98 and Win2K can
  196. bNoDssBase=False
  197. End If
  198. End If
  199. ' save the original provider type
  200. nOrigProvType=XEnroll.ProviderType
  201. If 0<>Err.Number Then
  202. ' something wrong with XEnroll
  203. GetCSPList=Err.Number
  204. Exit Function
  205. End If
  206. ' enumerate through each of the provider types
  207. For nProvType=0 To nMaxProvType
  208. Dim nCSPIndex
  209. nCSPIndex=0
  210. XEnroll.ProviderType=nProvType
  211. ' enumerate through each of the providers for this type
  212. Do
  213. Dim sProviderName
  214. 'get the name
  215. sProviderName=XEnroll.enumProviders(nCSPIndex, 0)
  216. If &H80070103=Err.Number Then
  217. ' no more providers
  218. Err.Clear
  219. Exit Do
  220. ElseIf 0<>Err.Number Then
  221. ' something wrong with XEnroll
  222. ' - ex, Win16 IE4 XEnroll doesn't support this call.
  223. GetCSPList=Err.Number
  224. Exit Function
  225. End If
  226. If ("Microsoft Base DSS Cryptographic Provider"=sProviderName And True=bNoDssBase) _
  227. Or ("Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"=sProviderName And True=bNoDssDh) Then
  228. ' skip this provider
  229. Else
  230. ' For each provider, add an element to the list box.
  231. Dim oOption
  232. Set oOption=document.createElement("Option")
  233. oOption.text=sProviderName
  234. oOption.Value=nProvType
  235. document.UIForm.lbCSP.add(oOption)
  236. If InStr(sProviderName, EnhancedCSPString) <> 0 Then
  237. oOption.selected=True
  238. nDefaultCSP=nTotCSPs
  239. End If
  240. If InStr(sProviderName, BaseCSPString) <> 0 Then
  241. 'just remember the base csp index
  242. nBaseCSP=nTotCSPs
  243. End If
  244. nTotCSPs=nTotCSPs+1
  245. End If
  246. ' get the next provider
  247. nCSPIndex=nCSPIndex+1
  248. Loop
  249. Next
  250. ' if there are no CSPs, we're kinda stuck
  251. If 0=nTotCSPs Then
  252. Set oElement=document.createElement("Option")
  253. oElement.text=L_NoCSPs_ErrorMessage
  254. document.UIForm.lbCSP.Options.Add oElement
  255. End If
  256. ' remove the 'loading' text
  257. document.UIForm.lbCSP.remove(0)
  258. ' select the default provider
  259. If -1 = nDefaultCSP Then
  260. 'no enhanced csp, how about base
  261. If -1 <> nBaseCSP Then
  262. 'ok, take base csp
  263. nDefaultCSP=nBaseCSP
  264. End If
  265. End If
  266. If -1<>nDefaultCSP Then
  267. document.UIForm.lbCSP.selectedIndex=nDefaultCSP
  268. End If
  269. If -1 = nDefaultCSP Then
  270. If 0 < nCSPIndex Then
  271. 'well, best bet is the 1st available one
  272. document.UIForm.lbCSP.selectedIndex=0
  273. End If
  274. End If
  275. ' restore the original provider type
  276. XEnroll.ProviderType=nOrigProvType
  277. ' set the return value and exit
  278. If 0<>Err.Number Then
  279. GetCSPList=Err.Number
  280. ElseIf 0=nTotCSPs Then
  281. ' signal no elements with -1
  282. GetCSPList=-1
  283. Else
  284. GetCSPList=0
  285. End If
  286. End Function
  287. Function AddCSPToList(sCSP)
  288. On Error Resume Next
  289. Dim oOption
  290. Dim nProviderType
  291. nProviderType = XEnroll.getProviderType(sCSP)
  292. If 0=Err.Number Then
  293. 'csp available on the machine
  294. Set oOption=document.createElement("Option")
  295. oOption.text=sCSP
  296. oOption.Value=nProviderType
  297. document.UIForm.lbCSP.add(oOption)
  298. If InStr(sCSP, EnhancedCSPString) <> 0 Then
  299. oOption.selected=True
  300. End If
  301. End If
  302. End Function
  303. </Script>
  304. <%End If '"IE"=sBrowser%>
  305. <%End If 'True=bIncludeGetCspList%>
  306. <%If "IE"=sBrowser Then%>
  307. <%If True=bIncludeTemplateCode Then%>
  308. <Script Language="JavaScript">
  309. var CTINFO_INDEX_OFFLINE =0;
  310. var CTINFO_INDEX_REALNAME =1;
  311. var CTINFO_INDEX_KEYSPEC =2;
  312. var CTINFO_INDEX_KEYFLAG =3;
  313. var CTINFO_INDEX_ENROLLFLAG =4;
  314. var CTINFO_INDEX_PRIVATEKEYFLAG =5;
  315. var CTINFO_INDEX_SUBJECTFLAG =6;
  316. var CTINFO_INDEX_RASIGNATURE =7;
  317. var CTINFO_INDEX_CSPLIST =8;
  318. var CTINFO_INDEX_EXTOID =9;
  319. var CTINFO_INDEX_EXTMAJ =10;
  320. var CTINFO_INDEX_EXTFMIN =11;
  321. var CTINFO_INDEX_EXTMIN =12;
  322. function getTemplateStringInfo(nIndex, sInTemplate)
  323. {
  324. //extract sub string from template string in a format
  325. //of "substr1;substr2;substr3;substr4;..."
  326. //";" is the separator, index starts from 0
  327. var nTemplateIndex, sTemplate;
  328. if (null == sInTemplate)
  329. {
  330. nTemplateIndex=document.UIForm.lbCertTemplate.selectedIndex;
  331. sTemplate=document.UIForm.lbCertTemplate.options[nTemplateIndex].value;
  332. }
  333. else
  334. {
  335. sTemplate = sInTemplate;
  336. }
  337. var sTemp = sTemplate;
  338. var n, m, nEnd;
  339. var fFound = true;
  340. //find sub-string start location
  341. for (n = 0; n < nIndex; ++n)
  342. {
  343. m = sTemp.indexOf(";");
  344. if (-1 == m)
  345. {
  346. fFound = false;
  347. break;
  348. }
  349. sTemp = sTemp.substr(m+1);
  350. }
  351. if (fFound)
  352. {
  353. //sTemp starts from the substring, find end index
  354. nEnd = sTemp.indexOf(";");
  355. if (-1 != nEnd)
  356. {
  357. sTemp = sTemp.substring(0, nEnd);
  358. }
  359. }
  360. else
  361. {
  362. sTemp = "";
  363. }
  364. return sTemp;
  365. }
  366. function updateCSPListFromStrings(sCSPList)
  367. {
  368. var n, m, nCSP;
  369. var L_NoDesiredCSPInstalledMsg = "You need to install the following CSPs before the enrollment, ";
  370. var L_AndMsg = "and ";
  371. var sSupportedCSPs = "";
  372. //remove the current csp list
  373. var nCSP = document.UIForm.lbCSP.length;
  374. //note, strange reasons, can't nCSP-1
  375. for (n = 0; n < nCSP; ++n)
  376. {
  377. document.UIForm.lbCSP.remove(0);
  378. }
  379. //add to the list
  380. while (-1 != (m = sCSPList.indexOf("?")))
  381. {
  382. //get csp from the list
  383. sCSP = sCSPList.substring(0, m);
  384. AddCSPToList(sCSP);
  385. if ("" == sSupportedCSPs)
  386. {
  387. sSupportedCSPs = sCSP;
  388. }
  389. else
  390. {
  391. sSupportedCSPs = sSupportedCSPs + ", ";
  392. }
  393. //move to the next csp
  394. sCSPList = sCSPList.substring(m+1);
  395. }
  396. if ("" != sCSPList)
  397. {
  398. //add the last csp
  399. AddCSPToList(sCSPList);
  400. if ("" == sSupportedCSPs)
  401. {
  402. sSupportedCSPs = sCSPList + ".";
  403. }
  404. else
  405. {
  406. sSupportedCSPs = sSupportedCSPs + ", " + L_AndMsg + sCSPList + ".";
  407. }
  408. }
  409. if (0 == document.UIForm.lbCSP.length)
  410. {
  411. alert(L_NoDesiredCSPInstalledMsg + sSupportedCSPs);
  412. }
  413. }
  414. </Script>
  415. <%End If 'True=bIncludeTemplateCode Then%>
  416. <%End If '"IE"=sBrowser%>
  417. <%If "IE"=sBrowser Then
  418. If True=bIncludeCheckClientCode Then%>
  419. <Script Language="JavaScript">
  420. //helper to decide downlevel browsers
  421. function isClientAbleToCreateCMC()
  422. {
  423. var sUserAgent = navigator.userAgent;
  424. var index;
  425. //check if W2K or newer
  426. index = sUserAgent.indexOf("Windows NT");
  427. if (-1 != index)
  428. {
  429. if (4 < parseInt(sUserAgent.substring(index+11, index+12)))
  430. {
  431. //either w2k or newer
  432. return true;
  433. }
  434. }
  435. if (-1 != sUserAgent.indexOf("Windows 98; Win 9x"))
  436. {
  437. //win ME
  438. return true;
  439. }
  440. return false;
  441. }
  442. </Script>
  443. <% End If 'True=bIncludeTemplateCode Then
  444. End If '"IE"=sBrowser%>
  445. <% ' ########## BEGIN SERVER SIDE EXECUTION ##########
  446. '-----------------------------------------------------------------
  447. ' Strings To Be Localized
  448. Const L_Unexpected_ErrorMessage="Unexpected Error"
  449. Const L_NoTemplates_ErrorMessage="(No templates found!)"
  450. '-----------------------------------------------------------------
  451. ' SCrdEnrl constants
  452. ' flags for enumCAName, getCAName and setCAName
  453. Const SCARD_ENROLL_CA_REAL_NAME=0 'default
  454. Const SCARD_ENROLL_CA_MACHINE_NAME=1
  455. Const SCARD_ENROLL_CA_DISPLAY_NAME=2
  456. Const SCARD_ENROLL_CA_UNIQUE_NAME=3 'machineName\displayName
  457. ' flags for getCertTemplateCount and enumCertTemplateName
  458. Const SCARD_ENROLL_USER_CERT_TEMPLATE=1
  459. Const SCARD_ENROLL_MACHINE_CERT_TEMPLATE=2
  460. Const SCARD_ENROLL_ENTERPRISE_CERT_TEMPLATE=&H08
  461. Const SCARD_ENROLL_OFFLINE_CERT_TEMPLATE=&H10
  462. Const SCARD_ENROLL_CROSS_CERT_TEMPLATE=&H20
  463. ' flags for enumCertTemplateName, getCertTemplateName and setCertTemplateName
  464. Const SCARD_ENROLL_CERT_TEMPLATE_REAL_NAME=0 ' default
  465. Const SCARD_ENROLL_CERT_TEMPLATE_DISPLAY_NAME=4
  466. '-----------------------------------------------------------------
  467. ' Get the list of Cert templates from SCrdEnr and write them to the web page
  468. ' returns error number, or -1 if no templates
  469. Function WriteTemplateList()
  470. On Error Resume Next
  471. Dim nTest, bAnyElements, SCrdEnrl, bAnyElementsReturn
  472. 'Stop 'debugging breakpoint
  473. bAnyElements=False
  474. ' create the object
  475. Set SCrdEnrl=Server.CreateObject("SCrdEnr.SCrdEnr.1")
  476. ' call an easy method to make sure everything is OK
  477. nTest=SCrdEnrl.CSPCount
  478. If 0<>Err.Number Then
  479. ' something's wrong with SCrdEnrl
  480. WriteTemplateError Err.Number
  481. WriteTemplateList=Err.Number
  482. Exit Function
  483. End If
  484. ' first, get the Enterprise (DS-backed) templates
  485. bAnyElementsReturn=EnumTemplates(SCrdEnrl, SCARD_ENROLL_USER_CERT_TEMPLATE Or SCARD_ENROLL_ENTERPRISE_CERT_TEMPLATE or SCARD_ENROLL_CROSS_CERT_TEMPLATE, "E")
  486. bAnyElements=bAnyElements Or bAnyElementsReturn
  487. ' Second, get the Offline (non-Enterprise, non-DS-backed) templates
  488. bAnyElementsReturn=EnumTemplates(SCrdEnrl, SCARD_ENROLL_OFFLINE_CERT_TEMPLATE Or SCARD_ENROLL_CROSS_CERT_TEMPLATE, "O")
  489. bAnyElements=bAnyElements Or bAnyElementsReturn
  490. ' if there are no templates, we're kinda stuck
  491. If False=bAnyElements Then
  492. %>
  493. <Option Value="X"><%=L_NoTemplates_ErrorMessage%></Option>
  494. <%
  495. End If
  496. ' set the return value and exit
  497. If 0<>Err.Number Then
  498. WriteTemplateError Err.Number
  499. WriteTemplateList=Err.Number
  500. ElseIf False=bAnyElements Then
  501. ' signal no elements with -1
  502. WriteTemplateList=-1
  503. Else
  504. WriteTemplateList=0
  505. End If
  506. End Function
  507. '-----------------------------------------------------------------
  508. ' write an error message to the web page
  509. Sub WriteTemplateError(nErrNumber)
  510. %>
  511. <Option Value="X">(<%=L_Unexpected_ErrorMessage%> 0x<%=HEX(nErrNumber)%>)</Option>
  512. <%
  513. End Sub
  514. '-----------------------------------------------------------------
  515. ' enumerate the templates the match the given flags and add them to the web page
  516. Function EnumTemplates(SCrdEnrl, nRequestedTemplateFlags, sPrefix)
  517. Dim nNumTemplates, sRealName, sDisplayName, nTemplateIndex, nNumCAs, nCAIndex, oElement, bAnyElements
  518. Dim sKeySpec, sKeyFlags, sCSP, sCSPs, sSubjectFlags, sPrivateKeyFlags, sEnrollmentFlags
  519. Dim sCTE, sCTEOid, sCTEMajor, sCTEMinor, sCTEMinorFlag, sRASignature
  520. Const SCARD_CTINFO_KEYSPEC=1
  521. Const SCARD_CTINFO_KEYFLAGS=2
  522. Const SCARD_CTINFO_EXT_OID=3
  523. Const SCARD_CTINFO_EXT_MAJOR=4
  524. Const SCARD_CTINFO_EXT_MINOR=5
  525. Const SCARD_CTINFO_EXT_MINOR_FLAG=6
  526. Const SCARD_CTINFO_SUBJECTFLAG=7
  527. Const SCARD_CTINFO_CSPLIST_FIRST=8
  528. Const SCARD_CTINFO_CSPLIST_NEXT=9
  529. Const SCARD_CTINFO_GENERALFLAGS=10
  530. Const SCARD_CTINFO_ENROLLMENTFLAGS=11
  531. Const SCARD_CTINFO_PRIVATEKEYFLAGS=12
  532. Const SCARD_CTINFO_RA_SIGNATURE=13
  533. On Error Resume Next
  534. bAnyElements=False
  535. ' get the number of known templates
  536. nNumTemplates=SCrdEnrl.getCertTemplateCount(nRequestedTemplateFlags)
  537. ' loop over all the known templates
  538. For nTemplateIndex=1 To nNumTemplates
  539. 'get the CertTemplate name
  540. sRealName=SCrdEnrl.enumCertTemplateName(nTemplateIndex-1, nRequestedTemplateFlags Or SCARD_ENROLL_CERT_TEMPLATE_REAL_NAME)
  541. sDisplayName=SCrdEnrl.enumCertTemplateName(nTemplateIndex-1, nRequestedTemplateFlags Or SCARD_ENROLL_CERT_TEMPLATE_DISPLAY_NAME)
  542. ' see it if supported by our CA
  543. ' get the number of CAs that support this template
  544. nNumCAs=SCrdEnrl.getCACount(sRealName)
  545. ' loop over all of those CAs and see if one is ours
  546. For nCAIndex=1 To nNumCAs
  547. ' If we find our CA, add this template to the list
  548. If sServerConfig=SCrdEnrl.enumCAName(nCAIndex-1, SCARD_ENROLL_CA_UNIQUE_NAME, sRealName) Then
  549. 'get template extension info
  550. 'Stop
  551. sKeySpec = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_KEYSPEC))
  552. sKeyFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_KEYFLAGS))
  553. sEnrollmentFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_ENROLLMENTFLAGS))
  554. 'get private key flags
  555. sPrivateKeyFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_PRIVATEKEYFLAGS))
  556. sSubjectFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_SUBJECTFLAG))
  557. 'get # of RA signatures
  558. sRASignature = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_RA_SIGNATURE))
  559. 'get csp list separated by ?
  560. sCSPs = Empty
  561. sCSP = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_CSPLIST_FIRST)
  562. While Not IsEmpty(sCSP)
  563. If IsEmpty(sCSPs) Then
  564. sCSPs = sCSP
  565. Else
  566. sCSPs = sCSPs + "?" + sCSP
  567. End If
  568. sCSP = Empty
  569. sCSP = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_CSPLIST_NEXT)
  570. Wend
  571. 'above actually return no more item error so clean up
  572. Err.Clear
  573. sCTEOid = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_OID)
  574. If ""=sCTEOid Then
  575. sCTE=";;;"
  576. Else
  577. sCTEMajor = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MAJOR))
  578. sCTEMinorFlag = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MINOR_FLAG))
  579. sCTEMinor = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MINOR))
  580. sCTE = sCTEOid & ";" & sCTEMajor & ";" & sCTEMinorFlag & ";" & sCTEMinor
  581. End If
  582. ' add it to the document
  583. %>
  584. <Option Value="<%=sPrefix%>;<%=sRealName%>;<%=sKeySpec%>;<%=sKeyFlags%>;<%=sEnrollmentFlags%>;<%=sPrivateKeyFlags%>;<%=sSubjectFlags%>;<%=sRASignature%>;<%=sCSPs%>;<%=sCTE%>"><%=sDisplayName%></Option>
  585. <%
  586. bAnyElements=True
  587. End If
  588. Next ' <- End CA loop
  589. Next ' <- End known template loop
  590. ' return success
  591. EnumTemplates=bAnyElements
  592. End Function
  593. Function IsUserTemplateAvailable()
  594. On Error Resume Next
  595. Dim nTest, nNumCAs, nCAIndex
  596. Const sUserTemplate="User"
  597. 'init
  598. IsUserTemplateAvailable = False
  599. 'create the scrdenrl object
  600. Set SCrdEnrl=Server.CreateObject("SCrdEnr.SCrdEnr.1")
  601. ' call an easy method to make sure everything is OK
  602. nTest=SCrdEnrl.CSPCount
  603. If 0<>Err.Number Then
  604. ' something's wrong with SCrdEnrl, just return FALSE
  605. Exit Function
  606. End If
  607. 'see if any CA support User template
  608. nNumCAs=SCrdEnrl.getCACount(sUserTemplate)
  609. If 0=nNumCAs Then
  610. 'no CA support it
  611. Exit Function
  612. End If
  613. 'loop over all of those CAs and see if one is ours
  614. For nCAIndex=1 To nNumCAs
  615. ' If we find our CA, add this template to the list
  616. If sServerConfig=SCrdEnrl.enumCAName(nCAIndex-1, SCARD_ENROLL_CA_UNIQUE_NAME, sUserTemplate) Then
  617. IsUserTemplateAvailable = True
  618. Exit Function 'found it
  619. End If
  620. Next 'CA loop
  621. End Function 'IsUserTemplateAvailable
  622. %>