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_JWK_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_JWK_H_ |
6 #define CONTENT_CHILD_WEBCRYPTO_JWK_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_JWK_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
Ryan Sleevi
2014/07/18 23:02:54
Replace with stdint
| |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
13 #include "third_party/WebKit/public/platform/WebCrypto.h" | 13 #include "third_party/WebKit/public/platform/WebCrypto.h" |
14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 namespace webcrypto { | 18 namespace webcrypto { |
19 | 19 |
20 class CryptoData; | 20 class CryptoData; |
21 class Status; | 21 class Status; |
22 | 22 |
23 // Writes a JWK-formatted symmetric key to |jwk_key_data|. | 23 // Writes a JWK-formatted symmetric key to |jwk_key_data|. |
24 // * raw_key_data: The actual key data | 24 // * raw_key_data: The actual key data |
25 // * algorithm: The JWK algorithm name (i.e. "alg") | 25 // * algorithm: The JWK algorithm name (i.e. "alg") |
26 // * extractable: The JWK extractability (i.e. "ext") | 26 // * extractable: The JWK extractability (i.e. "ext") |
27 // * usage_mask: The JWK usages (i.e. "key_ops") | 27 // * usage_mask: The JWK usages (i.e. "key_ops") |
28 void WriteSecretKeyJwk(const CryptoData& raw_key_data, | 28 void WriteSecretKeyJwk(const CryptoData& raw_key_data, |
29 const std::string& algorithm, | 29 const std::string& algorithm, |
30 bool extractable, | 30 bool extractable, |
31 blink::WebCryptoKeyUsageMask usage_mask, | 31 blink::WebCryptoKeyUsageMask usage_mask, |
32 std::vector<uint8>* jwk_key_data); | 32 std::vector<uint8_t>* jwk_key_data); |
33 | 33 |
34 // Parses a UTF-8 encoded JWK (key_data), and extracts the key material to | 34 // Parses a UTF-8 encoded JWK (key_data), and extracts the key material to |
35 // |*raw_key_data|. Returns Status::Success() on success, otherwise an error. | 35 // |*raw_key_data|. Returns Status::Success() on success, otherwise an error. |
36 // In order for this to succeed: | 36 // In order for this to succeed: |
37 // * expected_algorithm must match the JWK's "alg", if present. | 37 // * expected_algorithm must match the JWK's "alg", if present. |
38 // * expected_extractable must be consistent with the JWK's "ext", if | 38 // * expected_extractable must be consistent with the JWK's "ext", if |
39 // present. | 39 // present. |
40 // * expected_usage_mask must be a subset of the JWK's "key_ops" if present. | 40 // * expected_usage_mask must be a subset of the JWK's "key_ops" if present. |
41 Status ReadSecretKeyJwk(const CryptoData& key_data, | 41 Status ReadSecretKeyJwk(const CryptoData& key_data, |
42 const std::string& expected_algorithm, | 42 const std::string& expected_algorithm, |
43 bool expected_extractable, | 43 bool expected_extractable, |
44 blink::WebCryptoKeyUsageMask expected_usage_mask, | 44 blink::WebCryptoKeyUsageMask expected_usage_mask, |
45 std::vector<uint8>* raw_key_data); | 45 std::vector<uint8_t>* raw_key_data); |
46 | 46 |
47 // Creates an AES algorithm name for the given key size (in bytes). For | 47 // Creates an AES algorithm name for the given key size (in bytes). For |
48 // instance "A128CBC" is the result of suffix="CBC", keylen_bytes=16. | 48 // instance "A128CBC" is the result of suffix="CBC", keylen_bytes=16. |
49 std::string MakeJwkAesAlgorithmName(const std::string& suffix, | 49 std::string MakeJwkAesAlgorithmName(const std::string& suffix, |
50 unsigned int keylen_bytes); | 50 unsigned int keylen_bytes); |
51 | 51 |
52 // This is very similar to ReadSecretKeyJwk(), except instead of specifying an | 52 // This is very similar to ReadSecretKeyJwk(), except instead of specifying an |
53 // absolut "expected_algorithm", the suffix for an AES algorithm name is given | 53 // absolut "expected_algorithm", the suffix for an AES algorithm name is given |
54 // (See MakeJwkAesAlgorithmName() for an explanation of what the suffix is). | 54 // (See MakeJwkAesAlgorithmName() for an explanation of what the suffix is). |
55 // | 55 // |
56 // This is because the algorithm name for AES keys is dependent on the length | 56 // This is because the algorithm name for AES keys is dependent on the length |
57 // of the key. This function expects key lengths to be either 128, 192, or 256 | 57 // of the key. This function expects key lengths to be either 128, 192, or 256 |
58 // bits. | 58 // bits. |
59 Status ReadAesSecretKeyJwk(const CryptoData& key_data, | 59 Status ReadAesSecretKeyJwk(const CryptoData& key_data, |
60 const std::string& algorithm_name_suffix, | 60 const std::string& algorithm_name_suffix, |
61 bool expected_extractable, | 61 bool expected_extractable, |
62 blink::WebCryptoKeyUsageMask expected_usage_mask, | 62 blink::WebCryptoKeyUsageMask expected_usage_mask, |
63 std::vector<uint8>* raw_key_data); | 63 std::vector<uint8_t>* raw_key_data); |
64 | 64 |
65 // Writes a JWK-formated RSA public key and saves the result to | 65 // Writes a JWK-formated RSA public key and saves the result to |
66 // |*jwk_key_data|. | 66 // |*jwk_key_data|. |
67 void WriteRsaPublicKeyJwk(const CryptoData& n, | 67 void WriteRsaPublicKeyJwk(const CryptoData& n, |
68 const CryptoData& e, | 68 const CryptoData& e, |
69 const std::string& algorithm, | 69 const std::string& algorithm, |
70 bool extractable, | 70 bool extractable, |
71 blink::WebCryptoKeyUsageMask usage_mask, | 71 blink::WebCryptoKeyUsageMask usage_mask, |
72 std::vector<uint8>* jwk_key_data); | 72 std::vector<uint8_t>* jwk_key_data); |
73 | 73 |
74 // Writes a JWK-formated RSA private key and saves the result to | 74 // Writes a JWK-formated RSA private key and saves the result to |
75 // |*jwk_key_data|. | 75 // |*jwk_key_data|. |
76 void WriteRsaPrivateKeyJwk(const CryptoData& n, | 76 void WriteRsaPrivateKeyJwk(const CryptoData& n, |
77 const CryptoData& e, | 77 const CryptoData& e, |
78 const CryptoData& d, | 78 const CryptoData& d, |
79 const CryptoData& p, | 79 const CryptoData& p, |
80 const CryptoData& q, | 80 const CryptoData& q, |
81 const CryptoData& dp, | 81 const CryptoData& dp, |
82 const CryptoData& dq, | 82 const CryptoData& dq, |
83 const CryptoData& qi, | 83 const CryptoData& qi, |
84 const std::string& algorithm, | 84 const std::string& algorithm, |
85 bool extractable, | 85 bool extractable, |
86 blink::WebCryptoKeyUsageMask usage_mask, | 86 blink::WebCryptoKeyUsageMask usage_mask, |
87 std::vector<uint8>* jwk_key_data); | 87 std::vector<uint8_t>* jwk_key_data); |
88 | 88 |
89 // Describes the RSA components for a parsed key. The names of the properties | 89 // Describes the RSA components for a parsed key. The names of the properties |
90 // correspond with those from the JWK spec. Note that Chromium's WebCrypto | 90 // correspond with those from the JWK spec. Note that Chromium's WebCrypto |
91 // implementation does not support multi-primes, so there is no parsed field | 91 // implementation does not support multi-primes, so there is no parsed field |
92 // for othinfo. | 92 // for othinfo. |
93 struct JwkRsaInfo { | 93 struct JwkRsaInfo { |
94 JwkRsaInfo(); | 94 JwkRsaInfo(); |
95 ~JwkRsaInfo(); | 95 ~JwkRsaInfo(); |
96 | 96 |
97 bool is_private_key; | 97 bool is_private_key; |
(...skipping 20 matching lines...) Expand all Loading... | |
118 blink::WebCryptoKeyUsageMask expected_usage_mask, | 118 blink::WebCryptoKeyUsageMask expected_usage_mask, |
119 JwkRsaInfo* result); | 119 JwkRsaInfo* result); |
120 | 120 |
121 const char* GetJwkHmacAlgorithmName(blink::WebCryptoAlgorithmId hash); | 121 const char* GetJwkHmacAlgorithmName(blink::WebCryptoAlgorithmId hash); |
122 | 122 |
123 } // namespace webcrypto | 123 } // namespace webcrypto |
124 | 124 |
125 } // namespace content | 125 } // namespace content |
126 | 126 |
127 #endif // CONTENT_CHILD_WEBCRYPTO_JWK_H_ | 127 #endif // CONTENT_CHILD_WEBCRYPTO_JWK_H_ |
OLD | NEW |