| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 #include "webrtc/base/sslfingerprint.h" | 11 #include "webrtc/base/sslfingerprint.h" |
| 12 | 12 |
| 13 #include <ctype.h> | 13 #include <ctype.h> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "webrtc/base/helpers.h" | 16 #include "webrtc/base/helpers.h" |
| 17 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/base/messagedigest.h" | 18 #include "webrtc/base/messagedigest.h" |
| 18 #include "webrtc/base/stringencode.h" | 19 #include "webrtc/base/stringencode.h" |
| 19 | 20 |
| 20 namespace rtc { | 21 namespace rtc { |
| 21 | 22 |
| 22 SSLFingerprint* SSLFingerprint::Create( | 23 SSLFingerprint* SSLFingerprint::Create( |
| 23 const std::string& algorithm, const rtc::SSLIdentity* identity) { | 24 const std::string& algorithm, const rtc::SSLIdentity* identity) { |
| 24 if (!identity) { | 25 if (!identity) { |
| 25 return NULL; | 26 return NULL; |
| 26 } | 27 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 55 fingerprint.c_str(), | 56 fingerprint.c_str(), |
| 56 fingerprint.length(), | 57 fingerprint.length(), |
| 57 ':'); | 58 ':'); |
| 58 if (!value_len) | 59 if (!value_len) |
| 59 return NULL; | 60 return NULL; |
| 60 | 61 |
| 61 return new SSLFingerprint(algorithm, reinterpret_cast<uint8_t*>(value), | 62 return new SSLFingerprint(algorithm, reinterpret_cast<uint8_t*>(value), |
| 62 value_len); | 63 value_len); |
| 63 } | 64 } |
| 64 | 65 |
| 66 SSLFingerprint* SSLFingerprint::CreateFromCertificate( |
| 67 const RTCCertificate* cert) { |
| 68 std::string digest_alg; |
| 69 if (!cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_alg)) { |
| 70 LOG(LS_ERROR) << "Failed to retrieve the certificate's digest algorithm"; |
| 71 return nullptr; |
| 72 } |
| 73 |
| 74 SSLFingerprint* fingerprint = Create(digest_alg, cert->identity()); |
| 75 if (!fingerprint) { |
| 76 LOG(LS_ERROR) << "Failed to create identity fingerprint, alg=" |
| 77 << digest_alg; |
| 78 } |
| 79 return fingerprint; |
| 80 } |
| 81 |
| 65 SSLFingerprint::SSLFingerprint(const std::string& algorithm, | 82 SSLFingerprint::SSLFingerprint(const std::string& algorithm, |
| 66 const uint8_t* digest_in, | 83 const uint8_t* digest_in, |
| 67 size_t digest_len) | 84 size_t digest_len) |
| 68 : algorithm(algorithm) { | 85 : algorithm(algorithm) { |
| 69 digest.SetData(digest_in, digest_len); | 86 digest.SetData(digest_in, digest_len); |
| 70 } | 87 } |
| 71 | 88 |
| 72 SSLFingerprint::SSLFingerprint(const SSLFingerprint& from) | 89 SSLFingerprint::SSLFingerprint(const SSLFingerprint& from) |
| 73 : algorithm(from.algorithm), digest(from.digest) {} | 90 : algorithm(from.algorithm), digest(from.digest) {} |
| 74 | 91 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 } | 103 } |
| 87 | 104 |
| 88 std::string SSLFingerprint::ToString() const { | 105 std::string SSLFingerprint::ToString() const { |
| 89 std::string fp_str = algorithm; | 106 std::string fp_str = algorithm; |
| 90 fp_str.append(" "); | 107 fp_str.append(" "); |
| 91 fp_str.append(GetRfc4572Fingerprint()); | 108 fp_str.append(GetRfc4572Fingerprint()); |
| 92 return fp_str; | 109 return fp_str; |
| 93 } | 110 } |
| 94 | 111 |
| 95 } // namespace rtc | 112 } // namespace rtc |
| OLD | NEW |