Index: webrtc/base/sslidentity.cc |
diff --git a/webrtc/base/sslidentity.cc b/webrtc/base/sslidentity.cc |
index ce209dd4167c2211fdc80649be4dca7a48b3b487..180e60c58bbdeea6f67bab7331d93d6cba88dda6 100644 |
--- a/webrtc/base/sslidentity.cc |
+++ b/webrtc/base/sslidentity.cc |
@@ -18,6 +18,7 @@ |
#include <string> |
#include "webrtc/base/base64.h" |
+#include "webrtc/base/checks.h" |
#include "webrtc/base/logging.h" |
#include "webrtc/base/sslconfig.h" |
@@ -33,6 +34,55 @@ const char kPemTypeCertificate[] = "CERTIFICATE"; |
const char kPemTypeRsaPrivateKey[] = "RSA PRIVATE KEY"; |
const char kPemTypeEcPrivateKey[] = "EC PRIVATE KEY"; |
+KeyParams::KeyParams(KeyType key_type) { |
+ if (key_type == KT_ECDSA) { |
+ type_ = KT_ECDSA; |
+ params_.curve = EC_NIST_P256; |
+ } else if (key_type == KT_RSA) { |
+ type_ = KT_RSA; |
+ params_.rsa.mod_size = kRsaDefaultModSize; |
+ params_.rsa.pub_exp = kRsaDefaultExponent; |
+ } else { |
+ RTC_NOTREACHED(); |
+ } |
+} |
+ |
+// static |
+KeyParams KeyParams::RSA(int mod_size, int pub_exp) { |
+ KeyParams kt(KT_RSA); |
+ kt.params_.rsa.mod_size = mod_size; |
+ kt.params_.rsa.pub_exp = pub_exp; |
+ return kt; |
+} |
+ |
+// static |
+KeyParams KeyParams::ECDSA(ECCurve curve) { |
+ KeyParams kt(KT_ECDSA); |
+ kt.params_.curve = curve; |
+ return kt; |
+} |
+ |
+bool KeyParams::IsValid() const { |
+ if (type_ == KT_RSA) { |
+ return (params_.rsa.mod_size >= kRsaMinModSize && |
+ params_.rsa.mod_size <= kRsaMaxModSize && |
+ params_.rsa.pub_exp > params_.rsa.mod_size); |
+ } else if (type_ == KT_ECDSA) { |
+ return (params_.curve == EC_NIST_P256); |
+ } |
+ return false; |
+} |
+ |
+RSAParams KeyParams::rsa_params() const { |
+ RTC_DCHECK(type_ == KT_RSA); |
+ return params_.rsa; |
+} |
+ |
+ECCurve KeyParams::ec_curve() const { |
+ RTC_DCHECK(type_ == KT_ECDSA); |
+ return params_.curve; |
+} |
+ |
KeyType IntKeyTypeFamilyToKeyType(int key_type_family) { |
return static_cast<KeyType>(key_type_family); |
} |
@@ -108,8 +158,8 @@ SSLCertificate* SSLCertificate::FromPEMString(const std::string& pem_string) { |
} |
SSLIdentity* SSLIdentity::Generate(const std::string& common_name, |
- KeyType key_type) { |
- return OpenSSLIdentity::Generate(common_name, key_type); |
+ const KeyParams& key_params) { |
+ return OpenSSLIdentity::Generate(common_name, key_params); |
} |
SSLIdentity* SSLIdentity::GenerateForTest(const SSLIdentityParams& params) { |