iPXE
cms.h
Go to the documentation of this file.
1#ifndef _IPXE_CMS_H
2#define _IPXE_CMS_H
3
4/** @file
5 *
6 * Cryptographic Message Syntax (PKCS #7)
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <time.h>
14#include <ipxe/asn1.h>
15#include <ipxe/crypto.h>
16#include <ipxe/x509.h>
17#include <ipxe/refcnt.h>
18
19struct image;
20struct cms_message;
21
22/** A CMS message type */
23struct cms_type {
24 /** Name */
25 const char *name;
26 /** Object identifier */
28 /** Parse content
29 *
30 * @v cms CMS message
31 * @v raw ASN.1 cursor
32 * @ret rc Return status code
33 */
34 int ( * parse ) ( struct cms_message *cms,
35 const struct asn1_cursor *raw );
36};
37
38/** CMS participant information */
40 /** List of participant information blocks */
42 /** Certificate chain */
44
45 /** Digest algorithm (for signature messages) */
47 /** Public-key algorithm */
49
50 /** Signature or key value */
52};
53
54/** A CMS message */
56 /** Reference count */
57 struct refcnt refcnt;
58 /** Raw ASN.1 data */
60 /** Message type */
61 struct cms_type *type;
62
63 /** List of all certificates (for signature messages) */
65 /** List of participant information blocks */
67
68 /** Cipher algorithm */
70 /** Cipher initialization vector */
72 /** Cipher authentication tag */
74};
75
76/**
77 * Get reference to CMS message
78 *
79 * @v cms CMS message
80 * @ret cms CMS message
81 */
82static inline __attribute__ (( always_inline )) struct cms_message *
83cms_get ( struct cms_message *cms ) {
84 ref_get ( &cms->refcnt );
85 return cms;
86}
87
88/**
89 * Drop reference to CMS message
90 *
91 * @v cms CMS message
92 */
93static inline __attribute__ (( always_inline )) void
94cms_put ( struct cms_message *cms ) {
95 ref_put ( &cms->refcnt );
96}
97
98/**
99 * Check if CMS message is a signature message
100 *
101 * @v cms CMS message
102 * @ret is_signature Message is a signature message
103 */
104static inline __attribute__ (( always_inline )) int
106
107 /* CMS signatures include an optional CertificateSet */
108 return ( cms->certificates != NULL );
109}
110
111/**
112 * Check if CMS message is an encrypted message
113 *
114 * @v cms CMS message
115 * @ret is_encrypted Message is an encrypted message
116 */
117static inline __attribute__ (( always_inline )) int
119
120 /* CMS encrypted messages have a cipher algorithm */
121 return ( cms->cipher != NULL );
122}
123
124extern int cms_message ( struct image *image, struct cms_message **cms );
125extern int cms_verify ( struct cms_message *cms, struct image *image,
126 const char *name, time_t time, struct x509_chain *store,
127 struct x509_root *root );
128extern int cms_decrypt ( struct cms_message *cms, struct image *image,
129 const char *name, struct private_key *private_key );
130
131#endif /* _IPXE_CMS_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
__be32 raw[7]
Definition CIB_PRM.h:0
ASN.1 encoding.
const char * name
Definition ath9k_hw.c:1986
static int cms_is_signature(struct cms_message *cms)
Check if CMS message is a signature message.
Definition cms.h:105
int cms_decrypt(struct cms_message *cms, struct image *image, const char *name, struct private_key *private_key)
Decrypt CMS message.
Definition cms.c:1039
int cms_message(struct image *image, struct cms_message **cms)
Create CMS message.
Definition cms.c:672
static int cms_is_encrypted(struct cms_message *cms)
Check if CMS message is an encrypted message.
Definition cms.h:118
int cms_verify(struct cms_message *cms, struct image *image, const char *name, time_t time, struct x509_chain *store, struct x509_root *root)
Verify CMS signature.
Definition cms.c:834
static struct cms_message * cms_get(struct cms_message *cms)
Get reference to CMS message.
Definition cms.h:83
static void cms_put(struct cms_message *cms)
Drop reference to CMS message.
Definition cms.h:94
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
Cryptographic API.
Time source.
int64_t time_t
Seconds since the Epoch.
Definition time.h:19
Reference counting.
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
struct stp_switch root
Root switch.
Definition stp.h:15
An ASN.1 object cursor.
Definition asn1.h:21
A cipher algorithm.
Definition crypto.h:51
A CMS message.
Definition cms.h:55
struct asn1_cursor * raw
Raw ASN.1 data.
Definition cms.h:59
struct cms_type * type
Message type.
Definition cms.h:61
struct asn1_cursor mac
Cipher authentication tag.
Definition cms.h:73
struct refcnt refcnt
Reference count.
Definition cms.h:57
struct x509_chain * certificates
List of all certificates (for signature messages)
Definition cms.h:64
struct cipher_algorithm * cipher
Cipher algorithm.
Definition cms.h:69
struct asn1_cursor iv
Cipher initialization vector.
Definition cms.h:71
struct list_head participants
List of participant information blocks.
Definition cms.h:66
CMS participant information.
Definition cms.h:39
struct digest_algorithm * digest
Digest algorithm (for signature messages)
Definition cms.h:46
struct asn1_cursor value
Signature or key value.
Definition cms.h:51
struct list_head list
List of participant information blocks.
Definition cms.h:41
struct x509_chain * chain
Certificate chain.
Definition cms.h:43
struct pubkey_algorithm * pubkey
Public-key algorithm.
Definition cms.h:48
A CMS message type.
Definition cms.h:23
const char * name
Name.
Definition cms.h:25
struct asn1_cursor oid
Object identifier.
Definition cms.h:27
int(* parse)(struct cms_message *cms, const struct asn1_cursor *raw)
Parse content.
Definition cms.h:34
A message digest algorithm.
Definition crypto.h:19
An executable image.
Definition image.h:24
A doubly-linked list entry (or list head)
Definition list.h:19
A private key.
Definition privkey.h:17
A public key algorithm.
Definition crypto.h:122
An X.509 certificate chain.
Definition x509.h:201
An X.509 root certificate list.
Definition x509.h:375
X.509 certificates.