| 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> |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 439 } |
| 440 | 440 |
| 441 filter_ = SSL_ImportFD(NULL, filter_); | 441 filter_ = SSL_ImportFD(NULL, filter_); |
| 442 if (filter_ == NULL) { | 442 if (filter_ == NULL) { |
| 443 ThrowPRException("Failed SSL_ImportFD call"); | 443 ThrowPRException("Failed SSL_ImportFD call"); |
| 444 } | 444 } |
| 445 | 445 |
| 446 SECStatus status; | 446 SECStatus status; |
| 447 if (is_server) { | 447 if (is_server) { |
| 448 PK11_SetPasswordFunc(PasswordCallback); | 448 PK11_SetPasswordFunc(PasswordCallback); |
| 449 CERTCertDBHandle* certificate_database = CERT_GetDefaultCertDB(); | 449 |
| 450 if (certificate_database == NULL) { | 450 CERTCertificate* certificate = NULL; |
| 451 ThrowPRException("Certificate database cannot be loaded"); | 451 if (strstr(certificate_name, "CN=") != NULL) { |
| 452 } | 452 // Look up certificate using the distinguished name (DN) certificate_name. |
| 453 // TODO(whesse): Switch to a function that looks up certs by nickname, | 453 CERTCertDBHandle* certificate_database = CERT_GetDefaultCertDB(); |
| 454 // so that server and client uses of certificateName agree. | 454 if (certificate_database == NULL) { |
| 455 CERTCertificate* certificate = CERT_FindCertByNameString( | 455 ThrowPRException("Certificate database cannot be loaded"); |
| 456 certificate_database, | 456 } |
| 457 const_cast<char*>(certificate_name)); | 457 certificate = CERT_FindCertByNameString(certificate_database, |
| 458 if (certificate == NULL) { | 458 const_cast<char*>(certificate_name)); |
| 459 ThrowPRException("Cannot find server certificate by name"); | 459 if (certificate == NULL) { |
| 460 ThrowPRException( |
| 461 "Cannot find server certificate by distinguished name"); |
| 462 } |
| 463 } else { |
| 464 // Look up certificate using the nickname certificate_name. |
| 465 certificate = PK11_FindCertFromNickname( |
| 466 const_cast<char*>(certificate_name), |
| 467 static_cast<void*>(const_cast<char*>(password_))); |
| 468 if (certificate == NULL) { |
| 469 ThrowPRException("Cannot find server certificate by nickname"); |
| 470 } |
| 460 } | 471 } |
| 461 SECKEYPrivateKey* key = PK11_FindKeyByAnyCert( | 472 SECKEYPrivateKey* key = PK11_FindKeyByAnyCert( |
| 462 certificate, | 473 certificate, |
| 463 static_cast<void*>(const_cast<char*>(password_))); | 474 static_cast<void*>(const_cast<char*>(password_))); |
| 464 if (key == NULL) { | 475 if (key == NULL) { |
| 465 CERT_DestroyCertificate(certificate); | 476 CERT_DestroyCertificate(certificate); |
| 466 if (PR_GetError() == -8177) { | 477 if (PR_GetError() == -8177) { |
| 467 ThrowPRException("Certificate database password incorrect"); | 478 ThrowPRException("Certificate database password incorrect"); |
| 468 } else { | 479 } else { |
| 469 ThrowPRException("Failed PK11_FindKeyByAnyCert call." | 480 ThrowPRException("Failed PK11_FindKeyByAnyCert call." |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 if (PR_WOULD_BLOCK_ERROR != pr_error) { | 687 if (PR_WOULD_BLOCK_ERROR != pr_error) { |
| 677 ThrowPRException("Error reading plaintext from SSLFilter"); | 688 ThrowPRException("Error reading plaintext from SSLFilter"); |
| 678 } | 689 } |
| 679 bytes_processed = 0; | 690 bytes_processed = 0; |
| 680 } | 691 } |
| 681 break; | 692 break; |
| 682 } | 693 } |
| 683 } | 694 } |
| 684 return bytes_processed; | 695 return bytes_processed; |
| 685 } | 696 } |
| OLD | NEW |