2002-06-29 13:46:34 +00:00
|
|
|
/* packet.h - packet definitions
|
2004-01-22 01:08:58 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
|
|
|
|
* 2004 Free Software Foundation, Inc.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* This file is part of GnuPG.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1997-11-18 14:06:00 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1997-11-18 14:06:00 +00:00
|
|
|
* 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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
#ifndef G10_PACKET_H
|
|
|
|
#define G10_PACKET_H
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "iobuf.h"
|
2002-06-29 13:46:34 +00:00
|
|
|
#include "mpi.h"
|
|
|
|
#include "cipher.h"
|
1997-11-18 14:06:00 +00:00
|
|
|
#include "filter.h"
|
2002-06-29 13:46:34 +00:00
|
|
|
#include "global.h"
|
1999-11-13 16:43:23 +00:00
|
|
|
|
1998-12-23 12:41:40 +00:00
|
|
|
#define DEBUG_PARSE_PACKET 1
|
|
|
|
|
1997-12-01 10:33:23 +00:00
|
|
|
typedef enum {
|
|
|
|
PKT_NONE =0,
|
|
|
|
PKT_PUBKEY_ENC =1, /* public key encrypted packet */
|
|
|
|
PKT_SIGNATURE =2, /* secret key encrypted packet */
|
1998-05-03 15:42:08 +00:00
|
|
|
PKT_SYMKEY_ENC =3, /* session key packet (OpenPGP)*/
|
1997-12-01 10:33:23 +00:00
|
|
|
PKT_ONEPASS_SIG =4, /* one pass sig packet (OpenPGP)*/
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_SECRET_KEY =5, /* secret key */
|
|
|
|
PKT_PUBLIC_KEY =6, /* public key */
|
|
|
|
PKT_SECRET_SUBKEY =7, /* secret subkey (OpenPGP) */
|
1997-12-01 10:33:23 +00:00
|
|
|
PKT_COMPRESSED =8, /* compressed data packet */
|
|
|
|
PKT_ENCRYPTED =9, /* conventional encrypted data */
|
|
|
|
PKT_MARKER =10, /* marker packet (OpenPGP) */
|
|
|
|
PKT_PLAINTEXT =11, /* plaintext data with filename and mode */
|
|
|
|
PKT_RING_TRUST =12, /* keyring trust packet */
|
|
|
|
PKT_USER_ID =13, /* user id packet */
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_PUBLIC_SUBKEY =14, /* public subkey (OpenPGP) */
|
1998-05-03 19:35:33 +00:00
|
|
|
PKT_OLD_COMMENT =16, /* comment packet from an OpenPGP draft */
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_ATTRIBUTE =17, /* PGP's attribute packet */
|
2000-07-14 17:34:53 +00:00
|
|
|
PKT_ENCRYPTED_MDC =18, /* integrity protected encrypted data */
|
2003-01-06 22:56:08 +00:00
|
|
|
PKT_MDC =19, /* manipulation detection code packet */
|
1999-05-17 20:03:24 +00:00
|
|
|
PKT_COMMENT =61, /* new comment packet (private) */
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_GPG_CONTROL =63 /* internal control packet */
|
1997-12-01 10:33:23 +00:00
|
|
|
} pkttype_t;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
typedef struct packet_struct PACKET;
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
/* PKT_GPG_CONTROL types */
|
|
|
|
typedef enum {
|
|
|
|
CTRLPKT_CLEARSIGN_START = 1,
|
|
|
|
CTRLPKT_PIPEMODE = 2,
|
|
|
|
CTRLPKT_PLAINTEXT_MARK =3
|
|
|
|
} ctrlpkttype_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PREFTYPE_NONE = 0,
|
|
|
|
PREFTYPE_SYM = 1,
|
|
|
|
PREFTYPE_HASH = 2,
|
|
|
|
PREFTYPE_ZIP = 3
|
|
|
|
} preftype_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
byte type;
|
|
|
|
byte value;
|
|
|
|
} prefitem_t;
|
|
|
|
|
1998-05-03 15:42:08 +00:00
|
|
|
typedef struct {
|
2000-07-14 17:34:53 +00:00
|
|
|
int mode;
|
1998-05-03 15:42:08 +00:00
|
|
|
byte hash_algo;
|
|
|
|
byte salt[8];
|
|
|
|
u32 count;
|
|
|
|
} STRING2KEY;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
byte version;
|
|
|
|
byte cipher_algo; /* cipher algorithm used */
|
|
|
|
STRING2KEY s2k;
|
|
|
|
byte seskeylen; /* keylength in byte or 0 for no seskey */
|
|
|
|
byte seskey[1];
|
|
|
|
} PKT_symkey_enc;
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
typedef struct {
|
|
|
|
u32 keyid[2]; /* 64 bit keyid */
|
1998-03-19 15:27:29 +00:00
|
|
|
byte version;
|
1997-11-18 14:06:00 +00:00
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
1998-09-11 05:47:32 +00:00
|
|
|
byte throw_keyid;
|
2002-06-29 13:46:34 +00:00
|
|
|
MPI data[PUBKEY_MAX_NENC];
|
1997-11-18 14:06:00 +00:00
|
|
|
} PKT_pubkey_enc;
|
|
|
|
|
|
|
|
|
1997-12-02 19:36:53 +00:00
|
|
|
typedef struct {
|
|
|
|
u32 keyid[2]; /* 64 bit keyid */
|
|
|
|
byte sig_class; /* sig classification */
|
|
|
|
byte digest_algo; /* algorithm used for digest */
|
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
|
|
|
byte last; /* a stupid flag */
|
|
|
|
} PKT_onepass_sig;
|
|
|
|
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
typedef struct {
|
|
|
|
size_t size; /* allocated */
|
|
|
|
size_t len; /* used */
|
|
|
|
byte data[1];
|
|
|
|
} subpktarea_t;
|
|
|
|
|
|
|
|
struct revocation_key {
|
|
|
|
byte class;
|
|
|
|
byte algid;
|
|
|
|
byte fpr[MAX_FINGERPRINT_LEN];
|
|
|
|
};
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
typedef struct {
|
1998-10-01 07:23:00 +00:00
|
|
|
struct {
|
|
|
|
unsigned checked:1; /* signature has been checked */
|
|
|
|
unsigned valid:1; /* signature is good (if checked is set) */
|
2004-04-15 00:30:05 +00:00
|
|
|
unsigned chosen_selfsig:1; /* a selfsig that is the chosen one */
|
1998-10-01 07:23:00 +00:00
|
|
|
unsigned unknown_critical:1;
|
2002-06-29 13:46:34 +00:00
|
|
|
unsigned exportable:1;
|
|
|
|
unsigned revocable:1;
|
2003-08-26 03:56:47 +00:00
|
|
|
unsigned policy_url:1; /* At least one policy URL is present */
|
2002-06-29 13:46:34 +00:00
|
|
|
unsigned notation:1; /* At least one notation is present */
|
2003-08-26 03:56:47 +00:00
|
|
|
unsigned pref_ks:1; /* At least one preferred keyserver is present */
|
2002-06-29 13:46:34 +00:00
|
|
|
unsigned expired:1;
|
1998-10-01 07:23:00 +00:00
|
|
|
} flags;
|
|
|
|
u32 keyid[2]; /* 64 bit keyid */
|
1997-11-18 14:06:00 +00:00
|
|
|
u32 timestamp; /* signature made */
|
2002-06-29 13:46:34 +00:00
|
|
|
u32 expiredate; /* expires at this date or 0 if not at all */
|
1998-03-09 21:44:06 +00:00
|
|
|
byte version;
|
1997-11-18 14:06:00 +00:00
|
|
|
byte sig_class; /* sig classification, append for MD calculation*/
|
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
2002-06-29 13:46:34 +00:00
|
|
|
/* (PUBKEY_ALGO_xxx) */
|
|
|
|
byte digest_algo; /* algorithm used for digest (DIGEST_ALGO_xxxx) */
|
* keyedit.c (print_and_check_one_sig, show_key_and_fingerprint,
menu_addrevoker), keylist.c (list_keyblock_print, print_fingerprint): Show
"T" or the trust depth for trust signatures, and add spaces to some
strings to make room for it.
* packet.h, parse-packet.c (dump_sig_subpkt, parse_one_sig_subpkt,
parse_signature): Parse trust signature values.
* tdbio.h, tdbio.c (tdbio_read_record, tdbio_write_record): Reserve a byte
for the minimum ownertrust value (for use with trust signatures).
2002-10-29 18:00:07 +00:00
|
|
|
byte trust_depth;
|
|
|
|
byte trust_value;
|
|
|
|
const byte *trust_regexp;
|
2002-06-29 13:46:34 +00:00
|
|
|
struct revocation_key **revkey;
|
|
|
|
int numrevkeys;
|
|
|
|
subpktarea_t *hashed; /* all subpackets with hashed data (v4 only) */
|
|
|
|
subpktarea_t *unhashed; /* ditto for unhashed data */
|
1998-03-09 21:44:06 +00:00
|
|
|
byte digest_start[2]; /* first 2 bytes of the digest */
|
2002-06-29 13:46:34 +00:00
|
|
|
MPI data[PUBKEY_MAX_NSIG];
|
1997-11-18 14:06:00 +00:00
|
|
|
} PKT_signature;
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
#define ATTRIB_IMAGE 1
|
|
|
|
|
|
|
|
/* This is the cooked form of attributes */
|
|
|
|
struct user_attribute {
|
|
|
|
byte type;
|
|
|
|
const byte *data;
|
2002-07-01 16:40:52 +00:00
|
|
|
u32 len;
|
2002-06-29 13:46:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int ref; /* reference counter */
|
|
|
|
int len; /* length of the name */
|
|
|
|
struct user_attribute *attribs;
|
|
|
|
int numattribs;
|
|
|
|
byte *attrib_data; /* if this is not NULL, the packet is an attribute */
|
|
|
|
unsigned long attrib_len;
|
2003-01-14 18:13:22 +00:00
|
|
|
byte *namehash;
|
2002-06-29 13:46:34 +00:00
|
|
|
int help_key_usage;
|
|
|
|
u32 help_key_expire;
|
2003-01-06 22:56:08 +00:00
|
|
|
int help_full_count;
|
|
|
|
int help_marginal_count;
|
2003-05-31 04:06:06 +00:00
|
|
|
int is_primary; /* 2 if set via the primary flag, 1 if calculated */
|
2002-06-29 13:46:34 +00:00
|
|
|
int is_revoked;
|
|
|
|
int is_expired;
|
|
|
|
u32 expiredate; /* expires at this date or 0 if not at all */
|
|
|
|
prefitem_t *prefs; /* list of preferences (may be NULL)*/
|
|
|
|
int mdc_feature;
|
2003-02-22 23:58:39 +00:00
|
|
|
int ks_modify;
|
2002-06-29 13:46:34 +00:00
|
|
|
u32 created; /* according to the self-signature */
|
|
|
|
byte selfsigversion;
|
|
|
|
char name[1];
|
|
|
|
} PKT_user_id;
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1998-06-13 06:59:14 +00:00
|
|
|
/****************
|
|
|
|
* Note about the pkey/skey elements: We assume that the secret keys
|
|
|
|
* has the same elemts as the public key at the begin of the array, so
|
|
|
|
* that npkey < nskey and it is possible to compare the secret and
|
|
|
|
* public keys by comparing the first npkey elements of pkey againts skey.
|
|
|
|
*/
|
1997-11-18 14:06:00 +00:00
|
|
|
typedef struct {
|
1998-06-29 12:30:57 +00:00
|
|
|
u32 timestamp; /* key made */
|
1998-10-16 16:00:17 +00:00
|
|
|
u32 expiredate; /* expires at this date or 0 if not at all */
|
2002-06-29 13:46:34 +00:00
|
|
|
u32 max_expiredate; /* must not expire past this date */
|
2004-02-11 04:32:52 +00:00
|
|
|
u32 revokedate; /* revoked at this date */
|
1998-01-16 21:15:24 +00:00
|
|
|
byte hdrbytes; /* number of header bytes */
|
|
|
|
byte version;
|
2002-06-29 13:46:34 +00:00
|
|
|
byte selfsigversion; /* highest version of all of the self-sigs */
|
1997-11-18 14:06:00 +00:00
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
2002-06-29 13:46:34 +00:00
|
|
|
byte pubkey_usage; /* for now only used to pass it to getkey() */
|
2000-09-18 14:35:34 +00:00
|
|
|
byte req_usage; /* hack to pass a request to getkey() */
|
|
|
|
byte req_algo; /* Ditto */
|
|
|
|
u32 has_expired; /* set to the expiration date if expired */
|
2004-01-22 01:08:58 +00:00
|
|
|
int is_revoked; /* key has been revoked, 1 if by the
|
|
|
|
owner, 2 if by a designated revoker */
|
2003-12-30 00:46:42 +00:00
|
|
|
int maybe_revoked; /* a designated revocation is present, but
|
|
|
|
without the key to check it */
|
2000-09-18 14:35:34 +00:00
|
|
|
int is_valid; /* key (especially subkey) is valid */
|
2002-06-29 13:46:34 +00:00
|
|
|
int dont_cache; /* do not cache this */
|
2004-04-23 03:25:58 +00:00
|
|
|
byte backsig; /* 0=none, 1=bad, 2=good */
|
2000-09-18 14:35:34 +00:00
|
|
|
u32 main_keyid[2]; /* keyid of the primary key */
|
1998-07-09 13:37:17 +00:00
|
|
|
u32 keyid[2]; /* calculated by keyid_from_pk() */
|
2002-10-03 19:20:37 +00:00
|
|
|
byte is_primary;
|
* trustdb.h, trustdb.c (is_disabled), gpgv.c (is_disabled): Rename
is_disabled to cache_disabled_value, which now takes a pk and not just the
keyid. This is for speed since there is no need to re-fetch a key when we
already have that key handy. Cache the result of the check so we don't
need to hit the trustdb more than once.
* getkey.c (skip_disabled): New function to get a pk and call is_disabled
on it. (key_byname): Use it here.
* packet.h, getkey.c (skip_disabled), keylist.c (print_capabilities): New
"pk_is_disabled" macro to retrieve the cached disabled value if available,
and fill it in via cache_disabled_value if not available.
* trustdb.c (get_validity): Cache the disabled value since we have it
handy and it might be useful later.
* parse-packet.c (parse_key): Clear disabled flag when parsing a new key.
Just in case someone forgets to clear the whole key.
* getkey.c (merge_selfsigs_main): Add an "if all else fails" path for
setting a single user ID primary when there are multiple set primaries all
at the same second, or no primaries set and the most recent user IDs are
at the same second, or no signed user IDs at all. This is arbitrary, but
deterministic.
* exec.h, photoid.h: Add copyright message.
* keylist.c (list_keyblock_print): Don't dump attribs for
revoked/expired/etc uids for non-colon key listings. This is for
consistency with --show-photos.
* main.h, keylist.c (dump_attribs), mainproc.c (check_sig_and_print): Dump
attribs if --attrib-fd is set when verifying signatures.
* g10.c (main): New --gnupg option to disable the various --openpgp,
--pgpX, etc. options. This is the same as --no-XXXX for those options.
* revoke.c (ask_revocation_reason): Clear old reason if user elects to
repeat question. This is bug 153.
* keyedit.c (sign_uids): Show keyid of the key making the signature.
2003-05-21 16:42:22 +00:00
|
|
|
byte is_disabled; /* 0 for unset, 1 for enabled, 2 for disabled. */
|
2002-06-29 13:46:34 +00:00
|
|
|
prefitem_t *prefs; /* list of preferences (may be NULL) */
|
|
|
|
int mdc_feature; /* mdc feature set */
|
|
|
|
PKT_user_id *user_id; /* if != NULL: found by that uid */
|
|
|
|
struct revocation_key *revkey;
|
|
|
|
int numrevkeys;
|
2002-10-30 03:11:57 +00:00
|
|
|
u32 trust_timestamp;
|
|
|
|
byte trust_depth;
|
|
|
|
byte trust_value;
|
|
|
|
const byte *trust_regexp;
|
2002-06-29 13:46:34 +00:00
|
|
|
MPI pkey[PUBKEY_MAX_NPKEY];
|
1998-06-29 12:30:57 +00:00
|
|
|
} PKT_public_key;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
* trustdb.h, trustdb.c (is_disabled), gpgv.c (is_disabled): Rename
is_disabled to cache_disabled_value, which now takes a pk and not just the
keyid. This is for speed since there is no need to re-fetch a key when we
already have that key handy. Cache the result of the check so we don't
need to hit the trustdb more than once.
* getkey.c (skip_disabled): New function to get a pk and call is_disabled
on it. (key_byname): Use it here.
* packet.h, getkey.c (skip_disabled), keylist.c (print_capabilities): New
"pk_is_disabled" macro to retrieve the cached disabled value if available,
and fill it in via cache_disabled_value if not available.
* trustdb.c (get_validity): Cache the disabled value since we have it
handy and it might be useful later.
* parse-packet.c (parse_key): Clear disabled flag when parsing a new key.
Just in case someone forgets to clear the whole key.
* getkey.c (merge_selfsigs_main): Add an "if all else fails" path for
setting a single user ID primary when there are multiple set primaries all
at the same second, or no primaries set and the most recent user IDs are
at the same second, or no signed user IDs at all. This is arbitrary, but
deterministic.
* exec.h, photoid.h: Add copyright message.
* keylist.c (list_keyblock_print): Don't dump attribs for
revoked/expired/etc uids for non-colon key listings. This is for
consistency with --show-photos.
* main.h, keylist.c (dump_attribs), mainproc.c (check_sig_and_print): Dump
attribs if --attrib-fd is set when verifying signatures.
* g10.c (main): New --gnupg option to disable the various --openpgp,
--pgpX, etc. options. This is the same as --no-XXXX for those options.
* revoke.c (ask_revocation_reason): Clear old reason if user elects to
repeat question. This is bug 153.
* keyedit.c (sign_uids): Show keyid of the key making the signature.
2003-05-21 16:42:22 +00:00
|
|
|
/* Evaluates as true if the pk is disabled, and false if it isn't. If
|
|
|
|
there is no disable value cached, fill one in. */
|
|
|
|
#define pk_is_disabled(a) (((a)->is_disabled)?((a)->is_disabled==2):(cache_disabled_value((a))))
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
typedef struct {
|
1998-06-29 12:30:57 +00:00
|
|
|
u32 timestamp; /* key made */
|
1998-10-16 16:00:17 +00:00
|
|
|
u32 expiredate; /* expires at this date or 0 if not at all */
|
2002-06-29 13:46:34 +00:00
|
|
|
u32 max_expiredate; /* must not expire past this date */
|
1998-01-16 21:15:24 +00:00
|
|
|
byte hdrbytes; /* number of header bytes */
|
|
|
|
byte version;
|
1997-11-18 14:06:00 +00:00
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
1998-07-06 10:23:57 +00:00
|
|
|
byte pubkey_usage;
|
2000-09-18 14:35:34 +00:00
|
|
|
byte req_usage;
|
|
|
|
byte req_algo;
|
|
|
|
u32 has_expired; /* set to the expiration date if expired */
|
|
|
|
int is_revoked; /* key has been revoked */
|
|
|
|
int is_valid; /* key (especially subkey) is valid */
|
|
|
|
u32 main_keyid[2]; /* keyid of the primary key */
|
|
|
|
u32 keyid[2];
|
1999-01-07 17:05:48 +00:00
|
|
|
byte is_primary;
|
1998-04-14 17:51:16 +00:00
|
|
|
byte is_protected; /* The secret info is protected and must */
|
|
|
|
/* be decrypted before use, the protected */
|
1998-04-02 10:30:03 +00:00
|
|
|
/* MPIs are simply (void*) pointers to memory */
|
|
|
|
/* and should never be passed to a mpi_xxx() */
|
|
|
|
struct {
|
1998-04-14 17:51:16 +00:00
|
|
|
byte algo; /* cipher used to protect the secret information*/
|
2002-06-29 13:46:34 +00:00
|
|
|
byte sha1chk; /* SHA1 is used instead of a 16 bit checksum */
|
1998-05-03 15:42:08 +00:00
|
|
|
STRING2KEY s2k;
|
1999-04-18 08:18:52 +00:00
|
|
|
byte ivlen; /* used length of the iv */
|
|
|
|
byte iv[16]; /* initialization vector for CFB mode */
|
1998-04-02 10:30:03 +00:00
|
|
|
} protect;
|
2002-06-29 13:46:34 +00:00
|
|
|
MPI skey[PUBKEY_MAX_NSKEY];
|
1998-04-02 10:30:03 +00:00
|
|
|
u16 csum; /* checksum */
|
1998-06-29 12:30:57 +00:00
|
|
|
} PKT_secret_key;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int len; /* length of data */
|
|
|
|
char data[1];
|
|
|
|
} PKT_comment;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 len; /* reserved */
|
1998-07-02 19:31:46 +00:00
|
|
|
byte new_ctb;
|
1997-11-18 14:06:00 +00:00
|
|
|
byte algorithm;
|
|
|
|
IOBUF buf; /* IOBUF reference */
|
|
|
|
} PKT_compressed;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 len; /* length of encrypted data */
|
2002-06-29 13:46:34 +00:00
|
|
|
int extralen; /* this is (blocksize+2) */
|
1999-05-17 20:03:24 +00:00
|
|
|
byte new_ctb; /* uses a new CTB */
|
2004-03-03 00:09:16 +00:00
|
|
|
byte is_partial; /* partial length encoded */
|
2000-07-14 17:34:53 +00:00
|
|
|
byte mdc_method; /* > 0: integrity protected encrypted data packet */
|
1997-11-18 14:06:00 +00:00
|
|
|
IOBUF buf; /* IOBUF reference */
|
1997-12-01 10:33:23 +00:00
|
|
|
} PKT_encrypted;
|
1997-11-18 14:06:00 +00:00
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
typedef struct {
|
|
|
|
byte hash[20];
|
|
|
|
} PKT_mdc;
|
|
|
|
|
1999-07-08 14:24:35 +00:00
|
|
|
typedef struct {
|
|
|
|
unsigned int trustval;
|
2002-06-29 13:46:34 +00:00
|
|
|
unsigned int sigcache;
|
1999-07-08 14:24:35 +00:00
|
|
|
} PKT_ring_trust;
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
typedef struct {
|
|
|
|
u32 len; /* length of encrypted data */
|
|
|
|
IOBUF buf; /* IOBUF reference */
|
1998-07-02 19:31:46 +00:00
|
|
|
byte new_ctb;
|
2002-06-29 13:46:34 +00:00
|
|
|
byte is_partial; /* partial length encoded */
|
1997-11-18 14:06:00 +00:00
|
|
|
int mode;
|
|
|
|
u32 timestamp;
|
|
|
|
int namelen;
|
|
|
|
char name[1];
|
|
|
|
} PKT_plaintext;
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
typedef struct {
|
|
|
|
int control;
|
|
|
|
size_t datalen;
|
|
|
|
char data[1];
|
|
|
|
} PKT_gpg_control;
|
1999-05-17 20:03:24 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/* combine all packets into a union */
|
|
|
|
struct packet_struct {
|
1997-12-01 10:33:23 +00:00
|
|
|
pkttype_t pkttype;
|
1997-11-18 14:06:00 +00:00
|
|
|
union {
|
|
|
|
void *generic;
|
1998-05-03 15:42:08 +00:00
|
|
|
PKT_symkey_enc *symkey_enc; /* PKT_SYMKEY_ENC */
|
1997-12-01 10:33:23 +00:00
|
|
|
PKT_pubkey_enc *pubkey_enc; /* PKT_PUBKEY_ENC */
|
1997-12-02 19:36:53 +00:00
|
|
|
PKT_onepass_sig *onepass_sig; /* PKT_ONEPASS_SIG */
|
1997-12-01 10:33:23 +00:00
|
|
|
PKT_signature *signature; /* PKT_SIGNATURE */
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_public_key *public_key; /* PKT_PUBLIC_[SUB)KEY */
|
|
|
|
PKT_secret_key *secret_key; /* PKT_SECRET_[SUB]KEY */
|
1997-11-18 14:06:00 +00:00
|
|
|
PKT_comment *comment; /* PKT_COMMENT */
|
|
|
|
PKT_user_id *user_id; /* PKT_USER_ID */
|
|
|
|
PKT_compressed *compressed; /* PKT_COMPRESSED */
|
1999-05-17 20:03:24 +00:00
|
|
|
PKT_encrypted *encrypted; /* PKT_ENCRYPTED[_MDC] */
|
2000-07-14 17:34:53 +00:00
|
|
|
PKT_mdc *mdc; /* PKT_MDC */
|
1999-07-08 14:24:35 +00:00
|
|
|
PKT_ring_trust *ring_trust; /* PKT_RING_TRUST */
|
1997-11-18 14:06:00 +00:00
|
|
|
PKT_plaintext *plaintext; /* PKT_PLAINTEXT */
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_gpg_control *gpg_control; /* PKT_GPG_CONTROL */
|
1997-11-18 14:06:00 +00:00
|
|
|
} pkt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define init_packet(a) do { (a)->pkttype = 0; \
|
|
|
|
(a)->pkt.generic = NULL; \
|
|
|
|
} while(0)
|
|
|
|
|
1998-05-13 17:53:36 +00:00
|
|
|
typedef enum {
|
1998-12-14 20:22:42 +00:00
|
|
|
SIGSUBPKT_TEST_CRITICAL=-3,
|
1998-05-13 17:53:36 +00:00
|
|
|
SIGSUBPKT_LIST_UNHASHED=-2,
|
|
|
|
SIGSUBPKT_LIST_HASHED =-1,
|
|
|
|
SIGSUBPKT_NONE = 0,
|
|
|
|
SIGSUBPKT_SIG_CREATED = 2, /* signature creation time */
|
|
|
|
SIGSUBPKT_SIG_EXPIRE = 3, /* signature expiration time */
|
|
|
|
SIGSUBPKT_EXPORTABLE = 4, /* exportable */
|
|
|
|
SIGSUBPKT_TRUST = 5, /* trust signature */
|
|
|
|
SIGSUBPKT_REGEXP = 6, /* regular expression */
|
|
|
|
SIGSUBPKT_REVOCABLE = 7, /* revocable */
|
|
|
|
SIGSUBPKT_KEY_EXPIRE = 9, /* key expiration time */
|
|
|
|
SIGSUBPKT_ARR =10, /* additional recipient request */
|
|
|
|
SIGSUBPKT_PREF_SYM =11, /* preferred symmetric algorithms */
|
|
|
|
SIGSUBPKT_REV_KEY =12, /* revocation key */
|
|
|
|
SIGSUBPKT_ISSUER =16, /* issuer key ID */
|
|
|
|
SIGSUBPKT_NOTATION =20, /* notation data */
|
|
|
|
SIGSUBPKT_PREF_HASH =21, /* preferred hash algorithms */
|
|
|
|
SIGSUBPKT_PREF_COMPR =22, /* preferred compression algorithms */
|
|
|
|
SIGSUBPKT_KS_FLAGS =23, /* key server preferences */
|
|
|
|
SIGSUBPKT_PREF_KS =24, /* preferred key server */
|
|
|
|
SIGSUBPKT_PRIMARY_UID =25, /* primary user id */
|
|
|
|
SIGSUBPKT_POLICY =26, /* policy URL */
|
|
|
|
SIGSUBPKT_KEY_FLAGS =27, /* key flags */
|
1998-06-09 15:14:06 +00:00
|
|
|
SIGSUBPKT_SIGNERS_UID =28, /* signer's user id */
|
2000-07-14 17:34:53 +00:00
|
|
|
SIGSUBPKT_REVOC_REASON =29, /* reason for revocation */
|
2000-10-11 17:26:49 +00:00
|
|
|
SIGSUBPKT_FEATURES =30, /* feature flags */
|
2004-04-23 03:25:58 +00:00
|
|
|
|
* keygen.c (gen_elg, gen_dsa, gen_rsa, do_create, do_generate_keypair,
generate_subkeypair): New is_subkey argument to set whether a generated
key is a subkey. Do not overload the ret_sk. This is some early cleanup
to do backsigs for signing subkeys.
* keygen.c (write_keybinding, do_generate_keypair, generate_subkeypair):
Keep track of the unprotected subkey secret key so we can make a backsig
with it.
* keygen.c (make_backsig): New function to add a backsig to a binding sig
of signing subkeys. Currently disabled. (write_keybinding): Call it here,
for signing subkeys only.
* sign.c (make_keysig_packet): Allow generating 0x19 signatures (same as
0x18 or 0x28, but used for backsigs).
* packet.h, build-packet.c (build_sig_subpkt): Add new SIGSUBPKT_SIGNATURE
type for embedded signatures.
2004-04-16 16:07:07 +00:00
|
|
|
SIGSUBPKT_SIGNATURE =32, /* embedded signature */
|
1999-05-26 12:41:46 +00:00
|
|
|
|
|
|
|
SIGSUBPKT_FLAG_CRITICAL=128
|
1998-05-13 17:53:36 +00:00
|
|
|
} sigsubpkttype_t;
|
|
|
|
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/*-- mainproc.c --*/
|
1999-04-26 15:53:01 +00:00
|
|
|
int proc_packets( void *ctx, IOBUF a );
|
|
|
|
int proc_signature_packets( void *ctx, IOBUF a,
|
|
|
|
STRLIST signedfiles, const char *sigfile );
|
|
|
|
int proc_encryption_packets( void *ctx, IOBUF a );
|
1998-01-02 20:40:10 +00:00
|
|
|
int list_packets( IOBUF a );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- parse-packet.c --*/
|
|
|
|
int set_packet_list_mode( int mode );
|
1998-12-23 12:41:40 +00:00
|
|
|
|
|
|
|
#if DEBUG_PARSE_PACKET
|
2002-06-29 13:46:34 +00:00
|
|
|
int dbg_search_packet( IOBUF inp, PACKET *pkt, off_t *retpos, int with_uid,
|
|
|
|
const char* file, int lineno );
|
|
|
|
int dbg_parse_packet( IOBUF inp, PACKET *ret_pkt,
|
2000-10-06 12:28:44 +00:00
|
|
|
const char* file, int lineno );
|
2002-06-29 13:46:34 +00:00
|
|
|
int dbg_copy_all_packets( IOBUF inp, IOBUF out,
|
|
|
|
const char* file, int lineno );
|
|
|
|
int dbg_copy_some_packets( IOBUF inp, IOBUF out, off_t stopoff,
|
|
|
|
const char* file, int lineno );
|
|
|
|
int dbg_skip_some_packets( IOBUF inp, unsigned n,
|
|
|
|
const char* file, int lineno );
|
|
|
|
#define search_packet( a,b,c,d ) \
|
|
|
|
dbg_search_packet( (a), (b), (c), (d), __FILE__, __LINE__ )
|
|
|
|
#define parse_packet( a, b ) \
|
|
|
|
dbg_parse_packet( (a), (b), __FILE__, __LINE__ )
|
|
|
|
#define copy_all_packets( a,b ) \
|
|
|
|
dbg_copy_all_packets((a),(b), __FILE__, __LINE__ )
|
|
|
|
#define copy_some_packets( a,b,c ) \
|
|
|
|
dbg_copy_some_packets((a),(b),(c), __FILE__, __LINE__ )
|
|
|
|
#define skip_some_packets( a,b ) \
|
|
|
|
dbg_skip_some_packets((a),(b), __FILE__, __LINE__ )
|
1998-12-23 12:41:40 +00:00
|
|
|
#else
|
2002-06-29 13:46:34 +00:00
|
|
|
int search_packet( IOBUF inp, PACKET *pkt, off_t *retpos, int with_uid );
|
|
|
|
int parse_packet( IOBUF inp, PACKET *ret_pkt);
|
1998-02-11 03:25:44 +00:00
|
|
|
int copy_all_packets( IOBUF inp, IOBUF out );
|
2002-06-29 13:46:34 +00:00
|
|
|
int copy_some_packets( IOBUF inp, IOBUF out, off_t stopoff );
|
1998-02-11 03:25:44 +00:00
|
|
|
int skip_some_packets( IOBUF inp, unsigned n );
|
1998-12-23 12:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-23 03:25:58 +00:00
|
|
|
int parse_signature( IOBUF inp, int pkttype, unsigned long pktlen,
|
|
|
|
PKT_signature *sig );
|
2002-06-29 13:46:34 +00:00
|
|
|
const byte *enum_sig_subpkt ( const subpktarea_t *subpkts,
|
|
|
|
sigsubpkttype_t reqtype,
|
|
|
|
size_t *ret_n, int *start, int *critical );
|
|
|
|
const byte *parse_sig_subpkt ( const subpktarea_t *buffer,
|
|
|
|
sigsubpkttype_t reqtype,
|
|
|
|
size_t *ret_n );
|
|
|
|
const byte *parse_sig_subpkt2 ( PKT_signature *sig,
|
|
|
|
sigsubpkttype_t reqtype,
|
|
|
|
size_t *ret_n );
|
|
|
|
int parse_one_sig_subpkt( const byte *buffer, size_t n, int type );
|
|
|
|
void parse_revkeys(PKT_signature *sig);
|
|
|
|
int parse_attribute_subpkts(PKT_user_id *uid);
|
2002-09-10 08:40:12 +00:00
|
|
|
void make_attribute_uidname(PKT_user_id *uid, size_t max_namelen);
|
2002-06-29 13:46:34 +00:00
|
|
|
PACKET *create_gpg_control ( ctrlpkttype_t type,
|
|
|
|
const byte *data,
|
|
|
|
size_t datalen );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- build-packet.c --*/
|
|
|
|
int build_packet( IOBUF inp, PACKET *pkt );
|
|
|
|
u32 calc_packet_length( PACKET *pkt );
|
1998-05-13 17:53:36 +00:00
|
|
|
void build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
|
|
|
|
const byte *buffer, size_t buflen );
|
|
|
|
void build_sig_subpkt_from_sig( PKT_signature *sig );
|
2002-06-29 13:46:34 +00:00
|
|
|
int delete_sig_subpkt(subpktarea_t *buffer, sigsubpkttype_t type );
|
|
|
|
void build_attribute_subpkt(PKT_user_id *uid,byte type,
|
2002-07-01 16:40:52 +00:00
|
|
|
const void *buf,u32 buflen,
|
|
|
|
const void *header,u32 headerlen);
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- free-packet.c --*/
|
1998-05-03 15:42:08 +00:00
|
|
|
void free_symkey_enc( PKT_symkey_enc *enc );
|
1997-11-18 14:06:00 +00:00
|
|
|
void free_pubkey_enc( PKT_pubkey_enc *enc );
|
|
|
|
void free_seckey_enc( PKT_signature *enc );
|
1998-01-30 16:23:16 +00:00
|
|
|
int digest_algo_from_sig( PKT_signature *sig );
|
1998-06-29 12:30:57 +00:00
|
|
|
void release_public_key_parts( PKT_public_key *pk );
|
|
|
|
void free_public_key( PKT_public_key *key );
|
|
|
|
void release_secret_key_parts( PKT_secret_key *sk );
|
|
|
|
void free_secret_key( PKT_secret_key *sk );
|
2002-06-29 13:46:34 +00:00
|
|
|
void free_attributes(PKT_user_id *uid);
|
1997-11-18 14:06:00 +00:00
|
|
|
void free_user_id( PKT_user_id *uid );
|
|
|
|
void free_comment( PKT_comment *rem );
|
|
|
|
void free_packet( PACKET *pkt );
|
2002-06-29 13:46:34 +00:00
|
|
|
prefitem_t *copy_prefs (const prefitem_t *prefs);
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_public_key *copy_public_key( PKT_public_key *d, PKT_public_key *s );
|
2002-06-29 13:46:34 +00:00
|
|
|
void copy_public_parts_to_secret_key( PKT_public_key *pk, PKT_secret_key *sk );
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_secret_key *copy_secret_key( PKT_secret_key *d, PKT_secret_key *s );
|
1998-07-29 19:35:05 +00:00
|
|
|
PKT_signature *copy_signature( PKT_signature *d, PKT_signature *s );
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_user_id *scopy_user_id (PKT_user_id *sd );
|
1998-12-08 12:20:53 +00:00
|
|
|
int cmp_public_keys( PKT_public_key *a, PKT_public_key *b );
|
|
|
|
int cmp_secret_keys( PKT_secret_key *a, PKT_secret_key *b );
|
1998-10-18 15:21:22 +00:00
|
|
|
int cmp_signatures( PKT_signature *a, PKT_signature *b );
|
1998-06-29 12:30:57 +00:00
|
|
|
int cmp_public_secret_key( PKT_public_key *pk, PKT_secret_key *sk );
|
1998-02-17 20:48:52 +00:00
|
|
|
int cmp_user_ids( PKT_user_id *a, PKT_user_id *b );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-- sig-check.c --*/
|
2002-06-29 13:46:34 +00:00
|
|
|
int signature_check( PKT_signature *sig, MD_HANDLE digest );
|
2003-07-20 00:10:13 +00:00
|
|
|
int signature_check2( PKT_signature *sig, MD_HANDLE digest, u32 *r_expiredate,
|
2003-08-13 03:31:36 +00:00
|
|
|
int *r_expired, int *r_revoked, PKT_public_key *ret_pk );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- seckey-cert.c --*/
|
1998-06-29 12:30:57 +00:00
|
|
|
int is_secret_key_protected( PKT_secret_key *sk );
|
1998-09-11 05:47:32 +00:00
|
|
|
int check_secret_key( PKT_secret_key *sk, int retries );
|
1998-06-29 12:30:57 +00:00
|
|
|
int protect_secret_key( PKT_secret_key *sk, DEK *dek );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- pubkey-enc.c --*/
|
|
|
|
int get_session_key( PKT_pubkey_enc *k, DEK *dek );
|
2002-06-29 13:46:34 +00:00
|
|
|
int get_override_session_key( DEK *dek, const char *string );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1997-11-23 15:38:27 +00:00
|
|
|
/*-- compress.c --*/
|
1999-04-26 15:53:01 +00:00
|
|
|
int handle_compressed( void *ctx, PKT_compressed *cd,
|
1998-03-09 21:44:06 +00:00
|
|
|
int (*callback)(IOBUF, void *), void *passthru );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- encr-data.c --*/
|
1999-04-26 15:53:01 +00:00
|
|
|
int decrypt_data( void *ctx, PKT_encrypted *ed, DEK *dek );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- plaintext.c --*/
|
1998-07-08 09:29:43 +00:00
|
|
|
int handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|
|
|
int nooutput, int clearsig );
|
2002-06-29 13:46:34 +00:00
|
|
|
int ask_for_detached_datafile( MD_HANDLE md, MD_HANDLE md2,
|
1999-08-31 15:30:12 +00:00
|
|
|
const char *inname, int textmode );
|
1997-11-24 11:04:11 +00:00
|
|
|
|
|
|
|
/*-- comment.c --*/
|
|
|
|
int write_comment( IOBUF out, const char *s );
|
|
|
|
|
1997-12-09 12:46:23 +00:00
|
|
|
/*-- sign.c --*/
|
1998-06-29 12:30:57 +00:00
|
|
|
int make_keysig_packet( PKT_signature **ret_sig, PKT_public_key *pk,
|
|
|
|
PKT_user_id *uid, PKT_public_key *subpk,
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_secret_key *sk, int sigclass, int digest_algo,
|
|
|
|
int sigversion, u32 timestamp, u32 duration,
|
1998-06-25 10:19:08 +00:00
|
|
|
int (*mksubpkt)(PKT_signature *, void *),
|
|
|
|
void *opaque );
|
2002-06-29 13:46:34 +00:00
|
|
|
int update_keysig_packet( PKT_signature **ret_sig,
|
|
|
|
PKT_signature *orig_sig,
|
|
|
|
PKT_public_key *pk,
|
2002-12-04 18:50:10 +00:00
|
|
|
PKT_user_id *uid,
|
|
|
|
PKT_public_key *subpk,
|
2002-06-29 13:46:34 +00:00
|
|
|
PKT_secret_key *sk,
|
|
|
|
int (*mksubpkt)(PKT_signature *, void *),
|
|
|
|
void *opaque );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1998-07-29 19:35:05 +00:00
|
|
|
/*-- keygen.c --*/
|
|
|
|
PKT_user_id *generate_user_id(void);
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
#endif /*G10_PACKET_H*/
|