blob: 3d4f36e6a3e9886c70ba516bb77225929a1807b9 [file] [log] [blame]
Henrik Boström41b3a382015-08-20 12:15:54 +02001/*
2 * Copyright 2015 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
11#ifndef WEBRTC_BASE_RTCCERTIFICATE_H_
12#define WEBRTC_BASE_RTCCERTIFICATE_H_
13
jbauch555604a2016-04-26 03:13:22 -070014#include <memory>
15
Henrik Boström41b3a382015-08-20 12:15:54 +020016#include "webrtc/base/basictypes.h"
17#include "webrtc/base/refcount.h"
Henrik Boström41b3a382015-08-20 12:15:54 +020018#include "webrtc/base/scoped_ref_ptr.h"
19#include "webrtc/base/sslidentity.h"
20
21namespace rtc {
22
23// A thin abstraction layer between "lower level crypto stuff" like
24// SSLCertificate and WebRTC usage. Takes ownership of some lower level objects,
25// reference counting protects these from premature destruction.
26class RTCCertificate : public RefCountInterface {
27 public:
28 // Takes ownership of |identity|.
jbauch555604a2016-04-26 03:13:22 -070029 static scoped_refptr<RTCCertificate> Create(
30 std::unique_ptr<SSLIdentity> identity);
Henrik Boström41b3a382015-08-20 12:15:54 +020031
hbos3980d462015-12-09 05:26:49 -080032 // Returns the expiration time in ms relative to epoch, 1970-01-01T00:00:00Z.
33 uint64_t Expires() const;
34 // Checks if the certificate has expired, where |now| is expressed in ms
35 // relative to epoch, 1970-01-01T00:00:00Z.
36 bool HasExpired(uint64_t now) const;
Henrik Boström41b3a382015-08-20 12:15:54 +020037 const SSLCertificate& ssl_certificate() const;
38
39 // TODO(hbos): If possible, remove once RTCCertificate and its
40 // ssl_certificate() is used in all relevant places. Should not pass around
41 // raw SSLIdentity* for the sake of accessing SSLIdentity::certificate().
42 // However, some places might need SSLIdentity* for its public/private key...
43 SSLIdentity* identity() const { return identity_.get(); }
44
45 protected:
46 explicit RTCCertificate(SSLIdentity* identity);
47 ~RTCCertificate() override;
48
49 private:
50 // The SSLIdentity is the owner of the SSLCertificate. To protect our
51 // ssl_certificate() we take ownership of |identity_|.
jbauch555604a2016-04-26 03:13:22 -070052 std::unique_ptr<SSLIdentity> identity_;
Henrik Boström41b3a382015-08-20 12:15:54 +020053};
54
55} // namespace rtc
56
57#endif // WEBRTC_BASE_RTCCERTIFICATE_H_