aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-09-14 14:29:10 +0200
committerMartin Willi <martin@strongswan.org>2009-09-14 14:29:10 +0200
commitb9fbd66587d720975104074bda197bc2efcf3c77 (patch)
treeca0b0b7a0abaa71f9db173e308e7ad21d2b189e5 /src/libstrongswan/plugins
parent341af94dc655279dd9bf9de276ccf1141d02f9f3 (diff)
downloadstrongswan-b9fbd66587d720975104074bda197bc2efcf3c77.tar.bz2
strongswan-b9fbd66587d720975104074bda197bc2efcf3c77.tar.xz
Added support to build RSA keys from components in openssl
Diffstat (limited to 'src/libstrongswan/plugins')
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c58
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c29
2 files changed, 72 insertions, 15 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c
index ce65cddb4..d944002e5 100644
--- a/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c
@@ -327,8 +327,9 @@ openssl_rsa_private_key_t *openssl_rsa_private_key_load(key_type_t type,
va_list args)
{
private_openssl_rsa_private_key_t *this;
- chunk_t blob = chunk_empty;
+ chunk_t blob, n, e, d, p, q, exp1, exp2, coeff;
+ blob = n = e = d = p = q = exp1 = exp2 = coeff = chunk_empty;
while (TRUE)
{
switch (va_arg(args, builder_part_t))
@@ -336,6 +337,30 @@ openssl_rsa_private_key_t *openssl_rsa_private_key_load(key_type_t type,
case BUILD_BLOB_ASN1_DER:
blob = va_arg(args, chunk_t);
continue;
+ case BUILD_RSA_MODULUS:
+ n = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_PUB_EXP:
+ e = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_PRIV_EXP:
+ d = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_PRIME1:
+ p = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_PRIME2:
+ q = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_EXP1:
+ exp1 = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_EXP2:
+ exp2 = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_COEFF:
+ coeff = va_arg(args, chunk_t);
+ continue;
case BUILD_END:
break;
default:
@@ -345,18 +370,33 @@ openssl_rsa_private_key_t *openssl_rsa_private_key_load(key_type_t type,
}
this = create_empty();
- this->rsa = d2i_RSAPrivateKey(NULL, (const u_char**)&blob.ptr, blob.len);
- if (!this->rsa)
+ if (blob.ptr)
{
- destroy(this);
- return NULL;
+ this->rsa = d2i_RSAPrivateKey(NULL, (const u_char**)&blob.ptr, blob.len);
+ if (this->rsa && RSA_check_key(this->rsa))
+ {
+ return &this->public;
+ }
}
- if (!RSA_check_key(this->rsa))
+ else if (n.ptr && e.ptr && d.ptr && p.ptr && q.ptr &&
+ exp1.ptr && exp2.ptr && coeff.ptr)
{
- destroy(this);
- return NULL;
+ this->rsa = RSA_new();
+ this->rsa->n = BN_bin2bn((const u_char*)n.ptr, n.len, NULL);
+ this->rsa->e = BN_bin2bn((const u_char*)e.ptr, e.len, NULL);
+ this->rsa->d = BN_bin2bn((const u_char*)d.ptr, d.len, NULL);
+ this->rsa->p = BN_bin2bn((const u_char*)p.ptr, p.len, NULL);
+ this->rsa->q = BN_bin2bn((const u_char*)q.ptr, q.len, NULL);
+ this->rsa->dmp1 = BN_bin2bn((const u_char*)exp1.ptr, exp1.len, NULL);
+ this->rsa->dmq1 = BN_bin2bn((const u_char*)exp2.ptr, exp2.len, NULL);
+ this->rsa->iqmp = BN_bin2bn((const u_char*)coeff.ptr, coeff.len, NULL);
+ if (RSA_check_key(this->rsa))
+ {
+ return &this->public;
+ }
}
- return &this->public;
+ destroy(this);
+ return NULL;
}
/**
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
index 67c2e47d4..689dc27f6 100644
--- a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
@@ -304,8 +304,9 @@ openssl_rsa_public_key_t *openssl_rsa_public_key_load(key_type_t type,
va_list args)
{
private_openssl_rsa_public_key_t *this;
- chunk_t blob;
+ chunk_t blob, n, e;
+ n = e = blob = chunk_empty;
while (TRUE)
{
switch (va_arg(args, builder_part_t))
@@ -313,6 +314,12 @@ openssl_rsa_public_key_t *openssl_rsa_public_key_load(key_type_t type,
case BUILD_BLOB_ASN1_DER:
blob = va_arg(args, chunk_t);
continue;
+ case BUILD_RSA_MODULUS:
+ n = va_arg(args, chunk_t);
+ continue;
+ case BUILD_RSA_PUB_EXP:
+ e = va_arg(args, chunk_t);
+ continue;
case BUILD_END:
break;
default:
@@ -322,12 +329,22 @@ openssl_rsa_public_key_t *openssl_rsa_public_key_load(key_type_t type,
}
this = create_empty();
- this->rsa = d2i_RSAPublicKey(NULL, (const u_char**)&blob.ptr, blob.len);
- if (!this->rsa)
+ if (blob.ptr)
+ {
+ this->rsa = d2i_RSAPublicKey(NULL, (const u_char**)&blob.ptr, blob.len);
+ if (this->rsa)
+ {
+ return &this->public;
+ }
+ }
+ else if (n.ptr && e.ptr)
{
- destroy(this);
- return NULL;
+ this->rsa = RSA_new();
+ this->rsa->n = BN_bin2bn((const u_char*)n.ptr, n.len, NULL);
+ this->rsa->e = BN_bin2bn((const u_char*)e.ptr, e.len, NULL);
+ return &this->public;
}
- return &this->public;
+ destroy(this);
+ return NULL;
}