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