| 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 client certificates work, if the client and server | 5 // This test verifies that client certificates work, if the client and server |
| 6 // are in separate processes, and that connection renegotiation works, and | 6 // are in separate processes, and that connection renegotiation works, and |
| 7 // can request a client certificate to be sent. | 7 // can request a client certificate to be sent. |
| 8 | 8 |
| 9 import "dart:async"; | 9 import "dart:async"; |
| 10 import "dart:convert"; | 10 import "dart:convert"; |
| 11 import "dart:io"; | 11 import "dart:io"; |
| 12 | 12 |
| 13 import "package:expect/expect.dart"; | 13 import "package:expect/expect.dart"; |
| 14 import "package:path/path.dart"; | 14 import "package:path/path.dart"; |
| 15 | 15 |
| 16 const HOST_NAME = "localhost"; | 16 const HOST_NAME = "localhost"; |
| 17 const CERTIFICATE = "localhost_cert"; | 17 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 18 | 18 |
| 19 | 19 SecurityContext serverContext = new SecurityContext() |
| 20 String certificateDatabase() => Platform.script.resolve('pkcert').toFilePath(); | 20 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
| 21 | 21 ..usePrivateKey(localFile('certificates/server_key.pem'), |
| 22 password: 'dartdart'); |
| 22 | 23 |
| 23 Future<SecureServerSocket> runServer() { | 24 Future<SecureServerSocket> runServer() { |
| 24 SecureSocket.initialize(database: certificateDatabase(), | 25 return SecureServerSocket.bind(HOST_NAME, 0, serverContext) |
| 25 password: 'dartdart'); | |
| 26 | |
| 27 return SecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE) | |
| 28 .then((SecureServerSocket server) { | 26 .then((SecureServerSocket server) { |
| 29 server.listen((SecureSocket socket) { | 27 server.listen((SecureSocket socket) { |
| 30 Expect.isNull(socket.peerCertificate); | 28 Expect.isNull(socket.peerCertificate); |
| 31 | 29 |
| 32 StreamIterator<String> input = | 30 StreamIterator<String> input = |
| 33 new StreamIterator(socket.transform(UTF8.decoder) | 31 new StreamIterator(socket.transform(UTF8.decoder) |
| 34 .transform(new LineSplitter())); | 32 .transform(new LineSplitter())); |
| 35 input.moveNext().then((success) { | 33 input.moveNext().then((success) { |
| 36 Expect.isTrue(success); | 34 Expect.isTrue(success); |
| 37 Expect.equals('first', input.current); | 35 Expect.equals('first', input.current); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 64 | 62 |
| 65 void main() { | 63 void main() { |
| 66 runServer() | 64 runServer() |
| 67 .then((SecureServerSocket server) { | 65 .then((SecureServerSocket server) { |
| 68 var clientScript = Platform.script | 66 var clientScript = Platform.script |
| 69 .toFilePath() | 67 .toFilePath() |
| 70 .replaceFirst("_test.dart", "_client.dart"); | 68 .replaceFirst("_test.dart", "_client.dart"); |
| 71 Expect.isTrue(clientScript.endsWith("_client.dart")); | 69 Expect.isTrue(clientScript.endsWith("_client.dart")); |
| 72 Process.run(Platform.executable, | 70 Process.run(Platform.executable, |
| 73 [clientScript, | 71 [clientScript, |
| 74 server.port.toString(), | 72 server.port.toString()]) |
| 75 certificateDatabase()]) | |
| 76 .then((ProcessResult result) { | 73 .then((ProcessResult result) { |
| 77 if (result.exitCode != 0) { | 74 if (result.exitCode != 0) { |
| 78 print("Client failed, stdout:"); | 75 print("Client failed, stdout:"); |
| 79 print(result.stdout); | 76 print(result.stdout); |
| 80 print(" stderr:"); | 77 print(" stderr:"); |
| 81 print(result.stderr); | 78 print(result.stderr); |
| 82 Expect.fail('Client subprocess exit code: ${result.exitCode}'); | 79 Expect.fail('Client subprocess exit code: ${result.exitCode}'); |
| 83 } | 80 } |
| 84 }); | 81 }); |
| 85 }); | 82 }); |
| 86 } | 83 } |
| OLD | NEW |