public static async Task <SslSock> SslStartClientAsync(this ConnSock baseSock, PalSslClientAuthenticationOptions sslOptions, CancellationToken cancel = default) { SslSock ret = new SslSock(baseSock); await ret.StartSslClientAsync(sslOptions, cancel); return(ret); }
static async Task Test_Pipe_SslStream_Client(CancellationToken cancel) { string hostname = "news.goo.ne.jp"; int port = 443; AsyncCleanuperLady lady = new AsyncCleanuperLady(); try { var tcp = new FastPalTcpProtocolStub(lady, cancel: cancel); var sock = await tcp.ConnectAsync(hostname, port); FastSslProtocolStack ssl = new FastSslProtocolStack(lady, sock.UpperEnd, null, null, cancel); var sslClientOptions = new PalSslClientAuthenticationOptions() { TargetHost = hostname, ValidateRemoteCertificateProc = (cert) => { return(true); }, }; var ssl_sock = await ssl.SslStartClient(sslClientOptions, cancel); var app = ssl_sock.GetFastAppProtocolStub(cancel); app.AttachHandle.SetStreamReceiveTimeout(1000); var st = app.GetStream().GetPalNetworkStream(); var tcp_info = ssl_sock.Info.GetValue <ILayerInfoTcpEndPoint>(); var ssl_info = ssl_sock.Info.GetValue <ILayerInfoSsl>(); WriteLine($"Connected. {tcp_info.LocalIPAddress}:{tcp_info.LocalPort} -> {tcp_info.RemoteIPAddress}:{tcp_info.RemotePort}"); StreamWriter w = new StreamWriter(st); w.AutoFlush = true; await w.WriteAsync( "GET / HTTP/1.0\r\n" + $"HOST: {hostname}\r\n\r\n" ); StreamReader r = new StreamReader(st); while (true) { string s = await r.ReadLineAsync(); if (s == null) { break; } WriteLine(s); } } finally { await lady; } }
public LogClientOptions(TcpIpSystem?tcpIp, PalSslClientAuthenticationOptions sslAuthOptions, string serverHostname, int serverPort = Consts.Ports.LogServerDefaultServicePort) { this.ServerHostname = serverHostname._NonNullTrim(); this.ServerPort = serverPort; this.TcpIp = tcpIp ?? LocalNet; this.SslAuthOptions = sslAuthOptions; if (this.SslAuthOptions.TargetHost._IsEmpty()) { this.SslAuthOptions.TargetHost = this.ServerHostname; } }
public DataVaultClientOptions(string serverHostname, string accessKey, PalSslClientAuthenticationOptions sslAuthOptions, int serverPort = Consts.Ports.DataVaultServerDefaultServicePort, TcpIpSystem?tcpIp = null) { this.ServerHostname = serverHostname._NonNullTrim(); this.ServerPort = serverPort; this.TcpIp = tcpIp ?? LocalNet; this.SslAuthOptions = sslAuthOptions; this.AccessKey = accessKey; if (this.SslAuthOptions.TargetHost._IsEmpty()) { this.SslAuthOptions.TargetHost = this.ServerHostname; } }
public WebSocketConnectOptions(WebSocketOptions?wsOptions = null, PalSslClientAuthenticationOptions?sslOptions = null, TcpIpSystem?tcpIp = null) { this.TcpIp = tcpIp ?? LocalNet; this.WebSocketOptions = wsOptions ?? new WebSocketOptions(); if (sslOptions == null) { this.SslOptions = new PalSslClientAuthenticationOptions(true); } else { this.SslOptions = (PalSslClientAuthenticationOptions)sslOptions.Clone(); } }
static void Net_Test6_DualStack_Client() { string hostname = "www.google.com"; using (var tcp = LocalNet.ConnectIPv4v6Dual(new TcpConnectParam(hostname, 443, connectTimeout: 5 * 1000))) { tcp.Info.GetValue <ILayerInfoIpEndPoint>().RemoteIPAddress !.AddressFamily.ToString()._Print(); using (SslSock ssl = new SslSock(tcp)) { var sslClientOptions = new PalSslClientAuthenticationOptions() { TargetHost = hostname, ValidateRemoteCertificateProc = (cert) => { return(true); }, }; ssl.StartSslClient(sslClientOptions); var st = ssl.GetStream(); var w = new StreamWriter(st); var r = new StreamReader(st); w.WriteLine("GET / HTTP/1.0"); w.WriteLine($"HOST: {hostname}"); w.WriteLine(); w.WriteLine(); w.Flush(); while (true) { string?s = r.ReadLine(); if (s == null) { break; } Con.WriteLine(s); } } } }
static void Net_Test2_Ssl_Client() { string hostname = "www.google.co.jp"; using (ConnSock sock = LocalNet.Connect(new TcpConnectParam(hostname, 443))) { using (SslSock ssl = new SslSock(sock)) { //ssl.StartPCapRecorder(new PCapFileEmitter(new PCapFileEmitterOptions(new FilePath(@"c:\tmp\190610\test1.pcapng", flags: FileFlags.AutoCreateDirectory), false))); var sslClientOptions = new PalSslClientAuthenticationOptions() { TargetHost = hostname, ValidateRemoteCertificateProc = (cert) => { return(true); }, }; ssl.StartSslClient(sslClientOptions); var st = ssl.GetStream(); var w = new StreamWriter(st); var r = new StreamReader(st); w.WriteLine("GET / HTTP/1.0"); w.WriteLine($"HOST: {hostname}"); w.WriteLine(); w.WriteLine(); w.Flush(); while (true) { string?s = r.ReadLine(); if (s == null) { break; } Con.WriteLine(s); } } } }
public static SslSock SslStartClient(this ConnSock baseSock, PalSslClientAuthenticationOptions sslOptions, CancellationToken cancel = default) => SslStartClientAsync(baseSock, sslOptions, cancel)._GetResult();
public void StartSslClient(PalSslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken = default) => StartSslClientAsync(sslClientAuthenticationOptions, cancellationToken)._GetResult();
public async Task StartSslClientAsync(PalSslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken = default) { await Stack.SslStartClientAsync(sslClientAuthenticationOptions, cancellationToken); }
public async Task <WtcSocket> WideClientConnectAsync(string pcid, WideTunnelClientOptions clientOptions, bool noCache, CancellationToken cancel = default) { bool retryFlag = false; L_RETRY: WtConnectParam connectParam = await WideClientConnectInnerAsync(pcid, clientOptions, noCache, cancel); $"WideClientConnect: pcid {pcid}: Redirecting to {connectParam.HostName}:{connectParam.Port} (CacheUsed = {connectParam.CacheUsed}) ..."._Debug(); try { ConnSock tcpSock = await this.TcpIp.ConnectAsync(new TcpConnectParam(connectParam.HostName, connectParam.Port, AddressFamily.InterNetwork, connectTimeout : CoresConfig.WtcConfig.WpcTimeoutMsec, dnsTimeout : CoresConfig.WtcConfig.WpcTimeoutMsec), cancel); try { ConnSock targetSock = tcpSock; try { PalSslClientAuthenticationOptions sslOptions = new PalSslClientAuthenticationOptions(connectParam.HostName, false, (cert) => this.CheckValidationCallback(this, cert.NativeCertificate, null, SslPolicyErrors.None)); SslSock sslSock = new SslSock(tcpSock); try { await sslSock.StartSslClientAsync(sslOptions, cancel); targetSock = sslSock; } catch { await sslSock._DisposeSafeAsync(); throw; } WtcSocket wtcSocket = new WtcSocket(targetSock, new WtcOptions(this, connectParam)); await wtcSocket.StartWtcAsync(cancel); return(wtcSocket); } catch { await targetSock._DisposeSafeAsync(); throw; } } catch { await tcpSock._DisposeSafeAsync(); throw; } } catch { if (connectParam.CacheUsed && retryFlag == false) { retryFlag = true; // 接続キャッシュを使用して接続することに失敗した // 場合はキャッシュを消去して再試行する WideTunnel.ConnectParamCache.Delete(pcid); $"WideClientConnect: pcid {pcid}: Connect with Session Cache Failed. Retrying..."._Debug(); goto L_RETRY; } throw; } }