History

Revert "crypto: pkcs7 - remove sha1 support"

This reverts commit 16ab7cb5825fc3425c16ad2c6e53d827f382d7c6 because it broke iwd. iwd uses the KEYCTL_PKEY_* UAPIs via its dependency libell, and apparently it is relying on SHA-1 signature support. These UAPIs are fairly obscure, and their documentation does not mention which algorithms they support. iwd really should be using a properly supported userspace crypto library instead. Regardless, since something broke we have to revert the change. It may be possible that some parts of this commit can be reinstated without breaking iwd (e.g. probably the removal of MODULE_SIG_SHA1), but for now this just does a full revert to get things working again.

Eric Biggers committed 2 years ago

Commit 203a6761 parent 6a8dbd78 files · +107 −2Browse files

Unified · Split

8 files
  1. crypto/asymmetric_keys/mscode_parser.c +3 −0
  2. crypto/asymmetric_keys/pkcs7_parser.c +4 −0
  3. crypto/asymmetric_keys/public_key.c +2 −1
  4. crypto/asymmetric_keys/signature.c +1 −1
  5. crypto/asymmetric_keys/x509_cert_parser.c +8 −0
  6. crypto/testmgr.h +80 −0
  7. include/linux/oid_registry.h +4 −0
  8. kernel/module/Kconfig +5 −0
