aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-14 16:39:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-14 16:39:34 -0400
commitd25282d1c9b9bc4cda7f9d3c0205108e99aa7a9d (patch)
treef414482d768b015a609924293b779b4ad0b8f764 /Documentation
parentb6eea87fc6850d3531a64a27d2323a4498cd4e43 (diff)
parentdbadc17683e6c673a69b236c0f041b931cc55c42 (diff)
Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull module signing support from Rusty Russell: "module signing is the highlight, but it's an all-over David Howells frenzy..." Hmm "Magrathea: Glacier signing key". Somebody has been reading too much HHGTTG. * 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: (37 commits) X.509: Fix indefinite length element skip error handling X.509: Convert some printk calls to pr_devel asymmetric keys: fix printk format warning MODSIGN: Fix 32-bit overflow in X.509 certificate validity date checking MODSIGN: Make mrproper should remove generated files. MODSIGN: Use utf8 strings in signer's name in autogenerated X.509 certs MODSIGN: Use the same digest for the autogen key sig as for the module sig MODSIGN: Sign modules during the build process MODSIGN: Provide a script for generating a key ID from an X.509 cert MODSIGN: Implement module signature checking MODSIGN: Provide module signing public keys to the kernel MODSIGN: Automatically generate module signing keys if missing MODSIGN: Provide Kconfig options MODSIGN: Provide gitignore and make clean rules for extra files MODSIGN: Add FIPS policy module: signature checking hook X.509: Add a crypto key parser for binary (DER) X.509 certificates MPILIB: Provide a function to read raw data into an MPI X.509: Add an ASN.1 decoder X.509: Add simple ASN.1 grammar compiler ...
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/crypto/asymmetric-keys.txt312
-rw-r--r--Documentation/kernel-parameters.txt6
-rw-r--r--Documentation/security/keys.txt50
3 files changed, 367 insertions, 1 deletions
diff --git a/Documentation/crypto/asymmetric-keys.txt b/Documentation/crypto/asymmetric-keys.txt
new file mode 100644
index 000000000000..b7675904a747
--- /dev/null
+++ b/Documentation/crypto/asymmetric-keys.txt
@@ -0,0 +1,312 @@
1 =============================================
2 ASYMMETRIC / PUBLIC-KEY CRYPTOGRAPHY KEY TYPE
3 =============================================
4
5Contents:
6
7 - Overview.
8 - Key identification.
9 - Accessing asymmetric keys.
10 - Signature verification.
11 - Asymmetric key subtypes.
12 - Instantiation data parsers.
13
14
15========
16OVERVIEW
17========
18
19The "asymmetric" key type is designed to be a container for the keys used in
20public-key cryptography, without imposing any particular restrictions on the
21form or mechanism of the cryptography or form of the key.
22
23The asymmetric key is given a subtype that defines what sort of data is
24associated with the key and provides operations to describe and destroy it.
25However, no requirement is made that the key data actually be stored in the
26key.
27
28A completely in-kernel key retention and operation subtype can be defined, but
29it would also be possible to provide access to cryptographic hardware (such as
30a TPM) that might be used to both retain the relevant key and perform
31operations using that key. In such a case, the asymmetric key would then
32merely be an interface to the TPM driver.
33
34Also provided is the concept of a data parser. Data parsers are responsible
35for extracting information from the blobs of data passed to the instantiation
36function. The first data parser that recognises the blob gets to set the
37subtype of the key and define the operations that can be done on that key.
38
39A data parser may interpret the data blob as containing the bits representing a
40key, or it may interpret it as a reference to a key held somewhere else in the
41system (for example, a TPM).
42
43
44==================
45KEY IDENTIFICATION
46==================
47
48If a key is added with an empty name, the instantiation data parsers are given
49the opportunity to pre-parse a key and to determine the description the key
50should be given from the content of the key.
51
52This can then be used to refer to the key, either by complete match or by
53partial match. The key type may also use other criteria to refer to a key.
54
55The asymmetric key type's match function can then perform a wider range of
56comparisons than just the straightforward comparison of the description with
57the criterion string:
58
59 (1) If the criterion string is of the form "id:<hexdigits>" then the match
60 function will examine a key's fingerprint to see if the hex digits given
61 after the "id:" match the tail. For instance:
62
63 keyctl search @s asymmetric id:5acc2142
64
65 will match a key with fingerprint:
66
67 1A00 2040 7601 7889 DE11 882C 3823 04AD 5ACC 2142
68
69 (2) If the criterion string is of the form "<subtype>:<hexdigits>" then the
70 match will match the ID as in (1), but with the added restriction that
71 only keys of the specified subtype (e.g. tpm) will be matched. For
72 instance:
73
74 keyctl search @s asymmetric tpm:5acc2142
75
76Looking in /proc/keys, the last 8 hex digits of the key fingerprint are
77displayed, along with the subtype:
78
79 1a39e171 I----- 1 perm 3f010000 0 0 asymmetri modsign.0: DSA 5acc2142 []
80
81
82=========================
83ACCESSING ASYMMETRIC KEYS
84=========================
85
86For general access to asymmetric keys from within the kernel, the following
87inclusion is required:
88
89 #include <crypto/public_key.h>
90
91This gives access to functions for dealing with asymmetric / public keys.
92Three enums are defined there for representing public-key cryptography
93algorithms:
94
95 enum pkey_algo
96
97digest algorithms used by those:
98
99 enum pkey_hash_algo
100
101and key identifier representations:
102
103 enum pkey_id_type
104
105Note that the key type representation types are required because key
106identifiers from different standards aren't necessarily compatible. For
107instance, PGP generates key identifiers by hashing the key data plus some
108PGP-specific metadata, whereas X.509 has arbitrary certificate identifiers.
109
110The operations defined upon a key are:
111
112 (1) Signature verification.
113
114Other operations are possible (such as encryption) with the same key data
115required for verification, but not currently supported, and others
116(eg. decryption and signature generation) require extra key data.
117
118
119SIGNATURE VERIFICATION
120----------------------
121
122An operation is provided to perform cryptographic signature verification, using
123an asymmetric key to provide or to provide access to the public key.
124
125 int verify_signature(const struct key *key,
126 const struct public_key_signature *sig);
127
128The caller must have already obtained the key from some source and can then use
129it to check the signature. The caller must have parsed the signature and
130transferred the relevant bits to the structure pointed to by sig.
131
132 struct public_key_signature {
133 u8 *digest;
134 u8 digest_size;
135 enum pkey_hash_algo pkey_hash_algo : 8;
136 u8 nr_mpi;
137 union {
138 MPI mpi[2];
139 ...
140 };
141 };
142
143The algorithm used must be noted in sig->pkey_hash_algo, and all the MPIs that
144make up the actual signature must be stored in sig->mpi[] and the count of MPIs
145placed in sig->nr_mpi.
146
147In addition, the data must have been digested by the caller and the resulting
148hash must be pointed to by sig->digest and the size of the hash be placed in
149sig->digest_size.
150
151The function will return 0 upon success or -EKEYREJECTED if the signature
152doesn't match.
153
154The function may also return -ENOTSUPP if an unsupported public-key algorithm
155or public-key/hash algorithm combination is specified or the key doesn't
156support the operation; -EBADMSG or -ERANGE if some of the parameters have weird
157data; or -ENOMEM if an allocation can't be performed. -EINVAL can be returned
158if the key argument is the wrong type or is incompletely set up.
159
160
161=======================
162ASYMMETRIC KEY SUBTYPES
163=======================
164
165Asymmetric keys have a subtype that defines the set of operations that can be
166performed on that key and that determines what data is attached as the key
167payload. The payload format is entirely at the whim of the subtype.
168
169The subtype is selected by the key data parser and the parser must initialise
170the data required for it. The asymmetric key retains a reference on the
171subtype module.
172
173The subtype definition structure can be found in:
174
175 #include <keys/asymmetric-subtype.h>
176
177and looks like the following:
178
179 struct asymmetric_key_subtype {
180 struct module *owner;
181 const char *name;
182
183 void (*describe)(const struct key *key, struct seq_file *m);
184 void (*destroy)(void *payload);
185 int (*verify_signature)(const struct key *key,
186 const struct public_key_signature *sig);
187 };
188
189Asymmetric keys point to this with their type_data[0] member.
190
191The owner and name fields should be set to the owning module and the name of
192the subtype. Currently, the name is only used for print statements.
193
194There are a number of operations defined by the subtype:
195
196 (1) describe().
197
198 Mandatory. This allows the subtype to display something in /proc/keys
199 against the key. For instance the name of the public key algorithm type
200 could be displayed. The key type will display the tail of the key
201 identity string after this.
202
203 (2) destroy().
204
205 Mandatory. This should free the memory associated with the key. The
206 asymmetric key will look after freeing the fingerprint and releasing the
207 reference on the subtype module.
208
209 (3) verify_signature().
210
211 Optional. These are the entry points for the key usage operations.
212 Currently there is only the one defined. If not set, the caller will be
213 given -ENOTSUPP. The subtype may do anything it likes to implement an
214 operation, including offloading to hardware.
215
216
217==========================
218INSTANTIATION DATA PARSERS
219==========================
220
221The asymmetric key type doesn't generally want to store or to deal with a raw
222blob of data that holds the key data. It would have to parse it and error
223check it each time it wanted to use it. Further, the contents of the blob may
224have various checks that can be performed on it (eg. self-signatures, validity
225dates) and may contain useful data about the key (identifiers, capabilities).
226
227Also, the blob may represent a pointer to some hardware containing the key
228rather than the key itself.
229
230Examples of blob formats for which parsers could be implemented include:
231
232 - OpenPGP packet stream [RFC 4880].
233 - X.509 ASN.1 stream.
234 - Pointer to TPM key.
235 - Pointer to UEFI key.
236
237During key instantiation each parser in the list is tried until one doesn't
238return -EBADMSG.
239
240The parser definition structure can be found in:
241
242 #include <keys/asymmetric-parser.h>
243
244and looks like the following:
245
246 struct asymmetric_key_parser {
247 struct module *owner;
248 const char *name;
249
250 int (*parse)(struct key_preparsed_payload *prep);
251 };
252
253The owner and name fields should be set to the owning module and the name of
254the parser.
255
256There is currently only a single operation defined by the parser, and it is
257mandatory:
258
259 (1) parse().
260
261 This is called to preparse the key from the key creation and update paths.
262 In particular, it is called during the key creation _before_ a key is
263 allocated, and as such, is permitted to provide the key's description in
264 the case that the caller declines to do so.
265
266 The caller passes a pointer to the following struct with all of the fields
267 cleared, except for data, datalen and quotalen [see
268 Documentation/security/keys.txt].
269
270 struct key_preparsed_payload {
271 char *description;
272 void *type_data[2];
273 void *payload;
274 const void *data;
275 size_t datalen;
276 size_t quotalen;
277 };
278
279 The instantiation data is in a blob pointed to by data and is datalen in
280 size. The parse() function is not permitted to change these two values at
281 all, and shouldn't change any of the other values _unless_ they are
282 recognise the blob format and will not return -EBADMSG to indicate it is
283 not theirs.
284
285 If the parser is happy with the blob, it should propose a description for
286 the key and attach it to ->description, ->type_data[0] should be set to
287 point to the subtype to be used, ->payload should be set to point to the
288 initialised data for that subtype, ->type_data[1] should point to a hex
289 fingerprint and quotalen should be updated to indicate how much quota this
290 key should account for.
291
292 When clearing up, the data attached to ->type_data[1] and ->description
293 will be kfree()'d and the data attached to ->payload will be passed to the
294 subtype's ->destroy() method to be disposed of. A module reference for
295 the subtype pointed to by ->type_data[0] will be put.
296
297
298 If the data format is not recognised, -EBADMSG should be returned. If it
299 is recognised, but the key cannot for some reason be set up, some other
300 negative error code should be returned. On success, 0 should be returned.
301
302 The key's fingerprint string may be partially matched upon. For a
303 public-key algorithm such as RSA and DSA this will likely be a printable
304 hex version of the key's fingerprint.
305
306Functions are provided to register and unregister parsers:
307
308 int register_asymmetric_key_parser(struct asymmetric_key_parser *parser);
309 void unregister_asymmetric_key_parser(struct asymmetric_key_parser *subtype);
310
311Parsers may not have the same name. The names are otherwise only used for
312displaying in debugging messages.
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index e2ed3360b708..9776f068306b 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1593,6 +1593,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
1593 log everything. Information is printed at KERN_DEBUG 1593 log everything. Information is printed at KERN_DEBUG
1594 so loglevel=8 may also need to be specified. 1594 so loglevel=8 may also need to be specified.
1595 1595
1596 module.sig_enforce
1597 [KNL] When CONFIG_MODULE_SIG is set, this means that
1598 modules without (valid) signatures will fail to load.
1599 Note that if CONFIG_MODULE_SIG_ENFORCE is set, that
1600 is always true, so this option does nothing.
1601
1596 mousedev.tap_time= 1602 mousedev.tap_time=
1597 [MOUSE] Maximum time between finger touching and 1603 [MOUSE] Maximum time between finger touching and
1598 leaving touchpad surface for touch to be considered 1604 leaving touchpad surface for touch to be considered
diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
index aa0dbd74b71b..7d9ca92022d8 100644
--- a/Documentation/security/keys.txt
+++ b/Documentation/security/keys.txt
@@ -412,6 +412,10 @@ The main syscalls are:
412 to the keyring. In this case, an error will be generated if the process 412 to the keyring. In this case, an error will be generated if the process
413 does not have permission to write to the keyring. 413 does not have permission to write to the keyring.
414 414
415 If the key type supports it, if the description is NULL or an empty
416 string, the key type will try and generate a description from the content
417 of the payload.
418
415 The payload is optional, and the pointer can be NULL if not required by 419 The payload is optional, and the pointer can be NULL if not required by
416 the type. The payload is plen in size, and plen can be zero for an empty 420 the type. The payload is plen in size, and plen can be zero for an empty
417 payload. 421 payload.
@@ -1114,12 +1118,53 @@ The structure has a number of fields, some of which are mandatory:
1114 it should return 0. 1118 it should return 0.
1115 1119
1116 1120
1117 (*) int (*instantiate)(struct key *key, const void *data, size_t datalen); 1121 (*) int (*preparse)(struct key_preparsed_payload *prep);
1122
1123 This optional method permits the key type to attempt to parse payload
1124 before a key is created (add key) or the key semaphore is taken (update or
1125 instantiate key). The structure pointed to by prep looks like:
1126
1127 struct key_preparsed_payload {
1128 char *description;
1129 void *type_data[2];
1130 void *payload;
1131 const void *data;
1132 size_t datalen;
1133 size_t quotalen;
1134 };
1135
1136 Before calling the method, the caller will fill in data and datalen with
1137 the payload blob parameters; quotalen will be filled in with the default
1138 quota size from the key type and the rest will be cleared.
1139
1140 If a description can be proposed from the payload contents, that should be
1141 attached as a string to the description field. This will be used for the
1142 key description if the caller of add_key() passes NULL or "".
1143
1144 The method can attach anything it likes to type_data[] and payload. These
1145 are merely passed along to the instantiate() or update() operations.
1146
1147 The method should return 0 if success ful or a negative error code
1148 otherwise.
1149
1150
1151 (*) void (*free_preparse)(struct key_preparsed_payload *prep);
1152
1153 This method is only required if the preparse() method is provided,
1154 otherwise it is unused. It cleans up anything attached to the
1155 description, type_data and payload fields of the key_preparsed_payload
1156 struct as filled in by the preparse() method.
1157
1158
1159 (*) int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
1118 1160
1119 This method is called to attach a payload to a key during construction. 1161 This method is called to attach a payload to a key during construction.
1120 The payload attached need not bear any relation to the data passed to this 1162 The payload attached need not bear any relation to the data passed to this
1121 function. 1163 function.
1122 1164
1165 The prep->data and prep->datalen fields will define the original payload
1166 blob. If preparse() was supplied then other fields may be filled in also.
1167
1123 If the amount of data attached to the key differs from the size in 1168 If the amount of data attached to the key differs from the size in
1124 keytype->def_datalen, then key_payload_reserve() should be called. 1169 keytype->def_datalen, then key_payload_reserve() should be called.
1125 1170
@@ -1135,6 +1180,9 @@ The structure has a number of fields, some of which are mandatory:
1135 If this type of key can be updated, then this method should be provided. 1180 If this type of key can be updated, then this method should be provided.
1136 It is called to update a key's payload from the blob of data provided. 1181 It is called to update a key's payload from the blob of data provided.
1137 1182
1183 The prep->data and prep->datalen fields will define the original payload
1184 blob. If preparse() was supplied then other fields may be filled in also.
1185
1138 key_payload_reserve() should be called if the data length might change 1186 key_payload_reserve() should be called if the data length might change
1139 before any changes are actually made. Note that if this succeeds, the type 1187 before any changes are actually made. Note that if this succeeds, the type
1140 is committed to changing the key because it's already been altered, so all 1188 is committed to changing the key because it's already been altered, so all