RTCPeerConnection.generateCertificate is not a function
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 20:52:15 +0000 (20:52 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 20:52:15 +0000 (20:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173541
<rdar://problem/32638029>

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCCertificate-expected.txt:
* web-platform-tests/webrtc/RTCPeerConnection-generateCertificate-expected.txt:
* web-platform-tests/webrtc/interfaces.https-expected.txt:
* web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-constructor-expected.txt:

Source/ThirdParty/libwebrtc:

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:

Source/WebCore:

Add support for RTCCertificate generation through libwebrtc certificate generator.
Make generation in the webrtc network thread.
Support is as per spec (ECDSA and RSASSA_PKCS).

Partially covered by WPT tests.

* css/StyleBuilder.h: Fixing build.
* CMakeLists.txt:
* DerivedSources.make:
* Modules/webauthn/PublicKeyCredential.cpp: Fixing build.
* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::generateCertificate):
* Modules/mediastream/PeerConnectionBackend.h:
(WebCore::PeerConnectionBackend::CertificateInformation::RSASSA_PKCS1_v1_5):
(WebCore::PeerConnectionBackend::CertificateInformation::ECDSA_P256):
(WebCore::PeerConnectionBackend::CertificateInformation::CertificateInformation):
* Modules/mediastream/RTCCertificate.cpp: Added.
(WebCore::RTCCertificate::create):
(WebCore::RTCCertificate::RTCCertificate):
* Modules/mediastream/RTCCertificate.h: Added.
(WebCore::RTCCertificate::expires const):
(WebCore::RTCCertificate::getFingerprints const):
* Modules/mediastream/RTCCertificate.idl: Added.
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::certificateTypeFromAlgorithmIdentifier):
(WebCore::RTCPeerConnection::generateCertificate):
* Modules/mediastream/RTCPeerConnection.h:
* Modules/mediastream/RTCPeerConnection.idl:
* Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp: Added.
(WebCore::LibWebRTCCertificateGenerator::RTCCertificateGeneratorCallback::RTCCertificateGeneratorCallback):
(WebCore::LibWebRTCCertificateGenerator::RTCCertificateGeneratorCallback::~RTCCertificateGeneratorCallback):
(WebCore::LibWebRTCCertificateGenerator::keyParamsFromCertificateType):
(WebCore::LibWebRTCCertificateGenerator::generateCertificate):
* Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.h: Added.
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:
* platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
(WebCore::LibWebRTCProvider::certificateGenerator):
* platform/mediastream/libwebrtc/LibWebRTCProvider.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237140 268f45cc-cd09-0410-ab3c-d52691b4dbfc

31 files changed:
LayoutTests/http/wpt/webrtc/generateCertificate-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/webrtc/generateCertificate.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCCertificate-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-generateCertificate-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/interfaces.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-constructor-expected.txt
Source/ThirdParty/libwebrtc/ChangeLog
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp
Source/WebCore/Modules/mediastream/PeerConnectionBackend.h
Source/WebCore/Modules/mediastream/RTCCertificate.cpp [new file with mode: 0644]
Source/WebCore/Modules/mediastream/RTCCertificate.h [new file with mode: 0644]
Source/WebCore/Modules/mediastream/RTCCertificate.idl [new file with mode: 0644]
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.idl
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp [new file with mode: 0644]
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.h [new file with mode: 0644]
Source/WebCore/Modules/webauthn/PublicKeyCredential.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/WebCoreBuiltinNames.h
Source/WebCore/css/StyleBuilder.h
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h

diff --git a/LayoutTests/http/wpt/webrtc/generateCertificate-expected.txt b/LayoutTests/http/wpt/webrtc/generateCertificate-expected.txt
new file mode 100644 (file)
index 0000000..5c5a90e
--- /dev/null
@@ -0,0 +1,7 @@
+
+PASS generateCertificate() with algorithm as a string fails 
+PASS generateCertificate() with unsupported ECDSA curve 
+PASS generateCertificate() with unsupported RSA hash 
+PASS generateCertificate() with missing modulusLength should skip publicExponent 
+PASS generateCertificate() with missing exponent should skip modulusLength 
+
diff --git a/LayoutTests/http/wpt/webrtc/generateCertificate.html b/LayoutTests/http/wpt/webrtc/generateCertificate.html
new file mode 100644 (file)
index 0000000..598b8cd
--- /dev/null
@@ -0,0 +1,42 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>RTCCertificate Tests</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+promise_test(t => {
+    return promise_rejects(t, 'NotSupportedError', RTCPeerConnection.generateCertificate('ECDSA'));
+}, 'generateCertificate() with algorithm as a string fails');
+
+promise_test(t => {
+    return promise_rejects(t, 'NotSupportedError', RTCPeerConnection.generateCertificate({
+        name: 'ECDSA',
+        namedCurve: 'P-257'
+    }));
+}, 'generateCertificate() with unsupported ECDSA curve');
+
+promise_test(t => {
+    return promise_rejects(t, 'NotSupportedError', RTCPeerConnection.generateCertificate({
+        name: 'RSASSA-PKCS1-v1_5',
+        modulusLength: 2048,
+        publicExponent: new Uint8Array([1, 0, 1]),
+        hash: 'SHA-255'
+    }));
+}, 'generateCertificate() with unsupported RSA hash');
+
+promise_test(t => {
+    return RTCPeerConnection.generateCertificate({
+        name: 'RSASSA-PKCS1-v1_5',
+        publicExponent: new Uint8Array([]),
+        hash: 'SHA-256'
+    });
+}, 'generateCertificate() with missing modulusLength should skip publicExponent');
+
+promise_test(t => {
+    return RTCPeerConnection.generateCertificate({
+        name: 'RSASSA-PKCS1-v1_5',
+        modulusLength: 0,
+        hash: 'SHA-256'
+    });
+}, 'generateCertificate() with missing exponent should skip modulusLength');
+</script>
index 64495c2..61758bc 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-15  Youenn Fablet  <youenn@apple.com>
+
+        RTCPeerConnection.generateCertificate is not a function
+        https://bugs.webkit.org/show_bug.cgi?id=173541
+        <rdar://problem/32638029>
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc/RTCCertificate-expected.txt:
+        * web-platform-tests/webrtc/RTCPeerConnection-generateCertificate-expected.txt:
+        * web-platform-tests/webrtc/interfaces.https-expected.txt:
+        * web-platform-tests/webrtc/rtcpeerconnection/rtcpeerconnection-constructor-expected.txt:
+
 2018-10-15  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r237054.
