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

Side by Side Diff: components/gcm_driver/crypto/p256_key_util_openssl.cc

Issue 1453503002: [NOT FOR REVIEW] Ensure contributory behaviour for Web Push encryption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@push-renames
Patch Set: Created 5 years, 1 month 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/gcm_driver/crypto/p256_key_util.h" 5 #include "components/gcm_driver/crypto/p256_key_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <openssl/ec.h> 9 #include <openssl/ec.h>
10 #include <openssl/ecdh.h> 10 #include <openssl/ecdh.h>
11 #include <openssl/evp.h> 11 #include <openssl/evp.h>
12 12
13 #include "base/base64url.h"
14
13 #include "base/logging.h" 15 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "crypto/ec_private_key.h" 18 #include "crypto/ec_private_key.h"
17 #include "crypto/scoped_openssl_types.h" 19 #include "crypto/scoped_openssl_types.h"
18 20
19 namespace gcm { 21 namespace gcm {
20 22
21 namespace { 23 namespace {
22 24
(...skipping 15 matching lines...) Expand all
38 private_key.data(), private_key.data() + private_key.size()), 40 private_key.data(), private_key.data() + private_key.size()),
39 std::vector<uint8_t>( 41 std::vector<uint8_t>(
40 public_key_x509.data(), 42 public_key_x509.data(),
41 public_key_x509.data() + public_key_x509.size()))); 43 public_key_x509.data() + public_key_x509.size())));
42 44
43 if (!local_key_pair) { 45 if (!local_key_pair) {
44 DLOG(ERROR) << "Unable to create the local key pair."; 46 DLOG(ERROR) << "Unable to create the local key pair.";
45 return false; 47 return false;
46 } 48 }
47 49
50 std::vector<uint8_t> pubkey;
51 local_key_pair->ExportPublicKey(&pubkey);
52
53 std::string res(reinterpret_cast<char*>(pubkey.data()), pubkey.size());
54
55 std::string b;
56 base::Base64UrlEncode(res, base::Base64UrlEncodePolicy::OMIT_PADDING, &b);
57
58 LOG(INFO) << "x509 key: [" << b << "]";
59
48 crypto::ScopedEC_KEY ec_private_key( 60 crypto::ScopedEC_KEY ec_private_key(
49 EVP_PKEY_get1_EC_KEY(local_key_pair->key())); 61 EVP_PKEY_get1_EC_KEY(local_key_pair->key()));
50 62
51 if (!ec_private_key || !EC_KEY_check_key(ec_private_key.get())) { 63 if (!ec_private_key || !EC_KEY_check_key(ec_private_key.get())) {
52 DLOG(ERROR) << "The private key is invalid."; 64 DLOG(ERROR) << "The private key is invalid.";
53 return false; 65 return false;
54 } 66 }
55 67
56 crypto::ScopedEC_POINT point( 68 crypto::ScopedEC_POINT point(
57 EC_POINT_new(EC_KEY_get0_group(ec_private_key.get()))); 69 EC_POINT_new(EC_KEY_get0_group(ec_private_key.get())));
(...skipping 12 matching lines...) Expand all
70 ec_private_key.get(), nullptr) != sizeof(result)) { 82 ec_private_key.get(), nullptr) != sizeof(result)) {
71 DLOG(ERROR) << "Unable to compute the ECDH shared secret."; 83 DLOG(ERROR) << "Unable to compute the ECDH shared secret.";
72 return false; 84 return false;
73 } 85 }
74 86
75 out_shared_secret->assign(reinterpret_cast<char*>(result), sizeof(result)); 87 out_shared_secret->assign(reinterpret_cast<char*>(result), sizeof(result));
76 return true; 88 return true;
77 } 89 }
78 90
79 } // namespace gcm 91 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc ('k') | crypto/ec_private_key.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698