diff options
| author | Dmitry Kasatkin <dmitry.kasatkin@intel.com> | 2011-10-14 08:25:16 -0400 |
|---|---|---|
| committer | Dmitry Kasatkin <dmitry.kasatkin@intel.com> | 2011-11-09 05:10:37 -0500 |
| commit | 051dbb918c7fb7da8e64a2cd0d804ba73399709f (patch) | |
| tree | 34d547e74ef6edb7feeda4a8291b221cc016c393 | |
| parent | 7e8dec918ef8e0f68b4937c3c50fa57002077a4d (diff) | |
crypto: digital signature verification support
This patch implements RSA digital signature verification using GnuPG library.
The format of the signature and the public key is defined by their respective
headers. The signature header contains version information, algorithm,
and keyid, which was used to generate the signature.
The key header contains version and algorythim type.
The payload of the signature and the key are multi-precision integers.
The signing and key management utilities evm-utils provide functionality
to generate signatures and load keys into the kernel keyring.
When the key is added to the kernel keyring, the keyid defines the name
of the key.
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
Acked-by: Mimi Zohar <zohar@us.ibm.com>
| -rw-r--r-- | Documentation/digsig.txt | 96 | ||||
| -rw-r--r-- | include/linux/digsig.h | 64 | ||||
| -rw-r--r-- | lib/Kconfig | 8 | ||||
| -rw-r--r-- | lib/Makefile | 1 | ||||
| -rw-r--r-- | lib/digsig.c | 284 |
5 files changed, 453 insertions, 0 deletions
diff --git a/Documentation/digsig.txt b/Documentation/digsig.txt new file mode 100644 index 000000000000..3f682889068b --- /dev/null +++ b/Documentation/digsig.txt | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | Digital Signature Verification API | ||
| 2 | |||
| 3 | CONTENTS | ||
| 4 | |||
| 5 | 1. Introduction | ||
| 6 | 2. API | ||
| 7 | 3. User-space utilities | ||
| 8 | |||
| 9 | |||
| 10 | 1. Introduction | ||
| 11 | |||
| 12 | Digital signature verification API provides a method to verify digital signature. | ||
| 13 | Currently digital signatures are used by the IMA/EVM integrity protection subsystem. | ||
| 14 | |||
| 15 | Digital signature verification is implemented using cut-down kernel port of | ||
| 16 | GnuPG multi-precision integers (MPI) library. The kernel port provides | ||
| 17 | memory allocation errors handling, has been refactored according to kernel | ||
| 18 | coding style, and checkpatch.pl reported errors and warnings have been fixed. | ||
| 19 | |||
| 20 | Public key and signature consist of header and MPIs. | ||
| 21 | |||
| 22 | struct pubkey_hdr { | ||
| 23 | uint8_t version; /* key format version */ | ||
| 24 | time_t timestamp; /* key made, always 0 for now */ | ||
| 25 | uint8_t algo; | ||
| 26 | uint8_t nmpi; | ||
| 27 | char mpi[0]; | ||
| 28 | } __packed; | ||
| 29 | |||
| 30 | struct signature_hdr { | ||
| 31 | uint8_t version; /* signature format version */ | ||
| 32 | time_t timestamp; /* signature made */ | ||
| 33 | uint8_t algo; | ||
| 34 | uint8_t hash; | ||
| 35 | uint8_t keyid[8]; | ||
| 36 | uint8_t nmpi; | ||
| 37 | char mpi[0]; | ||
| 38 | } __packed; | ||
| 39 | |||
| 40 | keyid equals to SHA1[12-19] over the total key content. | ||
| 41 | Signature header is used as an input to generate a signature. | ||
| 42 | Such approach insures that key or signature header could not be changed. | ||
| 43 | It protects timestamp from been changed and can be used for rollback | ||
| 44 | protection. | ||
| 45 | |||
| 46 | 2. API | ||
| 47 | |||
| 48 | API currently includes only 1 function: | ||
| 49 | |||
| 50 | digsig_verify() - digital signature verification with public key | ||
| 51 | |||
| 52 | |||
| 53 | /** | ||
| 54 | * digsig_verify() - digital signature verification with public key | ||
| 55 | * @keyring: keyring to search key in | ||
| 56 | * @sig: digital signature | ||
| 57 | * @sigen: length of the signature | ||
| 58 | * @data: data | ||
| 59 | * @datalen: length of the data | ||
| 60 | * @return: 0 on success, -EINVAL otherwise | ||
| 61 | * | ||
| 62 | * Verifies data integrity against digital signature. | ||
| 63 | * Currently only RSA is supported. | ||
| 64 | * Normally hash of the content is used as a data for this function. | ||
| 65 | * | ||
| 66 | */ | ||
| 67 | int digsig_verify(struct key *keyring, const char *sig, int siglen, | ||
| 68 | const char *data, int datalen); | ||
| 69 | |||
| 70 | 3. User-space utilities | ||
| 71 | |||
| 72 | The signing and key management utilities evm-utils provide functionality | ||
| 73 | to generate signatures, to load keys into the kernel keyring. | ||
| 74 | Keys can be in PEM or converted to the kernel format. | ||
| 75 | When the key is added to the kernel keyring, the keyid defines the name | ||
| 76 | of the key: 5D2B05FC633EE3E8 in the example bellow. | ||
| 77 | |||
| 78 | Here is example output of the keyctl utility. | ||
| 79 | |||
| 80 | $ keyctl show | ||
| 81 | Session Keyring | ||
| 82 | -3 --alswrv 0 0 keyring: _ses | ||
| 83 | 603976250 --alswrv 0 -1 \_ keyring: _uid.0 | ||
| 84 | 817777377 --alswrv 0 0 \_ user: kmk | ||
| 85 | 891974900 --alswrv 0 0 \_ encrypted: evm-key | ||
| 86 | 170323636 --alswrv 0 0 \_ keyring: _module | ||
| 87 | 548221616 --alswrv 0 0 \_ keyring: _ima | ||
| 88 | 128198054 --alswrv 0 0 \_ keyring: _evm | ||
| 89 | |||
| 90 | $ keyctl list 128198054 | ||
| 91 | 1 key in keyring: | ||
| 92 | 620789745: --alswrv 0 0 user: 5D2B05FC633EE3E8 | ||
| 93 | |||
| 94 | |||
| 95 | Dmitry Kasatkin | ||
| 96 | 06.10.2011 | ||
diff --git a/include/linux/digsig.h b/include/linux/digsig.h new file mode 100644 index 000000000000..efae755017d7 --- /dev/null +++ b/include/linux/digsig.h | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2011 Nokia Corporation | ||
| 3 | * Copyright (C) 2011 Intel Corporation | ||
| 4 | * | ||
| 5 | * Author: | ||
| 6 | * Dmitry Kasatkin <dmitry.kasatkin@nokia.com> | ||
| 7 | * <dmitry.kasatkin@intel.com> | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation, version 2 of the License. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef _DIGSIG_H | ||
| 16 | #define _DIGSIG_H | ||
| 17 | |||
| 18 | #include <linux/key.h> | ||
| 19 | |||
| 20 | enum pubkey_algo { | ||
| 21 | PUBKEY_ALGO_RSA, | ||
| 22 | PUBKEY_ALGO_MAX, | ||
| 23 | }; | ||
| 24 | |||
| 25 | enum digest_algo { | ||
| 26 | DIGEST_ALGO_SHA1, | ||
| 27 | DIGEST_ALGO_SHA256, | ||
| 28 | DIGEST_ALGO_MAX | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct pubkey_hdr { | ||
| 32 | uint8_t version; /* key format version */ | ||
| 33 | time_t timestamp; /* key made, always 0 for now */ | ||
| 34 | uint8_t algo; | ||
| 35 | uint8_t nmpi; | ||
| 36 | char mpi[0]; | ||
| 37 | } __packed; | ||
| 38 | |||
| 39 | struct signature_hdr { | ||
| 40 | uint8_t version; /* signature format version */ | ||
| 41 | time_t timestamp; /* signature made */ | ||
| 42 | uint8_t algo; | ||
| 43 | uint8_t hash; | ||
| 44 | uint8_t keyid[8]; | ||
| 45 | uint8_t nmpi; | ||
| 46 | char mpi[0]; | ||
| 47 | } __packed; | ||
| 48 | |||
| 49 | #if defined(CONFIG_DIGSIG) || defined(CONFIG_DIGSIG_MODULE) | ||
| 50 | |||
| 51 | int digsig_verify(struct key *keyring, const char *sig, int siglen, | ||
| 52 | const char *digest, int digestlen); | ||
| 53 | |||
| 54 | #else | ||
| 55 | |||
| 56 | static inline int digsig_verify(struct key *keyring, const char *sig, | ||
| 57 | int siglen, const char *digest, int digestlen) | ||
| 58 | { | ||
| 59 | return -EOPNOTSUPP; | ||
| 60 | } | ||
| 61 | |||
| 62 | #endif /* CONFIG_DIGSIG */ | ||
| 63 | |||
| 64 | #endif /* _DIGSIG_H */ | ||
diff --git a/lib/Kconfig b/lib/Kconfig index d411de53be4f..c1a89185fe6b 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
| @@ -293,4 +293,12 @@ config MPILIB_EXTRA | |||
| 293 | This code in unnecessary for RSA digital signature verification, | 293 | This code in unnecessary for RSA digital signature verification, |
| 294 | and can be compiled if needed. | 294 | and can be compiled if needed. |
| 295 | 295 | ||
| 296 | config DIGSIG | ||
| 297 | tristate "In-kernel signature checker" | ||
| 298 | depends on CRYPTO | ||
| 299 | select MPILIB | ||
| 300 | help | ||
| 301 | Digital signature verification. Currently only RSA is supported. | ||
| 302 | Implementation is done using GnuPG MPI library | ||
| 303 | |||
| 296 | endmenu | 304 | endmenu |
diff --git a/lib/Makefile b/lib/Makefile index 6ba8cbf4c72f..0f5cff267aff 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -116,6 +116,7 @@ obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | |||
| 116 | obj-$(CONFIG_CORDIC) += cordic.o | 116 | obj-$(CONFIG_CORDIC) += cordic.o |
| 117 | 117 | ||
| 118 | obj-$(CONFIG_MPILIB) += mpi/ | 118 | obj-$(CONFIG_MPILIB) += mpi/ |
| 119 | obj-$(CONFIG_DIGSIG) += digsig.o | ||
| 119 | 120 | ||
| 120 | hostprogs-y := gen_crc32table | 121 | hostprogs-y := gen_crc32table |
| 121 | clean-files := crc32table.h | 122 | clean-files := crc32table.h |
diff --git a/lib/digsig.c b/lib/digsig.c new file mode 100644 index 000000000000..fd2402f67f89 --- /dev/null +++ b/lib/digsig.c | |||
| @@ -0,0 +1,284 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2011 Nokia Corporation | ||
| 3 | * Copyright (C) 2011 Intel Corporation | ||
| 4 | * | ||
| 5 | * Author: | ||
