Skip to contentSkip to conversation

keys: trusted and encrypted keys

PATCH New Mimi Zohar 1 participant 5 messages Oct 7, 2010

Subsystems (7)
lore
Share & tools
lore

Mimi Zohar

author
#0 lore raw

cover keys: trusted and encrypted keys

Since the original posting, the encrypted keys are started at late_initcall, in order to wait for the crypto API to be initialized, minor changes were made to Kconfig, and the TPM Maintainer acked the second patch.

Trusted and Encrypted Keys are two new key types added to the existing kernel key ring service. Both of these new types are variable length symmetic keys, and in both cases all keys are created in the kernel, and user space sees, stores, and loads only encrypted blobs. Trusted Keys require the availability of a Trusted Platform Module (TPM) chip for greater security, while Encrypted Keys can be used on any system. All user level blobs, are displayed and loaded in hex ascii for convenience, and are integrity verified.

Trusted Keys use a TPM both to generate and to seal the keys. Keys are sealed under a 2048 bit RSA key in the TPM, and optionally sealed to specified PCR (integrity measurement) values, and only unsealed by the TPM, if PCRs and blob integrity verifications match. A loaded Trusted Key can be updated with new (future) PCR values, so keys are easily migrated to new pcr values, such as when the kernel and initramfs are updated. The same key can have many saved blobs under different PCR values, so multiple boots are easily supported.

Trusted Keys are sealed under the SRK, which must have the default authorization value (20 zeros). This can be set at takeownership time with the trouser's utility "tpm_takeownership -u -z".

Usage:
keyctl add trusted name "NEW keylen [hex_pcrinfo]" ring keyctl add trusted name "LOAD hex_blob" ring keyctl update key "UPDATE hex_pcrinfo"
keyctl print keyid
keyctl pipe keyid > filename

The key length for new keys are always in bytes. Trusted Keys can be 32 - 128 bytes (256 - 1024 bits), the upper limit is to fit within the 2048 bit SRK (RSA) keylength, with all necessary structure/padding. The keywords NEW, LOAD, and UPDATE can be all upper or all lower case.

Encrypted keys do not depend on a TPM, and are faster, as they use AES for encryption/decryption. New keys are created from kernel generated random numbers, and are encrypted/decrypted using a specified 'master' key. The 'master' key can either be a trusted-key or user-key type. The main disadvantage of encrypted keys is that if they are not rooted in a trusted key, they are only as secure as the user key encrypting them. The master user key should therefore be loaded in as secure a way as possible, preferably early in boot.

Usage:
keyctl add encrypted name "NEW master-key-name keylen" ring keyctl add encrypted name "LOAD master-key-name keylen hex_blob" ring keyctl update keyid "UPDATE master-key-name"

The initial consumer of trusted keys is EVM, which at boot time needs a high quality symmetric key for HMAC protection of file metadata. The use of a trusted key provides strong guarantees that the EVM key has not been compromised by a user level problem, and when sealed to specific boot PCR values, protects against boot and offline attacks. Other uses for trusted and encrypted keys, such as for disk and file encryption are anticipated.

Mimi Zohar
Dave Safford

Mimi Zohar (4):
lib: hex2bin converts ascii hexadecimal string to binary
key: add tpm_send command
keys: add new trusted key-type
keys: add new key-type encrypted

 drivers/char/tpm/tpm.c            |   17 +
 include/keys/encrypted-type.h     |   30 ++
 include/keys/trusted-type.h       |   33 ++
 include/linux/kernel.h            |    1 +
 include/linux/tpm.h               |    3 +
 lib/hexdump.c                     |   16 +
 security/Kconfig                  |   31 ++
 security/keys/Makefile            |    2 +
 security/keys/encrypted_defined.c |  782 +++++++++++++++++++++++++++++
 security/keys/encrypted_defined.h |   52 ++
 security/keys/trusted_defined.c   |  997 +++++++++++++++++++++++++++++++++++++
 security/keys/trusted_defined.h   |  125 +++++
 12 files changed, 2089 insertions(+), 0 deletions(-)
 create mode 100644 include/keys/encrypted-type.h
 create mode 100644 include/keys/trusted-type.h
 create mode 100644 security/keys/encrypted_defined.c
 create mode 100644 security/keys/encrypted_defined.h
 create mode 100644 security/keys/trusted_defined.c
 create mode 100644 security/keys/trusted_defined.h
Signature · 1 line
1.7.2.2
author
#1 lore raw

PATCH 1/4 lib: hex2bin converts ascii hexadecimal string to binary

Similar to the kgdb_hex2mem() code, hex2bin converts a string to binary using the hex_to_bin() library call.

---
 include/linux/kernel.h |    1 +
 lib/hexdump.c          |   16 ++++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
include/linux/kernel.h +1 -0
index 2b0a35e..69ddea8 100644
@@ -396,6 +396,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 }
 
 extern int hex_to_bin(char ch);
