OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <keyhi.h> | 5 #include <keyhi.h> |
6 #include <pk11pub.h> | 6 #include <pk11pub.h> |
7 #include <prerror.h> | 7 #include <prerror.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 err_name = ""; | 31 err_name = ""; |
32 LOG(ERROR) << "Could not sign digest: " << err << " (" << err_name << ")"; | 32 LOG(ERROR) << "Could not sign digest: " << err << " (" << err_name << ")"; |
33 } | 33 } |
34 | 34 |
35 class SSLPlatformKeyChromecast : public ThreadedSSLPrivateKey::Delegate { | 35 class SSLPlatformKeyChromecast : public ThreadedSSLPrivateKey::Delegate { |
36 public: | 36 public: |
37 SSLPlatformKeyChromecast(crypto::ScopedSECKEYPrivateKey key) | 37 SSLPlatformKeyChromecast(crypto::ScopedSECKEYPrivateKey key) |
38 : key_(std::move(key)) {} | 38 : key_(std::move(key)) {} |
39 ~SSLPlatformKeyChromecast() override {} | 39 ~SSLPlatformKeyChromecast() override {} |
40 | 40 |
41 SSLPrivateKey::Type GetType() override { return SSLPrivateKey::Type::RSA; } | |
42 | |
43 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override { | 41 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override { |
44 return std::vector<SSLPrivateKey::Hash>{SSLPrivateKey::Hash::SHA256, | 42 return std::vector<SSLPrivateKey::Hash>{SSLPrivateKey::Hash::SHA256, |
45 SSLPrivateKey::Hash::SHA1}; | 43 SSLPrivateKey::Hash::SHA1}; |
46 } | 44 } |
47 | 45 |
48 size_t GetMaxSignatureLengthInBytes() override { | |
49 int len = PK11_SignatureLen(key_.get()); | |
50 if (len <= 0) | |
51 return 0; | |
52 return static_cast<size_t>(len); | |
53 } | |
54 | |
55 Error SignDigest(SSLPrivateKey::Hash hash, | 46 Error SignDigest(SSLPrivateKey::Hash hash, |
56 const base::StringPiece& input, | 47 const base::StringPiece& input, |
57 std::vector<uint8_t>* signature) override { | 48 std::vector<uint8_t>* signature) override { |
58 SECItem digest_item; | 49 SECItem digest_item; |
59 digest_item.data = | 50 digest_item.data = |
60 const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(input.data())); | 51 const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(input.data())); |
61 digest_item.len = input.size(); | 52 digest_item.len = input.size(); |
62 | 53 |
63 bssl::UniquePtr<uint8_t> free_digest_info; | 54 bssl::UniquePtr<uint8_t> free_digest_info; |
64 // PK11_Sign expects the caller to prepend the DigestInfo. | 55 // PK11_Sign expects the caller to prepend the DigestInfo. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | 114 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( |
124 *certificate); | 115 *certificate); |
125 } | 116 } |
126 | 117 |
127 return make_scoped_refptr(new ThreadedSSLPrivateKey( | 118 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
128 base::MakeUnique<SSLPlatformKeyChromecast>(std::move(key)), | 119 base::MakeUnique<SSLPlatformKeyChromecast>(std::move(key)), |
129 GetSSLPlatformKeyTaskRunner())); | 120 GetSSLPlatformKeyTaskRunner())); |
130 } | 121 } |
131 | 122 |
132 } // namespace net | 123 } // namespace net |
OLD | NEW |