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/base/default_origin_bound_cert_store.h" | 5 #include "net/base/default_origin_bound_cert_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 10 matching lines...) Expand all Loading... |
21 const base::Closure& completion_task) { | 21 const base::Closure& completion_task) { |
22 base::AutoLock autolock(lock_); | 22 base::AutoLock autolock(lock_); |
23 | 23 |
24 if (initialized_ && store_) | 24 if (initialized_ && store_) |
25 store_->Flush(completion_task); | 25 store_->Flush(completion_task); |
26 else if (!completion_task.is_null()) | 26 else if (!completion_task.is_null()) |
27 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 27 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
28 } | 28 } |
29 | 29 |
30 bool DefaultOriginBoundCertStore::GetOriginBoundCert( | 30 bool DefaultOriginBoundCertStore::GetOriginBoundCert( |
31 const std::string& origin, | 31 const std::string& domain, |
32 SSLClientCertType* type, | 32 SSLClientCertType* type, |
33 base::Time* creation_time, | 33 base::Time* creation_time, |
34 base::Time* expiration_time, | 34 base::Time* expiration_time, |
35 std::string* private_key_result, | 35 std::string* private_key_result, |
36 std::string* cert_result) { | 36 std::string* cert_result) { |
37 base::AutoLock autolock(lock_); | 37 base::AutoLock autolock(lock_); |
38 InitIfNecessary(); | 38 InitIfNecessary(); |
39 | 39 |
40 OriginBoundCertMap::iterator it = origin_bound_certs_.find(origin); | 40 OriginBoundCertMap::iterator it = origin_bound_certs_.find(domain); |
41 | 41 |
42 if (it == origin_bound_certs_.end()) | 42 if (it == origin_bound_certs_.end()) |
43 return false; | 43 return false; |
44 | 44 |
45 OriginBoundCert* cert = it->second; | 45 OriginBoundCert* cert = it->second; |
46 *type = cert->type(); | 46 *type = cert->type(); |
47 *creation_time = cert->creation_time(); | 47 *creation_time = cert->creation_time(); |
48 *expiration_time = cert->expiration_time(); | 48 *expiration_time = cert->expiration_time(); |
49 *private_key_result = cert->private_key(); | 49 *private_key_result = cert->private_key(); |
50 *cert_result = cert->cert(); | 50 *cert_result = cert->cert(); |
51 | 51 |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 void DefaultOriginBoundCertStore::SetOriginBoundCert( | 55 void DefaultOriginBoundCertStore::SetOriginBoundCert( |
56 const std::string& origin, | 56 const std::string& domain, |
57 SSLClientCertType type, | 57 SSLClientCertType type, |
58 base::Time creation_time, | 58 base::Time creation_time, |
59 base::Time expiration_time, | 59 base::Time expiration_time, |
60 const std::string& private_key, | 60 const std::string& private_key, |
61 const std::string& cert) { | 61 const std::string& cert) { |
62 base::AutoLock autolock(lock_); | 62 base::AutoLock autolock(lock_); |
63 InitIfNecessary(); | 63 InitIfNecessary(); |
64 | 64 |
65 InternalDeleteOriginBoundCert(origin); | 65 InternalDeleteOriginBoundCert(domain); |
66 InternalInsertOriginBoundCert( | 66 InternalInsertOriginBoundCert( |
67 origin, | 67 domain, |
68 new OriginBoundCert( | 68 new OriginBoundCert( |
69 origin, type, creation_time, expiration_time, private_key, cert)); | 69 domain, type, creation_time, expiration_time, private_key, cert)); |
70 } | 70 } |
71 | 71 |
72 void DefaultOriginBoundCertStore::DeleteOriginBoundCert( | 72 void DefaultOriginBoundCertStore::DeleteOriginBoundCert( |
73 const std::string& origin) { | 73 const std::string& domain) { |
74 base::AutoLock autolock(lock_); | 74 base::AutoLock autolock(lock_); |
75 InitIfNecessary(); | 75 InitIfNecessary(); |
76 InternalDeleteOriginBoundCert(origin); | 76 InternalDeleteOriginBoundCert(domain); |
77 } | 77 } |
78 | 78 |
79 void DefaultOriginBoundCertStore::DeleteAllCreatedBetween( | 79 void DefaultOriginBoundCertStore::DeleteAllCreatedBetween( |
80 base::Time delete_begin, | 80 base::Time delete_begin, |
81 base::Time delete_end) { | 81 base::Time delete_end) { |
82 base::AutoLock autolock(lock_); | 82 base::AutoLock autolock(lock_); |
83 InitIfNecessary(); | 83 InitIfNecessary(); |
84 for (OriginBoundCertMap::iterator it = origin_bound_certs_.begin(); | 84 for (OriginBoundCertMap::iterator it = origin_bound_certs_.begin(); |
85 it != origin_bound_certs_.end();) { | 85 it != origin_bound_certs_.end();) { |
86 OriginBoundCertMap::iterator cur = it; | 86 OriginBoundCertMap::iterator cur = it; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 // Initialize the store and sync in any saved persistent certs. | 139 // Initialize the store and sync in any saved persistent certs. |
140 std::vector<OriginBoundCert*> certs; | 140 std::vector<OriginBoundCert*> certs; |
141 // Reserve space for the maximum amount of certs a database should have. | 141 // Reserve space for the maximum amount of certs a database should have. |
142 // This prevents multiple vector growth / copies as we append certs. | 142 // This prevents multiple vector growth / copies as we append certs. |
143 certs.reserve(kMaxCerts); | 143 certs.reserve(kMaxCerts); |
144 store_->Load(&certs); | 144 store_->Load(&certs); |
145 | 145 |
146 for (std::vector<OriginBoundCert*>::const_iterator it = certs.begin(); | 146 for (std::vector<OriginBoundCert*>::const_iterator it = certs.begin(); |
147 it != certs.end(); ++it) { | 147 it != certs.end(); ++it) { |
148 origin_bound_certs_[(*it)->origin()] = *it; | 148 origin_bound_certs_[(*it)->domain()] = *it; |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 void DefaultOriginBoundCertStore::InternalDeleteOriginBoundCert( | 152 void DefaultOriginBoundCertStore::InternalDeleteOriginBoundCert( |
153 const std::string& origin) { | 153 const std::string& domain) { |
154 lock_.AssertAcquired(); | 154 lock_.AssertAcquired(); |
155 | 155 |
156 OriginBoundCertMap::iterator it = origin_bound_certs_.find(origin); | 156 OriginBoundCertMap::iterator it = origin_bound_certs_.find(domain); |
157 if (it == origin_bound_certs_.end()) | 157 if (it == origin_bound_certs_.end()) |
158 return; // There is nothing to delete. | 158 return; // There is nothing to delete. |
159 | 159 |
160 OriginBoundCert* cert = it->second; | 160 OriginBoundCert* cert = it->second; |
161 if (store_) | 161 if (store_) |
162 store_->DeleteOriginBoundCert(*cert); | 162 store_->DeleteOriginBoundCert(*cert); |
163 origin_bound_certs_.erase(it); | 163 origin_bound_certs_.erase(it); |
164 delete cert; | 164 delete cert; |
165 } | 165 } |
166 | 166 |
167 void DefaultOriginBoundCertStore::InternalInsertOriginBoundCert( | 167 void DefaultOriginBoundCertStore::InternalInsertOriginBoundCert( |
168 const std::string& origin, | 168 const std::string& domain, |
169 OriginBoundCert* cert) { | 169 OriginBoundCert* cert) { |
170 lock_.AssertAcquired(); | 170 lock_.AssertAcquired(); |
171 | 171 |
172 if (store_) | 172 if (store_) |
173 store_->AddOriginBoundCert(*cert); | 173 store_->AddOriginBoundCert(*cert); |
174 origin_bound_certs_[origin] = cert; | 174 origin_bound_certs_[domain] = cert; |
175 } | 175 } |
176 | 176 |
177 DefaultOriginBoundCertStore::PersistentStore::PersistentStore() {} | 177 DefaultOriginBoundCertStore::PersistentStore::PersistentStore() {} |
178 | 178 |
179 } // namespace net | 179 } // namespace net |
OLD | NEW |