/* * Send a "normal" message to the peer, of the specified * length: this is a sequence of 'len' random bytes, distinct * from 0x0A, followed one 0x0A byte. The peer is supposed to * respond with the SHA-1 hash of the message bytes (excluding * the final 0x0A), encoded in hexadecimal (lowercase) and * followed by a newline (0x0A). An exception is thrown if the * expected value is not obtained. */ void SendMessageNormal(SSLEngine eng, int len) { SHA1 sha1 = new SHA1(); byte[] buf = new byte[len + 1]; RNG.GetBytesNonZero(buf, 0, len); for (int i = 0; i < len; i++) { buf[i] ^= 0x0A; } buf[len] = 0x0A; if (len == 1) { buf[0] = (byte)('a' + (buf[0] & 0x0F)); } StringBuilder sb = new StringBuilder(); foreach (byte b in sha1.Hash(buf, 0, len)) { sb.AppendFormat("{0:x2}", b); } sb.Append('\n'); eng.Write(buf, 0, buf.Length); eng.Flush(); for (int i = 0; i < sb.Length; i++) { int x = eng.ReadByte(); int y = sb[i]; if (x != y) { throw new Exception(string.Format( "received {0} (exp: {1})", y, x)); } } }
private SslHandler CreateSslHandler(ChannelHandlerContext ctx, InetSocketAddress inetSocketAddress) { SSLEngine sslEngine = _sslContext.newEngine(ctx.alloc(), inetSocketAddress.HostName, inetSocketAddress.Port); foreach (System.Func <SSLEngine, SSLEngine> mod in _engineModifications) { sslEngine = mod(sslEngine); } // Don't need to set tls versions since that is set up from the context return(new SslHandler(sslEngine)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception protected internal override void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); SSLEngine sslEngine = _outerInstance.sslContext.newEngine(ch.alloc()); sslEngine.NeedClientAuth = true; SslHandler sslHandler = new SslHandler(sslEngine); pipeline.addLast(sslHandler); pipeline.addLast(new Responder()); }
/// <summary>Returns a configured SSLEngine.</summary> /// <returns>the configured SSLEngine.</returns> /// <exception cref="GeneralSecurityException"> /// thrown if the SSL engine could not /// be initialized. /// </exception> /// <exception cref="System.IO.IOException"> /// thrown if and IO error occurred while loading /// the server keystore. /// </exception> public virtual SSLEngine CreateSSLEngine() { SSLEngine sslEngine = context.CreateSSLEngine(); if (mode == SSLFactory.Mode.Client) { sslEngine.SetUseClientMode(true); } else { sslEngine.SetUseClientMode(false); sslEngine.SetNeedClientAuth(requireClientCert); } sslEngine.SetEnabledProtocols(enabledProtocols); return(sslEngine); }
string ReadLine(SSLEngine eng) { StringBuilder sb = new StringBuilder(); for (;;) { int c = eng.ReadByte(); if (c < 0) { throw new Exception("Unexpected EOF"); } if (c == 0x0A) { return(sb.ToString()); } sb.Append((char)c); } }
protected override void OnCreate(Bundle bundle) { try { base.OnCreate(bundle); InputDialog.DisplayDialog += OnDisplayDialog; AndroidEnvironment.UnhandledExceptionRaiser += HandleUnhandledException; global::Xamarin.Forms.Forms.Init(this, bundle); context = ApplicationContext; // or activity.getApplicationContext() PackageManager packageManager = context.PackageManager; string packageName = context.PackageName; AppData.Version = new OnSiteVersion(string.Format("{0}", packageManager.GetPackageInfo(packageName, 0).VersionName)); LoadApplication(new App()); //AppContext.AppContext.ShowInput = () => //{ // InputMethodManager showinput = (InputMethodManager)GetSystemService(InputMethodService); // showinput.ToggleSoftInput(ShowFlags.Forced, 0); //}; if (Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat) { ProviderInstaller.InstallIfNeeded(ApplicationContext); } SSLContext sslContext = SSLContext.GetInstance("TLSv1.2"); sslContext.Init(null, null, null); SSLEngine engine = sslContext.CreateSSLEngine(); } catch (Exception ex) { LogTracking.LogTrace(ex.ToString()); } }
private ChannelHandler NettyServerHandler(Channel channel, SslContext sslContext) { SSLEngine sslEngine = sslContext.newEngine(channel.alloc()); return(new SslHandler(sslEngine)); }
public abstract string chooseEngineServerAlias(string keyType, Principal[] issuers, SSLEngine engine);
// Z:\jsc.svn\examples\java\hybrid\Test\JVMCLRSSLServerSocket\JVMCLRSSLServerSocket\Program.cs public abstract string chooseEngineClientAlias(string[] keyType, Principal[] issuers, SSLEngine engine);
void SendCommand(SSLEngine eng, char cmd) { eng.WriteByte((byte)cmd); eng.WriteByte(0x0A); eng.Flush(); }