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 "content/child/webcrypto/structured_clone.h" | 5 #include "content/child/webcrypto/structured_clone.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/child/webcrypto/algorithm_dispatch.h" | 8 #include "content/child/webcrypto/algorithm_dispatch.h" |
9 #include "content/child/webcrypto/platform_crypto.h" | 9 #include "content/child/webcrypto/platform_crypto.h" |
10 #include "content/child/webcrypto/status.h" | 10 #include "content/child/webcrypto/status.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 blink::WebCryptoAlgorithm KeyAlgorithmToImportAlgorithm( | 37 blink::WebCryptoAlgorithm KeyAlgorithmToImportAlgorithm( |
38 const blink::WebCryptoKeyAlgorithm& algorithm) { | 38 const blink::WebCryptoKeyAlgorithm& algorithm) { |
39 switch (algorithm.paramsType()) { | 39 switch (algorithm.paramsType()) { |
40 case blink::WebCryptoKeyAlgorithmParamsTypeAes: | 40 case blink::WebCryptoKeyAlgorithmParamsTypeAes: |
41 return CreateAlgorithm(algorithm.id()); | 41 return CreateAlgorithm(algorithm.id()); |
42 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | 42 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
43 return CreateHmacImportAlgorithm(algorithm.hmacParams()->hash().id()); | 43 return CreateHmacImportAlgorithm(algorithm.hmacParams()->hash().id()); |
44 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: | 44 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
45 return CreateRsaHashedImportAlgorithm( | 45 return CreateRsaHashedImportAlgorithm( |
46 algorithm.id(), algorithm.rsaHashedParams()->hash().id()); | 46 algorithm.id(), algorithm.rsaHashedParams()->hash().id()); |
| 47 case blink::WebCryptoKeyAlgorithmParamsTypeEc: |
| 48 return CreateEcImportAlgorithm(algorithm.id(), |
| 49 algorithm.ecParams()->namedCurve()); |
47 case blink::WebCryptoKeyAlgorithmParamsTypeNone: | 50 case blink::WebCryptoKeyAlgorithmParamsTypeNone: |
48 break; | 51 break; |
49 default: | 52 default: |
50 break; | 53 break; |
51 } | 54 } |
| 55 NOTREACHED(); |
52 return blink::WebCryptoAlgorithm::createNull(); | 56 return blink::WebCryptoAlgorithm::createNull(); |
53 } | 57 } |
54 | 58 |
55 // There is some duplicated information in the serialized format used by | 59 // There is some duplicated information in the serialized format used by |
56 // structured clone (since the KeyAlgorithm is serialized separately from the | 60 // structured clone (since the KeyAlgorithm is serialized separately from the |
57 // key data). Use this extra information to further validate what was | 61 // key data). Use this extra information to further validate what was |
58 // deserialized from the key data. | 62 // deserialized from the key data. |
59 // | 63 // |
60 // A failure here implies either a bug in the code, or that the serialized data | 64 // A failure here implies either a bug in the code, or that the serialized data |
61 // was corrupted. | 65 // was corrupted. |
(...skipping 18 matching lines...) Expand all Loading... |
80 return false; | 84 return false; |
81 if (algorithm.rsaHashedParams()->publicExponent().size() != | 85 if (algorithm.rsaHashedParams()->publicExponent().size() != |
82 key.algorithm().rsaHashedParams()->publicExponent().size()) | 86 key.algorithm().rsaHashedParams()->publicExponent().size()) |
83 return false; | 87 return false; |
84 if (memcmp(algorithm.rsaHashedParams()->publicExponent().data(), | 88 if (memcmp(algorithm.rsaHashedParams()->publicExponent().data(), |
85 key.algorithm().rsaHashedParams()->publicExponent().data(), | 89 key.algorithm().rsaHashedParams()->publicExponent().data(), |
86 key.algorithm().rsaHashedParams()->publicExponent().size()) != | 90 key.algorithm().rsaHashedParams()->publicExponent().size()) != |
87 0) | 91 0) |
88 return false; | 92 return false; |
89 break; | 93 break; |
| 94 case blink::WebCryptoKeyAlgorithmParamsTypeEc: |
| 95 return algorithm.ecParams()->namedCurve() == |
| 96 key.algorithm().ecParams()->namedCurve(); |
90 case blink::WebCryptoKeyAlgorithmParamsTypeNone: | 97 case blink::WebCryptoKeyAlgorithmParamsTypeNone: |
91 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | 98 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
92 break; | 99 break; |
93 default: | 100 default: |
| 101 NOTREACHED(); |
94 return false; | 102 return false; |
95 } | 103 } |
96 | 104 |
97 return true; | 105 return true; |
98 } | 106 } |
99 | 107 |
100 } // namespace | 108 } // namespace |
101 | 109 |
102 // Note that this function is called from the target Blink thread. | 110 // Note that this function is called from the target Blink thread. |
103 bool SerializeKeyForClone(const blink::WebCryptoKey& key, | 111 bool SerializeKeyForClone(const blink::WebCryptoKey& key, |
(...skipping 23 matching lines...) Expand all Loading... |
127 usages, | 135 usages, |
128 key); | 136 key); |
129 if (status.IsError()) | 137 if (status.IsError()) |
130 return false; | 138 return false; |
131 return ValidateDeserializedKey(*key, algorithm, type); | 139 return ValidateDeserializedKey(*key, algorithm, type); |
132 } | 140 } |
133 | 141 |
134 } // namespace webcrypto | 142 } // namespace webcrypto |
135 | 143 |
136 } // namespace content | 144 } // namespace content |
OLD | NEW |