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

Side by Side Diff: content/browser/experiments/api_key_signature_verifier.cc

Issue 1563903002: Add public key and signature verification to browser-side API keys Base URL: https://chromium.googlesource.com/chromium/src.git@keys
Patch Set: Created 4 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/experiments/api_key_signature_verifier.h"
6
7 #include "base/base64.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
13 #include <openssl/curve25519.h>
14
15 namespace content {
16
17 namespace {
18
19 // This is the default public key used for validating signatures.
20 // TODO(iclelland): Move this to the embedder, and provide a mechanism to allow
21 // for multiple signing keys. https://crbug.com/543220
22 static const uint8_t kPublicKey[] = {
23 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
24 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
25 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
26 };
27 static const size_t kPublicKeyLength = sizeof(kPublicKey);
28
29 } // namespace
30
31 // static
32 bool ApiKeySignatureVerifier::VerifySignature(const std::string& signature_text,
33 const std::string& data) {
34 return VerifySignature(signature_text, data, kPublicKey, kPublicKeyLength);
35 }
36
37 // static
38 bool ApiKeySignatureVerifier::VerifySignature(const std::string& signature_text,
39 const std::string& data,
40 const uint8_t* public_key,
41 size_t public_key_length) {
42 std::string signature;
43 // signature is base64-encoded
44 if (!base::Base64Decode(signature_text, &signature)) {
45 return false;
46 }
47
48 // TODO: verify signature length is 64
49 int result = ED25519_verify(
50 reinterpret_cast<const uint8_t*>(data.data()), data.length(),
51 reinterpret_cast<const uint8_t*>(signature.data()), public_key);
52 return (result != 0);
53 }
54
55 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698