Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "webrtc/base/basictypes.h" | 14 #include "webrtc/base/basictypes.h" |
| 15 #include "webrtc/base/refcount.h" | 15 #include "webrtc/base/refcount.h" |
| 16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
| 17 #include "webrtc/base/scoped_ref_ptr.h" | 17 #include "webrtc/base/scoped_ref_ptr.h" |
| 18 #include "webrtc/base/sslidentity.h" | 18 #include "webrtc/base/sslidentity.h" |
| 19 | 19 |
| 20 namespace rtc { | 20 namespace rtc { |
| 21 | 21 |
| 22 // This class contains PEM strings of an RTCCertificate's private key and | |
| 23 // certificate and acts as a text representation of RTCCertificate. Certificates | |
| 24 // can be serialized and deserialized to and from this format, which allows for | |
| 25 // cloning and storing of certificates to disk. | |
|
hta-webrtc
2016/04/28 10:18:12
Do you want to say where the string format is defi
hbos
2016/04/28 10:44:37
Done.
| |
| 26 class RTCCertificatePEM { | |
| 27 public: | |
| 28 RTCCertificatePEM( | |
| 29 const std::string& private_key, | |
| 30 const std::string& certificate) | |
| 31 : private_key_(private_key), | |
| 32 certificate_(certificate) {} | |
| 33 | |
| 34 const std::string& private_key() const { return private_key_; } | |
| 35 const std::string& certificate() const { return certificate_; } | |
| 36 | |
| 37 private: | |
| 38 std::string private_key_; | |
| 39 std::string certificate_; | |
| 40 }; | |
| 41 | |
| 22 // A thin abstraction layer between "lower level crypto stuff" like | 42 // A thin abstraction layer between "lower level crypto stuff" like |
| 23 // SSLCertificate and WebRTC usage. Takes ownership of some lower level objects, | 43 // SSLCertificate and WebRTC usage. Takes ownership of some lower level objects, |
| 24 // reference counting protects these from premature destruction. | 44 // reference counting protects these from premature destruction. |
| 25 class RTCCertificate : public RefCountInterface { | 45 class RTCCertificate : public RefCountInterface { |
| 26 public: | 46 public: |
| 27 // Takes ownership of |identity|. | 47 // Takes ownership of |identity|. |
| 28 static scoped_refptr<RTCCertificate> Create(scoped_ptr<SSLIdentity> identity); | 48 static scoped_refptr<RTCCertificate> Create(scoped_ptr<SSLIdentity> identity); |
| 29 | 49 |
| 30 // Returns the expiration time in ms relative to epoch, 1970-01-01T00:00:00Z. | 50 // Returns the expiration time in ms relative to epoch, 1970-01-01T00:00:00Z. |
| 31 uint64_t Expires() const; | 51 uint64_t Expires() const; |
| 32 // Checks if the certificate has expired, where |now| is expressed in ms | 52 // Checks if the certificate has expired, where |now| is expressed in ms |
| 33 // relative to epoch, 1970-01-01T00:00:00Z. | 53 // relative to epoch, 1970-01-01T00:00:00Z. |
| 34 bool HasExpired(uint64_t now) const; | 54 bool HasExpired(uint64_t now) const; |
| 35 const SSLCertificate& ssl_certificate() const; | 55 const SSLCertificate& ssl_certificate() const; |
| 36 | 56 |
| 37 // TODO(hbos): If possible, remove once RTCCertificate and its | 57 // TODO(hbos): If possible, remove once RTCCertificate and its |
| 38 // ssl_certificate() is used in all relevant places. Should not pass around | 58 // ssl_certificate() is used in all relevant places. Should not pass around |
| 39 // raw SSLIdentity* for the sake of accessing SSLIdentity::certificate(). | 59 // raw SSLIdentity* for the sake of accessing SSLIdentity::certificate(). |
| 40 // However, some places might need SSLIdentity* for its public/private key... | 60 // However, some places might need SSLIdentity* for its public/private key... |
| 41 SSLIdentity* identity() const { return identity_.get(); } | 61 SSLIdentity* identity() const { return identity_.get(); } |
| 42 | 62 |
| 63 // To/from PEM, a text representation of the RTCCertificate. | |
| 64 RTCCertificatePEM ToPEM() const; | |
| 65 static scoped_refptr<RTCCertificate> FromPEM(const RTCCertificatePEM& pem); | |
| 66 bool operator==(const RTCCertificate& certificate) const; | |
| 67 bool operator!=(const RTCCertificate& certificate) const; | |
| 68 | |
| 43 protected: | 69 protected: |
| 44 explicit RTCCertificate(SSLIdentity* identity); | 70 explicit RTCCertificate(SSLIdentity* identity); |
| 45 ~RTCCertificate() override; | 71 ~RTCCertificate() override; |
| 46 | 72 |
| 47 private: | 73 private: |
| 48 // The SSLIdentity is the owner of the SSLCertificate. To protect our | 74 // The SSLIdentity is the owner of the SSLCertificate. To protect our |
| 49 // ssl_certificate() we take ownership of |identity_|. | 75 // ssl_certificate() we take ownership of |identity_|. |
| 50 scoped_ptr<SSLIdentity> identity_; | 76 scoped_ptr<SSLIdentity> identity_; |
| 51 }; | 77 }; |
| 52 | 78 |
| 53 } // namespace rtc | 79 } // namespace rtc |
| 54 | 80 |
| 55 #endif // WEBRTC_BASE_RTCCERTIFICATE_H_ | 81 #endif // WEBRTC_BASE_RTCCERTIFICATE_H_ |
| OLD | NEW |