Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/secure_socket.h" | 5 #include "bin/secure_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <key.h> | 13 #include <key.h> |
| 14 #include <keyt.h> | 14 #include <keyt.h> |
| 15 #include <nss.h> | 15 #include <nss.h> |
| 16 #include <pk11pub.h> | 16 #include <pk11pub.h> |
| 17 #include <prerror.h> | 17 #include <prerror.h> |
| 18 #include <prinit.h> | 18 #include <prinit.h> |
| 19 #include <prnetdb.h> | 19 #include <prnetdb.h> |
| 20 #include <secmod.h> | |
| 20 #include <ssl.h> | 21 #include <ssl.h> |
| 21 #include <sslproto.h> | 22 #include <sslproto.h> |
| 22 | 23 |
| 23 #include "bin/builtin.h" | 24 #include "bin/builtin.h" |
| 24 #include "bin/dartutils.h" | 25 #include "bin/dartutils.h" |
| 25 #include "bin/net/nss_memio.h" | 26 #include "bin/net/nss_memio.h" |
| 26 #include "bin/thread.h" | 27 #include "bin/thread.h" |
| 27 #include "bin/utils.h" | 28 #include "bin/utils.h" |
| 28 #include "platform/utils.h" | 29 #include "platform/utils.h" |
| 29 | 30 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 } | 327 } |
| 327 | 328 |
| 328 | 329 |
| 329 void SSLFilter::RegisterBadCertificateCallback(Dart_Handle callback) { | 330 void SSLFilter::RegisterBadCertificateCallback(Dart_Handle callback) { |
| 330 if (NULL != bad_certificate_callback_) { | 331 if (NULL != bad_certificate_callback_) { |
| 331 Dart_DeletePersistentHandle(bad_certificate_callback_); | 332 Dart_DeletePersistentHandle(bad_certificate_callback_); |
| 332 } | 333 } |
| 333 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback)); | 334 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback)); |
| 334 } | 335 } |
| 335 | 336 |
| 337 static const char* builtin_roots_module = | |
|
Søren Gjesse
2013/04/12 14:59:31
As we don't currently have secure_socket_<platform
| |
| 338 #if defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID) | |
| 339 "name=\"Root Certs\" library=\"libnssckbi.so\""; | |
| 340 #elif defined(TARGET_OS_MACOS) | |
| 341 "name=\"Root Certs\" library=\"libnssckbi.dylib\""; | |
| 342 #elif defined(TARGET_OS_WINDOWS) | |
| 343 "name=\"Root Certs\" library=\"nssckbi.dll\""; | |
| 344 #else | |
| 345 #error Automatic target os detection failed. | |
| 346 #endif | |
| 347 | |
| 348 | |
|
Bill Hesse
2013/04/12 14:42:14
Too many spaces.
| |
| 336 | 349 |
| 337 void SSLFilter::InitializeLibrary(const char* certificate_database, | 350 void SSLFilter::InitializeLibrary(const char* certificate_database, |
| 338 const char* password, | 351 const char* password, |
| 339 bool use_builtin_root_certificates, | 352 bool use_builtin_root_certificates, |
| 340 bool report_duplicate_initialization) { | 353 bool report_duplicate_initialization) { |
| 341 MutexLocker locker(&mutex_); | 354 MutexLocker locker(&mutex_); |
| 355 SECStatus status; | |
| 342 if (!library_initialized_) { | 356 if (!library_initialized_) { |
| 343 password_ = strdup(password); // This one copy persists until Dart exits. | 357 password_ = strdup(password); // This one copy persists until Dart exits. |
| 344 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); | 358 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
| 345 // TODO(whesse): Verify there are no UTF-8 issues here. | 359 // TODO(whesse): Verify there are no UTF-8 issues here. |
| 346 PRUint32 init_flags = NSS_INIT_READONLY; | 360 if (certificate_database == NULL || certificate_database[0] == '\0') { |
|
Søren Gjesse
2013/04/12 14:59:31
Maybe add a test which passes both null and the em
| |
| 347 if (certificate_database == NULL) { | 361 status = NSS_NoDB_Init(NULL); |
| 348 // Passing the empty string as the database path does not try to open | 362 if (status != SECSuccess) { |
| 349 // a database in the current directory. | 363 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 350 certificate_database = ""; | 364 ThrowPRException("Failed NSS_NoDB_Init call."); |
| 351 // The flag NSS_INIT_NOCERTDB is documented to do what we want here, | 365 } |
| 352 // however it causes the builtins not to be available on Windows. | 366 if (use_builtin_root_certificates) { |
| 353 init_flags |= NSS_INIT_FORCEOPEN; | 367 SECMODModule* module = SECMOD_LoadUserModule( |
| 354 } | 368 const_cast<char*>(builtin_roots_module), NULL, PR_FALSE); |
| 355 if (!use_builtin_root_certificates) { | 369 if (!module) { |
| 356 init_flags |= NSS_INIT_NOMODDB; | 370 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 357 } | 371 ThrowPRException("Failed to load builtin root certificates."); |
| 358 SECStatus status = NSS_Initialize(certificate_database, | 372 } |
| 359 "", | 373 } |
| 360 "", | 374 } else { |
| 361 SECMOD_DB, | 375 PRUint32 init_flags = NSS_INIT_READONLY; |
| 362 init_flags); | 376 if (!use_builtin_root_certificates) { |
| 363 if (status != SECSuccess) { | 377 init_flags |= NSS_INIT_NOMODDB; |
| 364 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 378 } |
| 365 ThrowPRException("Failed NSS_Init call."); | 379 status = NSS_Initialize(certificate_database, |
| 380 "", | |
| 381 "", | |
| 382 SECMOD_DB, | |
| 383 init_flags); | |
| 384 if (status != SECSuccess) { | |
| 385 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | |
| 386 ThrowPRException("Failed NSS_Init call."); | |
| 387 } | |
| 366 } | 388 } |
| 367 library_initialized_ = true; | 389 library_initialized_ = true; |
| 368 | 390 |
| 369 status = NSS_SetDomesticPolicy(); | 391 status = NSS_SetDomesticPolicy(); |
| 370 if (status != SECSuccess) { | 392 if (status != SECSuccess) { |
| 371 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 393 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 372 ThrowPRException("Failed NSS_SetDomesticPolicy call."); | 394 ThrowPRException("Failed NSS_SetDomesticPolicy call."); |
| 373 } | 395 } |
| 374 // Enable TLS, as well as SSL3 and SSL2. | 396 // Enable TLS, as well as SSL3 and SSL2. |
| 375 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); | 397 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 if (PR_WOULD_BLOCK_ERROR != pr_error) { | 709 if (PR_WOULD_BLOCK_ERROR != pr_error) { |
| 688 ThrowPRException("Error reading plaintext from SSLFilter"); | 710 ThrowPRException("Error reading plaintext from SSLFilter"); |
| 689 } | 711 } |
| 690 bytes_processed = 0; | 712 bytes_processed = 0; |
| 691 } | 713 } |
| 692 break; | 714 break; |
| 693 } | 715 } |
| 694 } | 716 } |
| 695 return bytes_processed; | 717 return bytes_processed; |
| 696 } | 718 } |
| OLD | NEW |