Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oBdCrl
LOCAL oAsn
LOCAL oXml
LOCAL i
LOCAL nCount_i
LOCAL cTagPath
LOCAL j
LOCAL nCount_j
LOCAL k
LOCAL nCount_k
LOCAL cRevokedCertSerialHex
LOCAL cDateRevoked
LOCAL oDt

nSuccess := 0

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

//  Load a binary .crl file.
oBdCrl := CreateObject("Chilkat.BinData")
nSuccess := oBdCrl:LoadFile("qa_data/crl/ca1.crl")
IF (nSuccess != 1)
    ? "Failed to load CRL file."
    oBdCrl:destroy()
    RETURN
ENDIF

oAsn := CreateObject("Chilkat.Asn")
nSuccess := oAsn:LoadBd(oBdCrl)
IF (nSuccess != 1)
    ? oAsn:LastErrorText
    oBdCrl:destroy()
    oAsn:destroy()
    RETURN
ENDIF

//  Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
oXml := CreateObject("Chilkat.Xml")
oXml:LoadXml(oAsn:AsnToXml())
nSuccess := oXml:SaveXml("qa_output/crl.xml")

//  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

oDt := CreateObject("Chilkat.CkDateTime")

i := 0
nCount_i := oXml:NumChildrenHavingTag("sequence")
DO WHILE i < nCount_i
    oXml:I := i

    j := 0
    nCount_j := oXml:NumChildrenHavingTag("sequence[i]|sequence")
    DO WHILE j < nCount_j
        oXml:J := j

        k := 0
        nCount_k := oXml:NumChildrenHavingTag("sequence[i]|sequence[j]|sequence")
        DO WHILE k < nCount_k
            oXml:K := k

            //  Get the revoked certificate's serial number in uppercase hex.
            cRevokedCertSerialHex := oXml:GetChildContent("sequence[i]|sequence[j]|sequence[k]|int")
            ? "serial number: " + cRevokedCertSerialHex

            //  Get the date/time revoked.  It will be a string formatted as "YYMMDDhhmmssZ", such as "181023093028Z"
            cDateRevoked := oXml:GetChildContent("sequence[i]|sequence[j]|sequence[k]|utctime")

            //  Starting in Chilkat v9.5.0.77, date/time strings formatted as YYMMDDhhmmssZ can be parsed as follows:
            oDt:SetFromTimestamp(cDateRevoked)
            ? "date revoked: " + oDt:GetAsRfc822(0)

            k := k + 1
        ENDDO
        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oBdCrl:destroy()
oAsn:destroy()
oXml:destroy()
oDt:destroy()