index 1413786..23b7012 100644 (file)
@@ -1,23 +1,11 @@
 
-FAIL Constructing RTCPeerConnection with expired certificate should reject with InvalidAccessError RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256',
-      expires: 0
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL Calling setConfiguration with different set of certs should reject with InvalidModificationError RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256'
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL RTCCertificate should have at least one fingerprint RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256'
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL RTCPeerConnection({ certificates }) should generate offer SDP with fingerprint of provided certificate RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256'
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL RTCPeerConnection({ certificates }) should generate offer SDP with fingerprint of all provided certificates RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256'
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
+FAIL Constructing RTCPeerConnection with expired certificate should reject with InvalidAccessError assert_throws: function "() =>
+        new RTCPeerConnection({ certificates: [cert] })" did not throw
+FAIL Calling setConfiguration with different set of certs should reject with InvalidModificationError assert_throws: function "() =>
+        pc.setConfiguration({
+          certificates: [cert2]
+        })" did not throw
+PASS RTCCertificate should have at least one fingerprint 
+FAIL RTCPeerConnection({ certificates }) should generate offer SDP with fingerprint of provided certificate assert_true: Expect fingerprint line to be found in SDP expected true got false
+FAIL RTCPeerConnection({ certificates }) should generate offer SDP with fingerprint of all provided certificates assert_true: Expect fingerprint line to be found in SDP expected true got false
 
index ab2d808..d467517 100644 (file)
@@ -1,31 +1,10 @@
 
-FAIL generateCertificate() with compulsary RSASSA-PKCS1-v1_5 parameters should succeed undefined is not a function (near '...RTCPeerConnection.generateCertificate...')
-FAIL generateCertificate() with compulsary ECDSA parameters should succeed RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256'
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL generateCertificate() with invalid string algorithm should reject with NotSupportedError RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate('invalid-algo')', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL generateCertificate() with invalid algorithm dict should reject with NotSupportedError RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-        name: 'invalid-algo'
-      })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL generateCertificate() with valid expires parameter should succeed RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256',
-      expires: 2000
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL generateCertificate() with 0 expires parameter should generate expired cert RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-      name: 'ECDSA',
-      namedCurve: 'P-256',
-      expires: 0
-    })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL generateCertificate() with invalid range for expires should reject with TypeError RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-        name: 'ECDSA',
-        namedCurve: 'P-256',
-        expires: -1
-      })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL generateCertificate() with invalid type for expires should reject with TypeError RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({
-        name: 'ECDSA',
-        namedCurve: 'P-256',
-        expires: 'invalid'
-      })', 'RTCPeerConnection.generateCertificate' is undefined)
+PASS generateCertificate() with compulsary RSASSA-PKCS1-v1_5 parameters should succeed 
+PASS generateCertificate() with compulsary ECDSA parameters should succeed 
+PASS generateCertificate() with invalid string algorithm should reject with NotSupportedError 
+PASS generateCertificate() with invalid algorithm dict should reject with NotSupportedError 
+PASS generateCertificate() with valid expires parameter should succeed 
+PASS generateCertificate() with 0 expires parameter should generate expired cert 
+PASS generateCertificate() with invalid range for expires should reject with TypeError 
+PASS generateCertificate() with invalid type for expires should reject with TypeError 
 
index 1d4cc64..ef828fd 100644 (file)
@@ -1,6 +1,6 @@
 
 PASS Main test driver 
-FAIL Test driver for asyncInitCertificate undefined is not a function (near '...RTCPeerConnection.generateCertificate...')
+PASS Test driver for asyncInitCertificate 
 FAIL Test driver for asyncInitTransports assert_unreached: Failed to run asyncInitTransports: ReferenceError: Can't find variable: RTCSctpTransport Reached unreachable code
 PASS Test driver for asyncInitMediaStreamTrack 
 PASS EventTarget interface: existence and properties of interface object 
index 481744b..860c8f1 100644 (file)
@@ -77,8 +77,10 @@ FAIL new RTCPeerConnection({ certificates: [undefined] }) assert_throws: functio
         eval(expr);
       }" did not throw
 PASS new RTCPeerConnection({ iceCandidatePoolSize: toNumberThrows }) 
