Creates an Online Certification Status Protocol (OCSP) request as a base64 string.
Public Declare Function OCSP_MakeRequest Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strIssuerCert As String, ByVal strCertFileOrSerialNum As String, ByVal strExtensions As String, ByVal nOptions As Long) As Long
nRet = OCSP_MakeRequest(strOutput, nOutChars, strIssuerCert, strCertFileOrSerialNum, strExtensions, nOptions)
long __stdcall OCSP_MakeRequest(char *szOutput, long nOutChars, const char *szIssuerCert, const char *szCertFileOrSerialNum, const char *szExtensions, long nOptions);
""
or NULL.If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.
Public Function ocspMakeRequest
(szIssuerCert As String, szCertFileOrSerialNum As String, nOptions As Long, Optional szExtensions As String = "") As String
static std::string dipki::Ocsp::MakeRequest (const std::string &issuerCert, const std::string &certFileOrSerialNumber, HashAlg hashAlg=HashAlg::Sha1)
static Ocsp.make_request(issuercert, certfile_or_serialnumber, hashalg=0)
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
The output is a base64 string suitable for an OCSP request to an Online Certificate Status Manager.
The issuer's X.509 certficate must be specified. The certificate to be checked
can either be specified directly as a filename or as a serialNumber in hexadecimal format preceded by "#x", e.g.
"#x01deadbeef"
.
If the latter format is used, it must be in hexadecimal format, so the serial number 10 would be passed as
"#x0a"
.
It is an error (NO_MATCH_ERROR
) if the issuer's name of the certificate to be checked
does not match the subject name of the issuer's certificate.
The default hash algorithm is SHA-1. Most Online Certificate Status Managers should accept MD5 and SHA-1.
Other hash algorithms may not be accepted.
One way to obtain a response is to paste the URL in the address bar of a web browser to return the status information. The base64 value produced by this function should first be URL-encoded (i.e. "/" replaced by "%2F", "+" replaced by "%2B", and "=" by "%3D"). For example, typing in the Firefox browser URL box
http://ocsp.comodoca.com/MFIwUDBOMEwwSjAJBgUrDgMCGgUABBRtl6lMY2%2BiPob4twryIF%2BFfgUdvwQUK8NGq7oOyWUqRtF5R8Ri4uHa%2FLgCEQD7xyMijIyAItiFkiPe5wZg
should offer to save a file with a name like
MFIwUDBOME...
.
This contains the response, which is a binary file that can be examined using the
OCSP_ReadResponse() function.
This example creates an OCSP request to check our own (old but never revoked) code signing certificate file dims.cer
.
This was issued by the holder of certificate in the file UTNUSERFirst-Object.cer
.
Dim nChars As Long Dim strCertFile As String Dim strIssuerFile As String Dim strBuf As String strIssuerFile = "UTNUSERFirst-Object.cer" strCertFile = "dims.cer" Debug.Print "IssuerFile=" & strIssuerFile Debug.Print "CertFile=" & strCertFile ' Find required length (or error) nChars = OCSP_MakeRequest("", 0, strIssuerFile, strCertFile, "", 0) Debug.Print "OCSP_MakeRequest returns " & nChars & "(expected +ve)" If (nChars <= 0) Then Exit Sub ' ERROR strBuf = String(nChars, " ") nChars = OCSP_MakeRequest(strBuf, nChars, strIssuerFile, strCertFile, "", 0) Debug.Print "OCSPRequest=" & strBuf ' Pass a hex serial number instead of filename strCertFile = "#x 00 FB C7 23 22 8C 8C 80 22 D8 85 92 23 DE E7 06 60" Debug.Print "Cert SerialNumber=" & strCertFile nChars = OCSP_MakeRequest("", 0, strIssuerFile, strCertFile, "", 0) Debug.Print "OCSP_MakeRequest returns " & nChars & "(expected +ve)" If (nChars <= 0) Then Exit Sub ' ERROR strBuf = String(nChars, " ") nChars = OCSP_MakeRequest(strBuf, nChars, strIssuerFile, strCertFile, "", 0) Debug.Print "OCSPRequest=" & strBuf
The above example should produce the following output:
IssuerFile=UTNUSERFirst-Object.cer CertFile=dims.cer OCSP_MakeRequest returns 112(expected +ve) OCSPRequest=MFIwUDBOMEwwSjAJBgUrDgMCGgUABBRtl6lMY2+iPob4twryIF+FfgUdvwQUK8NGq7oOyWUqRtF5R8Ri4uHa/LgCEQD7xyMijIyAItiFkiPe5wZg Cert SerialNumber=#x 00 FB C7 23 22 8C 8C 80 22 D8 85 92 23 DE E7 06 60 OCSP_MakeRequest returns 112(expected +ve) OCSPRequest=MFIwUDBOMEwwSjAJBgUrDgMCGgUABBRtl6lMY2+iPob4twryIF+FfgUdvwQUK8NGq7oOyWUqRtF5R8Ri4uHa/LgCEQD7xyMijIyAItiFkiPe5wZg
Dim strOcsp As String strOcsp = ocspMakeRequest("UTNUSERFirst-Object.cer", "dims.cer", PKI_HASH_SHA1) Debug.Print strOcsp ' Pass serial number instead of filename strOcsp = ocspMakeRequest("UTNUSERFirst-Object.cer", "#x 00 FB C7 23 22 8C 8C 80 22 D8 85 92 23 DE E7 06 60", PKI_HASH_SHA1) Debug.Print strOcsp