| 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_WEBCRYPTO_UTIL_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
| 6 #define CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/strings/string_piece.h" | |
| 12 #include "base/values.h" | |
| 13 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 14 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| 15 #include "third_party/WebKit/public/platform/WebCrypto.h" // TODO(eroman): dele
te | 13 #include "third_party/WebKit/public/platform/WebCrypto.h" // TODO(eroman): dele
te |
| 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 17 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 15 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
| 18 | 16 |
| 19 namespace content { | 17 namespace content { |
| 20 | 18 |
| 21 namespace webcrypto { | 19 namespace webcrypto { |
| 22 | 20 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 static Status ErrorJwkPropertyMissing(const std::string& property); | 66 static Status ErrorJwkPropertyMissing(const std::string& property); |
| 69 | 67 |
| 70 // The property |property| was not of type |expected_type|. | 68 // The property |property| was not of type |expected_type|. |
| 71 static Status ErrorJwkPropertyWrongType(const std::string& property, | 69 static Status ErrorJwkPropertyWrongType(const std::string& property, |
| 72 const std::string& expected_type); | 70 const std::string& expected_type); |
| 73 | 71 |
| 74 // The property |property| was a string, however could not be successfully | 72 // The property |property| was a string, however could not be successfully |
| 75 // base64 decoded. | 73 // base64 decoded. |
| 76 static Status ErrorJwkBase64Decode(const std::string& property); | 74 static Status ErrorJwkBase64Decode(const std::string& property); |
| 77 | 75 |
| 78 // The "ext" parameter was specified but was | 76 // The "extractable" parameter was specified but was |
| 79 // incompatible with the value requested by the Web Crypto call. | 77 // incompatible with the value requested by the Web Crypto call. |
| 80 static Status ErrorJwkExtInconsistent(); | 78 static Status ErrorJwkExtractableInconsistent(); |
| 81 | 79 |
| 82 // The "alg" parameter could not be converted to an equivalent | 80 // The "alg" parameter could not be converted to an equivalent |
| 83 // WebCryptoAlgorithm. Either it was malformed or unrecognized. | 81 // WebCryptoAlgorithm. Either it was malformed or unrecognized. |
| 84 static Status ErrorJwkUnrecognizedAlgorithm(); | 82 static Status ErrorJwkUnrecognizedAlgorithm(); |
| 85 | 83 |
| 86 // The "alg" parameter is incompatible with the (optional) Algorithm | 84 // The "alg" parameter is incompatible with the (optional) Algorithm |
| 87 // specified by the Web Crypto import operation. | 85 // specified by the Web Crypto import operation. |
| 88 static Status ErrorJwkAlgorithmInconsistent(); | 86 static Status ErrorJwkAlgorithmInconsistent(); |
| 89 | 87 |
| 90 // The "alg" parameter was not provided, however neither was an algorithm | 88 // The "alg" parameter was not provided, however neither was an algorithm |
| 91 // provided by the Web Crypto import operation. | 89 // provided by the Web Crypto import operation. |
| 92 static Status ErrorJwkAlgorithmMissing(); | 90 static Status ErrorJwkAlgorithmMissing(); |
| 93 | 91 |
| 94 // The "use" parameter was specified, however it couldn't be converted to an | 92 // The "use" parameter was specified, however it couldn't be converted to an |
| 95 // equivalent Web Crypto usage. | 93 // equivalent Web Crypto usage. |
| 96 static Status ErrorJwkUnrecognizedUse(); | 94 static Status ErrorJwkUnrecognizedUsage(); |
| 97 | |
| 98 // The "key_ops" parameter was specified, however one of the values in the | |
| 99 // array couldn't be converted to an equivalent Web Crypto usage. | |
| 100 static Status ErrorJwkUnrecognizedKeyop(); | |
| 101 | 95 |
| 102 // The "use" parameter was specified, however it is incompatible with that | 96 // The "use" parameter was specified, however it is incompatible with that |
| 103 // specified by the Web Crypto import operation. | 97 // specified by the Web Crypto import operation. |
| 104 static Status ErrorJwkUseInconsistent(); | 98 static Status ErrorJwkUsageInconsistent(); |
| 105 | |
| 106 // The "key_ops" parameter was specified, however it is incompatible with that | |
| 107 // specified by the Web Crypto import operation. | |
| 108 static Status ErrorJwkKeyopsInconsistent(); | |
| 109 | |
| 110 // Both the "key_ops" and the "use" parameters were specified, however they | |
| 111 // are incompatible with each other. | |
| 112 static Status ErrorJwkUseAndKeyopsInconsistent(); | |
| 113 | 99 |
| 114 // TODO(eroman): Private key import through JWK is not yet supported. | 100 // TODO(eroman): Private key import through JWK is not yet supported. |
| 115 static Status ErrorJwkRsaPrivateKeyUnsupported(); | 101 static Status ErrorJwkRsaPrivateKeyUnsupported(); |
| 116 | 102 |
| 117 // The "kty" parameter was given and was a string, however it was | 103 // The "kty" parameter was given and was a string, however it was |
| 118 // unrecognized. | 104 // unrecognized. |
| 119 static Status ErrorJwkUnrecognizedKty(); | 105 static Status ErrorJwkUnrecognizedKty(); |
| 120 | 106 |
| 121 // The amount of key data provided was incompatible with the selected | 107 // The amount of key data provided was incompatible with the selected |
| 122 // algorithm. For instance if the algorith name was A128CBC then EXACTLY | 108 // algorithm. For instance if the algorith name was A128CBC then EXACTLY |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned int new_size); | 211 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned int new_size); |
| 226 | 212 |
| 227 // Creates a WebArrayBuffer from a uint8 byte array | 213 // Creates a WebArrayBuffer from a uint8 byte array |
| 228 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data, | 214 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data, |
| 229 unsigned int data_size); | 215 unsigned int data_size); |
| 230 | 216 |
| 231 // TODO(eroman): Move this to JWK file. | 217 // TODO(eroman): Move this to JWK file. |
| 232 // This function decodes unpadded 'base64url' encoded data, as described in | 218 // This function decodes unpadded 'base64url' encoded data, as described in |
| 233 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. | 219 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. |
| 234 // In Web Crypto, this type of encoding is only used inside JWK. | 220 // In Web Crypto, this type of encoding is only used inside JWK. |
| 235 CONTENT_EXPORT bool Base64DecodeUrlSafe(const std::string& input, | 221 bool Base64DecodeUrlSafe(const std::string& input, std::string* output); |
| 236 std::string* output); | |
| 237 | |
| 238 // Returns an unpadded 'base64url' encoding of the input data, the opposite of | |
| 239 // Base64DecodeUrlSafe() above. | |
| 240 std::string Base64EncodeUrlSafe(const base::StringPiece& input); | |
| 241 | |
| 242 // Composes a Web Crypto usage mask from an array of JWK key_ops values. | |
| 243 CONTENT_EXPORT Status GetWebCryptoUsagesFromJwkKeyOps( | |
| 244 const base::ListValue* jwk_key_ops_value, | |
| 245 blink::WebCryptoKeyUsageMask* jwk_key_ops_mask); | |
| 246 | |
| 247 // Composes a JWK key_ops array from a Web Crypto usage mask. | |
| 248 base::ListValue* CreateJwkKeyOpsFromWebCryptoUsages( | |
| 249 blink::WebCryptoKeyUsageMask usage_mask); | |
| 250 | 222 |
| 251 CONTENT_EXPORT bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id); | 223 CONTENT_EXPORT bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id); |
| 252 | 224 |
| 253 // Returns the "hash" param for an algorithm if it exists, otherwise returns | 225 // Returns the "hash" param for an algorithm if it exists, otherwise returns |
| 254 // a null algorithm. | 226 // a null algorithm. |
| 255 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( | 227 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( |
| 256 const blink::WebCryptoAlgorithm& algorithm); | 228 const blink::WebCryptoAlgorithm& algorithm); |
| 257 | 229 |
| 258 // Creates a WebCryptoAlgorithm without any parameters. | 230 // Creates a WebCryptoAlgorithm without any parameters. |
| 259 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateAlgorithm( | 231 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateAlgorithm( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 281 | 253 |
| 282 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 254 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
| 283 unsigned keylen_bytes, | 255 unsigned keylen_bytes, |
| 284 blink::WebCryptoKeyAlgorithm* key_algorithm); | 256 blink::WebCryptoKeyAlgorithm* key_algorithm); |
| 285 | 257 |
| 286 } // namespace webcrypto | 258 } // namespace webcrypto |
| 287 | 259 |
| 288 } // namespace content | 260 } // namespace content |
| 289 | 261 |
| 290 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 262 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
| OLD | NEW |