Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: webrtc/base/rtccertificate.h

Issue 1898383003: RTCCertificate serialization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase with master (std::unique_ptr) Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/opensslidentity.cc ('k') | webrtc/base/rtccertificate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_RTCCERTIFICATE_H_ 11 #ifndef WEBRTC_BASE_RTCCERTIFICATE_H_
12 #define WEBRTC_BASE_RTCCERTIFICATE_H_ 12 #define WEBRTC_BASE_RTCCERTIFICATE_H_
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/base/basictypes.h" 16 #include "webrtc/base/basictypes.h"
17 #include "webrtc/base/refcount.h" 17 #include "webrtc/base/refcount.h"
18 #include "webrtc/base/scoped_ref_ptr.h" 18 #include "webrtc/base/scoped_ref_ptr.h"
19 #include "webrtc/base/sslidentity.h" 19 #include "webrtc/base/sslidentity.h"
20 20
21 namespace rtc { 21 namespace rtc {
22 22
23 // This class contains PEM strings of an RTCCertificate's private key and
24 // certificate and acts as a text representation of RTCCertificate. Certificates
25 // can be serialized and deserialized to and from this format, which allows for
26 // cloning and storing of certificates to disk. The PEM format is that of
27 // |SSLIdentity::PrivateKeyToPEMString| and |SSLCertificate::ToPEMString|, e.g.
28 // the string representations used by OpenSSL.
29 class RTCCertificatePEM {
30 public:
31 RTCCertificatePEM(
32 const std::string& private_key,
33 const std::string& certificate)
34 : private_key_(private_key),
35 certificate_(certificate) {}
36
37 const std::string& private_key() const { return private_key_; }
38 const std::string& certificate() const { return certificate_; }
39
40 private:
41 std::string private_key_;
42 std::string certificate_;
43 };
44
23 // A thin abstraction layer between "lower level crypto stuff" like 45 // A thin abstraction layer between "lower level crypto stuff" like
24 // SSLCertificate and WebRTC usage. Takes ownership of some lower level objects, 46 // SSLCertificate and WebRTC usage. Takes ownership of some lower level objects,
25 // reference counting protects these from premature destruction. 47 // reference counting protects these from premature destruction.
26 class RTCCertificate : public RefCountInterface { 48 class RTCCertificate : public RefCountInterface {
27 public: 49 public:
28 // Takes ownership of |identity|. 50 // Takes ownership of |identity|.
29 static scoped_refptr<RTCCertificate> Create( 51 static scoped_refptr<RTCCertificate> Create(
30 std::unique_ptr<SSLIdentity> identity); 52 std::unique_ptr<SSLIdentity> identity);
31 53
32 // Returns the expiration time in ms relative to epoch, 1970-01-01T00:00:00Z. 54 // Returns the expiration time in ms relative to epoch, 1970-01-01T00:00:00Z.
33 uint64_t Expires() const; 55 uint64_t Expires() const;
34 // Checks if the certificate has expired, where |now| is expressed in ms 56 // Checks if the certificate has expired, where |now| is expressed in ms
35 // relative to epoch, 1970-01-01T00:00:00Z. 57 // relative to epoch, 1970-01-01T00:00:00Z.
36 bool HasExpired(uint64_t now) const; 58 bool HasExpired(uint64_t now) const;
37 const SSLCertificate& ssl_certificate() const; 59 const SSLCertificate& ssl_certificate() const;
38 60
39 // TODO(hbos): If possible, remove once RTCCertificate and its 61 // TODO(hbos): If possible, remove once RTCCertificate and its
40 // ssl_certificate() is used in all relevant places. Should not pass around 62 // ssl_certificate() is used in all relevant places. Should not pass around
41 // raw SSLIdentity* for the sake of accessing SSLIdentity::certificate(). 63 // raw SSLIdentity* for the sake of accessing SSLIdentity::certificate().
42 // However, some places might need SSLIdentity* for its public/private key... 64 // However, some places might need SSLIdentity* for its public/private key...
43 SSLIdentity* identity() const { return identity_.get(); } 65 SSLIdentity* identity() const { return identity_.get(); }
44 66
67 // To/from PEM, a text representation of the RTCCertificate.
68 RTCCertificatePEM ToPEM() const;
69 static scoped_refptr<RTCCertificate> FromPEM(const RTCCertificatePEM& pem);
70 bool operator==(const RTCCertificate& certificate) const;
71 bool operator!=(const RTCCertificate& certificate) const;
72
45 protected: 73 protected:
46 explicit RTCCertificate(SSLIdentity* identity); 74 explicit RTCCertificate(SSLIdentity* identity);
47 ~RTCCertificate() override; 75 ~RTCCertificate() override;
48 76
49 private: 77 private:
50 // The SSLIdentity is the owner of the SSLCertificate. To protect our 78 // The SSLIdentity is the owner of the SSLCertificate. To protect our
51 // ssl_certificate() we take ownership of |identity_|. 79 // ssl_certificate() we take ownership of |identity_|.
52 std::unique_ptr<SSLIdentity> identity_; 80 std::unique_ptr<SSLIdentity> identity_;
53 }; 81 };
54 82
55 } // namespace rtc 83 } // namespace rtc
56 84
57 #endif // WEBRTC_BASE_RTCCERTIFICATE_H_ 85 #endif // WEBRTC_BASE_RTCCERTIFICATE_H_
OLDNEW
« no previous file with comments | « webrtc/base/opensslidentity.cc ('k') | webrtc/base/rtccertificate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698