Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable CMS sign/verify for provider-implemented PKEYs #17733

Closed
wants to merge 7 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion crypto/cms/cms_sd.c
Expand Up @@ -227,6 +227,30 @@ int ossl_cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert)
return -1;
}

/* Method to map any, incl. provider-implemented PKEY types to OIDs */
static int cms_generic_sign(CMS_SignerInfo *si, int verify)
{
if (!verify) {
int hnid;
X509_ALGOR *alg1, *alg2;
EVP_PKEY *pkey = si->pkey;
const char *typename = EVP_PKEY_get0_type_name(pkey);

CMS_SignerInfo_get0_algs(si, NULL, NULL, &alg1, &alg2);
if (alg1 == NULL || alg1->algorithm == NULL)
return -1;
hnid = OBJ_obj2nid(alg1->algorithm);
if (hnid == NID_undef)
return -1;
mattcaswell marked this conversation as resolved.
Show resolved Hide resolved

/* Generic PKEY->name->NID->OID mapping check */
if (typename == NULL)
return -1;
return X509_ALGOR_set0(alg2, OBJ_nid2obj(OBJ_sn2nid(typename)), V_ASN1_UNDEF, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest replacing OBJ_nid2obj(OBJ_sn2nid(typename)) with OBJ_txt2obj(typename, 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e2f1215.

}
return 1;
}

static int cms_sd_asn1_ctrl(CMS_SignerInfo *si, int cmd)
{
EVP_PKEY *pkey = si->pkey;
Expand All @@ -239,7 +263,7 @@ static int cms_sd_asn1_ctrl(CMS_SignerInfo *si, int cmd)

/* Something else? We'll give engines etc a chance to handle this */
mattcaswell marked this conversation as resolved.
Show resolved Hide resolved
if (pkey->ameth == NULL || pkey->ameth->pkey_ctrl == NULL)
return 1;
return cms_generic_sign(si, cmd);
i = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_CMS_SIGN, cmd, si);
if (i == -2) {
ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
Expand Down