Exemple #1
0
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            // We don't care about culuture of store at this time.
            // We simply need some non-localizable store settings to initialize thread culture.
            var currentStore = HccRequestContext.Current.CurrentStore;

            if (ForceWizardRedirect && currentStore == null && CurrentTab != AdminTabType.SetupWizard)
            {
                Response.Redirect(WizardPagePath);
            }

            HccRequestContextUtils.UpdateAdminContentCulture(HccRequestContext.Current);

            // Redirect to HTTPS if ssl required
            if (currentStore != null)
            {
                if (currentStore.Settings.ForceAdminSSL && !Request.IsSecureConnection)
                {
                    SSL.SSLRedirect(SSL.SSLRedirectTo.SSL);
                }

                CultureSwitch.SetCulture(currentStore);
            }

            ValidateBasicAccess();

            Localization = Factory.Instance.CreateLocalizationHelper(LocalResourceFile);
        }
 void Update()
 {
     //save when "S" is pressed
     if (Input.GetKeyDown(KeyCode.S))
     {
         Save();
     }
     //load when "L" is pressed
     if (Input.GetKeyDown(KeyCode.L))
     {
         Load();
     }
     //delete
     if (Input.GetKeyDown(KeyCode.D))
     {
         Delete();
     }
     //check if it exists
     if (Input.GetKeyDown(KeyCode.E))
     {
         Exists();
     }
     //clear a directory
     if (Input.GetKeyDown(KeyCode.C))
     {
         ClearDirectory();
     }
     if (Input.GetKeyDown(KeyCode.G))
     {
         directoryFiles = SSL.GetFilesInDirectory(fileName);
     }
 }
Exemple #3
0
    /**
     * Display what cipher we are using
     */
    private void display_cipher(SSL ssl)
    {
        Console.Write("CIPHER is ");

        switch (ssl.GetCipherId())
        {
        case axtls.SSL_AES128_SHA:
            Console.WriteLine("AES128-SHA");
            break;

        case axtls.SSL_AES256_SHA:
            Console.WriteLine("AES256-SHA");
            break;

        case axtls.SSL_RC4_128_SHA:
            Console.WriteLine("RC4-SHA");
            break;

        case axtls.SSL_RC4_128_MD5:
            Console.WriteLine("RC4-MD5");
            break;

        default:
            Console.WriteLine("Unknown - " + ssl.GetCipherId());
            break;
        }
    }
    public void Load()
    {
        Texture2D loadedTex = SSL.LoadPNG(fileName, obfuscate);                                                                            //load using settings

        loadThisSprite.sprite      = Sprite.Create(loadedTex, new Rect(0, 0, loadedTex.width, loadedTex.height), new Vector2(0.5f, 0.5f)); //create a sprite from loaded texture
        loadThisSprite.sprite.name = loadedTex.name;                                                                                       //assign name to sprite object
        loadText.text = loadedTex.name;                                                                                                    //show name on screen
    }
Exemple #5
0
 internal static int[] GetCurvesByName(string[] ss)
 {
     int[] r = new int[ss.Length];
     for (int i = 0; i < ss.Length; i++)
     {
         r[i] = SSL.GetCurveByName(ss[i]);
     }
     return(r);
 }
Exemple #6
0
 /// <summary>
 /// Saves the email settings to file
 /// </summary>
 public void Save()
 {
     XML.SetXMLValue("Email", "Sender", StringCipher.Encrypt(Sender, StringCipher.DefaultPassword));
     XML.SetXMLValue("Email", "Host", StringCipher.Encrypt(Host, StringCipher.DefaultPassword));
     XML.SetXMLValue("Email", "Port", StringCipher.Encrypt(Port.ToString(), StringCipher.DefaultPassword));
     XML.SetXMLValue("Email", "User", StringCipher.Encrypt(User, StringCipher.DefaultPassword));
     XML.SetXMLValue("Email", "Password", StringCipher.Encrypt(Password, StringCipher.DefaultPassword));
     XML.SetXMLValue("Email", "SSL", StringCipher.Encrypt(SSL.ToString(), StringCipher.DefaultPassword));
 }
