Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

719 lines
22 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:127698e4-e730-4e5c-a2b1-21490a70c8a1\"\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. var CTINFO_INDEX_FRIENDLYNAME=13;
  323. function getTemplateStringInfo(nIndex, sInTemplate)
  324. {
  325. //extract sub string from template string in a format
  326. //of "substr1;substr2;substr3;substr4;..."
  327. //";" is the separator, index starts from 0
  328. var nTemplateIndex, sTemplate;
  329. if (null == sInTemplate)
  330. {
  331. nTemplateIndex=document.UIForm.lbCertTemplate.selectedIndex;
  332. sTemplate=document.UIForm.lbCertTemplate.options[nTemplateIndex].value;
  333. }
  334. else
  335. {
  336. sTemplate = sInTemplate;
  337. }
  338. var sTemp = sTemplate;
  339. var n, m, nEnd;
  340. var fFound = true;
  341. //find sub-string start location
  342. for (n = 0; n < nIndex; ++n)
  343. {
  344. m = sTemp.indexOf(";");
  345. if (-1 == m)
  346. {
  347. fFound = false;
  348. break;
  349. }
  350. sTemp = sTemp.substr(m+1);
  351. }
  352. if (fFound)
  353. {
  354. //sTemp starts from the substring, find end index
  355. nEnd = sTemp.indexOf(";");
  356. if (-1 != nEnd)
  357. {
  358. sTemp = sTemp.substring(0, nEnd);
  359. }
  360. }
  361. else
  362. {
  363. sTemp = "";
  364. }
  365. return sTemp;
  366. }
  367. function updateCSPListFromStrings(sCSPList)
  368. {
  369. var n, m, nCSP;
  370. var L_NoDesiredCSPInstalledMsg = "You need to install the following CSPs before the enrollment, ";
  371. var L_AndMsg = "and ";
  372. var sSupportedCSPs = "";
  373. //remove the current csp list
  374. var nCSP = document.UIForm.lbCSP.length;
  375. //note, strange reasons, can't nCSP-1
  376. for (n = 0; n < nCSP; ++n)
  377. {
  378. document.UIForm.lbCSP.remove(0);
  379. }
  380. //add to the list
  381. while (-1 != (m = sCSPList.indexOf("?")))
  382. {
  383. //get csp from the list
  384. sCSP = sCSPList.substring(0, m);
  385. AddCSPToList(sCSP);
  386. if ("" == sSupportedCSPs)
  387. {
  388. sSupportedCSPs = sCSP;
  389. }
  390. else
  391. {
  392. sSupportedCSPs = sSupportedCSPs + ", ";
  393. }
  394. //move to the next csp
  395. sCSPList = sCSPList.substring(m+1);
  396. }
  397. if ("" != sCSPList)
  398. {
  399. //add the last csp
  400. AddCSPToList(sCSPList);
  401. if ("" == sSupportedCSPs)
  402. {
  403. sSupportedCSPs = sCSPList + ".";
  404. }
  405. else
  406. {
  407. sSupportedCSPs = sSupportedCSPs + ", " + L_AndMsg + sCSPList + ".";
  408. }
  409. }
  410. if (0 == document.UIForm.lbCSP.length)
  411. {
  412. alert(L_NoDesiredCSPInstalledMsg + sSupportedCSPs);
  413. }
  414. }
  415. </Script>
  416. <%End If 'True=bIncludeTemplateCode Then%>
  417. <%End If '"IE"=sBrowser%>
  418. <%If "IE"=sBrowser Then
  419. If True=bIncludeCheckClientCode Then%>
  420. <Script Language="JavaScript">
  421. //helper to decide downlevel browsers
  422. function isClientAbleToCreateCMC()
  423. {
  424. var sUserAgent = navigator.userAgent;
  425. var index;
  426. //check if W2K or newer
  427. index = sUserAgent.indexOf("Windows NT");
  428. if (-1 != index)
  429. {
  430. if (4 < parseInt(sUserAgent.substring(index+11, index+12)))
  431. {
  432. //either w2k or newer
  433. return true;
  434. }
  435. }
  436. if (-1 != sUserAgent.indexOf("Windows 98; Win 9x"))
  437. {
  438. //win ME
  439. return true;
  440. }
  441. return false;
  442. }
  443. </Script>
  444. <% End If 'True=bIncludeTemplateCode Then
  445. End If '"IE"=sBrowser%>
  446. <% ' ########## BEGIN SERVER SIDE EXECUTION ##########
  447. '-----------------------------------------------------------------
  448. ' Strings To Be Localized
  449. Const L_Unexpected_ErrorMessage="Unexpected Error"
  450. Const L_NoTemplates_ErrorMessage="(No templates found!)"
  451. '-----------------------------------------------------------------
  452. ' SCrdEnrl constants
  453. ' flags for enumCAName, getCAName and setCAName
  454. Const SCARD_ENROLL_CA_REAL_NAME=0 'default
  455. Const SCARD_ENROLL_CA_MACHINE_NAME=1
  456. Const SCARD_ENROLL_CA_DISPLAY_NAME=2
  457. Const SCARD_ENROLL_CA_UNIQUE_NAME=3 'machineName\displayName
  458. ' flags for getCertTemplateCount and enumCertTemplateName
  459. Const SCARD_ENROLL_USER_CERT_TEMPLATE=1
  460. Const SCARD_ENROLL_MACHINE_CERT_TEMPLATE=2
  461. Const SCARD_ENROLL_ENTERPRISE_CERT_TEMPLATE=&H08
  462. Const SCARD_ENROLL_OFFLINE_CERT_TEMPLATE=&H10
  463. Const SCARD_ENROLL_CROSS_CERT_TEMPLATE=&H20
  464. ' flags for enumCertTemplateName, getCertTemplateName and setCertTemplateName
  465. Const SCARD_ENROLL_CERT_TEMPLATE_REAL_NAME=0 ' default
  466. Const SCARD_ENROLL_CERT_TEMPLATE_DISPLAY_NAME=4
  467. '-----------------------------------------------------------------
  468. ' Get the list of Cert templates from SCrdEnr and write them to the web page
  469. ' returns error number, or -1 if no templates
  470. Function WriteTemplateList()
  471. On Error Resume Next
  472. Dim nTest, bAnyElements, SCrdEnrl, bAnyElementsReturn
  473. 'Stop 'debugging breakpoint
  474. bAnyElements=False
  475. ' create the object
  476. Set SCrdEnrl=Server.CreateObject("SCrdEnr.SCrdEnr.1")
  477. ' call an easy method to make sure everything is OK
  478. nTest=SCrdEnrl.CSPCount
  479. If 0<>Err.Number Then
  480. ' something's wrong with SCrdEnrl
  481. WriteTemplateError Err.Number
  482. WriteTemplateList=Err.Number
  483. Exit Function
  484. End If
  485. ' first, get the Enterprise (DS-backed) templates
  486. bAnyElementsReturn=EnumTemplates(SCrdEnrl, SCARD_ENROLL_USER_CERT_TEMPLATE Or SCARD_ENROLL_ENTERPRISE_CERT_TEMPLATE or SCARD_ENROLL_CROSS_CERT_TEMPLATE, "E")
  487. bAnyElements=bAnyElements Or bAnyElementsReturn
  488. ' Second, get the Offline (non-Enterprise, non-DS-backed) templates
  489. bAnyElementsReturn=EnumTemplates(SCrdEnrl, SCARD_ENROLL_OFFLINE_CERT_TEMPLATE Or SCARD_ENROLL_CROSS_CERT_TEMPLATE, "O")
  490. bAnyElements=bAnyElements Or bAnyElementsReturn
  491. ' if there are no templates, we're kinda stuck
  492. If False=bAnyElements Then
  493. %>
  494. <Option Value="X"><%=L_NoTemplates_ErrorMessage%></Option>
  495. <%
  496. End If
  497. ' set the return value and exit
  498. If 0<>Err.Number Then
  499. WriteTemplateError Err.Number
  500. WriteTemplateList=Err.Number
  501. ElseIf False=bAnyElements Then
  502. ' signal no elements with -1
  503. WriteTemplateList=-1
  504. Else
  505. WriteTemplateList=0
  506. End If
  507. End Function
  508. '-----------------------------------------------------------------
  509. ' write an error message to the web page
  510. Sub WriteTemplateError(nErrNumber)
  511. %>
  512. <Option Value="X">(<%=L_Unexpected_ErrorMessage%> 0x<%=HEX(nErrNumber)%>)</Option>
  513. <%
  514. End Sub
  515. '-----------------------------------------------------------------
  516. ' enumerate the templates the match the given flags and add them to the web page
  517. Function EnumTemplates(SCrdEnrl, nRequestedTemplateFlags, sPrefix)
  518. Dim nNumTemplates, sRealName, sDisplayName, nTemplateIndex, nNumCAs, nCAIndex, oElement, bAnyElements
  519. Dim sKeySpec, sKeyFlags, sCSP, sCSPs, sSubjectFlags, sPrivateKeyFlags, sEnrollmentFlags
  520. Dim sCTE, sCTEOid, sCTEMajor, sCTEMinor, sCTEMinorFlag, sRASignature
  521. Const SCARD_CTINFO_KEYSPEC=1
  522. Const SCARD_CTINFO_KEYFLAGS=2
  523. Const SCARD_CTINFO_EXT_OID=3
  524. Const SCARD_CTINFO_EXT_MAJOR=4
  525. Const SCARD_CTINFO_EXT_MINOR=5
  526. Const SCARD_CTINFO_EXT_MINOR_FLAG=6
  527. Const SCARD_CTINFO_SUBJECTFLAG=7
  528. Const SCARD_CTINFO_CSPLIST_FIRST=8
  529. Const SCARD_CTINFO_CSPLIST_NEXT=9
  530. Const SCARD_CTINFO_GENERALFLAGS=10
  531. Const SCARD_CTINFO_ENROLLMENTFLAGS=11
  532. Const SCARD_CTINFO_PRIVATEKEYFLAGS=12
  533. Const SCARD_CTINFO_RA_SIGNATURE=13
  534. On Error Resume Next
  535. bAnyElements=False
  536. ' get the number of known templates
  537. nNumTemplates=SCrdEnrl.getCertTemplateCount(nRequestedTemplateFlags)
  538. ' loop over all the known templates
  539. For nTemplateIndex=1 To nNumTemplates
  540. 'get the CertTemplate name
  541. sRealName=SCrdEnrl.enumCertTemplateName(nTemplateIndex-1, nRequestedTemplateFlags Or SCARD_ENROLL_CERT_TEMPLATE_REAL_NAME)
  542. sDisplayName=SCrdEnrl.enumCertTemplateName(nTemplateIndex-1, nRequestedTemplateFlags Or SCARD_ENROLL_CERT_TEMPLATE_DISPLAY_NAME)
  543. ' see it if supported by our CA
  544. ' get the number of CAs that support this template
  545. nNumCAs=SCrdEnrl.getCACount(sRealName)
  546. ' loop over all of those CAs and see if one is ours
  547. For nCAIndex=1 To nNumCAs
  548. ' If we find our CA, add this template to the list
  549. If sServerConfig=SCrdEnrl.enumCAName(nCAIndex-1, SCARD_ENROLL_CA_UNIQUE_NAME, sRealName) Then
  550. 'get template extension info
  551. 'Stop
  552. sKeySpec = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_KEYSPEC))
  553. sKeyFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_KEYFLAGS))
  554. sEnrollmentFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_ENROLLMENTFLAGS))
  555. 'get private key flags
  556. sPrivateKeyFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_PRIVATEKEYFLAGS))
  557. sSubjectFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_SUBJECTFLAG))
  558. 'get # of RA signatures
  559. sRASignature = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_RA_SIGNATURE))
  560. 'get csp list separated by ?
  561. sCSPs = Empty
  562. sCSP = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_CSPLIST_FIRST)
  563. While Not IsEmpty(sCSP)
  564. If IsEmpty(sCSPs) Then
  565. sCSPs = sCSP
  566. Else
  567. sCSPs = sCSPs + "?" + sCSP
  568. End If
  569. sCSP = Empty
  570. sCSP = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_CSPLIST_NEXT)
  571. Wend
  572. 'above actually return no more item error so clean up
  573. Err.Clear
  574. sCTEOid = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_OID)
  575. If ""=sCTEOid Then
  576. sCTE=";;;"
  577. Else
  578. sCTEMajor = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MAJOR))
  579. sCTEMinorFlag = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MINOR_FLAG))
  580. sCTEMinor = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MINOR))
  581. sCTE = sCTEOid & ";" & sCTEMajor & ";" & sCTEMinorFlag & ";" & sCTEMinor
  582. End If
  583. ' add it to the document
  584. %>
  585. <Option Value="<%=sPrefix%>;<%=sRealName%>;<%=sKeySpec%>;<%=sKeyFlags%>;<%=sEnrollmentFlags%>;<%=sPrivateKeyFlags%>;<%=sSubjectFlags%>;<%=sRASignature%>;<%=sCSPs%>;<%=sCTE%>;<%=sDisplayName%>"><%=sDisplayName%></Option>
  586. <%
  587. bAnyElements=True
  588. End If
  589. Next ' <- End CA loop
  590. Next ' <- End known template loop
  591. ' return success
  592. EnumTemplates=bAnyElements
  593. End Function
  594. Function IsUserTemplateAvailable()
  595. On Error Resume Next
  596. Dim nTest, nNumCAs, nCAIndex
  597. Const sUserTemplate="User"
  598. 'init
  599. IsUserTemplateAvailable = False
  600. 'create the scrdenrl object
  601. Set SCrdEnrl=Server.CreateObject("SCrdEnr.SCrdEnr.1")
  602. ' call an easy method to make sure everything is OK
  603. nTest=SCrdEnrl.CSPCount
  604. If 0<>Err.Number Then
  605. ' something's wrong with SCrdEnrl, just return FALSE
  606. Exit Function
  607. End If
  608. 'see if any CA support User template
  609. nNumCAs=SCrdEnrl.getCACount(sUserTemplate)
  610. If 0=nNumCAs Then
  611. 'no CA support it
  612. Exit Function
  613. End If
  614. 'loop over all of those CAs and see if one is ours
  615. For nCAIndex=1 To nNumCAs
  616. ' If we find our CA, add this template to the list
  617. If sServerConfig=SCrdEnrl.enumCAName(nCAIndex-1, SCARD_ENROLL_CA_UNIQUE_NAME, sUserTemplate) Then
  618. IsUserTemplateAvailable = True
  619. Exit Function 'found it
  620. End If
  621. Next 'CA loop
  622. End Function 'IsUserTemplateAvailable
  623. %>