Sample code for 30+ languages & platforms
DataFlex

Load .crl, Convert to XML, Get Revoked Serial Numbers and Dates

See more Certificates Examples

Load a binary .crl file (Certificate Revocation List), converts to XML, and then gets the revoked certificate serial numbers and revocation dates.

Note: This example requires Chilkat v9.5.0.77 or greater.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vBdCrl
    Handle hoBdCrl
    Handle hoAsn
    Handle hoXml
    Integer i
    Integer iCount_i
    String sTagPath
    Integer j
    Integer iCount_j
    Integer k
    Integer iCount_k
    String sRevokedCertSerialHex
    String sDateRevoked
    Handle hoDt
    String sTemp1

    Move False To iSuccess

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Load a binary .crl file.
    Get Create (RefClass(cComChilkatBinData)) To hoBdCrl
    If (Not(IsComObjectCreated(hoBdCrl))) Begin
        Send CreateComObject of hoBdCrl
    End
    Get ComLoadFile Of hoBdCrl "qa_data/crl/ca1.crl" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Failed to load CRL file."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatAsn)) To hoAsn
    If (Not(IsComObjectCreated(hoAsn))) Begin
        Send CreateComObject of hoAsn
    End
    Get pvComObject of hoBdCrl to vBdCrl
    Get ComLoadBd Of hoAsn vBdCrl To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoAsn To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Get ComAsnToXml Of hoAsn To sTemp1
    Get ComLoadXml Of hoXml sTemp1 To iSuccess
    Get ComSaveXml Of hoXml "qa_output/crl.xml" To iSuccess

    // Use this online tool to generate parsing code from CRL XML: 
    // Generate Parsing Code from XML

    // Here's code to parse the XML.  This code was generated by the above tool,
    // and then we modified it by removing unneeded code and changing some names

    Get Create (RefClass(cComCkDateTime)) To hoDt
    If (Not(IsComObjectCreated(hoDt))) Begin
        Send CreateComObject of hoDt
    End

    Move 0 To i
    Get ComNumChildrenHavingTag Of hoXml "sequence" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoXml To i

        Move 0 To j
        Get ComNumChildrenHavingTag Of hoXml "sequence[i]|sequence" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoXml To j

            Move 0 To k
            Get ComNumChildrenHavingTag Of hoXml "sequence[i]|sequence[j]|sequence" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoXml To k

                // Get the revoked certificate's serial number in uppercase hex.
                Get ComGetChildContent Of hoXml "sequence[i]|sequence[j]|sequence[k]|int" To sRevokedCertSerialHex
                Showln "serial number: " sRevokedCertSerialHex

                // Get the date/time revoked.  It will be a string formatted as "YYMMDDhhmmssZ", such as "181023093028Z"
                Get ComGetChildContent Of hoXml "sequence[i]|sequence[j]|sequence[k]|utctime" To sDateRevoked

                // Starting in Chilkat v9.5.0.77, date/time strings formatted as YYMMDDhhmmssZ can be parsed as follows:
                Get ComSetFromTimestamp Of hoDt sDateRevoked To iSuccess
                Get ComGetAsRfc822 Of hoDt False To sTemp1
                Showln "date revoked: " sTemp1

                Move (k + 1) To k
            Loop

            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure