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

Side by Side Diff: third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp

Issue 1418113002: RTCPeerConnection.generateCertificate taking AlgorithmIdentifier and using WebCrypto (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hello, WebCrypto Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 26 matching lines...) Expand all
37 #include "bindings/core/v8/Nullable.h" 37 #include "bindings/core/v8/Nullable.h"
38 #include "bindings/core/v8/ScriptPromiseResolver.h" 38 #include "bindings/core/v8/ScriptPromiseResolver.h"
39 #include "bindings/modules/v8/V8RTCCertificate.h" 39 #include "bindings/modules/v8/V8RTCCertificate.h"
40 #include "core/dom/Document.h" 40 #include "core/dom/Document.h"
41 #include "core/dom/ExceptionCode.h" 41 #include "core/dom/ExceptionCode.h"
42 #include "core/dom/ExecutionContext.h" 42 #include "core/dom/ExecutionContext.h"
43 #include "core/frame/LocalFrame.h" 43 #include "core/frame/LocalFrame.h"
44 #include "core/html/VoidCallback.h" 44 #include "core/html/VoidCallback.h"
45 #include "core/loader/FrameLoader.h" 45 #include "core/loader/FrameLoader.h"
46 #include "core/loader/FrameLoaderClient.h" 46 #include "core/loader/FrameLoaderClient.h"
47 #include "modules/crypto/CryptoResultImpl.h"
47 #include "modules/mediastream/MediaConstraintsImpl.h" 48 #include "modules/mediastream/MediaConstraintsImpl.h"
48 #include "modules/mediastream/MediaStreamEvent.h" 49 #include "modules/mediastream/MediaStreamEvent.h"
49 #include "modules/mediastream/RTCDTMFSender.h" 50 #include "modules/mediastream/RTCDTMFSender.h"
50 #include "modules/mediastream/RTCDataChannel.h" 51 #include "modules/mediastream/RTCDataChannel.h"
51 #include "modules/mediastream/RTCDataChannelEvent.h" 52 #include "modules/mediastream/RTCDataChannelEvent.h"
52 #include "modules/mediastream/RTCErrorCallback.h" 53 #include "modules/mediastream/RTCErrorCallback.h"
53 #include "modules/mediastream/RTCIceCandidateEvent.h" 54 #include "modules/mediastream/RTCIceCandidateEvent.h"
54 #include "modules/mediastream/RTCSessionDescription.h" 55 #include "modules/mediastream/RTCSessionDescription.h"
55 #include "modules/mediastream/RTCSessionDescriptionCallback.h" 56 #include "modules/mediastream/RTCSessionDescriptionCallback.h"
56 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h" 57 #include "modules/mediastream/RTCSessionDescriptionRequestImpl.h"
57 #include "modules/mediastream/RTCStatsCallback.h" 58 #include "modules/mediastream/RTCStatsCallback.h"
58 #include "modules/mediastream/RTCStatsRequestImpl.h" 59 #include "modules/mediastream/RTCStatsRequestImpl.h"
59 #include "modules/mediastream/RTCVoidRequestImpl.h" 60 #include "modules/mediastream/RTCVoidRequestImpl.h"
60 #include "platform/mediastream/RTCConfiguration.h" 61 #include "platform/mediastream/RTCConfiguration.h"
61 #include "platform/mediastream/RTCOfferOptions.h" 62 #include "platform/mediastream/RTCOfferOptions.h"
62 #include "public/platform/Platform.h" 63 #include "public/platform/Platform.h"
64 #include "public/platform/WebCryptoAlgorithmParams.h"
63 #include "public/platform/WebMediaStream.h" 65 #include "public/platform/WebMediaStream.h"
64 #include "public/platform/WebRTCCertificate.h" 66 #include "public/platform/WebRTCCertificate.h"
65 #include "public/platform/WebRTCCertificateGenerator.h" 67 #include "public/platform/WebRTCCertificateGenerator.h"
66 #include "public/platform/WebRTCConfiguration.h" 68 #include "public/platform/WebRTCConfiguration.h"
67 #include "public/platform/WebRTCDataChannelHandler.h" 69 #include "public/platform/WebRTCDataChannelHandler.h"
68 #include "public/platform/WebRTCDataChannelInit.h" 70 #include "public/platform/WebRTCDataChannelInit.h"
69 #include "public/platform/WebRTCICECandidate.h" 71 #include "public/platform/WebRTCICECandidate.h"
70 #include "public/platform/WebRTCKeyParams.h" 72 #include "public/platform/WebRTCKeyParams.h"
71 #include "public/platform/WebRTCOfferOptions.h" 73 #include "public/platform/WebRTCOfferOptions.h"
72 #include "public/platform/WebRTCSessionDescription.h" 74 #include "public/platform/WebRTCSessionDescription.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 117
116 void onError() override 118 void onError() override
117 { 119 {
118 m_resolver->reject(); 120 m_resolver->reject();
119 delete this; 121 delete this;
120 } 122 }
121 123
122 Persistent<ScriptPromiseResolver> m_resolver; 124 Persistent<ScriptPromiseResolver> m_resolver;
123 }; 125 };
124 126
127 static bool uint8ArrayToUint32(const WebVector<uint8_t>& exponentBytes, uint32_t * out)
128 {
129 if (exponentBytes.size() > 4) {
130 // |exponentBytes| is of minimal typed array length (at most 7 leading z ero bits for non-zero values) so there
eroman 2015/10/22 17:38:34 This implementation is not in line with the WebCry
hta - Chromium 2015/10/23 06:55:00 won't it have to be a change (at least a suggested
hbos_chromium 2015/10/23 09:59:05 @eroman: Ah I misinterpreted that piece of WebCryp
eroman 2015/10/23 19:13:03 @hta: Does not require any spec changes, just addi
eroman 2015/10/23 19:15:52 Oh actually, I withdraw the request to do that ref
hbos_chromium 2015/10/26 13:21:32 Done.
131 // is no need to check for leading 0-bytes. Thus exponentBytes.size() > 4 values do not fit in uint32_t.
132 return false;
133 }
134 // Big-endian: exponentBytes[0] is the most significant byte.
135 *out = 0;
136 for (size_t i = exponentBytes.size(), shift = 0; i-- > 0; shift += 8)
137 *out += (exponentBytes[i] << shift);
138 return true;
139 }
140
125 } // namespace 141 } // namespace
126 142
127 RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config uration, ExceptionState& exceptionState) 143 RTCConfiguration* RTCPeerConnection::parseConfiguration(const Dictionary& config uration, ExceptionState& exceptionState)
128 { 144 {
129 if (configuration.isUndefinedOrNull()) 145 if (configuration.isUndefinedOrNull())
130 return 0; 146 return 0;
131 147
132 RTCIceTransports iceTransports = RTCIceTransportsAll; 148 RTCIceTransports iceTransports = RTCIceTransportsAll;
133 String iceTransportsString; 149 String iceTransportsString;
134 if (DictionaryHelper::get(configuration, "iceTransports", iceTransportsStrin g)) { 150 if (DictionaryHelper::get(configuration, "iceTransports", iceTransportsStrin g)) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 482
467 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); 483 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState);
468 if (exceptionState.hadException()) 484 if (exceptionState.hadException())
469 return; 485 return;
470 486
471 bool valid = m_peerHandler->updateICE(configuration, constraints); 487 bool valid = m_peerHandler->updateICE(configuration, constraints);
472 if (!valid) 488 if (!valid)
473 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); 489 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration.");
474 } 490 }
475 491
476 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState) 492 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst AlgorithmIdentifier& keygenAlgorithm, ExceptionState& exceptionState)
477 { 493 {
478 // Validate and interpret input |keygenAlgorithm|. 494 // Normalize |keygenAlgorithm| with WebCrypto, making sure it is a recognize d AlgorithmIdentifier.
479 // TODO(hbos): Use WebCrypto normalization process to validate and interpret |keygenAlgorithm|. 495 WebCryptoAlgorithm cryptoAlgorithm;
480 // This may create a dependency between the Blink and WebCrypto modules? crb ug.com/544917 496 AlgorithmError error;
497 if (!normalizeAlgorithm(keygenAlgorithm, WebCryptoOperationGenerateKey, cryp toAlgorithm, &error)) {
498 // Reject generateCertificate with the same error as was produced by Web Crypto.
499 // |result| is garbage collected, no need to delete.
500 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
501 ScriptPromise promise = result->promise();
502 result->completeWithError(error.errorType, error.errorDetails);
503 return promise;
504 }
505
506 // Convert from WebCrypto representation to recognized WebRTCKeyParams. WebR TC supports a small subset of what are valid AlgorithmIdentifiers.
481 Nullable<WebRTCKeyParams> keyParams; 507 Nullable<WebRTCKeyParams> keyParams;
482 String name; 508 switch (cryptoAlgorithm.id()) {
483 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) { 509 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
484 if (name == "RSASSA-PKCS1-v1_5") { 510 // name: "RSASSA-PKCS1-v1_5"
485 // RSA - Supported |keygenAlgorithm|: 511 uint32_t publicExponent;
486 // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent : 65537 } 512 // "publicExponent" must fit in a uint32_t.
487 int modulusLength = -1; 513 // The only recognized "hash" is "SHA-256".
488 int publicExponent = -1; 514 if (uint8ArrayToUint32(cryptoAlgorithm.rsaHashedKeyGenParams()->publicEx ponent(), &publicExponent)
eroman 2015/10/22 17:38:34 nit: extract cryptoAlgorithm.rsaHashedKeyGenParams
hbos_chromium 2015/10/23 09:59:05 Acknowledged. With publicExponentToUint32 it's now
489 if (DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusL ength) 515 && cryptoAlgorithm.rsaHashedKeyGenParams()->hash().id() == WebCrypto AlgorithmIdSha256) {
490 && modulusLength >= 0 516 unsigned modulusLength = cryptoAlgorithm.rsaHashedKeyGenParams()->mo dulusLengthBits();
491 && DictionaryHelper::get(keygenAlgorithm, "publicExponent", publ icExponent) 517 keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, publi cExponent));
492 && publicExponent >= 0) {
493 keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, p ublicExponent));
494 }
495 } else if (name == "ECDSA") {
496 // ECDSA - Supported |keygenAlgorithm|:
497 // { name: "ECDSA", namedCurve: "P-256" }
498 String namedCurve;
499 DictionaryHelper::get(keygenAlgorithm, "namedCurve", namedCurve);
500 if (namedCurve == "P-256") {
501 keyParams.set(blink::WebRTCKeyParams::createECDSA(WebRTCECCurveN istP256));
502 }
503 } 518 }
hta - Chromium 2015/10/23 06:55:00 More readable to reject the promise from the hidde
hbos_chromium 2015/10/23 09:59:05 Done.
504 } 519 break;
505 if (keyParams.isNull()) { 520 case WebCryptoAlgorithmIdEcdsa:
506 // Invalid argument. 521 // name: "ECDSA"
507 return ScriptPromise::rejectWithDOMException( 522 // The only recognized "namedCurve" is "P-256".
508 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier"))); 523 if (cryptoAlgorithm.ecKeyGenParams()->namedCurve() == WebCryptoNamedCurv eP256) {
524 keyParams.set(blink::WebRTCKeyParams::createECDSA(blink::WebRTCECCur veNistP256));
525 }
526 break;
527 default:
528 break;
hta - Chromium 2015/10/23 06:55:00 More readable to reject straight from here.
hbos_chromium 2015/10/23 09:59:05 Done.
509 } 529 }
510 530
511 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( 531 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr(
512 Platform::current()->createRTCCertificateGenerator()); 532 Platform::current()->createRTCCertificateGenerator());
513 533
514 // Check validity of |keyParams|. 534 // If |keyParams| is null the AlgorithmIdentifier is unrecognized by WebRTC, if isValidKeyParams it is recognized but the parameters unsupported or invalid.
515 if (!certificateGenerator->isValidKeyParams(keyParams.get())) { 535 if (keyParams.isNull() || !certificateGenerator->isValidKeyParams(keyParams. get())) {
516 return ScriptPromise::rejectWithDOMException( 536 return ScriptPromise::rejectWithDOMException(
517 scriptState, DOMException::create(NotSupportedError, "The 1st argume nt provided is an AlgorithmIdentifier, but it has unsupported parameter values." )); 537 scriptState, DOMException::create(NotSupportedError, "The 1st argume nt provided is an AlgorithmIdentifier, but the algorithm or parameters specified are not supported."));
hta - Chromium 2015/10/23 06:55:00 You can do better (and more readable) by moving th
hbos_chromium 2015/10/23 09:59:05 Done.
518 } 538 }
519 539
520 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 540 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
521 ScriptPromise promise = resolver->promise(); 541 ScriptPromise promise = resolver->promise();
522 542
523 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: create(resolver); 543 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: create(resolver);
524 544
525 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon completion. 545 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon completion.
526 // The observer will manage its own destruction as well as the resolver's de struction. 546 // The observer will manage its own destruction as well as the resolver's de struction as well.
hta - Chromium 2015/10/23 06:55:00 Grammar nit: Delete the last "as well".
hbos_chromium 2015/10/23 09:59:05 Oops.
527 certificateGenerator->generateCertificate( 547 certificateGenerator->generateCertificate(
528 keyParams.get(), 548 keyParams.get(),
529 toDocument(scriptState->executionContext())->url(), 549 toDocument(scriptState->executionContext())->url(),
530 toDocument(scriptState->executionContext())->firstPartyForCookies(), 550 toDocument(scriptState->executionContext())->firstPartyForCookies(),
531 certificateObserver); 551 certificateObserver);
532 552
533 return promise; 553 return promise;
534 } 554 }
535 555
536 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState) 556 void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, Exception State& exceptionState)
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 { 989 {
970 visitor->trace(m_localStreams); 990 visitor->trace(m_localStreams);
971 visitor->trace(m_remoteStreams); 991 visitor->trace(m_remoteStreams);
972 visitor->trace(m_dataChannels); 992 visitor->trace(m_dataChannels);
973 visitor->trace(m_scheduledEvents); 993 visitor->trace(m_scheduledEvents);
974 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); 994 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor);
975 ActiveDOMObject::trace(visitor); 995 ActiveDOMObject::trace(visitor);
976 } 996 }
977 997
978 } // namespace blink 998 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698