x509-ocsp-0.4.0.1: Basic X509 OCSP implementation
Copyright(c) Alexey Radkov 2024
LicenseBSD-style
Maintaineralexey.radkov@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.X509.OCSP

Description

Encode and decode X509 OCSP requests and responses.

This module complies with rfc6960.

Synopsis

Shared data

data CertId Source #

Certificate Id.

This data is used when building OCSP requests and parsing OCSP responses.

Constructors

CertId 

Fields

Instances

Instances details
Show CertId Source # 
Instance details

Defined in Data.X509.OCSP

Eq CertId Source # 
Instance details

Defined in Data.X509.OCSP

Methods

(==) :: CertId -> CertId -> Bool #

(/=) :: CertId -> CertId -> Bool #

OCSP request

encodeOCSPRequestASN1 Source #

Arguments

:: Certificate

Certificate

-> Certificate

Issuer certificate

-> ([ASN1], CertId) 

Build and encode OCSP request in ASN.1 format.

The returned value contains the encoded request and an object of type CertId with hashes calculated by the SHA1 algorithm.

encodeOCSPRequest Source #

Arguments

:: Certificate

Certificate

-> Certificate

Issuer certificate

-> (ByteString, CertId) 

Build and encode OCSP request in ASN.1/DER format.

The returned value contains the encoded request and an object of type CertId with hashes calculated by the SHA1 algorithm.

OCSP response

data OCSPResponse Source #

OCSP response data.

Constructors

OCSPResponse 

Fields

Instances

Instances details
Show OCSPResponse Source # 
Instance details

Defined in Data.X509.OCSP

Eq OCSPResponse Source # 
Instance details

Defined in Data.X509.OCSP

data OCSPResponsePayload Source #

Payload data of OCSP response.

Constructors

OCSPResponsePayload 

Fields

data OCSPResponseCertData Source #

Selected certificate data of OCSP response.

Constructors

OCSPResponseCertData 

Fields

decodeOCSPResponse Source #

Arguments

:: CertId

Certificate Id

-> ByteString

OCSP response

-> Either ASN1Error (Maybe OCSPResponse) 

Decode OCSP response.

The value of the certificate id is expected to be equal to what was returned by encodeOCSPRequest as it is used to check the correctness of the response.

The Left value gets returned on parse errors detected by decodeASN1. The Right value with Nothing gets returned on unexpected ASN.1 contents.

OCSP response verification

data OCSPResponseVerificationData Source #

Verification data from OCSP response payload.

This data can be used to verify the signature of the OCSP response with verifySignature. The response is signed with signature ocspRespSignature. Binary data ocspRespDer and algorithm ocspRespSignatureAlg are what has been used to sign the response. The verification process may require the public key of the issuer certificate if it's not been attached in ocspRespCerts. The latter contains a list of signed certificates augmented by DER-encoded tbsCertificate as defined in rfc5280.

See details of signing and verification of OCSP responses in rfc6960.

Below is a simple implementation of the OCSP response signature verification.

{-# LANGUAGE RecordWildCards #-}

-- ...

verifySignature' :: OCSPResponse -> Certificate -> SignatureVerification
verifySignature' resp Certificate {..}
    | Just OCSPResponseVerificationData {..} <-
        getOCSPResponseVerificationData resp =
            verifySignature ocspRespSignatureAlg certPubKey ocspRespDer
                ocspRespSignature
    | otherwise = SignatureFailed SignatureInvalid

Note that the issuer certificate gets passed to verifySignature' rather than looked up in ocspRespCerts. The OCSP Signature Authority Delegation is not checked in this simple example.

To verify update times, check the values of ocspRespCertThisUpdate and ocspRespCertNextUpdate which both must have been constructed as TimeGeneralized.

Constructors

OCSPResponseVerificationData 

Fields

getOCSPResponseVerificationData Source #

Arguments

:: OCSPResponse

OCSP response

-> Maybe OCSPResponseVerificationData 

Get verification data from OCSP response.

The function returns Nothing on unexpected ASN.1 contents.

getOCSPResponseVerificationData' Source #

Arguments

:: [ASN1]

OCSP response payload

-> Maybe OCSPResponseVerificationData 

Get verification data from OCSP response payload.

This is a variant of getOCSPResponseVerificationData that accepts the OCSP response payload in ASN.1 format. The function returns Nothing on unexpected ASN.1 contents.