| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using Ice.Internal; |
| | 4 | | using System.Diagnostics; |
| | 5 | | using System.Net.Security; |
| | 6 | | using System.Security; |
| | 7 | | using System.Security.Cryptography; |
| | 8 | | using System.Security.Cryptography.X509Certificates; |
| | 9 | | using System.Text; |
| | 10 | |
|
| | 11 | | namespace Ice.SSL; |
| | 12 | |
|
| | 13 | | internal class SSLEngine |
| | 14 | | { |
| 1 | 15 | | internal SSLEngine(Ice.Communicator communicator) |
| | 16 | | { |
| 1 | 17 | | _communicator = communicator; |
| 1 | 18 | | _logger = communicator.getLogger(); |
| 1 | 19 | | _securityTraceLevel = _communicator.getProperties().getIcePropertyAsInt("IceSSL.Trace.Security"); |
| 1 | 20 | | _securityTraceCategory = "Security"; |
| 1 | 21 | | _trustManager = new TrustManager(_communicator); |
| 1 | 22 | | } |
| | 23 | |
|
| | 24 | | internal void initialize() |
| | 25 | | { |
| 1 | 26 | | Ice.Properties properties = communicator().getProperties(); |
| | 27 | |
|
| | 28 | | // Check for a default directory. We look in this directory for files mentioned in the configuration. |
| 1 | 29 | | _defaultDir = properties.getIceProperty("IceSSL.DefaultDir"); |
| | 30 | |
|
| 1 | 31 | | _verifyPeer = properties.getIcePropertyAsInt("IceSSL.VerifyPeer"); |
| | 32 | |
|
| | 33 | | // CheckCRL determines whether the certificate revocation list is checked, and how strictly. |
| 1 | 34 | | _checkCRL = properties.getIcePropertyAsInt("IceSSL.CheckCRL"); |
| | 35 | |
|
| 1 | 36 | | string certStoreLocation = properties.getIceProperty("IceSSL.CertStoreLocation"); |
| | 37 | | StoreLocation storeLocation; |
| 1 | 38 | | if (certStoreLocation == "CurrentUser") |
| | 39 | | { |
| 1 | 40 | | storeLocation = StoreLocation.CurrentUser; |
| | 41 | | } |
| 0 | 42 | | else if (certStoreLocation == "LocalMachine") |
| | 43 | | { |
| 0 | 44 | | storeLocation = StoreLocation.LocalMachine; |
| | 45 | | } |
| | 46 | | else |
| | 47 | | { |
| 0 | 48 | | _logger.warning( |
| 0 | 49 | | "Invalid IceSSL.CertStoreLocation value `" + certStoreLocation + "' adjusted to `CurrentUser'"); |
| 0 | 50 | | storeLocation = StoreLocation.CurrentUser; |
| | 51 | | } |
| 1 | 52 | | _useMachineContext = certStoreLocation == "LocalMachine"; |
| | 53 | |
|
| | 54 | | // CheckCertName determines whether we compare the name in a peer's certificate against its hostname. |
| 1 | 55 | | _checkCertName = properties.getIcePropertyAsInt("IceSSL.CheckCertName") > 0; |
| | 56 | |
|
| | 57 | | Debug.Assert(_certs == null); |
| | 58 | | // If IceSSL.CertFile is defined, load a certificate from a file and add it to the collection. |
| 1 | 59 | | _certs = []; |
| 1 | 60 | | string certFile = properties.getIceProperty("IceSSL.CertFile"); |
| 1 | 61 | | string passwordStr = properties.getIceProperty("IceSSL.Password"); |
| 1 | 62 | | string findCert = properties.getIceProperty("IceSSL.FindCert"); |
| | 63 | |
|
| 1 | 64 | | if (certFile.Length > 0) |
| | 65 | | { |
| 1 | 66 | | if (!checkPath(ref certFile)) |
| | 67 | | { |
| 0 | 68 | | throw new Ice.InitializationException($"IceSSL: certificate file not found: {certFile}"); |
| | 69 | | } |
| | 70 | |
|
| | 71 | | try |
| | 72 | | { |
| | 73 | | X509Certificate2 cert; |
| | 74 | | X509KeyStorageFlags importFlags; |
| 1 | 75 | | if (_useMachineContext) |
| | 76 | | { |
| 0 | 77 | | importFlags = X509KeyStorageFlags.MachineKeySet; |
| | 78 | | } |
| | 79 | | else |
| | 80 | | { |
| 1 | 81 | | importFlags = X509KeyStorageFlags.UserKeySet; |
| | 82 | | } |
| | 83 | |
|
| 1 | 84 | | if (passwordStr.Length > 0) |
| | 85 | | { |
| 1 | 86 | | using SecureString password = createSecureString(passwordStr); |
| 1 | 87 | | cert = new X509Certificate2(certFile, password, importFlags); |
| | 88 | | } |
| | 89 | | else |
| | 90 | | { |
| 1 | 91 | | cert = new X509Certificate2(certFile, (string)null, importFlags); |
| | 92 | | } |
| 1 | 93 | | _certs.Add(cert); |
| 1 | 94 | | } |
| 0 | 95 | | catch (CryptographicException ex) |
| | 96 | | { |
| 0 | 97 | | throw new Ice.InitializationException( |
| 0 | 98 | | $"IceSSL: error while attempting to load certificate from {certFile}", |
| 0 | 99 | | ex); |
| | 100 | | } |
| | 101 | | } |
| 1 | 102 | | else if (findCert.Length > 0) |
| | 103 | | { |
| 1 | 104 | | string certStore = properties.getIceProperty("IceSSL.CertStore"); |
| 1 | 105 | | _certs.AddRange(findCertificates("IceSSL.FindCert", storeLocation, certStore, findCert)); |
| 1 | 106 | | if (_certs.Count == 0) |
| | 107 | | { |
| 1 | 108 | | throw new Ice.InitializationException("IceSSL: no certificates found"); |
| | 109 | | } |
| | 110 | | } |
| | 111 | |
|
| | 112 | | Debug.Assert(_caCerts == null); |
| 1 | 113 | | string certAuthFile = properties.getIceProperty("IceSSL.CAs"); |
| 1 | 114 | | if (certAuthFile.Length > 0 || properties.getIcePropertyAsInt("IceSSL.UsePlatformCAs") <= 0) |
| | 115 | | { |
| 1 | 116 | | _caCerts = []; |
| | 117 | | } |
| | 118 | |
|
| 1 | 119 | | if (certAuthFile.Length > 0) |
| | 120 | | { |
| 1 | 121 | | if (!checkPath(ref certAuthFile)) |
| | 122 | | { |
| 0 | 123 | | throw new Ice.InitializationException($"IceSSL: CA certificate file not found: {certAuthFile}"); |
| | 124 | | } |
| | 125 | | try |
| | 126 | | { |
| | 127 | | try |
| | 128 | | { |
| | 129 | | // First try to import as a PEM file, which supports importing multiple certificates from a PEM |
| | 130 | | // encoded file |
| 1 | 131 | | _caCerts.ImportFromPemFile(certAuthFile); |
| 1 | 132 | | } |
| 0 | 133 | | catch (CryptographicException) |
| | 134 | | { |
| | 135 | | // Expected if the file is not in PEM format. |
| 0 | 136 | | } |
| | 137 | |
|
| 1 | 138 | | if (_caCerts.Count == 0) |
| | 139 | | { |
| | 140 | | // Fallback to Import which handles DER/PFX. |
| 1 | 141 | | _caCerts.Import(certAuthFile); |
| | 142 | | } |
| 1 | 143 | | } |
| 0 | 144 | | catch (Exception ex) |
| | 145 | | { |
| 0 | 146 | | throw new Ice.InitializationException( |
| 0 | 147 | | $"IceSSL: error while attempting to load CA certificate from {certAuthFile}", |
| 0 | 148 | | ex); |
| | 149 | | } |
| | 150 | | } |
| 1 | 151 | | } |
| | 152 | |
|
| 0 | 153 | | internal bool useMachineContext() => _useMachineContext; |
| | 154 | |
|
| 0 | 155 | | internal X509Certificate2Collection caCerts() => _caCerts; |
| | 156 | |
|
| 1 | 157 | | internal Ice.Communicator communicator() => _communicator; |
| | 158 | |
|
| 1 | 159 | | internal int securityTraceLevel() => _securityTraceLevel; |
| | 160 | |
|
| 1 | 161 | | internal string securityTraceCategory() => _securityTraceCategory; |
| | 162 | |
|
| 1 | 163 | | internal X509Certificate2Collection certs() => _certs; |
| | 164 | |
|
| | 165 | | internal void traceStream(SslStream stream, string connInfo) |
| | 166 | | { |
| 0 | 167 | | var s = new StringBuilder(); |
| 0 | 168 | | s.Append("SSL connection summary"); |
| 0 | 169 | | if (connInfo.Length > 0) |
| | 170 | | { |
| 0 | 171 | | s.Append('\n'); |
| 0 | 172 | | s.Append(connInfo); |
| | 173 | | } |
| 0 | 174 | | s.Append("\nauthenticated = " + (stream.IsAuthenticated ? "yes" : "no")); |
| 0 | 175 | | s.Append("\nencrypted = " + (stream.IsEncrypted ? "yes" : "no")); |
| 0 | 176 | | s.Append("\nsigned = " + (stream.IsSigned ? "yes" : "no")); |
| 0 | 177 | | s.Append("\nmutually authenticated = " + (stream.IsMutuallyAuthenticated ? "yes" : "no")); |
| 0 | 178 | | s.Append("\nhash algorithm = " + stream.HashAlgorithm + "/" + stream.HashStrength); |
| 0 | 179 | | s.Append("\ncipher algorithm = " + stream.CipherAlgorithm + "/" + stream.CipherStrength); |
| 0 | 180 | | s.Append("\nkey exchange algorithm = " + stream.KeyExchangeAlgorithm + "/" + stream.KeyExchangeStrength); |
| 0 | 181 | | s.Append("\nprotocol = " + stream.SslProtocol); |
| 0 | 182 | | _logger.trace(_securityTraceCategory, s.ToString()); |
| 0 | 183 | | } |
| | 184 | |
|
| | 185 | | internal void verifyPeer(ConnectionInfo info, string description) |
| | 186 | | { |
| 1 | 187 | | if (!_trustManager.verify(info, description)) |
| | 188 | | { |
| 1 | 189 | | string msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + |
| 1 | 190 | | description; |
| 1 | 191 | | if (_securityTraceLevel >= 1) |
| | 192 | | { |
| 0 | 193 | | _logger.trace(_securityTraceCategory, msg); |
| | 194 | | } |
| | 195 | |
|
| 1 | 196 | | throw new SecurityException($"IceSSL: {msg}"); |
| | 197 | | } |
| 1 | 198 | | } |
| | 199 | |
|
| | 200 | | internal SslClientAuthenticationOptions createClientAuthenticationOptions( |
| | 201 | | RemoteCertificateValidationCallback remoteCertificateValidationCallback, |
| | 202 | | string host) |
| | 203 | | { |
| 1 | 204 | | var authenticationOptions = new SslClientAuthenticationOptions |
| 1 | 205 | | { |
| 1 | 206 | | ClientCertificates = _certs, |
| 1 | 207 | | LocalCertificateSelectionCallback = (sender, targetHost, certs, remoteCertificate, acceptableIssuers) => |
| 1 | 208 | | { |
| 1 | 209 | | if (certs == null || certs.Count == 0) |
| 1 | 210 | | { |
| 1 | 211 | | return null; |
| 1 | 212 | | } |
| 1 | 213 | | else if (certs.Count == 1) |
| 1 | 214 | | { |
| 1 | 215 | | return certs[0]; |
| 1 | 216 | | } |
| 1 | 217 | |
|
| 1 | 218 | | // Use the first certificate that match the acceptable issuers. |
| 0 | 219 | | if (acceptableIssuers != null && acceptableIssuers.Length > 0) |
| 1 | 220 | | { |
| 0 | 221 | | foreach (X509Certificate certificate in certs) |
| 1 | 222 | | { |
| 0 | 223 | | if (Array.IndexOf(acceptableIssuers, certificate.Issuer) != -1) |
| 1 | 224 | | { |
| 0 | 225 | | return certificate; |
| 1 | 226 | | } |
| 1 | 227 | | } |
| 1 | 228 | | } |
| 0 | 229 | | return certs[0]; |
| 0 | 230 | | }, |
| 1 | 231 | | RemoteCertificateValidationCallback = remoteCertificateValidationCallback, |
| 1 | 232 | | TargetHost = host, |
| 1 | 233 | | }; |
| | 234 | |
|
| 1 | 235 | | authenticationOptions.CertificateChainPolicy = new X509ChainPolicy(); |
| 1 | 236 | | if (_caCerts is null) |
| | 237 | | { |
| 1 | 238 | | authenticationOptions.CertificateChainPolicy.TrustMode = X509ChainTrustMode.System; |
| | 239 | | } |
| | 240 | | else |
| | 241 | | { |
| 1 | 242 | | authenticationOptions.CertificateChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; |
| 1 | 243 | | foreach (X509Certificate certificate in _caCerts) |
| | 244 | | { |
| 1 | 245 | | authenticationOptions.CertificateChainPolicy.CustomTrustStore.Add(certificate); |
| | 246 | | } |
| | 247 | | } |
| | 248 | |
|
| 1 | 249 | | if (!_checkCertName) |
| | 250 | | { |
| 1 | 251 | | authenticationOptions.CertificateChainPolicy.VerificationFlags |= X509VerificationFlags.IgnoreInvalidName; |
| | 252 | | } |
| | 253 | |
|
| 1 | 254 | | if (_checkCRL == 1) |
| | 255 | | { |
| 0 | 256 | | authenticationOptions.CertificateChainPolicy.VerificationFlags |= |
| 0 | 257 | | X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown; |
| | 258 | | } |
| 1 | 259 | | authenticationOptions.CertificateChainPolicy.RevocationMode = |
| 1 | 260 | | _checkCRL == 0 ? X509RevocationMode.NoCheck : X509RevocationMode.Online; |
| 1 | 261 | | return authenticationOptions; |
| | 262 | | } |
| | 263 | |
|
| | 264 | | internal SslServerAuthenticationOptions createServerAuthenticationOptions( |
| | 265 | | RemoteCertificateValidationCallback remoteCertificateValidationCallback) |
| | 266 | | { |
| | 267 | | // Get the certificate collection and select the first one. |
| 1 | 268 | | X509Certificate2 cert = null; |
| 1 | 269 | | if (_certs.Count > 0) |
| | 270 | | { |
| 1 | 271 | | cert = _certs[0]; |
| | 272 | | } |
| | 273 | |
|
| 1 | 274 | | var authenticationOptions = new SslServerAuthenticationOptions |
| 1 | 275 | | { |
| 1 | 276 | | ServerCertificate = cert, |
| 1 | 277 | | ClientCertificateRequired = _verifyPeer > 0, |
| 1 | 278 | | RemoteCertificateValidationCallback = remoteCertificateValidationCallback, |
| 1 | 279 | | CertificateRevocationCheckMode = X509RevocationMode.NoCheck |
| 1 | 280 | | }; |
| | 281 | |
|
| 1 | 282 | | authenticationOptions.CertificateChainPolicy = new X509ChainPolicy(); |
| 1 | 283 | | if (_caCerts is null) |
| | 284 | | { |
| 0 | 285 | | authenticationOptions.CertificateChainPolicy.TrustMode = X509ChainTrustMode.System; |
| | 286 | | } |
| | 287 | | else |
| | 288 | | { |
| 1 | 289 | | authenticationOptions.CertificateChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; |
| 1 | 290 | | foreach (X509Certificate certificate in _caCerts) |
| | 291 | | { |
| 1 | 292 | | authenticationOptions.CertificateChainPolicy.CustomTrustStore.Add(certificate); |
| | 293 | | } |
| | 294 | | } |
| 1 | 295 | | authenticationOptions.CertificateChainPolicy.RevocationMode = |
| 1 | 296 | | _checkCRL == 0 ? X509RevocationMode.NoCheck : X509RevocationMode.Online; |
| 1 | 297 | | if (_checkCRL == 1) |
| | 298 | | { |
| 0 | 299 | | authenticationOptions.CertificateChainPolicy.VerificationFlags |= |
| 0 | 300 | | X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown; |
| | 301 | | } |
| 1 | 302 | | return authenticationOptions; |
| | 303 | | } |
| | 304 | |
|
| | 305 | | private static bool isAbsolutePath(string path) |
| | 306 | | { |
| | 307 | | // Skip whitespace |
| 1 | 308 | | path = path.Trim(); |
| | 309 | |
|
| 1 | 310 | | if (AssemblyUtil.isWindows) |
| | 311 | | { |
| | 312 | | // We need at least 3 non-whitespace characters to have an absolute path |
| 0 | 313 | | if (path.Length < 3) |
| | 314 | | { |
| 0 | 315 | | return false; |
| | 316 | | } |
| | 317 | |
|
| | 318 | | // Check for X:\ path ('\' may have been converted to '/') |
| 0 | 319 | | if ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z')) |
| | 320 | | { |
| 0 | 321 | | return path[1] == ':' && (path[2] == '\\' || path[2] == '/'); |
| | 322 | | } |
| | 323 | | } |
| | 324 | | // Check for UNC path |
| 1 | 325 | | return (path[0] == '\\' && path[1] == '\\') || path[0] == '/'; |
| | 326 | | } |
| | 327 | |
|
| | 328 | | private static X509Certificate2Collection findCertificates( |
| | 329 | | string prop, |
| | 330 | | StoreLocation storeLocation, |
| | 331 | | string name, |
| | 332 | | string value) |
| | 333 | | { |
| | 334 | | // Open the X509 certificate store. |
| | 335 | | X509Store store; |
| | 336 | | try |
| | 337 | | { |
| | 338 | | try |
| | 339 | | { |
| 1 | 340 | | store = new X509Store((StoreName)Enum.Parse(typeof(StoreName), name, true), storeLocation); |
| 1 | 341 | | } |
| 0 | 342 | | catch (ArgumentException) |
| | 343 | | { |
| 0 | 344 | | store = new X509Store(name, storeLocation); |
| 0 | 345 | | } |
| 1 | 346 | | store.Open(OpenFlags.ReadOnly); |
| 1 | 347 | | } |
| 0 | 348 | | catch (Exception ex) |
| | 349 | | { |
| 0 | 350 | | throw new Ice.InitializationException($"IceSSL: failure while opening store specified by {prop}", ex); |
| | 351 | | } |
| | 352 | |
|
| | 353 | | // Start with all of the certificates in the collection and filter as necessary. |
| | 354 | | // |
| | 355 | | // - If the value is "*", return all certificates. |
| | 356 | | // - Otherwise, search using key:value pairs. The following keys are supported: |
| | 357 | | // |
| | 358 | | // Issuer |
| | 359 | | // IssuerDN |
| | 360 | | // Serial |
| | 361 | | // Subject |
| | 362 | | // SubjectDN |
| | 363 | | // SubjectKeyId |
| | 364 | | // Thumbprint |
| | 365 | | // |
| | 366 | | // A value must be enclosed in single or double quotes if it contains whitespace. |
| 1 | 367 | | X509Certificate2Collection result = [.. store.Certificates]; |
| | 368 | | try |
| | 369 | | { |
| 1 | 370 | | if (value != "*") |
| | 371 | | { |
| 1 | 372 | | if (!value.Contains(':', StringComparison.Ordinal)) |
| | 373 | | { |
| 1 | 374 | | throw new Ice.InitializationException($"IceSSL: no key in `{value}'"); |
| | 375 | | } |
| 1 | 376 | | int start = 0; |
| | 377 | | int pos; |
| 1 | 378 | | while ((pos = value.IndexOf(':', start)) != -1) |
| | 379 | | { |
| | 380 | | // Parse the X509FindType. |
| 1 | 381 | | string field = value[start..pos].Trim().ToUpperInvariant(); |
| | 382 | | X509FindType findType; |
| 1 | 383 | | if (field == "SUBJECT") |
| | 384 | | { |
| 1 | 385 | | findType = X509FindType.FindBySubjectName; |
| | 386 | | } |
| 1 | 387 | | else if (field == "SUBJECTDN") |
| | 388 | | { |
| 1 | 389 | | findType = X509FindType.FindBySubjectDistinguishedName; |
| | 390 | | } |
| 1 | 391 | | else if (field == "ISSUER") |
| | 392 | | { |
| 1 | 393 | | findType = X509FindType.FindByIssuerName; |
| | 394 | | } |
| 1 | 395 | | else if (field == "ISSUERDN") |
| | 396 | | { |
| 1 | 397 | | findType = X509FindType.FindByIssuerDistinguishedName; |
| | 398 | | } |
| 1 | 399 | | else if (field == "THUMBPRINT") |
| | 400 | | { |
| 1 | 401 | | findType = X509FindType.FindByThumbprint; |
| | 402 | | } |
| 1 | 403 | | else if (field == "SUBJECTKEYID") |
| | 404 | | { |
| 1 | 405 | | findType = X509FindType.FindBySubjectKeyIdentifier; |
| | 406 | | } |
| 1 | 407 | | else if (field == "SERIAL") |
| | 408 | | { |
| 1 | 409 | | findType = X509FindType.FindBySerialNumber; |
| | 410 | | } |
| | 411 | | else |
| | 412 | | { |
| 1 | 413 | | throw new Ice.InitializationException($"IceSSL: unknown key in `{value}'"); |
| | 414 | | } |
| | 415 | |
|
| | 416 | | // Parse the argument. |
| 1 | 417 | | start = pos + 1; |
| 1 | 418 | | while (start < value.Length && (value[start] == ' ' || value[start] == '\t')) |
| | 419 | | { |
| 0 | 420 | | ++start; |
| | 421 | | } |
| | 422 | |
|
| 1 | 423 | | if (start == value.Length) |
| | 424 | | { |
| 0 | 425 | | throw new Ice.InitializationException($"IceSSL: missing argument in `{value}'"); |
| | 426 | | } |
| | 427 | |
|
| | 428 | | string arg; |
| 1 | 429 | | if (value[start] == '"' || value[start] == '\'') |
| | 430 | | { |
| 1 | 431 | | int end = start; |
| 1 | 432 | | ++end; |
| 1 | 433 | | while (end < value.Length) |
| | 434 | | { |
| 1 | 435 | | if (value[end] == value[start] && value[end - 1] != '\\') |
| | 436 | | { |
| | 437 | | break; |
| | 438 | | } |
| 1 | 439 | | ++end; |
| | 440 | | } |
| 1 | 441 | | if (end == value.Length || value[end] != value[start]) |
| | 442 | | { |
| 0 | 443 | | throw new Ice.InitializationException($"IceSSL: unmatched quote in `{value}'"); |
| | 444 | | } |
| 1 | 445 | | ++start; |
| 1 | 446 | | arg = value[start..end]; |
| 1 | 447 | | start = end + 1; |
| | 448 | | } |
| | 449 | | else |
| | 450 | | { |
| 1 | 451 | | char[] ws = [' ', '\t']; |
| 1 | 452 | | int end = value.IndexOfAny(ws, start); |
| 1 | 453 | | if (end == -1) |
| | 454 | | { |
| 1 | 455 | | arg = value[start..]; |
| 1 | 456 | | start = value.Length; |
| | 457 | | } |
| | 458 | | else |
| | 459 | | { |
| 1 | 460 | | arg = value[start..end]; |
| 1 | 461 | | start = end + 1; |
| | 462 | | } |
| | 463 | | } |
| | 464 | |
|
| | 465 | | // Execute the query. |
| | 466 | | // |
| | 467 | | // TODO: allow user to specify a value for validOnly? |
| 1 | 468 | | bool validOnly = false; |
| 1 | 469 | | if (findType == X509FindType.FindBySubjectDistinguishedName || |
| 1 | 470 | | findType == X509FindType.FindByIssuerDistinguishedName) |
| | 471 | | { |
| 1 | 472 | | X500DistinguishedNameFlags[] flags = [ |
| 1 | 473 | | X500DistinguishedNameFlags.None, |
| 1 | 474 | | X500DistinguishedNameFlags.Reversed, |
| 1 | 475 | | ]; |
| 1 | 476 | | var dn = new X500DistinguishedName(arg); |
| 1 | 477 | | X509Certificate2Collection r = result; |
| 1 | 478 | | for (int i = 0; i < flags.Length; ++i) |
| | 479 | | { |
| 1 | 480 | | r = result.Find(findType, dn.Decode(flags[i]), validOnly); |
| 1 | 481 | | if (r.Count > 0) |
| | 482 | | { |
| | 483 | | break; |
| | 484 | | } |
| | 485 | | } |
| 1 | 486 | | result = r; |
| | 487 | | } |
| | 488 | | else |
| | 489 | | { |
| 1 | 490 | | result = result.Find(findType, arg, validOnly); |
| | 491 | | } |
| | 492 | | } |
| | 493 | | } |
| 1 | 494 | | } |
| | 495 | | finally |
| | 496 | | { |
| 1 | 497 | | store.Close(); |
| 1 | 498 | | } |
| | 499 | |
|
| 1 | 500 | | return result; |
| | 501 | | } |
| | 502 | |
|
| | 503 | | private static SecureString createSecureString(string s) |
| | 504 | | { |
| 1 | 505 | | var result = new SecureString(); |
| 1 | 506 | | foreach (char ch in s) |
| | 507 | | { |
| 1 | 508 | | result.AppendChar(ch); |
| | 509 | | } |
| 1 | 510 | | return result; |
| | 511 | | } |
| | 512 | |
|
| | 513 | | private bool checkPath(ref string path) |
| | 514 | | { |
| 1 | 515 | | if (File.Exists(path)) |
| | 516 | | { |
| 0 | 517 | | return true; |
| | 518 | | } |
| | 519 | |
|
| 1 | 520 | | if (_defaultDir.Length > 0 && !isAbsolutePath(path)) |
| | 521 | | { |
| 1 | 522 | | string s = _defaultDir + Path.DirectorySeparatorChar + path; |
| 1 | 523 | | if (File.Exists(s)) |
| | 524 | | { |
| 1 | 525 | | path = s; |
| 1 | 526 | | return true; |
| | 527 | | } |
| | 528 | | } |
| 0 | 529 | | return false; |
| | 530 | | } |
| | 531 | |
|
| | 532 | | private readonly Ice.Communicator _communicator; |
| | 533 | | private readonly Ice.Logger _logger; |
| | 534 | | private readonly int _securityTraceLevel; |
| | 535 | | private readonly string _securityTraceCategory; |
| | 536 | | private string _defaultDir; |
| | 537 | | private bool _checkCertName; |
| | 538 | | private int _verifyPeer; |
| | 539 | | private int _checkCRL; |
| | 540 | | private X509Certificate2Collection _certs; |
| | 541 | | private bool _useMachineContext; |
| | 542 | | private X509Certificate2Collection _caCerts; |
| | 543 | | private readonly TrustManager _trustManager; |
| | 544 | | } |