| 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_SHARED_CRYPTO_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_SHARED_CRYPTO_H_ |
| 6 #define CONTENT_CHILD_WEBCRYPTO_SHARED_CRYPTO_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_SHARED_CRYPTO_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 14 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| 13 #include "third_party/WebKit/public/platform/WebCrypto.h" | 15 #include "third_party/WebKit/public/platform/WebCrypto.h" |
| 14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| 17 | 19 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 // | 32 // |
| 31 // Blink | 33 // Blink |
| 32 // | | 34 // | |
| 33 // ==============|========================== | 35 // ==============|========================== |
| 34 // | | 36 // | |
| 35 // content | 37 // content |
| 36 // | | 38 // | |
| 37 // | | 39 // | |
| 38 // v | 40 // v |
| 39 // WebCryptoImpl (Implements the blink::WebCrypto interface for | 41 // WebCryptoImpl (Implements the blink::WebCrypto interface for |
| 40 // | asynchronous completions) | 42 // | asynchronous completions; posts tasks to |
| 43 // | the webcrypto worker pool to fulfill the request |
| 44 // using the synchronous methods of shared_crypto.h) |
| 41 // | | 45 // | |
| 42 // | [shared_crypto_unittest.cc] | 46 // | [shared_crypto_unittest.cc] |
| 43 // | / | 47 // | / |
| 44 // | / (The blink::WebCrypto interface is not | 48 // | / (The blink::WebCrypto interface is not |
| 45 // | / testable from the chromium side because | 49 // | / testable from the chromium side because |
| 46 // | / the result object is not mockable. | 50 // | / the result object is not mockable. |
| 47 // | / Tests are done on shared_crypto instead. | 51 // | / Tests are done on shared_crypto instead. |
| 48 // V v | 52 // V v |
| 49 // [shared_crypto.h] (Exposes synchronous functions in the | 53 // [shared_crypto.h] (Exposes synchronous functions in the |
| 50 // | webcrypto:: namespace. This does | 54 // | webcrypto:: namespace. This does |
| 51 // | common validations, infers default | 55 // | common validations, infers default |
| 52 // | parameters, and casts the algorithm | 56 // | parameters, and casts the algorithm |
| 53 // | parameters to the right types) | 57 // | parameters to the right types) |
| 54 // | | 58 // | |
| 55 // V | 59 // V |
| 56 // [platform_crypto.h] (Exposes functions in the webcrypto::platform | 60 // [platform_crypto.h] (Exposes functions in the webcrypto::platform |
| 57 // | namespace) | 61 // | namespace) |
| 58 // | | 62 // | |
| 59 // | | 63 // | |
| 60 // V | 64 // V |
| 61 // [platform_crypto_{nss|openssl}.cc] (Implements using the platform crypto | 65 // [platform_crypto_{nss|openssl}.cc] (Implements using the platform crypto |
| 62 // library) | 66 // library) |
| 63 // | 67 // |
| 64 // The shared_crypto.h functions are responsible for: | 68 // The shared_crypto.h functions are responsible for: |
| 65 // | 69 // |
| 66 // * Validating the key usages | 70 // * Validating the key usages |
| 67 // * Inferring default parameters when not specified | 71 // * Inferring default parameters when not specified |
| 68 // * Validating key exportability | 72 // * Validating key exportability |
| 69 // * Validating algorithm with key.algorithm | 73 // * Validating algorithm with key.algorithm |
| 70 // * Converting the blink key to a more specific platform::{PublicKey, | 74 // * Converting the Blink key to a more specific platform::{PublicKey, |
| 71 // PrivateKey, SymKey} and making sure it was the right type. | 75 // PrivateKey, SymKey} and making sure it was the right type. |
| 72 // * Validating alogorithm specific parameters (for instance, was the iv for | 76 // * Validating alogorithm specific parameters (for instance, was the iv for |
| 73 // AES-CBC 16 bytes). | 77 // AES-CBC 16 bytes). |
| 74 // * Parse a JWK | 78 // * Parse a JWK |
| 75 | 79 |
| 76 CONTENT_EXPORT Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 80 CONTENT_EXPORT Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 77 const blink::WebCryptoKey& key, | 81 const blink::WebCryptoKey& key, |
| 78 const CryptoData& data, | 82 const CryptoData& data, |
| 79 blink::WebArrayBuffer* buffer); | 83 std::vector<uint8>* buffer); |
| 80 | 84 |
| 81 CONTENT_EXPORT Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 85 CONTENT_EXPORT Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 82 const blink::WebCryptoKey& key, | 86 const blink::WebCryptoKey& key, |
| 83 const CryptoData& data, | 87 const CryptoData& data, |
| 84 blink::WebArrayBuffer* buffer); | 88 std::vector<uint8>* buffer); |
| 85 | 89 |
| 86 CONTENT_EXPORT Status Digest(const blink::WebCryptoAlgorithm& algorithm, | 90 CONTENT_EXPORT Status Digest(const blink::WebCryptoAlgorithm& algorithm, |
| 87 const CryptoData& data, | 91 const CryptoData& data, |
| 88 blink::WebArrayBuffer* buffer); | 92 std::vector<uint8>* buffer); |
| 89 | 93 |
| 90 CONTENT_EXPORT scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( | 94 CONTENT_EXPORT scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( |
| 91 blink::WebCryptoAlgorithmId algorithm); | 95 blink::WebCryptoAlgorithmId algorithm); |
| 92 | 96 |
| 93 CONTENT_EXPORT Status | 97 CONTENT_EXPORT Status |
| 94 GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm, | 98 GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm, |
| 95 bool extractable, | 99 bool extractable, |
| 96 blink::WebCryptoKeyUsageMask usage_mask, | 100 blink::WebCryptoKeyUsageMask usage_mask, |
| 97 blink::WebCryptoKey* key); | 101 blink::WebCryptoKey* key); |
| 98 | 102 |
| 99 CONTENT_EXPORT Status | 103 CONTENT_EXPORT Status |
| 100 GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm, | 104 GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm, |
| 101 bool extractable, | 105 bool extractable, |
| 102 blink::WebCryptoKeyUsageMask usage_mask, | 106 blink::WebCryptoKeyUsageMask usage_mask, |
| 103 blink::WebCryptoKey* public_key, | 107 blink::WebCryptoKey* public_key, |
| 104 blink::WebCryptoKey* private_key); | 108 blink::WebCryptoKey* private_key); |
| 105 | 109 |
| 106 CONTENT_EXPORT Status ImportKey(blink::WebCryptoKeyFormat format, | 110 CONTENT_EXPORT Status ImportKey(blink::WebCryptoKeyFormat format, |
| 107 const CryptoData& key_data, | 111 const CryptoData& key_data, |
| 108 const blink::WebCryptoAlgorithm& algorithm, | 112 const blink::WebCryptoAlgorithm& algorithm, |
| 109 bool extractable, | 113 bool extractable, |
| 110 blink::WebCryptoKeyUsageMask usage_mask, | 114 blink::WebCryptoKeyUsageMask usage_mask, |
| 111 blink::WebCryptoKey* key); | 115 blink::WebCryptoKey* key); |
| 112 | 116 |
| 113 CONTENT_EXPORT Status ExportKey(blink::WebCryptoKeyFormat format, | 117 CONTENT_EXPORT Status ExportKey(blink::WebCryptoKeyFormat format, |
| 114 const blink::WebCryptoKey& key, | 118 const blink::WebCryptoKey& key, |
| 115 blink::WebArrayBuffer* buffer); | 119 std::vector<uint8>* buffer); |
| 116 | 120 |
| 117 CONTENT_EXPORT Status Sign(const blink::WebCryptoAlgorithm& algorithm, | 121 CONTENT_EXPORT Status Sign(const blink::WebCryptoAlgorithm& algorithm, |
| 118 const blink::WebCryptoKey& key, | 122 const blink::WebCryptoKey& key, |
| 119 const CryptoData& data, | 123 const CryptoData& data, |
| 120 blink::WebArrayBuffer* buffer); | 124 std::vector<uint8>* buffer); |
| 121 | 125 |
| 122 CONTENT_EXPORT Status | 126 CONTENT_EXPORT Status |
| 123 VerifySignature(const blink::WebCryptoAlgorithm& algorithm, | 127 VerifySignature(const blink::WebCryptoAlgorithm& algorithm, |
| 124 const blink::WebCryptoKey& key, | 128 const blink::WebCryptoKey& key, |
| 125 const CryptoData& signature, | 129 const CryptoData& signature, |
| 126 const CryptoData& data, | 130 const CryptoData& data, |
| 127 bool* signature_match); | 131 bool* signature_match); |
| 128 | 132 |
| 129 CONTENT_EXPORT Status | 133 CONTENT_EXPORT Status |
| 130 WrapKey(blink::WebCryptoKeyFormat format, | 134 WrapKey(blink::WebCryptoKeyFormat format, |
| 131 const blink::WebCryptoKey& wrapping_key, | 135 const blink::WebCryptoKey& wrapping_key, |
| 132 const blink::WebCryptoKey& key_to_wrap, | 136 const blink::WebCryptoKey& key_to_wrap, |
| 133 const blink::WebCryptoAlgorithm& wrapping_algorithm, | 137 const blink::WebCryptoAlgorithm& wrapping_algorithm, |
| 134 blink::WebArrayBuffer* buffer); | 138 std::vector<uint8>* buffer); |
| 135 | 139 |
| 136 CONTENT_EXPORT Status | 140 CONTENT_EXPORT Status |
| 137 UnwrapKey(blink::WebCryptoKeyFormat format, | 141 UnwrapKey(blink::WebCryptoKeyFormat format, |
| 138 const CryptoData& wrapped_key_data, | 142 const CryptoData& wrapped_key_data, |
| 139 const blink::WebCryptoKey& wrapping_key, | 143 const blink::WebCryptoKey& wrapping_key, |
| 140 const blink::WebCryptoAlgorithm& wrapping_algorithm, | 144 const blink::WebCryptoAlgorithm& wrapping_algorithm, |
| 141 const blink::WebCryptoAlgorithm& algorithm, | 145 const blink::WebCryptoAlgorithm& algorithm, |
| 142 bool extractable, | 146 bool extractable, |
| 143 blink::WebCryptoKeyUsageMask usage_mask, | 147 blink::WebCryptoKeyUsageMask usage_mask, |
| 144 blink::WebCryptoKey* key); | 148 blink::WebCryptoKey* key); |
| 145 | 149 |
| 146 CONTENT_EXPORT Status | 150 // Called on the target Blink thread. |
| 147 SerializeKeyForClone(const blink::WebCryptoKey& key, | 151 CONTENT_EXPORT bool SerializeKeyForClone(const blink::WebCryptoKey& key, |
| 148 blink::WebVector<unsigned char>* data); | 152 blink::WebVector<uint8>* key_data); |
| 149 | 153 |
| 150 CONTENT_EXPORT Status | 154 // Called on the target Blink thread. |
| 151 DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm, | 155 CONTENT_EXPORT bool DeserializeKeyForClone( |
| 152 blink::WebCryptoKeyType type, | 156 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 153 bool extractable, | 157 blink::WebCryptoKeyType type, |
| 154 blink::WebCryptoKeyUsageMask usage_mask, | 158 bool extractable, |
| 155 const CryptoData& key_data, | 159 blink::WebCryptoKeyUsageMask usage_mask, |
| 156 blink::WebCryptoKey* key); | 160 const CryptoData& key_data, |
| 161 blink::WebCryptoKey* key); |
| 157 | 162 |
| 158 } // namespace webcrypto | 163 } // namespace webcrypto |
| 159 | 164 |
| 160 } // namespace content | 165 } // namespace content |
| 161 | 166 |
| 162 #endif // CONTENT_CHILD_WEBCRYPTO_SHARED_CRYPTO_H_ | 167 #endif // CONTENT_CHILD_WEBCRYPTO_SHARED_CRYPTO_H_ |
| OLD | NEW |