blob: f4037f78b0f3282fcb1bec4cbc8dbc3a7d952bc9 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 Anton10542f22019-01-11 09:11:00 -080011#ifndef RTC_BASE_SSL_FINGERPRINT_H_
12#define RTC_BASE_SSL_FINGERPRINT_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#include <string>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/copy_on_write_buffer.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020019
20namespace rtc {
21
Yves Gerey988cc082018-10-23 12:03:01 +020022class RTCCertificate;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020023class SSLCertificate;
Yves Gerey988cc082018-10-23 12:03:01 +020024class SSLIdentity;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020025
26struct SSLFingerprint {
Steve Anton4905edb2018-10-15 19:27:44 -070027 // TODO(steveanton): Remove once downstream projects have moved off of this.
Henrik Grunell2b156262018-10-11 11:15:48 +000028 static SSLFingerprint* Create(const std::string& algorithm,
Mirko Bonadei6932fb22018-10-15 14:18:03 +000029 const rtc::SSLIdentity* identity);
Steve Anton4905edb2018-10-15 19:27:44 -070030 // 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 Kjellanderec78f1c2017-06-29 07:52:50 +020034
Steve Anton4905edb2018-10-15 19:27:44 -070035 static std::unique_ptr<SSLFingerprint> Create(
36 const std::string& algorithm,
37 const rtc::SSLCertificate& cert);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020038
Steve Anton4905edb2018-10-15 19:27:44 -070039 // TODO(steveanton): Remove once downstream projects have moved off of this.
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020040 static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm,
41 const std::string& fingerprint);
Steve Anton4905edb2018-10-15 19:27:44 -070042 // 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 Kjellanderec78f1c2017-06-29 07:52:50 +020046
47 // Creates a fingerprint from a certificate, using the same digest algorithm
48 // as the certificate's signature.
Steve Anton4905edb2018-10-15 19:27:44 -070049 static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
50 const RTCCertificate& cert);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020051
52 SSLFingerprint(const std::string& algorithm,
Steve Anton4905edb2018-10-15 19:27:44 -070053 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 Kjellanderec78f1c2017-06-29 07:52:50 +020056 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.orgf0488722014-05-13 18:00:26 +000072
Steve Anton10542f22019-01-11 09:11:00 -080073#endif // RTC_BASE_SSL_FINGERPRINT_H_