2013-11-15 15:54:31 +01:00
|
|
|
/* keybox-defs.h - internal Keybox definitions
|
2004-04-20 16:16:55 +02:00
|
|
|
* Copyright (C) 2001, 2004 Free Software Foundation, Inc.
|
2003-06-05 09:14:21 +02: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 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 09:14:21 +02: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 09:14:21 +02: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 09:14:21 +02:00
|
|
|
#endif
|
|
|
|
#include <gpg-error.h>
|
2004-12-18 11:22:10 +01:00
|
|
|
#define map_assuan_err(a) \
|
|
|
|
map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
|
|
|
|
|
2003-11-12 16:17:44 +01:00
|
|
|
#include <sys/types.h> /* off_t */
|
|
|
|
|
2017-12-22 12:55:32 +01:00
|
|
|
#include "../common/util.h"
|
2004-04-20 16:16:55 +02:00
|
|
|
#include "keybox.h"
|
2003-06-05 09:14:21 +02: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 17:08:57 +02: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 09:14:21 +02:00
|
|
|
int secret;
|
2008-04-01 17:08:57 +02: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 17:08:57 +02:00
|
|
|
/* Not yet used. */
|
2003-06-05 09:14:21 +02:00
|
|
|
int is_locked;
|
2008-04-01 17:08:57 +02:00
|
|
|
|
|
|
|
/* Not yet used. */
|
2003-06-05 09:14:21 +02:00
|
|
|
int did_full_scan;
|
2008-04-01 17:08:57 +02:00
|
|
|
|
|
|
|
/* The name of the resource file. */
|
2003-06-05 09:14:21 +02: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 09:14:21 +02:00
|
|
|
|
|
|
|
struct keybox_handle {
|
2016-01-13 10:16:27 +01:00
|
|
|
KB_NAME kb;
|
2003-06-05 09:14:21 +02:00
|
|
|
int secret; /* this is for a secret keybox */
|
2020-10-20 11:52:16 +02:00
|
|
|
estream_t fp;
|
2003-06-05 09:14:21 +02:00
|
|
|
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 09:14:21 +02:00
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
char *pattern;
|
|
|
|
} word_match;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-29 19:52:08 +01:00
|
|
|
/* OpenPGP helper structures. */
|
2004-08-24 21:55:47 +02:00
|
|
|
struct _keybox_openpgp_key_info
|
|
|
|
{
|
|
|
|
struct _keybox_openpgp_key_info *next;
|
2012-12-28 13:45:41 +01:00
|
|
|
int algo;
|
2019-03-14 08:54:59 +01:00
|
|
|
int version;
|
2019-01-29 19:52:08 +01:00
|
|
|
unsigned char grip[20];
|
2004-08-24 21:55:47 +02:00
|
|
|
unsigned char keyid[8];
|
2019-03-14 08:54:59 +01:00
|
|
|
int fprlen; /* Either 16, 20 or 32 */
|
|
|
|
unsigned char fpr[32];
|
2004-08-24 21:55:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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 09:14:21 +02: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 17:08:57 +02:00
|
|
|
/*-- keybox-init.c --*/
|
|
|
|
void _keybox_close_file (KEYBOX_HANDLE hd);
|
|
|
|
|
2003-06-05 09:14:21 +02: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);
|
2020-09-10 12:50:45 +02:00
|
|
|
char *_keybox_x509_email_kludge (const char *name);
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
#ifdef KEYBOX_WITH_X509
|
2003-12-17 13:27:21 +01:00
|
|
|
int _keybox_create_x509_blob (KEYBOXBLOB *r_blob, ksba_cert_t cert,
|
2003-06-05 09:14:21 +02:00
|
|
|
unsigned char *sha1_digest, int as_ephemeral);
|
|
|
|
#endif /*KEYBOX_WITH_X509*/
|
|
|
|
|
2005-06-16 10:12:03 +02:00
|
|
|
int _keybox_new_blob (KEYBOXBLOB *r_blob,
|
|
|
|
unsigned char *image, size_t imagelen,
|
2003-06-05 09:14:21 +02:00
|
|
|
off_t off);
|
|
|
|
void _keybox_release_blob (KEYBOXBLOB blob);
|
2005-06-16 10:12:03 +02:00
|
|
|
const unsigned char *_keybox_get_blob_image (KEYBOXBLOB blob, size_t *n);
|
2003-06-05 09:14:21 +02: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 09:14:21 +02:00
|
|
|
|
2004-08-24 21:55:47 +02: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 09:14:21 +02:00
|
|
|
/*-- keybox-file.c --*/
|
2020-10-20 11:52:16 +02:00
|
|
|
int _keybox_read_blob (KEYBOXBLOB *r_blob, estream_t fp, int *skipped_deleted);
|
|
|
|
int _keybox_write_blob (KEYBOXBLOB blob, estream_t fp, FILE *outfp);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2004-02-02 18:09:35 +01: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 09:14:21 +02:00
|
|
|
/*-- keybox-dump.c --*/
|
|
|
|
int _keybox_dump_blob (KEYBOXBLOB blob, FILE *fp);
|
2004-06-18 11:53:56 +02:00
|
|
|
int _keybox_dump_file (const char *filename, int stats_only, FILE *outfp);
|
2007-08-23 19:41:22 +02: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 09:14:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*-- keybox-util.c --*/
|
|
|
|
|
|
|
|
/*
|
2017-12-22 12:55:32 +01:00
|
|
|
* A couple of handy macros
|
|
|
|
*/
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif /*KEYBOX_DEFS_H*/
|