blob: ee29ccd6025a5d9cbb67debfbabd6d0de8144520 [file] [log] [blame]
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001/*
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 09:11:00 -080011#ifndef RTC_BASE_OPENSSL_UTILITY_H_
12#define RTC_BASE_OPENSSL_UTILITY_H_
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070013
14#include <openssl/ossl_typ.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070016#include <string>
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070017
18namespace rtc {
19// The openssl namespace holds static helper methods. All methods related
20// to OpenSSL that are commonly used and don't require global state should be
21// placed here.
22namespace openssl {
Taylor Brandstetter165c6182020-12-10 16:23:03 -080023
24#ifdef OPENSSL_IS_BORINGSSL
25// Does minimal parsing of a certificate (only verifying the presence of major
26// fields), primarily for the purpose of extracting the relevant out
27// parameters. Any that the caller is uninterested in can be null.
28bool ParseCertificate(CRYPTO_BUFFER* cert_buffer,
29 CBS* signature_algorithm_oid,
30 int64_t* expiration_time);
31#endif
32
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070033// Verifies that the hostname provided matches that in the peer certificate
34// attached to this SSL state.
Taylor Brandstetter165c6182020-12-10 16:23:03 -080035// TODO(crbug.com/webrtc/11710): When OS certificate verification is available,
36// skip compiling this as it adds a dependency on OpenSSL X509 objects, which we
37// are trying to avoid in favor of CRYPTO_BUFFERs (see crbug.com/webrtc/11410).
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070038bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host);
39
40// Logs all the errors in the OpenSSL errror queue from the current thread. A
41// prefix can be provided for context.
42void LogSSLErrors(const std::string& prefix);
43
Mirko Bonadeib889a202018-08-15 11:41:27 +020044#ifndef WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070045// Attempt to add the certificates from the loader into the SSL_CTX. False is
46// returned only if there are no certificates returned from the loader or none
47// of them can be added to the TrustStore for the provided context.
48bool LoadBuiltinSSLRootCertificates(SSL_CTX* ssl_ctx);
Mirko Bonadeib889a202018-08-15 11:41:27 +020049#endif // WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070050
Taylor Brandstetter165c6182020-12-10 16:23:03 -080051#ifdef OPENSSL_IS_BORINGSSL
52CRYPTO_BUFFER_POOL* GetBufferPool();
53#endif
54
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070055} // namespace openssl
56} // namespace rtc
57
Steve Anton10542f22019-01-11 09:11:00 -080058#endif // RTC_BASE_OPENSSL_UTILITY_H_