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 for secure_socket_renegotiate_test, that runs in a subprocess. | 5 // Client for secure_socket_renegotiate_test, that runs in a subprocess. |
6 // The test verifies that client certificates work, if the client and server | 6 // The test verifies that client certificates work, if the client and server |
7 // are in separate processes, and that connection renegotiation can request | 7 // are in separate processes, and that connection renegotiation can request |
8 // a client certificate to be sent. | 8 // a client certificate to be sent. |
9 | 9 |
10 import "dart:async"; | 10 import "dart:async"; |
| 11 import "dart:convert"; |
11 import "dart:io"; | 12 import "dart:io"; |
12 | 13 |
13 const HOST_NAME = "localhost"; | 14 const HOST_NAME = "localhost"; |
14 const CERTIFICATE = "localhost_cert"; | 15 const CERTIFICATE = "localhost_cert"; |
15 | 16 |
16 | 17 |
17 class ExpectException implements Exception { | 18 class ExpectException implements Exception { |
18 ExpectException(this.message); | 19 ExpectException(this.message); |
19 String toString() => message; | 20 String toString() => message; |
20 String message; | 21 String message; |
(...skipping 16 matching lines...) Expand all Loading... |
37 | 38 |
38 void runClient(int port) { | 39 void runClient(int port) { |
39 SecureSocket.connect(HOST_NAME, port, sendClientCertificate: true) | 40 SecureSocket.connect(HOST_NAME, port, sendClientCertificate: true) |
40 .then((SecureSocket socket) { | 41 .then((SecureSocket socket) { |
41 X509Certificate certificate = socket.peerCertificate; | 42 X509Certificate certificate = socket.peerCertificate; |
42 expect(certificate != null); | 43 expect(certificate != null); |
43 expectEquals('CN=localhost', certificate.subject); | 44 expectEquals('CN=localhost', certificate.subject); |
44 expectEquals('CN=myauthority', certificate.issuer); | 45 expectEquals('CN=myauthority', certificate.issuer); |
45 StreamIterator<String> input = new StreamIterator(socket | 46 StreamIterator<String> input = new StreamIterator(socket |
46 .transform(new StringDecoder()) | 47 .transform(new StringDecoder()) |
47 .transform(new LineTransformer())); | 48 .transform(new LineSplitter())); |
48 socket.writeln('first'); | 49 socket.writeln('first'); |
49 input.moveNext() | 50 input.moveNext() |
50 .then((success) { | 51 .then((success) { |
51 expect(success); | 52 expect(success); |
52 expectEquals('first reply', input.current); | 53 expectEquals('first reply', input.current); |
53 socket.renegotiate(); | 54 socket.renegotiate(); |
54 socket.writeln('renegotiated'); | 55 socket.writeln('renegotiated'); |
55 return input.moveNext(); | 56 return input.moveNext(); |
56 }) | 57 }) |
57 .then((success) { | 58 .then((success) { |
(...skipping 12 matching lines...) Expand all Loading... |
70 }); | 71 }); |
71 }); | 72 }); |
72 } | 73 } |
73 | 74 |
74 | 75 |
75 void main() { | 76 void main() { |
76 final args = new Options().arguments; | 77 final args = new Options().arguments; |
77 SecureSocket.initialize(database: args[1], password: 'dartdart'); | 78 SecureSocket.initialize(database: args[1], password: 'dartdart'); |
78 runClient(int.parse(args[0])); | 79 runClient(int.parse(args[0])); |
79 } | 80 } |
OLD | NEW |