| 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 // This test verifies that secure connections that fail due to | 5 // This test verifies that secure connections that fail due to | 
| 6 // unauthenticated certificates throw exceptions in HttpClient. | 6 // unauthenticated certificates throw exceptions in HttpClient. | 
| 7 | 7 | 
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; | 
| 9 import "package:path/path.dart"; | 9 import "package:path/path.dart"; | 
| 10 import "dart:async"; | 10 import "dart:async"; | 
| 11 import "dart:io"; | 11 import "dart:io"; | 
| 12 | 12 | 
| 13 const HOST_NAME = "localhost"; | 13 const HOST_NAME = "localhost"; | 
| 14 const CERTIFICATE = "localhost_cert"; | 14 const CERTIFICATE = "localhost_cert"; | 
| 15 | 15 | 
|  | 16 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 
|  | 17 | 
|  | 18 SecurityContext untrustedServerContext = new SecurityContext() | 
|  | 19   ..useCertificateChain(localFile('certificates/untrusted_server_chain.pem')) | 
|  | 20   ..usePrivateKey(localFile('certificates/untrusted_server_key.pem'), | 
|  | 21                   password: 'dartdart'); | 
|  | 22 | 
|  | 23 SecurityContext clientContext = new SecurityContext() | 
|  | 24   ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 
|  | 25 | 
| 16 Future<SecureServerSocket> runServer() { | 26 Future<SecureServerSocket> runServer() { | 
| 17   SecureSocket.initialize( |  | 
| 18       database: Platform.script.resolve('pkcert').toFilePath(), |  | 
| 19       password: 'dartdart'); |  | 
| 20 |  | 
| 21   return HttpServer.bindSecure( | 27   return HttpServer.bindSecure( | 
| 22       HOST_NAME, 0, backlog: 5, certificateName: 'localhost_cert') | 28       HOST_NAME, 0, untrustedServerContext, backlog: 5) | 
| 23   .then((server) { | 29   .then((server) { | 
| 24     server.listen((HttpRequest request) { | 30     server.listen((HttpRequest request) { | 
| 25       request.listen((_) { }, onDone: () { request.response.close(); }); | 31       request.listen((_) { }, onDone: () { request.response.close(); }); | 
| 26     }, onError: (e) { if (e is! HandshakeException) throw e; }); | 32     }, onError: (e) { if (e is! HandshakeException) throw e; }); | 
| 27     return server; | 33     return server; | 
| 28   }); | 34   }); | 
| 29 } | 35 } | 
| 30 | 36 | 
| 31 void main() { | 37 void main() { | 
| 32   var clientScript = Platform.script | 38   var clientScript = Platform.script | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 46       } | 52       } | 
| 47     }); | 53     }); | 
| 48   } | 54   } | 
| 49 | 55 | 
| 50   runServer().then((server) { | 56   runServer().then((server) { | 
| 51     clientProcess(server.port).then((_) { | 57     clientProcess(server.port).then((_) { | 
| 52       server.close(); | 58       server.close(); | 
| 53     }); | 59     }); | 
| 54   }); | 60   }); | 
| 55 } | 61 } | 
| OLD | NEW | 
|---|