| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 AlgorithmError error; | 48 AlgorithmError error; |
| 49 bool success = normalizeAlgorithm(raw, op, algorithm, &error); | 49 bool success = normalizeAlgorithm(raw, op, algorithm, &error); |
| 50 if (!success) | 50 if (!success) |
| 51 result->completeWithError(error.errorType, error.errorDetails); | 51 result->completeWithError(error.errorType, error.errorDetails); |
| 52 return success; | 52 return success; |
| 53 } | 53 } |
| 54 | 54 |
| 55 static bool canAccessWebCrypto(ScriptState* scriptState, CryptoResult* result) | 55 static bool canAccessWebCrypto(ScriptState* scriptState, CryptoResult* result) |
| 56 { | 56 { |
| 57 String errorMessage; | 57 String errorMessage; |
| 58 if (!scriptState->executionContext()->isSecureContext(errorMessage, Executio
nContext::WebCryptoSecureContextCheck)) { | 58 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage, Execu
tionContext::WebCryptoSecureContextCheck)) { |
| 59 result->completeWithError(WebCryptoErrorTypeNotSupported, errorMessage); | 59 result->completeWithError(WebCryptoErrorTypeNotSupported, errorMessage); |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 return true; | 63 return true; |
| 64 } | 64 } |
| 65 | 65 |
| 66 static bool copyStringProperty(const char* property, const Dictionary& source, J
SONObject* destination) | 66 static bool copyStringProperty(const char* property, const Dictionary& source, J
SONObject* destination) |
| 67 { | 67 { |
| 68 String value; | 68 String value; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 if (!canAccessWebCrypto(scriptState, result)) | 126 if (!canAccessWebCrypto(scriptState, result)) |
| 127 return promise; | 127 return promise; |
| 128 | 128 |
| 129 WebCryptoAlgorithm algorithm; | 129 WebCryptoAlgorithm algorithm; |
| 130 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu
lt)) | 130 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu
lt)) |
| 131 return promise; | 131 return promise; |
| 132 | 132 |
| 133 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result)
) | 133 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result)
) |
| 134 return promise; | 134 return promise; |
| 135 | 135 |
| 136 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke
y()); | 136 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key-
>key()); |
| 137 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); | 137 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); |
| 138 return promise; | 138 return promise; |
| 139 } | 139 } |
| 140 | 140 |
| 141 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde
ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 141 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde
ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) |
| 142 { | 142 { |
| 143 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 143 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 144 ScriptPromise promise = result->promise(); | 144 ScriptPromise promise = result->promise(); |
| 145 | 145 |
| 146 if (!canAccessWebCrypto(scriptState, result)) | 146 if (!canAccessWebCrypto(scriptState, result)) |
| 147 return promise; | 147 return promise; |
| 148 | 148 |
| 149 WebCryptoAlgorithm algorithm; | 149 WebCryptoAlgorithm algorithm; |
| 150 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu
lt)) | 150 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu
lt)) |
| 151 return promise; | 151 return promise; |
| 152 | 152 |
| 153 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result)
) | 153 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result)
) |
| 154 return promise; | 154 return promise; |
| 155 | 155 |
| 156 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke
y()); | 156 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key-
>key()); |
| 157 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); | 157 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); |
| 158 return promise; | 158 return promise; |
| 159 } | 159 } |
| 160 | 160 |
| 161 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti
fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 161 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti
fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) |
| 162 { | 162 { |
| 163 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 163 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 164 ScriptPromise promise = result->promise(); | 164 ScriptPromise promise = result->promise(); |
| 165 | 165 |
| 166 if (!canAccessWebCrypto(scriptState, result)) | 166 if (!canAccessWebCrypto(scriptState, result)) |
| 167 return promise; | 167 return promise; |
| 168 | 168 |
| 169 WebCryptoAlgorithm algorithm; | 169 WebCryptoAlgorithm algorithm; |
| 170 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result)
) | 170 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result)
) |
| 171 return promise; | 171 return promise; |
| 172 | 172 |
| 173 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result)) | 173 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result)) |
| 174 return promise; | 174 return promise; |
| 175 | 175 |
| 176 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke
y()); | 176 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key-
>key()); |
| 177 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat
a.byteLength(), result->result()); | 177 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat
a.byteLength(), result->result()); |
| 178 return promise; | 178 return promise; |
| 179 } | 179 } |
| 180 | 180 |
| 181 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo
rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c
onst DOMArrayPiece& data) | 181 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo
rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c
onst DOMArrayPiece& data) |
| 182 { | 182 { |
| 183 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 183 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 184 ScriptPromise promise = result->promise(); | 184 ScriptPromise promise = result->promise(); |
| 185 | 185 |
| 186 if (!canAccessWebCrypto(scriptState, result)) | 186 if (!canAccessWebCrypto(scriptState, result)) |
| 187 return promise; | 187 return promise; |
| 188 | 188 |
| 189 WebCryptoAlgorithm algorithm; | 189 WebCryptoAlgorithm algorithm; |
| 190 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul
t)) | 190 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul
t)) |
| 191 return promise; | 191 return promise; |
| 192 | 192 |
| 193 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result)) | 193 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result)) |
| 194 return promise; | 194 return promise; |
| 195 | 195 |
| 196 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke
y()); | 196 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key-
>key()); |
| 197 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat
ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re
sult()); | 197 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat
ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re
sult()); |
| 198 return promise; | 198 return promise; |
| 199 } | 199 } |
| 200 | 200 |
| 201 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden
tifier& rawAlgorithm, const DOMArrayPiece& data) | 201 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden
tifier& rawAlgorithm, const DOMArrayPiece& data) |
| 202 { | 202 { |
| 203 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 203 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 204 ScriptPromise promise = result->promise(); | 204 ScriptPromise promise = result->promise(); |
| 205 | 205 |
| 206 if (!canAccessWebCrypto(scriptState, result)) | 206 if (!canAccessWebCrypto(scriptState, result)) |
| 207 return promise; | 207 return promise; |
| 208 | 208 |
| 209 WebCryptoAlgorithm algorithm; | 209 WebCryptoAlgorithm algorithm; |
| 210 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul
t)) | 210 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul
t)) |
| 211 return promise; | 211 return promise; |
| 212 | 212 |
| 213 histogramAlgorithm(scriptState->executionContext(), algorithm); | 213 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); |
| 214 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng
th(), result->result()); | 214 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng
th(), result->result()); |
| 215 return promise; | 215 return promise; |
| 216 } | 216 } |
| 217 | 217 |
| 218 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) | 218 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) |
| 219 { | 219 { |
| 220 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 220 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 221 ScriptPromise promise = result->promise(); | 221 ScriptPromise promise = result->promise(); |
| 222 | 222 |
| 223 if (!canAccessWebCrypto(scriptState, result)) | 223 if (!canAccessWebCrypto(scriptState, result)) |
| 224 return promise; | 224 return promise; |
| 225 | 225 |
| 226 WebCryptoKeyUsageMask keyUsages; | 226 WebCryptoKeyUsageMask keyUsages; |
| 227 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) | 227 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) |
| 228 return promise; | 228 return promise; |
| 229 | 229 |
| 230 WebCryptoAlgorithm algorithm; | 230 WebCryptoAlgorithm algorithm; |
| 231 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationGenerateKey, algorithm,
result)) | 231 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationGenerateKey, algorithm,
result)) |
| 232 return promise; | 232 return promise; |
| 233 | 233 |
| 234 histogramAlgorithm(scriptState->executionContext(), algorithm); | 234 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); |
| 235 Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages
, result->result()); | 235 Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages
, result->result()); |
| 236 return promise; | 236 return promise; |
| 237 } | 237 } |
| 238 | 238 |
| 239 ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
wFormat, const ArrayBufferOrArrayBufferViewOrDictionary& keyData, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) | 239 ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
wFormat, const ArrayBufferOrArrayBufferViewOrDictionary& keyData, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) |
| 240 { | 240 { |
| 241 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 241 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 242 ScriptPromise promise = result->promise(); | 242 ScriptPromise promise = result->promise(); |
| 243 | 243 |
| 244 if (!canAccessWebCrypto(scriptState, result)) | 244 if (!canAccessWebCrypto(scriptState, result)) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 275 len = keyData.getAsArrayBuffer()->byteLength(); | 275 len = keyData.getAsArrayBuffer()->byteLength(); |
| 276 } else if (keyData.isArrayBufferView()) { | 276 } else if (keyData.isArrayBufferView()) { |
| 277 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBufferView()->
baseAddress()); | 277 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBufferView()->
baseAddress()); |
| 278 len = keyData.getAsArrayBufferView()->byteLength(); | 278 len = keyData.getAsArrayBufferView()->byteLength(); |
| 279 } else if (keyData.isDictionary()) { | 279 } else if (keyData.isDictionary()) { |
| 280 if (!copyJwkDictionaryToJson(keyData.getAsDictionary(), jsonUtf8, result
)) | 280 if (!copyJwkDictionaryToJson(keyData.getAsDictionary(), jsonUtf8, result
)) |
| 281 return promise; | 281 return promise; |
| 282 ptr = reinterpret_cast<const unsigned char*>(jsonUtf8.data()); | 282 ptr = reinterpret_cast<const unsigned char*>(jsonUtf8.data()); |
| 283 len = jsonUtf8.length(); | 283 len = jsonUtf8.length(); |
| 284 } | 284 } |
| 285 histogramAlgorithm(scriptState->executionContext(), algorithm); | 285 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); |
| 286 Platform::current()->crypto()->importKey(format, ptr, len, algorithm, extrac
table, keyUsages, result->result()); | 286 Platform::current()->crypto()->importKey(format, ptr, len, algorithm, extrac
table, keyUsages, result->result()); |
| 287 return promise; | 287 return promise; |
| 288 } | 288 } |
| 289 | 289 |
| 290 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra
wFormat, CryptoKey* key) | 290 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra
wFormat, CryptoKey* key) |
| 291 { | 291 { |
| 292 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 292 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 293 ScriptPromise promise = result->promise(); | 293 ScriptPromise promise = result->promise(); |
| 294 | 294 |
| 295 if (!canAccessWebCrypto(scriptState, result)) | 295 if (!canAccessWebCrypto(scriptState, result)) |
| 296 return promise; | 296 return promise; |
| 297 | 297 |
| 298 WebCryptoKeyFormat format; | 298 WebCryptoKeyFormat format; |
| 299 if (!CryptoKey::parseFormat(rawFormat, format, result)) | 299 if (!CryptoKey::parseFormat(rawFormat, format, result)) |
| 300 return promise; | 300 return promise; |
| 301 | 301 |
| 302 if (!key->extractable()) { | 302 if (!key->extractable()) { |
| 303 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); | 303 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); |
| 304 return promise; | 304 return promise; |
| 305 } | 305 } |
| 306 | 306 |
| 307 histogramKey(scriptState->executionContext(), key->key()); | 307 histogramKey(scriptState->getExecutionContext(), key->key()); |
| 308 Platform::current()->crypto()->exportKey(format, key->key(), result->result(
)); | 308 Platform::current()->crypto()->exportKey(format, key->key(), result->result(
)); |
| 309 return promise; | 309 return promise; |
| 310 } | 310 } |
| 311 | 311 |
| 312 ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF
ormat, CryptoKey* key, CryptoKey* wrappingKey, const AlgorithmIdentifier& rawWra
pAlgorithm) | 312 ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF
ormat, CryptoKey* key, CryptoKey* wrappingKey, const AlgorithmIdentifier& rawWra
pAlgorithm) |
| 313 { | 313 { |
| 314 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 314 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 315 ScriptPromise promise = result->promise(); | 315 ScriptPromise promise = result->promise(); |
| 316 | 316 |
| 317 if (!canAccessWebCrypto(scriptState, result)) | 317 if (!canAccessWebCrypto(scriptState, result)) |
| 318 return promise; | 318 return promise; |
| 319 | 319 |
| 320 WebCryptoKeyFormat format; | 320 WebCryptoKeyFormat format; |
| 321 if (!CryptoKey::parseFormat(rawFormat, format, result)) | 321 if (!CryptoKey::parseFormat(rawFormat, format, result)) |
| 322 return promise; | 322 return promise; |
| 323 | 323 |
| 324 WebCryptoAlgorithm wrapAlgorithm; | 324 WebCryptoAlgorithm wrapAlgorithm; |
| 325 if (!parseAlgorithm(rawWrapAlgorithm, WebCryptoOperationWrapKey, wrapAlgorit
hm, result)) | 325 if (!parseAlgorithm(rawWrapAlgorithm, WebCryptoOperationWrapKey, wrapAlgorit
hm, result)) |
| 326 return promise; | 326 return promise; |
| 327 | 327 |
| 328 if (!key->extractable()) { | 328 if (!key->extractable()) { |
| 329 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); | 329 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); |
| 330 return promise; | 330 return promise; |
| 331 } | 331 } |
| 332 | 332 |
| 333 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap
Key, result)) | 333 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap
Key, result)) |
| 334 return promise; | 334 return promise; |
| 335 | 335 |
| 336 histogramAlgorithmAndKey(scriptState->executionContext(), wrapAlgorithm, wra
ppingKey->key()); | 336 histogramAlgorithmAndKey(scriptState->getExecutionContext(), wrapAlgorithm,
wrappingKey->key()); |
| 337 histogramKey(scriptState->executionContext(), key->key()); | 337 histogramKey(scriptState->getExecutionContext(), key->key()); |
| 338 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(
), wrapAlgorithm, result->result()); | 338 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(
), wrapAlgorithm, result->result()); |
| 339 return promise; | 339 return promise; |
| 340 } | 340 } |
| 341 | 341 |
| 342 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra
wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori
thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg
orithm, bool extractable, const Vector<String>& rawKeyUsages) | 342 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra
wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori
thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg
orithm, bool extractable, const Vector<String>& rawKeyUsages) |
| 343 { | 343 { |
| 344 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 344 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 345 ScriptPromise promise = result->promise(); | 345 ScriptPromise promise = result->promise(); |
| 346 | 346 |
| 347 if (!canAccessWebCrypto(scriptState, result)) | 347 if (!canAccessWebCrypto(scriptState, result)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 359 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA
lgorithm, result)) | 359 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA
lgorithm, result)) |
| 360 return promise; | 360 return promise; |
| 361 | 361 |
| 362 WebCryptoAlgorithm unwrappedKeyAlgorithm; | 362 WebCryptoAlgorithm unwrappedKeyAlgorithm; |
| 363 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u
nwrappedKeyAlgorithm, result)) | 363 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u
nwrappedKeyAlgorithm, result)) |
| 364 return promise; | 364 return promise; |
| 365 | 365 |
| 366 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage
UnwrapKey, result)) | 366 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage
UnwrapKey, result)) |
| 367 return promise; | 367 return promise; |
| 368 | 368 |
| 369 histogramAlgorithmAndKey(scriptState->executionContext(), unwrapAlgorithm, u
nwrappingKey->key()); | 369 histogramAlgorithmAndKey(scriptState->getExecutionContext(), unwrapAlgorithm
, unwrappingKey->key()); |
| 370 histogramAlgorithm(scriptState->executionContext(), unwrappedKeyAlgorithm); | 370 histogramAlgorithm(scriptState->getExecutionContext(), unwrappedKeyAlgorithm
); |
| 371 Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrapped
Key.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm,
extractable, keyUsages, result->result()); | 371 Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrapped
Key.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm,
extractable, keyUsages, result->result()); |
| 372 return promise; | 372 return promise; |
| 373 } | 373 } |
| 374 | 374 |
| 375 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm
Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) | 375 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm
Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) |
| 376 { | 376 { |
| 377 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 377 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 378 ScriptPromise promise = result->promise(); | 378 ScriptPromise promise = result->promise(); |
| 379 | 379 |
| 380 if (!canAccessWebCrypto(scriptState, result)) | 380 if (!canAccessWebCrypto(scriptState, result)) |
| 381 return promise; | 381 return promise; |
| 382 | 382 |
| 383 WebCryptoAlgorithm algorithm; | 383 WebCryptoAlgorithm algorithm; |
| 384 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r
esult)) | 384 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r
esult)) |
| 385 return promise; | 385 return promise; |
| 386 | 386 |
| 387 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveBits,
result)) | 387 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveBits,
result)) |
| 388 return promise; | 388 return promise; |
| 389 | 389 |
| 390 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, baseKey
->key()); | 390 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, base
Key->key()); |
| 391 Platform::current()->crypto()->deriveBits(algorithm, baseKey->key(), lengthB
its, result->result()); | 391 Platform::current()->crypto()->deriveBits(algorithm, baseKey->key(), lengthB
its, result->result()); |
| 392 return promise; | 392 return promise; |
| 393 } | 393 } |
| 394 | 394 |
| 395 ScriptPromise SubtleCrypto::deriveKey(ScriptState* scriptState, const AlgorithmI
dentifier& rawAlgorithm, CryptoKey* baseKey, const AlgorithmIdentifier& rawDeriv
edKeyType, bool extractable, const Vector<String>& rawKeyUsages) | 395 ScriptPromise SubtleCrypto::deriveKey(ScriptState* scriptState, const AlgorithmI
dentifier& rawAlgorithm, CryptoKey* baseKey, const AlgorithmIdentifier& rawDeriv
edKeyType, bool extractable, const Vector<String>& rawKeyUsages) |
| 396 { | 396 { |
| 397 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 397 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
| 398 ScriptPromise promise = result->promise(); | 398 ScriptPromise promise = result->promise(); |
| 399 | 399 |
| 400 if (!canAccessWebCrypto(scriptState, result)) | 400 if (!canAccessWebCrypto(scriptState, result)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 412 return promise; | 412 return promise; |
| 413 | 413 |
| 414 WebCryptoAlgorithm importAlgorithm; | 414 WebCryptoAlgorithm importAlgorithm; |
| 415 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationImportKey, importAl
gorithm, result)) | 415 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationImportKey, importAl
gorithm, result)) |
| 416 return promise; | 416 return promise; |
| 417 | 417 |
| 418 WebCryptoAlgorithm keyLengthAlgorithm; | 418 WebCryptoAlgorithm keyLengthAlgorithm; |
| 419 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe
ngthAlgorithm, result)) | 419 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe
ngthAlgorithm, result)) |
| 420 return promise; | 420 return promise; |
| 421 | 421 |
| 422 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, baseKey
->key()); | 422 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, base
Key->key()); |
| 423 histogramAlgorithm(scriptState->executionContext(), importAlgorithm); | 423 histogramAlgorithm(scriptState->getExecutionContext(), importAlgorithm); |
| 424 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl
gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); | 424 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl
gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); |
| 425 return promise; | 425 return promise; |
| 426 } | 426 } |
| 427 | 427 |
| 428 } // namespace blink | 428 } // namespace blink |
| OLD | NEW |