2013-11-15 15:54:31 +01:00
|
|
|
/* keybox-defs.h - internal Keybox definitions
|
2004-04-20 14:16:55 +00:00
|
|
|
* Copyright (C) 2001, 2004 Free Software Foundation, Inc.
|
2003-06-05 07:14:21 +00:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 19:49:40 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 07:14:21 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2003-06-05 07:14:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEYBOX_DEFS_H
|
|
|
|
#define KEYBOX_DEFS_H 1
|
|
|
|
|
|
|
|
#ifdef GPG_ERR_SOURCE_DEFAULT
|
2012-02-06 20:50:47 +01:00
|
|
|
# if GPG_ERR_SOURCE_DEFAULT != GPG_ERR_SOURCE_KEYBOX
|
|
|
|
# error GPG_ERR_SOURCE_DEFAULT already defined
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_KEYBOX
|
2003-06-05 07:14:21 +00:00
|
|
|
#endif
|
|
|
|
#include <gpg-error.h>
|
2004-12-18 10:22:10 +00:00
|
|
|
#define map_assuan_err(a) \
|
|
|
|
map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
|
|
|
|
|
2003-11-12 15:17:44 +00:00
|
|
|
#include <sys/types.h> /* off_t */
|
|
|
|
|
2017-12-22 12:55:32 +01:00
|
|
|
#include "../common/util.h"
|
2004-04-20 14:16:55 +00:00
|
|
|
#include "keybox.h"
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct keyboxblob *KEYBOXBLOB;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct keybox_name *KB_NAME;
|
2011-02-04 12:57:53 +01:00
|
|
|
struct keybox_name
|
2008-04-01 15:08:57 +00:00
|
|
|
{
|
|
|
|
/* Link to the next resources, so that we can walk all
|
|
|
|
resources. */
|
|
|
|
KB_NAME next;
|
|
|
|
|
|
|
|
/* True if this is a keybox with secret keys. */
|
2003-06-05 07:14:21 +00:00
|
|
|
int secret;
|
2008-04-01 15:08:57 +00:00
|
|
|
|
|
|
|
/* A table with all the handles accessing this resources.
|
|
|
|
HANDLE_TABLE_SIZE gives the allocated length of this table unused
|
|
|
|
entrues are set to NULL. HANDLE_TABLE may be NULL. */
|
|
|
|
KEYBOX_HANDLE *handle_table;
|
|
|
|
size_t handle_table_size;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2016-01-13 10:16:27 +01:00
|
|
|
/* The lock handle or NULL it not yet initialized. */
|
|
|
|
dotlock_t lockhd;
|
|
|
|
|
2008-04-01 15:08:57 +00:00
|
|
|
/* Not yet used. */
|
2003-06-05 07:14:21 +00:00
|
|
|
int is_locked;
|
2008-04-01 15:08:57 +00:00
|
|
|
|
|
|
|
/* Not yet used. */
|
2003-06-05 07:14:21 +00:00
|
|
|
int did_full_scan;
|
2008-04-01 15:08:57 +00:00
|
|
|
|
|
|
|
/* The name of the resource file. */
|
2003-06-05 07:14:21 +00:00
|
|
|
char fname[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-02 15:55:00 +02:00
|
|
|
struct keybox_found_s
|
|
|
|
{
|
|
|
|
KEYBOXBLOB blob;
|
|
|
|
size_t pk_no;
|
|
|
|
size_t uid_no;
|
|
|
|
};
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
struct keybox_handle {
|
2016-01-13 10:16:27 +01:00
|
|
|
KB_NAME kb;
|
2003-06-05 07:14:21 +00:00
|
|
|
int secret; /* this is for a secret keybox */
|
|
|
|
FILE *fp;
|
|
|
|
int eof;
|
|
|
|
int error;
|
2011-02-04 12:57:53 +01:00
|
|
|
int ephemeral;
|
2014-10-09 19:10:32 +02:00
|
|
|
int for_openpgp; /* Used by gpg. */
|
2014-06-02 15:55:00 +02:00
|
|
|
struct keybox_found_s found;
|
|
|
|
struct keybox_found_s saved_found;
|
2003-06-05 07:14:21 +00:00
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
char *pattern;
|
|
|
|
} word_match;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-29 19:52:08 +01:00
|
|
|
/* OpenPGP helper structures. */
|
2004-08-24 19:55:47 +00:00
|
|
|
struct _keybox_openpgp_key_info
|
|
|
|
{
|
|
|
|
struct _keybox_openpgp_key_info *next;
|
2012-12-28 13:45:41 +01:00
|
|
|
int algo;
|
2019-01-29 19:52:08 +01:00
|
|
|
unsigned char grip[20];
|
2004-08-24 19:55:47 +00:00
|
|
|
unsigned char keyid[8];
|
|
|
|
int fprlen; /* Either 16 or 20 */
|
|
|
|
unsigned char fpr[20];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _keybox_openpgp_uid_info
|
|
|
|
{
|
|
|
|
struct _keybox_openpgp_uid_info *next;
|
|
|
|
size_t off;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _keybox_openpgp_info
|
|
|
|
{
|
|
|
|
int is_secret; /* True if this is a secret key. */
|
|
|
|
unsigned int nsubkeys;/* Total number of subkeys. */
|
|
|
|
unsigned int nuids; /* Total number of user IDs in the keyblock. */
|
|
|
|
unsigned int nsigs; /* Total number of signatures in the keyblock. */
|
|
|
|
|
|
|
|
/* Note, we use 2 structs here to better cope with the most common
|
|
|
|
use of having one primary and one subkey - this allows us to
|
|
|
|
statically allocate this structure and only malloc stuff for more
|
|
|
|
than one subkey. */
|
|
|
|
struct _keybox_openpgp_key_info primary;
|
|
|
|
struct _keybox_openpgp_key_info subkeys;
|
|
|
|
struct _keybox_openpgp_uid_info uids;
|
|
|
|
};
|
|
|
|
typedef struct _keybox_openpgp_info *keybox_openpgp_info_t;
|
|
|
|
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
/* Don't know whether this is needed: */
|
|
|
|
/* static struct { */
|
|
|
|
/* int dry_run; */
|
|
|
|
/* int quiet; */
|
|
|
|
/* int verbose; */
|
|
|
|
/* int preserve_permissions; */
|
|
|
|
/* } keybox_opt; */
|
|
|
|
|
2008-04-01 15:08:57 +00:00
|
|
|
/*-- keybox-init.c --*/
|
|
|
|
void _keybox_close_file (KEYBOX_HANDLE hd);
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
/*-- keybox-blob.c --*/
|
2012-12-28 14:03:16 +01:00
|
|
|
gpg_error_t _keybox_create_openpgp_blob (KEYBOXBLOB *r_blob,
|
|
|
|
keybox_openpgp_info_t info,
|
|
|
|
const unsigned char *image,
|
|
|
|
size_t imagelen,
|
|
|
|
int as_ephemeral);
|
2003-06-05 07:14:21 +00:00
|
|
|
#ifdef KEYBOX_WITH_X509
|
2003-12-17 12:27:21 +00:00
|
|
|
int _keybox_create_x509_blob (KEYBOXBLOB *r_blob, ksba_cert_t cert,
|
2003-06-05 07:14:21 +00:00
|
|
|
unsigned char *sha1_digest, int as_ephemeral);
|
|
|
|
#endif /*KEYBOX_WITH_X509*/
|
|
|
|
|
2005-06-16 08:12:03 +00:00
|
|
|
int _keybox_new_blob (KEYBOXBLOB *r_blob,
|
|
|
|
unsigned char *image, size_t imagelen,
|
2003-06-05 07:14:21 +00:00
|
|
|
off_t off);
|
|
|
|
void _keybox_release_blob (KEYBOXBLOB blob);
|
2005-06-16 08:12:03 +00:00
|
|
|
const unsigned char *_keybox_get_blob_image (KEYBOXBLOB blob, size_t *n);
|
2003-06-05 07:14:21 +00:00
|
|
|
off_t _keybox_get_blob_fileoffset (KEYBOXBLOB blob);
|
2014-10-09 19:10:32 +02:00
|
|
|
void _keybox_update_header_blob (KEYBOXBLOB blob, int for_openpgp);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
2004-08-24 19:55:47 +00:00
|
|
|
/*-- keybox-openpgp.c --*/
|
|
|
|
gpg_error_t _keybox_parse_openpgp (const unsigned char *image, size_t imagelen,
|
|
|
|
size_t *nparsed,
|
|
|
|
keybox_openpgp_info_t info);
|
|
|
|
void _keybox_destroy_openpgp_info (keybox_openpgp_info_t info);
|
|
|
|
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
/*-- keybox-file.c --*/
|
2017-04-01 11:10:47 +02:00
|
|
|
int _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted);
|
2003-06-05 07:14:21 +00:00
|
|
|
int _keybox_write_blob (KEYBOXBLOB blob, FILE *fp);
|
|
|
|
|
2004-02-02 17:09:35 +00:00
|
|
|
/*-- keybox-search.c --*/
|
|
|
|
gpg_err_code_t _keybox_get_flag_location (const unsigned char *buffer,
|
|
|
|
size_t length,
|
|
|
|
int what,
|
|
|
|
size_t *flag_off, size_t *flag_size);
|
|
|
|
|
2013-11-15 15:54:31 +01:00
|
|
|
static inline int
|
|
|
|
blob_get_type (KEYBOXBLOB blob)
|
|
|
|
{
|
|
|
|
const unsigned char *buffer;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
buffer = _keybox_get_blob_image (blob, &length);
|
|
|
|
if (length < 32)
|
|
|
|
return -1; /* blob too short */
|
|
|
|
|
|
|
|
return buffer[4];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
/*-- keybox-dump.c --*/
|
|
|
|
int _keybox_dump_blob (KEYBOXBLOB blob, FILE *fp);
|
2004-06-18 09:53:56 +00:00
|
|
|
int _keybox_dump_file (const char *filename, int stats_only, FILE *outfp);
|
2007-08-23 17:41:22 +00:00
|
|
|
int _keybox_dump_find_dups (const char *filename, int print_them, FILE *outfp);
|
|
|
|
int _keybox_dump_cut_records (const char *filename, unsigned long from,
|
|
|
|
unsigned long to, FILE *outfp);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-- keybox-util.c --*/
|
|
|
|
|
|
|
|
/*
|
2017-12-22 12:55:32 +01:00
|
|
|
* A couple of handy macros
|
|
|
|
*/
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif /*KEYBOX_DEFS_H*/
|