-FAIL new RTCPeerConnection({ certificates: [certificate] }) RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-256" })', 'RTCPeerConnection.generateCertificate' is undefined)
-FAIL new RTCPeerConnection({ certificates: [expiredCertificate] }) RTCPeerConnection.generateCertificate is not a function. (In 'RTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-256", expires: 0 })', 'RTCPeerConnection.generateCertificate' is undefined)
+PASS new RTCPeerConnection({ certificates: [certificate] }) 
+FAIL new RTCPeerConnection({ certificates: [expiredCertificate] }) assert_throws: function "function () {
+          new RTCPeerConnection({ certificates: [certificate] });
+        }" did not throw
 PASS localDescription initial value 
 PASS currentLocalDescription initial value 
 PASS pendingLocalDescription initial value 
index bd05595..32e8776 100644 (file)
@@ -1,3 +1,15 @@
+2018-10-15  Youenn Fablet  <youenn@apple.com>
+
+        RTCPeerConnection.generateCertificate is not a function
+        https://bugs.webkit.org/show_bug.cgi?id=173541
+        <rdar://problem/32638029>
+
+        Reviewed by Eric Carlson.
+
+        * Configurations/libwebrtc.iOS.exp:
+        * Configurations/libwebrtc.iOSsim.exp:
+        * Configurations/libwebrtc.mac.exp:
+
 2018-10-12  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed build fix, remove executable file imported with r237075.
index 40705a0..ed675cf 100644 (file)
@@ -220,3 +220,11 @@ __ZN6webrtc18RtpSenderInterface17SetFrameEncryptorEN3rtc13scoped_refptrINS_23Fra
 __ZN6webrtc30PeerConnectionFactoryInterface17CreateVideoSourceENSt3__110unique_ptrIN7cricket13VideoCapturerENS1_14default_deleteIS4_EEEE
 __ZNK3rtc14NetworkManager16GetMDnsResponderEv
 __ZTVN6webrtc18RtpSenderInterfaceE
+__ZN3rtc23RTCCertificateGeneratorC1EPNS_6ThreadES2_
+__ZN3rtc9KeyParams3RSAEii
+__ZN3rtc9KeyParams5ECDSAENS_7ECCurveE
+__ZNK3rtc14RTCCertificate7ExpiresEv
+__ZN3rtc19SSLCertificateStatsD1Ev
+__ZNK3rtc14RTCCertificate15ssl_certificateEv
+__ZNK3rtc14RTCCertificate5ToPEMEv
+__ZNK3rtc14SSLCertificate8GetStatsEv
index d301e63..dc198b3 100644 (file)
@@ -221,3 +221,11 @@ __ZN6webrtc18RtpSenderInterface17SetFrameEncryptorEN3rtc13scoped_refptrINS_23Fra
 __ZN6webrtc30PeerConnectionFactoryInterface17CreateVideoSourceENSt3__110unique_ptrIN7cricket13VideoCapturerENS1_14default_deleteIS4_EEEE
 __ZNK3rtc14NetworkManager16GetMDnsResponderEv
 __ZTVN6webrtc18RtpSenderInterfaceE
+__ZN3rtc23RTCCertificateGeneratorC1EPNS_6ThreadES2_
+__ZN3rtc9KeyParams3RSAEii
+__ZN3rtc9KeyParams5ECDSAENS_7ECCurveE
+__ZNK3rtc14RTCCertificate7ExpiresEv
+__ZN3rtc19SSLCertificateStatsD1Ev
+__ZNK3rtc14RTCCertificate15ssl_certificateEv
+__ZNK3rtc14RTCCertificate5ToPEMEv
+__ZNK3rtc14SSLCertificate8GetStatsEv
index d301e63..dc198b3 100644 (file)
@@ -221,3 +221,11 @@ __ZN6webrtc18RtpSenderInterface17SetFrameEncryptorEN3rtc13scoped_refptrINS_23Fra
 __ZN6webrtc30PeerConnectionFactoryInterface17CreateVideoSourceENSt3__110unique_ptrIN7cricket13VideoCapturerENS1_14default_deleteIS4_EEEE
 __ZNK3rtc14NetworkManager16GetMDnsResponderEv
 __ZTVN6webrtc18RtpSenderInterfaceE
