blob: 9cb85c2d3f74956635f03cc747789c003f2da73e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "quic/core/crypto/proof_source.h"
#include <string>
#include "quic/platform/api/quic_bug_tracker.h"
namespace quic {
CryptoBuffers::~CryptoBuffers() {
for (size_t i = 0; i < value.size(); i++) {
CRYPTO_BUFFER_free(value[i]);
}
}
ProofSource::Chain::Chain(const std::vector<std::string>& certs)
: certs(certs) {}
ProofSource::Chain::~Chain() {}
CryptoBuffers ProofSource::Chain::ToCryptoBuffers() const {
CryptoBuffers crypto_buffers;
crypto_buffers.value.reserve(certs.size());
for (size_t i = 0; i < certs.size(); i++) {
crypto_buffers.value.push_back(
CRYPTO_BUFFER_new(reinterpret_cast<const uint8_t*>(certs[i].data()),
certs[i].length(), nullptr));
}
return crypto_buffers;
}
bool ValidateCertAndKey(
const QuicReferenceCountedPointer<ProofSource::Chain>& chain,
const CertificatePrivateKey& key) {
if (chain.get() == nullptr || chain->certs.empty()) {
QUIC_BUG(quic_proof_source_empty_chain) << "Certificate chain is empty";
return false;
}
std::unique_ptr<CertificateView> leaf =
CertificateView::ParseSingleCertificate(chain->certs[0]);
if (leaf == nullptr) {
QUIC_BUG(quic_proof_source_unparsable_leaf_cert)
<< "Unabled to parse leaf certificate";
return false;
}
if (!key.MatchesPublicKey(*leaf)) {
QUIC_BUG(quic_proof_source_key_mismatch)
<< "Private key does not match the leaf certificate";
return false;
}
return true;
}
} // namespace quic
|