Provide CMS{,_SignerInfo}_get_version
authortb <tb@openbsd.org>
Fri, 28 Jul 2023 10:28:02 +0000 (10:28 +0000)
committertb <tb@openbsd.org>
Fri, 28 Jul 2023 10:28:02 +0000 (10:28 +0000)
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

lib/libcrypto/Symbols.list
lib/libcrypto/cms/cms.h
lib/libcrypto/cms/cms_lib.c
lib/libcrypto/hidden/openssl/cms.h

index b9ce49b..f9f1b10 100644 (file)
@@ -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
index 3c92be3..76672af 100644 (file)
@@ -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);
 
index fa62e61..37a11ba 100644 (file)
@@ -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.
index c777e85..0f450e6 100644 (file)
@@ -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 <beck@openbsd.org>
  *
@@ -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);