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