43#define EACCES_CERT_STATUS \
44 __einfo_error ( EINFO_EACCES_CERT_STATUS )
45#define EINFO_EACCES_CERT_STATUS \
46 __einfo_uniqify ( EINFO_EACCES, 0x01, \
47 "Certificate status not good" )
48#define EACCES_CERT_MISMATCH \
49 __einfo_error ( EINFO_EACCES_CERT_MISMATCH )
50#define EINFO_EACCES_CERT_MISMATCH \
51 __einfo_uniqify ( EINFO_EACCES, 0x02, \
52 "Certificate ID mismatch" )
53#define EACCES_NON_OCSP_SIGNING \
54 __einfo_error ( EINFO_EACCES_NON_OCSP_SIGNING )
55#define EINFO_EACCES_NON_OCSP_SIGNING \
56 __einfo_uniqify ( EINFO_EACCES, 0x03, \
57 "Not an OCSP signing certificate" )
59 __einfo_error ( EINFO_EACCES_STALE )
60#define EINFO_EACCES_STALE \
61 __einfo_uniqify ( EINFO_EACCES, 0x04, \
62 "Stale (or premature) OCSP repsonse" )
63#define EACCES_NO_RESPONDER \
64 __einfo_error ( EINFO_EACCES_NO_RESPONDER )
65#define EINFO_EACCES_NO_RESPONDER \
66 __einfo_uniqify ( EINFO_EACCES, 0x05, \
67 "Missing OCSP responder certificate" )
68#define ENOTSUP_RESPONSE_TYPE \
69 __einfo_error ( EINFO_ENOTSUP_RESPONSE_TYPE )
70#define EINFO_ENOTSUP_RESPONSE_TYPE \
71 __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \
72 "Unsupported OCSP response type" )
73#define ENOTSUP_RESPONDER_ID \
74 __einfo_error ( EINFO_ENOTSUP_RESPONDER_ID )
75#define EINFO_ENOTSUP_RESPONDER_ID \
76 __einfo_uniqify ( EINFO_ENOTSUP, 0x02, \
77 "Unsupported OCSP responder ID" )
78#define EPROTO_MALFORMED_REQUEST \
79 __einfo_error ( EINFO_EPROTO_MALFORMED_REQUEST )
80#define EINFO_EPROTO_MALFORMED_REQUEST \
81 __einfo_uniqify ( EINFO_EPROTO, OCSP_STATUS_MALFORMED_REQUEST, \
82 "Illegal confirmation request" )
83#define EPROTO_INTERNAL_ERROR \
84 __einfo_error ( EINFO_EPROTO_INTERNAL_ERROR )
85#define EINFO_EPROTO_INTERNAL_ERROR \
86 __einfo_uniqify ( EINFO_EPROTO, OCSP_STATUS_INTERNAL_ERROR, \
87 "Internal error in issuer" )
88#define EPROTO_TRY_LATER \
89 __einfo_error ( EINFO_EPROTO_TRY_LATER )
90#define EINFO_EPROTO_TRY_LATER \
91 __einfo_uniqify ( EINFO_EPROTO, OCSP_STATUS_TRY_LATER, \
93#define EPROTO_SIG_REQUIRED \
94 __einfo_error ( EINFO_EPROTO_SIG_REQUIRED )
95#define EINFO_EPROTO_SIG_REQUIRED \
96 __einfo_uniqify ( EINFO_EPROTO, OCSP_STATUS_SIG_REQUIRED, \
97 "Must sign the request" )
98#define EPROTO_UNAUTHORIZED \
99 __einfo_error ( EINFO_EPROTO_UNAUTHORIZED )
100#define EINFO_EPROTO_UNAUTHORIZED \
101 __einfo_uniqify ( EINFO_EPROTO, OCSP_STATUS_UNAUTHORIZED, \
102 "Request unauthorized" )
103#define EPROTO_STATUS( status ) \
104 EUNIQ ( EINFO_EPROTO, (status), EPROTO_MALFORMED_REQUEST, \
105 EPROTO_INTERNAL_ERROR, EPROTO_TRY_LATER, \
106 EPROTO_SIG_REQUIRED, EPROTO_UNAUTHORIZED )
109#define ocsp_digest_algorithm sha1_algorithm
170 pubkey_digest,
sizeof ( pubkey_digest ) ),
172 name_digest,
sizeof ( name_digest ) ),
181 DBGC ( ocsp,
"OCSP %p \"%s\" could not build request: %s\n",
185 DBGC2 ( ocsp,
"OCSP %p \"%s\" request is:\n",
191 cert_id_tail->
len = builder->
len;
198 DBGC ( ocsp,
"OCSP %p \"%s\" could not locate certID: %s\n",
223 if ( ! responder->
uri.
len ) {
224 DBGC ( ocsp,
"OCSP %p \"%s\" has no OCSP URI\n",
238 goto err_alloc_base64;
248 len = ( responder->
uri.
len + 1 + uri_len );
259 DBGC2 ( ocsp,
"OCSP %p \"%s\" URI is %s\n",
291 *ocsp =
zalloc (
sizeof ( **ocsp ) );
298 (*ocsp)->issuer =
x509_get ( issuer );
332 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
334 DBGC ( ocsp,
"OCSP %p \"%s\" could not locate responseStatus: "
341 DBGC ( ocsp,
"OCSP %p \"%s\" invalid status:\n",
350 DBGC ( ocsp,
"OCSP %p \"%s\" response status %d\n",
370 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
375 DBGC ( ocsp,
"OCSP %p \"%s\" response type not supported:\n",
415 memcpy ( &key_hash, &responder->
id, sizeof ( key_hash ) );
419 difference = (
sizeof ( digest ) - key_hash.
len );
431 return memcmp ( digest, key_hash.
data, sizeof ( digest ) );
448 memcpy ( responder_id,
raw,
sizeof ( *responder_id ) );
455 DBGC2 ( ocsp,
"OCSP %p \"%s\" responder identified by name\n",
460 DBGC2 ( ocsp,
"OCSP %p \"%s\" responder identified by key "
465 DBGC ( ocsp,
"OCSP %p \"%s\" unsupported responder ID type "
489 memcpy ( &cert_id,
raw,
sizeof ( cert_id ) );
493 memcpy ( &cursor, &cert_id,
sizeof ( cursor ) );
497 DBGC ( ocsp,
"OCSP %p \"%s\" certID missing algorithm:\n",
503 DBGC ( ocsp,
"OCSP %p \"%s\" certID wrong algorithm:\n",
512 DBGC ( ocsp,
"OCSP %p \"%s\" certID mismatch:\n",
537 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
550 DBGC ( ocsp,
"OCSP %p \"%s\" non-good certStatus:\n",
560 DBGC ( ocsp,
"OCSP %p \"%s\" could not parse thisUpdate: %s\n",
564 DBGC2 ( ocsp,
"OCSP %p \"%s\" this update was at time %lld\n",
573 DBGC ( ocsp,
"OCSP %p \"%s\" could not parse "
574 "nextUpdate: %s\n", ocsp,
578 DBGC2 ( ocsp,
"OCSP %p \"%s\" next update is at time %lld\n",
588 DBGC ( ocsp,
"OCSP %p \"%s\" responder is a moron\n",
610 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
612 memcpy ( &response->
tbs, &cursor, sizeof ( response->
tbs ) );
650 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
662 while ( cursor.
len ) {
667 DBGC ( ocsp,
"OCSP %p \"%s\" could not parse "
668 "certificate: %s\n", ocsp,
677 DBGC2 ( ocsp,
"OCSP %p \"%s\" response is signed by ",
679 DBGC2 ( ocsp,
"\"%s\"\n",
689 DBGC ( ocsp,
"OCSP %p \"%s\" missing responder certificate\n",
710 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
720 DBGC ( ocsp,
"OCSP %p \"%s\" cannot parse signature "
725 DBGC2 ( ocsp,
"OCSP %p \"%s\" signature algorithm is %s\n",
732 DBGC ( ocsp,
"OCSP %p \"%s\" cannot parse signature: %s\n",
759 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
791 memcpy ( &cursor,
raw,
sizeof ( cursor ) );
824 if ( ! response->
data )
863 DBGC ( ocsp,
"OCSP %p \"%s\" signature verification failed: "
868 DBGC2 ( ocsp,
"OCSP %p \"%s\" signature is correct\n",
897 if ( signer != ocsp->
issuer ) {
907 DBGC ( ocsp,
"OCSP %p \"%s\" could not validate ",
909 DBGC ( ocsp,
"signer \"%s\": %s\n",
919 DBGC ( ocsp,
"OCSP %p \"%s\" ",
921 DBGC ( ocsp,
"signer \"%s\" is not an OCSP-signing "
935 DBGC ( ocsp,
"OCSP %p \"%s\" response is not yet valid (at "
940 DBGC ( ocsp,
"OCSP %p \"%s\" response is stale (at time "
944 DBGC2 ( ocsp,
"OCSP %p \"%s\" response is valid (at time %lld)\n",
953 DBGC ( ocsp,
"OCSP %p \"%s\" could not validate certificate: "
957 DBGC ( ocsp,
"OCSP %p \"%s\" successfully validated ",
#define NULL
NULL pointer (VOID *)
union @162305117151260234136356364136041353210355154177 key
Sense key.
struct golan_eq_context ctx
u8 signature
CPU signature.
struct arbelprm_rc_send_wqe rc
int asn1_prepend(struct asn1_builder *builder, unsigned int type, const void *data, size_t len)
Prepend data to ASN.1 builder.
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
int asn1_skip_any(struct asn1_cursor *cursor)
Skip ASN.1 object of any type.
int asn1_generalized_time(const struct asn1_cursor *cursor, time_t *time)
Parse ASN.1 GeneralizedTime.
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
int asn1_enter_any(struct asn1_cursor *cursor)
Enter ASN.1 object of any type.
int asn1_skip(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object.
int asn1_enter_bits(struct asn1_cursor *cursor, unsigned int *unused)
Enter ASN.1 bit string.
int asn1_shrink_any(struct asn1_cursor *cursor)
Shrink ASN.1 object of any type.
int asn1_compare(const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2)
Compare two ASN.1 objects.
int asn1_signature_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified signature algorithm.
int asn1_wrap(struct asn1_builder *builder, unsigned int type)
Wrap ASN.1 builder.
int asn1_shrink(struct asn1_cursor *cursor, unsigned int type)
Shrink ASN.1 cursor to fit object.
int asn1_skip_if_exists(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object if present.
#define ASN1_EXPLICIT_TAG(number)
ASN.1 explicit tag.
#define ASN1_OID_SHA1
ASN.1 OID for id-sha1 (1.3.14.3.2.26)
#define ASN1_OID
ASN.1 object identifier.
#define ASN1_OID_OCSP_BASIC
ASN.1 OID for id-pkix-ocsp-basic ( 1.3.6.1.5.5.7.48.1.1)
#define ASN1_ENUMERATED
ASN.1 enumeration.
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
#define ASN1_SEQUENCE
ASN.1 sequence.
#define ASN1_IMPLICIT_TAG(number)
ASN.1 implicit tag.
#define ASN1_OCTET_STRING
ASN.1 octet string.
static unsigned int asn1_type(const struct asn1_cursor *cursor)
Extract ASN.1 type.
#define assert(condition)
Assert a condition at run-time.
size_t base64_encode(const void *raw, size_t raw_len, char *data, size_t len)
Base64-encode data.
static const char base64[64+1]
static size_t base64_encoded_len(size_t raw_len)
Calculate length of base64-encoded data.
Cryptographic configuration.
#define TIMESTAMP_ERROR_MARGIN
Margin of error (in seconds) allowed in signed timestamps.
uint32_t type
Operating system type.
uint8_t data[48]
Additional event data.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define EINVAL
Invalid argument.
#define ENOMEM
Not enough space.
#define ENOTTY
Inappropriate I/O control operation.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
u16 algorithm
Authentication algorithm (Open System or Shared Key)
static void digest_init(struct digest_algorithm *digest, void *ctx)
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
static int pubkey_verify(struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int64_t time_t
Seconds since the Epoch.
void * zalloc(size_t size)
Allocate cleared memory.
void * malloc(size_t size)
Allocate memory.
static const uint8_t ocsp_algorithm_id[]
OCSP digest algorithm identifier.
static int ocsp_request(struct ocsp_check *ocsp)
Build OCSP request.
static int ocsp_parse_certs(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP certificates.
static int ocsp_parse_response(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP response.
static int ocsp_parse_basic_response(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP basic response.
#define EACCES_CERT_STATUS
static int ocsp_parse_response_status(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP response status.
static int ocsp_parse_response_bytes(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP response bytes.
int ocsp_check(struct x509_certificate *cert, struct x509_certificate *issuer, struct ocsp_check **ocsp)
Create OCSP check.
int ocsp_validate(struct ocsp_check *ocsp, time_t time)
Validate OCSP response.
#define EACCES_CERT_MISMATCH
static int ocsp_compare_responder_key_hash(struct ocsp_check *ocsp, struct x509_certificate *cert)
Compare responder's certificate public key hash.
static void ocsp_free(struct refcnt *refcnt)
Free OCSP check.
static int ocsp_parse_responder_id(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP responder ID.
static int ocsp_compare_responder_name(struct ocsp_check *ocsp, struct x509_certificate *cert)
Compare responder's certificate name.
static int ocsp_uri_string(struct ocsp_check *ocsp)
Build OCSP URI string.
#define EPROTO_STATUS(status)
static int ocsp_parse_response_type(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP response type.
#define ocsp_digest_algorithm
OCSP digest algorithm.
#define ENOTSUP_RESPONDER_ID
static int ocsp_parse_responses(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP responses.
static int ocsp_parse_cert_id(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP certificate ID.
static const uint8_t oid_basic_response_type[]
OCSP basic response type.
static int ocsp_parse_tbs_response_data(struct ocsp_check *ocsp, const struct asn1_cursor *raw)
Parse OCSP response data.
static struct asn1_cursor oid_basic_response_type_cursor
OCSP basic response type cursor.
static int ocsp_check_signature(struct ocsp_check *ocsp, struct x509_certificate *signer)
Check OCSP response signature.
#define EACCES_NON_OCSP_SIGNING
#define ENOTSUP_RESPONSE_TYPE
#define EACCES_NO_RESPONDER
int ocsp_response(struct ocsp_check *ocsp, const void *data, size_t len)
Receive OCSP response.
Online Certificate Status Protocol.
#define OCSP_ALGORITHM_IDENTIFIER(...)
OCSP algorithm identifier.
static void ocsp_put(struct ocsp_check *ocsp)
Drop reference to OCSP check.
#define OCSP_STATUS_SUCCESSFUL
static void(* free)(struct refcnt *refcnt))
#define ref_init(refcnt, free)
Initialise a reference counter.
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
#define SHA1_CTX_SIZE
SHA-1 context size.
#define container_of(ptr, type, field)
Get containing structure.
char * strerror(int errno)
Retrieve string representation of error number.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
An ASN.1 OID-identified algorithm.
struct digest_algorithm * digest
Digest algorithm (if applicable)
struct pubkey_algorithm * pubkey
Public-key algorithm (if applicable)
size_t len
Length of data.
const void * data
Start of data.
size_t len
Length of data.
A message digest algorithm.
size_t digestsize
Digest size.
size_t ctxsize
Context size.
char * uri_string
URI string.
struct ocsp_response response
Response.
struct ocsp_request request
Request.
struct x509_certificate * issuer
Issuing certificate.
struct x509_certificate * cert
Certificate being checked.
struct asn1_cursor cert_id_tail
Certificate ID (excluding hashAlgorithm)
struct asn1_builder builder
Request builder.
struct asn1_cursor id
Responder ID.
int(* compare)(struct ocsp_check *ocsp, struct x509_certificate *cert)
Check if certificate is the responder's certificate.
struct asn1_algorithm * algorithm
Signature algorithm.
struct x509_certificate * signer
Signing certificate.
time_t next_update
Time at which newer status information will be available.
time_t this_update
Time at which status is known to be correct.
struct asn1_cursor tbs
Raw tbsResponseData.
struct ocsp_responder responder
Responder.
struct asn1_cursor signature
Signature value.
struct x509_ocsp_responder ocsp
OCSP responder.
struct x509_serial serial
Serial number.
struct x509_subject subject
Subject.
struct x509_extensions extensions
Extensions.
struct x509_root * root
Root against which certificate has been validated (if any)
struct x509_issuer issuer
Issuer.
unsigned int bits
Usage bits.
struct x509_authority_info_access auth_info
Authority information access.
struct x509_extended_key_usage ext_usage
Extended key usage.
struct asn1_cursor raw
Raw issuer.
X.509 certificate OCSP responder.
int good
OCSP status is good.
struct asn1_cursor uri
URI.
struct asn1_cursor value
Public key value.
struct asn1_cursor raw
Raw public key information.
struct asn1_cursor raw
Raw serial number.
struct asn1_cursor raw
Raw subject.
struct x509_public_key public_key
Public key information.
size_t uri_encode(unsigned int field, const void *raw, size_t raw_len, char *buf, ssize_t len)
Encode URI field.
Uniform Resource Identifiers.
int x509_validate(struct x509_certificate *cert, struct x509_certificate *issuer, time_t time, struct x509_root *root)
Validate X.509 certificate.
const char * x509_name(struct x509_certificate *cert)
Get X.509 certificate display name.
static struct x509_certificate * x509_get(struct x509_certificate *cert)
Get reference to X.509 certificate.
static void x509_invalidate(struct x509_certificate *cert)
Invalidate X.509 certificate.
static void x509_put(struct x509_certificate *cert)
Drop reference to X.509 certificate.