コード例 #1
0
        public async void Get()
        {
            bool isEncrypted = Convert.ToBoolean(_configuration["ConnectionStrings:Encrypted"]);

            if (isEncrypted)
            {
                /*
                 * In order to decrypt using this certificate, IIS_IUSRS has to have access to private key
                 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                 * WinHttpCertCfg.exe -g -c LOCAL_MACHINE\WebHosting -s "webgi.app" -a "HOMEVM10PRO\IIS_IUSRS"
                 *
                 */


                /*
                 * X509Store store = new X509Store("WebHosting", StoreLocation.LocalMachine);
                 * store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                 * X509Certificate2Collection foundCertificates =
                 *  store.Certificates.Find(
                 *      X509FindType.FindByThumbprint,
                 *      "7970ca8de61cae007db15dfb01cf6f961397ef02",
                 *      true);
                 * store.Close();
                 * if (foundCertificates.Count == 0)
                 *  return;
                 *
                 * X509Certificate2 cert = foundCertificates[0];
                 */

                string encr = GIxUtils.EncryptString("Data Source=172.22.22.12;Initial Catalog=GI_TEST;User ID=WebGi;Password=P@$$w0rd4W3bG1;Persist Security Info=True;TrustServerCertificate=true;");
                string decr = GIxUtils.DecyptString(encr);

                encr = GIxUtils.EncryptString("Barjakuzu010203");

                //X509Certificate2 cert = new X509Certificate2(@"C:\webgi\webgi-app.pfx");

                /*
                 * byte[] data = Encrypt(cert);
                 * byte[] data2 = Decrypt(cert, data);
                 * string decrString = Encoding.ASCII.GetString(data2);
                 *
                 * string base64Encoded = Convert.ToBase64String(data);
                 * byte[] data3 = Convert.FromBase64String(base64Encoded);
                 *
                 * byte[] data4 = Decrypt(cert, data3);
                 * string decrString3 = Encoding.ASCII.GetString(data4);
                 */

                //_configuration["ConnectionStrings:DefaultConnection"] = "OK";
            }


            //"<title>Service Hub</title><br/>**** " + _configuration["ConnectionStrings:DefaultConnection"] + "*****<br/>"+

            await Response.WriteAsync("<!DOCTYPE html>" +
                                      "<html lang=\"en\">" +
                                      "<head>" +
                                      "<meta charset=\"UTF - 8\">" +
                                      "<meta name=\"viewport\" content=\"width = device - width, initial - scale = 1.0\">" +
                                      "<style>body{font-family: Segoe UI,SegoeUI,Segoe WP,Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;font-weight: 400;}</style></head>" +
                                      "<body>" +
                                      "<center><h1>Service Hub - " + _configuration["Environmet"] + "</h1><hr><p>Nothing to see here</p></center>" +
                                      "</body>" +
                                      "</html>");
        }
コード例 #2
0
        private bool dbIssueSessionToken(ref LoginRequestJson req, ref LoginResponseJson resp)
        {
            try
            {
                string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
                string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();
                //string passwordEncr = GIxUtils.EncryptString(req.password);

                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_IssueSessionToken]";
                        sqlCommand.Parameters.AddWithValue("@APIKey", req.apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Username", req.username);
                        sqlCommand.Parameters.AddWithValue("@Password", req.password);

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("IsOk")]) != System.DBNull.Value)
                                {
                                    resp.success = (bool)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("UniqueID")]) != System.DBNull.Value)
                                {
                                    req.salt = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("UserWho")]) != System.DBNull.Value)
                                {
                                    resp.userWho = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Email")]) != System.DBNull.Value)
                                {
                                    resp.email = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Avatar")]) != System.DBNull.Value)
                                {
                                    resp.avatar = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Version")]) != System.DBNull.Value)
                                {
                                    resp.version = (string)value;
                                }
                                resp.user   = _loginRequest.username;
                                req.version = resp.version;
                            }
                            recordSet.Close();
                            recordSet.Dispose();
                        }
                    }

                    /////
                    /// JWT Base64 user credentials as sessionvarialbelHas + guid from DB

                    var token = new JwtBuilder()
                                .WithAlgorithm(new HMACSHA256Algorithm())                              // symmetric
                                .WithSecret(GIxUtils.DecyptString(_configuration["JWTSecretEncypted"]))
                                .AddClaim("exp", DateTimeOffset.UtcNow.AddDays(1).ToUnixTimeSeconds()) //
                                .AddClaim("LoginRequest", req)
                                .Encode();

                    //Console.WriteLine(token);
                    resp.token = token;

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            if (!resp.success)
            {
                throw new Exception("პაროლი ან მომხმარებლის სახელი არასწორად არის შეყვანილი.");
            }
            return(resp.success);
        }