I am trying to write an Exit module for the Certification server in VB.NET
and I cant get the module to be recognised by the Certification MMC snap in.
Its function is to capture Serial Numbers of newly created certificates.
This is quite obscure and I cant really find any example code. On the face
of it it looks pretty straightforward.
I have created a Class Library and created a class called Exit as this is
suggested for VB, tho I am not sure this is relevant to .Net. I have
referenced the two classes I need and its created the Interop classes. I
have implemented, as the SDK suggests, both ICertExit and ICertManageModule.
I need both of these for the module any way as I want to be able to have a
dialog. The project has the 'Register for COM Interop' ticked. In OLEVIEW
it's got both the interfaces yet when I try to add it its not presented in
the in list of Exit Modules in the Certificate Authority MMC properties
page.
I added the ComClass attribute in an attempt to get it to work, seems to
makes no obvious difference apart from adding more GUID's to the registry.
When I click the Add button on the Exit Modules dialog, a check with RegMon
shows me that it enumerates all the com classes and picks up
ICertManageExitModuleClass which implements the ICertManageModule , but
irritatingly not my Class which also implements that interface.
I am doing something wrong, anyone know what?
Alex
The code -
Imports System.security.Cryptography
Imports Microsoft.VisualBasic
<ComClass([Exit].ClassId, [Exit].InterfaceId, [Exit].EventsId)> _
Public Class [Exit]
Inherits System.Attribute
Implements CERTEXITLib.ICertExit, CERTEXITLib.ICertManageModule
Public Const ClassId As String = "0CFBCAED-CECA-4f74-8589-38B4EBB65F9B"
Public Const InterfaceId As String = "D2E8E505-B72F-46b1-BC80-464D1C8B3D7B"
Public Const EventsId As String = "BA4CD6A0-8909-49a4-A47D-2B3F2D8D3810"
' Values of interest for Initialize
Const EXITEVENT_INVALID As Integer = 0
Const EXITEVENT_CERTISSUED As Integer = &H1
Const EXITEVENT_CERTPENDING As Integer = &H2
Const EXITEVENT_CERTDENIED As Integer = &H4
Const EXITEVENT_CERTREVOKED As Integer = &H8
Const EXITEVENT_CERTRETRIEVEPENDING As Integer = &H10
Const EXITEVENT_CRLISSUED As Integer = &H20
Const EXITEVENT_SHUTDOWN As Integer = &H40
Const PROPTYPE_LONG As Integer = &H1
Const PROPTYPE_DATE As Integer = &H2
Const PROPTYPE_BINARY As Integer = &H3
Const PROPTYPE_STRING As Integer = &H4
Public Function Initialize(ByVal strConfig As String) As Integer Implements
CERTEXITLib.ICertExit.Initialize
Return EXITEVENT_CERTISSUED Or EXITEVENT_CERTREVOKED
End Function
Public Sub Notify(ByVal ExitEvent As Integer, ByVal Context As Integer)
Implements CERTEXITLib.ICertExit.Notify
Dim EventLog As New System.Diagnostics.EventLog
Try
Select Case ExitEvent
Case EXITEVENT_CERTISSUED
EventLog.WriteEntry("Cert Event - Certificate Issued")
Dim CertExitObject As New CERTCLIENTLib.CCertServerExit
CertExitObject.SetContext(Context)
Dim strSerialNumber As String
Try
strSerialNumber =
CType(CertExitObject.GetCertificateProperty("Seria lNumber",
PROPTYPE_STRING), String)
Catch ex As Exception
strSerialNumber = Nothing
End Try
If strSerialNumber = Nothing Then
EventLog.WriteEntry("Serial number type conversion failed")
Exit Sub
End If
EventLog.WriteEntry("Serial Number of issued certificate = " &
strSerialNumber)
Case EXITEVENT_CERTREVOKED
EventLog.WriteEntry("Cert Event - Certificate Revoked")
Case Else
End Select
Catch ex As Exception
EventLog.WriteEntry("There was an unhandled exception")
End Try
End Sub
Public Function GetDescription() As String Implements
CERTEXITLib.ICertExit.GetDescription
Return "Custom Exit Module (Dev)"
End Function
Public Sub Configure(ByVal strConfig As String, ByVal strStorageLocation As
String, ByVal Flags As Integer) Implements
CERTEXITLib.ICertManageModule.Configure
End Sub
Public Function GetProperty(ByVal strConfig As String, ByVal
strStorageLocation As String, ByVal strPropertyName As String, ByVal Flags
As Integer) As Object Implements CERTEXITLib.ICertManageModule.GetProperty
Return Nothing
End Function
Public Sub SetProperty(ByVal strConfig As String, ByVal strStorageLocation
As String, ByVal strPropertyName As String, ByVal Flags As Integer, ByRef
pvarProperty As Object) Implements CERTEXITLib.ICertManageModule.SetProperty
End Sub
Public Sub New()
MyBase.new()
End Sub
End Class