^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* PKCS#7 crypto data parser internal definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/oid_registry.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <crypto/pkcs7.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "x509_parser.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define kenter(FMT, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) pr_devel("==> %s("FMT")\n", __func__, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define kleave(FMT, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) pr_devel("<== %s()"FMT"\n", __func__, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct pkcs7_signed_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct pkcs7_signed_info *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct x509_certificate *signer; /* Signing certificate (in msg->certs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) unsigned index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) bool unsupported_crypto; /* T if not usable due to missing crypto */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) bool blacklisted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Message digest - the digest of the Content Data (or NULL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) const void *msgdigest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) unsigned msgdigest_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* Authenticated Attribute data (or NULL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned authattrs_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) const void *authattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned long aa_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define sinfo_has_content_type 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define sinfo_has_signing_time 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define sinfo_has_message_digest 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define sinfo_has_smime_caps 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define sinfo_has_ms_opus_info 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define sinfo_has_ms_statement_type 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) time64_t signing_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Message signature.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * This contains the generated digest of _either_ the Content Data or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * the Authenticated Attributes [RFC2315 9.3]. If the latter, one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * the attributes contains the digest of the the Content Data within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * THis also contains the issuing cert serial number and issuer's name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * [PKCS#7 or CMS ver 1] or issuing cert's SKID [CMS ver 3].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct public_key_signature *sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct pkcs7_message {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct x509_certificate *certs; /* Certificate list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct x509_certificate *crl; /* Revocation list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct pkcs7_signed_info *signed_infos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u8 version; /* Version of cert (1 -> PKCS#7 or CMS; 3 -> CMS) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) bool have_authattrs; /* T if have authattrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* Content Data (or NULL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) enum OID data_type; /* Type of Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) size_t data_len; /* Length of Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) size_t data_hdrlen; /* Length of Data ASN.1 header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) const void *data; /* Content Data (or 0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };