Esempio n. 1
0
    /*
     * 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));
            }
        }
    }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
//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());
            }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
    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);
        }
    }
Esempio n. 6
0
        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());
            }
        }
Esempio n. 7
0
        private ChannelHandler NettyServerHandler(Channel channel, SslContext sslContext)
        {
            SSLEngine sslEngine = sslContext.newEngine(channel.alloc());

            return(new SslHandler(sslEngine));
        }
Esempio n. 8
0
 public abstract string chooseEngineServerAlias(string keyType, Principal[] issuers, SSLEngine engine);
Esempio n. 9
0
        // Z:\jsc.svn\examples\java\hybrid\Test\JVMCLRSSLServerSocket\JVMCLRSSLServerSocket\Program.cs

        public abstract string chooseEngineClientAlias(string[] keyType, Principal[] issuers, SSLEngine engine);
Esempio n. 10
0
 void SendCommand(SSLEngine eng, char cmd)
 {
     eng.WriteByte((byte)cmd);
     eng.WriteByte(0x0A);
     eng.Flush();
 }
 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);