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

Side by Side Diff: runtime/bin/secure_socket.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
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>
10 #include <stdio.h> 9 #include <stdio.h>
11 #include <string.h> 10 #include <string.h>
11 #include <sys/stat.h>
12 12
13 #include <openssl/bio.h> 13 #include <openssl/bio.h>
14 #include <openssl/err.h> 14 #include <openssl/err.h>
15 #include <openssl/pkcs12.h> 15 #include <openssl/pkcs12.h>
16 #include <openssl/safestack.h> 16 #include <openssl/safestack.h>
17 #include <openssl/ssl.h> 17 #include <openssl/ssl.h>
18 #include <openssl/tls1.h> 18 #include <openssl/tls1.h>
19 #include <openssl/x509.h> 19 #include <openssl/x509.h>
20 20
21 #include "bin/builtin.h" 21 #include "bin/builtin.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // ERR_error_string_n is guaranteed to leave a null-terminated string. 76 // ERR_error_string_n is guaranteed to leave a null-terminated string.
77 } 77 }
78 error = ERR_get_error(); 78 error = ERR_get_error();
79 } 79 }
80 } 80 }
81 81
82 82
83 /* Handle an error reported from the BoringSSL library. */ 83 /* Handle an error reported from the BoringSSL library. */
84 static void ThrowIOException(int status, 84 static void ThrowIOException(int status,
85 const char* exception_type, 85 const char* exception_type,
86 const char* message, 86 const char* message) {
87 bool free_message = false) {
88 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE]; 87 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE];
89 FetchErrorString(error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE); 88 FetchErrorString(error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE);
90 OSError os_error_struct(status, error_string, OSError::kBoringSSL); 89 OSError os_error_struct(status, error_string, OSError::kBoringSSL);
91 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); 90 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct);
92 Dart_Handle exception = 91 Dart_Handle exception =
93 DartUtils::NewDartIOException(exception_type, message, os_error); 92 DartUtils::NewDartIOException(exception_type, message, os_error);
94 ASSERT(!Dart_IsError(exception)); 93 ASSERT(!Dart_IsError(exception));
95 if (free_message) {
96 free(const_cast<char*>(message));
97 }
98 Dart_ThrowException(exception); 94 Dart_ThrowException(exception);
99 UNREACHABLE(); 95 UNREACHABLE();
100 } 96 }
101 97
102 98
103 static SSLFilter* GetFilter(Dart_NativeArguments args) { 99 static SSLFilter* GetFilter(Dart_NativeArguments args) {
104 SSLFilter* filter; 100 SSLFilter* filter;
105 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); 101 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0));
106 ASSERT(Dart_IsInstance(dart_this)); 102 ASSERT(Dart_IsInstance(dart_this));
107 ThrowIfError(Dart_GetNativeInstanceField( 103 ThrowIfError(Dart_GetNativeInstanceField(
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 // CheckStatus should also throw an exception in uncaught cases. 666 // CheckStatus should also throw an exception in uncaught cases.
671 CheckStatus(status, "TlsException", "Failure in usePrivateKeyBytes"); 667 CheckStatus(status, "TlsException", "Failure in usePrivateKeyBytes");
672 } 668 }
673 669
674 670
675 static int SetTrustedCertificatesBytesPKCS12(SSL_CTX* context, 671 static int SetTrustedCertificatesBytesPKCS12(SSL_CTX* context,
676 BIO* bio, 672 BIO* bio,
677 const char* password) { 673 const char* password) {
678 ScopedPKCS12 p12(d2i_PKCS12_bio(bio, NULL)); 674 ScopedPKCS12 p12(d2i_PKCS12_bio(bio, NULL));
679 if (p12.get() == NULL) { 675 if (p12.get() == NULL) {
680 return NULL; 676 return 0;
681 } 677 }
682 678
683 EVP_PKEY* key = NULL; 679 EVP_PKEY* key = NULL;
684 X509 *cert = NULL; 680 X509 *cert = NULL;
685 STACK_OF(X509) *ca_certs = NULL; 681 STACK_OF(X509) *ca_certs = NULL;
686 int status = PKCS12_parse(p12.get(), password, &key, &cert, &ca_certs); 682 int status = PKCS12_parse(p12.get(), password, &key, &cert, &ca_certs);
687 if (status == 0) { 683 if (status == 0) {
688 return status; 684 return status;
689 } 685 }
690 686
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 } 776 }
781 BIO_free(roots_bio); 777 BIO_free(roots_bio);
782 } 778 }
783 779
784 780
785 static int UseChainBytesPKCS12(SSL_CTX* context, 781 static int UseChainBytesPKCS12(SSL_CTX* context,
786 BIO* bio, 782 BIO* bio,
787 const char* password) { 783 const char* password) {
788 ScopedPKCS12 p12(d2i_PKCS12_bio(bio, NULL)); 784 ScopedPKCS12 p12(d2i_PKCS12_bio(bio, NULL));
789 if (p12.get() == NULL) { 785 if (p12.get() == NULL) {
790 return NULL; 786 return 0;
791 } 787 }
792 788
793 EVP_PKEY* key = NULL; 789 EVP_PKEY* key = NULL;
794 X509 *cert = NULL; 790 X509 *cert = NULL;
795 STACK_OF(X509) *ca_certs = NULL; 791 STACK_OF(X509) *ca_certs = NULL;
796 int status = PKCS12_parse(p12.get(), password, &key, &cert, &ca_certs); 792 int status = PKCS12_parse(p12.get(), password, &key, &cert, &ca_certs);
797 if (status == 0) { 793 if (status == 0) {
798 return status; 794 return status;
799 } 795 }
800 796
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 } else { 1647 } else {
1652 if (SSL_LOG_DATA) Log::Print( 1648 if (SSL_LOG_DATA) Log::Print(
1653 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); 1649 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed);
1654 } 1650 }
1655 } 1651 }
1656 return bytes_processed; 1652 return bytes_processed;
1657 } 1653 }
1658 1654
1659 } // namespace bin 1655 } // namespace bin
1660 } // namespace dart 1656 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698