home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / security / certsvr / policyvb / policy.cls < prev    next >
Encoding:
Text File  |  1997-05-29  |  5.7 KB  |  163 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Policy"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. Private Const szOID_TEST1 As String = "0.1.2.3.4.5.6.0"
  11. Private Const szOID_TEST2 As String = "0.1.2.3.4.5.6.1"
  12. Private Const szOID_TEST3 As String = "0.1.2.3.4.5.6.2"
  13.  
  14. Public Function Initialize( _
  15.     strConfig As String)
  16. End Function
  17.  
  18. Public Function ShutDown()
  19. End Function
  20.  
  21. Public Function GetDescription() As String
  22.     GetDescription = "Property Form VB U/I Test Policy Module"
  23. End Function
  24.  
  25. Public Function VerifyRequest( _
  26.     strConfig As String, _
  27.     Context As Long, _
  28.     bNewRequest As Long, _
  29.     Flags As Long) As Long
  30.     
  31.     Dim Str As String
  32.     Dim PolicyForm As policyvb
  33.     Dim CertServer As CCertServerPolicy
  34.     Dim StringArray As CCertEncodeStringArray
  35.     Dim SampleStructure1 As CCertEncodeSampleStructure1
  36.     Dim Extension As String
  37.     Dim NotBefore As Date
  38.     Dim NotAfter As Date
  39.     
  40.     Set CertServer = New CCertServerPolicy
  41.     Set StringArray = New CCertEncodeStringArray
  42.     Set SampleStructure1 = New CCertEncodeSampleStructure1
  43.     Set PolicyForm = New policyvb
  44.     
  45.     CertServer.SetContext Context
  46.      
  47.     'Collect user information from the request:
  48.     Str = CertServer.GetRequestProperty(wszPROPSUBJECTDOT & wszPROPCOMMONNAME, PROPTYPE_STRING)
  49.     If (Len(Str) <> 0) Then
  50.         CertServer.SetCertificateProperty wszPROPSUBJECTDOT & wszPROPCOMMONNAME, PROPTYPE_STRING, Str
  51.     End If
  52.     PolicyForm.NameText.Text = Str
  53.  
  54.     Str = CertServer.GetRequestAttribute(wszCERT_VERSION)
  55.     PolicyForm.VersionText.Text = Str
  56.     
  57.     Str = CertServer.GetRequestAttribute(wszCERT_TYPE)
  58.     PolicyForm.RequestTypeText.Text = Str
  59.     
  60.     Str = CertServer.GetCertificateProperty(wszPROPSUBJECTDOT & wszPROPORGANIZATION, PROPTYPE_STRING)
  61.     If (Len(Str) <> 0) Then
  62.         CertServer.SetCertificateProperty wszPROPSUBJECTDOT & wszPROPORGANIZATION, PROPTYPE_STRING, Str
  63.     End If
  64.     PolicyForm.OrgText.Text = Str
  65.     
  66.     Str = CertServer.GetCertificateProperty(wszPROPSUBJECTDOT & wszPROPORGUNIT, PROPTYPE_STRING)
  67.     If (Len(Str) <> 0) Then
  68.         CertServer.SetCertificateProperty wszPROPSUBJECTDOT & wszPROPORGUNIT, PROPTYPE_STRING, Str
  69.     End If
  70.     PolicyForm.OrgUnitText.Text = Str
  71.     
  72.     Str = CertServer.GetCertificateProperty(wszPROPSUBJECTDOT & wszPROPLOCALITY, PROPTYPE_STRING)
  73.     If (Len(Str) <> 0) Then
  74.         CertServer.SetCertificateProperty wszPROPSUBJECTDOT & wszPROPLOCALITY, PROPTYPE_STRING, Str
  75.     End If
  76.     PolicyForm.LocalityText.Text = Str
  77.     
  78.     Str = CertServer.GetCertificateProperty(wszPROPSUBJECTDOT & wszPROPSTATE, PROPTYPE_STRING)
  79.     If (Len(Str) <> 0) Then
  80.         CertServer.SetCertificateProperty wszPROPSUBJECTDOT & wszPROPSTATE, PROPTYPE_STRING, Str
  81.     End If
  82.  
  83.     Str = CertServer.GetCertificateProperty(wszPROPSUBJECTDOT & wszPROPCOUNTRY, PROPTYPE_STRING)
  84.     If (Len(Str) <> 0) Then
  85.         CertServer.SetCertificateProperty wszPROPSUBJECTDOT & wszPROPCOUNTRY, PROPTYPE_STRING, Str
  86.     End If
  87.     PolicyForm.CountryText.Text = Str
  88.     
  89.     NotBefore = CertServer.GetCertificateProperty(wszPROPCERTIFICATENOTBEFOREDATE, PROPTYPE_DATE)
  90.     PolicyForm.NotBeforeText.Text = CStr(NotBefore)
  91.     
  92.     NotAfter = CertServer.GetCertificateProperty(wszPROPCERTIFICATENOTAFTERDATE, PROPTYPE_DATE)
  93.     PolicyForm.NotAfterText.Text = CStr(NotAfter)
  94.     
  95.     StringArray.Reset 3, CERT_RDN_IA5_STRING
  96.     StringArray.SetValue 0, "VB Test String 1"
  97.     StringArray.SetValue 1, "VB Test String 2"
  98.     StringArray.SetValue 2, "VB Test String 3"
  99.     Extension = StringArray.Encode
  100.     
  101.     CertServer.SetCertificateExtension _
  102.             szOID_TEST1, _
  103.             PROPTYPE_BINARY, _
  104.             EXTENSION_DISABLE_FLAG, _
  105.             Extension
  106.             
  107.     CertServer.SetCertificateExtension _
  108.             szOID_TEST2, _
  109.             PROPTYPE_STRING, _
  110.             EXTENSION_CRITICAL_FLAG, _
  111.             "http://UrlTest.htm"
  112.             
  113.     Extension = SampleStructure1.Encode( _
  114.             "SampleStructure1 String1", _
  115.             "SampleStructure1 String2", _
  116.             39, _
  117.             "BinaryBlob", _
  118.             Now + 1)
  119.             
  120.     CertServer.SetCertificateExtension _
  121.             szOID_TEST3, _
  122.             PROPTYPE_BINARY, _
  123.         0, _
  124.             Extension
  125.     
  126.     'If instructed to do so, grant/deny certificates after 3 second timer expires
  127.     If (Flags) Then PolicyForm.DisplayTimer.Enabled = True
  128.     
  129.     If (StrComp("US", PolicyForm.CountryText.Text, 1) <> 0) Then
  130.         PolicyForm.StatusText.Text = "Request denied; Country must be US!"
  131.         PolicyForm.StatusText.Font.Bold = True
  132.         PolicyForm.CountryText.Font.Strikethrough = True
  133.         PolicyForm.cmdIssue.Enabled = False
  134.         PolicyForm.cmdPending.Enabled = False
  135.     Else
  136.         PolicyForm.StatusText.Text = "Request is acceptable"
  137.     End If
  138.     
  139.     'Display the user information and collect the response:
  140.     PolicyForm.Show 1
  141.     
  142.     'assume VR_INSTANT_BAD:
  143.     VerifyRequest = VR_INSTANT_BAD
  144.         
  145.     'if certificate was accepted or the U/I timed out, and it is acceptable,
  146.     'return VR_INSTANT_OK:
  147.     If (PolicyForm.cmdIssue.Enabled) Then
  148.         If (StrComp("Deny", PolicyForm.Disposition.Text) <> 0) Then
  149.             If (StrComp("Pending", PolicyForm.Disposition.Text) = 0) Then
  150.                 VerifyRequest = VR_PENDING
  151.             Else
  152.                 ' "TimeOut" or "Issue":
  153.                 VerifyRequest = VR_INSTANT_OK
  154.             End If
  155.         End If
  156.     End If
  157.     Set PolicyForm = Nothing
  158.     Set CertServer = Nothing
  159.     Set StringArray = Nothing
  160.     Set SampleStructure1 = Nothing
  161. End Function
  162.  
  163.