iPXE
ocsp.h
Go to the documentation of this file.
1 #ifndef _IPXE_OCSP_H
2 #define _IPXE_OCSP_H
3 
4 /** @file
5  *
6  * Online Certificate Status Protocol
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdarg.h>
14 #include <time.h>
15 #include <ipxe/asn1.h>
16 #include <ipxe/x509.h>
17 #include <ipxe/refcnt.h>
18 #include <config/crypto.h>
19 
20 /* Allow OCSP to be disabled completely */
21 #ifdef OCSP_CHECK
22 #define OCSP_ENABLED 1
23 #else
24 #define OCSP_ENABLED 0
25 #endif
26 
27 /** OCSP algorithm identifier */
28 #define OCSP_ALGORITHM_IDENTIFIER( ... ) \
29  ASN1_OID, VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__, \
30  ASN1_NULL, 0x00
31 
32 /* OCSP response statuses */
33 #define OCSP_STATUS_SUCCESSFUL 0x00
34 #define OCSP_STATUS_MALFORMED_REQUEST 0x01
35 #define OCSP_STATUS_INTERNAL_ERROR 0x02
36 #define OCSP_STATUS_TRY_LATER 0x03
37 #define OCSP_STATUS_SIG_REQUIRED 0x05
38 #define OCSP_STATUS_UNAUTHORIZED 0x06
39 
40 struct ocsp_check;
41 
42 /** An OCSP request */
43 struct ocsp_request {
44  /** Request builder */
46  /** Certificate ID (excluding hashAlgorithm) */
48 };
49 
50 /** An OCSP responder */
52  /**
53  * Check if certificate is the responder's certificate
54  *
55  * @v ocsp OCSP check
56  * @v cert Certificate
57  * @ret difference Difference as returned by memcmp()
58  */
59  int ( * compare ) ( struct ocsp_check *ocsp,
60  struct x509_certificate *cert );
61  /** Responder ID */
62  struct asn1_cursor id;
63 };
64 
65 /** An OCSP response */
66 struct ocsp_response {
67  /** Raw response */
68  void *data;
69  /** Raw tbsResponseData */
70  struct asn1_cursor tbs;
71  /** Responder */
73  /** Time at which status is known to be correct */
75  /** Time at which newer status information will be available */
77  /** Signature algorithm */
79  /** Signature value */
81  /** Signing certificate */
83 };
84 
85 /** An OCSP check */
86 struct ocsp_check {
87  /** Reference count */
88  struct refcnt refcnt;
89  /** Certificate being checked */
91  /** Issuing certificate */
93  /** URI string */
94  char *uri_string;
95  /** Request */
97  /** Response */
99 };
100 
101 /**
102  * Get reference to OCSP check
103  *
104  * @v ocsp OCSP check
105  * @ret ocsp OCSP check
106  */
107 static inline __attribute__ (( always_inline )) struct ocsp_check *
108 ocsp_get ( struct ocsp_check *ocsp ) {
109  ref_get ( &ocsp->refcnt );
110  return ocsp;
111 }
112 
113 /**
114  * Drop reference to OCSP check
115  *
116  * @v ocsp OCSP check
117  */
118 static inline __attribute__ (( always_inline )) void
119 ocsp_put ( struct ocsp_check *ocsp ) {
120  ref_put ( &ocsp->refcnt );
121 }
122 
123 /**
124  * Check if X.509 certificate requires an OCSP check
125  *
126  * @v cert X.509 certificate
127  * @ret ocsp_required An OCSP check is required
128  */
129 static inline int ocsp_required ( struct x509_certificate *cert ) {
130 
131  /* An OCSP check is never required if OCSP checks are disabled */
132  if ( ! OCSP_ENABLED )
133  return 0;
134 
135  /* An OCSP check is required if an OCSP URI exists but the
136  * OCSP status is not (yet) good.
137  */
138  return ( cert->extensions.auth_info.ocsp.uri.len &&
139  ( ! cert->extensions.auth_info.ocsp.good ) );
140 }
141 
142 extern int ocsp_check ( struct x509_certificate *cert,
143  struct x509_certificate *issuer,
144  struct ocsp_check **ocsp );
145 extern int ocsp_response ( struct ocsp_check *ocsp, const void *data,
146  size_t len );
147 extern int ocsp_validate ( struct ocsp_check *check, time_t time );
148 
149 #endif /* _IPXE_OCSP_H */
struct asn1_cursor id
Responder ID.
Definition: ocsp.h:62
#define __attribute__(x)
Definition: compiler.h:10
An ASN.1 OID-identified algorithm.
Definition: asn1.h:408
int ocsp_response(struct ocsp_check *ocsp, const void *data, size_t len)
Receive OCSP response.
Definition: ocsp.c:814
int good
OCSP status is good.
Definition: x509.h:134
time_t next_update
Time at which newer status information will be available.
Definition: ocsp.h:76
struct x509_certificate * signer
Signing certificate.
Definition: ocsp.h:82
#define OCSP_ENABLED
Definition: ocsp.h:24
struct refcnt refcnt
Reference count.
Definition: ocsp.h:88
struct ocsp_response response
Response.
Definition: ocsp.h:98
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct x509_certificate * cert
Certificate being checked.
Definition: ocsp.h:90
static struct ocsp_check * ocsp_get(struct ocsp_check *ocsp)
Get reference to OCSP check.
Definition: ocsp.h:108
struct asn1_algorithm * algorithm
Signature algorithm.
Definition: ocsp.h:78
static int ocsp_required(struct x509_certificate *cert)
Check if X.509 certificate requires an OCSP check.
Definition: ocsp.h:129
An OCSP request.
Definition: ocsp.h:43
size_t len
Length of data.
Definition: asn1.h:25
A reference counter.
Definition: refcnt.h:27
struct asn1_cursor cert_id_tail
Certificate ID (excluding hashAlgorithm)
Definition: ocsp.h:47
An OCSP responder.
Definition: ocsp.h:51
ASN.1 encoding.
struct asn1_cursor tbs
Raw tbsResponseData.
Definition: ocsp.h:70
ring len
Length.
Definition: dwmac.h:231
struct x509_authority_info_access auth_info
Authority information access.
Definition: x509.h:165
int ocsp_validate(struct ocsp_check *check, time_t time)
Validate OCSP response.
Definition: ocsp.c:880
struct asn1_cursor uri
URI.
Definition: x509.h:132
An X.509 certificate.
Definition: x509.h:216
int(* compare)(struct ocsp_check *ocsp, struct x509_certificate *cert)
Check if certificate is the responder's certificate.
Definition: ocsp.h:59
struct x509_certificate * issuer
Issuing certificate.
Definition: ocsp.h:92
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:93
An ASN.1 object builder.
Definition: asn1.h:29
static void ocsp_put(struct ocsp_check *ocsp)
Drop reference to OCSP check.
Definition: ocsp.h:119
time_t this_update
Time at which status is known to be correct.
Definition: ocsp.h:74
X.509 certificates.
void * data
Raw response.
Definition: ocsp.h:68
struct ocsp_request request
Request.
Definition: ocsp.h:96
An OCSP response.
Definition: ocsp.h:66
Cryptographic configuration.
FILE_SECBOOT(PERMITTED)
Reference counting.
struct asn1_cursor signature
Signature value.
Definition: ocsp.h:80
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct ocsp_responder responder
Responder.
Definition: ocsp.h:72
int ocsp_check(struct x509_certificate *cert, struct x509_certificate *issuer, struct ocsp_check **ocsp)
Create OCSP check.
Definition: ocsp.c:280
int64_t time_t
Seconds since the Epoch.
Definition: time.h:19
Time source.
An OCSP check.
Definition: ocsp.h:86
struct x509_ocsp_responder ocsp
OCSP responder.
Definition: x509.h:140
An ASN.1 object cursor.
Definition: asn1.h:21
struct asn1_builder builder
Request builder.
Definition: ocsp.h:45
struct x509_extensions extensions
Extensions.
Definition: x509.h:249
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
char * uri_string
URI string.
Definition: ocsp.h:94