| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // | |
| 5 // Client that tests that a certificate authority certificate loaded | |
| 6 // at runtime can be used to verify a certificate chain. The server it | |
| 7 // connects to uses localhost_cert, signed by myauthority_cert, to connect | |
| 8 // securely. This client tests that addCertificate works if a certificate | |
| 9 // database has been specified. | |
| 10 | |
| 11 import 'dart:io'; | |
| 12 | |
| 13 void main() { | |
| 14 int port = int.parse(new Options().arguments[0]); | |
| 15 String certificate = new Options().arguments[1]; | |
| 16 String database = new Options().arguments[2]; | |
| 17 SecureSocket.initialize(database: database, | |
| 18 password: 'dartdart', | |
| 19 readOnly: false); | |
| 20 SecureSocket.removeCertificate('localhost_cert'); | |
| 21 SecureSocket.removeCertificate('myauthority_cert'); | |
| 22 var mycert = new File(certificate).readAsBytesSync(); | |
| 23 SecureSocket.addCertificate(mycert, | |
| 24 SecureSocket.TRUST_ISSUE_SERVER_CERTIFICATES); | |
| 25 if (null != SecureSocket.getCertificate('myauthority_cert')) { | |
| 26 throw "Expected getCertificate to return null"; | |
| 27 } | |
| 28 SecureSocket.connect('localhost', port).then((SecureSocket socket) { | |
| 29 socket.writeln('hello world'); | |
| 30 socket.listen((data) { }); | |
| 31 return socket.close(); | |
| 32 }).then((_) { | |
| 33 // The certificate is only in the in-memory cache, so cannot be removed. | |
| 34 try { | |
| 35 SecureSocket.removeCertificate('myauthority_cert'); | |
| 36 } catch (e) { | |
| 37 if (e is! CertificateException) throw "error $e"; | |
| 38 } | |
| 39 }).then((_) { | |
| 40 print('SUCCESS'); // Checked by parent process. | |
| 41 }); | |
| 42 } | |
| OLD | NEW |