aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/pubkey
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2008-09-02 11:00:13 +0000
committerMartin Willi <martin@strongswan.org>2008-09-02 11:00:13 +0000
commitf7c17aa15c13b10f7b624ae8da5ea3d921b77535 (patch)
treee8db73c667aa1c9f0d827ed590aeb6393d6037e3 /src/libstrongswan/plugins/pubkey
parent4da0116d78b726ef4125577bed8e9974883fc7fd (diff)
downloadstrongswan-f7c17aa15c13b10f7b624ae8da5ea3d921b77535.tar.bz2
strongswan-f7c17aa15c13b10f7b624ae8da5ea3d921b77535.tar.xz
refactored credential builder
allow enumeration of matching builders try a second builder if the first one fails builder clones resources internally on demand caller frees added resources on failure and success stricter handling of non-supported build parts
Diffstat (limited to 'src/libstrongswan/plugins/pubkey')
-rw-r--r--src/libstrongswan/plugins/pubkey/pubkey_cert.c33
-rw-r--r--src/libstrongswan/plugins/pubkey/pubkey_public_key.c66
2 files changed, 50 insertions, 49 deletions
diff --git a/src/libstrongswan/plugins/pubkey/pubkey_cert.c b/src/libstrongswan/plugins/pubkey/pubkey_cert.c
index 63dffb47b..6305f46a7 100644
--- a/src/libstrongswan/plugins/pubkey/pubkey_cert.c
+++ b/src/libstrongswan/plugins/pubkey/pubkey_cert.c
@@ -238,27 +238,28 @@ 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_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 5a072c482..0bb3d7120 100644
--- a/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
+++ b/src/libstrongswan/plugins/pubkey/pubkey_public_key.c
@@ -67,9 +67,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 +85,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 +123,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:
{
+ va_start(args, part);
+ blob = va_arg(args, chunk_t);
this->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 = 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);
}
/**