Modifications to PasswordVaultConsoleUtil.cpp
Produced: 5/14/2009 10:36:12 PM
   
Mode:  All, Ignoring Unimportant  
Left file: C:\project_repository\password_vault_cpp_source\password_vault_cpp_unobfuscated\PasswordVaultConsoleUtil.cpp  
Right file: C:\project_repository\password_vault_cpp_source\password_vault_cpp_obfuscated\PasswordVaultConsoleUtil.cpp  
1 1 /*****************************************************************
2 2 * Copyright (c):   2009, All Rights Reserved.
3 3 * Project:         Software Reverse Engineering (SRE) Education
4 4 *                  Password Vault Native C/C++ Application
5 5 * Programmer:      Teodoro Cipresso, San Jose State University
6 6 *                  teodoro@reversingproject.info
7 7 ******************************************************************
8 8  
9 9 This file is part of Password Vault.
10 10  
11 11 Password Vault is free software: you can redistribute it and/or modify
12 12 it under the terms of the GNU General Public License as published by
13 13 the Free Software Foundation, either version 3 of the License, or
14 14 (at your option) any later version.
15 15  
16 16 Password Vault is distributed in the hope that it will be useful,
17 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 19 GNU General Public License for more details.
20 20  
21 21 You should have received a copy of the GNU General Public License
22 22 along with Password Vault.  If not, see <http://www.gnu.org/licenses/>.
23 23  
24 24 */
25 25  
26 26 #include "passwordvaultconsoleutil.h"
27 27  
28 28 using namespace std;
29 29  
30 30 /**
31 31 * Default constructor
32 32 */
33 33 PasswordVaultConsoleUtil::PasswordVaultConsoleUtil()
34 34 {
35 35  
36 36 }
37 37  
38 38 /**
39 39 * Default destructor
40 40 */
41 41 PasswordVaultConsoleUtil::~PasswordVaultConsoleUtil()
42 42 {
43 43  
44 44 }
45 45  
46 46 /**
47 47 * Utility method for displaying status and prompt messages to the console.
48 48 */
49 49 void PasswordVaultConsoleUtil::DisplayMessage(const int _messageID, const char *_insert, const int _type)
50 50 {
51 51
52     string message(GetMessageText(_messageID));
  52   string message;
  53   GetMessageText(_messageID, &message);
53 54  
  55   string textBuffer;
54 56   switch (_type)
55 57   {
56 58   case INFORMATIONAL_MESSAGE:
57       message.insert(0, GetMessageText(__infoPrefix));
  59     message.assign(message.insert(0, GetMessageText(__infoPrefix, &textBuffer)));
58 60     break;
59 61   case WARNING_MESSAGE:
60       message.insert(0, GetMessageText(__warningPrefix));
  62     message.insert(0, GetMessageText(__warningPrefix, &textBuffer));
61 63     break;
62 64   case ERROR_MESSAGE:
63       message.insert(0, GetMessageText(__errorPrefix));
  65     message.insert(0, GetMessageText(__errorPrefix, &textBuffer));
64 66     break;
65 67   case PROMPT_MESSAGE:
66       message.insert(0, GetMessageText(__promptPrefix));
  68     message.insert(0, GetMessageText(__promptPrefix, &textBuffer));
67 69     break;
68 70   default:
69       message.insert(0, GetMessageText(__infoPrefix));
  71     message.insert(0, GetMessageText(__infoPrefix, &textBuffer));
70 72   }
71 73  
72     if (_insert != NULL)
  74   if (_insert != NULL && strlen(_insert) > 0
73 75   {
74 76     int insertPos = message.find("{*}", 0);
75 77     if (insertPos != string::npos)
76 78     {
77 79       message.replace(insertPos, 3, _insert);
78 80     }
79 81   }
80 82  
81 83   cout << endl << message;
82 84   if (_type != PROMPT_MESSAGE)
83 85   {
84 86     cout << endl;
85 87   }
86 88  
87 89 }
88 90  
89 91  
90 92 /**
91 93 * Displays program identification to standard out
92 94 */
93 95 void PasswordVaultConsoleUtil::DisplayProgramBanner()
94 96 {
95 97  
96 98   cout << endl << "+-----------------------------------------------+";
97 99   cout << endl << "|              Password Vault 1.0               |";
98 100 #ifdef TRIALVERSION
99 101   cout << endl << "|            (Limited Trial Version)            |";
100 102 #endif
101 103   cout << endl << "|                                               |";
102 104   cout << endl << "|  Teodoro Cipresso, San Jose State University  |";
103 105   cout << endl << "|  Contact: teodoro@reversingproject.info       |";
104 106   cout << endl << "|  AES 256-Bit Encryption using Crypto++ 5.5.2  |";
105 107   cout << endl << "+-----------------------------------------------+" << endl;
106 108  
107 109 }
108 110  
109 111 /**
110 112 * Display the program options menu to standard out
111 113 */
112 114 void PasswordVaultConsoleUtil::DisplayProgramMenu()
113 115 {
114 116  
  117   string textBuffer;
115 118   cout << endl;
116     cout << "(" << DISPLAY_PASSWORD_RECORDS << ") " << GetMessageText(__displayPasswordRecords) << endl;
117     cout << "(" << CREATE_PASSWORD_RECORD   << ") " << GetMessageText(__createPasswordRecord)   << endl;
118     cout << "(" << EDIT_PASSWORD_RECORD     << ") " << GetMessageText(__editPasswordRecord)     << endl;
119     cout << "(" << DELETE_PASSWORD_RECORD   << ") " << GetMessageText(__deletePasswordRecord)   << endl;
120     cout << "(" << CHANGE_VAULT_PASSWORD    << ") " << GetMessageText(__changeVaultPassword)    << endl;
121     cout << "(" << QUIT_PROGRAM             << ") " << GetMessageText(__quit)                   << endl;
  119   cout << "(" << DISPLAY_PASSWORD_RECORDS << ") " << GetMessageText(__displayPasswordRecords, &textBuffer) << endl;
  120   cout << "(" << CREATE_PASSWORD_RECORD   << ") " << GetMessageText(__createPasswordRecord, &textBuffer)   << endl;
  121   cout << "(" << EDIT_PASSWORD_RECORD     << ") " << GetMessageText(__editPasswordRecord, &textBuffer)     << endl;
  122   cout << "(" << DELETE_PASSWORD_RECORD   << ") " << GetMessageText(__deletePasswordRecord, &textBuffer)   << endl;
  123   cout << "(" << CHANGE_VAULT_PASSWORD    << ") " << GetMessageText(__changeVaultPassword, &textBuffer)    << endl;
  124   cout << "(" << QUIT_PROGRAM             << ") " << GetMessageText(__quit, &textBuffer)                   << endl;
122 125  
123 126 }
124 127  
125 128 /**
126 129 * Get the translatable string
127 130 */
128   const char* PasswordVaultConsoleUtil::GetMessageText(const int _messageID)
  131 const char* PasswordVaultConsoleUtil::GetMessageText(const int _messageID, string *_textBuffer)
129 132 {
  133  
130 134   switch (_messageID)
131 135   {
132       case __changeVaultPassword     : return  "Change the Vault Password";
133       case __createPasswordRecord    : return  "Create a Password Record";
134       case __dataDisallowedChars     : return  "The characters ': return ', '\"', '/', '<', and '>' are not allowed in record data.";
135       case __deletePasswordRecord    : return  "Delete a Password Record";
136       case __descriptionSet          : return  "The description was set to \"{*}\".";
137       case __displayPasswordRecords  : return  "Display Password Records";
138       case __editPasswordRecord      : return  "Edit a Password Record";
139       case __errorPrefix             : return  "[Error] ";
140       case __existingVaultNotFound   : return  "An existing password vault for the specified username \"{*}\" was not found--assuming new vault.";
141       case __incorrectPassOnChange   : return  "The specified current vault password entered is incorrect. Program will now exit without saving for safety.";
142       case __infoPrefix              : return  "[Info] ";
143       case __invalidMenuOption       : return  "An invalid menu option number was specified.";
144       case __nameSet                 : return  "The name was set to \"{*}\".";
145       case __noRecordsExist          : return  "No records exist.";
146       case __passwordIsBlank         : return  "Password cannot be blank.";
147       case __passwordSet             : return  "The password was set to \"{*}\".";
148       case __pressEnterToRetainVal   : return  "Pressing Enter on the following prompts will retain existing values.";
149       case __promptPrefix            : return  ">> ";
150       case __providedPasswordWrong   : return  "Unable to open password vault for username \"{*}\" with the provided password.";
151       case __quit                    : return  "Save Records and Quit";
152       case __recordCreated           : return  "Record successfully created.";
153       case __recordDeleted           : return  "Record \"{*}\" was deleted successfully.";
154       case __recordEdited            : return  "Record successfully edited.";
155       case __recordFound             : return  "Found a record with name \"{*}\".";
156       case __recordNameAlreadyExists : return  "A record with the name \"{*}\" already exists.";
157       case __recordNameIsBlank       : return  "Record name cannot be blank--returning to main menu...";
158       case __recordNotFound          : return  "A record with the name \"{*}\" was not found. Note: names are case-sensitive.";
159       case __selected                : return  "Selected \"{*}\":";
160       case __specifyDescription      : return  "Specify a description and press Enter: ";
161       case __specifyDescriptionEdit  : return  "Specify a description and press Enter ({*}): ";
162       case __specifyName             : return  "Specify a name and press Enter: ";
163       case __specifyNameEdit         : return  "Specify a name and press Enter ({*}): ";
164       case __specifyNameToDelete     : return  "Specify the name of the record to delete and press Enter: ";
165       case __specifyNameToEdit       : return  "Specify the name of the record to edit and press Enter: ";
166       case __specifyOptionNumber     : return  "Specify an option number and press Enter: ";
167       case __specifyPassword         : return  "Specify a password and press Enter: ";
168       case __specifyPasswordEdit     : return  "Specify a password and press Enter ({*}): ";
169       case __specifyUsername         : return  "Specify a username and press Enter: ";
170       case __specifyUsernameEdit     : return  "Specify a username and press Enter ({*}): ";
171       case __specifyVaultUsername    : return  "Specify vault username and press Enter: ";
172       case __specifyVaultPassword    : return  "Specify vault password and press Enter: ";
173       case __specifyVaultPassCurrent : return  "Specify current vault password and press Enter: ";
174       case __specifyVaultPassNew     : return  "Specify new vault password and press Enter: ";
175       case __unableToEncryptVault    : return  "Unable to encrypt password vault before saving to disk. CryptoPP::Exception: {*}";
176       case __unableToHashPassword    : return  "Unable to compute digest for password verification. CryptoPP::Exception: {*}";
177       case __unableToSaveVault       : return  "Unable to save password vault file \"{*}\" to disk. Check local file and folder permissions.";
178       case __userNameIllegalChars    : return  "Username cannot contain the characters: ? [ ] / \\ : return  + < > :; \" ' , * . { } !";
179       case __userNameIsBlank         : return  "Username cannot be blank.";
180       case __usernameSet             : return  "The username was set to \"{*}\".";
181       case __vaultLoadedOK           : return  "Existing password vault file \"{*}\" was loaded successfully.";
182       case __vaultPasswordChangeOK   : return  "The vault password for user \"{*}\" was changed successfully.";
183       case __vaultSavedOK            : return  "Password vault file \"{*}\" was saved successfully.";
184       case __warningPrefix           : return  "[Warning] ";
  136     case __changeVaultPassword     : DecryptMessageText("50756E7B74722D8175722D636E8279812D5D6E8080847C7F71", _textBuffer); break;
  137     case __createPasswordRecord    : DecryptMessageText("507F726E81722D6E2D5D6E8080847C7F712D5F72707C7F71", _textBuffer); break;
  138     case __dataDisallowedChars     : DecryptMessageText("6175722D70756E7F6E7081727F802D344734392D342F34392D343C34392D344934392D6E7B712D344B342D6E7F722D7B7C812D6E79797C8472712D767B2D7F72707C7F712D716E816E3B17", _textBuffer); break;
  139     case __deletePasswordRecord    : DecryptMessageText("5172797281722D6E2D5D6E8080847C7F712D5F72707C7F71", _textBuffer); break;
  140     case __descriptionSet          : DecryptMessageText("6175722D717280707F767D81767C7B2D846E802D8072812D817C2D2F88378A2F3B", _textBuffer); break;
  141     case __displayPasswordRecords  : DecryptMessageText("5176807D796E862D5D6E8080847C7F712D5F72707C7F7180", _textBuffer); break;
  142     case __editPasswordRecord      : DecryptMessageText("527176812D6E2D5D6E8080847C7F712D5F72707C7F71", _textBuffer); break;
  143     case __errorPrefix             : DecryptMessageText("68527F7F7C7F6A2D", _textBuffer); break;
  144     case __existingVaultNotFound   : DecryptMessageText("4E7B2D7285768081767B742D7D6E8080847C7F712D836E8279812D737C7F2D8175722D807D727076737672712D8280727F7B6E7A722D2F88378A2F2D846E802D7B7C812D737C827B713A3A6E8080827A767B742D7B72842D836E8279813B", _textBuffer); break;
  145     case __incorrectPassOnChange   : DecryptMessageText("6175722D807D727076737672712D70827F7F727B812D836E8279812D7D6E8080847C7F712D727B81727F72712D76802D767B707C7F7F7270813B2D5D7F7C747F6E7A2D847679792D7B7C842D728576812D847681757C82812D806E83767B742D737C7F2D806E737281863B", _textBuffer); break;
  146     case __infoPrefix              : DecryptMessageText("68567B737C6A2D", _textBuffer); break;
  147     case __invalidMenuOption       : DecryptMessageText("4E7B2D767B836E7976712D7A727B822D7C7D81767C7B2D7B827A6F727F2D846E802D807D727076737672713B", _textBuffer); break;
  148     case __nameSet                 : DecryptMessageText("6175722D7B6E7A722D846E802D8072812D817C2D2F88378A2F3B", _textBuffer); break;
  149     case __noRecordsExist          : DecryptMessageText("5B7C2D7F72707C7F71802D72857680813B", _textBuffer); break;
  150     case __passwordIsBlank         : DecryptMessageText("5D6E8080847C7F712D706E7B7B7C812D6F722D6F796E7B783B", _textBuffer); break;
  151     case __passwordSet             : DecryptMessageText("6175722D7D6E8080847C7F712D846E802D8072812D817C2D2F88378A2F3B", _textBuffer); break;
  152     case __pressEnterToRetainVal   : DecryptMessageText("5D7F728080767B742D527B81727F2D7C7B2D8175722D737C79797C84767B742D7D7F7C7A7D81802D847679792D7F72816E767B2D7285768081767B742D836E798272803B", _textBuffer); break;
  153     case __promptPrefix            : DecryptMessageText("4B4B2D", _textBuffer); break;
  154     case __providedPasswordWrong   : DecryptMessageText("627B6E6F79722D817C2D7C7D727B2D7D6E8080847C7F712D836E8279812D737C7F2D8280727F7B6E7A722D2F88378A2F2D847681752D8175722D7D7F7C83767172712D7D6E8080847C7F713B", _textBuffer); break;
  155     case __quit                    : DecryptMessageText("606E83722D5F72707C7F71802D6E7B712D5E827681", _textBuffer); break;
  156     case __recordCreated           : DecryptMessageText("5F72707C7F712D8082707072808073827979862D707F726E8172713B", _textBuffer); break;
  157     case __recordDeleted           : DecryptMessageText("5F72707C7F712D2F88378A2F2D846E802D717279728172712D8082707072808073827979863B", _textBuffer); break;
  158     case __recordEdited            : DecryptMessageText("5F72707C7F712D8082707072808073827979862D7271768172713B", _textBuffer); break;
  159     case __recordFound             : DecryptMessageText("537C827B712D6E2D7F72707C7F712D847681752D7B6E7A722D2F88378A2F3B", _textBuffer); break;
  160     case __recordNameAlreadyExists : DecryptMessageText("4E2D7F72707C7F712D847681752D8175722D7B6E7A722D2F88378A2F2D6E797F726E71862D7285768081803B", _textBuffer); break;
  161     case __recordNameIsBlank       : DecryptMessageText("5F72707C7F712D7B6E7A722D706E7B7B7C812D6F722D6F796E7B783A3A7F7281827F7B767B742D817C2D7A6E767B2D7A727B823B3B3B", _textBuffer); break;
  162     case __recordNotFound          : DecryptMessageText("4E2D7F72707C7F712D847681752D8175722D7B6E7A722D2F88378A2F2D846E802D7B7C812D737C827B713B2D5B7C8172472D7B6E7A72802D6E7F722D706E80723A80727B8076817683723B", _textBuffer); break;
  163     case __selected                : DecryptMessageText("60727972708172712D2F88378A2F47", _textBuffer); break;
  164     case __specifyDescription      : DecryptMessageText("607D72707673862D6E2D717280707F767D81767C7B2D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  165     case __specifyDescriptionEdit  : DecryptMessageText("607D72707673862D6E2D717280707F767D81767C7B2D6E7B712D7D7F7280802D527B81727F2D3588378A36472D", _textBuffer); break;
  166     case __specifyName             : DecryptMessageText("607D72707673862D6E2D7B6E7A722D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  167     case __specifyNameEdit         : DecryptMessageText("607D72707673862D6E2D7B6E7A722D6E7B712D7D7F7280802D527B81727F2D3588378A36472D", _textBuffer); break;
  168     case __specifyNameToDelete     : DecryptMessageText("607D72707673862D8175722D7B6E7A722D7C732D8175722D7F72707C7F712D817C2D7172797281722D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  169     case __specifyNameToEdit       : DecryptMessageText("607D72707673862D8175722D7B6E7A722D7C732D8175722D7F72707C7F712D817C2D727176812D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  170     case __specifyOptionNumber     : DecryptMessageText("607D72707673862D6E7B2D7C7D81767C7B2D7B827A6F727F2D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  171     case __specifyPassword         : DecryptMessageText("607D72707673862D6E2D7D6E8080847C7F712D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  172     case __specifyPasswordEdit     : DecryptMessageText("607D72707673862D6E2D7D6E8080847C7F712D6E7B712D7D7F7280802D527B81727F2D3588378A36472D", _textBuffer); break;
  173     case __specifyUsername         : DecryptMessageText("607D72707673862D6E2D8280727F7B6E7A722D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  174     case __specifyUsernameEdit     : DecryptMessageText("607D72707673862D6E2D8280727F7B6E7A722D6E7B712D7D7F7280802D527B81727F2D3588378A36472D", _textBuffer); break;
  175     case __specifyVaultUsername    : DecryptMessageText("607D72707673862D836E8279812D8280727F7B6E7A722D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  176     case __specifyVaultPassword    : DecryptMessageText("607D72707673862D836E8279812D7D6E8080847C7F712D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  177     case __specifyVaultPassCurrent : DecryptMessageText("607D72707673862D70827F7F727B812D836E8279812D7D6E8080847C7F712D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  178     case __specifyVaultPassNew     : DecryptMessageText("607D72707673862D7B72842D836E8279812D7D6E8080847C7F712D6E7B712D7D7F7280802D527B81727F472D", _textBuffer); break;
  179     case __unableToEncryptVault    : DecryptMessageText("627B6E6F79722D817C2D727B707F867D812D7D6E8080847C7F712D836E8279812D6F72737C7F722D806E83767B742D817C2D717680783B2D507F867D817C5D5D4747528570727D81767C7B472D88378A", _textBuffer); break;
  180     case __unableToHashPassword    : DecryptMessageText("627B6E6F79722D817C2D707C7A7D8281722D7176747280812D737C7F2D7D6E8080847C7F712D83727F767376706E81767C7B3B2D507F867D817C5D5D4747528570727D81767C7B472D88378A", _textBuffer); break;
  181     case __unableToSaveVault       : DecryptMessageText("627B6E6F79722D817C2D806E83722D7D6E8080847C7F712D836E8279812D737679722D2F88378A2F2D817C2D717680783B2D50757270782D797C706E792D737679722D6E7B712D737C7971727F2D7D727F7A768080767C7B803B", _textBuffer); break;
  182     case __userNameIllegalChars    : DecryptMessageText("6280727F7B6E7A722D706E7B7B7C812D707C7B816E767B2D8175722D70756E7F6E7081727F80472D4C2D682D6A2D3C2D692D472D7F7281827F7B2D2D382D492D4B2D47482D2F2D342D392D372D3B2D882D8A2D2E", _textBuffer); break;
  183     case __userNameIsBlank         : DecryptMessageText("6280727F7B6E7A722D706E7B7B7C812D6F722D6F796E7B783B", _textBuffer); break;
  184     case __usernameSet             : DecryptMessageText("6175722D8280727F7B6E7A722D846E802D8072812D817C2D2F88378A2F3B", _textBuffer); break;
  185     case __vaultLoadedOK           : DecryptMessageText("5285768081767B742D7D6E8080847C7F712D836E8279812D737679722D2F88378A2F2D846E802D797C6E7172712D8082707072808073827979863B", _textBuffer); break;
  186     case __vaultPasswordChangeOK   : DecryptMessageText("6175722D836E8279812D7D6E8080847C7F712D737C7F2D8280727F2D2F88378A2F2D846E802D70756E7B7472712D8082707072808073827979863B", _textBuffer); break;
  187     case __vaultSavedOK            : DecryptMessageText("5D6E8080847C7F712D836E8279812D737679722D2F88378A2F2D846E802D806E8372712D8082707072808073827979863B", _textBuffer); break;
  188     case __warningPrefix           : DecryptMessageText("68646E7F7B767B746A2D", _textBuffer); break;
185 189 #ifdef TRIALVERSION
186       case __recordLimitReached      : return  "Thank you for trying Password Vault! You have reached the maximum number of records allowed in this trial version.";
  190     case __recordLimitReached      : DecryptMessageText("61756E7B782D867C822D737C7F2D817F86767B742D5D6E8080847C7F712D636E8279812E2D667C822D756E83722D7F726E707572712D8175722D7A6E85767A827A2D7B827A6F727F2D7C732D7F72707C7F71802D6E79797C8472712D767B2D817576802D817F766E792D83727F80767C7B3B", _textBuffer); break;
187 191 #endif
188       default                        : return  "Message Not Found!";
  192     default                        : DecryptMessageText("5A7280806E74722D5B7C812D537C827B712E", _textBuffer);
189 193   }
190 194  
  195   return _textBuffer->c_str();
  196  
  197 }     
  198   
  199  
  200 #ifdef TRIALVERSION
  201  
  202 /**
  203 * Messages are encrypted using a substitution cipher.
  204 */
  205 void PasswordVaultConsoleUtil::DecryptMessageText(const char *_cipherText, string *_plainTextBuffer)
  206 {
  207  
  208    string cipherText;
  209   
  210    cipherText.assign(_cipherText);
  211  
  212    SubstitutionCipher cipher;
  213  
  214    _plainTextBuffer->assign(cipher.decryptFromHex(cipherText));
  215  
191 216 }
192 217  
  218 #endif
193 219  
194 220  
195 221  
  222  
  223  
  224