KEYS: Add support for PGP keys and signatures
Subsystems (7)
cover KEYS: Add support for PGP keys and signatures
Support for PGP keys and signatures was proposed by David long time ago, before the decision of using PKCS#7 for kernel modules signatures verification was made. After that, there has been not enough interest to support PGP too.
Lately, when discussing a proposal of introducing fsverity signatures in Fedora [1], developers expressed their preference on not having a separate key for signing, which would complicate the management of the distribution. They would be more in favor of using the same PGP key, currently used for signing RPM headers, also for file-based signatures (not only fsverity, but also IMA ones).
Another envisioned use case would be to add the ability to appraise RPM headers with their existing PGP signature, so that they can be used as an authenticated source of reference values for appraising remaining files [2].
To make these use cases possible, introduce support for PGP keys and signatures in the kernel, and load provided PGP keys in the built-in keyring, so that PGP signatures of RPM headers, fsverity digests, and IMA digests can be verified from this trust anchor.
In addition to the original version of the patch set, also introduce support for signature verification of PGP keys, so that those keys can be added to keyrings with a signature-based restriction (e.g. .ima). PGP keys are searched with partial IDs, provided with signature subtype 16 (Issuer). Search with full IDs could be supported with draft-ietf-openpgp-rfc4880bis-10, by retrieving the information from signature subtype 33 (Issuer Fingerprint). Due to the possibility of ID collisions, the key_or_keyring restriction is not supported.
The patch set includes two preliminary patches: patch 1 introduces mpi_key_length(), to get the number of bits and bytes of an MPI; patch 2 introduces rsa_parse_priv_key_raw() and rsa_parse_pub_key_raw(), to parse an RSA key in RAW format if the ASN.1 parser returns an error.
Patches 3-5 introduce the library necessary to parse PGP keys and signatures, whose support is added with patches 6-10. Patch 11 introduces verify_pgp_signature() to be used by kernel subsystems (e.g. fsverity and IMA). Patch 12 is for testing of PGP signatures. Finally, patches 13-14 allow loading a set of PGP keys from a supplied blob at boot time.
I generated the diff from [3] (rebased). It is available at:
https://github.com/robertosassu/linux/compare/pgp-signatures-v1-orig..pgp-signatures-v1
Changelog
v0 [3]:
- style fixes
- move include/linux/pgp.h and pgplib.h to crypto/asymmetric_keys
- introduce verify_pgp_signature()
- replace KEY_ALLOC_TRUSTED flag with KEY_ALLOC_BUILT_IN
- don't fetch PGP subkeys
- drop support for DSA
- store number of MPIs in pgp_key_algo_p_num_mpi array
- replace dynamic memory allocations with static ones in pgp_generate_fingerprint()
- store only keys with capability of verifying signatures
- remember selection of PGP signature packet and don't repeat parsing
- move search of the PGP key to verify the signature from the beginning to the end of the verification process (to be similar with PKCS#7)
- don't retry key search in the session keyring from the signature verification code, let the caller pass the desired keyring
- for the PGP signature test key type, retry the key search in the session keyring
- retry key search in restrict_link_by_signature() with a partial ID (provided in the PGP signature)
[1] https://fedoraproject.org/wiki/Changes/FsVerityRPM
[2] https://fedoraproject.org/wiki/Changes/DIGLIM
[3] https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-modsign.git/log/?h=pgp-parser
David Howells (8):
PGPLIB: PGP definitions (RFC 4880)
PGPLIB: Basic packet parser
PGPLIB: Signature parser
KEYS: PGP data parser
KEYS: Provide PGP key description autogeneration
KEYS: PGP-based public key signature verification
PGP: Provide a key type for testing PGP signatures
KEYS: Provide a function to load keys from a PGP keyring blob
Roberto Sassu (6):
mpi: Introduce mpi_key_length()
rsa: add parser of raw format
KEYS: Retry asym key search with partial ID in
restrict_link_by_signature()
KEYS: Calculate key digest and get signature of the key
verification: introduce verify_pgp_signature()
KEYS: Introduce load_pgp_public_keyring()
MAINTAINERS | 1 + certs/Kconfig | 11 + certs/Makefile | 7 + certs/system_certificates.S | 18 + certs/system_keyring.c | 91 ++++ crypto/asymmetric_keys/Kconfig | 38 ++ crypto/asymmetric_keys/Makefile | 13 + crypto/asymmetric_keys/pgp.h | 206 ++++++++ crypto/asymmetric_keys/pgp_library.c | 620 ++++++++++++++++++++++++ crypto/asymmetric_keys/pgp_parser.h | 18 + crypto/asymmetric_keys/pgp_preload.c | 110 +++++ crypto/asymmetric_keys/pgp_public_key.c | 484 ++++++++++++++++++ crypto/asymmetric_keys/pgp_signature.c | 507 +++++++++++++++++++ crypto/asymmetric_keys/pgp_test_key.c | 129 +++++ crypto/asymmetric_keys/pgplib.h | 74 +++ crypto/asymmetric_keys/restrict.c | 10 +- crypto/rsa.c | 14 +- crypto/rsa_helper.c | 69 +++ include/crypto/internal/rsa.h | 6 + include/crypto/pgp.h | 35 ++ include/linux/mpi.h | 2 + include/linux/verification.h | 23 + lib/mpi/mpicoder.c | 33 +- 23 files changed, 2506 insertions(+), 13 deletions(-) create mode 100644 crypto/asymmetric_keys/pgp.h create mode 100644 crypto/asymmetric_keys/pgp_library.c create mode 100644 crypto/asymmetric_keys/pgp_parser.h create mode 100644 crypto/asymmetric_keys/pgp_preload.c create mode 100644 crypto/asymmetric_keys/pgp_public_key.c create mode 100644 crypto/asymmetric_keys/pgp_signature.c create mode 100644 crypto/asymmetric_keys/pgp_test_key.c create mode 100644 crypto/asymmetric_keys/pgplib.h create mode 100644 include/crypto/pgp.h
Signature · 1 line
2.32.0
PATCH 1/14 mpi: Introduce mpi_key_length()
Introduce the new function to get the number of bits and bytes from an MPI.
--- include/linux/mpi.h | 2 ++ lib/mpi/mpicoder.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-)
include/linux/mpi.h +2 -0
@@ -90,6 +90,8 @@ enum gcry_mpi_format { };MPI mpi_read_raw_data (const void *xbuffer,size_t nbytes); +int mpi_key_length (const void *xbuffer,unsigned int ret_nread, +unsigned int *nbits_arg,unsigned int *nbytes_arg);MPI mpi_read_from_buffer (const void *buffer,unsigned *ret_nread);int mpi_fromstr (MPI val,const char *str);MPI mpi_scanval (const char *string);
lib/mpi/mpicoder.c +26 -7
@@ -79,22 +79,41 @@ MPI mpi_read_raw_data(const void *xbuffer, size_t nbytes) }EXPORT_SYMBOL_GPL (mpi_read_raw_data); -MPI mpi_read_from_buffer (const void *xbuffer,unsigned *ret_nread) +int mpi_key_length (const void *xbuffer,unsigned int ret_nread, +unsigned int *nbits_arg,unsigned int *nbytes_arg) {const uint8_t *buffer = xbuffer; -unsigned int nbits, nbytes; -MPI val; +unsigned int nbits; -if (*ret_nread <2 ) -return ERR_PTR (-EINVAL ); +if (ret_nread <2 ) +return -EINVAL ; nbits = buffer[0 ] <<8 | buffer[1 ];if (nbits >MAX_EXTERN_MPI_BITS ) {pr_info ("MPI: mpi too large (%u bits)\n" , nbits); -return ERR_PTR (-EINVAL ); +return -EINVAL ; } - nbytes =DIV_ROUND_UP (nbits,8 ); +if (nbits_arg) + *nbits_arg = nbits; +if (nbytes_arg) + *nbytes_arg =DIV_ROUND_UP (nbits,8 ); + +return 0 ; +} +EXPORT_SYMBOL_GPL (mpi_key_length); + +MPI mpi_read_from_buffer (const void *xbuffer,unsigned int *ret_nread) +{ +const uint8_t *buffer = xbuffer; +unsigned int nbytes; +MPI val; +int ret; + + ret =mpi_key_length (xbuffer, *ret_nread,NULL , &nbytes); +if (ret <0 ) +return ERR_PTR (ret); +if (nbytes +2 > *ret_nread) {pr_info ("MPI: mpi larger than buffer nbytes=%u ret_nread=%u\n" , nbytes, *ret_nread);
Signature · 1 line
2.32.0
PATCH 2/14 rsa: add parser of raw format
In reply to Roberto SassuParse the RSA key with RAW format if the ASN.1 parser returns an error.
--- crypto/rsa.c | 14 +++++-- crypto/rsa_helper.c | 69 +++++++++++++++++++++++++++++++++++ include/crypto/internal/rsa.h | 6 +++ 3 files changed, 85 insertions(+), 4 deletions(-)
crypto/rsa.c +10 -4
@@ -164,8 +164,11 @@ static int rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,rsa_free_mpi_key (mpi_key); ret =rsa_parse_pub_key (&raw_key, key, keylen); -if (ret) -return ret; +if (ret) { + ret =rsa_parse_pub_key_raw (&raw_key, key, keylen); +if (ret) +return ret; + } mpi_key->e =mpi_read_raw_data (raw_key.e, raw_key.e_sz);if (!mpi_key->e)
@@ -198,8 +201,11 @@ static int rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,rsa_free_mpi_key (mpi_key); ret =rsa_parse_priv_key (&raw_key, key, keylen); -if (ret) -return ret; +if (ret) { + ret =rsa_parse_priv_key_raw (&raw_key, key, keylen); +if (ret) +return ret; + } mpi_key->d =mpi_read_raw_data (raw_key.d, raw_key.d_sz);if (!mpi_key->d)
crypto/rsa_helper.c +69 -0
90 lines not on this page · raw message
include/crypto/internal/rsa.h +6 -0
@@ -50,8 +50,14 @@ struct rsa_key {int rsa_parse_pub_key (struct rsa_key *rsa_key,const void *key,unsigned int key_len); +int rsa_parse_pub_key_raw (struct rsa_key *rsa_key,const void *key, +unsigned int key_len); +int rsa_parse_priv_key (struct rsa_key *rsa_key,const void *key,unsigned int key_len); +int rsa_parse_priv_key_raw (struct rsa_key *rsa_key,const void *key, +unsigned int key_len); +extern struct crypto_template rsa_pkcs1pad_tmpl;#endif
Signature · 1 line
2.32.0
PATCH 3/14 PGPLIB: PGP definitions (RFC 4880)
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide some useful PGP definitions from RFC 4880. These describe details of public key crypto as used by crypto keys for things like signature verification.
--- crypto/asymmetric_keys/pgp.h | 206 +++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 crypto/asymmetric_keys/pgp.h
crypto/asymmetric_keys/pgp.h new file +206 -0
@@ -0,0 +1,206 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* PGP definitions (RFC 4880) +* +* Copyright (C) 2011 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#include <linux/types.h> + +struct pgp_key_ID { +u8 id[8 ]; +} __packed; + +struct pgp_time { +u8 time[4 ]; +} __packed; + +/* +* PGP public-key algorithm identifiers [RFC4880: 9.1] +*/ +enum pgp_pubkey_algo { +PGP_PUBKEY_RSA_ENC_OR_SIG =1 , +PGP_PUBKEY_RSA_ENC_ONLY =2 , +PGP_PUBKEY_RSA_SIG_ONLY =3 , +PGP_PUBKEY_ELGAMAL =16 , +PGP_PUBKEY_DSA =17 , +PGP_PUBKEY__LAST +}; + +/* +* PGP symmetric-key algorithm identifiers [RFC4880: 9.2] +*/ +enum pgp_symkey_algo { +PGP_SYMKEY_PLAINTEXT =0 , +PGP_SYMKEY_IDEA =1 , +PGP_SYMKEY_3DES =2 , +PGP_SYMKEY_CAST5 =3 , +PGP_SYMKEY_BLOWFISH =4 , +PGP_SYMKEY_AES_128KEY =7 , +PGP_SYMKEY_AES_192KEY =8 , +PGP_SYMKEY_AES_256KEY =9 , +PGP_SYMKEY_TWOFISH_256KEY =10 , +}; + +/* +* PGP compression algorithm identifiers [RFC4880: 9.3] +*/ +enum pgp_compr_algo { +PGP_COMPR_UNCOMPRESSED =0 , +PGP_COMPR_ZIP =1 , +PGP_COMPR_ZLIB =2 , +PGP_COMPR_BZIP2 =3 , +}; + +/* +* PGP hash algorithm identifiers [RFC4880: 9.4] +*/ +enum pgp_hash_algo { +PGP_HASH_MD5 =1 , +PGP_HASH_SHA1 =2 , +PGP_HASH_RIPE_MD_160 =3 , +PGP_HASH_SHA256 =8 , +PGP_HASH_SHA384 =9 , +PGP_HASH_SHA512 =10 , +PGP_HASH_SHA224 =11 , +PGP_HASH__LAST +}; + +extern const char *const pgp_hash_algorithms[PGP_HASH__LAST ]; + +/* +* PGP packet type tags [RFC4880: 4.3]. +*/ +enum pgp_packet_tag { +PGP_PKT_RESERVED =0 , +PGP_PKT_PUBKEY_ENC_SESSION_KEY =1 , +PGP_PKT_SIGNATURE =2 , +PGP_PKT_SYMKEY_ENC_SESSION_KEY =3 , +PGP_PKT_ONEPASS_SIGNATURE =4 , +PGP_PKT_SECRET_KEY =5 , +PGP_PKT_PUBLIC_KEY =6 , +PGP_PKT_SECRET_SUBKEY =7 , +PGP_PKT_COMPRESSED_DATA =8 , +PGP_PKT_SYM_ENC_DATA =9 , +PGP_PKT_MARKER =10 , +PGP_PKT_LITERAL_DATA =11 , +PGP_PKT_TRUST =12 , +PGP_PKT_USER_ID =13 , +PGP_PKT_PUBLIC_SUBKEY =14 , +PGP_PKT_USER_ATTRIBUTE =17 , +PGP_PKT_SYM_ENC_AND_INTEG_DATA =18 , +PGP_PKT_MODIFY_DETECT_CODE =19 , +PGP_PKT_PRIVATE_0 =60 , +PGP_PKT_PRIVATE_3 =63 , +PGP_PKT__HIGHEST =63 +}; + +/* +* Signature (tag 2) packet [RFC4880: 5.2]. +*/ +enum pgp_signature_version { +PGP_SIG_VERSION_3 =3 , +PGP_SIG_VERSION_4 =4 , +}; + +enum pgp_signature_type { +PGP_SIG_BINARY_DOCUMENT_SIG =0x00 , +PGP_SIG_CANONICAL_TEXT_DOCUMENT_SIG =0x01 , +PGP_SIG_STANDALONE_SIG =0x02 , +PGP_SIG_GENERAL_CERT_OF_UID_PUBKEY =0x10 , +PGP_SIG_PERSONAL_CERT_OF_UID_PUBKEY =0x11 , +PGP_SIG_CASUAL_CERT_OF_UID_PUBKEY =0x12 , +PGP_SIG_POSTITIVE_CERT_OF_UID_PUBKEY =0x13 , +PGP_SIG_SUBKEY_BINDING_SIG =0x18 , +PGP_SIG_PRIMARY_KEY_BINDING_SIG =0x19 , +PGP_SIG_DIRECTLY_ON_KEY =0x1F , +PGP_SIG_KEY_REVOCATION_SIG =0x20 , +PGP_SIG_SUBKEY_REVOCATION_SIG =0x28 , +PGP_SIG_CERT_REVOCATION_SIG =0x30 , +PGP_SIG_TIMESTAMP_SIG =0x40 , +PGP_SIG_THIRD_PARTY_CONFIRM_SIG =0x50 , +}; + +struct pgp_signature_v3_packet { +enum pgp_signature_version version :8 ;/* == PGP_SIG_VERSION_3 */ +u8 length_of_hashed;/* == 5 */ +struct { +enum pgp_signature_type signature_type :8 ; +struct pgp_time creation_time; + } __packed hashed; +struct pgp_key_ID issuer; +enum pgp_pubkey_algo pubkey_algo :8 ; +enum pgp_hash_algo hash_algo :8 ; +} __packed; + +struct pgp_signature_v4_packet { +enum pgp_signature_version version :8 ;/* == PGP_SIG_VERSION_4 */ +enum pgp_signature_type signature_type :8 ; +enum pgp_pubkey_algo pubkey_algo :8 ; +enum pgp_hash_algo hash_algo :8 ; +} __packed; + +/* +* V4 signature subpacket types [RFC4880: 5.2.3.1]. +*/ +enum pgp_sig_subpkt_type { +PGP_SIG_CREATION_TIME =2 , +PGP_SIG_EXPIRATION_TIME =3 , +PGP_SIG_EXPORTABLE_CERT =4 , +PGP_SIG_TRUST_SIG =5 , +PGP_SIG_REGEXP =6 , +PGP_SIG_REVOCABLE =7 , +PGP_SIG_KEY_EXPIRATION_TIME =9 , +PGP_SIG_PREF_SYM_ALGO =11 , +PGP_SIG_REVOCATION_KEY =12 , +PGP_SIG_ISSUER =16 , +PGP_SIG_NOTATION_DATA =20 , +PGP_SIG_PREF_HASH_ALGO =21 , +PGP_SIG_PREF_COMPR_ALGO =22 , +PGP_SIG_KEY_SERVER_PREFS =23 , +PGP_SIG_PREF_KEY_SERVER =24 , +PGP_SIG_PRIMARY_USER_ID =25 , +PGP_SIG_POLICY_URI =26 , +PGP_SIG_KEY_FLAGS =27 , +PGP_SIG_SIGNERS_USER_ID =28 , +PGP_SIG_REASON_FOR_REVOCATION =29 , +PGP_SIG_FEATURES =30 , +PGP_SIG_TARGET =31 , +PGP_SIG_EMBEDDED_SIG =32 , +PGP_SIG__LAST +}; + +#define PGP_SIG_SUBPKT_TYPE_CRITICAL_MASK 0x80 + +/* +* Key (tag 5, 6, 7 and 14) packet +*/ +enum pgp_key_version { +PGP_KEY_VERSION_2 =2 , +PGP_KEY_VERSION_3 =3 , +PGP_KEY_VERSION_4 =4 , +}; + +struct pgp_key_v3_packet { +enum pgp_key_version version :8 ; +struct pgp_time creation_time; +u8 expiry[2 ];/* 0 or time in days till expiry */ +enum pgp_pubkey_algo pubkey_algo :8 ; +u8 key_material[0 ]; +} __packed; + +struct pgp_key_v4_packet { +enum pgp_key_version version :8 ; +struct pgp_time creation_time; +enum pgp_pubkey_algo pubkey_algo :8 ; +u8 key_material[0 ]; +} __packed; + +/* +* Literal Data (tag 11) packet +*/ +enum pgp_literal_data_format { +PGP_LIT_FORMAT_BINARY =0x62 , +PGP_LIT_FORMAT_TEXT =0x74 , +PGP_LIT_FORMAT_TEXT_UTF8 =0x75 , +};
Signature · 1 line
2.32.0
PATCH 4/14 PGPLIB: Basic packet parser
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide a simple parser that extracts the packets from a PGP packet blob and passes the desirous ones to the given processor function:
struct pgp_parse_context {
u64 types_of_interest;
int (*process_packet)(struct pgp_parse_context *context,
enum pgp_packet_tag type,
u8 headerlen,
const u8 *data,
size_t datalen);
};
int pgp_parse_packets(const u8 *data, size_t datalen,
struct pgp_parse_context *ctx);This is configured on with CONFIG_PGP_LIBRARY.
--- crypto/asymmetric_keys/Kconfig | 6 + crypto/asymmetric_keys/Makefile | 5 + crypto/asymmetric_keys/pgp_library.c | 272 +++++++++++++++++++++++++++ crypto/asymmetric_keys/pgplib.h | 33 ++++ 4 files changed, 316 insertions(+) create mode 100644 crypto/asymmetric_keys/pgp_library.c create mode 100644 crypto/asymmetric_keys/pgplib.h
crypto/asymmetric_keys/Kconfig +6 -0
@@ -96,4 +96,10 @@ config SIGNED_PE_FILE_VERIFICATION This option provides support for verifying the signature(s) on a signed PE binary. +config PGP_LIBRARY + tristate "PGP parsing library" + help + This option enables a library that provides a number of simple + utility functions for parsing PGP (RFC 4880) packet-based messages. + endif # ASYMMETRIC_KEY_TYPE
crypto/asymmetric_keys/Makefile +5 -0
@@ -86,3 +86,8 @@ tpm_key_parser-y := \ $(obj)/tpm_parser.o: $(obj)/tpm.asn1.h $(obj)/tpm.asn1.o: $(obj)/tpm.asn1.c $(obj)/tpm.asn1.h + +# +# PGP handling +# +obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o
crypto/asymmetric_keys/pgp_library.c new file +272 -0
272 lines not on this page · raw message
crypto/asymmetric_keys/pgplib.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* PGP library definitions (RFC 4880) +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#include "pgp.h" + +/* +* PGP library packet parser +*/ +struct pgp_parse_context { +u64 types_of_interest; +int (*process_packet)(struct pgp_parse_context *context, +enum pgp_packet_tag type, +u8 headerlen, +const u8 *data, +size_t datalen); +}; + +extern int pgp_parse_packets (const u8 *data,size_t datalen, +struct pgp_parse_context *ctx); + +struct pgp_parse_pubkey { +enum pgp_key_version version :8 ; +enum pgp_pubkey_algo pubkey_algo :8 ; +__kernel_old_time_t creation_time; +__kernel_old_time_t expires_at; +}; + +extern int pgp_parse_public_key (const u8 **_data,size_t *_datalen, +struct pgp_parse_pubkey *pk);
Signature · 1 line
2.32.0
PATCH 5/14 PGPLIB: Signature parser
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide some PGP signature parsing helpers:
(1) A function to parse V4 signature subpackets and pass the desired ones to a processor function:
int pgp_parse_sig_subpkts(const u8 *data, size_t datalen,
struct pgp_parse_sig_context *ctx);
(2) A function to parse out basic signature parameters from any PGP signature such that the algorithms and public key can be selected:
int pgp_parse_sig_params(const u8 **_data, size_t *_datalen,
struct pgp_sig_parameters *p);
--- crypto/asymmetric_keys/pgp_library.c | 284 +++++++++++++++++++++++++++ crypto/asymmetric_keys/pgplib.h | 25 +++ 2 files changed, 309 insertions(+)
crypto/asymmetric_keys/pgp_library.c +284 -0
@@ -270,3 +270,287 @@ int pgp_parse_public_key(const u8 **_data, size_t *_datalen,return 0 ; }EXPORT_SYMBOL_GPL (pgp_parse_public_key); + +/** +* pgp_parse_sig_subpkt_header - Parse a PGP V4 signature subpacket header +* @_data: Start of the subpacket (updated to subpacket data) +* @_datalen: Amount of data remaining in buffer (decreased) +* @_type: Where the subpacket type will be returned +* +* Parse a PGP V4 signature subpacket header [RFC 4880: 5.2.3.1]. +* +* Return: packet data size on success; non-zero on error. If successful, +* *_data and *_datalen will have been updated and *_headerlen will be set to +* hold the length of the packet header. +*/ +static ssize_t pgp_parse_sig_subpkt_header (const u8 **_data,size_t *_datalen, +enum pgp_sig_subpkt_type *_type) +{ +enum pgp_sig_subpkt_type type; +const u8 *data = *_data; +size_t size, datalen = *_datalen; + +pr_devel ("-->%s(,%zu,,)\n" , __func__, datalen); + +if (datalen <2 ) + goto short_subpacket; + +pr_devel ("subpkt hdr %02x, %02x\n" , data[0 ], data[1 ]); + +switch (data[0 ]) { + case 0x00 ... 0xbf: +/* One-byte length */ + size = data[0 ]; + data++; + datalen--; +break ; + case 0xc0 ... 0xfe: +/* Two-byte length */ +if (datalen <3 ) + goto short_subpacket; + size = (data[0 ] -192 ) *256 ; + size += data[1 ] +192 ; + data +=2 ; + datalen -=2 ; +break ; +case 0xff : +if (datalen <6 ) + goto short_subpacket; + size = data[1 ] <<24 ; + size |= data[2 ] <<16 ; + size |= data[3 ] <<8 ; + size |= data[4 ]; + data +=5 ; + datalen -=5 ; +break ; + } + +/* The type octet is included in the size */ +pr_devel ("datalen=%zu size=%zu\n" , datalen, size); +if (datalen < size) + goto short_subpacket; +if (size ==0 ) + goto very_short_subpacket; +if (size >INT_MAX ) + goto too_big; + + type = *data++ & ~PGP_SIG_SUBPKT_TYPE_CRITICAL_MASK ; + datalen--; + size--; + + *_data = data; + *_datalen = datalen; + *_type = type; +pr_devel ("Found subpkt type=%u size=%zd\n" , type, size); +return size; + +very_short_subpacket: +pr_debug ("Signature subpacket size can't be zero\n" ); +return -EBADMSG ; +short_subpacket: +pr_debug ("Attempt to parse short signature subpacket\n" ); +return -EBADMSG ; +too_big: +pr_debug ("Signature subpacket size >2G\n" ); +return -EMSGSIZE ; +} + +/** +* pgp_parse_sig_subpkts - Parse a set of PGP V4 signatute subpackets +* @data: Data to be parsed (updated) +* @datalen: Amount of data (updated) +* @ctx: Parsing context +* +* Parse a set of PGP signature subpackets [RFC 4880: 5.2.3]. +* +* Return: 0 on successful parsing, an error value otherwise +*/ +static int pgp_parse_sig_subpkts (const u8 *data,size_t datalen, +struct pgp_parse_sig_context *ctx) +{ +enum pgp_sig_subpkt_type type; +ssize_t pktlen; +int ret; + +pr_devel ("-->%s(,%zu,,)\n" , __func__, datalen); + +while (datalen >2 ) { + pktlen =pgp_parse_sig_subpkt_header (&data, &datalen, &type); +if (pktlen <0 ) +return pktlen; +if (test_bit (type, ctx->types_of_interest)) { + ret = ctx->process_packet (ctx, type, data, pktlen); +if (ret <0 ) +return ret; + } + data += pktlen; + datalen -= pktlen; + } + +if (datalen !=0 ) { +pr_debug ("Excess octets in signature subpacket stream\n" ); +return -EBADMSG ; + } + +return 0 ; +} + +struct pgp_parse_sig_params_ctx { +struct pgp_parse_sig_context base; +struct pgp_sig_parameters *params; +bool got_the_issuer; +}; + +/* +* Process a V4 signature subpacket. +*/ +static int pgp_process_sig_params_subpkt (struct pgp_parse_sig_context *context, +enum pgp_sig_subpkt_type type, +const u8 *data, +size_t datalen) +{ +struct pgp_parse_sig_params_ctx *ctx = + container_of(context, struct pgp_parse_sig_params_ctx, base); + +if (ctx->got_the_issuer) { +pr_debug ("V4 signature packet has multiple issuers\n" ); +return -EBADMSG ; + } + +if (datalen !=8 ) { +pr_debug ("V4 signature issuer subpkt not 8 long (%zu)\n" , + datalen); +return -EBADMSG ; + } + +memcpy (&ctx->params->issuer, data,8 ); + ctx->got_the_issuer = true; +return 0 ; +} + +/** +* pgp_parse_sig_params - Parse basic parameters from a PGP signature packet +* @_data: Content of packet (updated) +* @_datalen: Length of packet remaining (updated) +* @p: The basic parameters +* +* Parse the basic parameters from a PGP signature packet [RFC 4880: 5.2] that +* are needed to start off a signature verification operation. The only ones +* actually necessary are the signature type (which affects how the data is +* transformed) and the hash algorithm. +* +* We also extract the public key algorithm and the issuer's key ID as we'll +* need those to determine if we actually have the public key available. If +* not, then we can't verify the signature anyway. +* +* Return: 0 if successful or a negative error code. *_data and *_datalen are +* updated to point to the 16-bit subset of the hash value and the set of MPIs. +*/ +int pgp_parse_sig_params (const u8 **_data,size_t *_datalen, +struct pgp_sig_parameters *p) +{ +const u8 *data = *_data; +size_t datalen = *_datalen; +int ret; + +pr_devel ("-->%s(,%zu,,)\n" , __func__, datalen); + +if (datalen <1 ) +return -EBADMSG ; + p->version = *data; + +if (p->version ==PGP_SIG_VERSION_3 ) { +const struct pgp_signature_v3_packet *v3 = (const void *)data; + +if (datalen <sizeof (*v3)) { +pr_debug ("Short V3 signature packet\n" ); +return -EBADMSG ; + } + datalen -=sizeof (*v3); + data +=sizeof (*v3); + +/* V3 has everything we need in the header */ + p->signature_type = v3->hashed.signature_type; +memcpy (&p->issuer, &v3->issuer,8 ); + p->pubkey_algo = v3->pubkey_algo; + p->hash_algo = v3->hash_algo; + + }else if (p->version ==PGP_SIG_VERSION_4 ) { +const struct pgp_signature_v4_packet *v4 = (const void *)data; +struct pgp_parse_sig_params_ctx ctx = { + .base.process_packet = pgp_process_sig_params_subpkt, + .params = p, + .got_the_issuer = false, + }; +size_t subdatalen; + +if (datalen <sizeof (*v4) +2 +2 +2 ) { +pr_debug ("Short V4 signature packet\n" ); +return -EBADMSG ; + } + datalen -=sizeof (*v4); + data +=sizeof (*v4); + +/* V4 has most things in the header... */ + p->signature_type = v4->signature_type; + p->pubkey_algo = v4->pubkey_algo; + p->hash_algo = v4->hash_algo; + +/* +* ... but we have to get the key ID from the subpackets, of +* which there are two sets. +*/ +__set_bit (PGP_SIG_ISSUER , ctx.base.types_of_interest); + + subdatalen = *data++ <<8 ; + subdatalen |= *data++; + datalen -=2 ; +if (subdatalen) { +/* Hashed subpackets */ +pr_devel ("hashed data: %zu (after %zu)\n" , + subdatalen,sizeof (*v4)); +if (subdatalen > datalen +2 +2 ) { +pr_debug ("Short V4 signature packet [hdata]\n" ); +return -EBADMSG ; + } + ret =pgp_parse_sig_subpkts (data, subdatalen, + &ctx.base); +if (ret <0 ) +return ret; + data += subdatalen; + datalen -= subdatalen; + } + + subdatalen = *data++ <<8 ; + subdatalen |= *data++; + datalen -=2 ; +if (subdatalen) { +/* Unhashed subpackets */ +pr_devel ("unhashed data: %zu\n" , subdatalen); +if (subdatalen > datalen +2 ) { +pr_debug ("Short V4 signature packet [udata]\n" ); +return -EBADMSG ; + } + ret =pgp_parse_sig_subpkts (data, subdatalen, + &ctx.base); +if (ret <0 ) +return ret; + data += subdatalen; + datalen -= subdatalen; + } + +if (!ctx.got_the_issuer) { +pr_debug ("V4 signature packet lacks issuer\n" ); +return -EBADMSG ; + } + }else { +pr_debug ("Signature packet with unhandled version %d\n" , + p->version); +return -EBADMSG ; + } + + *_data = data; + *_datalen = datalen; +return 0 ; +} +EXPORT_SYMBOL_GPL (pgp_parse_sig_params);
crypto/asymmetric_keys/pgplib.h +25 -0
@@ -31,3 +31,28 @@ struct pgp_parse_pubkey {extern int pgp_parse_public_key (const u8 **_data,size_t *_datalen,struct pgp_parse_pubkey *pk); + +struct pgp_parse_sig_context { +unsigned long types_of_interest[128 /BITS_PER_LONG ]; +int (*process_packet)(struct pgp_parse_sig_context *context, +enum pgp_sig_subpkt_type type, +const u8 *data, +size_t datalen); +}; + +extern int pgp_parse_sig_packets (const u8 *data,size_t datalen, +struct pgp_parse_sig_context *ctx); + +struct pgp_sig_parameters { +enum pgp_signature_version version :8 ; +enum pgp_signature_type signature_type :8 ; +enum pgp_pubkey_algo pubkey_algo :8 ; +enum pgp_hash_algo hash_algo :8 ; +union { +struct pgp_key_ID issuer; +__be32 issuer32[2 ]; + }; +}; + +extern int pgp_parse_sig_params (const u8 **_data,size_t *_datalen, +struct pgp_sig_parameters *p);
Signature · 1 line
2.32.0
PATCH 6/14 KEYS: PGP data parser
In reply to Roberto SassuFrom: David Howells <[email protected]>
Implement a PGP data parser for the crypto key type to use when instantiating a key.
This parser attempts to parse the instantiation data as a PGP packet sequence (RFC 4880) and if it parses okay, attempts to extract a public-key algorithm key or subkey from it.
If it finds such a key, it will set up a public_key subtype payload with appropriate handler routines (RSA) and attach it to the key.
Thanks to Tetsuo Handa <[email protected]> for pointing out some errors.
--- crypto/asymmetric_keys/Kconfig | 11 + crypto/asymmetric_keys/Makefile | 4 + crypto/asymmetric_keys/pgp_parser.h | 18 ++ crypto/asymmetric_keys/pgp_public_key.c | 358 ++++++++++++++++++++++++ 4 files changed, 391 insertions(+) create mode 100644 crypto/asymmetric_keys/pgp_parser.h create mode 100644 crypto/asymmetric_keys/pgp_public_key.c
crypto/asymmetric_keys/Kconfig +11 -0
@@ -102,4 +102,15 @@ config PGP_LIBRARY This option enables a library that provides a number of simple utility functions for parsing PGP (RFC 4880) packet-based messages. +config PGP_KEY_PARSER + tristate "PGP key parser" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select PGP_LIBRARY + select MD5 # V3 fingerprint generation + select SHA1 # V4 fingerprint generation + help + This option provides support for parsing PGP (RFC 4880) format blobs + for key data and provides the ability to instantiate a crypto key + from a public key packet found inside the blob. + endif # ASYMMETRIC_KEY_TYPE
crypto/asymmetric_keys/Makefile +4 -0
@@ -91,3 +91,7 @@ $(obj)/tpm.asn1.o: $(obj)/tpm.asn1.c $(obj)/tpm.asn1.h # PGP handling # obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o + +obj-$(CONFIG_PGP_KEY_PARSER) += pgp_key_parser.o +pgp_key_parser-y := \ + pgp_public_key.o
crypto/asymmetric_keys/pgp_parser.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* PGP crypto data parser internal definitions +* +* Copyright (C) 2011 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#include "pgplib.h" + +#define kenter (FMT , ...) \ + pr_devel("==> %s("FMT")\n", __func__, ##__VA_ARGS__) +#define kleave (FMT , ...) \ + pr_devel("<== %s()"FMT"\n", __func__, ##__VA_ARGS__) + +/* +* pgp_public_key.c +*/ +extern const char *pgp_to_public_key_algo[PGP_PUBKEY__LAST ];
crypto/asymmetric_keys/pgp_public_key.c new file +358 -0
358 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 7/14 KEYS: Provide PGP key description autogeneration
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide a facility to autogenerate the name of PGP keys from the contents of the payload. If add_key() is given a blank description, a description is constructed from the last user ID packet in the payload data plus the last 8 hex digits of the key ID. For instance:
keyctl padd asymmetric "" @s </tmp/key.pub
might create a key with a constructed description that can be seen in /proc/keys:
2f674b96 I--Q--- 1 perm 39390000 0 0 crypto \ Sample kernel key 31f0ae93: PGP.RSA 31f0ae93 []
--- crypto/asymmetric_keys/pgp_public_key.c | 47 ++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
crypto/asymmetric_keys/pgp_public_key.c +46 -1
@@ -59,6 +59,8 @@ struct pgp_key_data_parse_context {struct public_key *pub;u8 raw_fingerprint[HASH_MAX_DIGESTSIZE ];size_t raw_fingerprint_len; +const char *user_id; +size_t user_id_len; };/*
@@ -210,6 +212,15 @@ static int pgp_process_public_key(struct pgp_parse_context *context,kenter (",%u,%u,,%zu" , type, headerlen, datalen); +if (type ==PGP_PKT_USER_ID ) { +if (!ctx->user_id_len) { + ctx->user_id = data; + ctx->user_id_len = datalen; + } +kleave (" = 0 [user ID]" ); +return 0 ; + } +if (ctx->raw_fingerprint_len) {kleave (" = -ENOKEY [already]" );return -EBADMSG ;
@@ -315,13 +326,47 @@ static int pgp_key_parse(struct key_preparsed_payload *prep)kenter ("" );memset (&ctx,0 ,sizeof (ctx)); - ctx.pgp.types_of_interest = (1 <<PGP_PKT_PUBLIC_KEY ); + ctx.pgp.types_of_interest = (1 <<PGP_PKT_PUBLIC_KEY ) | + (1 <<PGP_PKT_USER_ID ); ctx.pgp.process_packet = pgp_process_public_key; ret =pgp_parse_packets (prep->data, prep->datalen, &ctx.pgp);if (ret <0 ) goto error; +if (ctx.user_id && ctx.user_id_len >0 ) { +/* +* Propose a description for the key (user ID without the +* comment). +*/ +size_t ulen = ctx.user_id_len; +const char *p; + + p =memchr (ctx.user_id,'(' , ulen); +if (p) { +/* Remove the comment */ +do { + p--; + }while (*p ==' ' && p > ctx.user_id); +if (*p !=' ' ) + p++; + ulen = p - ctx.user_id; + } + +if (ulen >255 -9 ) + ulen =255 -9 ; + prep->description =kmalloc (ulen +1 +8 +1 ,GFP_KERNEL ); + ret = -ENOMEM ; +if (!prep->description) + goto error; +memcpy (prep->description, ctx.user_id, ulen); + prep->description[ulen] =' ' ; +bin2hex (prep->description + ulen +1 , + ctx.raw_fingerprint + ctx.raw_fingerprint_len -4 ,4 ); + prep->description[ulen +9 ] =0 ; +pr_debug ("desc '%s'\n" , prep->description); + } +/* We're pinning the module by being linked against it */ __module_get (public_key_subtype.owner); prep->payload.data[asym_subtype] = &public_key_subtype;
Signature · 1 line
2.32.0
PATCH 8/14 KEYS: PGP-based public key signature verification
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide handlers for PGP-based public-key algorithm signature verification. This does most of the work involved in signature verification as most of it is public-key algorithm agnostic. The public-key verification algorithm itself is just the last little bit and is supplied the complete hash data to process.
This requires glue logic putting on top to make use of it - something that the patch introducing verify_pgp_signature() provides.
--- MAINTAINERS | 1 + crypto/asymmetric_keys/Makefile | 3 +- crypto/asymmetric_keys/pgp_signature.c | 507 +++++++++++++++++++++++++ include/crypto/pgp.h | 29 ++ 4 files changed, 539 insertions(+), 1 deletion(-) create mode 100644 crypto/asymmetric_keys/pgp_signature.c create mode 100644 include/crypto/pgp.h
MAINTAINERS +1 -0
@@ -3025,6 +3025,7 @@ L: [email protected] S: Maintained F: Documentation/crypto/asymmetric-keys.rst F: crypto/asymmetric_keys/ +F: include/crypto/pgp.h F: include/crypto/pkcs7.h F: include/crypto/public_key.h F: include/linux/verification.h
crypto/asymmetric_keys/Makefile +2 -1
@@ -94,4 +94,5 @@ obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o obj-$(CONFIG_PGP_KEY_PARSER) += pgp_key_parser.o pgp_key_parser-y := \ - pgp_public_key.o + pgp_public_key.o \ + pgp_signature.o
crypto/asymmetric_keys/pgp_signature.c new file +507 -0
507 lines not on this page · raw message
include/crypto/pgp.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* PGP signature processing +* +* Copyright (C) 2014 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#ifndef _CRYPTO_PGP_H +#define _CRYPTO_PGP_H + +#include <crypto/hash_info.h> + +struct key ; +struct pgp_sig_verify ; + +/* +* pgp_signature.c +*/ +extern struct pgp_sig_verify *pgp_sig_parse (const u8 *sigdata,size_t siglen); +extern int pgp_sig_add_data (struct pgp_sig_verify *ctx, +const void *data,size_t datalen); +extern int pgp_sig_get_digest (struct pgp_sig_verify *ctx,const u8 **buf, +u32 *len,enum hash_algo *hash_algo); +extern int pgp_sig_verify (struct pgp_sig_verify *ctx,struct key *keyring); +extern void pgp_sig_verify_cancel (struct pgp_sig_verify *ctx,bool keep_sig); +extern struct public_key_signature *pgp_sig_get_sig (struct pgp_sig_verify *ctx); +extern u8 pgp_sig_get_version (struct pgp_sig_verify *ctx); + +#endif /* _CRYPTO_PGP_H */
Signature · 1 line
2.32.0
PATCH 9/14 KEYS: Retry asym key search with partial ID in restrict_link_by_signature()
In reply to Roberto SassuRetry asymmetric key search in restrict_link_by_signature() to support the case of partial IDs, provided by PGP signatures (only the last 8 bytes).
Although recently draft-ietf-openpgp-rfc4880bis-10 supports the signature subpacket type 33, which contains the full issuer fingerprint, we cannot rely on existing signatures to support it.
--- crypto/asymmetric_keys/restrict.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
crypto/asymmetric_keys/restrict.c +8 -2
@@ -97,8 +97,14 @@ int restrict_link_by_signature(struct key *dest_keyring, key =find_asymmetric_key (trust_keyring, sig->auth_ids[0 ], sig->auth_ids[1 ], false); -if (IS_ERR (key)) -return -ENOKEY ; +if (IS_ERR (key)) { +/* Retry with a partial ID. */ + key =find_asymmetric_key (trust_keyring, + sig->auth_ids[0 ], sig->auth_ids[1 ], + true); +if (IS_ERR (key)) +return -ENOKEY ; + }if (use_builtin_keys && !test_bit (KEY_FLAG_BUILTIN , &key->flags)) ret = -ENOKEY ;
Signature · 1 line
2.32.0
PATCH 10/14 KEYS: Calculate key digest and get signature of the key
In reply to Roberto SassuCalculate the digest of the signature, according to the RFC4880 section 5.2.4, get the last suitable signature with type 0x13 (Positive certification of a User ID and Public Key packet), and store it in the asym_auth field of the key payload, so that it is available for validating a restriction on a keyring.
The rationale of taking the last signature is that, if there are multiple signatures, that would be of a different issuer (not a self-signature), that likely has more chances to be useful for the restriction verification. If there is one (the self-signature), that will be used.
--- crypto/asymmetric_keys/pgp_public_key.c | 81 +++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
crypto/asymmetric_keys/pgp_public_key.c +81 -0
@@ -14,6 +14,7 @@#include <keys/asymmetric-parser.h> #include <crypto/hash.h> #include <crypto/public_key.h> +#include <crypto/pgp.h> #include "pgp_parser.h"
@@ -61,6 +62,8 @@ struct pgp_key_data_parse_context {size_t raw_fingerprint_len;const char *user_id;size_t user_id_len; +const char *key_pkt; +size_t key_pkt_len; };/*
@@ -226,6 +229,12 @@ static int pgp_process_public_key(struct pgp_parse_context *context,return -EBADMSG ; } +/* Pointer refers to data being processed. */ +if (type ==PGP_PKT_PUBLIC_KEY ) { + ctx->key_pkt = data; + ctx->key_pkt_len = datalen; + } + pub =kzalloc (sizeof (struct public_key ),GFP_KERNEL );if (!pub)return -ENOMEM ;
@@ -314,6 +323,77 @@ static struct asymmetric_key_ids *pgp_key_generate_id(return NULL ; } +/* +* Calculate the digest of the signature according to the RFC4880, section +* 5.2.4 (packet type 0x13). +*/ +static int pgp_key_add_sig_data (struct pgp_key_data_parse_context *ctx, +struct pgp_sig_verify *sig_ctx) +{ +loff_t offset =0 ; +u8 *data; + +if (!ctx->key_pkt_len || !ctx->user_id_len) +return 0 ; + +/* 0x99 + key pkt len + key pkt + 0xb4 + user ID len + user ID */ + data =kmalloc (1 +sizeof (u16) + ctx->key_pkt_len + +1 +sizeof (u32) + ctx->user_id_len,GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data[offset++] =0x99 ; + data[offset++] = ctx->key_pkt_len >>8 ; + data[offset++] = ctx->key_pkt_len; + +memcpy (data + offset, ctx->key_pkt, ctx->key_pkt_len); + offset += ctx->key_pkt_len; + +if (pgp_sig_get_version (sig_ctx) ==PGP_SIG_VERSION_4 ) { + data[offset++] =0xb4 ; + data[offset++] = ctx->user_id_len >>24 ; + data[offset++] = ctx->user_id_len >>16 ; + data[offset++] = ctx->user_id_len >>8 ; + data[offset++] = ctx->user_id_len; + } + +memcpy (data + offset, ctx->user_id, ctx->user_id_len); + offset += ctx->user_id_len; + +pgp_sig_add_data (sig_ctx, data, offset); +kfree (data); +return 0 ; +} + +static struct public_key_signature *pgp_key_get_sig ( +struct key_preparsed_payload *prep, +struct pgp_key_data_parse_context *ctx) +{ +struct public_key_signature *sig =NULL ; +struct pgp_sig_verify *sig_ctx; +bool keep_sig = false; +int ret; + + sig_ctx =pgp_sig_parse (prep->data, prep->datalen); +if (IS_ERR (sig_ctx)) +return NULL ; + + ret =pgp_key_add_sig_data (ctx, sig_ctx); +if (ret <0 ) + goto out; + + sig =pgp_sig_get_sig (sig_ctx); +if (IS_ERR (sig)) { + sig =NULL ; + goto out; + } + + keep_sig = true; +out: +pgp_sig_verify_cancel (sig_ctx, keep_sig); +return sig; +} +/* * Attempt to parse the instantiation data blob for a key as a PGP packet * message holding a key.
@@ -372,6 +452,7 @@ static int pgp_key_parse(struct key_preparsed_payload *prep) prep->payload.data[asym_subtype] = &public_key_subtype; prep->payload.data[asym_key_ids] =pgp_key_generate_id (&ctx); prep->payload.data[asym_crypto] = ctx.pub; + prep->payload.data[asym_auth] =pgp_key_get_sig (prep, &ctx); prep->quotalen =100 ;return 0 ;
Signature · 1 line
2.32.0
PATCH 11/14 verification: introduce verify_pgp_signature()
In reply to Roberto SassuIntroduce verify_pgp_signature() to verify PGP signatures from detached data. It will be used by fsverity and by IMA.
--- certs/system_keyring.c | 70 ++++++++++++++++++++++++++++++++++++ include/linux/verification.h | 23 ++++++++++++ 2 files changed, 93 insertions(+)
certs/system_keyring.c +70 -0
@@ -16,6 +16,7 @@#include <keys/asymmetric-type.h> #include <keys/system_keyring.h> #include <crypto/pkcs7.h> +#include <crypto/pgp.h> #include "common.h" static struct key *builtin_trusted_keys;
@@ -289,6 +290,75 @@ int verify_pkcs7_signature(const void *data, size_t len, }EXPORT_SYMBOL_GPL (verify_pkcs7_signature); +#ifdef CONFIG_PGP_KEY_PARSER +/** +* verify_pgp_signature - Verify a PGP-based signature on system data. +* @data: The data to be verified (must be provided). +* @len: Size of @data. +* @raw_pgp: The PGP message that is the signature. +* @pgp_len: The size of @raw_pgp. +* @trusted_keys: Trusted keys to use (NULL for builtin trusted keys only, +* (void *)1UL for all trusted keys). +* @usage: The use to which the key is being put. +* @view_content: Callback to gain access to content. +* @ctx: Context for callback. +*/ +int verify_pgp_signature (const void *data,size_t len, +const void *raw_pgp,size_t pgp_len, +struct key *trusted_keys, +enum key_being_used_for usage, +int (*view_content)(void *ctx, +const void *data,size_t len, +size_t asn1hdrlen), +void *ctx) +{ +struct pgp_sig_verify *pgp_ctx; +int ret; + +if (!data || !len) +return -EINVAL ; + + pgp_ctx =pgp_sig_parse (raw_pgp, pgp_len); +if (IS_ERR (pgp_ctx)) +return PTR_ERR (pgp_ctx); + +if (!trusted_keys) { + trusted_keys = builtin_trusted_keys; + }else if (trusted_keys ==VERIFY_USE_SECONDARY_KEYRING ) { +#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING + trusted_keys = secondary_trusted_keys; +#else + trusted_keys = builtin_trusted_keys; +#endif + }else if (trusted_keys ==VERIFY_USE_PLATFORM_KEYRING ) { +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING + trusted_keys = platform_trusted_keys; +#else + trusted_keys =NULL ; +#endif +if (!trusted_keys) { + ret = -ENOKEY ; +pr_devel ("PGP platform keyring is not available\n" ); + goto error; + } + } + +/* The data should be detached - so we need to supply it. */ +if (pgp_sig_add_data (pgp_ctx, data, len)) { +pr_err ("Failed to supply data for PGP signature\n" ); + ret = -EBADMSG ; + goto error; + } + + ret =pgp_sig_verify (pgp_ctx, trusted_keys); +error: +pgp_sig_verify_cancel (pgp_ctx, false); +pr_devel ("<==%s() = %d\n" , __func__, ret); +return ret; +} +EXPORT_SYMBOL_GPL (verify_pgp_signature); + +#endif /* CONFIG_PGP_KEY_PARSER */ #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */ #ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING
include/linux/verification.h +23 -0
@@ -54,6 +54,29 @@ extern int verify_pkcs7_message_sig(const void *data, size_t len, size_t asn1hdrlen), void *ctx); +#ifdef CONFIG_PGP_KEY_PARSER +extern int verify_pgp_signature (const void *data,size_t len, +const void *raw_pgp,size_t pgp_len, +struct key *trusted_keys, +enum key_being_used_for usage, +int (*view_content)(void *ctx, +const void *data,size_t len, +size_t asn1hdrlen), +void *ctx); +#else +static inline int verify_pgp_signature (const void *data,size_t len, +const void *raw_pgp,size_t pgp_len, +struct key *trusted_keys, +enum key_being_used_for usage, +int (*view_content)(void *ctx, +const void *data,size_t len, +size_t asn1hdrlen), +void *ctx) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_PGP_KEY_PARSER */ +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION extern int verify_pefile_signature(const void *pebuf, unsigned pelen, struct key *trusted_keys,
Signature · 1 line
2.32.0
PATCH 12/14 PGP: Provide a key type for testing PGP signatures
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide a key type for testing the PGP signature parser. It is given a non-detached PGP message as payload:
keyctl padd pgp_test a @s <content.txt.gpg
A suitable message can be generated like this:
echo "This is a test attached-signed content" >content.txt gpg --compress-algo=none -s content.txt
--- crypto/asymmetric_keys/Kconfig | 13 +++ crypto/asymmetric_keys/Makefile | 2 + crypto/asymmetric_keys/pgp_library.c | 64 +++++++++++++ crypto/asymmetric_keys/pgp_test_key.c | 129 ++++++++++++++++++++++++++ crypto/asymmetric_keys/pgplib.h | 16 ++++ 5 files changed, 224 insertions(+) create mode 100644 crypto/asymmetric_keys/pgp_test_key.c
crypto/asymmetric_keys/Kconfig +13 -0
@@ -113,4 +113,17 @@ config PGP_KEY_PARSER for key data and provides the ability to instantiate a crypto key from a public key packet found inside the blob. +config PGP_TEST_KEY + tristate "PGP testing key type" + depends on SYSTEM_DATA_VERIFICATION + depends on PGP_KEY_PARSER=y + help + This option provides a type of key that can be loaded up from a + PGP message - provided the message is signed by a trusted key. If + it is, the PGP wrapper is discarded and reading the key returns + just the payload. If it isn't, adding the key will fail with an + error. + + This is intended for testing the PGP parser. + endif # ASYMMETRIC_KEY_TYPE
crypto/asymmetric_keys/Makefile +2 -0
@@ -96,3 +96,5 @@ obj-$(CONFIG_PGP_KEY_PARSER) += pgp_key_parser.o pgp_key_parser-y := \ pgp_public_key.o \ pgp_signature.o + +obj-$(CONFIG_PGP_TEST_KEY) += pgp_test_key.o
crypto/asymmetric_keys/pgp_library.c +64 -0
67 lines not on this page · raw message
crypto/asymmetric_keys/pgp_test_key.c new file +129 -0
129 lines not on this page · raw message
crypto/asymmetric_keys/pgplib.h +16 -0
@@ -56,3 +56,19 @@ struct pgp_sig_parameters {extern int pgp_parse_sig_params (const u8 **_data,size_t *_datalen,struct pgp_sig_parameters *p); + +#if IS_ENABLED (CONFIG_PGP_TEST_KEY ) + +struct pgp_literal_data_parameters { +enum pgp_literal_data_format format :8 ; +u8 filename_len; +u8 filename_offset; +u8 content_offset; +u32 content_len; +u32 time; +}; + +extern int pgp_parse_literal_data (const u8 *data,size_t datalen, +struct pgp_literal_data_parameters *p); + +#endif /* CONFIG_PGP_TEST_KEY */
Signature · 1 line
2.32.0
PATCH 13/14 KEYS: Provide a function to load keys from a PGP keyring blob
In reply to Roberto SassuFrom: David Howells <[email protected]>
Provide a function to load keys from a PGP keyring blob to the built-in keyring:
int preload_pgp_keys(const u8 *pgpdata, size_t pgpdatalen, struct key *keyring);
Descriptions are generated from user ID notes and key fingerprints. The keys will actually be identified by the ID calculated from the PGP data rather than by the description, so this shouldn't be a problem.
The keys are attached to the keyring supplied.
Looking as root in /proc/keys after the built-in keyring has been loaded:
383a00c1 I------ 1 perm 1f030000 0 0 asymmetri \ Red Hat, Inc. dbeca166: PGP.DSA dbeca166 []
Thanks to Tetsuo Handa <[email protected]> for some pointing out some errors.
--- crypto/asymmetric_keys/Kconfig | 8 ++ crypto/asymmetric_keys/Makefile | 1 + crypto/asymmetric_keys/pgp_preload.c | 110 +++++++++++++++++++++++++++ include/crypto/pgp.h | 8 +- 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 crypto/asymmetric_keys/pgp_preload.c
crypto/asymmetric_keys/Kconfig +8 -0
@@ -126,4 +126,12 @@ config PGP_TEST_KEY This is intended for testing the PGP parser. +config PGP_PRELOAD + bool "PGP public key preloading facility" + depends on SYSTEM_TRUSTED_KEYRING + select PGP_KEY_PARSER + help + This option provides a facility for the kernel to preload PGP-wrapped + bundles of keys during boot to the built-in keyring. + endif # ASYMMETRIC_KEY_TYPE
crypto/asymmetric_keys/Makefile +1 -0
@@ -91,6 +91,7 @@ $(obj)/tpm.asn1.o: $(obj)/tpm.asn1.c $(obj)/tpm.asn1.h # PGP handling # obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o +obj-$(CONFIG_PGP_PRELOAD) += pgp_preload.o obj-$(CONFIG_PGP_KEY_PARSER) += pgp_key_parser.o pgp_key_parser-y := \
crypto/asymmetric_keys/pgp_preload.c new file +110 -0
110 lines not on this page · raw message
include/crypto/pgp.h +7 -1
@@ -1,5 +1,5 @@/* SPDX-License-Identifier: GPL-2.0+ */ -/* PGP signature processing +/* PGP key and signature processing * * Copyright (C) 2014 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -26,4 +26,10 @@ extern void pgp_sig_verify_cancel(struct pgp_sig_verify *ctx, bool keep_sig);extern struct public_key_signature *pgp_sig_get_sig (struct pgp_sig_verify *ctx);extern u8 pgp_sig_get_version (struct pgp_sig_verify *ctx); +/* +* pgp_preload.c +*/ +extern int __init preload_pgp_keys (const u8 *pgpdata,size_t pgpdatalen, +struct key *keyring); +#endif /* _CRYPTO_PGP_H */
Signature · 1 line
2.32.0
PATCH 14/14 KEYS: Introduce load_pgp_public_keyring()
In reply to Roberto SassuPreload PGP keys from 'pubring.gpg', placed in certs/ of the kernel source directory.
--- certs/Kconfig | 11 +++++++++++ certs/Makefile | 7 +++++++ certs/system_certificates.S | 18 ++++++++++++++++++ certs/system_keyring.c | 21 +++++++++++++++++++++ 4 files changed, 57 insertions(+)
certs/Kconfig +11 -0
@@ -126,4 +126,15 @@ config SYSTEM_REVOCATION_KEYS containing X.509 certificates to be included in the default blacklist keyring. +config PGP_PRELOAD_PUBLIC_KEYS + bool "Preload PGP public keys" + depends on SYSTEM_TRUSTED_KEYRING + select PGP_PRELOAD + default n + help + Load at boot time the PGP public keys from a reserved area (populated + with the content of 'certs/pubring.gpg' provided at kernel build + time), and add them to the built-in keyring. Invalid keys are ignored + and the loading continues. + endmenu
certs/Makefile +7 -0
@@ -22,6 +22,13 @@ $(obj)/system_certificates.o: $(obj)/x509_certificate_list # Cope with signing_key.x509 existing in $(srctree) not $(objtree) AFLAGS_system_certificates.o := -I$(srctree) +ifdef CONFIG_PGP_PRELOAD_PUBLIC_KEYS +ifeq ($(shell ls $(srctree)/certs/pubring.gpg 2> /dev/null), $(srctree)/certs/pubring.gpg) +AFLAGS_system_certificates.o += -DHAVE_PUBRING_GPG +$(obj)/system_certificates.o: $(srctree)/certs/pubring.gpg +endif +endif + quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) cmd_extract_certs = scripts/extract-cert $(2) $@
certs/system_certificates.S +18 -0
@@ -47,3 +47,21 @@ module_cert_size: #else .long __module_cert_end - __module_cert_start #endif + + .align 8 + .globl pgp_public_keys +pgp_public_keys: +__pgp_key_list_start: +#ifdef HAVE_PUBRING_GPG + .incbin "certs/pubring.gpg" +#endif +__pgp_key_list_end: + + .align 8 + .globl pgp_public_keys_size +pgp_public_keys_size: +#ifdef CONFIG_64BIT + .quad __pgp_key_list_end - __pgp_key_list_start +#else + .long __pgp_key_list_end - __pgp_key_list_start +#endif
certs/system_keyring.c +21 -0
@@ -167,6 +167,27 @@ static __init int load_system_certificate_list(void) }late_initcall (load_system_certificate_list); +#ifdef CONFIG_PGP_PRELOAD_PUBLIC_KEYS +extern __initconst const u8 pgp_public_keys[]; +extern __initconst const unsigned long pgp_public_keys_size; + +/* +* Load a list of PGP keys. +*/ +static __init int load_pgp_public_keyring (void ) +{ +pr_notice ("Load PGP public keys\n" ); + +if (preload_pgp_keys (pgp_public_keys, + pgp_public_keys_size, + builtin_trusted_keys) <0 ) +pr_err ("Can't load PGP public keys\n" ); + +return 0 ; +} +late_initcall (load_pgp_public_keyring); +#endif /* CONFIG_PGP_PRELOAD_PUBLIC_KEYS */ +#ifdef CONFIG_SYSTEM_DATA_VERIFICATION /**
Signature · 1 line
2.32.0
Quoted 11 lines · Roberto Sassu
Support for PGP keys and signatures was proposed by David long time ago, before the decision of using PKCS#7 for kernel modules signatures verification was made. After that, there has been not enough interest to support PGP too.
Lately, when discussing a proposal of introducing fsverity signatures in Fedora [1], developers expressed their preference on not having a separate key for signing, which would complicate the management of the distribution. They would be more in favor of using the same PGP key, currently used for signing RPM headers, also for file-based signatures (not only fsverity, but also IMA ones).
Aren't PGP keys simply RSA / ECC / EdDSA keys with additional metadata? Can't they be unwrapped from their (complex) PGP format in userspace and loaded raw into the kernel, in a similar way as they are sometimes used for SSH authentication?
This will save us from having to add complex parsers (a well-known source of bugs) into the kernel - I guess there aren't any plans to add an in-kernel PGP Web of Trust implementation.
Thanks,
Maciej
Quoted 15 lines
From: Maciej S. Szmigiero [mailto:[email protected]]
Sent: Tuesday, January 11, 2022 9:33 PMQuoted 11 lines · Roberto Sassu
Support for PGP keys and signatures was proposed by David long time ago, before the decision of using PKCS#7 for kernel modules signatures verification was made. After that, there has been not enough interest to support PGP too.
Lately, when discussing a proposal of introducing fsverity signatures in Fedora [1], developers expressed their preference on not having a separate key for signing, which would complicate the management of the distribution. They would be more in favor of using the same PGP key, currently used for signing RPM headers, also for file-based signatures (not only fsverity, but also IMA ones).
Quoted 4 lines
Aren't PGP keys simply RSA / ECC / EdDSA keys with additional metadata? Can't they be unwrapped from their (complex) PGP format in userspace and loaded raw into the kernel, in a similar way as they are sometimes used for SSH authentication?
Probably, this would be possible by introducing a new asymmetric key subtype parsing PGP keys and signatures in a more simple format, after conversion by user space. But still, a parser would be required. To be honest, I would prefer to implement (actually David did) a parser following an RFC, than developing a new one.
Quoted 3 lines
This will save us from having to add complex parsers (a well-known source of bugs) into the kernel - I guess there aren't any plans to add an in-kernel PGP Web of Trust implementation.
I extensively tested the implementation with an ad-hoc fault injector, to see if the code can correctly handle errors. I also developed a fuzzer to corrupt the data before it is read by the kernel. Finally, I checked that there are not memory leaks. But I agree, there could still be bugs.
If you mean that a key can be added to the kernel if is vouched for by another key in the built-in keyring, I actually implemented this (was missing in the original implementation). Some keyrings, e.g. .ima, have this restriction.
The way this works is that, whenever you add a PGP key to the kernel, the parser takes not only the public key and the user ID, but also its signature by the same or another PGP key.
The signature is verified when the key is added to the keyring with that restriction, and only if the verification is successful the key can be added.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 2 lines
Thanks,
Maciej
Quoted 20 lines · Roberto Sassu
Quoted 15 lines
From: Maciej S. Szmigiero [mailto:[email protected]]
Sent: Tuesday, January 11, 2022 9:33 PMQuoted 11 lines · Roberto Sassu
Support for PGP keys and signatures was proposed by David long time ago, before the decision of using PKCS#7 for kernel modules signatures verification was made. After that, there has been not enough interest to support PGP too.
Lately, when discussing a proposal of introducing fsverity signatures in Fedora [1], developers expressed their preference on not having a separate key for signing, which would complicate the management of the distribution. They would be more in favor of using the same PGP key, currently used for signing RPM headers, also for file-based signatures (not only fsverity, but also IMA ones).
Quoted 4 lines
Aren't PGP keys simply RSA / ECC / EdDSA keys with additional metadata? Can't they be unwrapped from their (complex) PGP format in userspace and loaded raw into the kernel, in a similar way as they are sometimes used for SSH authentication?
Quoted 5 lines
Probably, this would be possible by introducing a new asymmetric key subtype parsing PGP keys and signatures in a more simple format, after conversion by user space. But still, a parser would be required. To be honest, I would prefer to implement (actually David did) a parser following an RFC, than developing a new one.
A parser in userspace is preferred to one in kernel since if there is a bug somewhere its consequences are much less severe.
And experience shows that parsers are especially prone to bugs. A userspace implementation can also be tightly sandboxed for extra security.
There are many existing OpenPGP parsing libraries to choose from.
Quoted 15 lines
Quoted 3 lines
This will save us from having to add complex parsers (a well-known source of bugs) into the kernel - I guess there aren't any plans to add an in-kernel PGP Web of Trust implementation.
I extensively tested the implementation with an ad-hoc fault injector, to see if the code can correctly handle errors. I also developed a fuzzer to corrupt the data before it is read by the kernel. Finally, I checked that there are not memory leaks. But I agree, there could still be bugs.
If you mean that a key can be added to the kernel if is vouched for by another key in the built-in keyring, I actually implemented this (was missing in the original implementation). Some keyrings, e.g. .ima, have this restriction.
Quoted 7 lines
The way this works is that, whenever you add a PGP key to the kernel, the parser takes not only the public key and the user ID, but also its signature by the same or another PGP key.
The signature is verified when the key is added to the keyring with that restriction, and only if the verification is successful the key can be added.
I understand but it would be great to make use as much as possible of the existing in-kernel signature verification mechanisms.
Quoted 1 line
Roberto
Thanks,
Maciej
Quoted 30 lines
From: Maciej S. Szmigiero [mailto:[email protected]]
Sent: Wednesday, January 12, 2022 9:16 PMQuoted 11 lines · Roberto Sassu
Quoted 11 lines
From: Maciej S. Szmigiero [mailto:[email protected]]
Sent: Tuesday, January 11, 2022 9:33 PMQuoted 8 lines · Roberto Sassu
Support for PGP keys and signatures was proposed by David long time ago, before the decision of using PKCS#7 for kernel modules signatures verification was made. After that, there has been not enough interest to support PGP too.
Lately, when discussing a proposal of introducing fsverity signatures in Fedora [1], developers expressed their preference on not having a separate key for signing, which would complicate the management of the
distribution.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
They would be more in favor of using the same PGP key, currently used for signing RPM headers, also for file-based signatures (not only fsverity, but also IMA ones).
Aren't PGP keys simply RSA / ECC / EdDSA keys with additional metadata? Can't they be unwrapped from their (complex) PGP format in userspace and loaded raw into the kernel, in a similar way as they are sometimes used for SSH authentication?
Quoted 5 lines
Probably, this would be possible by introducing a new asymmetric key subtype parsing PGP keys and signatures in a more simple format, after conversion by user space. But still, a parser would be required. To be honest, I would prefer to implement (actually David did) a parser following an RFC, than developing a new one.
Quoted 7 lines
A parser in userspace is preferred to one in kernel since if there is a bug somewhere its consequences are much less severe.
And experience shows that parsers are especially prone to bugs. A userspace implementation can also be tightly sandboxed for extra security.There are many existing OpenPGP parsing libraries to choose from.
I understand your point. However, it does not seem to me less risky to define a new format to upload the RSA key and the signature to avoid the complexity of PGP. Also, it does not seem more complex than PKCS#7, which is already in the kernel.
In addition, there are aspects of PGP that anyway have to be taken into account. One example is the digest calculation, which depends also on the PGP packet. Whenever the kernel verifies the signature, the additional data need to be appended to the original data. This risks to create more confusion, as the consumer of the data being verified might not be prepared to handle the additional data required for signature verification.
The kernel has already a well-defined way to process data with a signature. It expects a data structure called module_signature at the end of the data to verify, which include information required for the verification such as the digest algorithm, key ID, etc. It also has a selector called PKEY_ID_PGP, so that the code would handle a PGP signature. This data structure does not include space for the additional data required for the signature verification.
This patch set instead offers the new function verify_pgp_signature(), which takes the same arguments as verify_pkcs7_signature(), and can be used as in the example I mentioned above in a switch() where the selector is the signature type.
This patch set also offers the individual functions called inside verify_pgp_signature(), to support the case where the signature verification process is split in multiple parts
(e.g. security/integrity/ima/ima_modsig.c). Also in this case, the arguments passed to the PGP-related functions are similar to the PKCS#7 ones.
Another concern that I have is that, the approach of using an OpenPGP library still requires the Linux distribution vendors to do a transformation from the source data they have to another format. They have anyway to certify this transformation, even if it is done in user space. Maybe it is easier to keep the original data and verify the minimum necessary to handle PGP keys and signature in the kernel, rather than verifying a library running in user space with many other functions.
Quoted 19 lines
Quoted 19 lines
Quoted 3 lines
This will save us from having to add complex parsers (a well-known source of bugs) into the kernel - I guess there aren't any plans to add an in-kernel PGP Web of Trust implementation.
I extensively tested the implementation with an ad-hoc fault injector, to see if the code can correctly handle errors. I also developed a fuzzer to corrupt the data before it is read by the kernel. Finally, I checked that there are not memory leaks. But I agree, there could still be bugs.
If you mean that a key can be added to the kernel if is vouched for by another key in the built-in keyring, I actually implemented this (was missing in the original implementation). Some keyrings, e.g. .ima, have this restriction.
The way this works is that, whenever you add a PGP key to the kernel, the parser takes not only the public key and the user ID, but also its signature by the same or another PGP key.
Quoted 6 lines
Quoted 3 lines
The signature is verified when the key is added to the keyring with that restriction, and only if the verification is successful the key can be added.
I understand but it would be great to make use as much as possible of the existing in-kernel signature verification mechanisms.
Yes. I think this is the purpose of the asymmetric subtypes. They introduce a parser for the specific format, but once the relevant information are extracted, the in-kernel mechanisms are used.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 4 lines
Quoted 1 line
Roberto
Thanks,
Maciej
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019: https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519, similar to signify or minisign? Very minimal code in the kernel, in userspace, and very few moving parts to break.
Jason
James Bottomley
maintainerQuoted 15 lines · Jason A. Donenfeld
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019:
https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.
The reason is simple though: for all the detractors and whining, no- one's actually been able to come up with a more usable replacement. Very few people who complain about GPG actually submit patches to fix it. A few come up with their own infrastructure which tends to have even more problems.
Quoted 3 lines
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519,
Please, no, use universally supported crypto that we can use TPM hardware for, which for EC currently means P-256. It may be possible to get the TCG and the other security bodies to add Edwards signatures but the rate of progression of quantum means that Grover's Algorithm will likely get there first and we'll need P-521 or X448.
Quoted 2 lines
similar to signify or minisign? Very minimal code in the kernel, in
userspace, and very few moving parts to break.
Heh, this is the classic cryptographers dilemma: go for something pejorative which can be minimal but which has only a relatively small set of possible use cases and no future proofing or go for something extensible which ends up more complex and others then criticize as being a "swiss army knife".
James
Hi All,
Quoted 16 lines · James Bottomley
Quoted 15 lines · Jason A. Donenfeld
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019:
https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.
So while I understand why this is being proposed and clearly effort has gone into it, I also think it is not the right approach. It seems this proposal is to include a full PGP packet parser and verification logic in the kernel as an equivalent to allow PGP signatures to be submitted via FS_IOC_ENABLE_VERITY:
"FS_IOC_ENABLE_VERITY accepts a pointer to a PKCS#7 formatted detached signature in DER format of the file’s fs-verity digest."
I may be misinterpreting, but as I understand it logic for X.509/PKCS validation already exists in-kernel because of UEFI and module signing, so this signature would be verified up to trusted roots. The proposal is to duplicate all of this logic but in terms of PGP-formatted keys.
I believe this is unnecessary. Since it seems to require both a signature and verification up to a root, and distributions like Fedora already deal with x509 module signing keys for their kernel modules, I can't see the merit in including the full PGP system too. The least-effort approach, I would suggest, is to include an x509 representation of the signature in the RPM and use the existing API to push that up into the kernel, with the trust anchor the same as is used for module signing keys, or whatever distributions prefer (they, after all, control the kernel trust anchors).
I understand this requires some effort, but so too does maintaining a fully fledged PGP packet parser as privileged code for all time, and I think maintaining this in userspace is a) easier and b) less costly than doing it in kernel. As an added bonus, a PGP-parsing library in a memory-safe language could be used in userspace.
A slightly more drastic step would be to wholesale move to PKCS signatures for packaging. Linux distributions could be their own trusted roots for this purpose if they so desired, and since they control certificate bundles anyway they've no need to add them to the browser list if that is a concern, and can issue certs without SSL Client/SSL Server types and OIDs.
Quoted 5 lines
The reason is simple though: for all the detractors and whining, no- one's actually been able to come up with a more usable replacement. Very few people who complain about GPG actually submit patches to fix it. A few come up with their own infrastructure which tends to have even more problems.
Probably replacing with PKCS is a non-starter, but it is at least possible and it is highly likely distros package one or more tools capable of validating such signatures in their base installs.
There are multiple problems with PGP that receive complaints. They are:
1) No forward secrecy in messaging-based crypto.
2) The data format.
3) Outdated cryptography still supported.
4) UX.
Of these, all four could be levelled against PKCS standards and related tools too (except TLS protocols for the first point), and only 2 and 3 are relevant here since we are concerned with signature validation only.
I'm not "against" PGP per se, but I'm not convinced by the idea of adding PGP support just for fs-verity.
Quoted 9 lines
Quoted 3 lines
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519,
Please, no, use universally supported crypto that we can use TPM hardware for, which for EC currently means P-256. It may be possible to get the TCG and the other security bodies to add Edwards signatures but the rate of progression of quantum means that Grover's Algorithm will likely get there first and we'll need P-521 or X448.
I agree: whatever is chosen should in my view have decent support for hardware-backed keys, because I strongly hope that is what distribution key storage looks like. If not I might need to move to Gentoo.
The current RPM signing keys for Fedora are RSA-4096, which in my opinion does not actually meet the bar for "good hardware support for algorithm". RSA-2048 tokens are common, but 4096 much less so.
Unfortunately for this reason signify/minisign is not ideal as tools: so far as I can see it has no support for hardware-backed keys. That's not to say they couldn't, although they both use ed25519.
I am not sure if we'll end up in the situation where Grover's algorithm is efficient but Shor is not, but this is all guesswork until we get closer to a quantum computer with enough logical Qubits. But your substantive point I think is valid: hardware vendors are disappointingly slow at adopting edwards curves.
Quoted 8 lines
Quoted 2 lines
similar to signify or minisign? Very minimal code in the kernel, in
userspace, and very few moving parts to break.Heh, this is the classic cryptographers dilemma: go for something pejorative which can be minimal but which has only a relatively small set of possible use cases and no future proofing or go for something extensible which ends up more complex and others then criticize as being a "swiss army knife".
I think this is the wrong framing for the problem. We already have one extensible system that is complicated in the kernel. This patch proposes to add a second one achieving the same purpose instead of a userspace solution to take advantage of the existing code, which I think would be preferable and safer.
Antony
Eric Biggers
maintainerQuoted 21 lines · Antony Vennard
Hi All,
Quoted 16 lines · James Bottomley
Quoted 15 lines · Jason A. Donenfeld
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019:
https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.
Quoted 9 lines
So while I understand why this is being proposed and clearly effort has gone into it, I also think it is not the right approach. It seems this proposal is to include a full PGP packet parser and verification logic in the kernel as an equivalent to allow PGP signatures to be submitted via
FS_IOC_ENABLE_VERITY:"
FS_IOC_ENABLE_VERITYaccepts a pointer to a PKCS#7 formatted detached signature in DER format of the file’s fs-verity digest."
It's worth noting that if fs-verity built-in signatures are used, a trusted userspace program is still required to determine and enforce the policy of which files are required to be signed. The kernel only handles the actual signature verification. This was basically a proof-of-concept which reused the kernel's module signature verification code (which happens to use PKCS#7).
I'd encourage new users to either go all-in on a userspace solution, using a trusted userspace program to verify signatures of fs-verity file digests; *or* go all-in on an in-kernel solution, using the IMA support for fs-verity which Mimi Zohar is working on. A userspace solution could use a simple signature format, using a modern algorithm such as Ed25519. IMA uses a simple signature format too, though it uses a complex format (X.509) for public keys.
- Eric
Quoted 34 lines
From: Eric Biggers [mailto:[email protected]]
Sent: Wednesday, January 19, 2022 12:04 AMQuoted 21 lines · Antony Vennard
Hi All,
Quoted 16 lines · James Bottomley
Quoted 15 lines · Jason A. Donenfeld
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019:
https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.Quoted 9 lines
So while I understand why this is being proposed and clearly effort has gone into it, I also think it is not the right approach. It seems this proposal is to include a full PGP packet parser and verification logic in the kernel as an equivalent to allow PGP signatures to be submitted via
FS_IOC_ENABLE_VERITY:"
FS_IOC_ENABLE_VERITYaccepts a pointer to a PKCS#7 formatted detached signature in DER format of the file’s fs-verity digest."
Quoted 5 lines
It's worth noting that if fs-verity built-in signatures are used, a trusted userspace program is still required to determine and enforce the policy of which files are required to be signed. The kernel only handles the actual signature verification. This was basically a proof-of-concept which reused the kernel's module signature verification code (which happens to use PKCS#7).
Just to show how the fsverity code will look like after adding support for PGP signatures:
+ switch (vi->type) {
+ case PKEY_ID_PKCS7:
+ err = verify_pkcs7_signature(d, sizeof(*d) + hash_alg->digest_size,
+ signature, sig_size, fsverity_keyring, + VERIFYING_UNSPECIFIED_SIGNATURE, + NULL, NULL); + break; + case PKEY_ID_PGP: + err = verify_pgp_signature(d, sizeof(*d) + hash_alg->digest_size, + signature, sig_size, fsverity_keyring, + VERIFYING_UNSPECIFIED_SIGNATURE, + NULL, NULL);
+ break;
+ default:
+ err = -EOPNOTSUPP;
+ }
As you can see, the change will be straightforward.
On user space side, I plan to add the capability to fsverity-utils to produce a PGP signature with the GPG key passed by rpmsign.
Quoted 4 lines
I'd encourage new users to either go all-in on a userspace solution, using a trusted userspace program to verify signatures of fs-verity file digests; *or* go all-in on an in-kernel solution, using the IMA support for fs-verity which Mimi Zohar is working on. A userspace solution could use a simple
Probably, there is also the third option of an LSM (such as IPE) that gets from fsverity the information if the signature was validated, and decide depending on a policy. I would also expose the information about the restriction imposed on the keyring from which the key used to verify the signature was found.
Maybe IMA could use this approach too, which would avoid the need of introducing another signature format. If that is desired, you might want to coordinate with the authors of a Fedora feature:
https://fedoraproject.org/wiki/Changes/FsVerityRPM
which, as far as I know, plan to use the signature format already upstreamed.
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 4 lines
signature format, using a modern algorithm such as Ed25519. IMA uses a simple signature format too, though it uses a complex format (X.509) for public keys.
- Eric
Quoted 63 lines
From: Roberto Sassu [mailto:[email protected]]
Sent: Wednesday, January 19, 2022 2:25 PMQuoted 30 lines
From: Eric Biggers [mailto:[email protected]]
Sent: Wednesday, January 19, 2022 12:04 AMQuoted 27 lines · Antony Vennard
Hi All,
Quoted 16 lines · James Bottomley
Quoted 15 lines · Jason A. Donenfeld
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019:
https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.So while I understand why this is being proposed and clearly effort has gone into it, I also think it is not the right approach. It seems this proposal is to include a full PGP packet parser and verification logic in the kernel as an equivalent to allow PGP signatures to be submitted via
FS_IOC_ENABLE_VERITY:Quoted 6 lines
Quoted 3 lines
"
FS_IOC_ENABLE_VERITYaccepts a pointer to a PKCS#7 formatted detached signature in DER format of the file’s fs-verity digest."It's worth noting that if fs-verity built-in signatures are used, a trusted userspace program is still required to determine and enforce the policy of
which
Quoted 3 lines
files are required to be signed. The kernel only handles the actual signature verification. This was basically a proof-of-concept which reused the kernel's module signature verification code (which happens to use PKCS#7).
Just to show how the fsverity code will look like after adding support for PGP signatures:
(quoted diff) +16
-0+ switch (vi->type) { + case PKEY_ID_PKCS7: + err = verify_pkcs7_signature(d, sizeof(*d) + hash_alg->digest_size, + signature, sig_size, fsverity_keyring, + VERIFYING_UNSPECIFIED_SIGNATURE, + NULL, NULL); + break; + case PKEY_ID_PGP: + err = verify_pgp_signature(d, sizeof(*d) + hash_alg->digest_size, + signature, sig_size, fsverity_keyring, + VERIFYING_UNSPECIFIED_SIGNATURE, + NULL, NULL); + break; + default: + err = -EOPNOTSUPP; + }
Quoted 4 lines
As you can see, the change will be straightforward.
On user space side, I plan to add the capability to fsverity-utils to produce a PGP signature with the GPG key passed by rpmsign.
At the end, it was not necessary. With this patch set, rpmsign is able to produce a PGP signature without modifications to fsverity-utils:
https://github.com/robertosassu/rpm/commits/fsverity-gpg-v1
The modifications are very minimal, basically consist in introducing the new function rpmVeritySignFileGPG() that creates a file with the fsverity_formatted_digest structure, and signs it with the exposed function makeGPGSignatureArgs().
The fsverity rpm plugin works without modification, and the kernel takes care of the verification of the PGP signatures when a package is installed.
I wrote a more detailed procedure to sign and install a package with fsverity signatures in the PGP format. It can be found here:
https://www.spinics.net/lists/fedora-devel/msg296562.html
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 32 lines
Quoted 4 lines
I'd encourage new users to either go all-in on a userspace solution, using a trusted userspace program to verify signatures of fs-verity file digests; *or* go all-in on an in-kernel solution, using the IMA support for fs-verity which Mimi Zohar is working on. A userspace solution could use a simple
Probably, there is also the third option of an LSM (such as IPE) that gets from fsverity the information if the signature was validated, and decide depending on a policy. I would also expose the information about the restriction imposed on the keyring from which the key used to verify the signature was found.
Maybe IMA could use this approach too, which would avoid the need of introducing another signature format. If that is desired, you might want to coordinate with the authors of a Fedora feature:
https://fedoraproject.org/wiki/Changes/FsVerityRPM
which, as far as I know, plan to use the signature format already upstreamed.
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong RonghuaQuoted 1 line
signature format, using a modern algorithm such as Ed25519. IMA uses a
simple
Quoted 3 lines
signature format too, though it uses a complex format (X.509) for public keys.
- Eric
Quoted 10 lines · Eric Biggers
Quoted 2 lines · Antony Vennard
Hi All,
It's worth noting that if fs-verity built-in signatures are used, a trusted userspace program is still required to determine and enforce the policy of which files are required to be signed. The kernel only handles the actual signature verification. This was basically a proof-of-concept which reused the kernel's module signature verification code (which happens to use PKCS#7).
Quoted 6 lines
I'd encourage new users to either go all-in on a userspace solution, using a trusted userspace program to verify signatures of fs-verity file digests; *or* go all-in on an in-kernel solution, using the IMA support for fs-verity which Mimi Zohar is working on. A userspace solution could use a simple signature format, using a modern algorithm such as Ed25519. IMA uses a simple signature format too, though it uses a complex format (X.509) for public keys.
FWIW I checked some of the options for hardware key storage. Thales HSMs support Ed25519, at least according to their marketing materials. Similarly Javacard 3.1 supports (will support) X/Ed 25519/448, so when tokens supporting this emerge (if they haven't already) hardware support for modern algorithms should exist too.
I therefore agree. Use Ed25519.
Antony
Quoted 36 lines
From: Antony Vennard [mailto:[email protected]]
Sent: Tuesday, January 18, 2022 9:50 PM
Hi All,Quoted 16 lines · James Bottomley
Quoted 15 lines · Jason A. Donenfeld
Hi,
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019:
https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.So while I understand why this is being proposed and clearly effort has gone into it, I also think it is not the right approach. It seems this proposal is to include a full PGP packet parser and verification logic in the kernel as an equivalent to allow PGP signatures to be submitted via
FS_IOC_ENABLE_VERITY:"
FS_IOC_ENABLE_VERITYaccepts a pointer to a PKCS#7 formatted detached signature in DER format of the file’s fs-verity digest."I may be misinterpreting, but as I understand it logic for X.509/PKCS validation already exists in-kernel because of UEFI and module signing, so this signature would be verified up to trusted roots. The proposal is to duplicate all of this logic but in terms of PGP-formatted keys.
Quoted 4 lines
I believe this is unnecessary. Since it seems to require both a signature and verification up to a root, and distributions like Fedora already deal with x509 module signing keys for their kernel modules, I can't see the merit in including the full PGP system too. The
One of the problems, but I need to verify that, is that the key used for signing kernel modules might be available only when the kernel package is built. The GPG key should be available for every RPM.
If the GPG key is the only available, then probably the least-effort option would be to load the GPG key as it is. Or you have to create a dummy, unsigned X509 certificate with the public key extracted from the GPG key. The other option I mentioned in this discussion was to introduce a simple format to upload the key to the kernel, which still does not eliminate the risks due to parsing data.
In addition to that, there is the problem of maintaining the correct key IDs. If you create a dummy X509 certificate, this means calculating a new ID and using them in the signatures.
The last problem of trying to reuse the GPG key and convert it to a dummy X509 certificate is that the keyring restriction will not work. IMA and EVM keyrings requires that the key being added is signed with one of the keys in the built-in or secondary keyring. With the dummy X509 certificate, using those keyrings would not be possible.
Maybe you could include the signature in the X509 certificate, but you probably would not be able to calculate the digest for verifying the signature in the same way PGP does.
Quoted 5 lines
least-effort approach, I would suggest, is to include an x509 representation of the signature in the RPM and use the existing API to push that up into the kernel, with the trust anchor the same as is used for module signing keys, or whatever distributions prefer (they, after all, control the kernel trust anchors).
It could be even easier. IMA has already a very simple signature format. However, the main problem is the management of the keys required to verify the signatures.
After several iterations, trying to remove anything that was not essential from the patch set, I came to the conclusion that having the logic for both the keys and the signatures was the best compromise. True, it means more maintenance effort for the kernel, but this ensures the best interoperability with the current ecosystem.
I think the code is not particularly complicated that would be impractical to review.
Quoted 5 lines
I understand this requires some effort, but so too does maintaining a fully fledged PGP packet parser as privileged code for all time, and I think maintaining this in userspace is a) easier and b) less costly than doing it in kernel. As an added bonus, a PGP-parsing library in a memory-safe language could be used in userspace.
It just needs to parse the key, user ID and the signature packet and subpackets. Consider also that after parsing, nothing about PGP remains in the kernel. The asymmetric key type maintains just the public key, the key ID and the signature of the key (optionally).
Quoted 17 lines
A slightly more drastic step would be to wholesale move to PKCS signatures for packaging. Linux distributions could be their own trusted roots for this purpose if they so desired, and since they control certificate bundles anyway they've no need to add them to the browser list if that is a concern, and can issue certs without SSL Client/SSL Server types and OIDs.
Quoted 5 lines
The reason is simple though: for all the detractors and whining, no- one's actually been able to come up with a more usable replacement. Very few people who complain about GPG actually submit patches to fix it. A few come up with their own infrastructure which tends to have even more problems.
Probably replacing with PKCS is a non-starter, but it is at least possible and it is highly likely distros package one or more tools capable of validating such signatures in their base installs.
Quoted 6 lines
There are multiple problems with PGP that receive complaints. They are:
1) No forward secrecy in messaging-based crypto.
2) The data format.
3) Outdated cryptography still supported.
4) UX.
We are using PGP just for a very specific purpose, verifying signatures. Outdated cryptography could be disabled, if we wish.
Quoted 44 lines
Of these, all four could be levelled against PKCS standards and related tools too (except TLS protocols for the first point), and only 2 and 3 are relevant here since we are concerned with signature validation only.
I'm not "against" PGP per se, but I'm not convinced by the idea of adding PGP support just for fs-verity.
Quoted 9 lines
Quoted 3 lines
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519,
Please, no, use universally supported crypto that we can use TPM hardware for, which for EC currently means P-256. It may be possible to get the TCG and the other security bodies to add Edwards signatures but the rate of progression of quantum means that Grover's Algorithm will likely get there first and we'll need P-521 or X448.
I agree: whatever is chosen should in my view have decent support for hardware-backed keys, because I strongly hope that is what distribution key storage looks like. If not I might need to move to Gentoo.
The current RPM signing keys for Fedora are RSA-4096, which in my opinion does not actually meet the bar for "good hardware support for algorithm". RSA-2048 tokens are common, but 4096 much less so.
Unfortunately for this reason signify/minisign is not ideal as tools: so far as I can see it has no support for hardware-backed keys. That's not to say they couldn't, although they both use ed25519.
I am not sure if we'll end up in the situation where Grover's algorithm is efficient but Shor is not, but this is all guesswork until we get closer to a quantum computer with enough logical Qubits. But your substantive point I think is valid: hardware vendors are disappointingly slow at adopting edwards curves.
Quoted 8 lines
Quoted 2 lines
similar to signify or minisign? Very minimal code in the kernel, in
userspace, and very few moving parts to break.Heh, this is the classic cryptographers dilemma: go for something pejorative which can be minimal but which has only a relatively small set of possible use cases and no future proofing or go for something extensible which ends up more complex and others then criticize as being a "swiss army knife".
Quoted 5 lines
I think this is the wrong framing for the problem. We already have one extensible system that is complicated in the kernel. This patch proposes to add a second one achieving the same purpose instead of a userspace solution to take advantage of the existing code, which I think would be preferable and safer.
Sorry, I think that forcing all Linux distributions to do it seems unrealistic.
Parsing data in the PGP format seems to be the only barrier. Once we are confident that we parse this small number of packets correctly, the rest is just reusing the mechanisms already in place. And we make it easier for people to adopt security features.
Thanks
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 4 lines
From: Jason A. Donenfeld [mailto:[email protected]]
Sent: Monday, January 17, 2022 3:35 PM
Hi,
Quoted 12 lines
While it looks like you put a lot of work into this patchset, I think the general idea of adding PGP *to the kernel* is a pretty daunting proposition. The general consensus in the crypto engineering world is that PGP ought to be on its way out. We definitely don't want to perpetuate this project-on-life-support into the permanence of kernel code. Some quick Google searches will reveal a litany of blog posts to the tune of, "why oh why are people still using this?" Here's one from 2019: https://latacora.micro.blog/2019/07/16/the-pgp-problem.html . I think these are arguments to take seriously. And even if you disagree with some parts, you may want to consider whether the remaining parts warrant a bit of pause before adding this to the kernel and perpetuating PGP's design further.
Hi Jason
thanks a lot for the additional information. They could make people more aware of the risks so that they transition to more secure schemes.
The problem is that I don't see that transition coming soon. Transition from PGP to another scheme would require Linux distribution vendors to do an huge amount of work. It could probably take years before that transition occurs.
More specifically, the first task would be to modify how RPMs are signed (and thus how they are verified). The second task would be to have a different way to certify the public key. Lastly, Linux distribution vendors would have to change their building infrastructure to use the new certified key, a new version of the rpm package manager which takes as input the new key, produces a different type of signature and embeds it in the RPM header.
In this discussion:
people were concerned about the lifecycle of the secondary key used for fsverity signatures. Likely, completely replacing the key infrastructure would raise even bigger concerns.
The aim of this patch set is to make some security features available in a short time, by significantly reducing the burden of Linux distribution vendors for managing those security features. I mentioned fsverity, but my primary use case would be for DIGLIM (extract reference values for file digests from RPM headers and use them for IMA measurement or appraisal).
The main advantage of this patch set, at least for DIGLIM, is that it completely removes the need of changing the building infrastructure. To show the DIGLIM benefits, I retrofitted two already released Linux distributions (Fedora 34 and openSUSE Leap 15.3) with DIGLIM and the necessary changes in IMA, so that they prevent the execution of binaries and shared libraries which were not released by the distribution (the mechanism is completely configurable by the user to trust his binaries, if he wishes to). If you are interested, here is the link of the demo I developed:
https://lore.kernel.org/linux-integrity/[email protected]/
If in the future the transition from PGP to another scheme occurs, support for PGP keys and signatures can be still deprecated.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Zhong Ronghua
Quoted 7 lines
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519, similar to signify or minisign? Very minimal code in the kernel, in userspace, and very few moving parts to break.
Jason
Hi Roberto,
Thanks for your detailed reply.
Quoted 4 lines · Roberto Sassu
The problem is that I don't see that transition coming soon. Transition from PGP to another scheme would require Linux distribution vendors to do an huge amount of work. It could probably take years before that transition occurs.
Quoted 8 lines
More specifically, the first task would be to modify how RPMs are signed (and thus how they are verified). The second task would be to have a different way to certify the public key. Lastly, Linux distribution vendors would have to change their building infrastructure to use the new certified key, a new version of the rpm package manager which takes as input the new key, produces a different type of signature and embeds it in the RPM header.
Hm, yea, I see your dilemma.
On the one hand, you recognize the problems with what currently exists. On the other hand, you[r organization] hasn't made the transition to something better. So, rather than putting in what might be a lot of work to transition to something better (which includes actually evaluating *what* the better thing would be), you'd prefer to put in a smaller amount of work to make the current thing satisfy some of your needs, even though you recognize its flaws. It seems like this is one of those "short term" vs "long term" investment tradeoffs.
I don't have a whole lot _technical_ to say about long term vs short term thinking, but it does strike me that PGP is one of these cases where people have known about the flaws for decades, but the ecosystem keeps being extended because people continue to go with the short term solutions, one by one, and now they've wound up here, at the doorstep of the kernel. Maybe if at some point somebody puts down the foot and says, "the road of short term intentions stops here," there might gradually be impetus toward looking into long term solutions, e.g. viable PGP replacements? Just a thought.
Quoted 3 lines
If in the future the transition from PGP to another scheme occurs, support for PGP keys and signatures can be still deprecated.
Things in the kernel rarely disappear. At best, they become subtly neglected, and then somebody gets bit by some security bug. At worst, we're stuck maintaining a PGP implementation until the end of eternity.
On the technical front, though, I had sort of the same thought as
Maciej: is there some way that you can unwrap the PGP data in userspace, and re-encode it in ASN.1, and somehow magically account for the various metadata included in the signatures? The devil here might be in the details, and I'm not sure whether it's feasible. But if it is, this would seem to be a much nicer solution. I'm not the hugest fan of having an ASN.1 parser in the kernel either, but it's _already_ there, and if you could somehow piggyback on top of it, that means we'd be able to avoid importing this PGP implementation.
Concretely, it looks like the hardest part of this is the fact that pgp_digest_signature seems to hash in some PGP-specific metadata, not just the raw data. Am I reading that right, and that's the case? If so, that might spell trouble. You also mentioned in that other thread the possibility of using a new/custom PGP packet type for this? Is the idea there that you'd come up with something that could be unwrapped into an ASN.1-verifable blob, as a custom extension of PGP that distros could then distribute?
Jason
Quoted 5 lines · Jason A. Donenfeld
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519, similar to signify or minisign? Very minimal code in the kernel, in userspace, and very few moving parts to break.
I am concerned that ed25519 private key management is very rudimentary -- more often than not it is just kept somewhere on disk, often without any passphrase encryption.
With all its legacy warts, GnuPG at least has decent support for hardware off-load via OpenPGP smartcards or TPM integration in GnuPG 2.3, but the best we have with ed25519 is passhprase protection as implemented in minisign (and even that is rudimentary -- if you need to sign 10 things, you will need to type in your passphrase 10 times, as there is no passphrase agent of any kind).
The most promising non-PGP development of PKI signatures that I've seen lately is the openssh FIDO2 integration (the -sk keys) and support for signing/verifying arbitrary external content using ssh-keygen -n. It even does fairly sane things with identity/revocation/expiration via its allowed_signers implementation, even if I'm less excited about it all being in a single file.
Everything else is just treating key management as something out of scope, and I'm worried that it's going to result in a net loss in overall security.
-K
Quoted 3 lines · Konstantin Ryabitsev
The most promising non-PGP development of PKI signatures that I've seen lately is the openssh FIDO2 integration (the -sk keys) and support for signing/verifying arbitrary external content using
ssh-keygen -n. It even
Typo fix: that should be ssh-keygen -Y
-K
Quoted 7 lines · Konstantin Ryabitsev
Quoted 5 lines · Jason A. Donenfeld
If you're looking for a simple signature mechanism to replace the use of X.509 and all of that infrastructure, may I suggest just coming up with something simple using ed25519, similar to signify or minisign? Very minimal code in the kernel, in userspace, and very few moving parts to break.
Quoted 7 lines
I am concerned that ed25519 private key management is very rudimentary -- more often than not it is just kept somewhere on disk, often without any passphrase encryption.
With all its legacy warts, GnuPG at least has decent support for hardware off-load via OpenPGP smartcards or TPM integration in GnuPG 2.3, but the best we have with ed25519 is passhprase protection as implemented in minisign (and
I am not sure that I understood your point here correctly, but GnuPG already supports ed25519 keys, including stored on a smartcard - for example, on a YubiKey [1].
While the current software support for ed25519 might be limited, there is certainly progress being made, RFC 8410 allowed these algos for X.509 certificates.
Support for such certificates is already implemented in OpenSSL [2].
ECDSA, on the other hand, is very fragile with respect to random number generation at signing time.
We know that people got burned here in the past.
Thanks,
Maciej
[1]: https://developers.yubico.com/PGP/YubiKey_5.2.3_Enhancements_to_OpenPGP_3.4.html
[2]: https://blog.pinterjann.is/ed25519-certificates.html
Quoted 11 lines · Maciej S. Szmigiero
Quoted 7 lines
I am concerned that ed25519 private key management is very rudimentary -- more often than not it is just kept somewhere on disk, often without any passphrase encryption.
With all its legacy warts, GnuPG at least has decent support for hardware off-load via OpenPGP smartcards or TPM integration in GnuPG 2.3, but the best we have with ed25519 is passhprase protection as implemented in minisign (and
I am not sure that I understood your point here correctly, but GnuPG already supports ed25519 keys, including stored on a smartcard - for example, on a YubiKey [1].
Yes, I know, but you cannot use ed25519-capable OpenPGP smartcards to create non-PGP signatures. The discussion was about using ed25519 signatures directly (e.g. like signify/minisign do). Jason pointed out to me on IRC that it's possible to do it with YubiHSM, but it's an expensive device ($650 USD from Yubico).
Quoted 8 lines
While the current software support for ed25519 might be limited, there is certainly progress being made, RFC 8410 allowed these algos for X.509 certificates.
Support for such certificates is already implemented in OpenSSL [2].ECDSA, on the other hand, is very fragile with respect to random number generation at signing time.
We know that people got burned here in the past.
I think this is taking us far away from the main topic (which signing/verification standards to use in-kernel).
-K