summaryrefslogtreecommitdiff
path: root/crypto/ess/ess_asn1.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/ess/ess_asn1.c')
-rw-r--r--crypto/ess/ess_asn1.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/crypto/ess/ess_asn1.c b/crypto/ess/ess_asn1.c
index 19589d97f3..a8d13a3a20 100644
--- a/crypto/ess/ess_asn1.c
+++ b/crypto/ess/ess_asn1.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -9,9 +9,11 @@
#include <openssl/err.h>
#include <openssl/asn1t.h>
+#include <openssl/cms.h>
#include <openssl/ess.h>
#include <openssl/x509v3.h>
#include "crypto/ess.h"
+#include "crypto/cms.h"
/* ASN1 stuff for ESS Structure */
@@ -55,3 +57,61 @@ ASN1_SEQUENCE(ESS_SIGNING_CERT_V2) = {
IMPLEMENT_ASN1_FUNCTIONS(ESS_SIGNING_CERT_V2)
IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT_V2)
+
+/* No cms support means no CMS_SignerInfo* definitions */
+#ifndef OPENSSL_NO_CMS
+
+/*
+ * Returns < 0 if attribute is not found, 1 if found, or
+ * -1 on attribute parsing failure.
+ */
+int cms_signerinfo_get_signing_cert_v2(CMS_SignerInfo *si,
+ ESS_SIGNING_CERT_V2 **psc)
+{
+ ASN1_STRING *str;
+ ESS_SIGNING_CERT_V2 *sc;
+ ASN1_OBJECT *obj = OBJ_nid2obj(NID_id_smime_aa_signingCertificateV2);
+
+ if (psc != NULL)
+ *psc = NULL;
+ str = CMS_signed_get0_data_by_OBJ(si, obj, -3, V_ASN1_SEQUENCE);
+ if (str == NULL)
+ return 0;
+
+ sc = ASN1_item_unpack(str, ASN1_ITEM_rptr(ESS_SIGNING_CERT_V2));
+ if (sc == NULL)
+ return -1;
+ if (psc != NULL)
+ *psc = sc;
+ else
+ ESS_SIGNING_CERT_V2_free(sc);
+ return 1;
+}
+
+/*
+ * Returns < 0 if attribute is not found, 1 if found, or
+ * -1 on attribute parsing failure.
+ */
+int cms_signerinfo_get_signing_cert(CMS_SignerInfo *si,
+ ESS_SIGNING_CERT **psc)
+{
+ ASN1_STRING *str;
+ ESS_SIGNING_CERT *sc;
+ ASN1_OBJECT *obj = OBJ_nid2obj(NID_id_smime_aa_signingCertificate);
+
+ if (psc != NULL)
+ *psc = NULL;
+ str = CMS_signed_get0_data_by_OBJ(si, obj, -3, V_ASN1_SEQUENCE);
+ if (str == NULL)
+ return 0;
+
+ sc = ASN1_item_unpack(str, ASN1_ITEM_rptr(ESS_SIGNING_CERT));
+ if (sc == NULL)
+ return -1;
+ if (psc != NULL)
+ *psc = sc;
+ else
+ ESS_SIGNING_CERT_free(sc);
+ return 1;
+}
+#endif /* !OPENSSL_NO_CMS */