/* * Copyright 2020 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMStrings(
absl::string_view private_key,
absl::string_view certificate) {
std::unique_ptr<BoringSSLCertificate> cert(
BoringSSLCertificate::FromPEMString(certificate)); if (!cert) {
RTC_LOG(LS_ERROR)
<< "Failed to create BoringSSLCertificate from PEM string."; return nullptr;
}
auto key_pair = OpenSSLKeyPair::FromPrivateKeyPEMString(private_key); if (!key_pair) {
RTC_LOG(LS_ERROR) << "Failed to create key pair from PEM string."; return nullptr;
}
return absl::WrapUnique( new BoringSSLIdentity(std::move(key_pair), std::move(cert)));
}
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMChainStrings(
absl::string_view private_key,
absl::string_view certificate_chain) {
bssl::UniquePtr<BIO> bio(
BIO_new_mem_buf(certificate_chain.data(),
rtc::dchecked_cast<int>(certificate_chain.size()))); if (!bio) { return nullptr;
}
BIO_set_mem_eof_return(bio.get(), 0);
std::vector<std::unique_ptr<SSLCertificate>> certs; while (true) { char* name; char* header; unsignedchar* data; long len; // NOLINT int ret = PEM_read_bio(bio.get(), &name, &header, &data, &len); if (ret == 0) {
uint32_t err = ERR_peek_error(); if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
err = ERR_get_error(); break;
}
RTC_LOG(LS_ERROR) << "Failed to parse certificate from PEM string."; return nullptr;
}
bssl::UniquePtr<char> owned_name(name);
bssl::UniquePtr<char> owned_header(header);
bssl::UniquePtr<unsignedchar> owned_data(data); if (strcmp(owned_name.get(), PEM_STRING_X509) != 0) {
RTC_LOG(LS_ERROR)
<< "Non-certificate found while parsing certificate chain: "
<< owned_name.get(); return nullptr;
}
bssl::UniquePtr<CRYPTO_BUFFER> crypto_buffer(
CRYPTO_BUFFER_new(data, len, openssl::GetBufferPool())); if (!crypto_buffer) { return nullptr;
}
certs.emplace_back(new BoringSSLCertificate(std::move(crypto_buffer)));
} if (certs.empty()) {
RTC_LOG(LS_ERROR) << "Found no certificates in PEM string."; return nullptr;
}
auto key_pair = OpenSSLKeyPair::FromPrivateKeyPEMString(private_key); if (!key_pair) {
RTC_LOG(LS_ERROR) << "Failed to create key pair from PEM string."; return nullptr;
}
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CloneInternal() const { // We cannot use std::make_unique here because the referenced // BoringSSLIdentity constructor is private. return absl::WrapUnique( new BoringSSLIdentity(key_pair_->Clone(), cert_chain_->Clone()));
}
bool BoringSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) {
std::vector<CRYPTO_BUFFER*> cert_buffers; for (size_t i = 0; i < cert_chain_->GetSize(); ++i) {
cert_buffers.push_back( static_cast<const BoringSSLCertificate*>(&cert_chain_->Get(i))
->cert_buffer());
} // 1 is the documented success return code. if (1 != SSL_CTX_set_chain_and_key(ctx, &cert_buffers[0], cert_buffers.size(),
key_pair_->pkey(), nullptr)) {
openssl::LogSSLErrors("Configuring key and certificate"); returnfalse;
} returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.