From: tb Date: Fri, 28 Jul 2023 10:28:02 +0000 (+0000) Subject: Provide CMS{,_SignerInfo}_get_version X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5e651e03ef4bb2a427e4d3d660ea1ede924b91f5;p=openbsd Provide CMS{,_SignerInfo}_get_version Add accessors for the syntax versions of ContentInfo and SignerInfo. These will be used soon in rpki-client for some more compliance checks. ok job jsing --- diff --git a/lib/libcrypto/Symbols.list b/lib/libcrypto/Symbols.list index b9ce49b2779..f9f1b10c22d 100644 --- a/lib/libcrypto/Symbols.list +++ b/lib/libcrypto/Symbols.list @@ -557,6 +557,7 @@ CMS_SignerInfo_get0_md_ctx CMS_SignerInfo_get0_pkey_ctx CMS_SignerInfo_get0_signature CMS_SignerInfo_get0_signer_id +CMS_SignerInfo_get_version CMS_SignerInfo_set1_signer_cert CMS_SignerInfo_sign CMS_SignerInfo_verify @@ -597,6 +598,7 @@ CMS_get0_type CMS_get1_ReceiptRequest CMS_get1_certs CMS_get1_crls +CMS_get_version CMS_is_detached CMS_set1_eContentType CMS_set1_signers_certs diff --git a/lib/libcrypto/cms/cms.h b/lib/libcrypto/cms/cms.h index 3c92be34f77..76672af0979 100644 --- a/lib/libcrypto/cms/cms.h +++ b/lib/libcrypto/cms/cms.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cms.h,v 1.15 2019/08/11 10:15:30 jsing Exp $ */ +/* $OpenBSD: cms.h,v 1.16 2023/07/28 10:28:02 tb Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -128,6 +128,9 @@ int CMS_ContentInfo_print_ctx(BIO *out, CMS_ContentInfo *x, int indent, const AS const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms); +int CMS_get_version(const CMS_ContentInfo *cms, long *version); +int CMS_SignerInfo_get_version(const CMS_SignerInfo *si, long *version); + BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont); int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio); diff --git a/lib/libcrypto/cms/cms_lib.c b/lib/libcrypto/cms/cms_lib.c index fa62e61e964..37a11ba0079 100644 --- a/lib/libcrypto/cms/cms_lib.c +++ b/lib/libcrypto/cms/cms_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_lib.c,v 1.18 2023/07/08 08:26:26 beck Exp $ */ +/* $OpenBSD: cms_lib.c,v 1.19 2023/07/28 10:28:02 tb Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -237,6 +237,49 @@ CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio) } LCRYPTO_ALIAS(CMS_dataFinal); +int +CMS_get_version(const CMS_ContentInfo *cms, long *version) +{ + switch (OBJ_obj2nid(cms->contentType)) { + case NID_pkcs7_signed: + *version = cms->d.signedData->version; + return 1; + + case NID_pkcs7_enveloped: + *version = cms->d.envelopedData->version; + return 1; + + case NID_pkcs7_digest: + *version = cms->d.digestedData->version; + return 1; + + case NID_pkcs7_encrypted: + *version = cms->d.encryptedData->version; + return 1; + + case NID_id_smime_ct_authData: + *version = cms->d.authenticatedData->version; + return 1; + + case NID_id_smime_ct_compressedData: + *version = cms->d.compressedData->version; + return 1; + + default: + CMSerror(CMS_R_UNSUPPORTED_TYPE); + return 0; + } +} +LCRYPTO_ALIAS(CMS_get_version); + +int +CMS_SignerInfo_get_version(const CMS_SignerInfo *si, long *version) +{ + *version = si->version; + return 1; +} +LCRYPTO_ALIAS(CMS_SignerInfo_get_version); + /* * Return an OCTET STRING pointer to content. This allows it to be accessed * or set later. diff --git a/lib/libcrypto/hidden/openssl/cms.h b/lib/libcrypto/hidden/openssl/cms.h index c777e857d8f..0f450e603ca 100644 --- a/lib/libcrypto/hidden/openssl/cms.h +++ b/lib/libcrypto/hidden/openssl/cms.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cms.h,v 1.1 2023/07/08 08:26:26 beck Exp $ */ +/* $OpenBSD: cms.h,v 1.2 2023/07/28 10:28:02 tb Exp $ */ /* * Copyright (c) 2023 Bob Beck * @@ -35,6 +35,8 @@ LCRYPTO_USED(d2i_CMS_ReceiptRequest); LCRYPTO_USED(i2d_CMS_ReceiptRequest); LCRYPTO_USED(CMS_ContentInfo_print_ctx); LCRYPTO_USED(CMS_get0_type); +LCRYPTO_USED(CMS_get_version); +LCRYPTO_USED(CMS_SignerInfo_get_version); LCRYPTO_USED(CMS_dataInit); LCRYPTO_USED(CMS_dataFinal); LCRYPTO_USED(CMS_is_detached);