/// <summary> /// /// </summary> /// <param name="pKey"></param> /// <param name="pubKey"></param> /// <param name="stoNum"></param> /// <param name="pSecData"></param> /// <param name="pApp"> </param> /// <param name="onlyDbData"> </param> public EncryptedConfigContainer( string pKey, string pubKey, string stoNum, PawnSecVO pSecData, PawnSecApplication pApp = PawnSecApplication.None, bool onlyDbData = false) { this.Initialized = false; this.Created = false; if (string.IsNullOrEmpty(pKey) || string.IsNullOrEmpty(pubKey)) { return; } this._privateKey = pKey; this._publicKey = pubKey; if (!this.formulateDecryptionKey()) { throw new ApplicationException("Cannot create decryption key"); } this.Created = true; this.Initialized = this.Refresh(stoNum, pSecData, onlyDbData); if (this.Initialized) { this.AppType = pApp; } }
/// <summary> /// /// </summary> /// <param name="pKey"></param> /// <param name="clientData"></param> /// <param name="databaseData"></param> /// <param name="esbData"></param> /// <param name="macData"></param> /// <param name="app"> </param> public EncryptedConfigContainer( string pKey, DataTable clientData, DataTable databaseData, DataTable esbData, DataTable macData, PawnSecApplication app) { this.Initialized = false; this.Created = false; if (clientData == null || clientData.HasErrors || clientData.Rows == null || clientData.Rows.Count <= 0 || databaseData == null || databaseData.HasErrors || databaseData.Rows == null || databaseData.Rows.Count <= 0 || esbData == null || esbData.HasErrors || esbData.Rows == null || esbData.Rows.Count <= 0 || macData == null || macData.HasErrors || string.IsNullOrEmpty(pKey)) { return; } this._privateKey = pKey; //Acquire the public key from the client data table if (!this.acquirePublicKey(clientData)) { throw new ApplicationException("Cannot retrieve public key from client data"); } //Formulate the decrypt key if (!this.formulateDecryptionKey()) { throw new ApplicationException("Cannot create decryption key"); } //Set creation stage success this.Created = true; //Initialize the client data based on the client data table if (!this.initializeClientData(clientData)) { throw new ApplicationException("Cannot initialize client data retrieved from pawnsec"); } //Initialize the database entries from the database data table if (!this.initializeDbData(databaseData)) { throw new ApplicationException("Cannot initialize database data retrieved from pawnsec"); } //Initialize the ESB entries from the ESB data table if (!this.initializeEsbData(esbData)) { throw new ApplicationException("Cannot initialize esb data retrieved from pawnsec"); } //Initialize the machine list from the machine data table if (!this.initializeMachineList(macData)) { throw new ApplicationException( "Cannot initialize machine list data retrieved from pawnsec"); } this.Initialized = true; this.AppType = app; }
public static int Resolve(PawnSecApplication application) { switch (application) { case PawnSecApplication.Cashlinx: return(1); case PawnSecApplication.Support: return(2); case PawnSecApplication.Audit: return(3); case PawnSecApplication.AuditQueries: return(4); case PawnSecApplication.DSTRViewer: return(5); default: throw new InvalidProgramException("Unable to resolve application: " + application.ToString()); } }
/// <summary> /// Retrieves all security info for a client /// </summary> /// <param name="dataAccessor"></param> /// <param name="key"></param> /// <param name="ipAddress"></param> /// <param name="machineName"></param> /// <param name="macAddress"></param> /// <param name="clientHash"></param> /// <param name="application"></param> /// <param name="clientData"></param> /// <param name="esbData"></param> /// <param name="dbData"></param> /// <param name="macList"></param> /// <param name="errorCode"></param> /// <param name="errorText"></param> /// <returns></returns> public static bool ExecuteGetClientConfiguration( OracleDataAccessor dataAccessor, string key, string ipAddress, string machineName, string macAddress, string clientHash, PawnSecApplication application, out DataTable clientData, out DataTable esbData, out DataTable dbData, out DataTable macList, out string errorCode, out string errorText) { // initialize error output variables errorCode = String.Empty; errorText = String.Empty; // initialize data table output variables clientData = null; esbData = null; dbData = null; macList = null; if (string.IsNullOrEmpty(clientHash)) { BasicExceptionHandler.Instance.AddException("ExecuteGetClientConfiguration Failed", new ApplicationException("ExecuteGetClientConfiguration Failed: Invalid hash")); return(false); } // Check that there is at least one non-null, non-empty input parameter if (String.IsNullOrEmpty(ipAddress) && String.IsNullOrEmpty(machineName) && String.IsNullOrEmpty(macAddress)) { BasicExceptionHandler.Instance.AddException("ExecuteGetClientConfiguration Failed", new ApplicationException("ExecuteGetClientConfiguration Failed: No valid inputs")); return(false); } // Ensure the data accessor is valid if (dataAccessor == null || !dataAccessor.Initialized) { BasicExceptionHandler.Instance.AddException("ExecuteGetClientConfiguration Failed", new ApplicationException("ExecuteGetClientConfiguration Failed: Data accessor instance is invalid")); return(false); } // Set up input variables var inParams = new List <OracleProcParam> { new OracleProcParam("p_ip_address", ipAddress), new OracleProcParam("p_machinename", machineName), new OracleProcParam("p_macaddress", macAddress), new OracleProcParam("p_verchk", clientHash), new OracleProcParam("p_verchk_id", PawnSecApplicationResolver.Resolve(application)) }; // Set up output DataSet outputDataSet; bool retVal; var refCursArr = new List <PairType <string, string> > { new PairType <string, string>("o_client_data", "client_data"), new PairType <string, string>("o_esb_data", "esb_data"), new PairType <string, string>("o_dbs_data", "dbs_data"), new PairType <string, string>("o_machine_list", "mac_data") }; try { retVal = dataAccessor.issueSqlStoredProcCommand( "", "pawnsec", "get_client_info", inParams, refCursArr, "o_return_code", "o_return_text", key, out outputDataSet); errorCode = dataAccessor.ErrorCode; errorText = dataAccessor.ErrorDescription; } catch (OracleException oEx) { BasicExceptionHandler.Instance.AddException("ExecuteGetClientConfiguration Failed", oEx); errorCode = " --- ExecuteGetClientConfigurationFailed"; errorText = " --- OracleException thrown: " + oEx.Message; return(false); } if (retVal == false) { BasicExceptionHandler.Instance.AddException("ExecuteGetClientConfiguration Failed: return value is false", new ApplicationException()); errorCode = dataAccessor.ErrorCode + " -- ExecuteGetClientConfigurationFailed"; errorText = dataAccessor.ErrorDescription + " -- Return value is false"; return(false); } if (outputDataSet == null || !outputDataSet.IsInitialized || (outputDataSet.Tables == null || outputDataSet.Tables.Count <= 0)) { return(false); } clientData = outputDataSet.Tables["client_data"]; esbData = outputDataSet.Tables["esb_data"]; dbData = outputDataSet.Tables["dbs_data"]; macList = outputDataSet.Tables["mac_data"]; // method completed successfully return(true); }
public bool IsApplicationAllowed(PawnSecApplication application) { return((AllowedApplications & application) != 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); }