| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ssl/server_bound_cert_service.h" | 5 #include "net/ssl/server_bound_cert_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // Async lookup did not find a valid cert. Start generating a new one. | 572 // Async lookup did not find a valid cert. Start generating a new one. |
| 573 ServerBoundCertServiceWorker* worker = new ServerBoundCertServiceWorker( | 573 ServerBoundCertServiceWorker* worker = new ServerBoundCertServiceWorker( |
| 574 server_identifier, | 574 server_identifier, |
| 575 job->type(), | 575 job->type(), |
| 576 base::Bind(&ServerBoundCertService::GeneratedServerBoundCert, | 576 base::Bind(&ServerBoundCertService::GeneratedServerBoundCert, |
| 577 weak_ptr_factory_.GetWeakPtr())); | 577 weak_ptr_factory_.GetWeakPtr())); |
| 578 if (!worker->Start(task_runner_)) { | 578 if (!worker->Start(task_runner_)) { |
| 579 delete worker; | 579 delete worker; |
| 580 // TODO(rkn): Log to the NetLog. | 580 // TODO(rkn): Log to the NetLog. |
| 581 LOG(ERROR) << "ServerBoundCertServiceWorker couldn't be started."; | 581 LOG(ERROR) << "ServerBoundCertServiceWorker couldn't be started."; |
| 582 HandleResult(ERR_INSUFFICIENT_RESOURCES, server_identifier, | 582 HandleResult(ERR_INSUFFICIENT_RESOURCES, |
| 583 CLIENT_CERT_INVALID_TYPE, "", ""); | 583 server_identifier, |
| 584 CLIENT_CERT_INVALID_TYPE, |
| 585 std::string(), |
| 586 std::string()); |
| 584 return; | 587 return; |
| 585 } | 588 } |
| 586 } | 589 } |
| 587 | 590 |
| 588 ServerBoundCertStore* ServerBoundCertService::GetCertStore() { | 591 ServerBoundCertStore* ServerBoundCertService::GetCertStore() { |
| 589 return server_bound_cert_store_.get(); | 592 return server_bound_cert_store_.get(); |
| 590 } | 593 } |
| 591 | 594 |
| 592 void ServerBoundCertService::CancelRequest(ServerBoundCertServiceRequest* req) { | 595 void ServerBoundCertService::CancelRequest(ServerBoundCertServiceRequest* req) { |
| 593 DCHECK(CalledOnValidThread()); | 596 DCHECK(CalledOnValidThread()); |
| 594 req->Cancel(); | 597 req->Cancel(); |
| 595 } | 598 } |
| 596 | 599 |
| 597 void ServerBoundCertService::GeneratedServerBoundCert( | 600 void ServerBoundCertService::GeneratedServerBoundCert( |
| 598 const std::string& server_identifier, | 601 const std::string& server_identifier, |
| 599 int error, | 602 int error, |
| 600 scoped_ptr<ServerBoundCertStore::ServerBoundCert> cert) { | 603 scoped_ptr<ServerBoundCertStore::ServerBoundCert> cert) { |
| 601 DCHECK(CalledOnValidThread()); | 604 DCHECK(CalledOnValidThread()); |
| 602 | 605 |
| 603 if (error == OK) { | 606 if (error == OK) { |
| 604 // TODO(mattm): we should just Pass() the cert object to | 607 // TODO(mattm): we should just Pass() the cert object to |
| 605 // SetServerBoundCert(). | 608 // SetServerBoundCert(). |
| 606 server_bound_cert_store_->SetServerBoundCert( | 609 server_bound_cert_store_->SetServerBoundCert( |
| 607 cert->server_identifier(), cert->type(), cert->creation_time(), | 610 cert->server_identifier(), cert->type(), cert->creation_time(), |
| 608 cert->expiration_time(), cert->private_key(), cert->cert()); | 611 cert->expiration_time(), cert->private_key(), cert->cert()); |
| 609 | 612 |
| 610 HandleResult(error, server_identifier, cert->type(), cert->private_key(), | 613 HandleResult(error, server_identifier, cert->type(), cert->private_key(), |
| 611 cert->cert()); | 614 cert->cert()); |
| 612 } else { | 615 } else { |
| 613 HandleResult(error, server_identifier, CLIENT_CERT_INVALID_TYPE, "", ""); | 616 HandleResult(error, |
| 617 server_identifier, |
| 618 CLIENT_CERT_INVALID_TYPE, |
| 619 std::string(), |
| 620 std::string()); |
| 614 } | 621 } |
| 615 } | 622 } |
| 616 | 623 |
| 617 void ServerBoundCertService::HandleResult( | 624 void ServerBoundCertService::HandleResult( |
| 618 int error, | 625 int error, |
| 619 const std::string& server_identifier, | 626 const std::string& server_identifier, |
| 620 SSLClientCertType type, | 627 SSLClientCertType type, |
| 621 const std::string& private_key, | 628 const std::string& private_key, |
| 622 const std::string& cert) { | 629 const std::string& cert) { |
| 623 DCHECK(CalledOnValidThread()); | 630 DCHECK(CalledOnValidThread()); |
| 624 | 631 |
| 625 std::map<std::string, ServerBoundCertServiceJob*>::iterator j; | 632 std::map<std::string, ServerBoundCertServiceJob*>::iterator j; |
| 626 j = inflight_.find(server_identifier); | 633 j = inflight_.find(server_identifier); |
| 627 if (j == inflight_.end()) { | 634 if (j == inflight_.end()) { |
| 628 NOTREACHED(); | 635 NOTREACHED(); |
| 629 return; | 636 return; |
| 630 } | 637 } |
| 631 ServerBoundCertServiceJob* job = j->second; | 638 ServerBoundCertServiceJob* job = j->second; |
| 632 inflight_.erase(j); | 639 inflight_.erase(j); |
| 633 | 640 |
| 634 job->HandleResult(error, type, private_key, cert); | 641 job->HandleResult(error, type, private_key, cert); |
| 635 delete job; | 642 delete job; |
| 636 } | 643 } |
| 637 | 644 |
| 638 int ServerBoundCertService::cert_count() { | 645 int ServerBoundCertService::cert_count() { |
| 639 return server_bound_cert_store_->GetCertCount(); | 646 return server_bound_cert_store_->GetCertCount(); |
| 640 } | 647 } |
| 641 | 648 |
| 642 } // namespace net | 649 } // namespace net |
| OLD | NEW |