+__ZN3rtc23RTCCertificateGeneratorC1EPNS_6ThreadES2_
+__ZN3rtc9KeyParams3RSAEii
+__ZN3rtc9KeyParams5ECDSAENS_7ECCurveE
+__ZNK3rtc14RTCCertificate7ExpiresEv
+__ZN3rtc19SSLCertificateStatsD1Ev
+__ZNK3rtc14RTCCertificate15ssl_certificateEv
+__ZNK3rtc14RTCCertificate5ToPEMEv
+__ZNK3rtc14SSLCertificate8GetStatsEv
index 944b51b..5f05d1e 100644 (file)
@@ -38,6 +38,7 @@ set(WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/Modules/mediasession"
     "${WEBCORE_DIR}/Modules/mediasource"
     "${WEBCORE_DIR}/Modules/mediastream"
+    "${WEBCORE_DIR}/Modules/mediastream/libwebrtc"
     "${WEBCORE_DIR}/Modules/mediarecorder"
     "${WEBCORE_DIR}/Modules/navigatorcontentutils"
     "${WEBCORE_DIR}/Modules/notifications"
@@ -307,6 +308,7 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/mediastream/OverconstrainedError.idl
     Modules/mediastream/OverconstrainedErrorEvent.idl
     Modules/mediastream/RTCAnswerOptions.idl
+    Modules/mediastream/RTCCertificate.idl
     Modules/mediastream/RTCConfiguration.idl
     Modules/mediastream/RTCDTMFSender.idl
     Modules/mediastream/RTCDTMFToneChangeEvent.idl
index 2a517d9..924ed27 100644 (file)
@@ -1,3 +1,52 @@
+2018-10-15  Youenn Fablet  <youenn@apple.com>
+
+        RTCPeerConnection.generateCertificate is not a function
+        https://bugs.webkit.org/show_bug.cgi?id=173541
+        <rdar://problem/32638029>
+
+        Reviewed by Eric Carlson.
+
+        Add support for RTCCertificate generation through libwebrtc certificate generator.
+        Make generation in the webrtc network thread.
+        Support is as per spec (ECDSA and RSASSA_PKCS).
+
+        Partially covered by WPT tests.
+
+        * css/StyleBuilder.h: Fixing build.
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Modules/webauthn/PublicKeyCredential.cpp: Fixing build.
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::generateCertificate):
+        * Modules/mediastream/PeerConnectionBackend.h:
+        (WebCore::PeerConnectionBackend::CertificateInformation::RSASSA_PKCS1_v1_5):
+        (WebCore::PeerConnectionBackend::CertificateInformation::ECDSA_P256):
+        (WebCore::PeerConnectionBackend::CertificateInformation::CertificateInformation):
+        * Modules/mediastream/RTCCertificate.cpp: Added.
+        (WebCore::RTCCertificate::create):
+        (WebCore::RTCCertificate::RTCCertificate):
+        * Modules/mediastream/RTCCertificate.h: Added.
+        (WebCore::RTCCertificate::expires const):
+        (WebCore::RTCCertificate::getFingerprints const):
+        * Modules/mediastream/RTCCertificate.idl: Added.
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::certificateTypeFromAlgorithmIdentifier):
+        (WebCore::RTCPeerConnection::generateCertificate):
+        * Modules/mediastream/RTCPeerConnection.h:
+        * Modules/mediastream/RTCPeerConnection.idl:
+        * Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp: Added.
+        (WebCore::LibWebRTCCertificateGenerator::RTCCertificateGeneratorCallback::RTCCertificateGeneratorCallback):
+        (WebCore::LibWebRTCCertificateGenerator::RTCCertificateGeneratorCallback::~RTCCertificateGeneratorCallback):
+        (WebCore::LibWebRTCCertificateGenerator::keyParamsFromCertificateType):
+        (WebCore::LibWebRTCCertificateGenerator::generateCertificate):
+        * Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.h: Added.
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+        * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
+        (WebCore::LibWebRTCProvider::certificateGenerator):
+        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
+
 2018-10-15  Simon Fraser  <simon.fraser@apple.com>
 
         Add compact logging for the paint-order RenderLayer tree
index a412c1a..4a5fdfa 100644 (file)
@@ -231,6 +231,7 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/mediastream/OverconstrainedError.idl \
     $(WebCore)/Modules/mediastream/OverconstrainedErrorEvent.idl \
     $(WebCore)/Modules/mediastream/RTCAnswerOptions.idl \
+    $(WebCore)/Modules/mediastream/RTCCertificate.idl \
     $(WebCore)/Modules/mediastream/RTCConfiguration.idl \
     $(WebCore)/Modules/mediastream/RTCDTMFSender.idl \
     $(WebCore)/Modules/mediastream/RTCDTMFToneChangeEvent.idl \
index 2f17418..12aa9fa 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "EventNames.h"
 #include "JSRTCSessionDescription.h"
+#include "LibWebRTCCertificateGenerator.h"
 #include "Logging.h"
 #include "Page.h"
 #include "RTCIceCandidate.h"
@@ -545,6 +546,18 @@ ExceptionOr<Ref<RTCRtpTransceiver>> PeerConnectionBackend::addTransceiver(Ref<Me
     return Exception { NotSupportedError, "Not implemented"_s };
 }
 
