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

Unified Diff: tests/standalone/io/certificate_test_client_database.dart

Issue 21716004: dart:io | Add SecureSocket.importPrivateCertificates, that reads a PKCS#12 file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add delayed deletion of locked temp directory on Windows. Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: tests/standalone/io/certificate_test_client_database.dart
diff --git a/tests/standalone/io/certificate_test_client_database.dart b/tests/standalone/io/certificate_test_client_database.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9723a6ab0d60bd1739f5e693f39a634f245b21a9
--- /dev/null
+++ b/tests/standalone/io/certificate_test_client_database.dart
@@ -0,0 +1,42 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Client that tests that a certificate authority certificate loaded
+// at runtime can be used to verify a certificate chain. The server it
+// connects to uses localhost_cert, signed by myauthority_cert, to connect
+// securely. This client tests that addCertificate works if a certificate
+// database has been specified.
+
+import 'dart:io';
+
+void main() {
+ int port = int.parse(new Options().arguments[0]);
+ String certificate = new Options().arguments[1];
+ String database = new Options().arguments[2];
+ SecureSocket.initialize(database: database,
+ password: 'dartdart',
+ readOnly: false);
+ SecureSocket.removeCertificate('localhost_cert');
+ SecureSocket.removeCertificate('myauthority_cert');
+ var mycert = new File(certificate).readAsBytesSync();
+ SecureSocket.addCertificate(mycert,
+ SecureSocket.TRUST_ISSUE_SERVER_CERTIFICATES);
+ if (null != SecureSocket.getCertificate('myauthority_cert')) {
+ throw "Expected getCertificate to return null";
+ }
+ SecureSocket.connect('localhost', port).then((SecureSocket socket) {
+ socket.writeln('hello world');
+ socket.listen((data) { });
+ return socket.close();
+ }).then((_) {
+ // The certificate is only in the in-memory cache, so cannot be removed.
+ try {
+ SecureSocket.removeCertificate('myauthority_cert');
+ } catch (e) {
+ if (e is! CertificateException) throw "error $e";
+ }
+ }).then((_) {
+ print('SUCCESS'); // Checked by parent process.
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698