瀏覽代碼

Added certificateType option to C API

Paul-Louis Ageneau 4 年之前
父節點
當前提交
fff1912d30
共有 5 個文件被更改,包括 16 次插入2 次删除
  1. 5 1
      include/rtc/configuration.hpp
  2. 7 0
      include/rtc/rtc.h
  3. 1 0
      src/capi.cpp
  4. 2 0
      src/impl/certificate.cpp
  5. 1 1
      src/impl/certificate.hpp

+ 5 - 1
include/rtc/configuration.hpp

@@ -64,7 +64,11 @@ struct RTC_CPP_EXPORT ProxyServer {
 	string password;
 };
 
-enum class CertificateType { Ecdsa = 0, Rsa };
+enum class CertificateType {
+	Default = RTC_CERTIFICATE_DEFAULT, // ECDSA
+	Ecdsa = RTC_CERTIFICATE_ECDSA,
+	Rsa = RTC_CERTIFICATE_RSA
+};
 
 struct RTC_CPP_EXPORT Configuration {
 	// ICE settings

+ 7 - 0
include/rtc/rtc.h

@@ -88,6 +88,12 @@ typedef enum { // Don't change, it must match plog severity
 	RTC_LOG_VERBOSE = 6
 } rtcLogLevel;
 
+typedef enum {
+	RTC_CERTIFICATE_DEFAULT = 0,
+	RTC_CERTIFICATE_ECDSA = 1,
+	RTC_CERTIFICATE_RSA = 2,
+} rtcCertificateType;
+
 #if RTC_ENABLE_MEDIA
 
 typedef enum {
@@ -119,6 +125,7 @@ typedef enum {
 typedef struct {
 	const char **iceServers;
 	int iceServersCount;
+	rtcCertificateType certificateType;
 	bool enableIceTcp;
 	bool disableAutoNegotiation;
 	uint16_t portRangeBegin;

+ 1 - 0
src/capi.cpp

@@ -351,6 +351,7 @@ int rtcCreatePeerConnection(const rtcConfiguration *config) {
 		for (int i = 0; i < config->iceServersCount; ++i)
 			c.iceServers.emplace_back(string(config->iceServers[i]));
 
+		c.certificateType = static_cast<CertificateType>(config->certificateType);
 		c.enableIceTcp = config->enableIceTcp;
 		c.disableAutoNegotiation = config->disableAutoNegotiation;
 

+ 2 - 0
src/impl/certificate.cpp

@@ -102,6 +102,7 @@ certificate_ptr make_certificate_impl(CertificateType type) {
 	// All implementations MUST support DTLS 1.2 with the TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
 	// cipher suite and the P-256 curve
 	// See https://tools.ietf.org/html/rfc8827#section-6.5
+	case CertificateType::Default:
 	case CertificateType::Ecdsa: {
 		gnutls::check(gnutls_x509_privkey_generate(*privkey, GNUTLS_PK_ECDSA,
 		                                           GNUTLS_CURVE_TO_BITS(GNUTLS_ECC_CURVE_SECP256R1),
@@ -206,6 +207,7 @@ certificate_ptr make_certificate_impl(CertificateType type) {
 	// All implementations MUST support DTLS 1.2 with the TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
 	// cipher suite and the P-256 curve
 	// See https://tools.ietf.org/html/rfc8827#section-6.5
+	case CertificateType::Default:
 	case CertificateType::Ecdsa: {
 		PLOG_VERBOSE << "Generating ECDSA P-256 key pair";
 

+ 1 - 1
src/impl/certificate.hpp

@@ -62,7 +62,7 @@ string make_fingerprint(X509 *x509);
 using certificate_ptr = shared_ptr<Certificate>;
 using future_certificate_ptr = std::shared_future<certificate_ptr>;
 
-future_certificate_ptr make_certificate(CertificateType type = CertificateType::Ecdsa);
+future_certificate_ptr make_certificate(CertificateType type = CertificateType::Default);
 
 } // namespace rtc::impl