+extern void hex2bin(unsigned char *mem, char *buf, int count);
 
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
lib/hexdump.c +16 -0
index 5d7a480..66f96bb 100644
@@ -34,6 +34,22 @@ int hex_to_bin(char ch)
 EXPORT_SYMBOL(hex_to_bin);
 
 /**
+ * hex2bin - convert an ascii hexadecimal string to its binary representation
+ * @mem: result
+ * @buf: ascii hexadecimal string
+ * @count: result length
+ */
+void hex2bin(unsigned char *mem, char *buf, int count)
+{
+	while (count--) {
+		*mem = hex_to_bin(*buf++) << 4;
+		*mem += hex_to_bin(*buf++);
+		mem++;
+	}
+}
+EXPORT_SYMBOL(hex2bin);
+
+/**
  * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
Signature · 1 line
1.7.2.2
author
#2 lore raw

PATCH 2/4 key: add tpm_send command

In reply to Mimi Zohar

Add internal kernel tpm_send() command used to seal/unseal keys.

---
 drivers/char/tpm/tpm.c |   17 +++++++++++++++++
 include/linux/tpm.h    |    3 +++
 2 files changed, 20 insertions(+), 0 deletions(-)
drivers/char/tpm/tpm.c +17 -0
index 7c41335..5987d9c 100644
@@ -780,6 +780,23 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
 }
 EXPORT_SYMBOL_GPL(tpm_pcr_extend);
 
+int tpm_send(u32 chip_num, char *cmd, int buflen)
+{
+	struct tpm_chip *chip;
+	int rc;
+
+	chip = tpm_chip_find_get(chip_num);
+	if (chip == NULL)
+		return -ENODEV;
+
+	rc = transmit_cmd(chip, (struct tpm_cmd_t *)cmd, buflen,
+			  "attempting tpm_cmd");
+
+	module_put(chip->dev->driver->owner);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(tpm_send);
+
 ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
 		      char *buf)
 {
include/linux/tpm.h +3 -0
index ac5d1c1..a0ecaa9 100644
@@ -31,6 +31,7 @@
 
 extern int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf);
 extern int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash);
+extern int tpm_send(u32 chip_num, char *cmd, int buflen);
 #else
 static inline int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf) {
 	return -ENODEV;
@@ -38,5 +39,7 @@ static inline int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf) {
 static inline int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) {
 	return -ENODEV;
 }
+static inline int tpm_send(u32 chip_num, char *cmd, int buflen) {
+	return -ENODEV;
 #endif
 #endif
Signature · 1 line
1.7.2.2
author
#3 lore raw

PATCH 3/4 keys: add new trusted key-type

In reply to Mimi Zohar

Defines a new kernel key-type called 'trusted'. Trusted keys are TPM generated random numbers, RSA sealed by the TPM, and only unsealed by the TPM, if boot PCRs and other criteria match. Trusted keys are created/encrypted/decrypted in the kernel. Userspace ever only sees/stores encrypted blobs.

---
 include/keys/trusted-type.h     |   33 ++
 security/Kconfig                |   15 +
 security/keys/Makefile          |    1 +
 security/keys/trusted_defined.c |  997 +++++++++++++++++++++++++++++++++++++++
 security/keys/trusted_defined.h |  125 +++++
 5 files changed, 1171 insertions(+), 0 deletions(-)
 create mode 100644 include/keys/trusted-type.h
 create mode 100644 security/keys/trusted_defined.c
 create mode 100644 security/keys/trusted_defined.h
include/keys/trusted-type.h new file +33 -0
new file mode 100644
index 0000000..be7d44e
@@ -0,0 +1,33 @@
+/* trusted-type.h: trusted-defined key type
+ *
+ * Copyright (C) 2010 IBM Corporation
+ * Author: David Safford <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 of the License.
+ */
+
+#ifndef _KEYS_TRUSTED_TYPE_H
+#define _KEYS_TRUSTED_TYPE_H
+
+#include <linux/key.h>
+#include <linux/rcupdate.h>
+
+#define MAX_KEY_SIZE			128
+#define MAX_BLOB_SIZE			320
+#define MAX_PCRINFO_SIZE		64
+
+struct trusted_key_payload {
+	struct rcu_head rcu;	/* RCU destructor */
+	unsigned int key_len;
+	unsigned int blob_len;
+	unsigned int pcrinfo_len;
+	unsigned char key[MAX_KEY_SIZE];
+	unsigned char blob[MAX_BLOB_SIZE];
+	unsigned char pcrinfo[MAX_PCRINFO_SIZE];
+};
+
+extern struct key_type key_type_trusted;
+
+#endif /* _KEYS_TRUSTED_TYPE_H */
security/Kconfig +15 -0
index bd72ae6..38fdaf6 100644
@@ -21,6 +21,21 @@ config KEYS
 
 	  If you are unsure as to whether this is required, answer N.
 