crypto/asymmetric_keys/mscode_parser.c+3−0
@@ -75,6 +75,9 @@ int mscode_note_digest_algo(void *context, size_t hdrlen, · 74 unmodified lines
7575
7676 oid = look_up_OID(value, vlen);
7777 switch (oid) {
78+ case OID_sha1:
79+ ctx->digest_algo = "sha1";
80+ break;
7881 case OID_sha256:
7982 ctx->digest_algo = "sha256";
8083 break;
crypto/asymmetric_keys/pkcs7_parser.c+4−0
@@ -227,6 +227,9 @@ int pkcs7_sig_note_digest_algo(void *context, size_t hdrlen, · 226 unmodified lines
227227 struct pkcs7_parse_context *ctx = context;
228228
229229 switch (ctx->last_oid) {
230+ case OID_sha1:
231+ ctx->sinfo->sig->hash_algo = "sha1";
232+ break;
230233 case OID_sha256:
231234 ctx->sinfo->sig->hash_algo = "sha256";
232235 break;
@@ -278,6 +281,7 @@ int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen, · 45 unmodified lines
278281 ctx->sinfo->sig->pkey_algo = "rsa";
279282 ctx->sinfo->sig->encoding = "pkcs1";
280283 break;
284+ case OID_id_ecdsa_with_sha1:
281285 case OID_id_ecdsa_with_sha224:
282286 case OID_id_ecdsa_with_sha256:
283287 case OID_id_ecdsa_with_sha384:
crypto/asymmetric_keys/public_key.c+2−1
@@ -115,7 +115,8 @@ software_key_determine_akcipher(const struct public_key *pkey, · 114 unmodified lines
115115 */
116116 if (!hash_algo)
117117 return -EINVAL;
118− if (strcmp(hash_algo, "sha224") != 0 &&
118+ if (strcmp(hash_algo, "sha1") != 0 &&
119+ strcmp(hash_algo, "sha224") != 0 &&
119120 strcmp(hash_algo, "sha256") != 0 &&
120121 strcmp(hash_algo, "sha384") != 0 &&
121122 strcmp(hash_algo, "sha512") != 0 &&
crypto/asymmetric_keys/signature.c+1−1
@@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(decrypt_blob); · 114 unmodified lines
115115 * Sign the specified data blob using the private key specified by params->key.
116116 * The signature is wrapped in an encoding if params->encoding is specified
117117 * (eg. "pkcs1"). If the encoding needs to know the digest type, this can be
118− * passed through params->hash_algo (eg. "sha512").
118+ * passed through params->hash_algo (eg. "sha1").
119119 *
120120 * Returns the length of the data placed in the signature buffer or an error.
121121 */
crypto/asymmetric_keys/x509_cert_parser.c+8−0
@@ -198,6 +198,10 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag, · 197 unmodified lines
198198 default:
199199 return -ENOPKG; /* Unsupported combination */
200200
201+ case OID_sha1WithRSAEncryption:
202+ ctx->cert->sig->hash_algo = "sha1";
203+ goto rsa_pkcs1;
204+
201205 case OID_sha256WithRSAEncryption:
202206 ctx->cert->sig->hash_algo = "sha256";
203207 goto rsa_pkcs1;
@@ -214,6 +218,10 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag, · 10 unmodified lines
214218 ctx->cert->sig->hash_algo = "sha224";
215219 goto rsa_pkcs1;
216220
221+ case OID_id_ecdsa_with_sha1:
222+ ctx->cert->sig->hash_algo = "sha1";
223+ goto ecdsa;
224+
217225 case OID_id_rsassa_pkcs1_v1_5_with_sha3_256:
218226 ctx->cert->sig->hash_algo = "sha3-256";
219227 goto rsa_pkcs1;
crypto/testmgr.h+80−0
@@ -653,6 +653,30 @@ static const struct akcipher_testvec rsa_tv_template[] = { · 652 unmodified lines
653653 static const struct akcipher_testvec ecdsa_nist_p192_tv_template[] = {
654654 {
655655 .key =
656+ "\x04\xf7\x46\xf8\x2f\x15\xf6\x22\x8e\xd7\x57\x4f\xcc\xe7\xbb\xc1"
657+ "\xd4\x09\x73\xcf\xea\xd0\x15\x07\x3d\xa5\x8a\x8a\x95\x43\xe4\x68"
658+ "\xea\xc6\x25\xc1\xc1\x01\x25\x4c\x7e\xc3\x3c\xa6\x04\x0a\xe7\x08"
659+ "\x98",
660+ .key_len = 49,
661+ .params =
662+ "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48"
663+ "\xce\x3d\x03\x01\x01",
664+ .param_len = 21,
665+ .m =
666+ "\xcd\xb9\xd2\x1c\xb7\x6f\xcd\x44\xb3\xfd\x63\xea\xa3\x66\x7f\xae"
667+ "\x63\x85\xe7\x82",
668+ .m_size = 20,
669+ .algo = OID_id_ecdsa_with_sha1,
670+ .c =
671+ "\x30\x35\x02\x19\x00\xba\xe5\x93\x83\x6e\xb6\x3b\x63\xa0\x27\x91"
672+ "\xc6\xf6\x7f\xc3\x09\xad\x59\xad\x88\x27\xd6\x92\x6b\x02\x18\x10"
673+ "\x68\x01\x9d\xba\xce\x83\x08\xef\x95\x52\x7b\xa0\x0f\xe4\x18\x86"
674+ "\x80\x6f\xa5\x79\x77\xda\xd0",
675+ .c_size = 55,
676+ .public_key_vec = true,
677+ .siggen_sigver_test = true,
678+ }, {
679+ .key =
656680 "\x04\xb6\x4b\xb1\xd1\xac\xba\x24\x8f\x65\xb2\x60\x00\x90\xbf\xbd"
657681 "\x78\x05\x73\xe9\x79\x1d\x6f\x7c\x0b\xd2\xc3\x93\xa7\x28\xe1\x75"
658682 "\xf7\xd5\x95\x1d\x28\x10\xc0\x75\x50\x5c\x1a\x4f\x3f\x8f\xa5\xee"
@@ -756,6 +780,32 @@ static const struct akcipher_testvec ecdsa_nist_p192_tv_template[] = { · 97 unmodified lines
756780 static const struct akcipher_testvec ecdsa_nist_p256_tv_template[] = {
757781 {
758782 .key =
783+ "\x04\xb9\x7b\xbb\xd7\x17\x64\xd2\x7e\xfc\x81\x5d\x87\x06\x83\x41"
784+ "\x22\xd6\x9a\xaa\x87\x17\xec\x4f\x63\x55\x2f\x94\xba\xdd\x83\xe9"
785+ "\x34\x4b\xf3\xe9\x91\x13\x50\xb6\xcb\xca\x62\x08\xe7\x3b\x09\xdc"
786+ "\xc3\x63\x4b\x2d\xb9\x73\x53\xe4\x45\xe6\x7c\xad\xe7\x6b\xb0\xe8"
787+ "\xaf",
788+ .key_len = 65,
789+ .params =
790+ "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48"
791+ "\xce\x3d\x03\x01\x07",
792+ .param_len = 21,
793+ .m =
794+ "\xc2\x2b\x5f\x91\x78\x34\x26\x09\x42\x8d\x6f\x51\xb2\xc5\xaf\x4c"
795+ "\x0b\xde\x6a\x42",
796+ .m_size = 20,
797+ .algo = OID_id_ecdsa_with_sha1,
798+ .c =
799+ "\x30\x46\x02\x21\x00\xf9\x25\xce\x9f\x3a\xa6\x35\x81\xcf\xd4\xe7"
800+ "\xb7\xf0\x82\x56\x41\xf7\xd4\xad\x8d\x94\x5a\x69\x89\xee\xca\x6a"
801+ "\x52\x0e\x48\x4d\xcc\x02\x21\x00\xd7\xe4\xef\x52\x66\xd3\x5b\x9d"
802+ "\x8a\xfa\x54\x93\x29\xa7\x70\x86\xf1\x03\x03\xf3\x3b\xe2\x73\xf7"
803+ "\xfb\x9d\x8b\xde\xd4\x8d\x6f\xad",
804+ .c_size = 72,
805+ .public_key_vec = true,
806+ .siggen_sigver_test = true,
807+ }, {
808+ .key =
759809 "\x04\x8b\x6d\xc0\x33\x8e\x2d\x8b\x67\xf5\xeb\xc4\x7f\xa0\xf5\xd9"
760810 "\x7b\x03\xa5\x78\x9a\xb5\xea\x14\xe4\x23\xd0\xaf\xd7\x0e\x2e\xa0"
761811 "\xc9\x8b\xdb\x95\xf8\xb3\xaf\xac\x00\x2c\x2c\x1f\x7a\xfd\x95\x88"
@@ -866,6 +916,36 @@ static const struct akcipher_testvec ecdsa_nist_p256_tv_template[] = { · 104 unmodified lines
866916
867917 static const struct akcipher_testvec ecdsa_nist_p384_tv_template[] = {
868918 {
919+ .key = /* secp384r1(sha1) */
920+ "\x04\x89\x25\xf3\x97\x88\xcb\xb0\x78\xc5\x72\x9a\x14\x6e\x7a\xb1"
921+ "\x5a\xa5\x24\xf1\x95\x06\x9e\x28\xfb\xc4\xb9\xbe\x5a\x0d\xd9\x9f"
922+ "\xf3\xd1\x4d\x2d\x07\x99\xbd\xda\xa7\x66\xec\xbb\xea\xba\x79\x42"
923+ "\xc9\x34\x89\x6a\xe7\x0b\xc3\xf2\xfe\x32\x30\xbe\xba\xf9\xdf\x7e"
924+ "\x4b\x6a\x07\x8e\x26\x66\x3f\x1d\xec\xa2\x57\x91\x51\xdd\x17\x0e"
925+ "\x0b\x25\xd6\x80\x5c\x3b\xe6\x1a\x98\x48\x91\x45\x7a\x73\xb0\xc3"
926+ "\xf1",
927+ .key_len = 97,
928+ .params =
929+ "\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04"
930+ "\x00\x22",
931+ .param_len = 18,
932+ .m =
933+ "\x12\x55\x28\xf0\x77\xd5\xb6\x21\x71\x32\x48\xcd\x28\xa8\x25\x22"
934+ "\x3a\x69\xc1\x93",
935+ .m_size = 20,
936+ .algo = OID_id_ecdsa_with_sha1,
937+ .c =
938+ "\x30\x66\x02\x31\x00\xf5\x0f\x24\x4c\x07\x93\x6f\x21\x57\x55\x07"
939+ "\x20\x43\x30\xde\xa0\x8d\x26\x8e\xae\x63\x3f\xbc\x20\x3a\xc6\xf1"
940+ "\x32\x3c\xce\x70\x2b\x78\xf1\x4c\x26\xe6\x5b\x86\xcf\xec\x7c\x7e"
941+ "\xd0\x87\xd7\xd7\x6e\x02\x31\x00\xcd\xbb\x7e\x81\x5d\x8f\x63\xc0"
942+ "\x5f\x63\xb1\xbe\x5e\x4c\x0e\xa1\xdf\x28\x8c\x1b\xfa\xf9\x95\x88"
943+ "\x74\xa0\x0f\xbf\xaf\xc3\x36\x76\x4a\xa1\x59\xf1\x1c\xa4\x58\x26"
944+ "\x79\x12\x2a\xb7\xc5\x15\x92\xc5",
945+ .c_size = 104,
946+ .public_key_vec = true,
947+ .siggen_sigver_test = true,
948+ }, {
869949 .key = /* secp384r1(sha224) */
870950 "\x04\x69\x6c\xcf\x62\xee\xd0\x0d\xe5\xb5\x2f\x70\x54\xcf\x26\xa0"
871951 "\xd9\x98\x8d\x92\x2a\xab\x9b\x11\xcb\x48\x18\xa1\xa9\x0d\xd5\x18"
include/linux/oid_registry.h+4−0
@@ -17,10 +17,12 @@ · 16 unmodified lines
1717 * build_OID_registry.pl to generate the data for look_up_OID().
1818 */
1919 enum OID {
20+ OID_id_dsa_with_sha1, /* 1.2.840.10030.4.3 */
2021 OID_id_dsa, /* 1.2.840.10040.4.1 */
2122 OID_id_ecPublicKey, /* 1.2.840.10045.2.1 */
2223 OID_id_prime192v1, /* 1.2.840.10045.3.1.1 */
2324 OID_id_prime256v1, /* 1.2.840.10045.3.1.7 */
25+ OID_id_ecdsa_with_sha1, /* 1.2.840.10045.4.1 */
2426 OID_id_ecdsa_with_sha224, /* 1.2.840.10045.4.3.1 */
2527 OID_id_ecdsa_with_sha256, /* 1.2.840.10045.4.3.2 */
2628 OID_id_ecdsa_with_sha384, /* 1.2.840.10045.4.3.3 */
@@ -28,6 +30,7 @@ enum OID { · 1 unmodified line
2830
2931 /* PKCS#1 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)} */
3032 OID_rsaEncryption, /* 1.2.840.113549.1.1.1 */
33+ OID_sha1WithRSAEncryption, /* 1.2.840.113549.1.1.5 */
3134 OID_sha256WithRSAEncryption, /* 1.2.840.113549.1.1.11 */
3235 OID_sha384WithRSAEncryption, /* 1.2.840.113549.1.1.12 */
3336 OID_sha512WithRSAEncryption, /* 1.2.840.113549.1.1.13 */
@@ -64,6 +67,7 @@ enum OID { · 30 unmodified lines
6467 OID_PKU2U, /* 1.3.5.1.5.2.7 */
6568 OID_Scram, /* 1.3.6.1.5.5.14 */
6669 OID_certAuthInfoAccess, /* 1.3.6.1.5.5.7.1.1 */
70+ OID_sha1, /* 1.3.14.3.2.26 */
6771 OID_id_ansip384r1, /* 1.3.132.0.34 */
6872 OID_sha256, /* 2.16.840.1.101.3.4.2.1 */
6973 OID_sha384, /* 2.16.840.1.101.3.4.2.2 */
kernel/module/Kconfig+5−0
@@ -236,6 +236,10 @@ choice · 235 unmodified lines
236236 possible to load a signed module containing the algorithm to check
237237 the signature on that module.
238238
239+config MODULE_SIG_SHA1
240+ bool "Sign modules with SHA-1"
241+ select CRYPTO_SHA1
242+
239243 config MODULE_SIG_SHA256
240244 bool "Sign modules with SHA-256"
241245 select CRYPTO_SHA256
@@ -265,6 +269,7 @@ endchoice · 23 unmodified lines
265269 config MODULE_SIG_HASH
266270 string
267271 depends on MODULE_SIG || IMA_APPRAISE_MODSIG
272+ default "sha1" if MODULE_SIG_SHA1
268273 default "sha256" if MODULE_SIG_SHA256
269274 default "sha384" if MODULE_SIG_SHA384
270275 default "sha512" if MODULE_SIG_SHA512