From 3c8d1e1cf9bb15a3ea986b0fa3f53d33663d6c55 Mon Sep 17 00:00:00 2001 From: tb <> Date: Fri, 28 Jul 2023 10:28:02 +0000 Subject: 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 --- src/lib/libcrypto/cms/cms.h | 5 ++++- src/lib/libcrypto/cms/cms_lib.c | 45 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'src/lib/libcrypto/cms') diff --git a/src/lib/libcrypto/cms/cms.h b/src/lib/libcrypto/cms/cms.h index 3c92be34f7..76672af097 100644 --- a/src/lib/libcrypto/cms/cms.h +++ b/src/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/src/lib/libcrypto/cms/cms_lib.c b/src/lib/libcrypto/cms/cms_lib.c index fa62e61e96..37a11ba007 100644 --- a/src/lib/libcrypto/cms/cms_lib.c +++ b/src/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. -- cgit v1.2.3-55-g6feb