| 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 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 import "package:path/path.dart"; | 10 import "package:path/path.dart"; |
| 11 | 11 |
| 12 const HOST_NAME = "localhost"; | 12 const HOST_NAME = "localhost"; |
| 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 14 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | 14 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); |
| 15 | 15 |
| 16 SecurityContext serverContext = new SecurityContext() | 16 SecurityContext serverContext = new SecurityContext() |
| 17 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) | 17 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) |
| 18 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), | 18 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), |
| 19 password: 'dartdart'); | 19 password: 'dartdart'); |
| 20 // TODO: Specify which client certificate roots to trust. | 20 // TODO: Specify which client certificate roots to trust. |
| 21 | 21 |
| 22 SecurityContext clientContext = new SecurityContext() | 22 SecurityContext clientContext = new SecurityContext() |
| 23 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')) | 23 ..setTrustedCertificatesBytes( |
| 24 readLocalFile('certificates/trusted_certs.pem')) |
| 24 // TODO: Set a client certificate here. | 25 // TODO: Set a client certificate here. |
| 25 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) | 26 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) |
| 26 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), | 27 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), |
| 27 password: 'dartdart'); | 28 password: 'dartdart'); |
| 28 | 29 |
| 29 void main() { | 30 void main() { |
| 30 asyncStart(); | 31 asyncStart(); |
| 31 HttpServer.bindSecure(HOST_NAME, | 32 HttpServer.bindSecure(HOST_NAME, |
| 32 0, | 33 0, |
| 33 serverContext, | 34 serverContext, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 51 }) | 52 }) |
| 52 .then((message) { | 53 .then((message) { |
| 53 String received = new String.fromCharCodes(message); | 54 String received = new String.fromCharCodes(message); |
| 54 Expect.equals(received, "Hello"); | 55 Expect.equals(received, "Hello"); |
| 55 client.close(); | 56 client.close(); |
| 56 server.close(); | 57 server.close(); |
| 57 asyncEnd(); | 58 asyncEnd(); |
| 58 }); | 59 }); |
| 59 }); | 60 }); |
| 60 } | 61 } |
| OLD | NEW |