/* Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved. Governed by the TrueCrypt License 3.0 the full text of which is contained in the file License.txt included in TrueCrypt binary and source code distribution packages. */ #include "Platform/Serializer.h" #include "Common/SecurityToken.h" #include "Crc32.h" #include "Keyfile.h" #include "VolumeException.h" namespace VeraCrypt { void Keyfile::Apply (const BufferPtr &pool) const { if (Path.IsDirectory()) throw ParameterIncorrect (SRC_POS); File file; Crc32 crc32; size_t poolPos = 0; uint64 totalLength = 0; uint64 readLength; SecureBuffer keyfileBuf (File::GetOptimalReadSize()); if (SecurityToken::IsKeyfilePathValid (Path)) { // Apply keyfile generated by a security token vector keyfileData; SecurityToken::GetKeyfileData (SecurityTokenKeyfile (wstring (Path)), keyfileData); if (keyfileData.size() < MinProcessedLength) throw InsufficientData (SRC_POS, Path); for (size_t i = 0; i < keyfileData.size(); i++) { uint32 crc = crc32.Process (keyfileData[i]); pool[poolPos++] += (byte) (crc >> 24); pool[poolPos++] += (byte) (crc >> 16); pool[poolPos++] += (byte) (crc >> 8); pool[poolPos++] += (byte) crc; if (poolPos >= pool.Size()) poolPos = 0; if (++totalLength >= MaxProcessedLength) break; } Memory::Erase (&keyfileData.front(), keyfileData.size()); goto done; } file.Open (Path, File::OpenRead, File::ShareRead); while ((readLength = file.Read (keyfileBuf)) > 0) { for (size_t i = 0; i < readLength; i++) { uint32 crc = crc32.Process (keyfileBuf[i]); pool[poolPos++] += (byte) (crc >> 24); pool[poolPos++] += (byte) (crc >> 16); pool[poolPos++] += (byte) (crc >> 8); pool[poolPos++] += (byte) crc; if (poolPos >= pool.Size()) poolPos = 0; if (++totalLength >= MaxProcessedLength) goto done; } } done: if (totalLength < MinProcessedLength) throw InsufficientData (SRC_POS, Path); } shared_ptr Keyfile::ApplyListToPassword (shared_ptr keyfiles, shared_ptr password) { if (!password) password.reset (new VolumePassword); if (!keyfiles || keyfiles->size() < 1) return password; KeyfileList keyfilesExp; HiddenFileWasPresentInKeyfilePath = false; // Enumerate directories foreach (shared_ptr keyfile, *keyfiles) { if (FilesystemPath (*keyfile).IsDirectory()) { size_t keyfileCount = 0; foreach_ref (const FilePath &path, Directory::GetFilePaths (*keyfile)) { #ifdef TC_UNIX // Skip hidden files if (wstring (path.ToBaseName()).find (L'.') == 0) { HiddenFileWasPresentInKeyfilePath = true; continue; } #endif keyfilesExp.push_back (make_shared (path)); ++keyfileCount; } if (keyfileCount == 0) throw KeyfilePathEmpty (SRC_POS, FilesystemPath (*keyfile)); } else { keyfilesExp.push_back (keyfile); } } make_shared_auto (VolumePassword, newPassword); if (keyfilesExp.size() < 1) { newPassword->Set (*password); } else { SecureBuffer keyfilePool (VolumePassword::MaxSize); // Pad password with zeros if shorter than max length keyfilePool.Zero(); keyfilePool.CopyFrom (ConstBufferPtr (password->DataPtr(), password->Size())); // Apply all keyfiles foreach_ref (const Keyfile &k, keyfilesExp) { k.Apply (keyfilePool); } newPassword->Set (keyfilePool); } return newPassword; } shared_ptr Keyfile::DeserializeList (shared_ptr stream, const string &name) { shared_ptr keyfiles; Serializer sr (stream); if (!sr.DeserializeBool (name + "Null")) { keyfiles.reset (new KeyfileList); foreach (const wstring &k, sr.DeserializeWStringList (name)) keyfiles->push_back (make_shared (k)); } return keyfiles; } void Keyfile::SerializeList (shared_ptr stream, const string &name, shared_ptr keyfiles) { Serializer sr (stream); sr.Serialize (name + "Null", keyfiles == nullptr); if (keyfiles) { list sl; foreach_ref (const Keyfile &k, *keyfiles) sl.push_back (FilesystemPath (k)); sr.Serialize (name, sl); } } bool Keyfile::HiddenFileWasPresentInKeyfilePath = false; } a> 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*
 Copyright (c) 2015-2016 Mounir IDRASSI for the VeraCrypt project.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

#ifndef VC_HEADER_Main_Forms_VolumePimWizardPage
#define VC_HEADER_Main_Forms_VolumePimWizardPage

#include "Forms.h"

namespace VeraCrypt
{
	class VolumePimWizardPage : public VolumePimWizardPageBase
	{
	public:
		VolumePimWizardPage (wxPanel* parent);
		~VolumePimWizardPage ();

		int GetVolumePim () const;
		void SetVolumePim (int pim);
		bool IsValid ();
		void SetMaxStaticTextWidth (int width) { InfoStaticText->Wrap (width); }
		void SetPageText (const wxString &text) { InfoStaticText->SetLabel (text); }
		void OnDisplayPimCheckBoxClick( wxCommandEvent& event );

	protected:
		void SetPimValidator ();
		void OnPimChanged  (wxCommandEvent& event);
		void OnPimValueChanged  (int pim);
	};
}

#endif // VC_HEADER_Main_Forms_VolumePimWizardPage