Click here to Skip to main content
15,891,253 members
Articles / Desktop Programming / MFC

Exile 1.8 - The Password Manager

Rate me:
Please Sign up or sign in to vote.
4.57/5 (51 votes)
6 Mar 20058 min read 256.2K   7.4K   111  
Yet another password manager.
/********************************************************************
	Created:	27/3/2004, 18:23
	File name: 	D:\Projects\Exile\Exile\typedefs.h
	File path:	D:\Projects\Exile\Exile
	File base:	typedefs
	File ext:	h
	Author:		Gogolev Anton
*********************************************************************/

#ifndef __TYPEDEFS_H__
#define __TYPEDEFS_H__

#include <map>
#include <vector>
#include "../MD5/MD5.h"

//////////////////////////////////////////////////////////////////////////
// Storage Constants and Structures

// Exile Password Storage file layout:
//	1. Storage Header (STORAGEHEADER)
//	2. Tree Structure information (Left Parenthesis Notation)
//	3. Private entries (ENTRY)
//  4. Advanced entries (ADVANCED)

// Storage flags
const long SF_ANSI_VERSION = 0x0001; // ANSI storage version
const long SF_UNICODE_VERSION = 0x0002; // As opposed to ANSI - Unicode version

// Storage tag
const long STORAGETAG = 0xE2077737; // .pws with bytes reversed

// Current storage version
const long STORAGEVERSION = MAKELONG(5, 1);

// Storage structores
typedef struct tagSTORAGEHEADER {
	long lTag; // Storage tag
	long lVersion; // Storage version
	long lAdvanced; // Prior to 1.5 it was reserved, now - number of ADVANCED structures
	long lFlags; // Storage flags
	int nKeySize; // Key size (in bits)
	int nRounds; // Rounds of encryption
	MD5HASH hsPassword; // "User Name + Password", hashed
	long lIndex; // Maximum ID of entries
	long lElements; // Number of elements
	long lNodes; // Nodes in a tree
} STORAGEHEADER, *LPSTORAGEHEADER;

//////////////////////////////////////////////////////////////////////////
// Private Entries and Stuff...

// Fields sizes
const unsigned int nNameLength = 64; // Entry / Category name length
const unsigned int nLoginLength = 64; // Login length
const unsigned int nPasswordLength = 64;
const unsigned int nAddressLength = 128;
const unsigned int nNotesLength = 1024;
const unsigned int nWindowTitleLength = 128; // See SMARTTYPE and ADVANCED

// Entry flags
const unsigned int EF_CATEGORY = 0x0001; // The entry is a Category
const unsigned int EF_ELEMENT = 0x0002; // The entry is an Element
const unsigned int EF_ROOTCATEGORY = 0x0004; // To distinguish a Root Category

// Storage Versions 1.1, 1.2 Extended parameters
typedef struct tagEXTENDED {
	WORD wVKCode; // Virtual key code (for element hot key)
	WORD wModifiers; // Modifiers for hot key
	BYTE cRating; // New for 1.2 - Item (both Element and Category) Rating
} EXTENDED, *LPEXTENDED;

// This is where all information is stored. Its size (in bytes) must be
// a multiple of 8 since RC5 works with 64-bit block size.
// For ANSI we have 1392 bytes (174 blocks) for each entry (with 48 bytes reserved for future use).
// For Unicode we have 2736 bytes (342 blocks, again with 48 bytes reserved).
typedef struct tagPRIVATEENTRY {
	TCHAR szName[nNameLength];
	TCHAR szLogin[nLoginLength];
	TCHAR szPassword[nPasswordLength];
	TCHAR szAddress[nAddressLength];
	TCHAR szNotes[nNotesLength];
	union
	{
		BYTE abReserved[48]; // Set to 0 for Storage version 1.0;
		EXTENDED exData; // Extended data
	};	
} PRIVATEENTRY, *LPPRIVATEENTRY;

// Advanced Parameters. For version 1.5 it contains
// Window Title and Control IDs, where Login and Password
// are supposed to be entered. The array of parameters is
// written _after_ array of ENTRY structures.

// Version 1.5 SmartType Information
typedef struct tagSMARTTYPEINFO {
	BOOL bEnabled;
	int nPasswordCtrlID;
	int nLoginCtrlID;
	TCHAR szWindowTitle[nWindowTitleLength];
} SMARTTYPEINFO, *LPSMARTTYPEINFO;

typedef struct tagADVANCED {
	long lID; // Entry ID to which this structure is assigned
	SMARTTYPEINFO sti; // SmartType Info
	BYTE abReserved[512]; // For future use. Set to 0
} ADVANCED, *LPADVANCED;

// A wrapper for PRIVATEENTRY plus data which is not supposed
// to be encrypted, such as Flags, ID.
typedef struct tagENTRY {
	unsigned int nFlags; // Entry Flags
	long lID; // Entry ID, must be greater than 0;
	long lIconID; // Entry icon ID;
	long lReserved; // It's better to set it to 0
	PRIVATEENTRY pePrivate;
} ENTRY, *LPENTRY;

typedef std::map<long, ENTRY> MENTRY, *LPMENTRY; // Map long to Entry
typedef std::map<long, ADVANCED> MADVANCED, *LPMADVANCED; // Map long to ADVANCED

// Key info
// Used to store key information
typedef struct tagKEYINFO {
	MD5HASH hsPassword; // "User Name + Password", hashed
	BYTE *pbKey; // Pointer to Key (nKeySize / 8 bytes of data)
	int nRounds; // Rounds of encryption
	int nKeySize; // Key size (in bits)
} KEYINFO, *LPKEYINFO;

//////////////////////////////////////////////////////////////////////////
// Tree Structure tokens
// Negative values to distinguish tokens from nodes

const long TST_LEFTBRACKET = -1; 
const long TST_RIGHTBRACKET = -2;

//////////////////////////////////////////////////////////////////////////
// Tree Control Item Flags

// Item can be a drop target
const LPARAM TCIF_DROPTARGET = 0x8000; 

// Whether a drop target or not
inline BOOL IsDropTarget(const LPARAM &lParam) 
{
	return (lParam & TCIF_DROPTARGET);
}

// Sets item to be a drop target
inline LPARAM SetDropTarget(const LPARAM &lParam)
{
	return (lParam | TCIF_DROPTARGET);
}

// Real item LPARAM, regardless of it being either a
// drop target or not.
inline LPARAM GetItemParam(const LPARAM &lParam) 
{
	return (lParam & (~TCIF_DROPTARGET));
}

typedef std::vector<LONG> VTREE;

#endif //__TYPEDEFS_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

Comments and Discussions