]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Implement PKCS#7 "data" content type parsing
authorMartin Willi <martin@revosec.ch>
Mon, 26 Nov 2012 14:03:49 +0000 (15:03 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 19 Dec 2012 09:32:07 +0000 (10:32 +0100)
src/libstrongswan/plugins/pkcs7/Makefile.am
src/libstrongswan/plugins/pkcs7/pkcs7_data.c [new file with mode: 0644]
src/libstrongswan/plugins/pkcs7/pkcs7_data.h [new file with mode: 0644]
src/libstrongswan/plugins/pkcs7/pkcs7_generic.c

index f133851df70ee495dc65b736d2b5a506d499daad..bef07aafdfa9e7a4e727df13f469459e3fc01669 100644 (file)
@@ -11,6 +11,7 @@ endif
 
 libstrongswan_pkcs7_la_SOURCES = \
        pkcs7_generic.h pkcs7_generic.c \
+       pkcs7_data.h pkcs7_data.c \
        pkcs7_plugin.h pkcs7_plugin.c
 
 libstrongswan_pkcs7_la_LDFLAGS = -module -avoid-version
diff --git a/src/libstrongswan/plugins/pkcs7/pkcs7_data.c b/src/libstrongswan/plugins/pkcs7/pkcs7_data.c
new file mode 100644 (file)
index 0000000..8c4c7ec
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * 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 "pkcs7_data.h"
+
+#include <asn1/asn1.h>
+
+typedef struct private_pkcs7_data_t private_pkcs7_data_t;
+
+/**
+ * Private data of a PKCS#7 signed-data container.
+ */
+struct private_pkcs7_data_t {
+
+       /**
+        * Implements pkcs7_t.
+        */
+       pkcs7_t public;
+
+       /**
+        * Encoded data
+        */
+       chunk_t content;
+
+       /**
+        * Encoded PKCS#7 signed-data
+        */
+       chunk_t encoding;
+};
+
+METHOD(container_t, get_type, container_type_t,
+       private_pkcs7_data_t *this)
+{
+       return CONTAINER_PKCS7_DATA;
+}
+
+METHOD(container_t, create_signature_enumerator, enumerator_t*,
+       private_pkcs7_data_t *this)
+{
+       return enumerator_create_empty();
+}
+
+METHOD(container_t, get_data, bool,
+       private_pkcs7_data_t *this, chunk_t *data)
+{
+       chunk_t chunk;
+
+       chunk = this->content;
+       if (asn1_unwrap(&chunk, &chunk) == ASN1_OCTET_STRING)
+       {
+               *data = chunk_clone(chunk);
+               return TRUE;
+       }
+       return FALSE;
+}
+
+METHOD(container_t, get_encoding, bool,
+       private_pkcs7_data_t *this, chunk_t *data)
+{
+       *data = chunk_clone(this->encoding);
+       return TRUE;
+}
+
+METHOD(container_t, destroy, void,
+       private_pkcs7_data_t *this)
+{
+       free(this->content.ptr);
+       free(this->encoding.ptr);
+       free(this);
+}
+
+/**
+ * See header.
+ */
+pkcs7_t *pkcs7_data_load(chunk_t encoding, chunk_t content)
+{
+       private_pkcs7_data_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,
+                       },
+               },
+               .encoding = chunk_clone(encoding),
+               .content = chunk_clone(content),
+       );
+
+       return &this->public;
+}
diff --git a/src/libstrongswan/plugins/pkcs7/pkcs7_data.h b/src/libstrongswan/plugins/pkcs7/pkcs7_data.h
new file mode 100644 (file)
index 0000000..b0a0578
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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 pkcs7_data pkcs7_data
+ * @{ @ingroup pkcs7
+ */
+
+#ifndef PKCS7_DATA_H_
+#define PKCS7_DATA_H_
+
+#include <credentials/builder.h>
+#include <credentials/containers/pkcs7.h>
+
+/**
+ * Parse a PKCS#7 "data" container.
+ *
+ * @param encoding     full contentInfo encoding
+ * @param content      DER encoded content from contentInfo
+ * @return                     CONTAINER_PKCS7_DATA container, NULL on failure
+ */
+pkcs7_t *pkcs7_data_load(chunk_t encoding, chunk_t content);
+
+#endif /** PKCS7_DATA_H_ @}*/
index 9e6bc33065ad4041bd8da7b99d4905f2c9d27f5f..e20846dcd4f8845ba6a78bca548f8a1c1e13c10a 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "pkcs7_generic.h"
+#include "pkcs7_data.h"
 
 #include <utils/debug.h>
 #include <asn1/oid.h>
@@ -76,6 +77,8 @@ end:
        {
                switch (type)
                {
+                       case OID_PKCS7_DATA:
+                               return pkcs7_data_load(blob, content);
                        default:
                                DBG1(DBG_ASN, "pkcs7 content type %d not supported", type);
                                return NULL;