The vault file is used to store keys and key-signatures on disk. More...

Classes

struct  _vault_t
 This structure represents a vault. More...
 
struct  _vault_header_t
 Defines the vault header. More...
 
struct  _vault_item_header_t
 An item header. More...
 

Typedefs

typedef struct _vault_t vault_t
 Name of the struct. More...
 
typedef struct _vault_header_t vault_header_t
 Name of the struct. More...
 
typedef struct _vault_item_header_t vault_item_header_t
 Name of the struct. More...
 

Functions

vault_tpcpvault_init (PCPCTX *ptx, char *filename)
 Open a vault file. More...
 
int pcpvault_additem (PCPCTX *ptx, vault_t *vault, void *item, size_t itemsize, uint8_t type)
 Add an item to the vault. More...
 
int pcpvault_addkey (PCPCTX *ptx, vault_t *vault, void *item, uint8_t type)
 Add a key to the vault. More...
 
int pcpvault_close (PCPCTX *ptx, vault_t *vault)
 Close a vault file. More...
 
void pcpvault_free (vault_t *vault)
 Free vault resources. More...
 
int pcpvault_fetchall (PCPCTX *ptx, vault_t *vault)
 Reads in the vault contents. More...
 

Detailed Description

The vault file is used to store keys and key-signatures on disk.

It works like a keyring.

Vault File Format

The vault file contains all public and secret keys. It's a portable binary file.

The file starts with a header:

+-------------------------------------------+
| Field Size Description |
+-------------------------------------------+
| File ID | 1 | Vault Identifier 0xC4 |
+-------------------------------------------+
| Version | 4 | Big endian, version |
+-------------------------------------------+
| Checksum | 32 | SHA256 Checksum |
+-------------------------------------------+

The checksum is a checksum of all keys.

The header is followed by the keys. Each key is preceded by an item header which looks like this:

+--------------------------------------------+
| Field Size Description |
+--------------------------------------------+
| Type | 1 | Key type (S,P,M) |
+--------------------------------------------+
| Size | 4 | Big endian, keysize |
+--------------------------------------------+
| Version | 4 | Big endian, keyversion |
+--------------------------------------------+
| Checksum | 32 | SHA256 Key Checksum |
+--------------------------------------------+

Type can be one of:

  • PCP_KEY_TYPE_MAINSECRET 0x01
  • PCP_KEY_TYPE_SECRET 0x02
  • PCP_KEY_TYPE_PUBLIC 0x03

The item header is followed by the actual key contents.

Typedef Documentation

Name of the struct.

Definition at line 245 of file structs.h.

Name of the struct.

Definition at line 257 of file structs.h.

typedef struct _vault_t vault_t

Name of the struct.

Definition at line 234 of file structs.h.

Function Documentation

int pcpvault_additem ( PCPCTX ptx,
vault_t vault,
void *  item,
size_t  itemsize,
uint8_t  type 
)

Add an item to the vault.

Adds item with the size itemsize and type type to the vault. Generates the item header and the checksum of the item.

This function writes directly into the vault file. Use with care. To be safe, use pcpvault_addkey() instead.

Parameters
[in]ptxpcp context.
[out]vaultThe vault object.
[in]itemThe item to write.
[in]itemsizeSize of the item.
[in]typeType of the item.
See Also
_PCP_KEY_TYPES.
Returns
Returns the number of bytes written or 0 in case of an error. Check fatals_if_any().
int pcpvault_addkey ( PCPCTX ptx,
vault_t vault,
void *  item,
uint8_t  type 
)

Add a key to the vault.

This function determines the size of the item to write based on the given type. It converts the internal structure to a binary blob and converty multibyte values to big endian.

It copies the given vault file to a temporary vault file, adds the item and if this went ok, copies the temporary file back to the original location. It then re-calculates the vault checksum and puts it into the vault header.

Parameters
[in]ptxpcp context.
[out]vaultThe vault object.
[in]itemThe item to write (a key or keysig)
[in]typeType of the item.
See Also
_PCP_KEY_TYPES.
Returns
Returns 0 on success or 1 in case of errors. Check fatals_if_any().
int pcpvault_close ( PCPCTX ptx,
vault_t vault 
)

Close a vault file.

If the vault is in unsafed state, write everything to disk and close the vault. Before overwriting the current vault file a backup will be made. If anything fails during writing the backup file will be retained and the error message will contain the filename of the backup file, so that the user doesn't loose data.

Parameters
[in]ptxpcp context.
[out]vaultThe vault object.
Returns
Returns 0. Check fatals_if_any() anyway.
int pcpvault_fetchall ( PCPCTX ptx,
vault_t vault 
)

Reads in the vault contents.

This function reads the open vault contents and puts them into the apropriate hashes.

See Also
KEYHASH.

Currently only known types can be read. If your're saving unknown types to the vault, an error will occur.

See Also
_PCP_KEY_TYPES.

Each item will be converted put into the aproprieate structure, multibyte values will be converted to host endianess. It also calculates the checksum of the vault contents and compares it with the one stored in the vault header. If it doesn't match an error will be thrown.

Parameters
[in]ptxpcp context.
[out]vaultThe vault object.
Returns
Returns 0 on success or -1 in case of errors. Check fatals_if_any().
void pcpvault_free ( vault_t vault)

Free vault resources.

Parameters
[in]vaultThe vault object.
vault_t* pcpvault_init ( PCPCTX ptx,
char *  filename 
)

Open a vault file.

If the file doesn't exist, it will be created.

Parameters
[in]ptxpcp context.
[in]filenameThe filename of the vault file.
Returns
Returns a vault object.