diff options
Diffstat (limited to 'extra/yassl/src/ssl.cpp')
-rw-r--r-- | extra/yassl/src/ssl.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 9c1016ba53d..9516e8b985e 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -37,6 +37,8 @@ #include "file.hpp" // for TaoCrypt Source #include "coding.hpp" // HexDecoder #include "helpers.hpp" // for placement new hack +#include "rsa.hpp" // for TaoCrypt RSA key decode +#include "dsa.hpp" // for TaoCrypt DSA key decode #include <stdio.h> #ifdef _WIN32 @@ -54,6 +56,8 @@ namespace yaSSL { int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) { + int ret = SSL_SUCCESS; + if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM) return SSL_BAD_FILETYPE; @@ -141,8 +145,31 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) } } } + + if (type == PrivateKey && ctx->privateKey_) { + // see if key is valid early + TaoCrypt::Source rsaSource(ctx->privateKey_->get_buffer(), + ctx->privateKey_->get_length()); + TaoCrypt::RSA_PrivateKey rsaKey; + rsaKey.Initialize(rsaSource); + + if (rsaSource.GetError().What()) { + // rsa failed see if DSA works + + TaoCrypt::Source dsaSource(ctx->privateKey_->get_buffer(), + ctx->privateKey_->get_length()); + TaoCrypt::DSA_PrivateKey dsaKey; + dsaKey.Initialize(dsaSource); + + if (rsaSource.GetError().What()) { + // neither worked + ret = SSL_FAILURE; + } + } + } + fclose(input); - return SSL_SUCCESS; + return ret; } |