Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 21561004: WebCrypto: Add crypto.subtle.verify() to the platform interfaces. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing file common.js Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.h ('k') | Source/modules/crypto/SubtleCrypto.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // algorithm. 94 // algorithm.
95 95
96 if (key.algorithm().paramsType() == WebKit::WebCryptoAlgorithmParamsTypeHmac Params) { 96 if (key.algorithm().paramsType() == WebKit::WebCryptoAlgorithmParamsTypeHmac Params) {
97 return key.algorithm().hmacParams()->hash().id() == algorithm.hmacParams ()->hash().id(); 97 return key.algorithm().hmacParams()->hash().id() == algorithm.hmacParams ()->hash().id();
98 } 98 }
99 99
100 ASSERT_NOT_REACHED(); 100 ASSERT_NOT_REACHED();
101 return false; 101 return false;
102 } 102 }
103 103
104 PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm , Key* key, AlgorithmOperation operationType, ExceptionState& es) 104 PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm , Key* key, AlgorithmOperation operationType, ArrayBufferView* signature, Except ionState& es)
105 { 105 {
106 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); 106 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
107 if (!platformCrypto) { 107 if (!platformCrypto) {
108 es.throwDOMException(NotSupportedError); 108 es.throwDOMException(NotSupportedError);
109 return 0; 109 return 0;
110 } 110 }
111 111
112 WebKit::WebCryptoAlgorithm algorithm; 112 WebKit::WebCryptoAlgorithm algorithm;
113 if (!normalizeAlgorithm(rawAlgorithm, operationType, algorithm, es)) 113 if (!normalizeAlgorithm(rawAlgorithm, operationType, algorithm, es))
114 return 0; 114 return 0;
115 115
116 // All operations other than Digest require a valid Key. 116 // All operations other than Digest require a valid Key.
117 if (operationType != Digest) { 117 if (operationType != Digest) {
118 if (!key) { 118 if (!key) {
119 es.throwDOMException(TypeError); 119 es.throwDOMException(TypeError);
120 return 0; 120 return 0;
121 } 121 }
122 122
123 if (!keyCanBeUsedForAlgorithm(key->key(), algorithm, operationType)) { 123 if (!keyCanBeUsedForAlgorithm(key->key(), algorithm, operationType)) {
124 es.throwDOMException(NotSupportedError); 124 es.throwDOMException(NotSupportedError);
125 return 0; 125 return 0;
126 } 126 }
127 } 127 }
128 128
129 // Only Verify takes a signature.
130 if (operationType == Verify && !signature) {
131 es.throwDOMException(TypeError);
132 return 0;
133 }
134
129 RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create(); 135 RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create();
130 WebKit::WebCryptoOperationResult result(opImpl.get()); 136 WebKit::WebCryptoOperationResult result(opImpl.get());
131 137
132 switch (operationType) { 138 switch (operationType) {
133 case Encrypt: 139 case Encrypt:
134 platformCrypto->encrypt(algorithm, key->key(), result); 140 platformCrypto->encrypt(algorithm, key->key(), result);
135 break; 141 break;
136 case Decrypt: 142 case Decrypt:
137 platformCrypto->decrypt(algorithm, key->key(), result); 143 platformCrypto->decrypt(algorithm, key->key(), result);
138 break; 144 break;
139 case Sign: 145 case Sign:
140 platformCrypto->sign(algorithm, key->key(), result); 146 platformCrypto->sign(algorithm, key->key(), result);
141 break; 147 break;
148 case Verify:
149 platformCrypto->verifySignature(algorithm, key->key(), reinterpret_cast< const unsigned char*>(signature->baseAddress()), signature->byteLength(), result );
150 break;
142 case Digest: 151 case Digest:
143 platformCrypto->digest(algorithm, result); 152 platformCrypto->digest(algorithm, result);
144 break; 153 break;
145 default: 154 default:
146 ASSERT_NOT_REACHED(); 155 ASSERT_NOT_REACHED();
147 return 0; 156 return 0;
148 } 157 }
149 158
150 if (opImpl->throwInitializationError(es)) 159 if (opImpl->throwInitializationError(es))
151 return 0; 160 return 0;
152 return CryptoOperation::create(algorithm, opImpl.get()); 161 return CryptoOperation::create(algorithm, opImpl.get());
153 } 162 }
154 163
155 } // namespace 164 } // namespace
156 165
157 SubtleCrypto::SubtleCrypto() 166 SubtleCrypto::SubtleCrypto()
158 { 167 {
159 ScriptWrappable::init(this); 168 ScriptWrappable::init(this);
160 } 169 }
161 170
162 PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm , Key* key, ExceptionState& es) 171 PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm , Key* key, ExceptionState& es)
163 { 172 {
164 return createCryptoOperation(rawAlgorithm, key, Encrypt, es); 173 return createCryptoOperation(rawAlgorithm, key, Encrypt, 0, es);
165 } 174 }
166 175
167 PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm , Key* key, ExceptionState& es) 176 PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm , Key* key, ExceptionState& es)
168 { 177 {
169 return createCryptoOperation(rawAlgorithm, key, Decrypt, es); 178 return createCryptoOperation(rawAlgorithm, key, Decrypt, 0, es);
170 } 179 }
171 180
172 PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, K ey* key, ExceptionState& es) 181 PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, K ey* key, ExceptionState& es)
173 { 182 {
174 return createCryptoOperation(rawAlgorithm, key, Sign, es); 183 return createCryptoOperation(rawAlgorithm, key, Sign, 0, es);
175 } 184 }
176 185
177 PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawA lgorithm, Key* key, ExceptionState& es) 186 PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawA lgorithm, Key* key, ArrayBufferView* signature, ExceptionState& es)
178 { 187 {
179 // FIXME 188 return createCryptoOperation(rawAlgorithm, key, Verify, signature, es);
180 return 0;
181 } 189 }
182 190
183 PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionState& es) 191 PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionState& es)
184 { 192 {
185 return createCryptoOperation(rawAlgorithm, 0, Digest, es); 193 return createCryptoOperation(rawAlgorithm, 0, Digest, 0, es);
186 } 194 }
187 195
188 ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* k eyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es) 196 ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* k eyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es)
189 { 197 {
190 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); 198 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
191 if (!platformCrypto) { 199 if (!platformCrypto) {
192 es.throwDOMException(NotSupportedError); 200 es.throwDOMException(NotSupportedError);
193 return ScriptObject(); 201 return ScriptObject();
194 } 202 }
195 203
(...skipping 20 matching lines...) Expand all
216 224
217 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas eAddress()); 225 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas eAddress());
218 226
219 RefPtr<KeyOperation> keyOp = KeyOperation::create(); 227 RefPtr<KeyOperation> keyOp = KeyOperation::create();
220 WebKit::WebCryptoKeyOperationResult result(keyOp.get()); 228 WebKit::WebCryptoKeyOperationResult result(keyOp.get());
221 platformCrypto->importKey(format, keyDataBytes, keyData->byteLength(), algor ithm, extractable, keyUsages, result); 229 platformCrypto->importKey(format, keyDataBytes, keyData->byteLength(), algor ithm, extractable, keyUsages, result);
222 return keyOp->returnValue(es); 230 return keyOp->returnValue(es);
223 } 231 }
224 232
225 } // namespace WebCore 233 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.h ('k') | Source/modules/crypto/SubtleCrypto.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698