blob: f24f4d808e7fd52a83d6f8e2f48c796bdd11c6b7 [file] [log] [blame]
David Howellsc26fd692012-09-24 17:11:48 +01001/* X.509 certificate parser internal definitions
2 *
3 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
David Howells57be4a72013-08-30 16:16:34 +010012#include <linux/time.h>
David Howellsc26fd692012-09-24 17:11:48 +010013#include <crypto/public_key.h>
David Howells146aa8b2015-10-21 14:04:48 +010014#include <keys/asymmetric-type.h>
David Howellsc26fd692012-09-24 17:11:48 +010015
16struct x509_certificate {
17 struct x509_certificate *next;
David Howells84aabd42014-07-01 16:40:19 +010018 struct x509_certificate *signer; /* Certificate that signed this one */
David Howellsc26fd692012-09-24 17:11:48 +010019 struct public_key *pub; /* Public key details */
David Howells77d09102016-04-06 16:13:33 +010020 struct public_key_signature *sig; /* Signature parameters */
David Howellsc26fd692012-09-24 17:11:48 +010021 char *issuer; /* Name of certificate issuer */
22 char *subject; /* Name of certificate subject */
David Howellsb92e6572015-07-20 21:16:26 +010023 struct asymmetric_key_id *id; /* Issuer + Serial number */
Dmitry Kasatkin8dd60982014-10-06 16:52:12 +010024 struct asymmetric_key_id *skid; /* Subject + subjectKeyId (optional) */
David Howellsfd19a3d2015-07-29 16:58:32 +010025 time64_t valid_from;
26 time64_t valid_to;
David Howellsc26fd692012-09-24 17:11:48 +010027 const void *tbs; /* Signed data */
David Howellsb426beb2013-08-30 16:18:02 +010028 unsigned tbs_size; /* Size of signed data */
29 unsigned raw_sig_size; /* Size of sigature */
30 const void *raw_sig; /* Signature data */
David Howells84aabd42014-07-01 16:40:19 +010031 const void *raw_serial; /* Raw serial number in ASN.1 */
32 unsigned raw_serial_size;
33 unsigned raw_issuer_size;
34 const void *raw_issuer; /* Raw issuer name in ASN.1 */
35 const void *raw_subject; /* Raw subject name in ASN.1 */
36 unsigned raw_subject_size;
David Howellsdd2f6c42014-10-03 16:17:02 +010037 unsigned raw_skid_size;
38 const void *raw_skid; /* Raw subjectKeyId in ASN.1 */
David Howells84aabd42014-07-01 16:40:19 +010039 unsigned index;
40 bool seen; /* Infinite recursion prevention */
41 bool verified;
42 bool trusted;
David Howells6c2dc5a2016-04-06 16:13:34 +010043 bool self_signed; /* T if self-signed (check unsupported_sig too) */
44 bool unsupported_key; /* T if key uses unsupported crypto */
45 bool unsupported_sig; /* T if signature uses unsupported crypto */
David Howellsc26fd692012-09-24 17:11:48 +010046};
47
48/*
49 * x509_cert_parser.c
50 */
51extern void x509_free_certificate(struct x509_certificate *cert);
52extern struct x509_certificate *x509_cert_parse(const void *data, size_t datalen);
David Howellsfd19a3d2015-07-29 16:58:32 +010053extern int x509_decode_time(time64_t *_t, size_t hdrlen,
54 unsigned char tag,
55 const unsigned char *value, size_t vlen);
David Howellsb426beb2013-08-30 16:18:02 +010056
57/*
58 * x509_public_key.c
59 */
60extern int x509_get_sig_params(struct x509_certificate *cert);
David Howells6c2dc5a2016-04-06 16:13:34 +010061extern int x509_check_for_self_signed(struct x509_certificate *cert);