%' CODEPAGE=65001 'UTF-8%> <%' certsgcl.inc - (CERT)srv web - (S)cript: (G)et (C)sp (L)ist ' Copyright (C) Microsoft Corporation, 1998 - 1999 %> <%If True=bIncludeXEnroll Then%> <%If "IE"=sBrowser Then%>
<%End If%> <%If "Text"<>sBrowser Then%> <%End If%> <%If "IE"=sBrowser Then%> <%End If '"IE"=sBrowser%> <%End If 'True=bIncludeXEnroll%> <%If True=bIncludeGetCspList Then%> <%If "IE"=sBrowser Then%> <%End If '"IE"=sBrowser%> <%End If 'True=bIncludeGetCspList%> <%If "IE"=sBrowser Then%> <%If True=bIncludeTemplateCode Then%> <%End If 'True=bIncludeTemplateCode Then%> <%End If '"IE"=sBrowser%> <%If "IE"=sBrowser Then If True=bIncludeCheckClientCode Then%> <% End If 'True=bIncludeTemplateCode Then End If '"IE"=sBrowser%> <% ' ########## BEGIN SERVER SIDE EXECUTION ########## '----------------------------------------------------------------- ' Strings To Be Localized Const L_Unexpected_ErrorMessage="Unexpected Error" Const L_NoTemplates_ErrorMessage="(No templates found!)" '----------------------------------------------------------------- ' SCrdEnrl constants ' flags for enumCAName, getCAName and setCAName Const SCARD_ENROLL_CA_REAL_NAME=0 'default Const SCARD_ENROLL_CA_MACHINE_NAME=1 Const SCARD_ENROLL_CA_DISPLAY_NAME=2 Const SCARD_ENROLL_CA_UNIQUE_NAME=3 'machineName\displayName ' flags for getCertTemplateCount and enumCertTemplateName Const SCARD_ENROLL_USER_CERT_TEMPLATE=1 Const SCARD_ENROLL_MACHINE_CERT_TEMPLATE=2 Const SCARD_ENROLL_ENTERPRISE_CERT_TEMPLATE=&H08 Const SCARD_ENROLL_OFFLINE_CERT_TEMPLATE=&H10 Const SCARD_ENROLL_CROSS_CERT_TEMPLATE=&H20 ' flags for enumCertTemplateName, getCertTemplateName and setCertTemplateName Const SCARD_ENROLL_CERT_TEMPLATE_REAL_NAME=0 ' default Const SCARD_ENROLL_CERT_TEMPLATE_DISPLAY_NAME=4 '----------------------------------------------------------------- ' Get the list of Cert templates from SCrdEnr and write them to the web page ' returns error number, or -1 if no templates Function WriteTemplateList() On Error Resume Next Dim nTest, bAnyElements, SCrdEnrl, bAnyElementsReturn 'Stop 'debugging breakpoint bAnyElements=False ' create the object Set SCrdEnrl=Server.CreateObject("SCrdEnr.SCrdEnr.1") ' call an easy method to make sure everything is OK nTest=SCrdEnrl.CSPCount If 0<>Err.Number Then ' something's wrong with SCrdEnrl WriteTemplateError Err.Number WriteTemplateList=Err.Number Exit Function End If ' first, get the Enterprise (DS-backed) templates bAnyElementsReturn=EnumTemplates(SCrdEnrl, SCARD_ENROLL_USER_CERT_TEMPLATE Or SCARD_ENROLL_ENTERPRISE_CERT_TEMPLATE or SCARD_ENROLL_CROSS_CERT_TEMPLATE, "E") bAnyElements=bAnyElements Or bAnyElementsReturn ' Second, get the Offline (non-Enterprise, non-DS-backed) templates bAnyElementsReturn=EnumTemplates(SCrdEnrl, SCARD_ENROLL_OFFLINE_CERT_TEMPLATE Or SCARD_ENROLL_CROSS_CERT_TEMPLATE, "O") bAnyElements=bAnyElements Or bAnyElementsReturn ' if there are no templates, we're kinda stuck If False=bAnyElements Then %> <% End If ' set the return value and exit If 0<>Err.Number Then WriteTemplateError Err.Number WriteTemplateList=Err.Number ElseIf False=bAnyElements Then ' signal no elements with -1 WriteTemplateList=-1 Else WriteTemplateList=0 End If End Function '----------------------------------------------------------------- ' write an error message to the web page Sub WriteTemplateError(nErrNumber) %> <% End Sub '----------------------------------------------------------------- ' enumerate the templates the match the given flags and add them to the web page Function EnumTemplates(SCrdEnrl, nRequestedTemplateFlags, sPrefix) Dim nNumTemplates, sRealName, sDisplayName, nTemplateIndex, nNumCAs, nCAIndex, oElement, bAnyElements Dim sKeySpec, sKeyFlags, sCSP, sCSPs, sSubjectFlags, sPrivateKeyFlags, sEnrollmentFlags Dim sCTE, sCTEOid, sCTEMajor, sCTEMinor, sCTEMinorFlag, sRASignature Const SCARD_CTINFO_KEYSPEC=1 Const SCARD_CTINFO_KEYFLAGS=2 Const SCARD_CTINFO_EXT_OID=3 Const SCARD_CTINFO_EXT_MAJOR=4 Const SCARD_CTINFO_EXT_MINOR=5 Const SCARD_CTINFO_EXT_MINOR_FLAG=6 Const SCARD_CTINFO_SUBJECTFLAG=7 Const SCARD_CTINFO_CSPLIST_FIRST=8 Const SCARD_CTINFO_CSPLIST_NEXT=9 Const SCARD_CTINFO_GENERALFLAGS=10 Const SCARD_CTINFO_ENROLLMENTFLAGS=11 Const SCARD_CTINFO_PRIVATEKEYFLAGS=12 Const SCARD_CTINFO_RA_SIGNATURE=13 On Error Resume Next bAnyElements=False ' get the number of known templates nNumTemplates=SCrdEnrl.getCertTemplateCount(nRequestedTemplateFlags) ' loop over all the known templates For nTemplateIndex=1 To nNumTemplates 'get the CertTemplate name sRealName=SCrdEnrl.enumCertTemplateName(nTemplateIndex-1, nRequestedTemplateFlags Or SCARD_ENROLL_CERT_TEMPLATE_REAL_NAME) sDisplayName=SCrdEnrl.enumCertTemplateName(nTemplateIndex-1, nRequestedTemplateFlags Or SCARD_ENROLL_CERT_TEMPLATE_DISPLAY_NAME) ' see it if supported by our CA ' get the number of CAs that support this template nNumCAs=SCrdEnrl.getCACount(sRealName) ' loop over all of those CAs and see if one is ours For nCAIndex=1 To nNumCAs ' If we find our CA, add this template to the list If sServerConfig=SCrdEnrl.enumCAName(nCAIndex-1, SCARD_ENROLL_CA_UNIQUE_NAME, sRealName) Then 'get template extension info 'Stop sKeySpec = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_KEYSPEC)) sKeyFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_KEYFLAGS)) sEnrollmentFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_ENROLLMENTFLAGS)) 'get private key flags sPrivateKeyFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_PRIVATEKEYFLAGS)) sSubjectFlags = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_SUBJECTFLAG)) 'get # of RA signatures sRASignature = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_RA_SIGNATURE)) 'get csp list separated by ? sCSPs = Empty sCSP = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_CSPLIST_FIRST) While Not IsEmpty(sCSP) If IsEmpty(sCSPs) Then sCSPs = sCSP Else sCSPs = sCSPs + "?" + sCSP End If sCSP = Empty sCSP = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_CSPLIST_NEXT) Wend 'above actually return no more item error so clean up Err.Clear sCTEOid = SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_OID) If ""=sCTEOid Then sCTE=";;;" Else sCTEMajor = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MAJOR)) sCTEMinorFlag = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MINOR_FLAG)) sCTEMinor = CStr(SCrdEnrl.getCertTemplateInfo(sRealName, SCARD_CTINFO_EXT_MINOR)) sCTE = sCTEOid & ";" & sCTEMajor & ";" & sCTEMinorFlag & ";" & sCTEMinor End If ' add it to the document %> <% bAnyElements=True End If Next ' <- End CA loop Next ' <- End known template loop ' return success EnumTemplates=bAnyElements End Function Function IsUserTemplateAvailable() On Error Resume Next Dim nTest, nNumCAs, nCAIndex Const sUserTemplate="User" 'init IsUserTemplateAvailable = False 'create the scrdenrl object Set SCrdEnrl=Server.CreateObject("SCrdEnr.SCrdEnr.1") ' call an easy method to make sure everything is OK nTest=SCrdEnrl.CSPCount If 0<>Err.Number Then ' something's wrong with SCrdEnrl, just return FALSE Exit Function End If 'see if any CA support User template nNumCAs=SCrdEnrl.getCACount(sUserTemplate) If 0=nNumCAs Then 'no CA support it Exit Function End If 'loop over all of those CAs and see if one is ours For nCAIndex=1 To nNumCAs ' If we find our CA, add this template to the list If sServerConfig=SCrdEnrl.enumCAName(nCAIndex-1, SCARD_ENROLL_CA_UNIQUE_NAME, sUserTemplate) Then IsUserTemplateAvailable = True Exit Function 'found it End If Next 'CA loop End Function 'IsUserTemplateAvailable %>