+void PeerConnectionBackend::generateCertificate(Document& document, const CertificateInformation& info, DOMPromiseDeferred<IDLInterface<RTCCertificate>>&& promise)
+{
+#if USE(LIBWEBRTC)
+    LibWebRTCCertificateGenerator::generateCertificate(document.page()->libWebRTCProvider(), info, WTFMove(promise));
+#else
+    UNUSED_PARAM(document);
+    UNUSED_PARAM(expires);
+    UNUSED_PARAM(type);
+    promise.reject(NotSupportedError);
+#endif
+}
+
 #if !RELEASE_LOG_DISABLED
 WTFLogChannel& PeerConnectionBackend::logChannel() const
 {
index 6521765..56f6f09 100644 (file)
 
 namespace WebCore {
 
+class Document;
 class MediaStream;
 class MediaStreamTrack;
 class PeerConnectionBackend;
+class RTCCertificate;
 class RTCDataChannelHandler;
 class RTCIceCandidate;
 class RTCPeerConnection;
@@ -133,6 +135,35 @@ public:
 
     void finishedRegisteringMDNSName(const String& ipAddress, const String& name);
 
+    struct CertificateInformation {
+        enum class Type { RSASSAPKCS1v15, ECDSAP256 };
+        struct RSA {
+            unsigned modulusLength;
+            int publicExponent;
+        };
+
+        static CertificateInformation RSASSA_PKCS1_v1_5()
+        {
+            return CertificateInformation { Type::RSASSAPKCS1v15 };
+        }
+
+        static CertificateInformation ECDSA_P256()
+        {
+            return CertificateInformation { Type::ECDSAP256 };
+        }
+
+        explicit CertificateInformation(Type type)
+            : type(type)
+        {
+        }
+
+        Type type;
+        std::optional<double> expires;
+
+        std::optional<RSA> rsaParameters;
+    };
+    static void generateCertificate(Document&, const CertificateInformation&, DOMPromiseDeferred<IDLInterface<RTCCertificate>>&&);
+
 protected:
     void fireICECandidateEvent(RefPtr<RTCIceCandidate>&&, String&& url);
     void doneGatheringCandidates();
diff --git a/Source/WebCore/Modules/mediastream/RTCCertificate.cpp b/Source/WebCore/Modules/mediastream/RTCCertificate.cpp
new file mode 100644 (file)
index 0000000..c137fa1
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RTCCertificate.h"
+
+#if ENABLE(WEB_RTC)
+
+namespace WebCore {
+
+Ref<RTCCertificate> RTCCertificate::create(double expires, Vector<DtlsFingerprint>&& fingerprints, String&& pemCertificate, String&& pemPrivateKey)
+{
+    return adoptRef(*new RTCCertificate(expires, WTFMove(fingerprints), WTFMove(pemCertificate), WTFMove(pemPrivateKey)));
+}
+
+RTCCertificate::RTCCertificate(double expires, Vector<DtlsFingerprint>&& fingerprints, String&& pemCertificate, String&& pemPrivateKey)
+    : m_expires(expires)
+    , m_fingerprints(WTFMove(fingerprints))
+    , m_pemCertificate(WTFMove(pemCertificate))
+    , m_pemPrivateKey(WTFMove(pemPrivateKey))
+{
+}
+
+}
+
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/Modules/mediastream/RTCCertificate.h b/Source/WebCore/Modules/mediastream/RTCCertificate.h
new file mode 100644 (file)
index 0000000..6e27c35
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_RTC)
+
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class RTCCertificate : public RefCounted<RTCCertificate> {
+public:
+    struct DtlsFingerprint {
+        String algorithm;
+        String value;
+    };
+
+    static Ref<RTCCertificate> create(double expires, Vector<DtlsFingerprint>&&, String&& pemCertificate, String&& pemPrivateKey);
+
+    double expires() const { return m_expires; }
+    const Vector<DtlsFingerprint>& getFingerprints() const { return m_fingerprints; }
+
+    const String& pemCertificate() const { return m_pemCertificate; }
+    const String& pemPrivateKey() const { return m_pemPrivateKey; }
+
+private:
+    RTCCertificate(double expires, Vector<DtlsFingerprint>&&, String&& pemCertificate, String&& pemPrivateKey);
+
+    double m_expires { 0 };
+    Vector<DtlsFingerprint> m_fingerprints;
+    String m_pemCertificate;
+    String m_pemPrivateKey;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/Modules/mediastream/RTCCertificate.idl b/Source/WebCore/Modules/mediastream/RTCCertificate.idl
new file mode 100644 (file)
index 0000000..32caed9
--- /dev/null
@@ -0,0 +1,45 @@
+ /*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection,
+    JSGenerateToJSObject,
+] dictionary RTCDtlsFingerprint {
+    DOMString algorithm;
+    DOMString value;
+};
+
+typedef (object or DOMString) AlgorithmIdentifier;
+
+[
+    Conditional=WEB_RTC,
+    EnabledAtRuntime=PeerConnection,
+    ImplementationLacksVTable
+] interface RTCCertificate {
+    readonly attribute double expires;
+    sequence<RTCDtlsFingerprint> getFingerprints();
+    // FIXME: Expose getSupportedAlgorithms.
+};
index ee90075..befc395 100644 (file)
@@ -40,6 +40,7 @@
 #include "Event.h"
 #include "EventNames.h"
 #include "Frame.h"
+#include "JSRTCPeerConnection.h"
 #include "Logging.h"
 #include "MediaEndpointConfiguration.h"
 #include "MediaStream.h"
@@ -539,6 +540,63 @@ void RTCPeerConnection::dispatchEvent(Event& event)
     EventTarget::dispatchEvent(event);
 }
 
+static inline ExceptionOr<PeerConnectionBackend::CertificateInformation> certificateTypeFromAlgorithmIdentifier(JSC::ExecState& state, RTCPeerConnection::AlgorithmIdentifier&& algorithmIdentifier)
+{
+    if (WTF::holds_alternative<String>(algorithmIdentifier))
+        return Exception { NotSupportedError, "Algorithm is not supported"_s };
+
+    auto& value = WTF::get<JSC::Strong<JSC::JSObject>>(algorithmIdentifier);
+
+    JSC::VM& vm = state.vm();
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    auto parameters = convertDictionary<RTCPeerConnection::CertificateParameters>(state, value.get());
+    if (UNLIKELY(scope.exception())) {
+        scope.clearException();
+        return Exception { TypeError, "Unable to read certificate parameters"_s };
+    }
+
+    if (parameters.expires && *parameters.expires < 0)
+        return Exception { TypeError, "Expire value is invalid"_s };
+
+    if (parameters.name == "RSASSA-PKCS1-v1_5"_s) {
+        if (!parameters.hash.isNull() && parameters.hash != "SHA-256"_s)
+            return Exception { NotSupportedError, "Only SHA-256 is supported for RSASSA-PKCS1-v1_5"_s };
+
+        auto result = PeerConnectionBackend::CertificateInformation::RSASSA_PKCS1_v1_5();
+        if (parameters.modulusLength && parameters.publicExponent) {
+            int publicExponent = 0;
+            int value = 1;
+            for (unsigned counter = 0; counter < parameters.publicExponent->byteLength(); ++counter) {
+                publicExponent += parameters.publicExponent->data()[counter] * value;
+                value <<= 8;
+            }
+
+            result.rsaParameters = PeerConnectionBackend::CertificateInformation::RSA { *parameters.modulusLength, publicExponent };
+        }
+        result.expires = parameters.expires;
+        return WTFMove(result);
+    }
+    if (parameters.name == "ECDSA"_s && parameters.namedCurve == "P-256"_s) {
+        auto result = PeerConnectionBackend::CertificateInformation::ECDSA_P256();
+        result.expires = parameters.expires;
+        return WTFMove(result);
+    }
+
+    return Exception { NotSupportedError, "Algorithm is not supported"_s };
+}
+
+void RTCPeerConnection::generateCertificate(JSC::ExecState& state, AlgorithmIdentifier&& algorithmIdentifier, DOMPromiseDeferred<IDLInterface<RTCCertificate>>&& promise)
+{
+    auto parameters = certificateTypeFromAlgorithmIdentifier(state, WTFMove(algorithmIdentifier));
+    if (parameters.hasException()) {
+        promise.reject(parameters.releaseException());
+        return;
+    }
+    auto& document = downcast<Document>(*JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->scriptExecutionContext());
+    PeerConnectionBackend::generateCertificate(document, parameters.returnValue(), WTFMove(promise));
+}
+
 #if !RELEASE_LOG_DISABLED
 WTFLogChannel& RTCPeerConnection::logChannel() const
 {
index 35c1edf..8eeec60 100644 (file)
@@ -45,6 +45,7 @@
 #include "RTCPeerConnectionState.h"
 #include "RTCRtpTransceiver.h"
 #include "RTCSignalingState.h"
+#include <JavaScriptCore/Uint8Array.h>
 #include <wtf/LoggerHelper.h>
 
 namespace WebCore {
@@ -80,6 +81,18 @@ public:
 
     ExceptionOr<void> initializeWith(Document&, RTCConfiguration&&);
 
+    struct CertificateParameters {
+        String name;
+        String hash;
+        String namedCurve;
+        std::optional<uint32_t> modulusLength;
+        RefPtr<Uint8Array> publicExponent;
+        std::optional<double> expires;
+    };
+
+    using AlgorithmIdentifier = Variant<JSC::Strong<JSC::JSObject>, String>;
+    static void generateCertificate(JSC::ExecState&, AlgorithmIdentifier&&, DOMPromiseDeferred<IDLInterface<RTCCertificate>>&&);
+
     // 4.3.2 RTCPeerConnection Interface
     void queuedCreateOffer(RTCOfferOptions&&, PeerConnection::SessionDescriptionPromise&&);
     void queuedCreateAnswer(RTCAnswerOptions&&, PeerConnection::SessionDescriptionPromise&&);
index f32262b..884a8be 100644 (file)
@@ -47,6 +47,20 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
 };
 
 [
+Conditional=WEB_RTC,
+EnabledAtRuntime=PeerConnection
+] dictionary RTCCertificateParameters {
+    DOMString name;
+    DOMString hash;
+    DOMString namedCurve;
+    unsigned long modulusLength;
+    Uint8Array publicExponent;
+    double expires;
+};
+
+typedef (object or DOMString) AlgorithmIdentifier;
+
+[
     Conditional=WEB_RTC,
     EnabledAtRuntime=PeerConnection,
     ImplementedAs=RTCRtpTransceiverInit
@@ -114,8 +128,7 @@ typedef RTCRtpTransceiverDirection RtpTransceiverDirection;
 
 
     // 4.11 Certificate management
-    // FIXME 169644: missing generateCertificate
-
+    [CallWith=ScriptState] static Promise<RTCCertificate> generateCertificate(AlgorithmIdentifier keygenAlgorithm);
 
     // 5.1 RTCPeerConnection extensions
     // RTP Media API extensions
diff --git a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp
new file mode 100644 (file)
index 0000000..1f1ebf2
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2018 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LibWebRTCCertificateGenerator.h"
+
+#if USE(LIBWEBRTC)
+
+#include "JSRTCCertificate.h"
+#include "LibWebRTCMacros.h"
+
+ALLOW_UNUSED_PARAMETERS_BEGIN
+
+#include <webrtc/rtc_base/rtccertificategenerator.h>
+
+ALLOW_UNUSED_PARAMETERS_END
+
+namespace WebCore {
+
+namespace LibWebRTCCertificateGenerator {
+
+static inline String fromStdString(const std::string& value)
+{
+    return String::fromUTF8(value.data(), value.length());
+}
+
+class RTCCertificateGeneratorCallback : public ThreadSafeRefCounted<RTCCertificateGeneratorCallback, WTF::DestructionThread::Main>, public rtc::RTCCertificateGeneratorCallback {
+public:
+    explicit RTCCertificateGeneratorCallback(DOMPromiseDeferred<IDLInterface<RTCCertificate>>&& promise)
+        : m_promise(WTFMove(promise))
+    {
+    }
+
+    void AddRef() const final { ref(); }
+    rtc::RefCountReleaseStatus Release() const final
+    {
+        auto result = refCount() - 1;
+        deref();
+        return result ? rtc::RefCountReleaseStatus::kOtherRefsRemained : rtc::RefCountReleaseStatus::kDroppedLastRef;
+    }
+
+private:
+    void OnSuccess(const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) final
+    {
+        callOnMainThread([promise = WTFMove(m_promise.value()), certificate]() mutable {
+            Vector<RTCCertificate::DtlsFingerprint> fingerprints;
+            auto stats = certificate->ssl_certificate().GetStats();
+            auto* info = stats.get();
+            while (info) {
+                StringView fingerprint { reinterpret_cast<const unsigned char*>(info->fingerprint.data()), static_cast<unsigned>(info->fingerprint.length()) };
+                fingerprints.append({ fromStdString(info->fingerprint_algorithm), fingerprint.convertToASCIILowercase() });
+                info = info->issuer.get();
+            };
+
+            auto pem = certificate->ToPEM();
+            promise.resolve(RTCCertificate::create(certificate->Expires(), WTFMove(fingerprints), fromStdString(pem.certificate()), fromStdString(pem.private_key())));
+        });
+    }
+
+    void OnFailure() final
+    {
+        callOnMainThread([promise = WTFMove(m_promise.value())]() mutable {
+            promise.reject(Exception { TypeError, "Unable to create a certificate"_s});
+        });
+    }
+
+    std::optional<DOMPromiseDeferred<IDLInterface<RTCCertificate>>> m_promise;
+};
+
+static inline rtc::KeyParams keyParamsFromCertificateType(const PeerConnectionBackend::CertificateInformation& info)
+{
+    switch (info.type) {
+    case PeerConnectionBackend::CertificateInformation::Type::ECDSAP256:
+        return rtc::KeyParams::ECDSA();
+    case PeerConnectionBackend::CertificateInformation::Type::RSASSAPKCS1v15:
+        if (info.rsaParameters)
+            return rtc::KeyParams::RSA(info.rsaParameters->modulusLength, info.rsaParameters->publicExponent);
+        return rtc::KeyParams::RSA(2048, 65537);
+    }
+}
+
+void generateCertificate(LibWebRTCProvider& provider, const PeerConnectionBackend::CertificateInformation& info, DOMPromiseDeferred<IDLInterface<RTCCertificate>>&& promise)
+{
+    rtc::scoped_refptr<RTCCertificateGeneratorCallback> callback(new RTCCertificateGeneratorCallback(WTFMove(promise)));
+
+    absl::optional<uint64_t> expiresMs;
+    if (info.expires)
+        expiresMs = static_cast<uint64_t>(*info.expires);
+
+    provider.certificateGenerator().GenerateCertificateAsync(keyParamsFromCertificateType(info), expiresMs, WTFMove(callback));
+}
+
+} // namespace LibWebRTCCertificateGenerator
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
diff --git a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.h b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.h
new file mode 100644 (file)
index 0000000..417c32e
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "PeerConnectionBackend.h"
+
+namespace WebCore {
+
+class LibWebRTCProvider;
+
+namespace LibWebRTCCertificateGenerator {
+
+void generateCertificate(LibWebRTCProvider&, const PeerConnectionBackend::CertificateInformation&, DOMPromiseDeferred<IDLInterface<RTCCertificate>>&&);
+
+} // namespace LibWebRTCCertificateGenerator
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
index 21f700c..cff64dd 100644 (file)
 
 #if ENABLE(WEB_AUTHN)
 
+#include "AuthenticatorAssertionResponse.h"
+#include "AuthenticatorAttestationResponse.h"
 #include "AuthenticatorCoordinator.h"
+#include "AuthenticatorResponse.h"
 #include "Document.h"
 #include "JSDOMPromiseDeferred.h"
 #include "Page.h"
index 53f218c..d2a2902 100644 (file)
@@ -167,6 +167,7 @@ Modules/mediastream/MediaStreamTrackEvent.cpp
 Modules/mediastream/MediaTrackConstraints.cpp
 Modules/mediastream/NavigatorMediaDevices.cpp
 Modules/mediastream/PeerConnectionBackend.cpp
+Modules/mediastream/RTCCertificate.cpp
 Modules/mediastream/RTCController.cpp
 Modules/mediastream/RTCDTMFSender.cpp
 Modules/mediastream/RTCDTMFToneChangeEvent.cpp
@@ -183,6 +184,8 @@ Modules/mediastream/RTCTrackEvent.cpp
 Modules/mediastream/UserMediaController.cpp
 Modules/mediastream/UserMediaRequest.cpp
 
+Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp
+
 Modules/navigatorcontentutils/NavigatorContentUtils.cpp
 
 Modules/notifications/Notification.cpp
@@ -2879,6 +2882,7 @@ JSPublicKeyCredentialDescriptor.cpp
 JSPublicKeyCredentialRequestOptions.cpp
 JSPublicKeyCredentialType.cpp
 JSRTCAnswerOptions.cpp
+JSRTCCertificate.cpp
 JSRTCConfiguration.cpp
 JSRTCDTMFSender.cpp
 JSRTCDTMFToneChangeEvent.cpp
index fa4a980..ac35e3b 100644 (file)
                41189EF71AD8232800B90A0D /* ReadableStreamDefaultController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultController.idl; sourceTree = "<group>"; };
                41189EF71AD8232800B93F64 /* ReadableByteStreamController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableByteStreamController.idl; sourceTree = "<group>"; };
                41189EF71AD8232800B95672 /* ReadableStreamBYOBRequest.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamBYOBRequest.idl; sourceTree = "<group>"; };
+               41209E91216D593C00A73A12 /* RTCCertificate.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCCertificate.idl; sourceTree = "<group>"; };
+               41209E93216D5C7900A73A12 /* RTCCertificate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RTCCertificate.h; sourceTree = "<group>"; };
+               41209E94216EA69A00A73A12 /* RTCCertificate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RTCCertificate.cpp; sourceTree = "<group>"; };
+               41209E95216EC34E00A73A12 /* LibWebRTCCertificateGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCCertificateGenerator.h; path = libwebrtc/LibWebRTCCertificateGenerator.h; sourceTree = "<group>"; };
+               41209E96216EC34F00A73A12 /* LibWebRTCCertificateGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCCertificateGenerator.cpp; path = libwebrtc/LibWebRTCCertificateGenerator.cpp; sourceTree = "<group>"; };
                4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptState.cpp; sourceTree = "<group>"; };
                4129C9801F5861C7009D7403 /* ReadableStreamSink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamSink.h; sourceTree = "<group>"; };
                4129C9811F5861C7009D7403 /* ReadableStreamSink.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamSink.idl; sourceTree = "<group>"; };
                                5E2C434D1BCEE2E50001E2BC /* PeerConnectionBackend.h */,
                                316DCB2B1E78F3A9001B5F87 /* RTCAnswerOptions.h */,
                                316DCB2C1E78F3A9001B5F87 /* RTCAnswerOptions.idl */,
+                               41209E94216EA69A00A73A12 /* RTCCertificate.cpp */,
+                               41209E93216D5C7900A73A12 /* RTCCertificate.h */,
+                               41209E91216D593C00A73A12 /* RTCCertificate.idl */,
                                07AB996518DA3C010018771E /* RTCConfiguration.h */,
                                07AB996618DA3C010018771E /* RTCConfiguration.idl */,
                                418205481E53EAAD00D62207 /* RTCController.cpp */,
                417612AA1E3A992300C3D81D /* libwebrtc */ = {
                        isa = PBXGroup;
                        children = (
+                               41209E96216EC34F00A73A12 /* LibWebRTCCertificateGenerator.cpp */,
+                               41209E95216EC34E00A73A12 /* LibWebRTCCertificateGenerator.h */,
                                5CDD833F1E43253D00621E92 /* LibWebRTCDataChannelHandler.cpp */,
                                5CDD83401E43253D00621E92 /* LibWebRTCDataChannelHandler.h */,
                                417612AB1E3A993B00C3D81D /* LibWebRTCMediaEndpoint.cpp */,
index 2226a75..fb1a5d2 100644 (file)
@@ -125,6 +125,7 @@ namespace WebCore {
     macro(PerformanceServerTiming) \
     macro(PointerEvent) \
     macro(PublicKeyCredential) \
+    macro(RTCCertificate) \
     macro(RTCDTMFSender) \
     macro(RTCDTMFToneChangeEvent) \
     macro(RTCDataChannel) \
index 551e2fa..d66ba03 100644 (file)
@@ -32,6 +32,7 @@ namespace WebCore {
 
 class CSSValue;
 class StyleResolver;
+struct CSSRegisteredCustomProperty;
 
 class StyleBuilder {
 public:
index 39925df..64e380e 100644 (file)
@@ -106,6 +106,7 @@ struct PeerConnectionFactoryAndThreads : public rtc::MessageHandler {
     std::unique_ptr<LibWebRTCAudioModule> audioDeviceModule;
     std::unique_ptr<rtc::NetworkManager> networkManager;
     std::unique_ptr<BasicPacketSocketFactory> packetSocketFactory;
+    std::unique_ptr<rtc::RTCCertificateGenerator> certificateGenerator;
 
 private:
     void OnMessage(rtc::Message*);
@@ -265,6 +266,15 @@ rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPee
     return m_factory->CreatePeerConnection(configuration, WTFMove(portAllocator), nullptr, &observer);
 }
 
+rtc::RTCCertificateGenerator& LibWebRTCProvider::certificateGenerator()
+{
+    auto& factoryAndThreads = getStaticFactoryAndThreads(m_useNetworkThreadWithSocketServer);
+    if (!factoryAndThreads.certificateGenerator)
+        factoryAndThreads.certificateGenerator = std::make_unique<rtc::RTCCertificateGenerator>(factoryAndThreads.signalingThread.get(), factoryAndThreads.networkThread.get());
+
+    return *factoryAndThreads.certificateGenerator;
+}
+
 #endif // USE(LIBWEBRTC)
 
 } // namespace WebCore
index 2f19714..d808c48 100644 (file)
@@ -47,6 +47,7 @@ namespace rtc {
 class NetworkManager;
 class PacketSocketFactory;
 class Thread;
+class RTCCertificateGenerator;
 }
 
 namespace webrtc {
@@ -111,6 +112,8 @@ public:
     void supportsVP8(bool value) { m_supportsVP8 = value; }
     virtual void disableNonLocalhostConnections() { m_disableNonLocalhostConnections = true; }
 
+    rtc::RTCCertificateGenerator& certificateGenerator();
+
 protected:
     LibWebRTCProvider() = default;