| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "crypto/nss_crypto_module_delegate.h" | 21 #include "crypto/nss_crypto_module_delegate.h" |
| 22 #include "crypto/scoped_test_nss_db.h" | 22 #include "crypto/scoped_test_nss_db.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 #if defined(USE_NSS) | 29 #if defined(USE_NSS) |
| 30 class StubCryptoModuleDelegate : public crypto::NSSCryptoModuleDelegate { | 30 class StubCryptoModuleDelegate : public crypto::NSSCryptoModuleDelegate { |
| 31 public: | 31 public: |
| 32 explicit StubCryptoModuleDelegate(crypto::ScopedPK11Slot slot) | 32 explicit StubCryptoModuleDelegate(crypto::ScopedPK11Slot slot) |
| 33 : slot_(slot.Pass()) {} | 33 : slot_(slot.Pass()) {} |
| 34 | 34 |
| 35 virtual std::string RequestPassword(const std::string& slot_name, | 35 virtual std::string RequestPassword(const std::string& slot_name, |
| 36 bool retry, | 36 bool retry, |
| 37 bool* cancelled) override{ | 37 bool* cancelled) override { |
| 38 return std::string(); | 38 return std::string(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual crypto::ScopedPK11Slot RequestSlot() override { | 41 virtual crypto::ScopedPK11Slot RequestSlot() override { |
| 42 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot_.get())); | 42 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot_.get())); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 crypto::ScopedPK11Slot slot_; | 46 crypto::ScopedPK11Slot slot_; |
| 47 }; | 47 }; |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 class KeygenHandlerTest : public ::testing::Test { | 50 class KeygenHandlerTest : public ::testing::Test { |
| 51 public: | 51 public: |
| 52 KeygenHandlerTest() {} | 52 KeygenHandlerTest() {} |
| 53 virtual ~KeygenHandlerTest() {} | 53 virtual ~KeygenHandlerTest() {} |
| 54 | 54 |
| 55 scoped_ptr<KeygenHandler> CreateKeygenHandler() { | 55 scoped_ptr<KeygenHandler> CreateKeygenHandler() { |
| 56 scoped_ptr<KeygenHandler> handler(new KeygenHandler( | 56 scoped_ptr<KeygenHandler> handler(new KeygenHandler( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // segfaults on shutdown when the threads' thread-specific data | 133 // segfaults on shutdown when the threads' thread-specific data |
| 134 // destructors run. | 134 // destructors run. |
| 135 PR_DetachThread(); | 135 PR_DetachThread(); |
| 136 #endif | 136 #endif |
| 137 } | 137 } |
| 138 | 138 |
| 139 // We asynchronously generate the keys so as not to hang up the IO thread. This | 139 // We asynchronously generate the keys so as not to hang up the IO thread. This |
| 140 // test tries to catch concurrency problems in the keygen implementation. | 140 // test tries to catch concurrency problems in the keygen implementation. |
| 141 TEST_F(KeygenHandlerTest, ConcurrencyTest) { | 141 TEST_F(KeygenHandlerTest, ConcurrencyTest) { |
| 142 const int NUM_HANDLERS = 5; | 142 const int NUM_HANDLERS = 5; |
| 143 base::WaitableEvent* events[NUM_HANDLERS] = { NULL }; | 143 base::WaitableEvent* events[NUM_HANDLERS] = {NULL}; |
| 144 std::string results[NUM_HANDLERS]; | 144 std::string results[NUM_HANDLERS]; |
| 145 for (int i = 0; i < NUM_HANDLERS; i++) { | 145 for (int i = 0; i < NUM_HANDLERS; i++) { |
| 146 scoped_ptr<KeygenHandler> handler(CreateKeygenHandler()); | 146 scoped_ptr<KeygenHandler> handler(CreateKeygenHandler()); |
| 147 events[i] = new base::WaitableEvent(false, false); | 147 events[i] = new base::WaitableEvent(false, false); |
| 148 base::WorkerPool::PostTask(FROM_HERE, | 148 base::WorkerPool::PostTask(FROM_HERE, |
| 149 base::Bind(ConcurrencyTestCallback, | 149 base::Bind(ConcurrencyTestCallback, |
| 150 "some challenge", | 150 "some challenge", |
| 151 events[i], | 151 events[i], |
| 152 base::Passed(&handler), | 152 base::Passed(&handler), |
| 153 &results[i]), | 153 &results[i]), |
| 154 true); | 154 true); |
| 155 } | 155 } |
| 156 | 156 |
| 157 for (int i = 0; i < NUM_HANDLERS; i++) { | 157 for (int i = 0; i < NUM_HANDLERS; i++) { |
| 158 // Make sure the job completed | 158 // Make sure the job completed |
| 159 events[i]->Wait(); | 159 events[i]->Wait(); |
| 160 delete events[i]; | 160 delete events[i]; |
| 161 events[i] = NULL; | 161 events[i] = NULL; |
| 162 | 162 |
| 163 VLOG(1) << "KeygenHandler " << i << " produced: " << results[i]; | 163 VLOG(1) << "KeygenHandler " << i << " produced: " << results[i]; |
| 164 AssertValidSignedPublicKeyAndChallenge(results[i], "some challenge"); | 164 AssertValidSignedPublicKeyAndChallenge(results[i], "some challenge"); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace | 168 } // namespace |
| 169 | 169 |
| 170 } // namespace net | 170 } // namespace net |
| OLD | NEW |