OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 patch class SecureSocket { | 5 patch class SecureSocket { |
6 /* patch */ factory SecureSocket._(RawSecureSocket rawSocket) => | 6 /* patch */ factory SecureSocket._(RawSecureSocket rawSocket) => |
7 new _SecureSocket(rawSocket); | 7 new _SecureSocket(rawSocket); |
8 } | 8 } |
9 | 9 |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 implements SecurityContext { | 130 implements SecurityContext { |
131 _SecurityContext() { | 131 _SecurityContext() { |
132 _createNativeContext(); | 132 _createNativeContext(); |
133 } | 133 } |
134 | 134 |
135 void _createNativeContext() native "SecurityContext_Allocate"; | 135 void _createNativeContext() native "SecurityContext_Allocate"; |
136 | 136 |
137 static final SecurityContext defaultContext = | 137 static final SecurityContext defaultContext = |
138 new _SecurityContext().._trustBuiltinRoots(); | 138 new _SecurityContext().._trustBuiltinRoots(); |
139 | 139 |
140 Future usePrivateKey(String keyFile, {String password}) { | 140 void usePrivateKey(String keyFile, {String password}) { |
141 return (new File(keyFile)).readAsBytes().then((bytes) { | 141 usePrivateKeySync(keyFile, password: password); |
142 usePrivateKeyBytes(bytes, password: password); | 142 } |
143 }); | 143 void usePrivateKeySync(String keyFile, {String password}) { |
| 144 List<int> bytes = (new File(keyFile)).readAsBytesSync(); |
| 145 usePrivateKeyBytes(bytes, password: password); |
144 } | 146 } |
145 void usePrivateKeyBytes(List<int> keyBytes, {String password}) | 147 void usePrivateKeyBytes(List<int> keyBytes, {String password}) |
146 native "SecurityContext_UsePrivateKeyBytes"; | 148 native "SecurityContext_UsePrivateKeyBytes"; |
147 void setTrustedCertificates({String file, String directory}) | 149 |
148 native "SecurityContext_SetTrustedCertificates"; | 150 void setTrustedCertificates(String file) { |
149 Future useCertificateChain(String chainFile) { | 151 setTrustedCertificatesSync(file); |
150 return (new File(chainFile)).readAsBytes().then((bytes) { | 152 } |
151 useCertificateChainBytes(bytes); | 153 void setTrustedCertificatesSync(String file) { |
152 }); | 154 List<int> bytes = (new File(file)).readAsBytesSync(); |
| 155 setTrustedCertificatesBytes(bytes); |
| 156 } |
| 157 void setTrustedCertificatesBytes(List<int> certBytes) |
| 158 native "SecurityContext_SetTrustedCertificatesBytes"; |
| 159 |
| 160 void useCertificateChain({String file, String directory}) { |
| 161 if (directory != null) { |
| 162 throw new UnsupportedError( |
| 163 "The directory argument to useCertificateChain is not supported."); |
| 164 } |
| 165 useCertificateChainSync(file); |
| 166 } |
| 167 void useCertificateChainSync(String chainFile) { |
| 168 List<int> bytes = (new File(chainFile)).readAsBytesSync(); |
| 169 useCertificateChainBytes(bytes); |
153 } | 170 } |
154 void useCertificateChainBytes(List<int> chainBytes) | 171 void useCertificateChainBytes(List<int> chainBytes) |
155 native "SecurityContext_UseCertificateChainBytes"; | 172 native "SecurityContext_UseCertificateChainBytes"; |
156 void setClientAuthorities(String file) | 173 |
157 native "SecurityContext_SetClientAuthorities"; | 174 void setClientAuthorities(String file) { |
| 175 setClientAuthoritiesSync(file); |
| 176 } |
| 177 void setClientAuthoritiesSync(String file) { |
| 178 List<int> bytes = (new File(file)).readAsBytesSync(); |
| 179 setClientAuthoritiesBytes(bytes); |
| 180 } |
| 181 void setClientAuthoritiesBytes(List<int> authCertBytes) |
| 182 native "SecurityContext_SetClientAuthoritiesBytes"; |
158 void setAlpnProtocols(List<String> protocols, bool isServer) { | 183 void setAlpnProtocols(List<String> protocols, bool isServer) { |
159 Uint8List encodedProtocols = | 184 Uint8List encodedProtocols = |
160 SecurityContext._protocolsToLengthEncoding(protocols); | 185 SecurityContext._protocolsToLengthEncoding(protocols); |
161 _setAlpnProtocols(encodedProtocols, isServer); | 186 _setAlpnProtocols(encodedProtocols, isServer); |
162 } | 187 } |
163 void _setAlpnProtocols(Uint8List protocols, bool isServer) | 188 void _setAlpnProtocols(Uint8List protocols, bool isServer) |
164 native "SecurityContext_SetAlpnProtocols"; | 189 native "SecurityContext_SetAlpnProtocols"; |
165 void _trustBuiltinRoots() | 190 void _trustBuiltinRoots() |
166 native "SecurityContext_TrustBuiltinRoots"; | 191 native "SecurityContext_TrustBuiltinRoots"; |
167 } | 192 } |
(...skipping 14 matching lines...) Expand all Loading... |
182 return new DateTime.fromMillisecondsSinceEpoch(_startValidity(), | 207 return new DateTime.fromMillisecondsSinceEpoch(_startValidity(), |
183 isUtc: true); | 208 isUtc: true); |
184 } | 209 } |
185 DateTime get endValidity { | 210 DateTime get endValidity { |
186 return new DateTime.fromMillisecondsSinceEpoch(_endValidity(), | 211 return new DateTime.fromMillisecondsSinceEpoch(_endValidity(), |
187 isUtc: true); | 212 isUtc: true); |
188 } | 213 } |
189 int _startValidity() native "X509_StartValidity"; | 214 int _startValidity() native "X509_StartValidity"; |
190 int _endValidity() native "X509_EndValidity"; | 215 int _endValidity() native "X509_EndValidity"; |
191 } | 216 } |
OLD | NEW |