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

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: Addressed comments 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"
65 #include "public/platform/WebCryptoUtil.h"
63 #include "public/platform/WebMediaStream.h" 66 #include "public/platform/WebMediaStream.h"
64 #include "public/platform/WebRTCCertificate.h" 67 #include "public/platform/WebRTCCertificate.h"
65 #include "public/platform/WebRTCCertificateGenerator.h" 68 #include "public/platform/WebRTCCertificateGenerator.h"
66 #include "public/platform/WebRTCConfiguration.h" 69 #include "public/platform/WebRTCConfiguration.h"
67 #include "public/platform/WebRTCDataChannelHandler.h" 70 #include "public/platform/WebRTCDataChannelHandler.h"
68 #include "public/platform/WebRTCDataChannelInit.h" 71 #include "public/platform/WebRTCDataChannelInit.h"
69 #include "public/platform/WebRTCICECandidate.h" 72 #include "public/platform/WebRTCICECandidate.h"
70 #include "public/platform/WebRTCKeyParams.h" 73 #include "public/platform/WebRTCKeyParams.h"
71 #include "public/platform/WebRTCOfferOptions.h" 74 #include "public/platform/WebRTCOfferOptions.h"
72 #include "public/platform/WebRTCSessionDescription.h" 75 #include "public/platform/WebRTCSessionDescription.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 469
467 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState); 470 WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstrai nts, exceptionState);
468 if (exceptionState.hadException()) 471 if (exceptionState.hadException())
469 return; 472 return;
470 473
471 bool valid = m_peerHandler->updateICE(configuration, constraints); 474 bool valid = m_peerHandler->updateICE(configuration, constraints);
472 if (!valid) 475 if (!valid)
473 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); 476 exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration.");
474 } 477 }
475 478
476 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst Dictionary& keygenAlgorithm, ExceptionState& exceptionState) 479 ScriptPromise RTCPeerConnection::generateCertificate(ScriptState* scriptState, c onst AlgorithmIdentifier& keygenAlgorithm, ExceptionState& exceptionState)
477 { 480 {
478 // Validate and interpret input |keygenAlgorithm|. 481 // Normalize |keygenAlgorithm| with WebCrypto, making sure it is a recognize d AlgorithmIdentifier.
479 // TODO(hbos): Use WebCrypto normalization process to validate and interpret |keygenAlgorithm|. 482 WebCryptoAlgorithm cryptoAlgorithm;
480 // This may create a dependency between the Blink and WebCrypto modules? crb ug.com/544917 483 AlgorithmError error;
484 if (!normalizeAlgorithm(keygenAlgorithm, WebCryptoOperationGenerateKey, cryp toAlgorithm, &error)) {
485 // Reject generateCertificate with the same error as was produced by Web Crypto.
486 // |result| is garbage collected, no need to delete.
487 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
488 ScriptPromise promise = result->promise();
489 result->completeWithError(error.errorType, error.errorDetails);
490 return promise;
491 }
492
493 // Convert from WebCrypto representation to recognized WebRTCKeyParams. WebR TC supports a small subset of what are valid AlgorithmIdentifiers.
494 const char* unsupportedParamsString = "The 1st argument provided is an Algor ithmIdentifier with a supported algorithm name, but the parameters are not suppo rted.";
481 Nullable<WebRTCKeyParams> keyParams; 495 Nullable<WebRTCKeyParams> keyParams;
482 String name; 496 switch (cryptoAlgorithm.id()) {
483 if (DictionaryHelper::get(keygenAlgorithm, "name", name)) { 497 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
484 if (name == "RSASSA-PKCS1-v1_5") { 498 // name: "RSASSA-PKCS1-v1_5"
485 // RSA - Supported |keygenAlgorithm|: 499 unsigned publicExponent;
486 // { name: "RSASSA-PKCS1-v1_5", modulusLength: <int>, publicExponent : 65537 } 500 // "publicExponent" must fit in an unsigned int. The only recognized "ha sh" is "SHA-256".
487 int modulusLength = -1; 501 if (bigIntegerToUint(cryptoAlgorithm.rsaHashedKeyGenParams()->publicExpo nent(), publicExponent)
488 int publicExponent = -1; 502 && cryptoAlgorithm.rsaHashedKeyGenParams()->hash().id() == WebCrypto AlgorithmIdSha256) {
489 if (DictionaryHelper::get(keygenAlgorithm, "modulusLength", modulusL ength) 503 unsigned modulusLength = cryptoAlgorithm.rsaHashedKeyGenParams()->mo dulusLengthBits();
490 && modulusLength >= 0 504 keyParams.set(blink::WebRTCKeyParams::createRSA(modulusLength, publi cExponent));
491 && DictionaryHelper::get(keygenAlgorithm, "publicExponent", publ icExponent) 505 } else {
492 && publicExponent >= 0) { 506 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(NotSupportedError, unsupportedParamsString));
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 } 507 }
508 break;
509 case WebCryptoAlgorithmIdEcdsa:
510 // name: "ECDSA"
511 // The only recognized "namedCurve" is "P-256".
512 if (cryptoAlgorithm.ecKeyGenParams()->namedCurve() == WebCryptoNamedCurv eP256) {
513 keyParams.set(blink::WebRTCKeyParams::createECDSA(blink::WebRTCECCur veNistP256));
514 } else {
515 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(NotSupportedError, unsupportedParamsString));
516 }
517 break;
518 default:
519 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError, "The 1st argument provided is an AlgorithmIdentifier, but the algorithm is not supported."));
520 break;
504 } 521 }
505 if (keyParams.isNull()) { 522 ASSERT(!keyParams.isNull());
506 // Invalid argument.
507 return ScriptPromise::rejectWithDOMException(
508 scriptState, DOMException::create(InvalidAccessError, ExceptionMessa ges::argumentNullOrIncorrectType(1, "AlgorithmIdentifier")));
509 }
510 523
511 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr( 524 OwnPtr<WebRTCCertificateGenerator> certificateGenerator = adoptPtr(
512 Platform::current()->createRTCCertificateGenerator()); 525 Platform::current()->createRTCCertificateGenerator());
513 526
514 // Check validity of |keyParams|. 527 // |keyParams| was successfully constructed, but does the certificate genera tor support these parameters?
515 if (!certificateGenerator->isValidKeyParams(keyParams.get())) { 528 if (!certificateGenerator->isSupportedKeyParams(keyParams.get())) {
516 return ScriptPromise::rejectWithDOMException( 529 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError, unsupportedParamsString));
517 scriptState, DOMException::create(NotSupportedError, "The 1st argume nt provided is an AlgorithmIdentifier, but it has unsupported parameter values." ));
518 } 530 }
519 531
520 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 532 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
521 ScriptPromise promise = resolver->promise(); 533 ScriptPromise promise = resolver->promise();
522 534
523 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: create(resolver); 535 WebRTCCertificateObserver* certificateObserver = WebRTCCertificateObserver:: create(resolver);
524 536
525 // Generate certificate. The |certificateObserver| will resolve the promise asynchronously upon completion. 537 // 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. 538 // The observer will manage its own destruction as well as the resolver's de struction.
527 certificateGenerator->generateCertificate( 539 certificateGenerator->generateCertificate(
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 { 981 {
970 visitor->trace(m_localStreams); 982 visitor->trace(m_localStreams);
971 visitor->trace(m_remoteStreams); 983 visitor->trace(m_remoteStreams);
972 visitor->trace(m_dataChannels); 984 visitor->trace(m_dataChannels);
973 visitor->trace(m_scheduledEvents); 985 visitor->trace(m_scheduledEvents);
974 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor); 986 RefCountedGarbageCollectedEventTargetWithInlineData<RTCPeerConnection>::trac e(visitor);
975 ActiveDOMObject::trace(visitor); 987 ActiveDOMObject::trace(visitor);
976 } 988 }
977 989
978 } // namespace blink 990 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698