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

Side by Side Diff: content/child/webcrypto/jwk.cc

Issue 282133002: [webcryto] Validate key usages during key creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "jwk.h" 5 #include "jwk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 10
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 if (!dict->Get(path, &value)) 443 if (!dict->Get(path, &value))
444 return Status::Success(); 444 return Status::Success();
445 445
446 if (!value->GetAsBoolean(result)) 446 if (!value->GetAsBoolean(result))
447 return Status::ErrorJwkPropertyWrongType(path, "boolean"); 447 return Status::ErrorJwkPropertyWrongType(path, "boolean");
448 448
449 *property_exists = true; 449 *property_exists = true;
450 return Status::Success(); 450 return Status::Success();
451 } 451 }
452 452
453 // Returns true if the set bits in b make up a subset of the set bits in a.
454 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a,
455 blink::WebCryptoKeyUsageMask b) {
456 return (a & b) == b;
457 }
458
459 // Writes a secret/symmetric key to a JWK dictionary. 453 // Writes a secret/symmetric key to a JWK dictionary.
460 void WriteSecretKey(const std::vector<uint8>& raw_key, 454 void WriteSecretKey(const std::vector<uint8>& raw_key,
461 base::DictionaryValue* jwk_dict) { 455 base::DictionaryValue* jwk_dict) {
462 DCHECK(jwk_dict); 456 DCHECK(jwk_dict);
463 jwk_dict->SetString("kty", "oct"); 457 jwk_dict->SetString("kty", "oct");
464 // For a secret/symmetric key, the only extra JWK field is 'k', containing the 458 // For a secret/symmetric key, the only extra JWK field is 'k', containing the
465 // base64url encoding of the raw key. 459 // base64url encoding of the raw key.
466 const base::StringPiece key_str( 460 const base::StringPiece key_str(
467 reinterpret_cast<const char*>(Uint8VectorStart(raw_key)), raw_key.size()); 461 reinterpret_cast<const char*>(Uint8VectorStart(raw_key)), raw_key.size());
468 jwk_dict->SetString("k", Base64EncodeUrlSafe(key_str)); 462 jwk_dict->SetString("k", Base64EncodeUrlSafe(key_str));
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 820
827 std::string json; 821 std::string json;
828 base::JSONWriter::Write(&jwk_dict, &json); 822 base::JSONWriter::Write(&jwk_dict, &json);
829 buffer->assign(json.data(), json.data() + json.size()); 823 buffer->assign(json.data(), json.data() + json.size());
830 return Status::Success(); 824 return Status::Success();
831 } 825 }
832 826
833 } // namespace webcrypto 827 } // namespace webcrypto
834 828
835 } // namespace content 829 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/platform_crypto.h » ('j') | content/child/webcrypto/shared_crypto.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698