| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Client that tests that a certificate authority certificate loaded | 5 // Client that tests that a certificate authority certificate loaded |
| 6 // at runtime can be used to verify a certificate chain. The server it | 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 | 7 // connects to uses localhost_cert, signed by myauthority_cert, to connect |
| 8 // securely. | 8 // securely. |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 threw = false; | 26 threw = false; |
| 27 try { | 27 try { |
| 28 SecureSocket.addCertificate(mycert, "Trust me, I'm a string"); | 28 SecureSocket.addCertificate(mycert, "Trust me, I'm a string"); |
| 29 } on CertificateException catch (e) { | 29 } on CertificateException catch (e) { |
| 30 threw = true; | 30 threw = true; |
| 31 } | 31 } |
| 32 if (!threw) throw new AssertException("Expected bad trust string to throw"); | 32 if (!threw) throw new AssertException("Expected bad trust string to throw"); |
| 33 | 33 |
| 34 SecureSocket.addCertificate(mycert, | 34 SecureSocket.addCertificate(mycert, |
| 35 SecureSocket.TRUST_ISSUE_SERVER_CERTIFICATES); | 35 SecureSocket.TRUST_ISSUE_SERVER_CERTIFICATES); |
| 36 |
| 36 SecureSocket.connect('localhost', port).then((SecureSocket socket) { | 37 SecureSocket.connect('localhost', port).then((SecureSocket socket) { |
| 37 socket.writeln("hello world"); | 38 socket.writeln('hello world'); |
| 38 socket.listen((data) { }); | 39 socket.listen((data) { }); |
| 39 socket.close(); | 40 return socket.close(); |
| 41 }).then((_) { |
| 42 SecureSocket.changeTrust('myauthority_cert', ',,'); |
| 43 return SecureSocket.connect('localhost', port); |
| 44 }).then((_) { |
| 45 throw new AssertException( |
| 46 "Expected untrusted authority to stop connection"); |
| 47 }, onError: (e) { |
| 48 if (e is! CertificateException) throw e; |
| 49 }).then((_) { |
| 50 SecureSocket.changeTrust('myauthority_cert', 'C,,'); |
| 51 return SecureSocket.connect('localhost', port); |
| 52 }).then((SecureSocket socket) { |
| 53 socket.writeln('hello world'); |
| 54 socket.listen((data) { }); |
| 55 return socket.close(); |
| 56 }).then((_) { |
| 57 SecureSocket.removeCertificate('myauthority_cert'); |
| 58 return SecureSocket.connect('localhost', port); |
| 59 }).then((_) { |
| 60 throw new AssertException("Expected untrusted root to stop connection"); |
| 61 }, onError: (e) { |
| 62 if (e is! CertificateException) throw e; |
| 63 }).then((_) { |
| 64 print('SUCCESS'); // Checked by parent process. |
| 40 }); | 65 }); |
| 41 } | 66 } |
| OLD | NEW |