henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef RTC_BASE_SSL_FINGERPRINT_H_ |
| 12 | #define RTC_BASE_SSL_FINGERPRINT_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 16 | #include <string> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 17 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "rtc_base/copy_on_write_buffer.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 19 | |
| 20 | namespace rtc { |
| 21 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 22 | class RTCCertificate; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 23 | class SSLCertificate; |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 24 | class SSLIdentity; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 25 | |
| 26 | struct SSLFingerprint { |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 27 | // TODO(steveanton): Remove once downstream projects have moved off of this. |
Henrik Grunell | 2b15626 | 2018-10-11 11:15:48 +0000 | [diff] [blame] | 28 | static SSLFingerprint* Create(const std::string& algorithm, |
Mirko Bonadei | 6932fb2 | 2018-10-15 14:18:03 +0000 | [diff] [blame] | 29 | const rtc::SSLIdentity* identity); |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 30 | // TODO(steveanton): Rename to Create once projects have migrated. |
| 31 | static std::unique_ptr<SSLFingerprint> CreateUnique( |
| 32 | const std::string& algorithm, |
| 33 | const rtc::SSLIdentity& identity); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 34 | |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 35 | static std::unique_ptr<SSLFingerprint> Create( |
| 36 | const std::string& algorithm, |
| 37 | const rtc::SSLCertificate& cert); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 38 | |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 39 | // TODO(steveanton): Remove once downstream projects have moved off of this. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 40 | static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm, |
| 41 | const std::string& fingerprint); |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 42 | // TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated. |
| 43 | static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572( |
| 44 | const std::string& algorithm, |
| 45 | const std::string& fingerprint); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 46 | |
| 47 | // Creates a fingerprint from a certificate, using the same digest algorithm |
| 48 | // as the certificate's signature. |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 49 | static std::unique_ptr<SSLFingerprint> CreateFromCertificate( |
| 50 | const RTCCertificate& cert); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 51 | |
| 52 | SSLFingerprint(const std::string& algorithm, |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 53 | ArrayView<const uint8_t> digest_view); |
| 54 | // TODO(steveanton): Remove once downstream projects have moved off of this. |
| 55 | SSLFingerprint(const std::string& algorithm, |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 56 | const uint8_t* digest_in, |
| 57 | size_t digest_len); |
| 58 | |
| 59 | SSLFingerprint(const SSLFingerprint& from); |
| 60 | |
| 61 | bool operator==(const SSLFingerprint& other) const; |
| 62 | |
| 63 | std::string GetRfc4572Fingerprint() const; |
| 64 | |
| 65 | std::string ToString() const; |
| 66 | |
| 67 | std::string algorithm; |
| 68 | rtc::CopyOnWriteBuffer digest; |
| 69 | }; |
| 70 | |
| 71 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 72 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 73 | #endif // RTC_BASE_SSL_FINGERPRINT_H_ |