Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit b2000c4

Browse files
authored
Add support for certificates with public key algorithm ECDSA. (#64)
RSA is not allowed in WebTransport serverCertificateHash API. See Chromium change https://chromium-review.googlesource.com/c/chromium/src/+/3399288
1 parent c8328a4 commit b2000c4

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

web_transport/sdk/impl/proof_source_owt.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
namespace owt {
2525
namespace quic {
2626

27-
ProofSourceOwt::ProofSourceOwt() {}
27+
ProofSourceOwt::ProofSourceOwt()
28+
: private_key_(nullptr), ticket_crypter_(nullptr) {}
2829

2930
ProofSourceOwt::~ProofSourceOwt() {}
3031

@@ -72,7 +73,8 @@ bool ProofSourceOwt::Initialize(const base::FilePath& pfx_path,
7273
}
7374

7475
chain_ = new ::quic::ProofSource::Chain(certs_string);
75-
private_key_ = crypto::RSAPrivateKey::CreateFromKey(key);
76+
private_key_ = std::make_unique<::quic::CertificatePrivateKey>(
77+
bssl::UniquePtr<EVP_PKEY>(key));
7678
return true;
7779
}
7880

@@ -101,18 +103,19 @@ bool ProofSourceOwt::GetProofInner(
101103
::quic::QuicCryptoProof* proof) {
102104
// This function is copied from `ProofSourceChromium`, but `leaf_cert_scts` is
103105
// not set.
104-
DCHECK(proof != nullptr);
105-
DCHECK(private_key_.get()) << " this: " << this;
106+
DCHECK(proof);
107+
DCHECK(private_key_);
106108

107109
crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
108110
bssl::ScopedEVP_MD_CTX sign_context;
109111
EVP_PKEY_CTX* pkey_ctx;
110112

111113
uint32_t len_tmp = chlo_hash.length();
112114
if (!EVP_DigestSignInit(sign_context.get(), &pkey_ctx, EVP_sha256(), nullptr,
113-
private_key_->key()) ||
114-
!EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) ||
115-
!EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, -1) ||
115+
private_key_->private_key()) ||
116+
(EVP_PKEY_id(private_key_->private_key()) == EVP_PKEY_RSA &&
117+
(!EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) ||
118+
!EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, -1))) ||
116119
!EVP_DigestSignUpdate(
117120
sign_context.get(),
118121
reinterpret_cast<const uint8_t*>(::quic::kProofSignatureLabel),
@@ -198,9 +201,10 @@ void ProofSourceOwt::ComputeTlsSignature(
198201
size_t siglen;
199202
std::string sig;
200203
if (!EVP_DigestSignInit(sign_context.get(), &pkey_ctx, EVP_sha256(), nullptr,
201-
private_key_->key()) ||
202-
!EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) ||
203-
!EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, -1) ||
204+
private_key_->private_key()) ||
205+
(EVP_PKEY_id(private_key_->private_key()) == EVP_PKEY_RSA &&
206+
(!EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) ||
207+
!EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, -1))) ||
204208
!EVP_DigestSignUpdate(sign_context.get(),
205209
reinterpret_cast<const uint8_t*>(in.data()),
206210
in.size()) ||

web_transport/sdk/impl/proof_source_owt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ProofSourceOwt : public ::quic::ProofSource {
7272
out_chain,
7373
::quic::QuicCryptoProof* proof);
7474

75-
std::unique_ptr<crypto::RSAPrivateKey> private_key_;
75+
std::unique_ptr<::quic::CertificatePrivateKey> private_key_;
7676
std::vector<scoped_refptr<net::X509Certificate>> certs_in_file_;
7777
::quic::QuicReferenceCountedPointer<::quic::ProofSource::Chain> chain_;
7878
std::unique_ptr<::quic::ProofSource::TicketCrypter> ticket_crypter_;

0 commit comments

Comments
 (0)