public EventStoreClientAPIClusterFixture() { var serverCertificate = GetServerCertificate(); var rootCertificates = new X509Certificate2Collection(GetRootCertificate()); for (var i = 0; i < ClusterSize; i++) { var vNodeBuilder = ClusterVNodeBuilder .AsClusterMember(ClusterSize) .DisableDnsDiscovery() .WithGossipSeeds(GetGossipSeedEndPointsExceptFor(i, false)) .WithHttpOn(new IPEndPoint(IPAddress.Loopback, HttpPort[i])) .WithInternalTcpOn(new IPEndPoint(IPAddress.Loopback, InternalTcpPort[i])) .WithInternalSecureTcpOn(new IPEndPoint(IPAddress.Loopback, InternalSecureTcpPort[i])) .WithExternalTcpOn(new IPEndPoint(IPAddress.Loopback, ExternalTcpPort[i])) .WithExternalSecureTcpOn(new IPEndPoint(IPAddress.Loopback, ExternalSecureTcpPort[i])) .WithServerCertificate(serverCertificate) .WithTrustedRootCertificates(rootCertificates) .WithCertificateReservedNodeCommonName(Opts.CertificateReservedNodeCommonNameDefault) .RunInMemory() .EnableExternalTCP(); _nodes[i] = vNodeBuilder.Build(); var httpEndPoint = new IPEndPoint(IPAddress.Loopback, HttpPort[i]); _hosts[i] = new WebHostBuilder() .UseKestrel(o => { o.Listen(httpEndPoint, options => { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { options.Protocols = HttpProtocols.Http2; } else { options.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = serverCertificate, ClientCertificateMode = ClientCertificateMode.AllowCertificate, ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => { var(isValid, error) = ClusterVNode.ValidateClientCertificateWithTrustedRootCerts(certificate, chain, sslPolicyErrors, rootCertificates); if (!isValid && error != null) { Log.Error("Client certificate validation error: {e}", error); } return(isValid); } }); } }); }) .ConfigureServices(services => services.AddSingleton(_nodes[i].Startup)) .Build(); } }
public EventStoreClientAPIFixture() { using var stream = typeof(EventStoreClientAPIFixture) .Assembly .GetManifestResourceStream(typeof(EventStoreClientAPIFixture), "server.p12"); using var mem = new MemoryStream(); stream.CopyTo(mem); var vNodeBuilder = ClusterVNodeBuilder .AsSingleNode() .WithExternalTcpOn(new IPEndPoint(IPAddress.Loopback, ExternalPort)) .WithExternalSecureTcpOn(new IPEndPoint(IPAddress.Loopback, ExternalSecurePort)) .WithServerCertificate(new X509Certificate2(mem.ToArray(), "1111")) .RunInMemory(); _node = vNodeBuilder.Build(); Connections = new Dictionary <bool, IEventStoreConnection> { [false] = CreateConnection(settings => settings.UseSsl(false), ExternalPort), [true] = CreateConnection(settings => settings.UseSsl(true), ExternalSecurePort) }; }