+config TRUSTED_KEYS
+	tristate "TRUSTED KEYS"
+	depends on KEYS && TCG_TPM
+	select CRYPTO
+	select CRYPTO_HMAC
+	select CRYPTO_SHA1
+	help
+	  This option provides support for creating/sealing/unsealing keys
+	  in the kernel. Trusted keys are TPM generated random numbers
+	  symmetric keys, RSA sealed by the TPM, and only unsealed by the
+	  TPM, if boot PCRs and other criteria match.  Userspace ever only
+	  sees/stores encrypted blobs.
+
+	  If you are unsure as to whether this is required, answer N.
+
 config KEYS_DEBUG_PROC_KEYS
 	bool "Enable the /proc/keys file by which keys may be viewed"
 	depends on KEYS
security/keys/Makefile +1 -0
index 74d5447..fcb1070 100644
@@ -13,6 +13,7 @@ obj-y := \
 	request_key_auth.o \
 	user_defined.o
 
+obj-$(CONFIG_TRUSTED_KEYS) += trusted_defined.o
 obj-$(CONFIG_KEYS_COMPAT) += compat.o
 obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_SYSCTL) += sysctl.o
security/keys/trusted_defined.c new file +997 -0

997 lines not on this page · raw message

security/keys/trusted_defined.h new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
1.7.2.2
author
#4 lore raw

PATCH 4/4 keys: add new key-type encrypted

In reply to Mimi Zohar

Defines a new kernel key-type called 'encrypted'. Encrypted keys are kernel generated random numbers, which are encrypted/decrypted with a 'trusted' symmetric key. Encrypted keys are created/encrypted/decrypted in the kernel. Userspace only ever sees/stores encrypted blobs.

Changelog:
- wait until late_initcall for crypto libraries to be registered
- cleanup security/Kconfig

---
 include/keys/encrypted-type.h     |   30 ++
 security/Kconfig                  |   16 +
 security/keys/Makefile            |    1 +
 security/keys/encrypted_defined.c |  782 +++++++++++++++++++++++++++++++++++++
 security/keys/encrypted_defined.h |   52 +++
 5 files changed, 881 insertions(+), 0 deletions(-)
 create mode 100644 include/keys/encrypted-type.h
 create mode 100644 security/keys/encrypted_defined.c
 create mode 100644 security/keys/encrypted_defined.h
include/keys/encrypted-type.h new file +30 -0
new file mode 100644
index 0000000..e2312e0
@@ -0,0 +1,30 @@
+/* encrypted-type.h: encrypted-defined key type
+ *
+ * Copyright (C) 2010 IBM Corporation
+ * Author: Mimi Zohar <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 of the License.
+ */
+
+#ifndef _KEYS_ENCRYPTED_TYPE_H
+#define _KEYS_ENCRYPTED_TYPE_H
+
+#include <linux/key.h>
+#include <linux/rcupdate.h>
+
+struct encrypted_key_payload {
+	struct rcu_head rcu;	/* RCU destructor */
+	char *master_desc;	/* datablob: master key name */
+	char *datalen;		/* datablob: decrypted key length */
+	void *iv;		/* datablob: iv */
+	void *encrypted_data;	/* datablob: encrypted key */
+	unsigned short datablob_len;	/* length of datablob */
+	unsigned short decrypted_datalen;	/* decrypted data length */
+	char decrypted_data[0];	/* decrypted data +  datablob + hmac */
+};
+
+extern struct key_type key_type_encrypted;
+
+#endif /* _KEYS_ENCRYPTED_TYPE_H */
security/Kconfig +16 -0
index 38fdaf6..d591398 100644
@@ -36,6 +36,22 @@ config TRUSTED_KEYS
 
 	  If you are unsure as to whether this is required, answer N.
 
+config ENCRYPTED_KEYS
+	tristate "ENCRYPTED KEYS"
+	depends on KEYS && TRUSTED_KEYS
+	select CRYPTO_AES
+	select CRYPTO_CBC
+	select CRYPTO_SHA256
+	select CRYPTO_RNG
+	help
+	  This option provides support for create/encrypting/decrypting keys
+	  in the kernel.  Encrypted keys are kernel generated random numbers,
+	  which are encrypted/decrypted with a 'master' symmetric key. The
+	  'master' key can be either a trusted-key or user-key type.
+	  Userspace only ever sees/stores encrypted blobs.
+
+	  If you are unsure as to whether this is required, answer N.
+
 config KEYS_DEBUG_PROC_KEYS
 	bool "Enable the /proc/keys file by which keys may be viewed"
 	depends on KEYS
security/keys/Makefile +1 -0
index fcb1070..6c94105 100644
@@ -14,6 +14,7 @@ obj-y := \
 	user_defined.o
 
 obj-$(CONFIG_TRUSTED_KEYS) += trusted_defined.o
+obj-$(CONFIG_ENCRYPTED_KEYS) += encrypted_defined.o
 obj-$(CONFIG_KEYS_COMPAT) += compat.o
 obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_SYSCTL) += sysctl.o
security/keys/encrypted_defined.c new file +782 -0

782 lines not on this page · raw message

security/keys/encrypted_defined.h new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.7.2.2