#include "Token.h" #include "Platform/Finally.h" #include "Platform/ForEach.h" #if !defined(TC_WINDOWS) || defined(TC_PROTOTYPE) #include "Platform/SerializerFactory.h" #include "Platform/StringConverter.h" #include "Platform/SystemException.h" #else #include "Dictionary.h" #include "Language.h" #endif #include #include #include #include "SecurityToken.h" #include "EMVToken.h" #include "PCSCException.h" #include "iostream" using namespace std; namespace VeraCrypt { vector> Token::GetAvailableKeyfiles(bool isEMVSupportEnabled) { vector> availableKeyfiles; bool securityTokenLibraryInitialized = true; bool scardLibraryInitialized = true; try { foreach (SecurityTokenKeyfile k, SecurityToken::GetAvailableKeyfiles()) { availableKeyfiles.push_back(shared_ptr(new SecurityTokenKeyfile(k))); } } catch (SecurityTokenLibraryNotInitialized&) { securityTokenLibraryInitialized = false; } if (isEMVSupportEnabled) { try { foreach (EMVTokenKeyfile k, EMVToken::GetAvailableKeyfiles()) { availableKeyfiles.push_back(shared_ptr(new EMVTokenKeyfile(k))); } } catch (ScardLibraryInitializationFailed&) { scardLibraryInitialized = false; } } if (availableKeyfiles.size() == 0) { if (!securityTokenLibraryInitialized) { throw SecurityTokenLibraryNotInitialized(); } else if (!scardLibraryInitialized) { throw ScardLibraryInitializationFailed(); } } return availableKeyfiles; } bool Token::IsKeyfilePathValid(const wstring& tokenKeyfilePath, bool isEMVSupportEnabled) { if (isEMVSupportEnabled) { return SecurityToken::IsKeyfilePathValid(tokenKeyfilePath) || EMVToken::IsKeyfilePathValid(tokenKeyfilePath); } return SecurityToken::IsKeyfilePathValid(tokenKeyfilePath); } list > Token::GetAvailableTokens() { list > availableTokens; foreach(SecurityTokenInfo securityToken, SecurityToken::GetAvailableTokens()) { availableTokens.push_back(shared_ptr(new SecurityTokenInfo(std::move(securityToken)))); } return availableTokens ; } shared_ptr Token::getTokenKeyfile(const TokenKeyfilePath& path) { shared_ptr tokenKeyfile; if (SecurityToken::IsKeyfilePathValid(path)) { tokenKeyfile = shared_ptr(new SecurityTokenKeyfile(path)); } else { if (EMVToken::IsKeyfilePathValid(path)) { tokenKeyfile = shared_ptr(new EMVTokenKeyfile(path)); } } return tokenKeyfile; } }it' value='search'/>
blob: 9ef2f035502dad84ef374630e3eb6e09139435da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 Legal Notice: Some portions of the source code contained in this file were
 derived from the source code of TrueCrypt 7.1a, which is 
 Copyright (c) 2003-2012 TrueCrypt Developers Association and which is 
 governed by the TrueCrypt License 3.0, also from the source code of
 Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
 and which is governed by the 'License Agreement for Encryption for the Masses' 
 Modifications and additions to the original source code (contained in this file) 
 and all other portions of this file are Copyright (c) 2013-2016 IDRIX
 and are governed by the Apache License 2.0 the full text of which is
 contained in the file License.txt included in VeraCrypt binary and source
 code distribution packages. */

#ifndef PASSWORD_H
#define PASSWORD_H

// User text input limits
#define MIN_PASSWORD			1		// Minimum possible password length
#define MAX_PASSWORD			64		// Maximum possible password length
#define MAX_PIM				7		// Maximum allowed digits in a PIM (enough for maximum value)
#define MAX_PIM_VALUE		2147468 // Maximum value to have a positive 32-bit result for formula 15000 + (PIM x 1000)
#define MAX_BOOT_PIM			5		// Maximum allowed digits in a PIM for boot (enough for 16-bit value)
#define MAX_BOOT_PIM_VALUE	65535

#define PASSWORD_LEN_WARNING	20		// Display a warning when a password is shorter than this

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
	// Modifying this structure can introduce incompatibility with previous versions
	unsigned __int32 Length;
	unsigned char Text[MAX_PASSWORD + 1];
	char Pad[3]; // keep 64-bit alignment
} Password;

#if defined(_WIN32) && !defined(TC_WINDOWS_DRIVER) && !defined(_UEFI)

void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
BOOL CheckPasswordLength (HWND hwndDlg, unsigned __int32 passwordLength, int pim, BOOL bForBoot, BOOL bSkipPasswordWarning, BOOL bSkipPimWarning);		
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);			
int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5, int old_pim, BOOL truecryptMode, Password *newPassword, int pkcs5, int pim, int wipePassCount, HWND hwndDlg);

#endif	// defined(_WIN32) && !defined(TC_WINDOWS_DRIVER) && !defined(_UEFI)

#ifdef __cplusplus
}
#endif

#endif	// PASSWORD_H