Certification Server Exit Module (Tough Problem)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    #1

    Certification Server Exit Module (Tough Problem)

    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 ICertManageModu le.
    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
    ICertManageExit ModuleClass which implements the ICertManageModu le , 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.Visua lBasic

    <ComClass([Exit].ClassId, [Exit].InterfaceId, [Exit].EventsId)> _

    Public Class [Exit]

    Inherits System.Attribut e

    Implements CERTEXITLib.ICe rtExit, CERTEXITLib.ICe rtManageModule

    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_INVAL ID As Integer = 0

    Const EXITEVENT_CERTI SSUED As Integer = &H1

    Const EXITEVENT_CERTP ENDING As Integer = &H2

    Const EXITEVENT_CERTD ENIED As Integer = &H4

    Const EXITEVENT_CERTR EVOKED As Integer = &H8

    Const EXITEVENT_CERTR ETRIEVEPENDING As Integer = &H10

    Const EXITEVENT_CRLIS SUED As Integer = &H20

    Const EXITEVENT_SHUTD OWN 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(ByVa l strConfig As String) As Integer Implements
    CERTEXITLib.ICe rtExit.Initiali ze

    Return EXITEVENT_CERTI SSUED Or EXITEVENT_CERTR EVOKED

    End Function

    Public Sub Notify(ByVal ExitEvent As Integer, ByVal Context As Integer)
    Implements CERTEXITLib.ICe rtExit.Notify

    Dim EventLog As New System.Diagnost ics.EventLog

    Try

    Select Case ExitEvent

    Case EXITEVENT_CERTI SSUED

    EventLog.WriteE ntry("Cert Event - Certificate Issued")

    Dim CertExitObject As New CERTCLIENTLib.C CertServerExit

    CertExitObject. SetContext(Cont ext)

    Dim strSerialNumber As String

    Try

    strSerialNumber =
    CType(CertExitO bject.GetCertif icateProperty(" SerialNumber",
    PROPTYPE_STRING ), String)

    Catch ex As Exception

    strSerialNumber = Nothing

    End Try

    If strSerialNumber = Nothing Then

    EventLog.WriteE ntry("Serial number type conversion failed")

    Exit Sub

    End If

    EventLog.WriteE ntry("Serial Number of issued certificate = " &
    strSerialNumber )

    Case EXITEVENT_CERTR EVOKED

    EventLog.WriteE ntry("Cert Event - Certificate Revoked")

    Case Else

    End Select

    Catch ex As Exception

    EventLog.WriteE ntry("There was an unhandled exception")

    End Try

    End Sub

    Public Function GetDescription( ) As String Implements
    CERTEXITLib.ICe rtExit.GetDescr iption

    Return "Custom Exit Module (Dev)"

    End Function

    Public Sub Configure(ByVal strConfig As String, ByVal strStorageLocat ion As
    String, ByVal Flags As Integer) Implements
    CERTEXITLib.ICe rtManageModule. Configure

    End Sub

    Public Function GetProperty(ByV al strConfig As String, ByVal
    strStorageLocat ion As String, ByVal strPropertyName As String, ByVal Flags
    As Integer) As Object Implements CERTEXITLib.ICe rtManageModule. GetProperty

    Return Nothing

    End Function

    Public Sub SetProperty(ByV al strConfig As String, ByVal strStorageLocat ion
    As String, ByVal strPropertyName As String, ByVal Flags As Integer, ByRef
    pvarProperty As Object) Implements CERTEXITLib.ICe rtManageModule. SetProperty

    End Sub



    Public Sub New()

    MyBase.new()

    End Sub

    End Class




Working...