aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2024-02-09 17:57:40 -0500
committerGreg Hudson <ghudson@mit.edu>2024-03-18 21:05:39 -0400
commitbdcd6075bd4593c8f67722ce075c9519faec58b7 (patch)
treed066b8381af7693311e36a166a80d88d16aaede3
parentf95dfb7908456f9563cee66706216a21df8d791f (diff)
downloadkrb5-bdcd6075bd4593c8f67722ce075c9519faec58b7.zip
krb5-bdcd6075bd4593c8f67722ce075c9519faec58b7.tar.gz
krb5-bdcd6075bd4593c8f67722ce075c9519faec58b7.tar.bz2
Correct PKINIT EC cert signature metadata
When generating CMS SignedData in PKINIT, check the certificate's public key type and set the signatureAlgorithm field appropriately. (This field is currently ignored by OpenSSL when verifying CMS SignedData.) ticket: 9111 (new)
-rw-r--r--src/plugins/preauth/pkinit/pkinit_crypto_openssl.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
index ae78181..25796fd 100644
--- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
+++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
@@ -1662,7 +1662,22 @@ cleanup:
return retval;
}
+/* Return the name ID of the signature algorithm for cert, assuming that the
+ * digest used is SHA-256 and the cert uses either an RSA or EC public key. */
+static int
+cert_sig_alg(X509 *cert)
+{
+ /* Use X509_get0_pubkey() when OpenSSL 1.0 support is removed. */
+ EVP_PKEY *pkey = X509_get_pubkey(cert);
+ int id;
+ if (pkey != NULL && EVP_PKEY_get_base_id(pkey) == EVP_PKEY_EC)
+ id = NID_ecdsa_with_SHA256;
+ else
+ id = NID_sha256WithRSAEncryption;
+ EVP_PKEY_free(pkey);
+ return id;
+}
krb5_error_code
cms_signeddata_create(krb5_context context,
@@ -1695,6 +1710,7 @@ cms_signeddata_create(krb5_context context,
unsigned int alg_len = 0, digest_len = 0;
unsigned char *y = NULL;
ASN1_OBJECT *oid = NULL, *oid_copy;
+ int sig_alg_id;
/* Start creating PKCS7 data. */
if ((p7 = PKCS7_new()) == NULL)
@@ -1782,8 +1798,8 @@ cms_signeddata_create(krb5_context context,
/* Set sig algs */
if (p7si->digest_enc_alg->parameter != NULL)
ASN1_TYPE_free(p7si->digest_enc_alg->parameter);
- p7si->digest_enc_alg->algorithm =
- OBJ_nid2obj(NID_sha256WithRSAEncryption);
+ sig_alg_id = cert_sig_alg(id_cryptoctx->my_cert);
+ p7si->digest_enc_alg->algorithm = OBJ_nid2obj(sig_alg_id);
if (!(p7si->digest_enc_alg->parameter = ASN1_TYPE_new()))
goto cleanup;
p7si->digest_enc_alg->parameter->type = V_ASN1_NULL;