Exemple #7
0
        public unsafe static int SSL_read(SSL ssl, Span <byte> input)
        {
            fixed(void *ptr = &input.DangerousGetPinnableReference())
            {
                var result = SSL_read(ssl, ptr, input.Length);

                return(result);
            }
        }
Exemple #8
0
        public unsafe static int SSL_write(SSL ssl, Span <byte> output)
        {
            fixed(byte *ptr = &output.DangerousGetPinnableReference())
            {
                var result = SSL_write(ssl, ptr, output.Length);

                return(result);
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!Request.IsSecureConnection)
            {
                SSL.SSLRedirect(this.MTApp, this.MTApp.CurrentStore, SSL.SSLRedirectTo.SSL);
            }
        }
        private void BuildURI()
        {
            Uri uri;

            // TODO we should not assume anything here... what if they want to put http:// | https:// ???
            //    should add some detection logic for that
            uri = new Uri(String.Format("{0}://{1}:{2}/api/client/command.php", (SSL.IsTrue()) ? "https" : "http", URI, Port));

            Request = new Requests(uri, API_KEY, API_HASH);
        }
Exemple #11
0
 int[] GetVersions()
 {
     string[] r  = JSON.GetStringArray(conf, "versions");
     int[]    vv = new int[r.Length];
     for (int i = 0; i < r.Length; i++)
     {
         vv[i] = SSL.GetVersionByName(r[i]);
     }
     return(vv);
 }
Exemple #12
0
        public IActionResult NewSsl(int DomainId)
        {
            try
            {
                return(Json(SSL.GenerateSSL("C:\\MYcert", "ya.ru")));
            }

            catch (Exception e)
            {
                return(Json(e.Message));
            }
        }
