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

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: 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (Dart_IsString(password_object)) { 181 if (Dart_IsString(password_object)) {
182 ThrowIfError(Dart_StringToCString(password_object, &password)); 182 ThrowIfError(Dart_StringToCString(password_object, &password));
183 } else if (Dart_IsNull(password_object)) { 183 } else if (Dart_IsNull(password_object)) {
184 // Pass the empty string as the password. 184 // Pass the empty string as the password.
185 password = ""; 185 password = "";
186 } else { 186 } else {
187 Dart_ThrowException(DartUtils::NewDartArgumentError( 187 Dart_ThrowException(DartUtils::NewDartArgumentError(
188 "Password argument to SetCertificateDatabase is not a String or null")); 188 "Password argument to SetCertificateDatabase is not a String or null"));
189 } 189 }
190 190
191 SSLFilter::InitializeLibrary(certificate_database, password); 191 Dart_Handle builtin_roots_object =
192 ThrowIfError(Dart_GetNativeArgument(args, 2));
193 // Check that the type is boolean, and get the boolean value from it.
194 bool builtin_roots = true;
195 if (Dart_IsBoolean(builtin_roots_object)) {
196 ThrowIfError(Dart_BooleanValue(builtin_roots_object, &builtin_roots));
197 } else {
198 Dart_ThrowException(DartUtils::NewDartArgumentError(
199 "UseBuiltinRoots argument to SetCertificateDatabase is not a bool"));
200 }
201
202 SSLFilter::InitializeLibrary(certificate_database, password, builtin_roots);
192 Dart_ExitScope(); 203 Dart_ExitScope();
193 } 204 }
194 205
195 206
196 void SSLFilter::Init(Dart_Handle dart_this) { 207 void SSLFilter::Init(Dart_Handle dart_this) {
197 string_start_ = ThrowIfError( 208 string_start_ = ThrowIfError(
198 Dart_NewPersistentHandle(DartUtils::NewString("start"))); 209 Dart_NewPersistentHandle(DartUtils::NewString("start")));
199 string_length_ = ThrowIfError( 210 string_length_ = ThrowIfError(
200 Dart_NewPersistentHandle(DartUtils::NewString("length"))); 211 Dart_NewPersistentHandle(DartUtils::NewString("length")));
201 212
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 245 }
235 246
236 247
237 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) { 248 void SSLFilter::RegisterHandshakeCompleteCallback(Dart_Handle complete) {
238 ASSERT(NULL == handshake_complete_); 249 ASSERT(NULL == handshake_complete_);
239 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete)); 250 handshake_complete_ = ThrowIfError(Dart_NewPersistentHandle(complete));
240 } 251 }
241 252
242 253
243 void SSLFilter::InitializeLibrary(const char* certificate_database, 254 void SSLFilter::InitializeLibrary(const char* certificate_database,
244 const char* password) { 255 const char* password,
256 bool use_builtin_root_certificates) {
245 MutexLocker locker(&mutex_); 257 MutexLocker locker(&mutex_);
246 if (!library_initialized_) { 258 if (!library_initialized_) {
247 library_initialized_ = true; 259 library_initialized_ = true;
248 password_ = strdup(password); // This one copy persists until Dart exits. 260 password_ = strdup(password); // This one copy persists until Dart exits.
249 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 261 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
250 // TODO(whesse): Verify there are no UTF-8 issues here. 262 // TODO(whesse): Verify there are no UTF-8 issues here.
251 SECStatus status = NSS_Init(certificate_database); 263 PRUint32 init_flags = 0;
264 if (!use_builtin_root_certificates) {
265 init_flags |= NSS_INIT_NOMODDB;
266 }
267 SECStatus status = NSS_Initialize(certificate_database,
268 "",
269 "",
270 SECMOD_DB,
271 init_flags);
252 if (status != SECSuccess) { 272 if (status != SECSuccess) {
253 ThrowPRException("Unsuccessful NSS_Init call."); 273 ThrowPRException("Unsuccessful NSS_Init call.");
254 } 274 }
255 275
256 status = NSS_SetDomesticPolicy(); 276 status = NSS_SetDomesticPolicy();
257 if (status != SECSuccess) { 277 if (status != SECSuccess) {
258 ThrowPRException("Unsuccessful NSS_SetDomesticPolicy call."); 278 ThrowPRException("Unsuccessful NSS_SetDomesticPolicy call.");
259 } 279 }
260 // Enable TLS, as well as SSL3 and SSL2. 280 // Enable TLS, as well as SSL3 and SSL2.
261 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); 281 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) { 500 if (PR_WOULD_BLOCK_ERROR != pr_error) {
481 ThrowPRException("Error reading plaintext from SSLFilter"); 501 ThrowPRException("Error reading plaintext from SSLFilter");
482 } 502 }
483 bytes_processed = 0; 503 bytes_processed = 0;
484 } 504 }
485 break; 505 break;
486 } 506 }
487 } 507 }
488 return bytes_processed; 508 return bytes_processed;
489 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698