| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/ocsp/nss_ocsp.h" | 5 #include "net/ocsp/nss_ocsp.h" |
| 6 | 6 |
| 7 #include <certt.h> | 7 #include <certt.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <ocsp.h> | 9 #include <ocsp.h> |
| 10 #include <nspr.h> | 10 #include <nspr.h> |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 SEC_HttpClientFcn client_fcn_; | 134 SEC_HttpClientFcn client_fcn_; |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(OCSPNSSInitialization); | 136 DISALLOW_COPY_AND_ASSIGN(OCSPNSSInitialization); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 base::LazyInstance<OCSPNSSInitialization> g_ocsp_nss_initialization( | 139 base::LazyInstance<OCSPNSSInitialization> g_ocsp_nss_initialization( |
| 140 base::LINKER_INITIALIZED); | 140 base::LINKER_INITIALIZED); |
| 141 | 141 |
| 142 // Concrete class for SEC_HTTP_REQUEST_SESSION. | 142 // Concrete class for SEC_HTTP_REQUEST_SESSION. |
| 143 // Public methods except virtual methods of URLRequest::Delegate (On* methods) | 143 // Public methods except virtual methods of net::URLRequest::Delegate |
| 144 // run on certificate verifier thread (worker thread). | 144 // (On* methods) run on certificate verifier thread (worker thread). |
| 145 // Virtual methods of URLRequest::Delegate and private methods run | 145 // Virtual methods of net::URLRequest::Delegate and private methods run |
| 146 // on IO thread. | 146 // on IO thread. |
| 147 class OCSPRequestSession | 147 class OCSPRequestSession |
| 148 : public base::RefCountedThreadSafe<OCSPRequestSession>, | 148 : public base::RefCountedThreadSafe<OCSPRequestSession>, |
| 149 public URLRequest::Delegate { | 149 public net::URLRequest::Delegate { |
| 150 public: | 150 public: |
| 151 OCSPRequestSession(const GURL& url, | 151 OCSPRequestSession(const GURL& url, |
| 152 const char* http_request_method, | 152 const char* http_request_method, |
| 153 base::TimeDelta timeout) | 153 base::TimeDelta timeout) |
| 154 : url_(url), | 154 : url_(url), |
| 155 http_request_method_(http_request_method), | 155 http_request_method_(http_request_method), |
| 156 timeout_(timeout), | 156 timeout_(timeout), |
| 157 request_(NULL), | 157 request_(NULL), |
| 158 buffer_(new net::IOBuffer(kRecvBufferSize)), | 158 buffer_(new net::IOBuffer(kRecvBufferSize)), |
| 159 response_code_(-1), | 159 response_code_(-1), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 const std::string& http_response_headers() const { | 241 const std::string& http_response_headers() const { |
| 242 DCHECK(finished_); | 242 DCHECK(finished_); |
| 243 return response_headers_->raw_headers(); | 243 return response_headers_->raw_headers(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 const std::string& http_response_data() const { | 246 const std::string& http_response_data() const { |
| 247 DCHECK(finished_); | 247 DCHECK(finished_); |
| 248 return data_; | 248 return data_; |
| 249 } | 249 } |
| 250 | 250 |
| 251 virtual void OnResponseStarted(URLRequest* request) { | 251 virtual void OnResponseStarted(net::URLRequest* request) { |
| 252 DCHECK_EQ(request, request_); | 252 DCHECK_EQ(request, request_); |
| 253 DCHECK_EQ(MessageLoopForIO::current(), io_loop_); | 253 DCHECK_EQ(MessageLoopForIO::current(), io_loop_); |
| 254 | 254 |
| 255 int bytes_read = 0; | 255 int bytes_read = 0; |
| 256 if (request->status().is_success()) { | 256 if (request->status().is_success()) { |
| 257 response_code_ = request_->GetResponseCode(); | 257 response_code_ = request_->GetResponseCode(); |
| 258 response_headers_ = request_->response_headers(); | 258 response_headers_ = request_->response_headers(); |
| 259 response_headers_->GetMimeType(&response_content_type_); | 259 response_headers_->GetMimeType(&response_content_type_); |
| 260 request_->Read(buffer_, kRecvBufferSize, &bytes_read); | 260 request_->Read(buffer_, kRecvBufferSize, &bytes_read); |
| 261 } | 261 } |
| 262 OnReadCompleted(request_, bytes_read); | 262 OnReadCompleted(request_, bytes_read); |
| 263 } | 263 } |
| 264 | 264 |
| 265 virtual void OnReadCompleted(URLRequest* request, int bytes_read) { | 265 virtual void OnReadCompleted(net::URLRequest* request, int bytes_read) { |
| 266 DCHECK_EQ(request, request_); | 266 DCHECK_EQ(request, request_); |
| 267 DCHECK_EQ(MessageLoopForIO::current(), io_loop_); | 267 DCHECK_EQ(MessageLoopForIO::current(), io_loop_); |
| 268 | 268 |
| 269 do { | 269 do { |
| 270 if (!request_->status().is_success() || bytes_read <= 0) | 270 if (!request_->status().is_success() || bytes_read <= 0) |
| 271 break; | 271 break; |
| 272 data_.append(buffer_->data(), bytes_read); | 272 data_.append(buffer_->data(), bytes_read); |
| 273 } while (request_->Read(buffer_, kRecvBufferSize, &bytes_read)); | 273 } while (request_->Read(buffer_, kRecvBufferSize, &bytes_read)); |
| 274 | 274 |
| 275 if (!request_->status().is_io_pending()) { | 275 if (!request_->status().is_io_pending()) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 if (url_request_context == NULL) | 342 if (url_request_context == NULL) |
| 343 return; | 343 return; |
| 344 | 344 |
| 345 { | 345 { |
| 346 AutoLock autolock(lock_); | 346 AutoLock autolock(lock_); |
| 347 DCHECK(!io_loop_); | 347 DCHECK(!io_loop_); |
| 348 io_loop_ = MessageLoopForIO::current(); | 348 io_loop_ = MessageLoopForIO::current(); |
| 349 g_ocsp_io_loop.Get().AddRequest(this); | 349 g_ocsp_io_loop.Get().AddRequest(this); |
| 350 } | 350 } |
| 351 | 351 |
| 352 request_ = new URLRequest(url_, this); | 352 request_ = new net::URLRequest(url_, this); |
| 353 request_->set_context(url_request_context); | 353 request_->set_context(url_request_context); |
| 354 // To meet the privacy requirements of off-the-record mode. | 354 // To meet the privacy requirements of off-the-record mode. |
| 355 request_->set_load_flags( | 355 request_->set_load_flags( |
| 356 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES | | 356 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES | |
| 357 net::LOAD_DO_NOT_SEND_COOKIES); | 357 net::LOAD_DO_NOT_SEND_COOKIES); |
| 358 | 358 |
| 359 if (http_request_method_ == "POST") { | 359 if (http_request_method_ == "POST") { |
| 360 DCHECK(!upload_content_.empty()); | 360 DCHECK(!upload_content_.empty()); |
| 361 DCHECK(!upload_content_type_.empty()); | 361 DCHECK(!upload_content_type_.empty()); |
| 362 | 362 |
| 363 request_->set_method("POST"); | 363 request_->set_method("POST"); |
| 364 extra_request_headers_.SetHeader( | 364 extra_request_headers_.SetHeader( |
| 365 net::HttpRequestHeaders::kContentType, upload_content_type_); | 365 net::HttpRequestHeaders::kContentType, upload_content_type_); |
| 366 request_->AppendBytesToUpload(upload_content_.data(), | 366 request_->AppendBytesToUpload(upload_content_.data(), |
| 367 static_cast<int>(upload_content_.size())); | 367 static_cast<int>(upload_content_.size())); |
| 368 } | 368 } |
| 369 if (!extra_request_headers_.IsEmpty()) | 369 if (!extra_request_headers_.IsEmpty()) |
| 370 request_->SetExtraRequestHeaders(extra_request_headers_); | 370 request_->SetExtraRequestHeaders(extra_request_headers_); |
| 371 | 371 |
| 372 request_->Start(); | 372 request_->Start(); |
| 373 AddRef(); // Release after |request_| deleted. | 373 AddRef(); // Release after |request_| deleted. |
| 374 } | 374 } |
| 375 | 375 |
| 376 GURL url_; // The URL we eventually wound up at | 376 GURL url_; // The URL we eventually wound up at |
| 377 std::string http_request_method_; | 377 std::string http_request_method_; |
| 378 base::TimeDelta timeout_; // The timeout for OCSP | 378 base::TimeDelta timeout_; // The timeout for OCSP |
| 379 URLRequest* request_; // The actual request this wraps | 379 net::URLRequest* request_; // The actual request this wraps |
| 380 scoped_refptr<net::IOBuffer> buffer_; // Read buffer | 380 scoped_refptr<net::IOBuffer> buffer_; // Read buffer |
| 381 net::HttpRequestHeaders extra_request_headers_; | 381 net::HttpRequestHeaders extra_request_headers_; |
| 382 std::string upload_content_; // HTTP POST payload | 382 std::string upload_content_; // HTTP POST payload |
| 383 std::string upload_content_type_; // MIME type of POST payload | 383 std::string upload_content_type_; // MIME type of POST payload |
| 384 | 384 |
| 385 int response_code_; // HTTP status code for the request | 385 int response_code_; // HTTP status code for the request |
| 386 std::string response_content_type_; | 386 std::string response_content_type_; |
| 387 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 387 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 388 std::string data_; // Results of the requst | 388 std::string data_; // Results of the requst |
| 389 | 389 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // Our Http Client functions operate in blocking mode. | 560 // Our Http Client functions operate in blocking mode. |
| 561 SECStatus OCSPCreateSession(const char* host, PRUint16 portnum, | 561 SECStatus OCSPCreateSession(const char* host, PRUint16 portnum, |
| 562 SEC_HTTP_SERVER_SESSION* pSession) { | 562 SEC_HTTP_SERVER_SESSION* pSession) { |
| 563 VLOG(1) << "OCSP create session: host=" << host << " port=" << portnum; | 563 VLOG(1) << "OCSP create session: host=" << host << " port=" << portnum; |
| 564 pthread_mutex_lock(&g_request_context_lock); | 564 pthread_mutex_lock(&g_request_context_lock); |
| 565 URLRequestContext* request_context = g_request_context; | 565 URLRequestContext* request_context = g_request_context; |
| 566 pthread_mutex_unlock(&g_request_context_lock); | 566 pthread_mutex_unlock(&g_request_context_lock); |
| 567 if (request_context == NULL) { | 567 if (request_context == NULL) { |
| 568 LOG(ERROR) << "No URLRequestContext for OCSP handler."; | 568 LOG(ERROR) << "No URLRequestContext for OCSP handler."; |
| 569 // The application failed to call SetURLRequestContextForOCSP, so we | 569 // The application failed to call SetURLRequestContextForOCSP, so we |
| 570 // can't create and use URLRequest. PR_NOT_IMPLEMENTED_ERROR is not an | 570 // can't create and use net::URLRequest. PR_NOT_IMPLEMENTED_ERROR is not an |
| 571 // accurate error code for this error condition, but is close enough. | 571 // accurate error code for this error condition, but is close enough. |
| 572 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); | 572 PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); |
| 573 return SECFailure; | 573 return SECFailure; |
| 574 } | 574 } |
| 575 *pSession = new OCSPServerSession(host, portnum); | 575 *pSession = new OCSPServerSession(host, portnum); |
| 576 return SECSuccess; | 576 return SECSuccess; |
| 577 } | 577 } |
| 578 | 578 |
| 579 SECStatus OCSPKeepAliveSession(SEC_HTTP_SERVER_SESSION session, | 579 SECStatus OCSPKeepAliveSession(SEC_HTTP_SERVER_SESSION session, |
| 580 PRPollDesc **pPollDesc) { | 580 PRPollDesc **pPollDesc) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 896 |
| 897 URLRequestContext* GetURLRequestContextForOCSP() { | 897 URLRequestContext* GetURLRequestContextForOCSP() { |
| 898 pthread_mutex_lock(&g_request_context_lock); | 898 pthread_mutex_lock(&g_request_context_lock); |
| 899 URLRequestContext* request_context = g_request_context; | 899 URLRequestContext* request_context = g_request_context; |
| 900 pthread_mutex_unlock(&g_request_context_lock); | 900 pthread_mutex_unlock(&g_request_context_lock); |
| 901 DCHECK(!request_context || request_context->is_main()); | 901 DCHECK(!request_context || request_context->is_main()); |
| 902 return request_context; | 902 return request_context; |
| 903 } | 903 } |
| 904 | 904 |
| 905 } // namespace net | 905 } // namespace net |
| OLD | NEW |