Example #1
0
        /// <summary>
        /// Updates whether client is allowed or not
        /// </summary>
        /// <param name="isAllowed"></param>
        /// <returns></returns>
        public bool UpdateAllowedInfo(bool isAllowed)
        {
            if (this.dataAccessor == null || this.state == PawnSecState.DISCONNECTED)
            {
                return(false);
            }

            string allowed = (isAllowed ? "1" : "0");

            string errorCode = String.Empty;
            string errorText = String.Empty;

            var machineName = System.Environment.MachineName.ToLower();

            machineName = string.Concat(machineName, MACHINE_SERVER);

            bool retVal = PawnSecurityProcedures.ExecuteUpdateClientInfo(
                this.dataAccessor,
                KEY,
                null,
                machineName,
                null,
                allowed,
                null,
                out errorCode,
                out errorText);

            if (retVal != true)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Error Updating Allowed Info.");
                return(false);
            }

            // success
            return(true);
        }
Example #2
0
        /// <summary>
        /// Retrieves data from PawnSec
        /// </summary>
        public bool RetrieveSecurityData(string privateKey, string clientKey, bool disconnectAfter, PawnSecApplication app)
        {
            this.pawnSecLogger.logMessage(LogLevel.DEBUG, this, "RetrievingSecurityData()...");
            if (this.dataAccessor == null || this.state == PawnSecState.DISCONNECTED)
            {
                this.pawnSecLogger.logMessage(LogLevel.ERROR, this, "- Data Accessor is invalid or disconnected");
                return(false);
            }

            //Retrieve the machine name
            var machineName = System.Environment.MachineName;

            if (this.pawnSecLogger.IsLogDebug)
            {
                this.pawnSecLogger.logMessage(
                    LogLevel.DEBUG, "- Machine Name From Environment: {0}", machineName);
            }
            machineName = string.Concat(machineName, MACHINE_SERVER);
            this.pawnSecLogger.logMessage(LogLevel.INFO, this, "- Machine Name = {0}", machineName);

            string ipAddress;
            string macAddress;

            try
            {
                //Create the host information object
                this.hostInfo = new HostInformation(this.pawnSecLogger);

                //Retrieve the Ip address
                ipAddress = hostInfo.IPAddress;
                this.pawnSecLogger.logMessage(LogLevel.DEBUG, this, "- IP Address  = {0}", ipAddress);

                //Retrieve the MAC address
                macAddress = hostInfo.MACAddress;
                this.pawnSecLogger.logMessage(LogLevel.DEBUG, this, "- MAC Address = {0}", macAddress);
            }
            catch (Exception eX)
            {
                ipAddress  = null;
                macAddress = null;
                this.pawnSecLogger.logMessage(LogLevel.WARN, this, "- Could not retrieve MAC address or IP address - Exception thrown {0}- default to machine name: {1}", eX, machineName);
            }

            //Create output variables
            string    errorCode;
            string    errorText;
            DataTable clientData;
            DataTable esbData;
            DataTable dbData;
            DataTable macData;

            bool retVal = PawnSecurityProcedures.ExecuteGetClientConfiguration(
                this.dataAccessor,
                KEY,
                ipAddress,
                machineName,
                macAddress,
                clientKey,
                app,
                out clientData,
                out esbData,
                out dbData,
                out macData,
                out errorCode,
                out errorText);

            // check the table data
            if (retVal != true || clientData == null || !clientData.IsInitialized || clientData.HasErrors ||
                esbData == null || !esbData.IsInitialized || esbData.HasErrors ||
                dbData == null || !dbData.IsInitialized || dbData.HasErrors ||
                macData == null || !macData.IsInitialized || macData.HasErrors)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Incomplete data retrieval occurred.");
                return(false);
            }

            // check public key data
            if (clientData.Rows != null && clientData.Rows.Count > 0)
            {
                DataRow row = clientData.Rows[0];

                if (row != null)
                {
                    string publicKey = row["datapublickey"].ToString();
                    if (string.IsNullOrEmpty(publicKey))
                    {
                        this.pawnSecLogger.logMessage(
                            LogLevel.FATAL, this, "No Public Key found.");

                        return(false);
                    }
                }
                else
                {
                    this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "No row data found.");

                    return(false);
                }
            }
            else
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "No row data exists.");

                return(false);
            }

            // check to make sure that we have at least one db server and three esb servers
            if (esbData.Rows == null || dbData.Rows == null || esbData.Rows.Count < 3 || dbData.Rows.Count < 1)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Application critical information was not retrieved.");
                return(false);
            }

            try
            {
                // set data into configuration
                this.encryptedConfig =
                    new EncryptedConfigContainer(privateKey,
                                                 clientData, dbData, esbData, macData, app);
                this.pawnSecLogger.logMessage(
                    LogLevel.DEBUG, this, "Set Encrypted Configuration data");

                if (!string.IsNullOrWhiteSpace(encryptedConfig.ClientConfig.GlobalConfiguration.AdobeReaderPath) &&
                    !File.Exists(encryptedConfig.ClientConfig.GlobalConfiguration.AdobeReaderPath))
                {
                    this.pawnSecLogger.logMessage(LogLevel.WARN, this, "Pdf Viewer does not exist at \"" + encryptedConfig.ClientConfig.GlobalConfiguration.AdobeReaderPath + "\"");
                }

                /*
                 * if (UpdateConnectionInfo(true))
                 * {
                 *  this.pawnSecLogger.logMessage(LogLevel.INFO, this, "Client successfully connected to PAWNSEC.");
                 * }
                 * else
                 * {
                 *  this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Client failed to connect to PAWNSEC.");
                 * }*/

                // disconnect from PAWNSEC database);
                if (disconnectAfter)
                {
                    this.Disconnect();
                }
            }
            catch (Exception eX)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Encrypted Configuration failed to initialize: {0}.", eX);
                return(false);
            }

            // everything has succeeded at this point
            return(true);
        }