Parcourir la source

Added certificateType option to C API

Paul-Louis Ageneau il y a 4 ans
Parent
commit
fff1912d30
5 fichiers modifiés avec 16 ajouts et 2 suppressions
  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;
 	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 {
 struct RTC_CPP_EXPORT Configuration {
 	// ICE settings
 	// 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
 	RTC_LOG_VERBOSE = 6
 } rtcLogLevel;
 } rtcLogLevel;
 
 
+typedef enum {
+	RTC_CERTIFICATE_DEFAULT = 0,
+	RTC_CERTIFICATE_ECDSA = 1,
+	RTC_CERTIFICATE_RSA = 2,
+} rtcCertificateType;
+
 #if RTC_ENABLE_MEDIA
 #if RTC_ENABLE_MEDIA
 
 
 typedef enum {
 typedef enum {
@@ -119,6 +125,7 @@ typedef enum {
 typedef struct {
 typedef struct {
 	const char **iceServers;
 	const char **iceServers;
 	int iceServersCount;
 	int iceServersCount;
+	rtcCertificateType certificateType;
 	bool enableIceTcp;
 	bool enableIceTcp;
 	bool disableAutoNegotiation;
 	bool disableAutoNegotiation;
 	uint16_t portRangeBegin;
 	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)
 		for (int i = 0; i < config->iceServersCount; ++i)
 			c.iceServers.emplace_back(string(config->iceServers[i]));
 			c.iceServers.emplace_back(string(config->iceServers[i]));
 
 
+		c.certificateType = static_cast<CertificateType>(config->certificateType);
 		c.enableIceTcp = config->enableIceTcp;
 		c.enableIceTcp = config->enableIceTcp;
 		c.disableAutoNegotiation = config->disableAutoNegotiation;
 		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
 	// All implementations MUST support DTLS 1.2 with the TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
 	// cipher suite and the P-256 curve
 	// cipher suite and the P-256 curve
 	// See https://tools.ietf.org/html/rfc8827#section-6.5
 	// See https://tools.ietf.org/html/rfc8827#section-6.5
+	case CertificateType::Default:
 	case CertificateType::Ecdsa: {
 	case CertificateType::Ecdsa: {
 		gnutls::check(gnutls_x509_privkey_generate(*privkey, GNUTLS_PK_ECDSA,
 		gnutls::check(gnutls_x509_privkey_generate(*privkey, GNUTLS_PK_ECDSA,
 		                                           GNUTLS_CURVE_TO_BITS(GNUTLS_ECC_CURVE_SECP256R1),
 		                                           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
 	// All implementations MUST support DTLS 1.2 with the TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
 	// cipher suite and the P-256 curve
 	// cipher suite and the P-256 curve
 	// See https://tools.ietf.org/html/rfc8827#section-6.5
 	// See https://tools.ietf.org/html/rfc8827#section-6.5
+	case CertificateType::Default:
 	case CertificateType::Ecdsa: {
 	case CertificateType::Ecdsa: {
 		PLOG_VERBOSE << "Generating ECDSA P-256 key pair";
 		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 certificate_ptr = shared_ptr<Certificate>;
 using future_certificate_ptr = std::shared_future<certificate_ptr>;
 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
 } // namespace rtc::impl