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