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

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

Issue 11308271: Add built-in root certificates to dart:io SecureSocket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix dart2js errors on new dart:io stuff. Created 8 years 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
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> 9 #include <sys/stat.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 "Illegal argument to ProcessBuffer")); 152 "Illegal argument to ProcessBuffer"));
153 } 153 }
154 154
155 intptr_t bytes_read = 155 intptr_t bytes_read =
156 GetFilter(args)->ProcessBuffer(static_cast<int>(buffer_id)); 156 GetFilter(args)->ProcessBuffer(static_cast<int>(buffer_id));
157 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); 157 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read));
158 Dart_ExitScope(); 158 Dart_ExitScope();
159 } 159 }
160 160
161 161
162 void FUNCTION_NAME(SecureSocket_SetCertificateDatabase) 162 void FUNCTION_NAME(SecureSocket_InitializeLibrary)
163 (Dart_NativeArguments args) { 163 (Dart_NativeArguments args) {
164 Dart_EnterScope(); 164 Dart_EnterScope();
165 Dart_Handle certificate_database_object = 165 Dart_Handle certificate_database_object =
166 ThrowIfError(Dart_GetNativeArgument(args, 0)); 166 ThrowIfError(Dart_GetNativeArgument(args, 0));
167 // Check that the type is string, and get the UTF-8 C string value from it. 167 // Check that the type is string, and get the UTF-8 C string value from it.
168 const char* certificate_database = NULL; 168 const char* certificate_database = NULL;
169 if (Dart_IsString(certificate_database_object)) { 169 if (Dart_IsString(certificate_database_object)) {
170 ThrowIfError(Dart_StringToCString(certificate_database_object, 170 ThrowIfError(Dart_StringToCString(certificate_database_object,
171 &certificate_database)); 171 &certificate_database));
172 } else { 172 } else if (!Dart_IsNull(certificate_database_object)) {
173 Dart_ThrowException(DartUtils::NewDartArgumentError( 173 Dart_ThrowException(DartUtils::NewDartArgumentError(
174 "Non-String certificate directory argument to SetCertificateDatabase")); 174 "Non-String certificate directory argument to SetCertificateDatabase"));
175 } 175 }
176 // Leave certificate_database as NULL if no value was provided.
176 177
177 Dart_Handle password_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); 178 Dart_Handle password_object = ThrowIfError(Dart_GetNativeArgument(args, 1));
178 // Check that the type is string or null, 179 // Check that the type is string or null,
179 // and get the UTF-8 C string value from it. 180 // and get the UTF-8 C string value from it.
180 const char* password = NULL; 181 const char* password = NULL;
181 if (Dart_IsString(password_object)) { 182 if (Dart_IsString(password_object)) {
182 ThrowIfError(Dart_StringToCString(password_object, &password)); 183 ThrowIfError(Dart_StringToCString(password_object, &password));
183 } else if (Dart_IsNull(password_object)) { 184 } else if (Dart_IsNull(password_object)) {
184 // Pass the empty string as the password. 185 // Pass the empty string as the password.
185 password = ""; 186 password = "";
186 } else { 187 } else {
187 Dart_ThrowException(DartUtils::NewDartArgumentError( 188 Dart_ThrowException(DartUtils::NewDartArgumentError(
188 "Password argument to SetCertificateDatabase is not a String or null")); 189 "Password argument to SetCertificateDatabase is not a String or null"));
189 } 190 }
190 191
191 SSLFilter::InitializeLibrary(certificate_database, password); 192 Dart_Handle builtin_roots_object =
193 ThrowIfError(Dart_GetNativeArgument(args, 2));
194 // Check that the type is boolean, and get the boolean value from it.
195 bool builtin_roots = true;
196 if (Dart_IsBoolean(builtin_roots_object)) {
197 ThrowIfError(Dart_BooleanValue(builtin_roots_object, &builtin_roots));
198 } else {
199 Dart_ThrowException(DartUtils::NewDartArgumentError(
200 "UseBuiltinRoots argument to SetCertificateDatabase is not a bool"));
201 }
202
203 SSLFilter::InitializeLibrary(certificate_database, password, builtin_roots);
192 Dart_ExitScope(); 204 Dart_ExitScope();
193 } 205 }
194 206
195 207
196 void SSLFilter::Init(Dart_Handle dart_this) { 208 void SSLFilter::Init(Dart_Handle dart_this) {
197 string_start_ = ThrowIfError( 209 string_start_ = ThrowIfError(
198 Dart_NewPersistentHandle(DartUtils::NewString("start"))); 210 Dart_NewPersistentHandle(DartUtils::NewString("start")));
199 string_length_ = ThrowIfError( 211 string_length_ = ThrowIfError(
200 Dart_NewPersistentHandle(DartUtils::NewString("length"))); 212 Dart_NewPersistentHandle(DartUtils::NewString("length")));
201 213
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 246 }
235 247
236 248
237 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) { 249 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) {
238 ASSERT(NULL == handshake_complete_); 250 ASSERT(NULL == handshake_complete_);
239 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete)); 251 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete));
240 } 252 }
241 253
242 254
243 void SSLFilter::InitializeLibrary(const char* certificate_database, 255 void SSLFilter::InitializeLibrary(const char* certificate_database,
244 const char* password) { 256 const char* password,
257 bool use_builtin_root_certificates) {
245 MutexLocker locker(&mutex_); 258 MutexLocker locker(&mutex_);
246 if (!library_initialized_) { 259 if (!library_initialized_) {
247 library_initialized_ = true; 260 library_initialized_ = true;
248 password_ = strdup(password); // This one copy persists until Dart exits. 261 password_ = strdup(password); // This one copy persists until Dart exits.
249 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 262 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
250 // TODO(whesse): Verify there are no UTF-8 issues here. 263 // TODO(whesse): Verify there are no UTF-8 issues here.
251 SECStatus status = NSS_Init(certificate_database); 264 PRUint32 init_flags = NSS_INIT_READONLY;
265 if (certificate_database == NULL) {
266 // This will not open a database in the current directory, even if it
Mads Ager (google) 2012/12/03 09:15:09 This looks strange. The documentation just says th
Bill Hesse 2012/12/03 12:20:04 I was referring only to passing "" as the database
Mads Ager (google) 2012/12/03 13:00:13 Thanks for updating the comment. Please add the pa
267 // exists.
268 certificate_database = "";
269 init_flags |= NSS_INIT_FORCEOPEN;
270 }
271 if (!use_builtin_root_certificates) {
272 init_flags |= NSS_INIT_NOMODDB;
273 }
274 SECStatus status = NSS_Initialize(certificate_database,
275 "",
276 "",
277 SECMOD_DB,
278 init_flags);
252 if (status != SECSuccess) { 279 if (status != SECSuccess) {
253 ThrowPRException("Unsuccessful NSS_Init call."); 280 ThrowPRException("Unsuccessful NSS_Init call.");
254 } 281 }
255 282
256 status = NSS_SetDomesticPolicy(); 283 status = NSS_SetDomesticPolicy();
257 if (status != SECSuccess) { 284 if (status != SECSuccess) {
258 ThrowPRException("Unsuccessful NSS_SetDomesticPolicy call."); 285 ThrowPRException("Unsuccessful NSS_SetDomesticPolicy call.");
259 } 286 }
260 // Enable TLS, as well as SSL3 and SSL2. 287 // Enable TLS, as well as SSL3 and SSL2.
261 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); 288 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if (PR_WOULD_BLOCK_ERROR != pr_error) { 507 if (PR_WOULD_BLOCK_ERROR != pr_error) {
481 ThrowPRException("Error reading plaintext from SSLFilter"); 508 ThrowPRException("Error reading plaintext from SSLFilter");
482 } 509 }
483 bytes_processed = 0; 510 bytes_processed = 0;
484 } 511 }
485 break; 512 break;
486 } 513 }
487 } 514 }
488 return bytes_processed; 515 return bytes_processed;
489 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698