| 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 | 10 |
| 11 InternetAddress HOST; | 11 InternetAddress HOST; |
| 12 | 12 |
| 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 14 | 14 |
| 15 SecurityContext serverContext(String certType, String password) => | 15 SecurityContext serverContext(String certType, String password) => |
| 16 new SecurityContext() | 16 new SecurityContext() |
| 17 ..useCertificateChainSync( | 17 ..useCertificateChain(localFile( |
| 18 localFile('certificates/server_chain.$certType'), password: password) | 18 'certificates/server_chain.$certType'), password: password) |
| 19 ..usePrivateKeySync( | 19 ..usePrivateKey(localFile( |
| 20 localFile('certificates/server_key.$certType'), password: password) | 20 'certificates/server_key.$certType'), password: password) |
| 21 ..setTrustedCertificatesSync(localFile( | 21 ..setTrustedCertificates(localFile( |
| 22 'certificates/client_authority.$certType'), password: password) | 22 'certificates/client_authority.$certType'), password: password) |
| 23 ..setClientAuthoritiesSync(localFile( | 23 ..setClientAuthorities(localFile( |
| 24 'certificates/client_authority.$certType'), password: password); | 24 'certificates/client_authority.$certType'), password: password); |
| 25 | 25 |
| 26 SecurityContext clientCertContext(String certType, String password) => | 26 SecurityContext clientCertContext(String certType, String password) => |
| 27 new SecurityContext() | 27 new SecurityContext() |
| 28 ..setTrustedCertificatesSync( | 28 ..setTrustedCertificates(localFile( |
| 29 localFile('certificates/trusted_certs.$certType'), password: password) | 29 'certificates/trusted_certs.$certType'), password: password) |
| 30 ..useCertificateChainSync( | 30 ..useCertificateChain(localFile( |
| 31 localFile('certificates/client1.$certType'), password: password) | 31 'certificates/client1.$certType'), password: password) |
| 32 ..usePrivateKeySync( | 32 ..usePrivateKey(localFile( |
| 33 localFile('certificates/client1_key.$certType'), password: password); | 33 'certificates/client1_key.$certType'), password: password); |
| 34 | 34 |
| 35 SecurityContext clientNoCertContext(String certType, String password) => | 35 SecurityContext clientNoCertContext(String certType, String password) => |
| 36 new SecurityContext() | 36 new SecurityContext() |
| 37 ..setTrustedCertificatesSync(localFile( | 37 ..setTrustedCertificates(localFile( |
| 38 'certificates/trusted_certs.$certType'), password: password); | 38 'certificates/trusted_certs.$certType'), password: password); |
| 39 | 39 |
| 40 Future testClientCertificate( | 40 Future testClientCertificate( |
| 41 {bool required, bool sendCert, String certType, String password}) async { | 41 {bool required, bool sendCert, String certType, String password}) async { |
| 42 var server = await SecureServerSocket.bind(HOST, 0, | 42 var server = await SecureServerSocket.bind(HOST, 0, |
| 43 serverContext(certType, password), | 43 serverContext(certType, password), |
| 44 requestClientCertificate: true, | 44 requestClientCertificate: true, |
| 45 requireClientCertificate: required); | 45 requireClientCertificate: required); |
| 46 var clientContext = sendCert ? | 46 var clientContext = sendCert ? |
| 47 clientCertContext(certType, password) : | 47 clientCertContext(certType, password) : |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 await testClientCertificate( | 94 await testClientCertificate( |
| 95 required: false, sendCert: true, certType: 'p12', password: 'dartdart'); | 95 required: false, sendCert: true, certType: 'p12', password: 'dartdart'); |
| 96 await testClientCertificate( | 96 await testClientCertificate( |
| 97 required: true, sendCert: true, certType: 'p12', password: 'dartdart'); | 97 required: true, sendCert: true, certType: 'p12', password: 'dartdart'); |
| 98 await testClientCertificate( | 98 await testClientCertificate( |
| 99 required: false, sendCert: false, certType: 'p12', password: 'dartdart'); | 99 required: false, sendCert: false, certType: 'p12', password: 'dartdart'); |
| 100 await testClientCertificate( | 100 await testClientCertificate( |
| 101 required: true, sendCert: false, certType: 'p12', password: 'dartdart'); | 101 required: true, sendCert: false, certType: 'p12', password: 'dartdart'); |
| 102 asyncEnd(); | 102 asyncEnd(); |
| 103 } | 103 } |
| OLD | NEW |