Exemple #13
0
        // check out document
        public static MSOpenKMCore.bean.OKMDocument checkoutDocument(document doc, String type, String host, String username, String password)
        {
            String  token       = "";
            OKMAuth authService = null;

            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // Create a new document
                MSOpenKMCore.bean.OKMDocument oKMDocument = Util.copy(doc, type);

                // Creates new document
                FileStream fileStream = new FileStream(oKMDocument.getLocalFilename(), FileMode.CreateNew);

                // Checking out document
                documentService.checkout(token, doc.path);
                byte[] byteDoc = documentService.getContent(token, doc.path, false);

                // Write the data to the file, byte by byte.
                for (int i = 0; i < byteDoc.Length; i++)
                {
                    fileStream.WriteByte(byteDoc[i]);
                }

                fileStream.Close();

                // Logout OpenKM
                authService.logout(token);
                token = "";

                return(oKMDocument);
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (checkoutDocument)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
Exemple #14
0
    int RunEnum(bool cmdClient, bool doit)
    {
        int count = 0;

        foreach (int version in versions)
        {
            foreach (int suite in cipherSuites)
            {
                if (version < SSL.TLS12 && SSL.IsTLS12(suite))
                {
                    continue;
                }
                if (!SSL.IsECDHE(suite))
                {
                    if (doit)
                    {
                        RunEnum(cmdClient,
                                version, suite, -1, -1);
                    }
                    count++;
                    continue;
                }
                bool needRSA = (version >= SSL.TLS12) &&
                               SSL.IsECDHE_RSA(suite);
                bool needECDSA = (version >= SSL.TLS12) &&
                                 SSL.IsECDHE_ECDSA(suite);
                foreach (int hs in hashAndSigns)
                {
                    int sa = hs & 0xFF;
                    if (needRSA && sa != SSL.RSA)
                    {
                        continue;
                    }
                    if (needECDSA && sa != SSL.ECDSA)
                    {
                        continue;
                    }
                    foreach (int curve in curves)
                    {
                        if (doit)
                        {
                            RunEnum(cmdClient,
                                    version,
                                    suite,
                                    curve, hs);
                        }
                        count++;
                    }
                }
            }
        }
        return(count);
    }
Exemple #15
0
 /// <summary>
 /// utk create connection string
 /// </summary>
 /// <param name="strProvider">Provider, defauld SQLOLEDB.1</param>
 /// <param name="strServer">Server</param>
 /// <param name="strDatabase">initial Database</param>
 /// <param name="strUser">User name</param>
 /// <param name="strPass">Password</param>
 /// <param name="isSSL">penggunaan SSL / tidak (saat ini belum digunakan)</param>
 /// <returns></returns>
 public static string SetupConnection(string strProvider, string strServer, string strDatabase,
                                      string strUser, string strPass, SSL isSSL) // harus tambah SSL
 {
     if (strUser != "" && strPass != "")
     {
         return("Server = " + strServer + ";Initial Catalog=" + strDatabase + ";" + "Persist Security Info=False" +
                ";User ID=" + strUser + ";Password="******";MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
     }
     else
     {
         return("Provider = " + strProvider + ";Server=" + strServer + ";Database=" + strDatabase + ";Trusted_Connection=Yes;");
     }
 }
Exemple #16
0
 // Init services
 private void initServices()
 {
     try
     {
         SSL.init(configXML.getHost());
         authService       = new OKMAuth(configXML.getHost());
         repositoryService = new OKMRepository(configXML.getHost());
         folderService     = new OKMFolder(configXML.getHost());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #17
0
        internal override bool DoHandshake()
        {
            CheckConfigHashAndSign();

            ResetHashes();
            MakeRandom(serverRandom);

            bool resume;

            if (!ParseClientHello(out resume))
            {
                return(false);
            }
            HandshakeCount++;
            SetOutputRecordVersion(Version);
            SetInputRecordVersion(Version);

            if (resume)
            {
                SendServerHello();
                SendCCSAndFinished();
                FlushSub();
                ParseCCSAndFinished();
                SetAppData();
                IsResume = true;
                return(true);
            }

            SendServerHello();
            SendCertificate();
            if (SSL.IsECDHE(CipherSuite))
            {
                SendServerKeyExchange();
            }
            SendServerHelloDone();
            FlushSub();

            ParseClientKeyExchange();
            ParseCCSAndFinished();
            SendCCSAndFinished();
            FlushSub();
            SetAppData();
            IsResume = false;
            if (SessionCache != null)
            {
                SessionCache.Store(SessionParameters);
            }
            return(true);
        }
Exemple #18
0
        /// <summary>
        /// Main function
        /// </summary>
        static void Main()
        {
            try
            {
#if HAS_SSL
                SSL _ssl = new SSL("coinche_srv.pfx");
#endif

                // Register packets handler
                NetworkComms.AppendGlobalConnectionEstablishHandler(AddClient);
                NetworkComms.AppendGlobalConnectionCloseHandler(RemoveClient);

#if HAS_SSL
                List <IPEndPoint> desiredlocalEndPoints = (from current in HostInfo.IP.FilteredLocalAddresses()
                                                           select new IPEndPoint(current, 0)).ToList();

                // Create a list of matching TCP listeners where we provide the listenerSSLOptions
                List <ConnectionListenerBase> listeners = (from current in desiredlocalEndPoints
                                                           select(ConnectionListenerBase)(new TCPConnectionListener(NetworkComms.DefaultSendReceiveOptions,
                                                                                                                    ApplicationLayerProtocolStatus.Enabled,
                                                                                                                    _ssl.ListenerOptions))).ToList();

                // Start listening for connections
                Connection.StartListening(listeners, desiredlocalEndPoints, true);
#else
                Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0));
#endif

                // Print out the IPs and ports we are now listening on
                Console.WriteLine("Server listening for TCP connection on:");
                foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP))
                {
                    Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }
            finally
            {
                // Let the user close the server
                Console.WriteLine("\nPress any key to close server.");
                Console.ReadKey(true);

                // We have used NetworkComms so we should ensure that we correctly call shutdown
                NetworkComms.Shutdown();
            }
        }
Exemple #19
0
 public byte[] GetCertificateHash()
 {
     if (IsHTTPS)
     {
         string ssl = SSL.Replace(" ", string.Empty);
         return(Enumerable.Range(0, ssl.Length)
                .Where(t => t % 2 == 0)
                .Select(t => Convert.ToByte(ssl.Substring(t, 2), 16))
                .ToArray());
     }
     else
     {
         return(new byte[] { });
     }
 }
Exemple #20
0
    /**
     * Display what session id we have.
     */
    private void display_session_id(SSL ssl)
    {
        byte[] session_id = ssl.GetSessionId();

        if (session_id.Length > 0)
        {
            Console.WriteLine("-----BEGIN SSL SESSION PARAMETERS-----");
            foreach (byte b in session_id)
            {
                Console.Write("{0:x02}", b);
            }

            Console.WriteLine("\n-----END SSL SESSION PARAMETERS-----");
        }
    }
        internal TlsClientPipeline(IPipeConnection inputPipe, SSL_CTX context, ClientOptions clientOptions)
        {
            _innerConnection = inputPipe;
            _readInnerPipe   = new Pipe(new PipeOptions(System.Buffers.MemoryPool.Default));
            _writeInnerPipe  = new Pipe(new PipeOptions(System.Buffers.MemoryPool.Default));
            _context         = context;
            _ssl             = SSL_new(_context);

            _clientOptions = clientOptions;

            _readBio  = s_ReadBio.New();
            _writeBio = s_WriteBio.New();
            SSL_set0_rbio(_ssl, _readBio);
            SSL_set0_wbio(_ssl, _writeBio);
            SSL_set_connect_state(_ssl);
        }
    public void Save()
    {
        Prepare();
        if (fileType == FileType.JSON)
        {
            SSL.SaveJSON(myObject, FileName, obfuscate);
        }
        else
        {
            SSL.SaveXML(myObject, FileName, obfuscate);
        }

        spr.color = Color.green;         //physically show it was saved
        output    = SSL.LoadTXT(FileName);
        UpdateUI();
    }
Exemple #23
0
        static void Main(string[] args)
        {
            try
            {
#if HAS_SSL
                SSL _ssl = new SSL("coinche_cli.pfx");
#endif

                // Request server IP and port number
                Console.WriteLine("Please enter the server IP and port in the format 192.168.0.1:10000 and press return:");
                string serverInfo = Console.ReadLine();

                // Parse the necessary information out of the provided string
                string serverIP   = serverInfo.Split(':').First();
                int    serverPort = int.Parse(serverInfo.Split(':').Last());

                ConnectionInfo connInfo = new ConnectionInfo(serverIP, serverPort);
#if HAS_SSL
                Connection co = TCPConnection.GetConnection(connInfo, _ssl.SendingSendReceiveOptions, _ssl.ConnectionOptions);
#else
                Connection co = TCPConnection.GetConnection(connInfo);
#endif
                co.AppendIncomingPacketHandler <string>("WelcomeResponse", WelcomeResponseHandler);

                // Send the message in a single line
                Console.WriteLine("Please enter your pseudonyme:");
                string pseudo = Console.ReadLine();
                co.SendObject("WelcomeRequest", pseudo);


                while (co.ConnectionAlive())
                {
                    Thread.Sleep(500);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("An error occured.");
                Console.WriteLine("Please double check that the server is up and running and try again.");
            }

            finally
            {
                // We have used comms so we make sure to call shutdown
                NetworkComms.Shutdown();
            }
        }
 public void Load()
 {
     if (fileType == FileType.JSON)
     {
         //SSL.LoadJSON(ref myObject,FileName, obfuscate);
         myObject = SSL.LoadJSON <MyObjectType>(FileName, obfuscate);
     }
     else
     {
         myObject = SSL.LoadXML <MyObjectType>(FileName, obfuscate);
         //SSL.LoadXML(ref myObject, FileName, obfuscate);
     }
     Apply();
     spr.color = Color.blue;         //physically show it was loaded
     output    = SSL.LoadTXT(FileName);
     UpdateUI();
 }
Exemple #25
0
        public void SaveConfiguration()
        {
            var manager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            manager.AppSettings.Settings["period"].Value       = period.ToString();
            manager.AppSettings.Settings["heure"].Value        = heure.ToString();
            manager.AppSettings.Settings["minute"].Value       = minute.ToString();
            manager.AppSettings.Settings["path"].Value         = path;
            manager.AppSettings.Settings["nbSaves"].Value      = nbSaves.ToString();
            manager.AppSettings.Settings["autoShutDown"].Value = autoShutDown.ToString();
            manager.AppSettings.Settings["from"].Value         = ExpAdress;
            manager.AppSettings.Settings["to"].Value           = DestAdress;
            manager.AppSettings.Settings["SSL"].Value          = SSL.ToString();
            manager.AppSettings.Settings["MDPfrom"].Value      = PWDExp;
            manager.AppSettings.Settings["SMTP"].Value         = SMTP;
            manager.AppSettings.Settings["port"].Value         = Port.ToString();
            manager.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
Exemple #26
0
        // create document
        public static void create(String localFileName, String docPath, String host, String username, String password)
        {
            String  token       = "";
            OKMAuth authService = null;

            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // create document
                document doc = new document();
                doc.path = docPath;
                documentService.create(token, doc, FileUtil.readFile(localFileName));

                // Logout OpenKM
                authService.logout(token);
                token = "";
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (create)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
Exemple #27
0
        // Checkin document
        public static void checkin(MSOpenKMCore.bean.OKMDocument oKMDocument, String host, String username, String password)
        {
            String token = "";

            MSOpenKMCore.ws.OKMAuth     authService     = null;
            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new MSOpenKMCore.ws.OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // Checkin document
                //documentService.setContent(token, oKMDocument.getPath(), FileUtil.readFile(oKMDocument.getLocalFilename()));
                //documentService.checkin(token, oKMDocument.getPath(), "");

                // Logout OpenKM
                authService.logout(token);
                token = "";
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (checkin)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
Exemple #28
0
        // cancel checkout document
        public static void cancelCheckout(MSOpenKMCore.bean.OKMDocument oKMDocument, String host, String username, String password)
        {
            String  token       = "";
            OKMAuth authService = null;

            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new MSOpenKMCore.ws.OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // Cancelling checkout
                documentService.cancelCheckout(token, oKMDocument.getPath());

                // Logout OpenKM
                authService.logout(token);
                token = "";
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (cancelCheckout)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
Exemple #29
0
    void RunEnum(bool cmdClient, int version, int suite, int curve, int hs)
    {
        IDictionary <string, object> d =
            new SortedDictionary <string, object>(
                StringComparer.Ordinal);

        d["name"]         = TEnumToString(version, suite, curve, hs);
        d["versionMin"]   = SSL.VersionName(version);
        d["versionMax"]   = SSL.VersionName(version);
        d["cipherSuites"] = new string[] {
            SSL.CipherSuiteName(suite)
        };
        if (curve >= 0)
        {
            d["curves"] = new string[] {
                SSL.CurveName(curve)
            };
            d["hashAndSigns"] = new string[] {
                SSL.HashAndSignName(hs)
            };
        }
        else
        {
            d["curves"]       = new string[0];
            d["hashAndSigns"] = new string[0];
        }
        if (SSL.IsRSA(suite) || SSL.IsECDHE_RSA(suite))
        {
            d["serverCertType"] = "RSA";
        }
        if (SSL.IsECDH(suite) || SSL.IsECDHE_ECDSA(suite))
        {
            d["serverCertType"] = "EC";
        }
        RunTest(cmdClient, d);
    }
Exemple #30
0
    /*
     * do_client()
     */
    private void do_client(int build_mode, string[] args)
    {
        if (build_mode < axtls.SSL_BUILD_ENABLE_CLIENT)
        {
            print_client_options(build_mode, args[1]);
        }

        int i = 1, res;
        int port = 4433;
        bool quiet = false;
        string password = null;
        int reconnect = 0;
        string private_key_file = null;
        string hostname = "127.0.0.1";

        /* organise the cert/ca_cert lists */
        int cert_index = 0;
        int ca_cert_index = 0;
        int cert_size = SSLUtil.MaxCerts();
        int ca_cert_size = SSLUtil.MaxCACerts();
        string[] cert = new string[cert_size];
        string[] ca_cert = new string[ca_cert_size];

        uint options = axtls.SSL_SERVER_VERIFY_LATER|axtls.SSL_DISPLAY_CERTS;
        byte[] session_id = null;

        while (i < args.Length)
        {
            if (args[i] == "-connect")
            {
                string host_port;

                if (i >= args.Length-1)
                {
                    print_client_options(build_mode, args[i]);
                }

                host_port = args[++i];
                int index_colon;

                if ((index_colon = host_port.IndexOf(':')) < 0)
                    print_client_options(build_mode, args[i]);

                hostname = new string(host_port.ToCharArray(), 
                        0, index_colon);
                port = Int32.Parse(new String(host_port.ToCharArray(), 
                            index_colon+1, host_port.Length-index_colon-1));
            }
            else if (args[i] == "-cert")
            {
                if (i >= args.Length-1 || cert_index >= cert_size)
                {
                    print_client_options(build_mode, args[i]);
                }

                cert[cert_index++] = args[++i];
            }
            else if (args[i] == "-key")
            {
                if (i >= args.Length-1)
                {
                    print_client_options(build_mode, args[i]);
                }

                private_key_file = args[++i];
                options |= axtls.SSL_NO_DEFAULT_KEY;
            }
            else if (args[i] == "-CAfile")
            {
                if (i >= args.Length-1 || ca_cert_index >= ca_cert_size)
                {
                    print_client_options(build_mode, args[i]);
                }

                ca_cert[ca_cert_index++] = args[++i];
            }
            else if (args[i] == "-verify")
            {
                options &= ~(uint)axtls.SSL_SERVER_VERIFY_LATER;
            }
            else if (args[i] == "-reconnect")
            {
                reconnect = 4;
            }
            else if (args[i] == "-quiet")
            {
                quiet = true;
                options &= ~(uint)axtls.SSL_DISPLAY_CERTS;
            }
            else if (args[i] == "-pass")
            {
                if (i >= args.Length-1)
                {
                    print_client_options(build_mode, args[i]);
                }

                password = args[++i];
            }
            else if (build_mode == axtls.SSL_BUILD_FULL_MODE)
            {
                if (args[i] == "-debug")
                {
                    options |= axtls.SSL_DISPLAY_BYTES;
                }
                else if (args[i] == "-state")
                {
                    options |= axtls.SSL_DISPLAY_STATES;
                }
                else if (args[i] == "-show-rsa")
                {
                    options |= axtls.SSL_DISPLAY_RSA;
                }
                else
                    print_client_options(build_mode, args[i]);
            }
            else    /* don't know what this is */
                print_client_options(build_mode, args[i]);

            i++;
        }

        // IPHostEntry hostInfo = Dns.Resolve(hostname); 
        IPHostEntry hostInfo = Dns.GetHostEntry(hostname);
        IPAddress[] addresses = hostInfo.AddressList;
        IPEndPoint ep = new IPEndPoint(addresses[0], port); 
        Socket client_sock = new Socket(AddressFamily.InterNetwork, 
                SocketType.Stream, ProtocolType.Tcp);
        client_sock.Connect(ep);

        if (!client_sock.Connected)
        {
            Console.WriteLine("could not connect");
            Environment.Exit(1);
        }

        if (!quiet)
        {
            Console.WriteLine("CONNECTED");
        }

        /**********************************************************************
         * This is where the interesting stuff happens. Up until now we've
         * just been setting up sockets etc. Now we do the SSL handshake.
         **********************************************************************/
        SSLClient ssl_ctx = new SSLClient(options,
                                    axtls.SSL_DEFAULT_CLNT_SESS);

        if (ssl_ctx == null)
        {
            Console.Error.WriteLine("Error: Client context is invalid");
            Environment.Exit(1);
        }

        if (private_key_file != null)
        {
            int obj_type = axtls.SSL_OBJ_RSA_KEY;

            if (private_key_file.EndsWith(".p8"))
                obj_type = axtls.SSL_OBJ_PKCS8;
            else if (private_key_file.EndsWith(".p12"))
                obj_type = axtls.SSL_OBJ_PKCS12;

            if (ssl_ctx.ObjLoad(obj_type,
                             private_key_file, password) != axtls.SSL_OK)
            {
                Console.Error.WriteLine("Private key '" + private_key_file +
                                                            "' is undefined.");
                Environment.Exit(1);
            }
        }

        for (i = 0; i < cert_index; i++)
        {
            if (ssl_ctx.ObjLoad(axtls.SSL_OBJ_X509_CERT, 
                                        cert[i], null) != axtls.SSL_OK)
            {
                Console.WriteLine("Certificate '" + cert[i] + 
                        "' is undefined.");
                Environment.Exit(1);
            }
        }

        for (i = 0; i < ca_cert_index; i++)
        {
            if (ssl_ctx.ObjLoad(axtls.SSL_OBJ_X509_CACERT, 
                                        ca_cert[i], null) != axtls.SSL_OK)
            {
                Console.WriteLine("Certificate '" + cert[i] + 
                                                        "' is undefined.");
                Environment.Exit(1);
            }
        }

        SSL ssl = new SSL(new IntPtr(0));   /* keep compiler happy */

        /* Try session resumption? */
        if (reconnect > 0)
        {
            while (reconnect-- > 0)
            {
                ssl = ssl_ctx.Connect(client_sock, session_id);

                if ((res = ssl.HandshakeStatus()) != axtls.SSL_OK)
                {
                    if (!quiet)
                    {
                        SSLUtil.DisplayError(res);
                    }

                    ssl.Dispose();
                    Environment.Exit(1);
                }

                display_session_id(ssl);
                session_id = ssl.GetSessionId();

                if (reconnect > 0)
                {
                    ssl.Dispose();
                    client_sock.Close();
                    
                    /* and reconnect */
                    client_sock = new Socket(AddressFamily.InterNetwork, 
                        SocketType.Stream, ProtocolType.Tcp);
                    client_sock.Connect(ep);
                }
            }
        }
        else
        {
            ssl = ssl_ctx.Connect(client_sock, null);
        }

        /* check the return status */
        if ((res = ssl.HandshakeStatus()) != axtls.SSL_OK)
        {
            if (!quiet)
            {
                SSLUtil.DisplayError(res);
            }

            Environment.Exit(1);
        }

        if (!quiet)
        {
            string common_name =
                ssl.GetCertificateDN(axtls.SSL_X509_CERT_COMMON_NAME);

            if (common_name != null)
            {
                Console.WriteLine("Common Name:\t\t\t" + common_name);
            }

            display_session_id(ssl);
            display_cipher(ssl);
        }

        for (;;)
        {
            string user_input = Console.ReadLine();

            if (user_input == null)
                break;

            byte[] buf = new byte[user_input.Length+2];
            buf[buf.Length-2] = (byte)'\n';     /* add the carriage return */
            buf[buf.Length-1] = 0;              /* null terminate */

            for (i = 0; i < buf.Length-2; i++)
            {
                buf[i] = (byte)user_input[i];
            }

            if ((res = ssl_ctx.Write(ssl, buf, buf.Length)) < axtls.SSL_OK)
            {
                if (!quiet)
                {
                    SSLUtil.DisplayError(res);
                }

                break;
            }
        }

        ssl_ctx.Dispose();
    }
Exemple #31
0
    /**
     * Display what session id we have.
     */
    private void display_session_id(SSL ssl)
    {    
        byte[] session_id = ssl.GetSessionId();

        if (session_id.Length > 0)
        {
            Console.WriteLine("-----BEGIN SSL SESSION PARAMETERS-----");
            foreach (byte b in session_id)
            {
                Console.Write("{0:x02}", b);
            }

            Console.WriteLine("\n-----END SSL SESSION PARAMETERS-----");
        }
    }
 private void Renegotiate(SSL.Client.SSLConnection conn)
 {
     conn.LoadNewClientCredentials(null);
 }
        private void ServerCertVerify(SSL.Common.Misc.CeriticateInfo ServCertInfo)
        {
            SSL.Common.Misc.ServerCertChainPolicyStatus Reason = ServCertInfo.PolStatus;
            byte[] CertData = ServCertInfo.CertData;

            if(CertData.Length > 0)
            {
                System.Security.Cryptography.X509Certificates.X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate(CertData);
            }
        }
Exemple #34
0
 public static extern void SSL_set0_wbio(SSL ssl, BIO wbio);
Exemple #35
0
    /**
     * Display what cipher we are using 
     */
    private void display_cipher(SSL ssl)
    {
        Console.Write("CIPHER is ");

        switch (ssl.GetCipherId())
        {
            case axtls.SSL_AES128_SHA:
                Console.WriteLine("AES128-SHA");
                break;

            case axtls.SSL_AES256_SHA:
                Console.WriteLine("AES256-SHA");
                break;

            case axtls.SSL_RC4_128_SHA:
                Console.WriteLine("RC4-SHA");
                break;

            case axtls.SSL_RC4_128_MD5:
                Console.WriteLine("RC4-MD5");
                break;

            default:
                Console.WriteLine("Unknown - " + ssl.GetCipherId());
                break;
        }
    }