OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ScriptPromise promise = result->promise(); | 143 ScriptPromise promise = result->promise(); |
144 | 144 |
145 blink::WebCryptoKeyUsageMask keyUsages; | 145 blink::WebCryptoKeyUsageMask keyUsages; |
146 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) | 146 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) |
147 return promise; | 147 return promise; |
148 | 148 |
149 blink::WebCryptoAlgorithm algorithm; | 149 blink::WebCryptoAlgorithm algorithm; |
150 if (!parseAlgorithm(rawAlgorithm, GenerateKey, algorithm, result.get())) | 150 if (!parseAlgorithm(rawAlgorithm, GenerateKey, algorithm, result.get())) |
151 return promise; | 151 return promise; |
152 | 152 |
| 153 if (!verifyUsagesAreConsistentForAlgorithm(algorithm.id(), keyUsages, result
.get())) |
| 154 return promise; |
| 155 |
153 blink::Platform::current()->crypto()->generateKey(algorithm, extractable, ke
yUsages, result->result()); | 156 blink::Platform::current()->crypto()->generateKey(algorithm, extractable, ke
yUsages, result->result()); |
154 return promise; | 157 return promise; |
155 } | 158 } |
156 | 159 |
157 ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView*
keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>&
rawKeyUsages) | 160 ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView*
keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>&
rawKeyUsages) |
158 { | 161 { |
159 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); | 162 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); |
160 ScriptPromise promise = result->promise(); | 163 ScriptPromise promise = result->promise(); |
161 | 164 |
162 if (!ensureNotNull(keyData, "keyData", result.get())) | 165 if (!ensureNotNull(keyData, "keyData", result.get())) |
163 return promise; | 166 return promise; |
164 | 167 |
165 blink::WebCryptoKeyFormat format; | 168 blink::WebCryptoKeyFormat format; |
166 if (!Key::parseFormat(rawFormat, format, result.get())) | 169 if (!Key::parseFormat(rawFormat, format, result.get())) |
167 return promise; | 170 return promise; |
168 | 171 |
169 blink::WebCryptoKeyUsageMask keyUsages; | 172 blink::WebCryptoKeyUsageMask keyUsages; |
170 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) | 173 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) |
171 return promise; | 174 return promise; |
172 | 175 |
173 blink::WebCryptoAlgorithm algorithm; | 176 blink::WebCryptoAlgorithm algorithm; |
174 if (!parseAlgorithm(rawAlgorithm, ImportKey, algorithm, result.get())) | 177 if (!parseAlgorithm(rawAlgorithm, ImportKey, algorithm, result.get())) |
175 return promise; | 178 return promise; |
176 | 179 |
| 180 if (!verifyUsagesAreConsistentForAlgorithm(algorithm.id(), keyUsages, result
.get())) |
| 181 return promise; |
| 182 |
177 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); | 183 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); |
178 | 184 |
179 blink::Platform::current()->crypto()->importKey(format, keyDataBytes, keyDat
a->byteLength(), algorithm, extractable, keyUsages, result->result()); | 185 blink::Platform::current()->crypto()->importKey(format, keyDataBytes, keyDat
a->byteLength(), algorithm, extractable, keyUsages, result->result()); |
180 return promise; | 186 return promise; |
181 } | 187 } |
182 | 188 |
183 ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key) | 189 ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key) |
184 { | 190 { |
185 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); | 191 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); |
186 ScriptPromise promise = result->promise(); | 192 ScriptPromise promise = result->promise(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 return promise; | 257 return promise; |
252 | 258 |
253 blink::WebCryptoAlgorithm unwrapAlgorithm; | 259 blink::WebCryptoAlgorithm unwrapAlgorithm; |
254 if (!parseAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, result.g
et())) | 260 if (!parseAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, result.g
et())) |
255 return promise; | 261 return promise; |
256 | 262 |
257 blink::WebCryptoAlgorithm unwrappedKeyAlgorithm; | 263 blink::WebCryptoAlgorithm unwrappedKeyAlgorithm; |
258 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorit
hm, result.get())) | 264 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorit
hm, result.get())) |
259 return promise; | 265 return promise; |
260 | 266 |
| 267 if (!verifyUsagesAreConsistentForAlgorithm(unwrappedKeyAlgorithm.id(), keyUs
ages, result.get())) |
| 268 return promise; |
| 269 |
261 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result
.get())) | 270 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result
.get())) |
262 return promise; | 271 return promise; |
263 | 272 |
264 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap
pedKey->baseAddress()); | 273 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap
pedKey->baseAddress()); |
265 unsigned wrappedKeyDataSize = wrappedKey->byteLength(); | 274 unsigned wrappedKeyDataSize = wrappedKey->byteLength(); |
266 | 275 |
267 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap
pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex
tractable, keyUsages, result->result()); | 276 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap
pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex
tractable, keyUsages, result->result()); |
268 return promise; | 277 return promise; |
269 } | 278 } |
270 | 279 |
271 } // namespace WebCore | 280 } // namespace WebCore |
OLD | NEW |