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 #include <algorithm> | 5 #include <algorithm> |
6 #include <functional> | 6 #include <functional> |
7 #include <map> | 7 #include <map> |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 158 |
159 base::LazyInstance<JwkAlgorithmRegistry> jwk_alg_registry = | 159 base::LazyInstance<JwkAlgorithmRegistry> jwk_alg_registry = |
160 LAZY_INSTANCE_INITIALIZER; | 160 LAZY_INSTANCE_INITIALIZER; |
161 | 161 |
162 bool ImportAlgorithmsConsistent(const blink::WebCryptoAlgorithm& alg1, | 162 bool ImportAlgorithmsConsistent(const blink::WebCryptoAlgorithm& alg1, |
163 const blink::WebCryptoAlgorithm& alg2) { | 163 const blink::WebCryptoAlgorithm& alg2) { |
164 DCHECK(!alg1.isNull()); | 164 DCHECK(!alg1.isNull()); |
165 DCHECK(!alg2.isNull()); | 165 DCHECK(!alg2.isNull()); |
166 if (alg1.id() != alg2.id()) | 166 if (alg1.id() != alg2.id()) |
167 return false; | 167 return false; |
168 if (alg1.paramsType() != alg2.paramsType()) | 168 // Inner hash algorithms must be compared too, but only if present. |
169 return false; | 169 if (alg1.paramsType() == |
eroman
2014/03/18 06:18:39
I am not sure that I understand the change made he
padolph
2014/03/18 17:52:19
Without this change the RsaEsJwkSymkeyWrapUnwrapRo
eroman
2014/03/19 04:04:00
I see thanks for explaining.
That sounds like a p
| |
170 switch (alg1.paramsType()) { | 170 blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams || |
171 case blink::WebCryptoAlgorithmParamsTypeNone: | 171 alg1.paramsType() == |
172 return true; | 172 blink::WebCryptoAlgorithmParamsTypeHmacImportParams) { |
173 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: | 173 if (alg1.paramsType() != alg2.paramsType()) |
174 return ImportAlgorithmsConsistent(alg1.rsaHashedImportParams()->hash(), | |
175 alg2.rsaHashedImportParams()->hash()); | |
176 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: | |
177 return ImportAlgorithmsConsistent(alg1.hmacImportParams()->hash(), | |
178 alg2.hmacImportParams()->hash()); | |
179 default: | |
180 return false; | 174 return false; |
175 switch (alg1.paramsType()) { | |
176 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: | |
177 return ImportAlgorithmsConsistent(alg1.rsaHashedImportParams()->hash(), | |
178 alg2.rsaHashedImportParams()->hash()); | |
179 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: | |
180 return ImportAlgorithmsConsistent(alg1.hmacImportParams()->hash(), | |
181 alg2.hmacImportParams()->hash()); | |
182 default: | |
183 return false; | |
184 } | |
181 } | 185 } |
186 return true; | |
182 } | 187 } |
183 | 188 |
184 // Extracts the required string property with key |path| from |dict| and saves | 189 // Extracts the required string property with key |path| from |dict| and saves |
185 // the result to |*result|. If the property does not exist or is not a string, | 190 // the result to |*result|. If the property does not exist or is not a string, |
186 // returns an error. | 191 // returns an error. |
187 Status GetJwkString(base::DictionaryValue* dict, | 192 Status GetJwkString(base::DictionaryValue* dict, |
188 const std::string& path, | 193 const std::string& path, |
189 std::string* result) { | 194 std::string* result) { |
190 base::Value* value = NULL; | 195 base::Value* value = NULL; |
191 if (!dict->Get(path, &value)) | 196 if (!dict->Get(path, &value)) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 } // namespace | 389 } // namespace |
385 | 390 |
386 Status ImportKeyJwk(const CryptoData& key_data, | 391 Status ImportKeyJwk(const CryptoData& key_data, |
387 const blink::WebCryptoAlgorithm& algorithm_or_null, | 392 const blink::WebCryptoAlgorithm& algorithm_or_null, |
388 bool extractable, | 393 bool extractable, |
389 blink::WebCryptoKeyUsageMask usage_mask, | 394 blink::WebCryptoKeyUsageMask usage_mask, |
390 blink::WebCryptoKey* key) { | 395 blink::WebCryptoKey* key) { |
391 // TODO(padolph): Generalize this comment to include export, and move to top | 396 // TODO(padolph): Generalize this comment to include export, and move to top |
392 // of file. | 397 // of file. |
393 | 398 |
394 // TODO(padolph): Generalize this comment to include export, and move to top | |
395 // of file. | |
396 | |
397 // The goal of this method is to extract key material and meta data from the | 399 // The goal of this method is to extract key material and meta data from the |
398 // incoming JWK, combine them with the input parameters, and ultimately import | 400 // incoming JWK, combine them with the input parameters, and ultimately import |
399 // a Web Crypto Key. | 401 // a Web Crypto Key. |
400 // | 402 // |
401 // JSON Web Key Format (JWK) | 403 // JSON Web Key Format (JWK) |
402 // http://tools.ietf.org/html/draft-ietf-jose-json-web-key-21 | 404 // http://tools.ietf.org/html/draft-ietf-jose-json-web-key-21 |
403 // | 405 // |
404 // A JWK is a simple JSON dictionary with the following entries | 406 // A JWK is a simple JSON dictionary with the following entries |
405 // - "kty" (Key Type) Parameter, REQUIRED | 407 // - "kty" (Key Type) Parameter, REQUIRED |
406 // - <kty-specific parameters, see below>, REQUIRED | 408 // - <kty-specific parameters, see below>, REQUIRED |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 std::string json; | 768 std::string json; |
767 base::JSONWriter::Write(&jwk_dict, &json); | 769 base::JSONWriter::Write(&jwk_dict, &json); |
768 *buffer = CreateArrayBuffer(reinterpret_cast<const uint8*>(json.data()), | 770 *buffer = CreateArrayBuffer(reinterpret_cast<const uint8*>(json.data()), |
769 json.size()); | 771 json.size()); |
770 return Status::Success(); | 772 return Status::Success(); |
771 } | 773 } |
772 | 774 |
773 } // namespace webcrypto | 775 } // namespace webcrypto |
774 | 776 |
775 } // namespace content | 777 } // namespace content |
OLD | NEW |