Commit 345bd207 authored by eroman@chromium.org's avatar eroman@chromium.org

[webcrypto] Don't execute cancelled crypto operations.

BUG=375430

Review URL: https://codereview.chromium.org/341923004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278274 0039d316-1c4b-4281-b951-d872f2087c98
parent a671109d
...@@ -170,6 +170,14 @@ struct BaseState { ...@@ -170,6 +170,14 @@ struct BaseState {
explicit BaseState(const blink::WebCryptoResult& result) explicit BaseState(const blink::WebCryptoResult& result)
: origin_thread(GetCurrentBlinkThread()), result(result) {} : origin_thread(GetCurrentBlinkThread()), result(result) {}
bool cancelled() {
#ifdef WEBCRYPTO_RESULT_HAS_CANCELLED
return result.cancelled();
#else
return false;
#endif
}
scoped_refptr<base::TaskRunner> origin_thread; scoped_refptr<base::TaskRunner> origin_thread;
webcrypto::Status status; webcrypto::Status status;
...@@ -352,6 +360,8 @@ void DoEncryptReply(scoped_ptr<EncryptState> state) { ...@@ -352,6 +360,8 @@ void DoEncryptReply(scoped_ptr<EncryptState> state) {
void DoEncrypt(scoped_ptr<EncryptState> passed_state) { void DoEncrypt(scoped_ptr<EncryptState> passed_state) {
EncryptState* state = passed_state.get(); EncryptState* state = passed_state.get();
if (state->cancelled())
return;
state->status = webcrypto::Encrypt(state->algorithm, state->status = webcrypto::Encrypt(state->algorithm,
state->key, state->key,
webcrypto::CryptoData(state->data), webcrypto::CryptoData(state->data),
...@@ -366,6 +376,8 @@ void DoDecryptReply(scoped_ptr<DecryptState> state) { ...@@ -366,6 +376,8 @@ void DoDecryptReply(scoped_ptr<DecryptState> state) {
void DoDecrypt(scoped_ptr<DecryptState> passed_state) { void DoDecrypt(scoped_ptr<DecryptState> passed_state) {
DecryptState* state = passed_state.get(); DecryptState* state = passed_state.get();
if (state->cancelled())
return;
state->status = webcrypto::Decrypt(state->algorithm, state->status = webcrypto::Decrypt(state->algorithm,
state->key, state->key,
webcrypto::CryptoData(state->data), webcrypto::CryptoData(state->data),
...@@ -380,6 +392,8 @@ void DoDigestReply(scoped_ptr<DigestState> state) { ...@@ -380,6 +392,8 @@ void DoDigestReply(scoped_ptr<DigestState> state) {
void DoDigest(scoped_ptr<DigestState> passed_state) { void DoDigest(scoped_ptr<DigestState> passed_state) {
DigestState* state = passed_state.get(); DigestState* state = passed_state.get();
if (state->cancelled())
return;
state->status = webcrypto::Digest( state->status = webcrypto::Digest(
state->algorithm, webcrypto::CryptoData(state->data), &state->buffer); state->algorithm, webcrypto::CryptoData(state->data), &state->buffer);
state->origin_thread->PostTask( state->origin_thread->PostTask(
...@@ -399,6 +413,8 @@ void DoGenerateKeyReply(scoped_ptr<GenerateKeyState> state) { ...@@ -399,6 +413,8 @@ void DoGenerateKeyReply(scoped_ptr<GenerateKeyState> state) {
void DoGenerateKey(scoped_ptr<GenerateKeyState> passed_state) { void DoGenerateKey(scoped_ptr<GenerateKeyState> passed_state) {
GenerateKeyState* state = passed_state.get(); GenerateKeyState* state = passed_state.get();
if (state->cancelled())
return;
state->is_asymmetric = state->is_asymmetric =
webcrypto::IsAlgorithmAsymmetric(state->algorithm.id()); webcrypto::IsAlgorithmAsymmetric(state->algorithm.id());
if (state->is_asymmetric) { if (state->is_asymmetric) {
...@@ -440,6 +456,8 @@ void DoImportKeyReply(scoped_ptr<ImportKeyState> state) { ...@@ -440,6 +456,8 @@ void DoImportKeyReply(scoped_ptr<ImportKeyState> state) {
void DoImportKey(scoped_ptr<ImportKeyState> passed_state) { void DoImportKey(scoped_ptr<ImportKeyState> passed_state) {
ImportKeyState* state = passed_state.get(); ImportKeyState* state = passed_state.get();
if (state->cancelled())
return;
state->status = webcrypto::ImportKey(state->format, state->status = webcrypto::ImportKey(state->format,
webcrypto::CryptoData(state->key_data), webcrypto::CryptoData(state->key_data),
state->algorithm, state->algorithm,
...@@ -474,6 +492,8 @@ void DoExportKeyReply(scoped_ptr<ExportKeyState> state) { ...@@ -474,6 +492,8 @@ void DoExportKeyReply(scoped_ptr<ExportKeyState> state) {
void DoExportKey(scoped_ptr<ExportKeyState> passed_state) { void DoExportKey(scoped_ptr<ExportKeyState> passed_state) {
ExportKeyState* state = passed_state.get(); ExportKeyState* state = passed_state.get();
if (state->cancelled())
return;
state->status = state->status =
webcrypto::ExportKey(state->format, state->key, &state->buffer); webcrypto::ExportKey(state->format, state->key, &state->buffer);
state->origin_thread->PostTask( state->origin_thread->PostTask(
...@@ -486,6 +506,8 @@ void DoSignReply(scoped_ptr<SignState> state) { ...@@ -486,6 +506,8 @@ void DoSignReply(scoped_ptr<SignState> state) {
void DoSign(scoped_ptr<SignState> passed_state) { void DoSign(scoped_ptr<SignState> passed_state) {
SignState* state = passed_state.get(); SignState* state = passed_state.get();
if (state->cancelled())
return;
state->status = webcrypto::Sign(state->algorithm, state->status = webcrypto::Sign(state->algorithm,
state->key, state->key,
webcrypto::CryptoData(state->data), webcrypto::CryptoData(state->data),
...@@ -505,6 +527,8 @@ void DoVerifyReply(scoped_ptr<VerifySignatureState> state) { ...@@ -505,6 +527,8 @@ void DoVerifyReply(scoped_ptr<VerifySignatureState> state) {
void DoVerify(scoped_ptr<VerifySignatureState> passed_state) { void DoVerify(scoped_ptr<VerifySignatureState> passed_state) {
VerifySignatureState* state = passed_state.get(); VerifySignatureState* state = passed_state.get();
if (state->cancelled())
return;
state->status = state->status =
webcrypto::VerifySignature(state->algorithm, webcrypto::VerifySignature(state->algorithm,
state->key, state->key,
...@@ -522,6 +546,8 @@ void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) { ...@@ -522,6 +546,8 @@ void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) {
void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) { void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) {
WrapKeyState* state = passed_state.get(); WrapKeyState* state = passed_state.get();
if (state->cancelled())
return;
state->status = webcrypto::WrapKey(state->format, state->status = webcrypto::WrapKey(state->format,
state->key, state->key,
state->wrapping_key, state->wrapping_key,
...@@ -538,6 +564,8 @@ void DoUnwrapKeyReply(scoped_ptr<UnwrapKeyState> state) { ...@@ -538,6 +564,8 @@ void DoUnwrapKeyReply(scoped_ptr<UnwrapKeyState> state) {
void DoUnwrapKey(scoped_ptr<UnwrapKeyState> passed_state) { void DoUnwrapKey(scoped_ptr<UnwrapKeyState> passed_state) {
UnwrapKeyState* state = passed_state.get(); UnwrapKeyState* state = passed_state.get();
if (state->cancelled())
return;
state->status = state->status =
webcrypto::UnwrapKey(state->format, webcrypto::UnwrapKey(state->format,
webcrypto::CryptoData(state->wrapped_key), webcrypto::CryptoData(state->wrapped_key),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment