public bool InitializeSecurityData(ResourceProperties resourceProperties, string clientKey, string storeNumber, PawnSecVO pSecVo, out string machineName, out string ipAddress, out string macAddress) { machineName = string.Empty; ipAddress = string.Empty; macAddress = string.Empty; if (this.encryptedConfig != null) { return(true); } this.pawnSecLogger.logMessage(LogLevel.DEBUG, this, "InitializeSecurityData()..."); 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 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); 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 - default to machine name: {0}", machineName); return(false); } this.encryptedConfig = new EncryptedConfigContainer(resourceProperties.PrivateKey, clientKey, storeNumber, pSecVo); return(true); }
public MainWindow() { //Check to ensure that only one DSTRViewer is running at a time bool appStarted; if (Application.Current != null) { Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; } using (new Mutex(true, "DSTRViewer", out appStarted)) { if (appStarted) { InitializeComponent(); this.curEnvString = string.Empty; this.curUserName = string.Empty; this.encConfig = null; return; } var currentProcess = Process.GetCurrentProcess(); foreach (var process in Process.GetProcessesByName(currentProcess.ProcessName)) { if (process.Id == currentProcess.Id) { MessageBox.Show( "DSTRViewer is already running. Please click OK.", "Application Started", MessageBoxButton.OK, MessageBoxImage.Stop); if (Application.Current != null) { Application.Current.Shutdown(); } this.Close(); return; } } } //If we are still here, something is wrong, kill the application MessageBox.Show( "Invalid DSTRViewer process response. Killing the application.", "Oooooops - Something is Wrong Here", MessageBoxButton.OK, MessageBoxImage.Exclamation); if (Application.Current != null) { Application.Current.Shutdown(); } this.Close(); }
public PawnSecSetupForm( DataAccessTools dA, SecurityAccessor pSecAccess, StoreSetupVO sConfig, PawnSecVO pSecVo, EncryptedConfigContainer pEnc, string clientKey, string storeNum, bool initCreate) { InitializeComponent(); this.logLevel = LogLevel.DEBUG; this.storeNumber = storeNum; GlobalChangesMade = false; StoreChangesMade = false; MachineChangesMade = false; initialCreation = initCreate; this.storeData = sConfig; pawnSecAccessor = pSecAccess; pawnSecVo = pSecVo; //CreatingWorkstation = false; this.dAPawnSec = dA; ResourceProperties resourceProperties = new ResourceProperties(); resourceProperties.PrivateKey = clientKey; if (initCreate) { if (!pawnSecAccessor.InitializeSecurityData(resourceProperties, clientKey, storeNum, pSecVo, out this.machineName, out this.ipAddress, out this.macAddress)) { throw new ApplicationException( "Cannot initialize encryption portion of PAWNSEC™."); } this.pSec = pawnSecAccessor.EncryptConfig; } else { this.pSec = pEnc; } }
/// <summary> /// Parameterless Constructor to establish default assignments /// </summary> public SecurityAccessor() { this.dataAccessor = null; this.errorMessage = String.Empty; this.state = PawnSecState.DISCONNECTED; this.hostInfo = null; this.dbHost = String.Empty; this.dbPassword = String.Empty; this.dbPort = String.Empty; this.dbSchema = String.Empty; this.dbService = String.Empty; this.dbUser = String.Empty; var dNow = DateTime.Now; var yearStr = dNow.Date.Year.ToString().PadLeft(4, '0'); var monthStr = dNow.Date.Month.ToString().PadLeft(2, '0'); var dayStr = dNow.Date.Day.ToString().PadLeft(2, '0'); var hrStr = dNow.Hour.ToString().PadLeft(2, '0'); var minStr = dNow.Minute.ToString().PadLeft(2, '0'); var sb = new StringBuilder(64); //Determine current executable location and log directory if it exists string curDir = System.IO.Directory.GetCurrentDirectory(); sb.Append(curDir + @"\logs\pawnsec_details_"); sb.AppendFormat("{0}_{1}_{2}-{3}_{4}.log", yearStr, monthStr, dayStr, hrStr, minStr); this.pawnSecLogger = new TempFileLogger(sb.ToString(), DefaultLoggerHandlers.defaultLogLevelCheckHandler, DefaultLoggerHandlers.defaultLogLevelGenerator, DefaultLoggerHandlers.defaultLogMessageHandler, DefaultLoggerHandlers.defaultLogMessageFormatHandler, DefaultLoggerHandlers.defaultDateStampGenerator); this.pawnSecLogger.setLogLevel(LogLevel.DEBUG); this.pawnSecLogger.logMessage(LogLevel.INFO, this, "PAWNSECAccessor instance constructed"); //Clear out encrypted container this.encryptedConfig = null; }
/// <summary> /// /// </summary> /// <param name="environmentStr"></param> /// <param name="errTxt"></param> /// <returns></returns> private bool loadEnvironmentData(string environmentStr, out string errTxt) { errTxt = string.Empty; var rt = true; if (string.IsNullOrEmpty(environmentStr)) { errTxt = "Invalid environment string."; return(false); } //Setup file logger FileLogger.Instance.initializeLogger( string.Format("logs/dstr_viewer_{0}.log", DateTime.Now.Ticks), DefaultLoggerHandlers.defaultLogLevelCheckHandler, DefaultLoggerHandlers.defaultLogLevelGenerator, DefaultLoggerHandlers.defaultDateStampGenerator, DefaultLoggerHandlers.defaultLogMessageHandler, DefaultLoggerHandlers.defaultLogMessageFormatHandler); FileLogger.Instance.setEnabled(true); FileLogger.Instance.setLogLevel(LogLevel.DEBUG); //Setup audit logger this.auditLogger = AuditLogger.Instance; this.auditLogger.SetAuditLogEnabledChangeHandler(auditLogEnabledChangeHandler); this.auditLogger.SetAuditLogHandler(logAuditMessageHandler); this.auditLogger.SetEnabled(true); //Pwn sec tuples (user name, password, host, port, schema, service) var internalStorage = new Dictionary <string, Tuple <string, string, string, string, string, string> >(8) { { "CLXD3", new Tuple <string, string, string, string, string, string> (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==", @"5HYH35IsmBLxuFKgDA0deV4cSI9w/aeE", @"c5oa+iWxTPs=", @"Ny2VIxVYqnA=", @"tN2vG1Y6pleVpj7+YIrMdxtI3uI0kDL1") }, { "CLXI", new Tuple <string, string, string, string, string, string> (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==", @"1xaOn6Ot6HRjXbIPl7E2WJ3Bs9SmWpEy", @"c5oa+iWxTPs=", @"Ny2VIxVYqnA=", @"7GS8RS4GC4MRrLvSkAHG8w==") }, { "CLXT", new Tuple <string, string, string, string, string, string> (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==", @"bYtNZ/PbgPkj30psRLKPF+5CvrNdg5WA", @"07s4aRvDFLs=", @"Ny2VIxVYqnA=", @"BBBxdZodCA0RrLvSkAHG8w==") }, { "CLXT2", new Tuple <string, string, string, string, string, string> (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==", @"bYtNZ/PbgPkj30psRLKPF+5CvrNdg5WA", @"07s4aRvDFLs=", @"Ny2VIxVYqnA=", @"Ny/sG2mylyCVpj7+YIrMdxtI3uI0kDL1") }, { PROD, new Tuple <string, string, string, string, string, string> (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==", @"bIyV3M7QftbxuFKgDA0deV4cSI9w/aeE", @"07s4aRvDFLs=", @"Ny2VIxVYqnA=", @"ZisF3qmLAEMRrLvSkAHG8w==") } }; //Construct data storage at runtime and select based on environment string //Grab the tuple and make the proper connections if (CollectionUtilities.isNotEmptyContainsKey(internalStorage, environmentStr)) { var cxnInfo = internalStorage[environmentStr]; var privKey = Common.Properties.Resources.PrivateKey; if (cxnInfo != null) { //Create pawn security connection credentials this.pwnSecCred = new Credentials { UserName = StringUtilities.Decrypt(cxnInfo.Item1, privKey, true), PassWord = StringUtilities.Decrypt(cxnInfo.Item2, privKey, true), DBHost = StringUtilities.Decrypt(cxnInfo.Item3, privKey, true), DBPort = StringUtilities.Decrypt(cxnInfo.Item4, privKey, true), DBService = StringUtilities.Decrypt(cxnInfo.Item6, privKey, true), DBSchema = StringUtilities.Decrypt(cxnInfo.Item5, privKey, true) }; //Create pawn security data access tools this.pwnSecDataTools = DataAccessService.CreateDataAccessTools(); if (!DataAccessService.Connect(PawnStoreProcedures.PAWNSEC, this.pwnSecCred, DataAccessTools.ConnectMode.MULTIPLE, DataAccessTools.LogMode.DEBUG, ref this.pwnSecDataTools)) { errTxt = "Could not connect to pawn security database."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); } rt = false; } else { //Create pawn sec vo this.pawnSecData = new PawnSecVO(); string decryptKey; //Get primary oracle connection credentials if (!PawnStoreProcedures.GetAllPawnSecData(ref this.pwnSecDataTools, ref this.pawnSecData, out decryptKey)) { errTxt = "Could not load pawn security data for selected environment"; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); } rt = false; } else { //Get the oracle server info this.databaseServer = this.pawnSecData.DatabaseServiceList.Find( vo => (string.Equals(vo.ServiceType, EncryptedConfigContainer.ORACLEKEY, StringComparison.Ordinal))); //Connect to the primary Oracle server this.cshLnxCred = new Credentials { UserName = StringUtilities.Decrypt(this.databaseServer.DbUser, decryptKey, true), PassWord = StringUtilities.Decrypt(this.databaseServer.DbUserPwd, decryptKey, true), DBHost = StringUtilities.Decrypt(this.databaseServer.Server, decryptKey, true), DBPort = StringUtilities.Decrypt(this.databaseServer.Port, decryptKey, true), DBService = StringUtilities.Decrypt(this.databaseServer.AuxInfo, decryptKey, true), DBSchema = StringUtilities.Decrypt(this.databaseServer.Schema, decryptKey, true) }; this.cshLnxDataTools = DataAccessService.CreateDataAccessTools(); if (!DataAccessService.Connect(PawnStoreProcedures.CCSOWNER, this.cshLnxCred, DataAccessTools.ConnectMode.MULTIPLE, DataAccessTools.LogMode.DEBUG, ref this.cshLnxDataTools)) { errTxt = "Could not connect to primary Cashlinx database"; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); } rt = false; } else { //Get the couch server info this.couchServer = this.pawnSecData.DatabaseServiceList.Find( vo => (string.Equals(vo.ServiceType, EncryptedConfigContainer.COUCHDBKEY, StringComparison.Ordinal))); //Get the LDAP server info //Change #00042 - Removing LDAP authentication from DSTR viewer /*this.ldapServer = this.pawnSecData.DatabaseServiceList.Find( * vo => (string.Equals(vo.ServiceType, EncryptedConfigContainer.LDAPKEY, StringComparison.Ordinal)));*/ //Setup the LDAP connection this.encConfig = new EncryptedConfigContainer( Common.Properties.Resources.PrivateKey, this.pawnSecData.GlobalConfiguration.DataPublicKey, "00152", //Hard coded to 00152 for pawn security retrieval - GJL 05/08/2012 this.pawnSecData, PawnSecApplication.None, true); //Change #00042 - Removing LDAP authentication from DSTR viewer /* * var ldapService = * conf.GetLDAPService( * out loginDN, * out searchDN, * out userIdKey, * out userPwd, * out pwdPolicyCN); * if (ldapService != null && FileLogger.Instance.IsLogDebug) * { * FileLogger.Instance.logMessage( * LogLevel.DEBUG, this, "- Connecting to LDAP server:{0}{1}", * System.Environment.NewLine, conf.DecryptValue(ldapService.Server)); * } * * //Connect to the LDAP server * PawnLDAPAccessor.Instance.InitializeConnection( * conf.DecryptValue(ldapService.Server), * conf.DecryptValue(ldapService.Port), * loginDN, * userPwd, * pwdPolicyCN, * searchDN, * userIdKey); * * if (PawnLDAPAccessor.Instance.State != PawnLDAPAccessor.LDAPState.CONNECTED) * { * errTxt = "Could not connect to the LDAP Server"; * if (FileLogger.Instance.IsLogError) * { * FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); * } * rt = false; * } * else * { * //Authenticate the user * var attemptCount = 1; * DateTime pwdLastMod; * bool lockedOut; * string[] pwdHistory; * string displayName; * if (!PawnLDAPAccessor.Instance.AuthorizeUser( * this.curUserName, this.curPassword, ref attemptCount, * out pwdLastMod, out pwdHistory, out displayName, out lockedOut)) * { * errTxt = "Could not verify user name and password"; * if (FileLogger.Instance.IsLogError) * { * FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); * } * rt = false; * } * } */ } } } } else { errTxt = "Could not find valid connection info in internal environment data."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); } rt = false; } } else { errTxt = "Environment string not found in internal environment data."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt); } rt = false; } return(rt); }
/// <summary> /// Initializes common secured machine names and ports from PAWNSEC as well as some common init tasks /// - Exception Handler /// - Oracle connection /// - Couch service /// - Database time /// - Shop date & time /// - Site Id /// - Main application logger /// - Cashlinx PDA URL /// </summary> /// <param name="dSession"> </param> /// <param name="confRef"></param> /// <param name="appName"> </param> /// <param name="auditLogEnabled"> </param> /// <param name="exceptionHandler"> </param> /// <param name="multiConnect"></param> /// <param name="keyedConnect"></param> /// <param name="key"></param> /// <param name="auditLogEnabledChangeHandler"> </param> /// <param name="auditLogHandler"> </param> public void Init( DesktopSession dSession, EncryptedConfigContainer confRef, string appName, AuditLogEnabledChangeHandler auditLogEnabledChangeHandler, AuditLogHandler auditLogHandler, bool auditLogEnabled, Func <bool> exceptionHandler = null, bool multiConnect = false, bool keyedConnect = false, string key = null) { //Get DesktopSession instance this.desktopSession = dSession; if (this.desktopSession == null) { throw new ApplicationException("DesktopSession is null! Exiting!"); } //Setup exception handler var exHandler = BasicExceptionHandler.Instance; exHandler.PrintStackTrace = true; if (exceptionHandler != null) { exHandler.setExceptionCallback(exceptionHandler); } else { exHandler.setExceptionCallback(exceptionCallbackMethod); } //Get client config for DB connection var clientConfigDB = confRef.GetOracleDBService(); this.OracleDA = new OracleDataAccessor( confRef.DecryptValue(clientConfigDB.DbUser), confRef.DecryptValue(clientConfigDB.DbUserPwd), confRef.DecryptValue(clientConfigDB.Server), confRef.DecryptValue(clientConfigDB.Port), confRef.DecryptValue(clientConfigDB.AuxInfo), confRef.DecryptValue(clientConfigDB.Schema), (uint)confRef.ClientConfig.StoreConfiguration.FetchSizeMultiplier, multiConnect, keyedConnect, key); if (!this.OracleDA.Initialized) { throw new ApplicationException("Oracle data accessor is not initialized. Cannot interact with the database. Exiting!"); } //Get client config for Couch connection var clientDocDb = confRef.GetCouchDBService(); if (clientDocDb != null) { this.CouchDBConnector = new SecuredCouchConnector( confRef.DecryptValue(clientDocDb.Server), confRef.DecryptValue(clientDocDb.Port), DesktopSession.SSL_PORT, confRef.DecryptValue(clientDocDb.Schema), confRef.DecryptValue(clientDocDb.DbUser), confRef.DecryptValue(clientDocDb.DbUserPwd), DesktopSession.SECURE_COUCH_CONN); } else { throw new ApplicationException("Cannot initialize secured document server connection! Exiting!"); } //Retrieve database time DateTime time; ShopProcedures.ExecuteGetDatabaseTime(this.OracleDA, out time); this.DatabaseTime = time; //Set shop date time var storeConf = confRef.ClientConfig.StoreConfiguration; ShopDateTime.Instance.setOffsets(0, 0, 0, 0, 0, 0, 0); ShopDateTime.Instance.SetDatabaseTime(this.DatabaseTime); ShopDateTime.Instance.SetPawnSecOffsetTime(storeConf); //Initialize the site this.currentSiteId = new SiteId(); this.currentSiteId.StoreNumber = confRef.ClientConfig.StoreSite.StoreNumber; //Load store information LoadStoreData(currentSiteId.StoreNumber); //Finalize site info population this.currentSiteId.TerminalId = confRef.ClientConfig.ClientConfiguration.WorkstationId; this.currentSiteId.Alias = confRef.ClientConfig.StoreSite.Alias; this.currentSiteId.Company = confRef.ClientConfig.StoreSite.CompanyNumber; this.currentSiteId.CompanyNumber = confRef.ClientConfig.StoreSite.CompanyNumber; this.currentSiteId.Date = ShopDateTime.Instance.ShopDate; this.currentSiteId.State = confRef.ClientConfig.StoreSite.State; this.currentSiteId.LoanAmount = 0.00M; try { //Initialize the logger this.initializeLogger(appName); //Initialize audit logger this.initializeAuditLogger(auditLogEnabledChangeHandler, auditLogHandler, auditLogEnabled); } catch (Exception eX) { throw new ApplicationException("One or both primary loggers failed to initialize!", eX); } //Retrieve URL var pdaUrlObj = confRef.GetURL(); if (pdaUrlObj != null) { this.CashlinxPDAURL = confRef.DecryptValue(pdaUrlObj.AuxInfo); } else { throw new ApplicationException("Cannot determine CashlinxPDA URL! Exiting!"); } }
/// <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); }