| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/devtools/adb/android_rsa.h" | 5 #include "chrome/browser/devtools/adb/android_rsa.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 std::vector<uint8> key_info(decoded_key.begin(), decoded_key.end()); | 189 std::vector<uint8> key_info(decoded_key.begin(), decoded_key.end()); |
| 190 key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); | 190 key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); |
| 191 } | 191 } |
| 192 if (!key) { | 192 if (!key) { |
| 193 key.reset(crypto::RSAPrivateKey::Create(2048)); | 193 key.reset(crypto::RSAPrivateKey::Create(2048)); |
| 194 std::vector<uint8> key_info; | 194 std::vector<uint8> key_info; |
| 195 if (!key || !key->ExportPrivateKey(&key_info)) | 195 if (!key || !key->ExportPrivateKey(&key_info)) |
| 196 return NULL; | 196 return NULL; |
| 197 | 197 |
| 198 std::string key_string(key_info.begin(), key_info.end()); | 198 std::string key_string(key_info.begin(), key_info.end()); |
| 199 base::Base64Encode(key_string, &encoded_key); | 199 if (base::Base64Encode(key_string, &encoded_key)) { |
| 200 profile->GetPrefs()->SetString(prefs::kDevToolsAdbKey, | 200 profile->GetPrefs()->SetString(prefs::kDevToolsAdbKey, |
| 201 encoded_key); | 201 encoded_key); |
| 202 } |
| 202 } | 203 } |
| 203 return key.release(); | 204 return key.release(); |
| 204 } | 205 } |
| 205 | 206 |
| 206 std::string AndroidRSAPublicKey(crypto::RSAPrivateKey* key) { | 207 std::string AndroidRSAPublicKey(crypto::RSAPrivateKey* key) { |
| 207 std::vector<uint8> public_key; | 208 std::vector<uint8> public_key; |
| 208 if (!key) | 209 if (!key) |
| 209 return kDummyRSAPublicKey; | 210 return kDummyRSAPublicKey; |
| 210 | 211 |
| 211 key->ExportPublicKey(&public_key); | 212 key->ExportPublicKey(&public_key); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 std::string AndroidRSASign(crypto::RSAPrivateKey* key, | 262 std::string AndroidRSASign(crypto::RSAPrivateKey* key, |
| 262 const std::string& body) { | 263 const std::string& body) { |
| 263 std::vector<uint8> digest(body.begin(), body.end()); | 264 std::vector<uint8> digest(body.begin(), body.end()); |
| 264 std::vector<uint8> result; | 265 std::vector<uint8> result; |
| 265 if (!crypto::SignatureCreator::Sign(key, vector_as_array(&digest), | 266 if (!crypto::SignatureCreator::Sign(key, vector_as_array(&digest), |
| 266 digest.size(), &result)) { | 267 digest.size(), &result)) { |
| 267 return std::string(); | 268 return std::string(); |
| 268 } | 269 } |
| 269 return std::string(result.begin(), result.end()); | 270 return std::string(result.begin(), result.end()); |
| 270 } | 271 } |
| OLD | NEW |