| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/threading/thread_restrictions.h" | |
| 19 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
| 20 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/boringssl/src/include/openssl/bytestring.h" | 21 #include "third_party/boringssl/src/include/openssl/bytestring.h" |
| 23 #include "third_party/boringssl/src/include/openssl/evp.h" | 22 #include "third_party/boringssl/src/include/openssl/evp.h" |
| 24 | 23 |
| 25 #if defined(USE_NSS_CERTS) | 24 #if defined(USE_NSS_CERTS) |
| 26 #include <private/pprthred.h> // PR_DetachThread | 25 #include <private/pprthred.h> // PR_DetachThread |
| 27 #include "crypto/nss_crypto_module_delegate.h" | 26 #include "crypto/nss_crypto_module_delegate.h" |
| 28 #include "crypto/scoped_test_nss_db.h" | 27 #include "crypto/scoped_test_nss_db.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 handler->set_stores_key(false); // Don't leave the key-pair behind | 168 handler->set_stores_key(false); // Don't leave the key-pair behind |
| 170 std::string result = handler->GenKeyAndSignChallenge(); | 169 std::string result = handler->GenKeyAndSignChallenge(); |
| 171 VLOG(1) << "KeygenHandler produced: " << result; | 170 VLOG(1) << "KeygenHandler produced: " << result; |
| 172 AssertValidSignedPublicKeyAndChallenge(result, kChallenge); | 171 AssertValidSignedPublicKeyAndChallenge(result, kChallenge); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void ConcurrencyTestCallback(const std::string& challenge, | 174 void ConcurrencyTestCallback(const std::string& challenge, |
| 176 base::WaitableEvent* event, | 175 base::WaitableEvent* event, |
| 177 std::unique_ptr<KeygenHandler> handler, | 176 std::unique_ptr<KeygenHandler> handler, |
| 178 std::string* result) { | 177 std::string* result) { |
| 179 // We allow Singleton use on the worker thread here since we use a | |
| 180 // WaitableEvent to synchronize, so it's safe. | |
| 181 base::ThreadRestrictions::ScopedAllowSingleton scoped_allow_singleton; | |
| 182 handler->set_stores_key(false); // Don't leave the key-pair behind. | 178 handler->set_stores_key(false); // Don't leave the key-pair behind. |
| 183 *result = handler->GenKeyAndSignChallenge(); | 179 *result = handler->GenKeyAndSignChallenge(); |
| 184 event->Signal(); | 180 event->Signal(); |
| 185 #if defined(USE_NSS_CERTS) | 181 #if defined(USE_NSS_CERTS) |
| 186 // Detach the thread from NSPR. | 182 // Detach the thread from NSPR. |
| 187 // Calling NSS functions attaches the thread to NSPR, which stores | 183 // Calling NSS functions attaches the thread to NSPR, which stores |
| 188 // the NSPR thread ID in thread-specific data. | 184 // the NSPR thread ID in thread-specific data. |
| 189 // The threads in our thread pool terminate after we have called | 185 // The threads in our thread pool terminate after we have called |
| 190 // PR_Cleanup. Unless we detach them from NSPR, net_unittests gets | 186 // PR_Cleanup. Unless we detach them from NSPR, net_unittests gets |
| 191 // segfaults on shutdown when the threads' thread-specific data | 187 // segfaults on shutdown when the threads' thread-specific data |
| (...skipping 29 matching lines...) Expand all Loading... |
| 221 events[i] = NULL; | 217 events[i] = NULL; |
| 222 | 218 |
| 223 VLOG(1) << "KeygenHandler " << i << " produced: " << results[i]; | 219 VLOG(1) << "KeygenHandler " << i << " produced: " << results[i]; |
| 224 AssertValidSignedPublicKeyAndChallenge(results[i], "some challenge"); | 220 AssertValidSignedPublicKeyAndChallenge(results[i], "some challenge"); |
| 225 } | 221 } |
| 226 } | 222 } |
| 227 | 223 |
| 228 } // namespace | 224 } // namespace |
| 229 | 225 |
| 230 } // namespace net | 226 } // namespace net |
| OLD | NEW |