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