| 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_OPENSSL_KEY_OPENSSL_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_ |
| 6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_ |
| 7 | 7 |
| 8 #include <openssl/ossl_typ.h> |
| 9 |
| 8 #include "content/child/webcrypto/algorithm_implementation.h" | 10 #include "content/child/webcrypto/algorithm_implementation.h" |
| 11 #include "crypto/scoped_openssl_types.h" |
| 9 | 12 |
| 10 namespace content { | 13 namespace content { |
| 11 | 14 |
| 12 namespace webcrypto { | 15 namespace webcrypto { |
| 13 | 16 |
| 17 class AsymKeyOpenSsl; |
| 14 class SymKeyOpenSsl; | 18 class SymKeyOpenSsl; |
| 15 | 19 |
| 16 // Base key class for all OpenSSL keys, used to safely cast between types. Each | 20 // Base key class for all OpenSSL keys, used to safely cast between types. Each |
| 17 // key maintains a copy of its serialized form in either 'raw', 'pkcs8', or | 21 // key maintains a copy of its serialized form in either 'raw', 'pkcs8', or |
| 18 // 'spki' format. This is to allow structured cloning of keys synchronously from | 22 // 'spki' format. This is to allow structured cloning of keys synchronously from |
| 19 // the target Blink thread without having to lock access to the key. | 23 // the target Blink thread without having to lock access to the key. |
| 20 class KeyOpenSsl : public blink::WebCryptoKeyHandle { | 24 class KeyOpenSsl : public blink::WebCryptoKeyHandle { |
| 21 public: | 25 public: |
| 22 explicit KeyOpenSsl(const CryptoData& serialized_key_data); | 26 explicit KeyOpenSsl(const CryptoData& serialized_key_data); |
| 23 virtual ~KeyOpenSsl(); | 27 virtual ~KeyOpenSsl(); |
| 24 | 28 |
| 25 virtual SymKeyOpenSsl* AsSymKey(); | 29 virtual SymKeyOpenSsl* AsSymKey(); |
| 30 virtual AsymKeyOpenSsl* AsAsymKey(); |
| 26 | 31 |
| 27 const std::vector<uint8>& serialized_key_data() const { | 32 const std::vector<uint8>& serialized_key_data() const { |
| 28 return serialized_key_data_; | 33 return serialized_key_data_; |
| 29 } | 34 } |
| 30 | 35 |
| 31 private: | 36 private: |
| 32 const std::vector<uint8> serialized_key_data_; | 37 const std::vector<uint8> serialized_key_data_; |
| 33 }; | 38 }; |
| 34 | 39 |
| 35 class SymKeyOpenSsl : public KeyOpenSsl { | 40 class SymKeyOpenSsl : public KeyOpenSsl { |
| 36 public: | 41 public: |
| 37 virtual ~SymKeyOpenSsl(); | 42 virtual ~SymKeyOpenSsl(); |
| 38 explicit SymKeyOpenSsl(const CryptoData& raw_key_data); | 43 explicit SymKeyOpenSsl(const CryptoData& raw_key_data); |
| 39 | 44 |
| 40 static SymKeyOpenSsl* Cast(const blink::WebCryptoKey& key); | 45 static SymKeyOpenSsl* Cast(const blink::WebCryptoKey& key); |
| 41 | 46 |
| 42 virtual SymKeyOpenSsl* AsSymKey() OVERRIDE; | 47 virtual SymKeyOpenSsl* AsSymKey() OVERRIDE; |
| 43 | 48 |
| 44 const std::vector<uint8>& raw_key_data() const { | 49 const std::vector<uint8>& raw_key_data() const { |
| 45 return serialized_key_data(); | 50 return serialized_key_data(); |
| 46 } | 51 } |
| 47 | 52 |
| 48 private: | 53 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(SymKeyOpenSsl); | 54 DISALLOW_COPY_AND_ASSIGN(SymKeyOpenSsl); |
| 50 }; | 55 }; |
| 51 | 56 |
| 57 class AsymKeyOpenSsl : public KeyOpenSsl { |
| 58 public: |
| 59 virtual ~AsymKeyOpenSsl(); |
| 60 AsymKeyOpenSsl(crypto::ScopedEVP_PKEY key, |
| 61 const CryptoData& serialized_key_data); |
| 62 |
| 63 static AsymKeyOpenSsl* Cast(const blink::WebCryptoKey& key); |
| 64 |
| 65 virtual AsymKeyOpenSsl* AsAsymKey() OVERRIDE; |
| 66 |
| 67 EVP_PKEY* key() { return key_.get(); } |
| 68 |
| 69 private: |
| 70 crypto::ScopedEVP_PKEY key_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(AsymKeyOpenSsl); |
| 73 }; |
| 74 |
| 52 } // namespace webcrypto | 75 } // namespace webcrypto |
| 53 | 76 |
| 54 } // namespace content | 77 } // namespace content |
| 55 | 78 |
| 56 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_ | 79 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_ |
| OLD | NEW |