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

Side by Side Diff: chrome/browser/renderer_host/x509_user_cert_resource_handler.cc

Issue 652137: Mac: implement <keygen> support, including adding generated cert to the Keychain. (Closed)
Patch Set: Responding to review feedback. Created 10 years, 9 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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/renderer_host/x509_user_cert_resource_handler.h" 5 #include "chrome/browser/renderer_host/x509_user_cert_resource_handler.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/download/download_file.h" 10 #include "chrome/browser/download/download_file.h"
11 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 11 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
12 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" 12 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
13 #include "chrome/common/resource_response.h" 13 #include "chrome/common/resource_response.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "net/base/cert_database.h"
16 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
17 #include "net/base/mime_sniffer.h" 16 #include "net/base/mime_sniffer.h"
18 #include "net/base/mime_util.h" 17 #include "net/base/mime_util.h"
19 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
20 19
21 X509UserCertResourceHandler::X509UserCertResourceHandler( 20 X509UserCertResourceHandler::X509UserCertResourceHandler(
22 ResourceDispatcherHost* host, URLRequest* request) 21 ResourceDispatcherHost* host, URLRequest* request)
23 : host_(host), 22 : host_(host),
24 request_(request), 23 request_(request),
25 content_length_(0), 24 content_length_(0),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // TODO(gauravsh): Should this be handled by a separate thread? 71 // TODO(gauravsh): Should this be handled by a separate thread?
73 buffer_->contents.push_back(std::make_pair(buffer, *bytes_read)); 72 buffer_->contents.push_back(std::make_pair(buffer, *bytes_read));
74 73
75 return true; 74 return true;
76 } 75 }
77 76
78 bool X509UserCertResourceHandler::OnResponseCompleted( 77 bool X509UserCertResourceHandler::OnResponseCompleted(
79 int request_id, 78 int request_id,
80 const URLRequestStatus& urs, 79 const URLRequestStatus& urs,
81 const std::string& sec_info) { 80 const std::string& sec_info) {
81 if (urs.status() != URLRequestStatus::SUCCESS)
82 return false;
83
82 // TODO(gauravsh): Verify that 'request_id' was actually a keygen form post 84 // TODO(gauravsh): Verify that 'request_id' was actually a keygen form post
83 // and only then import the certificate. 85 // and only then import the certificate.
84 scoped_ptr<net::CertDatabase> cert_db(new net::CertDatabase());
85 AssembleResource(); 86 AssembleResource();
86 87 scoped_refptr<net::X509Certificate> cert =
87 return cert_db->AddUserCert(resource_buffer_->data(), content_length_); 88 net::X509Certificate::CreateFromBytes(resource_buffer_->data(),
89 content_length_);
90 request_->delegate()->OnClientCertificateGenerated(request_, cert);
91 return true;
88 } 92 }
89 93
90 void X509UserCertResourceHandler::AssembleResource() { 94 void X509UserCertResourceHandler::AssembleResource() {
91 size_t bytes_copied = 0; 95 size_t bytes_copied = 0;
92 resource_buffer_ = new net::IOBuffer(content_length_); 96 resource_buffer_ = new net::IOBuffer(content_length_);
93 97
94 for (size_t i = 0; i < buffer_->contents.size(); ++i) { 98 for (size_t i = 0; i < buffer_->contents.size(); ++i) {
95 net::IOBuffer* data = buffer_->contents[i].first; 99 net::IOBuffer* data = buffer_->contents[i].first;
96 const int data_len = buffer_->contents[i].second; 100 const int data_len = buffer_->contents[i].second;
97 DCHECK(bytes_copied + data_len <= content_length_); 101 DCHECK(bytes_copied + data_len <= content_length_);
98 memcpy(resource_buffer_->data() + bytes_copied, data->data(), data_len); 102 memcpy(resource_buffer_->data() + bytes_copied, data->data(), data_len);
99 bytes_copied += data_len; 103 bytes_copied += data_len;
100 } 104 }
101 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698