]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Add a stub for OpenSSL PKCS#7 parsing
authorMartin Willi <martin@revosec.ch>
Wed, 28 Nov 2012 13:59:49 +0000 (14:59 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 19 Dec 2012 09:32:08 +0000 (10:32 +0100)
src/libstrongswan/plugins/openssl/Makefile.am
src/libstrongswan/plugins/openssl/openssl_pkcs7.c [new file with mode: 0644]
src/libstrongswan/plugins/openssl/openssl_pkcs7.h [new file with mode: 0644]
src/libstrongswan/plugins/openssl/openssl_plugin.c

index c59888663fbdc8db2542eeac0c8a1f882985b5f3..f971a5e0872cbe3eead16c1c172e996606c894e2 100644 (file)
@@ -23,6 +23,7 @@ libstrongswan_openssl_la_SOURCES = \
        openssl_ec_public_key.c openssl_ec_public_key.h \
        openssl_x509.c openssl_x509.h \
        openssl_crl.c openssl_crl.h \
+       openssl_pkcs7.c openssl_pkcs7.h \
        openssl_rng.c openssl_rng.h \
        openssl_hmac.c openssl_hmac.h
 
diff --git a/src/libstrongswan/plugins/openssl/openssl_pkcs7.c b/src/libstrongswan/plugins/openssl/openssl_pkcs7.c
new file mode 100644 (file)
index 0000000..b53e1c4
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "openssl_pkcs7.h"
+
+#include <library.h>
+
+typedef struct private_openssl_pkcs7_t private_openssl_pkcs7_t;
+
+/**
+ * Private data of an openssl_pkcs7_t object.
+ */
+struct private_openssl_pkcs7_t {
+
+       /**
+        * Public pkcs7_t interface.
+        */
+       pkcs7_t public;
+};
+
+METHOD(container_t, get_type, container_type_t,
+       private_openssl_pkcs7_t *this)
+{
+       return CONTAINER_PKCS7_DATA;
+}
+
+METHOD(container_t, create_signature_enumerator, enumerator_t*,
+       private_openssl_pkcs7_t *this)
+{
+       return enumerator_create_empty();
+}
+
+METHOD(pkcs7_t, get_attribute, bool,
+       private_openssl_pkcs7_t *this, int oid,
+       enumerator_t *enumerator, chunk_t *value)
+{
+       return FALSE;
+}
+
+METHOD(pkcs7_t, create_cert_enumerator, enumerator_t*,
+       private_openssl_pkcs7_t *this)
+{
+       return enumerator_create_empty();
+}
+
+METHOD(container_t, get_data, bool,
+       private_openssl_pkcs7_t *this, chunk_t *data)
+{
+       return FALSE;
+}
+
+METHOD(container_t, get_encoding, bool,
+       private_openssl_pkcs7_t *this, chunk_t *data)
+{
+       return FALSE;
+}
+
+METHOD(container_t, destroy, void,
+       private_openssl_pkcs7_t *this)
+{
+       free(this);
+}
+
+/**
+ * Generic constructor
+ */
+static private_openssl_pkcs7_t* create_empty()
+{
+       private_openssl_pkcs7_t *this;
+
+       INIT(this,
+               .public = {
+                       .container = {
+                               .get_type = _get_type,
+                               .create_signature_enumerator = _create_signature_enumerator,
+                               .get_data = _get_data,
+                               .get_encoding = _get_encoding,
+                               .destroy = _destroy,
+                       },
+                       .get_attribute = _get_attribute,
+                       .create_cert_enumerator = _create_cert_enumerator,
+               },
+       );
+
+       return this;
+}
+
+/**
+ * See header
+ */
+pkcs7_t *openssl_pkcs7_load(container_type_t type, va_list args)
+{
+       chunk_t blob = chunk_empty;
+       private_openssl_pkcs7_t *this;
+
+       while (TRUE)
+       {
+               switch (va_arg(args, builder_part_t))
+               {
+                       case BUILD_BLOB_ASN1_DER:
+                               blob = va_arg(args, chunk_t);
+                               continue;
+                       case BUILD_END:
+                               break;
+                       default:
+                               return NULL;
+               }
+               break;
+       }
+       if (blob.len)
+       {
+               this = create_empty();
+               /* TODO: parse blob */
+               destroy(this);
+       }
+       return NULL;
+}
diff --git a/src/libstrongswan/plugins/openssl/openssl_pkcs7.h b/src/libstrongswan/plugins/openssl/openssl_pkcs7.h
new file mode 100644 (file)
index 0000000..2c7939e
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup openssl_pkcs7 openssl_pkcs7
+ * @{ @ingroup openssl_p
+ */
+
+#ifndef OPENSSL_PKCS7_H_
+#define OPENSSL_PKCS7_H_
+
+#include <credentials/containers/pkcs7.h>
+
+/**
+ * Load a generic PKCS#7 container.
+ *
+ * The argument list must contain a single BUILD_BLOB_ASN1_DER argument.
+ *
+ * @param type         type of the container, CONTAINER_PKCS7
+ * @param args         builder_part_t argument list
+ * @return                     container, NULL on failure
+ */
+pkcs7_t *openssl_pkcs7_load(container_type_t type, va_list args);
+
+#endif /** OPENSSL_PKCS7_H_ @}*/
index 1f7497a70fe2d1ecbf522a952de380fafafe182c..dd6a379d26b72a49d2ec22612d1f126f1ff2d025 100644 (file)
@@ -40,6 +40,7 @@
 #include "openssl_ec_public_key.h"
 #include "openssl_x509.h"
 #include "openssl_crl.h"
+#include "openssl_pkcs7.h"
 #include "openssl_rng.h"
 #include "openssl_hmac.h"
 
@@ -365,6 +366,10 @@ METHOD(plugin_t, get_features, int,
                                PLUGIN_SDEPEND(PUBKEY, KEY_DSA),
                PLUGIN_REGISTER(CERT_DECODE, openssl_crl_load, TRUE),
                        PLUGIN_PROVIDE(CERT_DECODE, CERT_X509_CRL),
+#ifndef OPENSSL_NO_CMS
+               PLUGIN_REGISTER(CONTAINER_DECODE, openssl_pkcs7_load, TRUE),
+                       PLUGIN_PROVIDE(CONTAINER_DECODE, CONTAINER_PKCS7),
+#endif /* OPENSSL_NO_CMS */
 #ifndef OPENSSL_NO_ECDH
                /* EC DH groups */
                PLUGIN_REGISTER(DH, openssl_ec_diffie_hellman_create),