OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ |
| 6 #define CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ |
| 7 |
| 8 #include "content/child/webcrypto/algorithm_implementation.h" |
| 9 |
| 10 #include "crypto/scoped_nss_types.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 namespace webcrypto { |
| 15 |
| 16 class PrivateKeyNss; |
| 17 class PublicKeyNss; |
| 18 class SymKeyNss; |
| 19 |
| 20 // 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' |
| 22 // format. This is to allow structured cloning of keys synchronously from the |
| 23 // target Blink thread without having to lock access to the key. |
| 24 class KeyNss : public blink::WebCryptoKeyHandle { |
| 25 public: |
| 26 explicit KeyNss(const CryptoData& serialized_key_data); |
| 27 virtual ~KeyNss(); |
| 28 |
| 29 virtual SymKeyNss* AsSymKey(); |
| 30 virtual PublicKeyNss* AsPublicKey(); |
| 31 virtual PrivateKeyNss* AsPrivateKey(); |
| 32 |
| 33 const std::vector<uint8>& serialized_key_data() const { |
| 34 return serialized_key_data_; |
| 35 } |
| 36 |
| 37 private: |
| 38 const std::vector<uint8> serialized_key_data_; |
| 39 }; |
| 40 |
| 41 class SymKeyNss : public KeyNss { |
| 42 public: |
| 43 virtual ~SymKeyNss(); |
| 44 SymKeyNss(crypto::ScopedPK11SymKey key, const CryptoData& raw_key_data); |
| 45 |
| 46 static SymKeyNss* Cast(const blink::WebCryptoKey& key); |
| 47 |
| 48 PK11SymKey* key() { return key_.get(); } |
| 49 virtual SymKeyNss* AsSymKey() OVERRIDE; |
| 50 |
| 51 const std::vector<uint8>& raw_key_data() const { |
| 52 return serialized_key_data(); |
| 53 } |
| 54 |
| 55 private: |
| 56 crypto::ScopedPK11SymKey key_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(SymKeyNss); |
| 59 }; |
| 60 |
| 61 class PublicKeyNss : public KeyNss { |
| 62 public: |
| 63 virtual ~PublicKeyNss(); |
| 64 PublicKeyNss(crypto::ScopedSECKEYPublicKey key, const CryptoData& spki_data); |
| 65 |
| 66 static PublicKeyNss* Cast(const blink::WebCryptoKey& key); |
| 67 |
| 68 SECKEYPublicKey* key() { return key_.get(); } |
| 69 virtual PublicKeyNss* AsPublicKey() OVERRIDE; |
| 70 |
| 71 const std::vector<uint8>& spki_data() const { return serialized_key_data(); } |
| 72 |
| 73 private: |
| 74 crypto::ScopedSECKEYPublicKey key_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(PublicKeyNss); |
| 77 }; |
| 78 |
| 79 class PrivateKeyNss : public KeyNss { |
| 80 public: |
| 81 virtual ~PrivateKeyNss(); |
| 82 PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key, |
| 83 const CryptoData& pkcs8_data); |
| 84 |
| 85 static PrivateKeyNss* Cast(const blink::WebCryptoKey& key); |
| 86 |
| 87 SECKEYPrivateKey* key() { return key_.get(); } |
| 88 virtual PrivateKeyNss* AsPrivateKey() OVERRIDE; |
| 89 |
| 90 const std::vector<uint8>& pkcs8_data() const { return serialized_key_data(); } |
| 91 |
| 92 private: |
| 93 crypto::ScopedSECKEYPrivateKey key_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(PrivateKeyNss); |
| 96 }; |
| 97 |
| 98 } // namespace webcrypto |
| 99 |
| 100 } // namespace content |
| 101 |
| 102 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_ |
OLD | NEW |