blob: c233f136fb354db9987bf72fcba9b6560b6b30bf [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Howellsc26fd692012-09-24 17:11:48 +01002/* X.509 certificate parser internal definitions
3 *
4 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
David Howellsc26fd692012-09-24 17:11:48 +01006 */
7
David Howells57be4a72013-08-30 16:16:34 +01008#include <linux/time.h>
David Howellsc26fd692012-09-24 17:11:48 +01009#include <crypto/public_key.h>
David Howells146aa8b2015-10-21 14:04:48 +010010#include <keys/asymmetric-type.h>
David Howellsc26fd692012-09-24 17:11:48 +010011
12struct x509_certificate {
13 struct x509_certificate *next;
David Howells84aabd42014-07-01 16:40:19 +010014 struct x509_certificate *signer; /* Certificate that signed this one */
David Howellsc26fd692012-09-24 17:11:48 +010015 struct public_key *pub; /* Public key details */
David Howells77d09102016-04-06 16:13:33 +010016 struct public_key_signature *sig; /* Signature parameters */
David Howellsc26fd692012-09-24 17:11:48 +010017 char *issuer; /* Name of certificate issuer */
18 char *subject; /* Name of certificate subject */
David Howellsb92e6572015-07-20 21:16:26 +010019 struct asymmetric_key_id *id; /* Issuer + Serial number */
Dmitry Kasatkin8dd60982014-10-06 16:52:12 +010020 struct asymmetric_key_id *skid; /* Subject + subjectKeyId (optional) */
David Howellsfd19a3d2015-07-29 16:58:32 +010021 time64_t valid_from;
22 time64_t valid_to;
David Howellsc26fd692012-09-24 17:11:48 +010023 const void *tbs; /* Signed data */
David Howellsb426beb2013-08-30 16:18:02 +010024 unsigned tbs_size; /* Size of signed data */
25 unsigned raw_sig_size; /* Size of sigature */
26 const void *raw_sig; /* Signature data */
David Howells84aabd42014-07-01 16:40:19 +010027 const void *raw_serial; /* Raw serial number in ASN.1 */
28 unsigned raw_serial_size;
29 unsigned raw_issuer_size;
30 const void *raw_issuer; /* Raw issuer name in ASN.1 */
31 const void *raw_subject; /* Raw subject name in ASN.1 */
32 unsigned raw_subject_size;
David Howellsdd2f6c42014-10-03 16:17:02 +010033 unsigned raw_skid_size;
34 const void *raw_skid; /* Raw subjectKeyId in ASN.1 */
David Howells84aabd42014-07-01 16:40:19 +010035 unsigned index;
36 bool seen; /* Infinite recursion prevention */
37 bool verified;
David Howells6c2dc5a2016-04-06 16:13:34 +010038 bool self_signed; /* T if self-signed (check unsupported_sig too) */
39 bool unsupported_key; /* T if key uses unsupported crypto */
40 bool unsupported_sig; /* T if signature uses unsupported crypto */
David Howells43652952017-04-03 16:07:25 +010041 bool blacklisted;
David Howellsc26fd692012-09-24 17:11:48 +010042};
43
44/*
45 * x509_cert_parser.c
46 */
47extern void x509_free_certificate(struct x509_certificate *cert);
48extern struct x509_certificate *x509_cert_parse(const void *data, size_t datalen);
David Howellsfd19a3d2015-07-29 16:58:32 +010049extern int x509_decode_time(time64_t *_t, size_t hdrlen,
50 unsigned char tag,
51 const unsigned char *value, size_t vlen);
David Howellsb426beb2013-08-30 16:18:02 +010052
53/*
54 * x509_public_key.c
55 */
56extern int x509_get_sig_params(struct x509_certificate *cert);
David Howells6c2dc5a2016-04-06 16:13:34 +010057extern int x509_check_for_self_signed(struct x509_certificate *cert);