blob: dd183c283a6293ff05b3659ebd2d0b11e306df42 [file] [log] [blame]
Benjamin Wrightd6f86e82018-05-08 20:12:251/*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef RTC_BASE_OPENSSL_UTILITY_H_
12#define RTC_BASE_OPENSSL_UTILITY_H_
Benjamin Wrightd6f86e82018-05-08 20:12:2513
14#include <openssl/ossl_typ.h>
Jonas Olssona4d87372019-07-05 17:08:3315
Benjamin Wrightd6f86e82018-05-08 20:12:2516#include <string>
Benjamin Wrightd6f86e82018-05-08 20:12:2517
Ali Tofigh7fa90572022-03-17 14:47:4918#include "absl/strings/string_view.h"
19
Benjamin Wrightd6f86e82018-05-08 20:12:2520namespace rtc {
21// The openssl namespace holds static helper methods. All methods related
22// to OpenSSL that are commonly used and don't require global state should be
23// placed here.
24namespace openssl {
Taylor Brandstetter165c6182020-12-11 00:23:0325
26#ifdef OPENSSL_IS_BORINGSSL
27// Does minimal parsing of a certificate (only verifying the presence of major
28// fields), primarily for the purpose of extracting the relevant out
29// parameters. Any that the caller is uninterested in can be null.
30bool ParseCertificate(CRYPTO_BUFFER* cert_buffer,
31 CBS* signature_algorithm_oid,
32 int64_t* expiration_time);
33#endif
34
Benjamin Wrightd6f86e82018-05-08 20:12:2535// Verifies that the hostname provided matches that in the peer certificate
36// attached to this SSL state.
Taylor Brandstetter165c6182020-12-11 00:23:0337// TODO(crbug.com/webrtc/11710): When OS certificate verification is available,
38// skip compiling this as it adds a dependency on OpenSSL X509 objects, which we
39// are trying to avoid in favor of CRYPTO_BUFFERs (see crbug.com/webrtc/11410).
Ali Tofigh7fa90572022-03-17 14:47:4940bool VerifyPeerCertMatchesHost(SSL* ssl, absl::string_view host);
Benjamin Wrightd6f86e82018-05-08 20:12:2541
42// Logs all the errors in the OpenSSL errror queue from the current thread. A
43// prefix can be provided for context.
Ali Tofigh7fa90572022-03-17 14:47:4944void LogSSLErrors(absl::string_view prefix);
Benjamin Wrightd6f86e82018-05-08 20:12:2545
Mirko Bonadeib889a202018-08-15 09:41:2746#ifndef WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS
Benjamin Wrightd6f86e82018-05-08 20:12:2547// Attempt to add the certificates from the loader into the SSL_CTX. False is
48// returned only if there are no certificates returned from the loader or none
49// of them can be added to the TrustStore for the provided context.
50bool LoadBuiltinSSLRootCertificates(SSL_CTX* ssl_ctx);
Mirko Bonadeib889a202018-08-15 09:41:2751#endif // WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS
Benjamin Wrightd6f86e82018-05-08 20:12:2552
Taylor Brandstetter165c6182020-12-11 00:23:0353#ifdef OPENSSL_IS_BORINGSSL
54CRYPTO_BUFFER_POOL* GetBufferPool();
55#endif
56
Benjamin Wrightd6f86e82018-05-08 20:12:2557} // namespace openssl
58} // namespace rtc
59
Steve Anton10542f22019-01-11 17:11:0060#endif // RTC_BASE_OPENSSL_UTILITY_H_