OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ |
6 #define CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ |
7 | 7 |
8 #include "content/child/webcrypto/algorithm_implementation.h" | 8 #include <stdint.h> |
| 9 #include <vector> |
9 | 10 |
10 #include "crypto/scoped_nss_types.h" | 11 #include "crypto/scoped_nss_types.h" |
| 12 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 namespace webcrypto { | 16 namespace webcrypto { |
15 | 17 |
| 18 class CryptoData; |
16 class PrivateKeyNss; | 19 class PrivateKeyNss; |
17 class PublicKeyNss; | 20 class PublicKeyNss; |
18 class SymKeyNss; | 21 class SymKeyNss; |
19 | 22 |
20 // Base key class for all NSS keys, used to safely cast between types. Each key | 23 // Base key class for all NSS keys, used to safely cast between types. Each key |
21 // maintains a copy of its serialized form in either 'raw', 'pkcs8', or 'spki' | 24 // maintains a copy of its serialized form in either 'raw', 'pkcs8', or 'spki' |
22 // format. This is to allow structured cloning of keys synchronously from the | 25 // format. This is to allow structured cloning of keys synchronously from the |
23 // target Blink thread without having to lock access to the key. | 26 // target Blink thread without having to lock access to the key. |
24 class KeyNss : public blink::WebCryptoKeyHandle { | 27 class KeyNss : public blink::WebCryptoKeyHandle { |
25 public: | 28 public: |
26 explicit KeyNss(const CryptoData& serialized_key_data); | 29 explicit KeyNss(const CryptoData& serialized_key_data); |
27 virtual ~KeyNss(); | 30 virtual ~KeyNss(); |
28 | 31 |
29 virtual SymKeyNss* AsSymKey(); | 32 virtual SymKeyNss* AsSymKey(); |
30 virtual PublicKeyNss* AsPublicKey(); | 33 virtual PublicKeyNss* AsPublicKey(); |
31 virtual PrivateKeyNss* AsPrivateKey(); | 34 virtual PrivateKeyNss* AsPrivateKey(); |
32 | 35 |
33 const std::vector<uint8>& serialized_key_data() const { | 36 const std::vector<uint8_t>& serialized_key_data() const { |
34 return serialized_key_data_; | 37 return serialized_key_data_; |
35 } | 38 } |
36 | 39 |
37 private: | 40 private: |
38 const std::vector<uint8> serialized_key_data_; | 41 const std::vector<uint8_t> serialized_key_data_; |
39 }; | 42 }; |
40 | 43 |
41 class SymKeyNss : public KeyNss { | 44 class SymKeyNss : public KeyNss { |
42 public: | 45 public: |
43 virtual ~SymKeyNss(); | 46 virtual ~SymKeyNss(); |
44 SymKeyNss(crypto::ScopedPK11SymKey key, const CryptoData& raw_key_data); | 47 SymKeyNss(crypto::ScopedPK11SymKey key, const CryptoData& raw_key_data); |
45 | 48 |
46 static SymKeyNss* Cast(const blink::WebCryptoKey& key); | 49 static SymKeyNss* Cast(const blink::WebCryptoKey& key); |
47 | 50 |
48 PK11SymKey* key() { return key_.get(); } | 51 PK11SymKey* key() { return key_.get(); } |
49 virtual SymKeyNss* AsSymKey() OVERRIDE; | 52 virtual SymKeyNss* AsSymKey() OVERRIDE; |
50 | 53 |
51 const std::vector<uint8>& raw_key_data() const { | 54 const std::vector<uint8_t>& raw_key_data() const { |
52 return serialized_key_data(); | 55 return serialized_key_data(); |
53 } | 56 } |
54 | 57 |
55 private: | 58 private: |
56 crypto::ScopedPK11SymKey key_; | 59 crypto::ScopedPK11SymKey key_; |
57 | 60 |
58 DISALLOW_COPY_AND_ASSIGN(SymKeyNss); | 61 DISALLOW_COPY_AND_ASSIGN(SymKeyNss); |
59 }; | 62 }; |
60 | 63 |
61 class PublicKeyNss : public KeyNss { | 64 class PublicKeyNss : public KeyNss { |
62 public: | 65 public: |
63 virtual ~PublicKeyNss(); | 66 virtual ~PublicKeyNss(); |
64 PublicKeyNss(crypto::ScopedSECKEYPublicKey key, const CryptoData& spki_data); | 67 PublicKeyNss(crypto::ScopedSECKEYPublicKey key, const CryptoData& spki_data); |
65 | 68 |
66 static PublicKeyNss* Cast(const blink::WebCryptoKey& key); | 69 static PublicKeyNss* Cast(const blink::WebCryptoKey& key); |
67 | 70 |
68 SECKEYPublicKey* key() { return key_.get(); } | 71 SECKEYPublicKey* key() { return key_.get(); } |
69 virtual PublicKeyNss* AsPublicKey() OVERRIDE; | 72 virtual PublicKeyNss* AsPublicKey() OVERRIDE; |
70 | 73 |
71 const std::vector<uint8>& spki_data() const { return serialized_key_data(); } | 74 const std::vector<uint8_t>& spki_data() const { |
| 75 return serialized_key_data(); |
| 76 } |
72 | 77 |
73 private: | 78 private: |
74 crypto::ScopedSECKEYPublicKey key_; | 79 crypto::ScopedSECKEYPublicKey key_; |
75 | 80 |
76 DISALLOW_COPY_AND_ASSIGN(PublicKeyNss); | 81 DISALLOW_COPY_AND_ASSIGN(PublicKeyNss); |
77 }; | 82 }; |
78 | 83 |
79 class PrivateKeyNss : public KeyNss { | 84 class PrivateKeyNss : public KeyNss { |
80 public: | 85 public: |
81 virtual ~PrivateKeyNss(); | 86 virtual ~PrivateKeyNss(); |
82 PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key, | 87 PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key, |
83 const CryptoData& pkcs8_data); | 88 const CryptoData& pkcs8_data); |
84 | 89 |
85 static PrivateKeyNss* Cast(const blink::WebCryptoKey& key); | 90 static PrivateKeyNss* Cast(const blink::WebCryptoKey& key); |
86 | 91 |
87 SECKEYPrivateKey* key() { return key_.get(); } | 92 SECKEYPrivateKey* key() { return key_.get(); } |
88 virtual PrivateKeyNss* AsPrivateKey() OVERRIDE; | 93 virtual PrivateKeyNss* AsPrivateKey() OVERRIDE; |
89 | 94 |
90 const std::vector<uint8>& pkcs8_data() const { return serialized_key_data(); } | 95 const std::vector<uint8_t>& pkcs8_data() const { |
| 96 return serialized_key_data(); |
| 97 } |
91 | 98 |
92 private: | 99 private: |
93 crypto::ScopedSECKEYPrivateKey key_; | 100 crypto::ScopedSECKEYPrivateKey key_; |
94 | 101 |
95 DISALLOW_COPY_AND_ASSIGN(PrivateKeyNss); | 102 DISALLOW_COPY_AND_ASSIGN(PrivateKeyNss); |
96 }; | 103 }; |
97 | 104 |
98 } // namespace webcrypto | 105 } // namespace webcrypto |
99 | 106 |
100 } // namespace content | 107 } // namespace content |
101 | 108 |
102 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ | 109 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ |
OLD | NEW |