Commit e79bd298 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Use rtc::KeyParams over blink::WebRTCKeyParams

The later is a 1:1 wrapper to the former, and now that
the WebRTC feature is Onion soup'ed, the use of third_party/webrtc
types is preferred.

BUG=787254, 919392
R=guidou@chromium.org, haraken@chromium.org

Change-Id: I22853ca19e1fe67a95a8508a2bbb7b3ad25ec17a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884473
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712080}
parent 75cd80f8
......@@ -287,7 +287,6 @@ source_set("blink_headers") {
"platform/web_rtc_dtmf_sender_handler.h",
"platform/web_rtc_dtmf_sender_handler_client.h",
"platform/web_rtc_ice_candidate.h",
"platform/web_rtc_key_params.h",
"platform/web_rtc_legacy_stats.h",
"platform/web_rtc_offer_options.h",
"platform/web_rtc_peer_connection_handler.h",
......
/*
* Copyright (C) 2015 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_RTC_KEY_PARAMS_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_RTC_KEY_PARAMS_H_
#include "base/logging.h"
#include "third_party/blink/public/platform/web_common.h"
namespace blink {
// Corresponds to rtc::KeyType in WebRTC.
enum WebRTCKeyType {
kWebRTCKeyTypeRSA,
kWebRTCKeyTypeECDSA,
kWebRTCKeyTypeNull
};
// Corresponds to rtc::RSAParams in WebRTC.
struct WebRTCRSAParams {
unsigned mod_length;
unsigned pub_exp;
};
// Corresponds to rtc::ECCurve in WebRTC.
enum WebRTCECCurve { kWebRTCECCurveNistP256 };
// Corresponds to rtc::KeyParams in WebRTC.
class WebRTCKeyParams {
public:
static WebRTCKeyParams CreateRSA(unsigned mod_length, unsigned pub_exp) {
WebRTCKeyParams key_params(kWebRTCKeyTypeRSA);
key_params.params_.rsa.mod_length = mod_length;
key_params.params_.rsa.pub_exp = pub_exp;
return key_params;
}
static WebRTCKeyParams CreateECDSA(WebRTCECCurve curve) {
WebRTCKeyParams key_params(kWebRTCKeyTypeECDSA);
key_params.params_.ec_curve = curve;
return key_params;
}
WebRTCKeyParams() : WebRTCKeyParams(kWebRTCKeyTypeNull) {}
WebRTCKeyType KeyType() const { return key_type_; }
WebRTCRSAParams RsaParams() const {
DCHECK_EQ(key_type_, kWebRTCKeyTypeRSA);
return params_.rsa;
}
WebRTCECCurve EcCurve() const {
DCHECK_EQ(key_type_, kWebRTCKeyTypeECDSA);
return params_.ec_curve;
}
private:
WebRTCKeyParams(WebRTCKeyType key_type) : key_type_(key_type) {}
WebRTCKeyType key_type_;
union {
WebRTCRSAParams rsa;
WebRTCECCurve ec_curve;
} params_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_RTC_KEY_PARAMS_H_
......@@ -19,21 +19,6 @@
namespace blink {
namespace {
rtc::KeyParams WebRTCKeyParamsToKeyParams(
const blink::WebRTCKeyParams& key_params) {
switch (key_params.KeyType()) {
case blink::kWebRTCKeyTypeRSA:
return rtc::KeyParams::RSA(key_params.RsaParams().mod_length,
key_params.RsaParams().pub_exp);
case blink::kWebRTCKeyTypeECDSA:
return rtc::KeyParams::ECDSA(
static_cast<rtc::ECCurve>(key_params.EcCurve()));
default:
NOTREACHED();
return rtc::KeyParams();
}
}
// A certificate generation request spawned by
// |GenerateCertificateWithOptionalExpiration|. This
// is handled by a separate class so that reference counting can keep the
......@@ -50,7 +35,7 @@ class RTCCertificateGeneratorRequest
}
void GenerateCertificateAsync(
const blink::WebRTCKeyParams& key_params,
const rtc::KeyParams& key_params,
const absl::optional<uint64_t>& expires_ms,
blink::RTCCertificateCallback completion_callback) {
DCHECK(main_thread_->BelongsToCurrentThread());
......@@ -68,14 +53,14 @@ class RTCCertificateGeneratorRequest
~RTCCertificateGeneratorRequest() {}
void GenerateCertificateOnWorkerThread(
const blink::WebRTCKeyParams key_params,
const rtc::KeyParams key_params,
const absl::optional<uint64_t> expires_ms,
blink::RTCCertificateCallback completion_callback) {
DCHECK(worker_thread_->BelongsToCurrentThread());
rtc::scoped_refptr<rtc::RTCCertificate> certificate =
rtc::RTCCertificateGenerator::GenerateCertificate(
WebRTCKeyParamsToKeyParams(key_params), expires_ms);
rtc::RTCCertificateGenerator::GenerateCertificate(key_params,
expires_ms);
main_thread_->PostTask(
FROM_HERE,
......@@ -98,11 +83,11 @@ class RTCCertificateGeneratorRequest
};
void GenerateCertificateWithOptionalExpiration(
const blink::WebRTCKeyParams& key_params,
const rtc::KeyParams& key_params,
const absl::optional<uint64_t>& expires_ms,
blink::RTCCertificateCallback completion_callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK(WebRTCKeyParamsToKeyParams(key_params).IsValid());
DCHECK(key_params.IsValid());
auto* pc_dependency_factory =
blink::PeerConnectionDependencyFactory::GetInstance();
pc_dependency_factory->EnsureInitialized();
......@@ -117,7 +102,7 @@ void GenerateCertificateWithOptionalExpiration(
} // namespace
void RTCCertificateGenerator::GenerateCertificate(
const blink::WebRTCKeyParams& key_params,
const rtc::KeyParams& key_params,
blink::RTCCertificateCallback completion_callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
GenerateCertificateWithOptionalExpiration(
......@@ -125,7 +110,7 @@ void RTCCertificateGenerator::GenerateCertificate(
}
void RTCCertificateGenerator::GenerateCertificateWithExpiration(
const blink::WebRTCKeyParams& key_params,
const rtc::KeyParams& key_params,
uint64_t expires_ms,
blink::RTCCertificateCallback completion_callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
......@@ -134,8 +119,8 @@ void RTCCertificateGenerator::GenerateCertificateWithExpiration(
}
bool RTCCertificateGenerator::IsSupportedKeyParams(
const blink::WebRTCKeyParams& key_params) {
return WebRTCKeyParamsToKeyParams(key_params).IsValid();
const rtc::KeyParams& key_params) {
return key_params.IsValid();
}
rtc::scoped_refptr<rtc::RTCCertificate> RTCCertificateGenerator::FromPEM(
......
......@@ -8,7 +8,6 @@
#include <memory>
#include "base/macros.h"
#include "third_party/blink/public/platform/web_rtc_key_params.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/webrtc/api/peer_connection_interface.h"
......@@ -34,11 +33,11 @@ class MODULES_EXPORT RTCCertificateGenerator {
// same thread that called generateCertificate when the operation is
// completed.
void GenerateCertificate(
const blink::WebRTCKeyParams& key_params,
const rtc::KeyParams& key_params,
blink::RTCCertificateCallback completion_callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
void GenerateCertificateWithExpiration(
const blink::WebRTCKeyParams& key_params,
const rtc::KeyParams& key_params,
uint64_t expires_ms,
blink::RTCCertificateCallback completion_callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
......@@ -46,7 +45,7 @@ class MODULES_EXPORT RTCCertificateGenerator {
// Determines if the parameters are supported by |GenerateCertificate|.
// For example, if the number of bits of some parameter is too small or too
// large we may want to reject it for security or performance reasons.
bool IsSupportedKeyParams(const blink::WebRTCKeyParams& key_params);
bool IsSupportedKeyParams(const rtc::KeyParams& key_params);
// Creates a certificate from the PEM strings. See also
// |rtc::RTCCertificate::ToPEM|.
......
......@@ -48,7 +48,6 @@
#include "third_party/blink/public/platform/web_rtc_answer_options.h"
#include "third_party/blink/public/platform/web_rtc_data_channel_init.h"
#include "third_party/blink/public/platform/web_rtc_ice_candidate.h"
#include "third_party/blink/public/platform/web_rtc_key_params.h"
#include "third_party/blink/public/platform/web_rtc_offer_options.h"
#include "third_party/blink/public/platform/web_rtc_session_description.h"
#include "third_party/blink/public/platform/web_rtc_session_description_request.h"
......@@ -129,6 +128,7 @@
#include "third_party/webrtc/api/jsep.h"
#include "third_party/webrtc/api/peer_connection_interface.h"
#include "third_party/webrtc/pc/session_description.h"
#include "third_party/webrtc/rtc_base/ssl_identity.h"
namespace blink {
......@@ -1659,7 +1659,7 @@ ScriptPromise RTCPeerConnection::generateCertificate(
const char* unsupported_params_string =
"The 1st argument provided is an AlgorithmIdentifier with a supported "
"algorithm name, but the parameters are not supported.";
base::Optional<WebRTCKeyParams> key_params;
base::Optional<rtc::KeyParams> key_params;
switch (crypto_algorithm.Id()) {
case kWebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
// name: "RSASSA-PKCS1-v1_5"
......@@ -1672,8 +1672,7 @@ ScriptPromise RTCPeerConnection::generateCertificate(
kWebCryptoAlgorithmIdSha256) {
unsigned modulus_length =
crypto_algorithm.RsaHashedKeyGenParams()->ModulusLengthBits();
key_params =
WebRTCKeyParams::CreateRSA(modulus_length, public_exponent);
key_params = rtc::KeyParams::RSA(modulus_length, public_exponent);
} else {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
......@@ -1686,7 +1685,7 @@ ScriptPromise RTCPeerConnection::generateCertificate(
// The only recognized "namedCurve" is "P-256".
if (crypto_algorithm.EcKeyGenParams()->NamedCurve() ==
kWebCryptoNamedCurveP256) {
key_params = WebRTCKeyParams::CreateECDSA(kWebRTCECCurveNistP256);
key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256);
} else {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment