iPXE
|
Online Certificate Status Protocol. More...
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/asn1.h>
#include <ipxe/x509.h>
#include <ipxe/sha1.h>
#include <ipxe/base64.h>
#include <ipxe/uri.h>
#include <ipxe/ocsp.h>
#include <config/crypto.h>
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER) | |
static void | ocsp_free (struct refcnt *refcnt) |
Free OCSP check. More... | |
static int | ocsp_request (struct ocsp_check *ocsp) |
Build OCSP request. More... | |
static int | ocsp_uri_string (struct ocsp_check *ocsp) |
Build OCSP URI string. More... | |
int | ocsp_check (struct x509_certificate *cert, struct x509_certificate *issuer, struct ocsp_check **ocsp) |
Create OCSP check. More... | |
static int | ocsp_parse_response_status (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP response status. More... | |
static int | ocsp_parse_response_type (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP response type. More... | |
static int | ocsp_compare_responder_name (struct ocsp_check *ocsp, struct x509_certificate *cert) |
Compare responder's certificate name. More... | |
static int | ocsp_compare_responder_key_hash (struct ocsp_check *ocsp, struct x509_certificate *cert) |
Compare responder's certificate public key hash. More... | |
static int | ocsp_parse_responder_id (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP responder ID. More... | |
static int | ocsp_parse_cert_id (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP certificate ID. More... | |
static int | ocsp_parse_responses (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP responses. More... | |
static int | ocsp_parse_tbs_response_data (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP response data. More... | |
static int | ocsp_parse_certs (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP certificates. More... | |
static int | ocsp_parse_basic_response (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP basic response. More... | |
static int | ocsp_parse_response_bytes (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP response bytes. More... | |
static int | ocsp_parse_response (struct ocsp_check *ocsp, const struct asn1_cursor *raw) |
Parse OCSP response. More... | |
int | ocsp_response (struct ocsp_check *ocsp, const void *data, size_t len) |
Receive OCSP response. More... | |
static int | ocsp_check_signature (struct ocsp_check *ocsp, struct x509_certificate *signer) |
Check OCSP response signature. More... | |
int | ocsp_validate (struct ocsp_check *ocsp, time_t time) |
Validate OCSP response. More... | |
Variables | |
static const uint8_t | ocsp_algorithm_id [] |
OCSP digest algorithm identifier. More... | |
static const uint8_t | oid_basic_response_type [] = { ASN1_OID_OCSP_BASIC } |
OCSP basic response type. More... | |
static struct asn1_cursor | oid_basic_response_type_cursor |
OCSP basic response type cursor. More... | |
Online Certificate Status Protocol.
Definition in file ocsp.c.
#define EACCES_CERT_STATUS __einfo_error ( EINFO_EACCES_CERT_STATUS ) |
#define EINFO_EACCES_CERT_STATUS |
#define EACCES_CERT_MISMATCH __einfo_error ( EINFO_EACCES_CERT_MISMATCH ) |
#define EINFO_EACCES_CERT_MISMATCH |
#define EACCES_NON_OCSP_SIGNING __einfo_error ( EINFO_EACCES_NON_OCSP_SIGNING ) |
#define EINFO_EACCES_NON_OCSP_SIGNING |
#define EACCES_STALE __einfo_error ( EINFO_EACCES_STALE ) |
#define EINFO_EACCES_STALE |
#define EACCES_NO_RESPONDER __einfo_error ( EINFO_EACCES_NO_RESPONDER ) |
#define EINFO_EACCES_NO_RESPONDER |
#define ENOTSUP_RESPONSE_TYPE __einfo_error ( EINFO_ENOTSUP_RESPONSE_TYPE ) |
#define EINFO_ENOTSUP_RESPONSE_TYPE |
#define ENOTSUP_RESPONDER_ID __einfo_error ( EINFO_ENOTSUP_RESPONDER_ID ) |
#define EINFO_ENOTSUP_RESPONDER_ID |
#define EPROTO_MALFORMED_REQUEST __einfo_error ( EINFO_EPROTO_MALFORMED_REQUEST ) |
#define EINFO_EPROTO_MALFORMED_REQUEST |
#define EPROTO_INTERNAL_ERROR __einfo_error ( EINFO_EPROTO_INTERNAL_ERROR ) |
#define EINFO_EPROTO_INTERNAL_ERROR |
#define EPROTO_TRY_LATER __einfo_error ( EINFO_EPROTO_TRY_LATER ) |
#define EINFO_EPROTO_TRY_LATER |
#define EPROTO_SIG_REQUIRED __einfo_error ( EINFO_EPROTO_SIG_REQUIRED ) |
#define EINFO_EPROTO_SIG_REQUIRED |
#define EPROTO_UNAUTHORIZED __einfo_error ( EINFO_EPROTO_UNAUTHORIZED ) |
#define EINFO_EPROTO_UNAUTHORIZED |
#define EPROTO_STATUS | ( | status | ) |
#define ocsp_digest_algorithm sha1_algorithm |
FILE_LICENCE | ( | GPL2_OR_LATER | ) |
|
static |
Free OCSP check.
refcnt | Reference count |
Definition at line 126 of file ocsp.c.
References ocsp_request::builder, ocsp_check::cert, container_of, asn1_builder::data, ocsp_response::data, free, ocsp_check::issuer, ocsp_check::request, ocsp_check::response, ocsp_response::signer, ocsp_check::uri_string, and x509_put().
Referenced by ocsp_check().
|
static |
Build OCSP request.
ocsp | OCSP check |
rc | Return status code |
Definition at line 145 of file ocsp.c.
References asn1_enter(), ASN1_OCTET_STRING, asn1_prepend(), asn1_prepend_raw(), ASN1_SEQUENCE, asn1_skip(), asn1_wrap(), ocsp_request::builder, ocsp_check::cert, ocsp_request::cert_id_tail, asn1_cursor::data, asn1_builder::data, asn1_bit_string::data, DBGC, DBGC2, DBGC2_HDA, digest, digest_final(), digest_init(), digest_update(), ocsp_check::issuer, x509_certificate::issuer, asn1_cursor::len, asn1_builder::len, asn1_bit_string::len, ocsp_algorithm_id, ocsp_digest_algorithm, x509_subject::public_key, x509_issuer::raw, x509_serial::raw, x509_public_key::raw_bits, rc, ocsp_check::request, x509_certificate::serial, strerror(), x509_certificate::subject, and x509_name().
|
static |
Build OCSP URI string.
ocsp | OCSP check |
rc | Return status code |
Definition at line 211 of file ocsp.c.
References x509_extensions::auth_info, base64, base64_encode(), base64_encoded_len(), ocsp_request::builder, ocsp_check::cert, asn1_cursor::data, asn1_builder::data, DBGC, DBGC2, ENOMEM, ENOTTY, x509_certificate::extensions, free, len, asn1_cursor::len, asn1_builder::len, malloc(), memcpy(), NULL, x509_authority_info_access::ocsp, rc, ocsp_check::request, x509_ocsp_responder::uri, uri_encode(), URI_PATH, ocsp_check::uri_string, x509_name(), and zalloc().
Referenced by ocsp_check().
int ocsp_check | ( | struct x509_certificate * | cert, |
struct x509_certificate * | issuer, | ||
struct ocsp_check ** | ocsp | ||
) |
Create OCSP check.
cert | Certificate to check |
issuer | Issuing certificate |
ocsp | OCSP check |
rc | Return status code |
Definition at line 279 of file ocsp.c.
References assert(), ENOMEM, NULL, ocsp_free(), ocsp_put(), ocsp_uri_string(), rc, ref_init, x509_certificate::root, x509_get(), and zalloc().
|
static |
Parse OCSP response status.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 324 of file ocsp.c.
References asn1_enter(), ASN1_ENUMERATED, ocsp_check::cert, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL, EPROTO_STATUS, asn1_cursor::len, memcpy(), OCSP_STATUS_SUCCESSFUL, raw, rc, status, strerror(), and x509_name().
Referenced by ocsp_parse_response().
|
static |
Parse OCSP response type.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 364 of file ocsp.c.
References asn1_compare(), asn1_enter(), ASN1_OID, ocsp_check::cert, asn1_cursor::data, DBGC, DBGC_HDA, ENOTSUP_RESPONSE_TYPE, asn1_cursor::len, memcpy(), oid_basic_response_type_cursor, raw, and x509_name().
Referenced by ocsp_parse_response_bytes().
|
static |
Compare responder's certificate name.
ocsp | OCSP check |
cert | Certificate |
difference | Difference as returned by memcmp() |
Definition at line 390 of file ocsp.c.
References asn1_compare(), ocsp_responder::id, x509_subject::raw, ocsp_response::responder, ocsp_check::response, and x509_certificate::subject.
Referenced by ocsp_parse_responder_id().
|
static |
Compare responder's certificate public key hash.
ocsp | OCSP check |
cert | Certificate |
difference | Difference as returned by memcmp() |
Definition at line 405 of file ocsp.c.
References asn1_enter(), ASN1_OCTET_STRING, ctx, asn1_cursor::data, asn1_bit_string::data, digest, digest_final(), digest_init(), digest_update(), ocsp_responder::id, asn1_cursor::len, asn1_bit_string::len, memcmp(), memcpy(), x509_subject::public_key, x509_public_key::raw_bits, ocsp_response::responder, ocsp_check::response, sha1_algorithm, SHA1_CTX_SIZE, SHA1_DIGEST_SIZE, and x509_certificate::subject.
Referenced by ocsp_parse_responder_id().
|
static |
Parse OCSP responder ID.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 440 of file ocsp.c.
References asn1_enter_any(), ASN1_EXPLICIT_TAG, asn1_type(), ocsp_check::cert, ocsp_responder::compare, DBGC, DBGC2, ENOTSUP_RESPONDER_ID, ocsp_responder::id, memcpy(), ocsp_compare_responder_key_hash(), ocsp_compare_responder_name(), raw, ocsp_response::responder, ocsp_check::response, type, and x509_name().
Referenced by ocsp_parse_tbs_response_data().
|
static |
Parse OCSP certificate ID.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 477 of file ocsp.c.
References algorithm, asn1_compare(), asn1_enter(), ASN1_OID, ASN1_SEQUENCE, asn1_shrink(), asn1_skip(), ocsp_check::cert, ocsp_request::cert_id_tail, asn1_cursor::data, DBGC, DBGC_HDA, EACCES_CERT_MISMATCH, asn1_cursor::len, memcpy(), ocsp_algorithm_id, raw, rc, ocsp_check::request, and x509_name().
Referenced by ocsp_parse_responses().
|
static |
Parse OCSP responses.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 529 of file ocsp.c.
References asn1_enter(), ASN1_EXPLICIT_TAG, asn1_generalized_time(), ASN1_IMPLICIT_TAG, ASN1_SEQUENCE, asn1_skip_any(), asn1_type(), ocsp_check::cert, asn1_cursor::data, DBGC, DBGC2, DBGC_HDA, EACCES_CERT_STATUS, asn1_cursor::len, memcpy(), ocsp_response::next_update, NULL, ocsp_parse_cert_id(), raw, rc, ocsp_check::response, strerror(), ocsp_response::this_update, time, and x509_name().
Referenced by ocsp_parse_tbs_response_data().
|
static |
Parse OCSP response data.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 602 of file ocsp.c.
References asn1_enter(), ASN1_EXPLICIT_TAG, ASN1_SEQUENCE, asn1_shrink_any(), asn1_skip_any(), asn1_skip_if_exists(), memcpy(), ocsp_parse_responder_id(), ocsp_parse_responses(), raw, rc, ocsp_check::response, and ocsp_response::tbs.
Referenced by ocsp_parse_basic_response().
|
static |
Parse OCSP certificates.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 641 of file ocsp.c.
References asn1_enter(), ASN1_EXPLICIT_TAG, ASN1_SEQUENCE, asn1_skip_any(), ocsp_check::cert, ocsp_responder::compare, asn1_cursor::data, DBGC, DBGC2, DBGC_HDA, EACCES_NO_RESPONDER, asn1_cursor::len, memcpy(), raw, rc, ocsp_response::responder, ocsp_check::response, ocsp_response::signer, strerror(), x509_name(), and x509_put().
Referenced by ocsp_parse_basic_response().
|
static |
Parse OCSP basic response.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 700 of file ocsp.c.
References ocsp_response::algorithm, algorithm, asn1_enter(), ASN1_EXPLICIT_TAG, asn1_integral_bit_string(), ASN1_SEQUENCE, asn1_signature_algorithm(), asn1_skip_any(), asn1_type(), ocsp_check::cert, DBGC, DBGC2, memcpy(), ocsp_parse_certs(), ocsp_parse_tbs_response_data(), raw, rc, ocsp_check::response, signature, ocsp_response::signature, strerror(), and x509_name().
Referenced by ocsp_parse_response_bytes().
|
static |
Parse OCSP response bytes.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 751 of file ocsp.c.
References asn1_enter(), ASN1_EXPLICIT_TAG, ASN1_OCTET_STRING, ASN1_SEQUENCE, asn1_skip_any(), memcpy(), ocsp_parse_basic_response(), ocsp_parse_response_type(), raw, and rc.
Referenced by ocsp_parse_response().
|
static |
Parse OCSP response.
ocsp | OCSP check |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 783 of file ocsp.c.
References asn1_enter(), ASN1_SEQUENCE, asn1_skip_any(), memcpy(), ocsp_parse_response_bytes(), ocsp_parse_response_status(), raw, and rc.
Referenced by ocsp_response().
int ocsp_response | ( | struct ocsp_check * | ocsp, |
const void * | data, | ||
size_t | len | ||
) |
Receive OCSP response.
ocsp | OCSP check |
data | Response data |
len | Length of response data |
rc | Return status code |
Definition at line 812 of file ocsp.c.
References data, asn1_cursor::data, ocsp_response::data, ENOMEM, free, len, asn1_cursor::len, malloc(), memcpy(), NULL, ocsp_parse_response(), rc, ocsp_check::response, ocsp_response::signer, and x509_put().
|
static |
Check OCSP response signature.
ocsp | OCSP check |
signer | Signing certificate |
rc | Return status code |
Definition at line 842 of file ocsp.c.
References ocsp_response::algorithm, ocsp_check::cert, pubkey_algorithm::ctxsize, asn1_cursor::data, asn1_bit_string::data, DBGC, DBGC2, digest, asn1_algorithm::digest, digest_final(), digest_init(), digest_update(), asn1_cursor::len, asn1_bit_string::len, asn1_algorithm::pubkey, pubkey_final(), pubkey_init(), pubkey_verify(), x509_subject::public_key, x509_public_key::raw, rc, ocsp_check::response, ocsp_response::signature, strerror(), x509_certificate::subject, ocsp_response::tbs, and x509_name().
Referenced by ocsp_validate().
int ocsp_validate | ( | struct ocsp_check * | ocsp, |
time_t | time | ||
) |
Validate OCSP response.
ocsp | OCSP check |
time | Time at which to validate response |
rc | Return status code |
Definition at line 892 of file ocsp.c.
References assert(), x509_extensions::auth_info, x509_extended_key_usage::bits, ocsp_check::cert, ocsp_response::data, DBGC, DBGC2, EACCES_NON_OCSP_SIGNING, EACCES_STALE, x509_extensions::ext_usage, x509_certificate::extensions, x509_ocsp_responder::good, ocsp_check::issuer, ocsp_response::next_update, NULL, x509_authority_info_access::ocsp, ocsp_check_signature(), rc, ocsp_check::response, x509_certificate::root, ocsp_response::signer, strerror(), ocsp_response::this_update, time, TIMESTAMP_ERROR_MARGIN, x509_invalidate(), x509_name(), X509_OCSP_SIGNING, and x509_validate().
Referenced by validator_ocsp_validate().
|
static |
OCSP digest algorithm identifier.
Definition at line 111 of file ocsp.c.
Referenced by ocsp_parse_cert_id(), and ocsp_request().
|
static |
|
static |
OCSP basic response type cursor.
Definition at line 118 of file ocsp.c.
Referenced by ocsp_parse_response_type().