|
|
1.1.1.3 ! root 1: /* The source code contained in this file has been derived from the source code ! 2: of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and ! 3: additions to that source code contained in this file are Copyright (c) 2004 ! 4: TrueCrypt Team and Copyright (c) 2004 TrueCrypt Foundation. Unmodified ! 5: parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation ! 6: release. Please see the file license.txt for full license details. */ 1.1 root 7: 8: #include "TCdefs.h" 9: 10: #include "crypto.h" 11: #include "fat.h" 12: #include "format.h" 13: #include "volumes.h" 14: #include "password.h" 15: #include "apidrvr.h" 16: #include "dlgcode.h" 17: #include "pkcs5.h" 18: #include "endian.h" 19: 20: #include <io.h> 21: 22: void 23: VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword, 24: HWND hVerify, char *szPassword, 25: char *szVerify) 26: { 27: char szTmp1[MAX_PASSWORD + 1]; 28: char szTmp2[MAX_PASSWORD + 1]; 29: int k = GetWindowTextLength (hPassword); 30: BOOL bEnable = FALSE; 31: 32: if (hwndDlg); /* Remove warning */ 33: 34: GetWindowText (hPassword, szTmp1, sizeof (szTmp1)); 35: GetWindowText (hVerify, szTmp2, sizeof (szTmp2)); 36: 37: if (strcmp (szTmp1, szTmp2) != 0) 38: bEnable = FALSE; 39: else 40: { 41: if (k >= MIN_PASSWORD) 42: bEnable = TRUE; 43: else 44: bEnable = FALSE; 45: } 46: 47: if (szPassword != NULL) 48: memcpy (szPassword, szTmp1, sizeof (szTmp1)); 49: 50: if (szVerify != NULL) 51: memcpy (szVerify, szTmp2, sizeof (szTmp2)); 52: 53: burn (szTmp1, sizeof (szTmp1)); 54: burn (szTmp2, sizeof (szTmp2)); 55: 56: EnableWindow (hButton, bEnable); 57: } 58: 59: int 1.1.1.3 ! root 60: ChangePwd (char *lpszVolume, char *lpszOldPassword, char *lpszPassword, int pkcs5) 1.1 root 61: { 62: int nDosLinkCreated = 0, nStatus; 63: char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; 64: char szDosDevice[TC_MAX_PATH]; 65: char buffer[SECTOR_SIZE], boot[SECTOR_SIZE]; 66: PCRYPTO_INFO cryptoInfo = NULL, ci = NULL; 67: void *dev = INVALID_HANDLE_VALUE; 68: OPEN_TEST_STRUCT driver; 69: DISKIO_STRUCT win9x_r0; 70: diskio_f write, read; 71: DWORD dwError; 72: BOOL bDevice; 73: 74: if (Randinit ()) return 1; 75: 76: CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice); 77: 78: if (nCurrentOS == WIN_NT || bDevice == FALSE) 79: { 80: write = (diskio_f) _lwrite; 81: read = (diskio_f) _lread; 82: 83: if (bDevice == FALSE) 84: { 85: strcpy (szCFDevice, szDiskFile); 86: } 87: else 88: { 89: nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); 90: if (nDosLinkCreated != 0) 91: { 92: return nDosLinkCreated; 93: } 94: } 95: 96: dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 97: } 98: else 99: { 100: write = (diskio_f) win9x_io; 101: read = (diskio_f) win9x_io; 102: 103: if (OpenDevice (lpszVolume, &driver) == FALSE) 104: { 105: return ERR_OS_ERROR; 106: } 107: else if (driver.secstart == driver.seclast) 108: { 109: return ERR_ACCESS_DENIED; 110: } 111: 112: win9x_r0.devicenum = driver.device; 113: win9x_r0.sectorstart = driver.secstart; 114: 115: dev = &win9x_r0; 116: } 117: 118: if (dev == INVALID_HANDLE_VALUE) 119: { 120: return ERR_OS_ERROR; 121: } 122: 123: 124: WaitCursor (); 125: 126: win9x_r0.mode = 0; 127: 128: /* Read in volume */ 129: nStatus = (*read) ((HFILE) dev, buffer, sizeof (buffer)); 130: if (nStatus != sizeof (buffer)) 131: { 132: nStatus = ERR_VOL_SIZE_WRONG; 133: goto error; 134: } 135: 136: memcpy (boot, buffer, SECTOR_SIZE); 137: 138: /* Parse header */ 139: nStatus = VolumeReadHeader (buffer, lpszOldPassword, &cryptoInfo); 140: if (nStatus != 0) 141: { 142: cryptoInfo = NULL; 143: goto error; 144: } 145: 146: /* Change password now */ 147: 148: if (dev != &win9x_r0) 149: { 150: nStatus = _llseek ((HFILE) dev, 0, FILE_BEGIN); 151: 152: if (nStatus != 0) 153: { 154: nStatus = ERR_VOL_SEEKING; 155: goto error; 156: } 157: } 158: 159: win9x_r0.mode = 1; 160: win9x_r0.sectorstart -= 1; 161: 1.1.1.3 ! root 162: if (pkcs5 != 0) ! 163: cryptoInfo->pkcs5 = pkcs5; ! 164: 1.1 root 165: VolumeWriteHeader (boot, 166: cryptoInfo->cipher, 167: lpszPassword, 168: cryptoInfo->pkcs5, 169: cryptoInfo->master_decrypted_key, 170: cryptoInfo->volume_creation_time, 171: &ci); 172: 173: crypto_close (ci); 174: 175: /* Write out new encrypted key + key check */ 176: nStatus = (*write) ((HFILE) dev, boot, SECTOR_SIZE); 177: 178: if (nStatus != SECTOR_SIZE) 179: { 180: nStatus = ERR_VOL_WRITING; 181: goto error; 182: } 183: 184: /* That's it done... */ 185: nStatus = 0; 186: 187: error: 188: 189: burn (buffer, sizeof (buffer)); 190: 191: if (cryptoInfo != NULL) 192: crypto_close (cryptoInfo); 193: 194: dwError = GetLastError (); 195: 196: if (dev != &win9x_r0) 197: { 198: CloseHandle ((HANDLE) dev); 199: 200: if (bDevice == TRUE && nDosLinkCreated != 0) 201: { 202: int x = RemoveFakeDosName (szDiskFile, szDosDevice); 203: if (x != 0) 204: { 205: dwError = GetLastError (); 206: nStatus = x; 207: } 208: } 209: } 210: 211: SetLastError (dwError); 212: 213: NormalCursor (); 214: 215: return nStatus; 216: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.