Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: net/socket/ssl_test_util.cc

Issue 558008: Use the USE_NSS macro to help porting to FreeBSD, OpenBSD, etc.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/des.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/socket/ssl_test_util.h"
6
5 #include <algorithm> 7 #include <algorithm>
6 #include <string> 8 #include <string>
7 #include <vector> 9 #include <vector>
8 10
9 #include "net/socket/ssl_test_util.h"
10
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include <windows.h> 14 #include <windows.h>
15 #include <wincrypt.h> 15 #include <wincrypt.h>
16 #elif defined(OS_LINUX) 16 #elif defined(USE_NSS)
17 #include <nspr.h> 17 #include <nspr.h>
18 #include <nss.h> 18 #include <nss.h>
19 #include <secerr.h> 19 #include <secerr.h>
20 #include <ssl.h> 20 #include <ssl.h>
21 #include <sslerr.h> 21 #include <sslerr.h>
22 #include <pk11pub.h> 22 #include <pk11pub.h>
23 #include "base/nss_util.h" 23 #include "base/nss_util.h"
24 #elif defined(OS_MACOSX) 24 #elif defined(OS_MACOSX)
25 #include <Security/Security.h> 25 #include <Security/Security.h>
26 #include "base/scoped_cftyperef.h" 26 #include "base/scoped_cftyperef.h"
(...skipping 10 matching lines...) Expand all
37 #include "net/socket/tcp_client_socket.h" 37 #include "net/socket/tcp_client_socket.h"
38 #include "net/socket/tcp_pinger.h" 38 #include "net/socket/tcp_pinger.h"
39 #include "testing/platform_test.h" 39 #include "testing/platform_test.h"
40 40
41 #if defined(OS_WIN) 41 #if defined(OS_WIN)
42 #pragma comment(lib, "crypt32.lib") 42 #pragma comment(lib, "crypt32.lib")
43 #endif 43 #endif
44 44
45 namespace { 45 namespace {
46 46
47 #if defined(OS_LINUX) 47 #if defined(USE_NSS)
48 static CERTCertificate* LoadTemporaryCert(const FilePath& filename) { 48 static CERTCertificate* LoadTemporaryCert(const FilePath& filename) {
49 base::EnsureNSSInit(); 49 base::EnsureNSSInit();
50 50
51 std::string rawcert; 51 std::string rawcert;
52 if (!file_util::ReadFileToString(filename, &rawcert)) { 52 if (!file_util::ReadFileToString(filename, &rawcert)) {
53 LOG(ERROR) << "Can't load certificate " << filename.value(); 53 LOG(ERROR) << "Can't load certificate " << filename.value();
54 return NULL; 54 return NULL;
55 } 55 }
56 56
57 CERTCertificate *cert; 57 CERTCertificate *cert;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const int TestServerLauncher::kBadHTTPSPort = 9666; 131 const int TestServerLauncher::kBadHTTPSPort = 9666;
132 132
133 // The issuer name of the cert that should be trusted for the test to work. 133 // The issuer name of the cert that should be trusted for the test to work.
134 const wchar_t TestServerLauncher::kCertIssuerName[] = L"Test CA"; 134 const wchar_t TestServerLauncher::kCertIssuerName[] = L"Test CA";
135 135
136 TestServerLauncher::TestServerLauncher() : process_handle_( 136 TestServerLauncher::TestServerLauncher() : process_handle_(
137 base::kNullProcessHandle), 137 base::kNullProcessHandle),
138 forking_(false), 138 forking_(false),
139 connection_attempts_(kDefaultTestConnectionAttempts), 139 connection_attempts_(kDefaultTestConnectionAttempts),
140 connection_timeout_(kDefaultTestConnectionTimeout) 140 connection_timeout_(kDefaultTestConnectionTimeout)
141 #if defined(OS_LINUX) 141 #if defined(USE_NSS)
142 , cert_(NULL) 142 , cert_(NULL)
143 #endif 143 #endif
144 { 144 {
145 InitCertPath(); 145 InitCertPath();
146 } 146 }
147 147
148 TestServerLauncher::TestServerLauncher(int connection_attempts, 148 TestServerLauncher::TestServerLauncher(int connection_attempts,
149 int connection_timeout) 149 int connection_timeout)
150 : process_handle_(base::kNullProcessHandle), 150 : process_handle_(base::kNullProcessHandle),
151 forking_(false), 151 forking_(false),
152 connection_attempts_(connection_attempts), 152 connection_attempts_(connection_attempts),
153 connection_timeout_(connection_timeout) 153 connection_timeout_(connection_timeout)
154 #if defined(OS_LINUX) 154 #if defined(USE_NSS)
155 , cert_(NULL) 155 , cert_(NULL)
156 #endif 156 #endif
157 { 157 {
158 InitCertPath(); 158 InitCertPath();
159 } 159 }
160 160
161 void TestServerLauncher::InitCertPath() { 161 void TestServerLauncher::InitCertPath() {
162 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); 162 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_);
163 cert_dir_ = cert_dir_.Append(FILE_PATH_LITERAL("net")) 163 cert_dir_ = cert_dir_.Append(FILE_PATH_LITERAL("net"))
164 .Append(FILE_PATH_LITERAL("data")) 164 .Append(FILE_PATH_LITERAL("data"))
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 process_handle_ = base::kNullProcessHandle; 346 process_handle_ = base::kNullProcessHandle;
347 LOG(INFO) << "Stopped."; 347 LOG(INFO) << "Stopped.";
348 } else { 348 } else {
349 LOG(INFO) << "Kill failed?"; 349 LOG(INFO) << "Kill failed?";
350 } 350 }
351 351
352 return ret; 352 return ret;
353 } 353 }
354 354
355 TestServerLauncher::~TestServerLauncher() { 355 TestServerLauncher::~TestServerLauncher() {
356 #if defined(OS_LINUX) 356 #if defined(USE_NSS)
357 if (cert_) 357 if (cert_)
358 CERT_DestroyCertificate(reinterpret_cast<CERTCertificate*>(cert_)); 358 CERT_DestroyCertificate(reinterpret_cast<CERTCertificate*>(cert_));
359 #elif defined(OS_MACOSX) 359 #elif defined(OS_MACOSX)
360 SetMacTestCertificate(NULL); 360 SetMacTestCertificate(NULL);
361 #endif 361 #endif
362 Stop(); 362 Stop();
363 } 363 }
364 364
365 FilePath TestServerLauncher::GetRootCertPath() { 365 FilePath TestServerLauncher::GetRootCertPath() {
366 FilePath path(cert_dir_); 366 FilePath path(cert_dir_);
367 path = path.AppendASCII("root_ca_cert.crt"); 367 path = path.AppendASCII("root_ca_cert.crt");
368 return path; 368 return path;
369 } 369 }
370 370
371 FilePath TestServerLauncher::GetOKCertPath() { 371 FilePath TestServerLauncher::GetOKCertPath() {
372 FilePath path(cert_dir_); 372 FilePath path(cert_dir_);
373 path = path.AppendASCII("ok_cert.pem"); 373 path = path.AppendASCII("ok_cert.pem");
374 return path; 374 return path;
375 } 375 }
376 376
377 FilePath TestServerLauncher::GetExpiredCertPath() { 377 FilePath TestServerLauncher::GetExpiredCertPath() {
378 FilePath path(cert_dir_); 378 FilePath path(cert_dir_);
379 path = path.AppendASCII("expired_cert.pem"); 379 path = path.AppendASCII("expired_cert.pem");
380 return path; 380 return path;
381 } 381 }
382 382
383 bool TestServerLauncher::LoadTestRootCert() { 383 bool TestServerLauncher::LoadTestRootCert() {
384 #if defined(OS_LINUX) 384 #if defined(USE_NSS)
385 if (cert_) 385 if (cert_)
386 return true; 386 return true;
387 387
388 // TODO(dkegel): figure out how to get this to only happen once? 388 // TODO(dkegel): figure out how to get this to only happen once?
389 389
390 // This currently leaks a little memory. 390 // This currently leaks a little memory.
391 // TODO(dkegel): fix the leak and remove the entry in 391 // TODO(dkegel): fix the leak and remove the entry in
392 // tools/valgrind/suppressions.txt 392 // tools/valgrind/suppressions.txt
393 cert_ = reinterpret_cast<PrivateCERTCertificate*>( 393 cert_ = reinterpret_cast<PrivateCERTCertificate*>(
394 LoadTemporaryCert(GetRootCertPath())); 394 LoadTemporaryCert(GetRootCertPath()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 "certificate to your trusted roots for this test to work. " 429 "certificate to your trusted roots for this test to work. "
430 "For more info visit:\n" 430 "For more info visit:\n"
431 "http://dev.chromium.org/developers/testing\n"; 431 "http://dev.chromium.org/developers/testing\n";
432 return false; 432 return false;
433 } 433 }
434 #endif 434 #endif
435 return true; 435 return true;
436 } 436 }
437 437
438 } // namespace net 438 } // namespace net
OLDNEW
« no previous file with comments | « net/http/des.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698