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

Unified Diff: content/renderer/webcrypto_impl_nss.cc

Issue 24616003: Implement verify() for HMAC using NSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_build_sh
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/webcrypto_impl.cc ('k') | content/renderer/webcrypto_impl_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/webcrypto_impl_nss.cc
diff --git a/content/renderer/webcrypto_impl_nss.cc b/content/renderer/webcrypto_impl_nss.cc
index caf986fce44f168fe5c390239d27336919066188..05eeefda45c5e0516de8ddcd14a593c9e32c0bbe 100644
--- a/content/renderer/webcrypto_impl_nss.cc
+++ b/content/renderer/webcrypto_impl_nss.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "crypto/nss_util.h"
#include "crypto/scoped_nss_types.h"
+#include "crypto/secure_util.h"
eroman 2013/09/25 23:18:51 this should be sorted above crypto/scroped_nss
Bryan Eyler 2013/09/25 23:57:05 For alphabetical ordering? I think this is correc
eroman 2013/09/26 00:10:42 Oops, my bad :)
#include "third_party/WebKit/public/platform/WebArrayBuffer.h"
#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
#include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
@@ -249,4 +250,73 @@ bool WebCryptoImpl::SignInternal(
return true;
}
+bool WebCryptoImpl::VerifySignatureInternal(
+ const WebKit::WebCryptoAlgorithm& algorithm,
+ const WebKit::WebCryptoKey& key,
+ const unsigned char* signature,
+ unsigned signature_size,
+ const unsigned char* data,
+ unsigned data_size,
+ bool* signature_match) {
+ switch (algorithm.id()) {
+ case WebKit::WebCryptoAlgorithmIdHmac: {
+ const WebKit::WebCryptoHmacParams* params = algorithm.hmacParams();
+ if (!params) {
+ return false;
+ }
+
+ SymKeyHandle* sym_key = reinterpret_cast<SymKeyHandle*>(key.handle());
+
+ DCHECK_EQ(PK11_GetMechanism(sym_key->key()),
eroman 2013/09/25 23:18:51 Isn't this a duplication of DigestInternal? Please
Bryan Eyler 2013/09/25 23:57:05 Yeah, I was trying to avoid creating a WebArrayBuf
+ WebCryptoAlgorithmToHMACMechanism(params->hash()));
+ DCHECK_NE(0, key.usages() & WebKit::WebCryptoKeyUsageSign);
+
+ SECItem param_item = { siBuffer, NULL, 0 };
+ SECItem data_item = {
+ siBuffer,
+ const_cast<unsigned char*>(data),
+ data_size
+ };
+ // First call is to figure out the length.
+ SECItem signature_item = { siBuffer, NULL, 0 };
+
+ if (PK11_SignWithSymKey(sym_key->key(),
+ PK11_GetMechanism(sym_key->key()),
+ &param_item,
+ &signature_item,
+ &data_item) != SECSuccess) {
+ NOTREACHED();
+ return false;
+ }
+
+ DCHECK_NE(0u, signature_item.len);
+
+ std::vector<unsigned char> result(signature_item.len);
+ signature_item.data = result.data();
+
+ if (PK11_SignWithSymKey(sym_key->key(),
+ PK11_GetMechanism(sym_key->key()),
+ &param_item,
+ &signature_item,
+ &data_item) != SECSuccess) {
+ NOTREACHED();
+ return false;
+ }
+
+ DCHECK_EQ(signature_item.len, result.size());
+
+ // To ensure optimal security usage, do not support truncated signatures.
eroman 2013/09/25 23:18:51 This comment should be in terms of the webcrypto s
Bryan Eyler 2013/09/25 23:57:05 Done.
+ *signature_match =
+ crypto::SecureMemEqual(result.data(), signature, signature_size) &&
+ result.size() == signature_size;
+
+ break;
+ }
+ default:
+ return false;
+ }
+
+ return true;
+}
+
} // namespace content
« no previous file with comments | « content/renderer/webcrypto_impl.cc ('k') | content/renderer/webcrypto_impl_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698