mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 22:30:40 +01:00

This extends the API surface so that custom certificates can be provided by an API user in both the standalone and factory creation paths for the OpenSSLAdapter. Prior to this change the SSL roots were hardcoded in a header file and directly included into openssladapter.cc. This forces the 100 kilobytes of certificates to always be compiled into the library. This is undesirable in certain linking cases where these certificates can be shared from another binary that already has an equivalent set of trusted roots hard coded into the binary. Support for removing the hard coded SSL roots has also been added through a new build flag. By default the hard coded SSL roots will be included and will be used if no other trusted root certificates are provided. The main goal of this CL is to reduce total binary size requirements of WebRTC by about 100kb in certain applications where adding these certificates is redundant. Change-Id: Ifd36d92b5cb32d1b3098a61ddfc244d76df8f30f Bug: chromium:526260 Change-Id: Ifd36d92b5cb32d1b3098a61ddfc244d76df8f30f Reviewed-on: https://webrtc-review.googlesource.com/64841 Commit-Queue: Benjamin Wright <benwright@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23180}
80 lines
2.5 KiB
C++
80 lines
2.5 KiB
C++
/*
|
|
* Copyright 2004 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.
|
|
*/
|
|
|
|
#ifndef RTC_BASE_OPENSSLCERTIFICATE_H_
|
|
#define RTC_BASE_OPENSSLCERTIFICATE_H_
|
|
|
|
#include <openssl/evp.h>
|
|
#include <openssl/x509.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "rtc_base/checks.h"
|
|
#include "rtc_base/constructormagic.h"
|
|
#include "rtc_base/sslcertificate.h"
|
|
#include "rtc_base/sslidentity.h"
|
|
|
|
typedef struct ssl_ctx_st SSL_CTX;
|
|
|
|
namespace rtc {
|
|
|
|
class OpenSSLKeyPair;
|
|
|
|
// OpenSSLCertificate encapsulates an OpenSSL X509* certificate object,
|
|
// which is also reference counted inside the OpenSSL library.
|
|
class OpenSSLCertificate : public SSLCertificate {
|
|
public:
|
|
// X509 object has its reference count incremented. So the caller and
|
|
// OpenSSLCertificate share ownership.
|
|
explicit OpenSSLCertificate(X509* x509);
|
|
|
|
static OpenSSLCertificate* Generate(OpenSSLKeyPair* key_pair,
|
|
const SSLIdentityParams& params);
|
|
static OpenSSLCertificate* FromPEMString(const std::string& pem_string);
|
|
|
|
~OpenSSLCertificate() override;
|
|
|
|
OpenSSLCertificate* GetReference() const override;
|
|
|
|
X509* x509() const { return x509_; }
|
|
|
|
std::string ToPEMString() const override;
|
|
void ToDER(Buffer* der_buffer) const override;
|
|
bool operator==(const OpenSSLCertificate& other) const;
|
|
bool operator!=(const OpenSSLCertificate& other) const;
|
|
|
|
// Compute the digest of the certificate given algorithm
|
|
bool ComputeDigest(const std::string& algorithm,
|
|
unsigned char* digest,
|
|
size_t size,
|
|
size_t* length) const override;
|
|
|
|
// Compute the digest of a certificate as an X509 *
|
|
static bool ComputeDigest(const X509* x509,
|
|
const std::string& algorithm,
|
|
unsigned char* digest,
|
|
size_t size,
|
|
size_t* length);
|
|
|
|
bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
|
|
|
|
int64_t CertificateExpirationTime() const override;
|
|
|
|
private:
|
|
void AddReference() const;
|
|
|
|
X509* x509_; // NOT OWNED
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLCertificate);
|
|
};
|
|
|
|
} // namespace rtc
|
|
|
|
#endif // RTC_BASE_OPENSSLCERTIFICATE_H_
|