summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/pubkey
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
commit8b80ab5a6950ce6515f477624794defd7531642a (patch)
treeaa8303f3806c5615fbeafc4dc82febe3cd7c24dc /src/libstrongswan/plugins/pubkey
parentdb67c87db3c9089ea8d2e14f617bf3d9e2af261f (diff)
downloadvyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.tar.gz
vyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.8)
Diffstat (limited to 'src/libstrongswan/plugins/pubkey')
-rw-r--r--src/libstrongswan/plugins/pubkey/Makefile.in2
-rw-r--r--src/libstrongswan/plugins/pubkey/pubkey_cert.c56
-rw-r--r--src/libstrongswan/plugins/pubkey/pubkey_public_key.c75
3 files changed, 78 insertions, 55 deletions
diff --git a/src/libstrongswan/plugins/pubkey/Makefile.in b/src/libstrongswan/plugins/pubkey/Makefile.in
index ced339d15..ef1004672 100644
--- a/src/libstrongswan/plugins/pubkey/Makefile.in
+++ b/src/libstrongswan/plugins/pubkey/Makefile.in
@@ -189,6 +189,8 @@ localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
piddir = @piddir@
diff --git a/src/libstrongswan/plugins/pubkey/pubkey_cert.c b/src/libstrongswan/plugins/pubkey/pubkey_cert.c
index 63dffb47b..762557094 100644
--- a/src/libstrongswan/plugins/pubkey/pubkey_cert.c
+++ b/src/libstrongswan/plugins/pubkey/pubkey_cert.c
@@ -19,6 +19,11 @@
#include <debug.h>
+/**
+ * defined in pubkey_public_key.c
+ */
+extern public_key_t *pubkey_public_key_load(chunk_t blob);
+
typedef struct private_pubkey_cert_t private_pubkey_cert_t;
/**
@@ -60,7 +65,7 @@ static certificate_type_t get_type(private_pubkey_cert_t *this)
*/
static identification_t* get_subject(private_pubkey_cert_t *this)
{
- return this->key->get_id(this->key, ID_PUBKEY_SHA1);
+ return this->key->get_id(this->key, ID_PUBKEY_INFO_SHA1);
}
/**
@@ -109,7 +114,7 @@ static bool equals(private_pubkey_cert_t *this, certificate_t *other)
{
return FALSE;
}
- return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_SHA1));
+ return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_INFO_SHA1));
}
/**
@@ -211,6 +216,13 @@ static pubkey_cert_t *pubkey_cert_create(public_key_t *key)
return &this->public;
}
+static pubkey_cert_t *pubkey_cert_create_from_chunk(chunk_t blob)
+{
+ public_key_t *key = pubkey_public_key_load(chunk_clone(blob));
+
+ return (key)? pubkey_cert_create(key) : NULL;
+}
+
typedef struct private_builder_t private_builder_t;
/**
* Builder implementation for key loading
@@ -238,27 +250,35 @@ static pubkey_cert_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
+ if (!this->key)
{
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
+ va_list args;
- switch (part)
- {
- case BUILD_PUBLIC_KEY:
+ switch (part)
{
- va_start(args, part);
- this->key = pubkey_cert_create(va_arg(args, public_key_t*));
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ {
+ va_start(args, part);
+ this->key = pubkey_cert_create_from_chunk(va_arg(args, chunk_t));
+ va_end(args);
+ return;
+ }
+ case BUILD_PUBLIC_KEY:
+ {
+ va_start(args, part);
+ this->key = pubkey_cert_create(va_arg(args, public_key_t*));
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
+ if (this->key)
+ {
+ destroy((private_pubkey_cert_t*)this->key);
+ }
+ builder_cancel(&this->public);
}
/**
diff --git a/src/libstrongswan/plugins/pubkey/pubkey_public_key.c b/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
index 0527ed758..4b5f4aac2 100644
--- a/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
+++ b/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
@@ -14,7 +14,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: pubkey_public_key.c 4059 2008-06-11 14:10:02Z martin $
+ * $Id: pubkey_public_key.c 4379 2008-10-08 01:19:26Z andreas $
*/
#include "pubkey_public_key.h"
@@ -39,9 +39,10 @@ static const asn1Object_t pkinfoObjects[] = {
/**
- * Load a public key from an ASN1 encoded blob
+ * Load a public key from an ASN.1 encoded blob
+ * Also used by pubkey_cert.c
*/
-static public_key_t *load(chunk_t blob)
+public_key_t *pubkey_public_key_load(chunk_t blob)
{
asn1_parser_t *parser;
chunk_t object;
@@ -67,9 +68,8 @@ static public_key_t *load(chunk_t blob)
else if (oid == OID_EC_PUBLICKEY)
{
/* we need the whole subjectPublicKeyInfo for EC public keys */
- key = lib->creds->create(lib->creds,
- CRED_PUBLIC_KEY, KEY_ECDSA, BUILD_BLOB_ASN1_DER,
- chunk_clone(blob), BUILD_END);
+ key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY,
+ KEY_ECDSA, BUILD_BLOB_ASN1_DER, blob, BUILD_END);
goto end;
}
else
@@ -86,8 +86,7 @@ static public_key_t *load(chunk_t blob)
object = chunk_skip(object, 1);
}
key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, type,
- BUILD_BLOB_ASN1_DER, chunk_clone(object),
- BUILD_END);
+ BUILD_BLOB_ASN1_DER, object, BUILD_END);
break;
}
}
@@ -125,41 +124,43 @@ static public_key_t *build(private_builder_t *this)
*/
static void add(private_builder_t *this, builder_part_t part, ...)
{
- va_list args;
-
- if (this->key)
- {
- DBG1("ignoring surplus build part %N", builder_part_names, part);
- return;
- }
- va_start(args, part);
- switch (part)
+ if (!this->key)
{
- case BUILD_BLOB_ASN1_DER:
+ va_list args;
+ chunk_t blob;
+
+ switch (part)
{
- this->key = load(va_arg(args, chunk_t));
- break;
- }
- case BUILD_BLOB_ASN1_PEM:
- {
- bool pgp;
- char *pem;
- chunk_t blob;
-
- pem = va_arg(args, char *);
- blob = chunk_clone(chunk_create(pem, strlen(pem)));
- if (pem_to_bin(&blob, &chunk_empty, &pgp))
+ case BUILD_BLOB_ASN1_DER:
{
- this->key = load(chunk_clone(blob));
+ va_start(args, part);
+ blob = va_arg(args, chunk_t);
+ this->key = pubkey_public_key_load(chunk_clone(blob));
+ va_end(args);
+ return;
}
- free(blob.ptr);
- break;
+ case BUILD_BLOB_ASN1_PEM:
+ {
+ bool pgp;
+ char *pem;
+
+ va_start(args, part);
+ pem = va_arg(args, char *);
+ blob = chunk_clone(chunk_create(pem, strlen(pem)));
+ if (pem_to_bin(&blob, &chunk_empty, &pgp))
+ {
+ this->key = pubkey_public_key_load(chunk_clone(blob));
+ }
+ free(blob.ptr);
+ va_end(args);
+ return;
+ }
+ default:
+ break;
}
- default:
- DBG1("ignoring unsupported build part %N", builder_part_names, part);
- break;
}
- va_end(args);
+ DESTROY_IF(this->key);
+ builder_cancel(&this->public);
}
/**