Logo Search packages:      
Sourcecode: yapet version File versions  Download package

YAPET::File Class Reference

#include <file.h>

List of all members.


Detailed Description

Class for storing and retrieving encrypted data to and from disk.

This class takes care of storing and retrieving encrypted password records to and from disk.

Each file created by this class starts with a unencrypted recognition string which currently consists of the 8 bytes "YAPET1.0" as depicted below.

+--------+--------+--------+--------+--------+--------+--------+--------+
|   Y    |   A    |   P    |   E    |   T    |   1    |   .    |   0    |
| 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte |
+--------+--------+--------+--------+--------+--------+--------+--------+

After the recognition string a 4 byte unsigned integer which is stored in big-endian order follows. This indicator is read to determine how many bytes to read in order to get the encrypted header.

+--------+--------+--------+--------+
|   Length indicator in big-endian  |
|         order (4 bytes)           |
+--------+--------+--------+--------+--...---+
|  Encrypted header exactly as many bytes    |
|        indicated by the prefix             |
+--------+--------+--------+--------+--...---+

The decrypted header is 25 bytes in size. The first byte indicates the version of the file. The next 20 bytes are used as control string. After decryption, the control string is compared to the predefined clear text control string, in order to find out whether or not the key used to decrypt was the same used to encrypt.

+--------+
|Version |
| 1 byte |
+--------+--------+--------+--...---+
|          Control String           |
|             20 bytes              |
+--------+--------+--------+--...---+
|  Time when the Password  |
|    was set (4 bytes)     |
+--------+--------+--------+

Each encrypted password record is prefixed by a 4 byte unsigned integer which is stored in big-endian order. The methods take care returning them in the appropriate order of the host system. That integer is used to indicate the length of the following encrypted data chunk.

+--------+--------+--------+--------+
|   Length indicator in big-endian  |
|         order (4 bytes)           |
+--------+--------+--------+--------+--...---+
|  Encrypted password record of exactly as   |
|   many bytes as indicated by the prefix    |
+--------+--------+--------+--------+--...---+
|   Length indicator in big-endian  |
|         order (4 bytes)           |
+--------+--------+--------+--------+--...---+
|  Encrypted password record of exactly as   |
|   many bytes as indicated by the prefix    |
+--------+--------+--------+--------+--...---+
	      [ . . . ]

Putting this together, an encrypted file created by this class looks like this

+--------+--------+--------+--------+--------+--------+--------+--------+
|   Y    |   A    |   P    |   E    |   T    |   1    |   .    |   0    |
| 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte | 1 byte |
+--------+--------+--------+--------+--------+--------+--------+--------+
|   Length indicator in big-endian  |
|         order (4 bytes)           |
+--------+--------+--------+--------+--...---+
|  Encrypted header exactly as many bytes    |
|        indicated by the prefix             |
+--------+--------+--------+--------+--...---+
|   Length indicator in big-endian  |
|         order (4 bytes)           |
+--------+--------+--------+--------+--...---+
|  Encrypted password record of exactly as   |
|   many bytes as indicated by the prefix    |
+--------+--------+--------+--------+--...---+
|   Length indicator in big-endian  |
|         order (4 bytes)           |
+--------+--------+--------+--------+--...---+
|  Encrypted password record of exactly as   |
|   many bytes as indicated by the prefix    |
+--------+--------+--------+--------+--...---+
	      [ . . . ]

Instances of this class keeps the file open for the lifetime of the instance.

When saving a password record list, the file is reopened with the O_TRUNC specified. The recognition string and header are copied over from the former version of the file.

See also:
Record, FileHeader, PasswordRecord

Definition at line 170 of file file.h.


Public Member Functions

 File (const File &f) throw (YAPETException)
 File (const std::string &fn, const Key &key, bool create=false, bool secure=true) throw (YAPETException)
 Constructor.
bool filesecurityEnabled () const
 Returns whether or not file security is enabled.
std::string getFilename () const
 Returns the file name of the current file.
time_t getMasterPWSet (const Key &key) const throw (YAPETException,YAPETInvalidPasswordException)
const Fileoperator= (const File &f) throw (YAPETException)
 Returns the time the master password was set.
std::list< PartDecread (const Key &key) const throw (YAPETException)
 Reads the stored password records from the file.
void save (std::list< PartDec > &records) throw (YAPETException)
 Saves a password record list.
void setFilesecurity (bool secure)
 Sets file security.
void setNewKey (const Key &oldkey, const Key &newkey) throw (YAPETException)
 Sets a new encryption key for the current file.
 ~File ()

Protected Member Functions

void initFile (const Key &key) throw (YAPETException)
 Initializes an empty file.
bool isempty () const throw (YAPETException)
 Indicates whether or not the file is empty.
BDBufferread () const throw (YAPETException)
 Reads from the current offset in the file.
BDBufferreadHeader () const throw (YAPETException)
 Reads the encrypted header.
void seekDataSection () const throw (YAPETException)
uint32_t uint32_from_disk (uint32_t i) const
uint32_t uint32_to_disk (uint32_t i) const
void validateKey (const Key &key) throw (YAPETException,YAPETInvalidPasswordException)
 Validates the given key.
void write (const BDBuffer &buff, bool forceappend=false, bool forcewrite=false) throw (YAPETException, YAPETRetryException)
 Writes at the current offset in the file.
void writeHeader (const BDBuffer &enc_header) throw (YAPETException)
 Writes the given encrypted header to the file.
void writeHeader (const Record< FileHeader > &header, const Key &key) throw (YAPETException)
 Writes the given header encrypted to the file.

Private Member Functions

void checkFileSecurity () throw (YAPETException)
 Checks the permissions and owner of a file for security.
time_t lastModified () const throw (YAPETException)
 Returns the last modification time of the open file.
void openCreate () throw (YAPETException)
 Creates and opens a new file.
void openNoCreate () throw (YAPETException)
 Opens an existing file.
void preparePWSave () throw (YAPETException)
 Prepare the file for saving the password records.
void seekAbs (off_t offset) const throw (YAPETException)
 Seek to an absolute offset.
void seekCurr (off_t offset) const throw (YAPETException)
 Seek to a position relative to the current offset.
void setFileSecurity () throw (YAPETException)
 Sets the owner and permissions on a file.

Private Attributes

int fd
 The file descriptor of the password file.
std::string filename
 The file name of the file.
time_t mtime
 The modification time of the file.
bool usefsecurity
 Flag for enabling file security.

Classes

struct  DWORD
 A 32 bits double word. More...
union  ENDIAN
 Used for little-big endian conversion. More...
struct  WORD
 A 16 bits word. More...

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index