Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1710)

Unified Diff: Source/modules/mediastream/RTCPeerConnection.cpp

Issue 1311853005: RTCCertificate and RTCPeerConnection.generateCertificate added to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code cleanup, added comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/mediastream/RTCPeerConnection.cpp
diff --git a/Source/modules/mediastream/RTCPeerConnection.cpp b/Source/modules/mediastream/RTCPeerConnection.cpp
index b3ae4317d8a5817b673b7bd3035222e7243f6680..48fe31b065c3eba5d76a92cb2806d6bb63fa5116 100644
--- a/Source/modules/mediastream/RTCPeerConnection.cpp
+++ b/Source/modules/mediastream/RTCPeerConnection.cpp
@@ -34,6 +34,8 @@
#include "bindings/core/v8/ArrayValue.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/modules/v8/V8RTCCertificate.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
@@ -195,6 +197,29 @@ RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config
}
}
+ ArrayValue certificates;
+ if (DictionaryHelper::get(configuration, "certificates", certificates)
+ && !certificates.isUndefinedOrNull()) {
+ size_t numberOfCertificates;
+ certificates.length(numberOfCertificates);
+ for (size_t i = 0; i < numberOfCertificates; ++i) {
+ RTCCertificate* certificate = nullptr;
+
+ Dictionary dictCert;
+ certificates.get(i, dictCert);
+ v8::Local<v8::Value> valCert = dictCert.v8Value();
+ if (!valCert.IsEmpty()) {
+ certificate = V8RTCCertificate::toImplWithTypeCheck(configuration.isolate(), valCert);
+ }
+ if (!certificate) {
+ exceptionState.throwTypeError("Malformed sequence<RTCCertificate>");
+ return 0;
+ }
+
+ rtcConfiguration->appendCertificate(certificate->certificate()->shallowCopy());
+ }
+ }
+
return rtcConfiguration;
}
@@ -399,6 +424,83 @@ void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dict
exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration.");
}
+// The observer deletes itself upon generation complete. Keeps |m_resolver| alive until destruction.
+static class GenerateRTCCertificateObserver : public WebRTCCertificateObserver {
+public:
+ GenerateRTCCertificateObserver(ScriptPromiseResolver* resolver)
Guido Urdaneta 2015/09/03 11:07:49 Constructor should be private and you should have
hbos_chromium 2015/09/03 16:01:37 Done.
+ : m_resolver(resolver)
+ {
+ }
+
+ ~GenerateRTCCertificateObserver() override
+ {
+ }
+
+ DEFINE_INLINE_TRACE() { visitor->trace(m_resolver); }
+
+private:
+ void onGenerateComplete(WebRTCCertificate* certificate) override
+ {
+ m_resolver->resolve(certificate ? new RTCCertificate(certificate) : nullptr);
+ delete this;
+ }
+
+ Persistent<ScriptPromiseResolver> m_resolver;
+};
+
+ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, const Dictionary& keygenAlgorithm, ExceptionState& exceptionState)
+{
+ // Validate and interpret input |keygenAlgorithm|.
+ // The value |keyType| corresponds to the rtc::KeyType in libjingle.
+ int keyType = -1;
+ String name;
+ if (DictionaryHelper::get(keygenAlgorithm, "name", name)) {
+ if (name == "RSASSA-PKCS1-v1_5") {
+ // RSA - Supported |keygenAlgorithm|:
+ // { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: 65537 }
+ // { name: "RSASSA-PKCS1-v1_5", modulusLength: 1024, publicExponent: 65537 } (not a MUST in specification, but the one actually being used)
+ // TODO(hbos): Use modulusLength and not the default (1024).
+ int modulusLength = -1;
+ DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusLength);
+ int publicExponent = -1;
+ DictionaryHelper::get(keygenAlgorithm, "publicExponent", publicExponent);
+ if ((modulusLength == 2048 || modulusLength == 1024) && publicExponent == 65537) {
+ keyType = 0;
+ }
+ } else if (name == "ECDSA") {
+ // ECDSA - Supported |keygenAlgorithm|:
+ // { name: "ECDSA", namedCurve: "P-256" }
+ String namedCurve;
+ DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve);
+ if (namedCurve == "P-256") {
+ keyType = 1;
+ }
+ }
+ }
+ if (keyType == -1) {
+ // Invalid argument.
+ return ScriptPromise::rejectWithDOMException(
+ scriptState, DOMException::create(InvalidAccessError, ExceptionMessages::argumentNullOrIncorrectType(1, "AlgorithmIdentifier")));
+ }
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ GenerateRTCCertificateObserver* certificateObserver = new GenerateRTCCertificateObserver(resolver);
+
+ // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon generate completion.
+ // The observer will manage its own and the resolver's destruction as well.
+ WebRTCCertificateGenerator* certificateGenerator = Platform::current()->createRTCCertificateGenerator();
+ certificateGenerator->generateCertificate(
+ keyType,
+ toDocument(scriptState->executionContext())->url(),
+ toDocument(scriptState->executionContext())->firstPartyForCookies(),
+ certificateObserver);
+ delete certificateGenerator;
Guido Urdaneta 2015/09/03 11:07:49 Is it safe to delete |certificateGenerator| here?
hbos_chromium 2015/09/03 16:01:37 Yes the object need only live for the generateCert
+
+ return promise;
+}
+
void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, ExceptionState& exceptionState)
{
if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))

Powered by Google App Engine
This is Rietveld 408576698