162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/* X.509 certificate parser internal definitions
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
562306a36Sopenharmony_ci * Written by David Howells (dhowells@redhat.com)
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/time.h>
962306a36Sopenharmony_ci#include <crypto/public_key.h>
1062306a36Sopenharmony_ci#include <keys/asymmetric-type.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cistruct x509_certificate {
1362306a36Sopenharmony_ci	struct x509_certificate *next;
1462306a36Sopenharmony_ci	struct x509_certificate *signer;	/* Certificate that signed this one */
1562306a36Sopenharmony_ci	struct public_key *pub;			/* Public key details */
1662306a36Sopenharmony_ci	struct public_key_signature *sig;	/* Signature parameters */
1762306a36Sopenharmony_ci	char		*issuer;		/* Name of certificate issuer */
1862306a36Sopenharmony_ci	char		*subject;		/* Name of certificate subject */
1962306a36Sopenharmony_ci	struct asymmetric_key_id *id;		/* Issuer + Serial number */
2062306a36Sopenharmony_ci	struct asymmetric_key_id *skid;		/* Subject + subjectKeyId (optional) */
2162306a36Sopenharmony_ci	time64_t	valid_from;
2262306a36Sopenharmony_ci	time64_t	valid_to;
2362306a36Sopenharmony_ci	const void	*tbs;			/* Signed data */
2462306a36Sopenharmony_ci	unsigned	tbs_size;		/* Size of signed data */
2562306a36Sopenharmony_ci	unsigned	raw_sig_size;		/* Size of signature */
2662306a36Sopenharmony_ci	const void	*raw_sig;		/* Signature data */
2762306a36Sopenharmony_ci	const void	*raw_serial;		/* Raw serial number in ASN.1 */
2862306a36Sopenharmony_ci	unsigned	raw_serial_size;
2962306a36Sopenharmony_ci	unsigned	raw_issuer_size;
3062306a36Sopenharmony_ci	const void	*raw_issuer;		/* Raw issuer name in ASN.1 */
3162306a36Sopenharmony_ci	const void	*raw_subject;		/* Raw subject name in ASN.1 */
3262306a36Sopenharmony_ci	unsigned	raw_subject_size;
3362306a36Sopenharmony_ci	unsigned	raw_skid_size;
3462306a36Sopenharmony_ci	const void	*raw_skid;		/* Raw subjectKeyId in ASN.1 */
3562306a36Sopenharmony_ci	unsigned	index;
3662306a36Sopenharmony_ci	bool		seen;			/* Infinite recursion prevention */
3762306a36Sopenharmony_ci	bool		verified;
3862306a36Sopenharmony_ci	bool		self_signed;		/* T if self-signed (check unsupported_sig too) */
3962306a36Sopenharmony_ci	bool		unsupported_sig;	/* T if signature uses unsupported crypto */
4062306a36Sopenharmony_ci	bool		blacklisted;
4162306a36Sopenharmony_ci};
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/*
4462306a36Sopenharmony_ci * x509_cert_parser.c
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_ciextern void x509_free_certificate(struct x509_certificate *cert);
4762306a36Sopenharmony_ciextern struct x509_certificate *x509_cert_parse(const void *data, size_t datalen);
4862306a36Sopenharmony_ciextern int x509_decode_time(time64_t *_t,  size_t hdrlen,
4962306a36Sopenharmony_ci			    unsigned char tag,
5062306a36Sopenharmony_ci			    const unsigned char *value, size_t vlen);
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/*
5362306a36Sopenharmony_ci * x509_public_key.c
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ciextern int x509_get_sig_params(struct x509_certificate *cert);
5662306a36Sopenharmony_ciextern int x509_check_for_self_signed(struct x509_certificate *cert);
57