1 /* packet.h - OpenPGP packet definitions
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 * 2007 Free Software Foundation, Inc.
4 * Copyright (C) 2015 g10 Code GmbH
6 * This file is part of GnuPG.
8 * GnuPG is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuPG is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <https://www.gnu.org/licenses/>.
26 #include "../common/iobuf.h"
27 #include "../common/strlist.h"
30 #include "../common/openpgpdefs.h"
31 #include "../common/userids.h"
34 #define DEBUG_PARSE_PACKET 1
37 /* Constants to allocate static MPI arrays. */
38 #define PUBKEY_MAX_NPKEY 5
39 #define PUBKEY_MAX_NSKEY 7
40 #define PUBKEY_MAX_NSIG 2
41 #define PUBKEY_MAX_NENC 2
44 #define PUBKEY_USAGE_SIG GCRY_PK_USAGE_SIGN /* Good for signatures. */
45 #define PUBKEY_USAGE_ENC GCRY_PK_USAGE_ENCR /* Good for encryption. */
46 #define PUBKEY_USAGE_CERT GCRY_PK_USAGE_CERT /* Also good to certify keys.*/
47 #define PUBKEY_USAGE_AUTH GCRY_PK_USAGE_AUTH /* Good for authentication. */
48 #define PUBKEY_USAGE_UNKNOWN GCRY_PK_USAGE_UNKN /* Unknown usage flag. */
49 #define PUBKEY_USAGE_NONE 256 /* No usage given. */
50 #if (GCRY_PK_USAGE_SIGN | GCRY_PK_USAGE_ENCR | GCRY_PK_USAGE_CERT \
51 | GCRY_PK_USAGE_AUTH | GCRY_PK_USAGE_UNKN) >= 256
52 # error Please choose another value for PUBKEY_USAGE_NONE
56 #define is_RSA(a) ((a)==PUBKEY_ALGO_RSA || (a)==PUBKEY_ALGO_RSA_E \
57 || (a)==PUBKEY_ALGO_RSA_S )
58 #define is_ELGAMAL(a) ((a)==PUBKEY_ALGO_ELGAMAL_E)
59 #define is_DSA(a) ((a)==PUBKEY_ALGO_DSA)
61 /* A pointer to the packet object. */
62 typedef struct packet_struct PACKET;
64 /* PKT_GPG_CONTROL types */
66 CTRLPKT_CLEARSIGN_START = 1,
68 CTRLPKT_PLAINTEXT_MARK =3
83 /* A string-to-key specifier as defined in RFC 4880, Section 3.7. */
86 int mode; /* Must be an integer due to the GNU modes 1001 et al. */
89 /* The *coded* (i.e., the serialized version) iteration count. */
93 /* A symmetric-key encrypted session key packet as defined in RFC
94 4880, Section 5.3. All fields are serialized. */
96 /* RFC 4880: this must be 4. */
98 /* The cipher algorithm used to encrypt the session key. (This may
99 be different from the algorithm that is used to encrypt the SED
102 /* The string-to-key specifier. */
104 /* The length of SESKEY in bytes or 0 if this packet does not
105 encrypt a session key. (In the latter case, the results of the
106 S2K function on the password is the session key. See RFC 4880,
109 /* The session key as encrypted by the S2K specifier. */
113 /* A public-key encrypted session key packet as defined in RFC 4880,
114 Section 5.1. All fields are serialized. */
116 /* The 64-bit keyid. */
118 /* The packet's version. Currently, only version 3 is defined. */
120 /* The algorithm used for the public key encryption scheme. */
122 /* Whether to hide the key id. This value is not directly
125 /* The session key. */
126 gcry_mpi_t data[PUBKEY_MAX_NENC];
130 /* A one-pass signature packet as defined in RFC 4880, Section
131 5.4. All fields are serialized. */
133 u32 keyid[2]; /* The 64-bit keyid */
134 /* The signature's classification (RFC 4880, Section 5.2.1). */
136 byte digest_algo; /* algorithm used for digest */
137 byte pubkey_algo; /* algorithm used for public key scheme */
138 /* A message can be signed by multiple keys. In this case, there
139 are n one-pass signature packets before the message to sign and
140 n signatures packets after the message. It is conceivable that
141 someone wants to not only sign the message, but all of the
142 signatures. Now we need to distinguish between signing the
143 message and signing the message plus the surrounding
144 signatures. This is the point of this flag. If set, it means:
145 I sign all of the data starting at the next packet. */
150 /* A v4 OpenPGP signature has a hashed and unhashed area containing
151 co-called signature subpackets (RFC 4880, Section 5.2.3). These
152 areas are described by this data structure. Use enum_sig_subpkt to
155 size_t size; /* allocated */
156 size_t len; /* used (serialized) */
157 byte data[1]; /* the serialized subpackes (serialized) */
160 /* The in-memory representation of a designated revoker signature
161 subpacket (RFC 4880, Section 5.2.3.15). */
162 struct revocation_key {
163 /* A bit field. 0x80 must be set. 0x40 means this information is
164 sensitive (and should not be uploaded to a keyserver by
167 /* The public-key algorithm ID. */
169 /* The fingerprint of the authorized key. */
170 byte fpr[MAX_FINGERPRINT_LEN];
174 /* Object to keep information about a PKA DNS record. */
177 int valid; /* An actual PKA record exists for EMAIL. */
178 int checked; /* Set to true if the FPR has been checked against the
180 char *uri; /* Malloced string with the URI. NULL if the URI is
182 unsigned char fpr[20]; /* The fingerprint as stored in the PKA RR. */
183 char email[1];/* The email address from the notation data. */
187 /* A signature packet (RFC 4880, Section 5.2). Only a subset of these
188 fields are directly serialized (these are marked as such); the rest
189 are read from the subpackets, which are not synthesized when
190 serializing this data structure (i.e., when using build_packet()).
191 Instead, the subpackets must be created by hand. */
196 unsigned checked:1; /* Signature has been checked. */
197 unsigned valid:1; /* Signature is good (if checked is set). */
198 unsigned chosen_selfsig:1; /* A selfsig that is the chosen one. */
199 unsigned unknown_critical:1;
200 unsigned exportable:1;
201 unsigned revocable:1;
202 unsigned policy_url:1; /* At least one policy URL is present */
203 unsigned notation:1; /* At least one notation is present */
204 unsigned pref_ks:1; /* At least one preferred keyserver is present */
206 unsigned pka_tried:1; /* Set if we tried to retrieve the PKA record. */
208 /* The key that allegedly generated this signature. (Directly
209 serialized in v3 sigs; for v4 sigs, this must be explicitly added
210 as an issuer subpacket (5.2.3.5.) */
212 /* When the signature was made (seconds since the Epoch). (Directly
213 serialized in v3 sigs; for v4 sigs, this must be explicitly added
214 as a signature creation time subpacket (5.2.3.4).) */
216 u32 expiredate; /* Expires at this date or 0 if not at all. */
217 /* The serialization format used / to use. If 0, then defaults to
218 version 3. (Serialized.) */
220 /* The signature type. (See RFC 4880, Section 5.2.1.) */
222 /* Algorithm used for public key scheme (e.g., PUBKEY_ALGO_RSA).
225 /* Algorithm used for digest (e.g., DIGEST_ALGO_SHA1).
230 const byte *trust_regexp;
231 struct revocation_key *revkey;
233 pka_info_t *pka_info; /* Malloced PKA data or NULL if not
234 available. See also flags.pka_tried. */
235 char *signers_uid; /* Malloced value of the SIGNERS_UID
236 * subpacket or NULL. This string has
237 * already been sanitized. */
238 subpktarea_t *hashed; /* All subpackets with hashed data (v4 only). */
239 subpktarea_t *unhashed; /* Ditto for unhashed data. */
240 /* First 2 bytes of the digest. (Serialized. Note: this is not
241 automatically filled in when serializing a signature!) */
242 byte digest_start[2];
243 /* The signature. (Serialized.) */
244 gcry_mpi_t data[PUBKEY_MAX_NSIG];
245 /* The message digest and its length (in bytes). Note the maximum
246 digest length is 512 bits (64 bytes). If DIGEST_LEN is 0, then
247 the digest's value has not been saved here. */
248 byte digest[512 / 8];
252 #define ATTRIB_IMAGE 1
254 /* This is the cooked form of attributes. */
255 struct user_attribute {
262 /* A user id (RFC 4880, Section 5.11) or a user attribute packet (RFC
263 4880, Section 5.12). Only a subset of these fields are directly
264 serialized (these are marked as such); the rest are read from the
265 self-signatures in merge_keys_and_selfsig()). */
268 int ref; /* reference counter */
269 /* The length of NAME. */
271 struct user_attribute *attribs;
273 /* If this is not NULL, the packet is a user attribute rather than a
274 user id (See RFC 4880 5.12). (Serialized.) */
276 /* The length of ATTRIB_DATA. */
277 unsigned long attrib_len;
282 int help_marginal_count;
283 int is_primary; /* 2 if set via the primary flag, 1 if calculated */
286 u32 expiredate; /* expires at this date or 0 if not at all */
287 prefitem_t *prefs; /* list of preferences (may be NULL)*/
288 u32 created; /* according to the self-signature */
292 /* TODO: Move more flags here */
294 unsigned int ks_modify:1;
295 unsigned int compacted:1;
297 char *mbox; /* NULL or the result of mailbox_from_userid. */
298 /* The text contained in the user id packet, which is normally the
299 name and email address of the key holder (See RFC 4880 5.11).
300 (Serialized.). For convenience an extra Nul is always appended. */
308 /* revoked at this date */
310 /* the keyid of the revoking key (selfsig or designated revoker) */
312 /* the algo of the revoking key */
317 /* Information pertaining to secret keys. */
320 int is_protected:1; /* The secret info is protected and must */
321 /* be decrypted before use, the protected */
322 /* MPIs are simply (void*) pointers to memory */
323 /* and should never be passed to a mpi_xxx() */
324 int sha1chk:1; /* SHA1 is used instead of a 16 bit checksum */
325 u16 csum; /* Checksum for old protection modes. */
326 byte algo; /* Cipher used to protect the secret information. */
327 STRING2KEY s2k; /* S2K parameter. */
328 byte ivlen; /* Used length of the IV. */
329 byte iv[16]; /* Initialization vector for CFB mode. */
334 * The in-memory representation of a public key (RFC 4880, Section
335 * 5.5). Note: this structure contains significantly more information
336 * than is contained in an OpenPGP public key packet. This
337 * information is derived from the self-signed signatures (by
338 * merge_keys_and_selfsig()) and is ignored when serializing the
339 * packet. The fields that are actually written out when serializing
340 * this packet are marked as accordingly.
342 * We assume that secret keys have the same number of parameters as
343 * the public key and that the public parameters are the first items
344 * in the PKEY array. Thus NPKEY is always less than NSKEY and it is
345 * possible to compare the secret and public keys by comparing the
346 * first NPKEY elements of the PKEY array. Note that since GnuPG 2.1
347 * we don't use secret keys anymore directly because they are managed
348 * by gpg-agent. However for parsing OpenPGP key files we need a way
349 * to temporary store those secret keys. We do this by putting them
350 * into the public key structure and extending the PKEY field to NSKEY
351 * elements; the extra secret key information are stored in the
356 /* When the key was created. (Serialized.) */
358 u32 expiredate; /* expires at this date or 0 if not at all */
359 u32 max_expiredate; /* must not expire past this date */
360 struct revoke_info revoked;
361 /* An OpenPGP packet consists of a header and a body. This is the
362 size of the header. If this is 0, an appropriate size is
363 automatically chosen based on the size of the body.
366 /* The serialization format. If 0, the default version (4) is used
367 when serializing. (Serialized.) */
369 byte selfsigversion; /* highest version of all of the self-sigs */
370 /* The public key algorithm. (Serialized.) */
372 byte pubkey_usage; /* for now only used to pass it to getkey() */
373 byte req_usage; /* hack to pass a request to getkey() */
374 u32 has_expired; /* set to the expiration date if expired */
375 /* keyid of the primary key. Never access this value directly.
376 Instead, use pk_main_keyid(). */
378 /* keyid of this key. Never access this value directly! Instead,
381 prefitem_t *prefs; /* list of preferences (may be NULL) */
384 unsigned int mdc:1; /* MDC feature set. */
385 unsigned int disabled_valid:1;/* The next flag is valid. */
386 unsigned int disabled:1; /* The key has been disabled. */
387 unsigned int primary:1; /* This is a primary key. */
388 unsigned int revoked:2; /* Key has been revoked.
389 1 = revoked by the owner
390 2 = revoked by designated revoker. */
391 unsigned int maybe_revoked:1; /* A designated revocation is
392 present, but without the key to
394 unsigned int valid:1; /* Key (especially subkey) is valid. */
395 unsigned int dont_cache:1; /* Do not cache this key. */
396 unsigned int backsig:2; /* 0=none, 1=bad, 2=good. */
397 unsigned int serialno_valid:1;/* SERIALNO below is valid. */
398 unsigned int exact:1; /* Found via exact (!) search. */
400 PKT_user_id *user_id; /* If != NULL: found by that uid. */
401 struct revocation_key *revkey;
406 const byte *trust_regexp;
407 char *serialno; /* Malloced hex string or NULL if it is
408 likely not on a card. See also
409 flags.serialno_valid. */
410 /* If not NULL this malloced structure describes a secret key.
412 struct seckey_info *seckey_info;
413 /* The public key. Contains pubkey_get_npkey (pubkey_algo) +
414 pubkey_get_nskey (pubkey_algo) MPIs. (If pubkey_get_npkey
415 returns 0, then the algorithm is not understood and the PKEY
416 contains a single opaque MPI.) (Serialized.) */
417 gcry_mpi_t pkey[PUBKEY_MAX_NSKEY]; /* Right, NSKEY elements. */
420 /* Evaluates as true if the pk is disabled, and false if it isn't. If
421 there is no disable value cached, fill one in. */
422 #define pk_is_disabled(a) \
423 (((a)->flags.disabled_valid)? \
424 ((a)->flags.disabled):(cache_disabled_value((a))))
428 int len; /* length of data */
432 /* A compression packet (RFC 4880, Section 5.6). */
436 /* Whether the serialized version of the packet used / should use
439 /* The compression algorithm. */
441 /* An iobuf holding the data to be decompressed. (This is not used
446 /* A symmetrically encrypted data packet (RFC 4880, Section 5.7) or a
447 symmetrically encrypted integrity protected data packet (Section
450 /* Remaining length of encrypted data. */
452 /* When encrypting, the first block size bytes of data are random
453 data and the following 2 bytes are copies of the last two bytes
454 of the random data (RFC 4880, Section 5.7). This provides a
455 simple check that the key is correct. extralen is the size of
456 this extra data. This is used by build_packet when writing out
457 the packet's header. */
459 /* Whether the serialized version of the packet used / should use
462 /* Whether the packet has an indeterminate length (old format) or
463 was encoded using partial body length headers (new format).
464 Note: this is ignored when encrypting. */
466 /* If 0, MDC is disabled. Otherwise, the MDC method that was used
467 (currently, only DIGEST_ALGO_SHA1 is supported). */
469 /* An iobuf holding the data to be decrypted. (This is not used for
479 unsigned int trustval;
480 unsigned int sigcache;
483 /* A plaintext packet (see RFC 4880, 5.9). */
485 /* The length of data in BUF or 0 if unknown. */
487 /* A buffer containing the data stored in the packet's body. */
490 byte is_partial; /* partial length encoded */
491 /* The data's formatting. This is either 'b', 't', 'u', 'l' or '1'
492 (however, the last two are deprecated). */
495 /* The name of the file. This can be at most 255 characters long,
496 since namelen is just a byte in the serialized format. */
507 /* combine all packets into a union */
508 struct packet_struct {
512 PKT_symkey_enc *symkey_enc; /* PKT_SYMKEY_ENC */
513 PKT_pubkey_enc *pubkey_enc; /* PKT_PUBKEY_ENC */
514 PKT_onepass_sig *onepass_sig; /* PKT_ONEPASS_SIG */
515 PKT_signature *signature; /* PKT_SIGNATURE */
516 PKT_public_key *public_key; /* PKT_PUBLIC_[SUB]KEY */
517 PKT_public_key *secret_key; /* PKT_SECRET_[SUB]KEY */
518 PKT_comment *comment; /* PKT_COMMENT */
519 PKT_user_id *user_id; /* PKT_USER_ID */
520 PKT_compressed *compressed; /* PKT_COMPRESSED */
521 PKT_encrypted *encrypted; /* PKT_ENCRYPTED[_MDC] */
522 PKT_mdc *mdc; /* PKT_MDC */
523 PKT_ring_trust *ring_trust; /* PKT_RING_TRUST */
524 PKT_plaintext *plaintext; /* PKT_PLAINTEXT */
525 PKT_gpg_control *gpg_control; /* PKT_GPG_CONTROL */
529 #define init_packet(a) do { (a)->pkttype = 0; \
530 (a)->pkt.generic = NULL; \
534 /* A notation. See RFC 4880, Section 5.2.3.16. */
537 /* The notation's name. */
539 /* If the notation is human readable, then the value is stored here
540 as a NUL-terminated string. If it is not human readable a human
541 readable approximation of the binary value _may_ be stored
544 /* Sometimes we want to %-expand the value. In these cases, we save
545 that transformed value here. */
547 /* If the notation is not human readable, then the value is stored
550 /* The amount of data stored in BDAT.
552 Note: if this is 0 and BDAT is NULL, this does not necessarily
553 mean that the value is human readable. It could be that we have
554 a 0-length value. To determine whether the notation is human
555 readable, always check if VALUE is not NULL. This works, because
556 if a human-readable value has a length of 0, we will still
557 allocate space for the NUL byte. */
561 /* The notation is critical. */
562 unsigned int critical:1;
563 /* The notation is human readable. */
564 unsigned int human:1;
565 /* The notation should be deleted. */
566 unsigned int ignore:1;
569 /* A field to facilitate creating a list of notations. */
570 struct notation *next;
572 typedef struct notation *notation_t;
575 void reset_literals_seen(void);
576 int proc_packets (ctrl_t ctrl, void *ctx, iobuf_t a );
577 int proc_signature_packets (ctrl_t ctrl, void *ctx, iobuf_t a,
578 strlist_t signedfiles, const char *sigfile );
579 int proc_signature_packets_by_fd (ctrl_t ctrl,
580 void *anchor, IOBUF a, int signed_data_fd );
581 int proc_encryption_packets (ctrl_t ctrl, void *ctx, iobuf_t a);
582 int list_packets( iobuf_t a );
584 /*-- parse-packet.c --*/
586 /* Sets the packet list mode to MODE (i.e., whether we are dumping a
587 packet or not). Returns the current mode. This allows for
588 temporarily suspending dumping by doing the following:
590 int saved_mode = set_packet_list_mode (0);
592 set_packet_list_mode (saved_mode);
594 int set_packet_list_mode( int mode );
596 #if DEBUG_PARSE_PACKET
597 /* There are debug functions and should not be used directly. */
598 int dbg_search_packet( iobuf_t inp, PACKET *pkt, off_t *retpos, int with_uid,
599 const char* file, int lineno );
600 int dbg_parse_packet( iobuf_t inp, PACKET *ret_pkt,
601 const char* file, int lineno );
602 int dbg_copy_all_packets( iobuf_t inp, iobuf_t out,
603 const char* file, int lineno );
604 int dbg_copy_some_packets( iobuf_t inp, iobuf_t out, off_t stopoff,
605 const char* file, int lineno );
606 int dbg_skip_some_packets( iobuf_t inp, unsigned n,
607 const char* file, int lineno );
608 #define search_packet( a,b,c,d ) \
609 dbg_search_packet( (a), (b), (c), (d), __FILE__, __LINE__ )
610 #define parse_packet( a, b ) \
611 dbg_parse_packet( (a), (b), __FILE__, __LINE__ )
612 #define copy_all_packets( a,b ) \
613 dbg_copy_all_packets((a),(b), __FILE__, __LINE__ )
614 #define copy_some_packets( a,b,c ) \
615 dbg_copy_some_packets((a),(b),(c), __FILE__, __LINE__ )
616 #define skip_some_packets( a,b ) \
617 dbg_skip_some_packets((a),(b), __FILE__, __LINE__ )
619 /* Return the next valid OpenPGP packet in *PKT. (This function will
620 skip any packets whose type is 0.)
622 Returns 0 on success, -1 if EOF is reached, and an error code
623 otherwise. In the case of an error, the packet in *PKT may be
624 partially constructed. As such, even if there is an error, it is
625 necessary to free *PKT to avoid a resource leak. To detect what
626 has been allocated, clear *PKT before calling this function. */
627 int parse_packet( iobuf_t inp, PACKET *pkt);
629 /* Return the first OpenPGP packet in *PKT that contains a key (either
630 a public subkey, a public key, a secret subkey or a secret key) or,
631 if WITH_UID is set, a user id.
633 Saves the position in the pipeline of the start of the returned
634 packet (according to iobuf_tell) in RETPOS, if it is not NULL.
636 The return semantics are the same as parse_packet. */
637 int search_packet( iobuf_t inp, PACKET *pkt, off_t *retpos, int with_uid );
639 /* Copy all packets (except invalid packets, i.e., those with a type
640 of 0) from INP to OUT until either an error occurs or EOF is
643 Returns -1 when end of file is reached or an error code, if an
644 error occurred. (Note: this function never returns 0, because it
645 effectively keeps going until it gets an EOF.) */
646 int copy_all_packets( iobuf_t inp, iobuf_t out );
648 /* Like copy_all_packets, but stops at the first packet that starts at
649 or after STOPOFF (as indicated by iobuf_tell).
651 Example: if STOPOFF is 100, the first packet in INP goes from 0 to
652 110 and the next packet starts at offset 111, then the packet
653 starting at offset 0 will be completely processed (even though it
654 extends beyond STOPOFF) and the packet starting at offset 111 will
655 not be processed at all. */
656 int copy_some_packets( iobuf_t inp, iobuf_t out, off_t stopoff );
658 /* Skips the next N packets from INP.
660 If parsing a packet returns an error code, then the function stops
661 immediately and returns the error code. Note: in the case of an
662 error, this function does not indicate how many packets were
663 successfully processed. */
664 int skip_some_packets( iobuf_t inp, unsigned n );
667 /* Parse a signature packet and store it in *SIG.
669 The signature packet is read from INP. The OpenPGP header (the tag
670 and the packet's length) have already been read; the next byte read
671 from INP should be the first byte of the packet's contents. The
672 packet's type (as extract from the tag) must be passed as PKTTYPE
673 and the packet's length must be passed as PKTLEN. This is used as
674 the upper bound on the amount of data read from INP. If the packet
675 is shorter than PKTLEN, the data at the end will be silently
676 skipped. If an error occurs, an error code will be returned. -1
677 means the EOF was encountered. 0 means parsing was successful. */
678 int parse_signature( iobuf_t inp, int pkttype, unsigned long pktlen,
679 PKT_signature *sig );
681 /* Given a subpacket area (typically either PKT_signature.hashed or
682 PKT_signature.unhashed), either:
684 - test whether there are any subpackets with the critical bit set
685 that we don't understand,
687 - list the subpackets, or,
689 - find a subpacket with a specific type.
691 REQTYPE indicates the type of operation.
693 If REQTYPE is SIGSUBPKT_TEST_CRITICAL, then this function checks
694 whether there are any subpackets that have the critical bit and
695 which GnuPG cannot handle. If GnuPG understands all subpackets
696 whose critical bit is set, then this function returns simply
697 returns SUBPKTS. If there is a subpacket whose critical bit is set
698 and which GnuPG does not understand, then this function returns
699 NULL and, if START is not NULL, sets *START to the 1-based index of
700 the subpacket that violates the constraint.
702 If REQTYPE is SIGSUBPKT_LIST_HASHED or SIGSUBPKT_LIST_UNHASHED, the
703 packets are dumped. Note: if REQTYPE is SIGSUBPKT_LIST_HASHED,
704 this function does not check whether the hash is correct; this is
705 merely an indication of the section that the subpackets came from.
707 If REQTYPE is anything else, then this function interprets the
708 values as a subpacket type and looks for the first subpacket with
709 that type. If such a packet is found, *CRITICAL (if not NULL) is
710 set if the critical bit was set, *RET_N is set to the offset of the
711 subpacket's content within the SUBPKTS buffer, *START is set to the
712 1-based index of the subpacket within the buffer, and returns
715 *START is the number of initial subpackets to not consider. Thus,
716 if *START is 2, then the first 2 subpackets are ignored. */
717 const byte *enum_sig_subpkt ( const subpktarea_t *subpkts,
718 sigsubpkttype_t reqtype,
719 size_t *ret_n, int *start, int *critical );
723 enum_sig_subpkt (buffer, reqtype, ret_n, NULL, NULL); */
724 const byte *parse_sig_subpkt ( const subpktarea_t *buffer,
725 sigsubpkttype_t reqtype,
728 /* This calls parse_sig_subpkt first on the hashed signature area in
729 SIG and then, if that returns NULL, calls parse_sig_subpkt on the
730 unhashed subpacket area in SIG. */
731 const byte *parse_sig_subpkt2 ( PKT_signature *sig,
732 sigsubpkttype_t reqtype);
734 /* Returns whether the N byte large buffer BUFFER is sufficient to
735 hold a subpacket of type TYPE. Note: the buffer refers to the
736 contents of the subpacket (not the header) and it must already be
737 initialized: for some subpackets, it checks some internal
740 Returns 0 if the size is acceptable. Returns -2 if the buffer is
741 definitely too short. To check for an error, check whether the
742 return value is less than 0. */
743 int parse_one_sig_subpkt( const byte *buffer, size_t n, int type );
745 /* Looks for revocation key subpackets (see RFC 4880 5.2.3.15) in the
746 hashed area of the signature packet. Any that are found are added
747 to SIG->REVKEY and SIG->NUMREVKEYS is updated appropriately. */
748 void parse_revkeys(PKT_signature *sig);
750 /* Extract the attributes from the buffer at UID->ATTRIB_DATA and
751 update UID->ATTRIBS and UID->NUMATTRIBS accordingly. */
752 int parse_attribute_subpkts(PKT_user_id *uid);
754 /* Set the UID->NAME field according to the attributes. MAX_NAMELEN
755 must be at least 71. */
756 void make_attribute_uidname(PKT_user_id *uid, size_t max_namelen);
758 /* Allocate and initialize a new GPG control packet. DATA is the data
759 to save in the packet. */
760 PACKET *create_gpg_control ( ctrlpkttype_t type,
764 /*-- build-packet.c --*/
765 int build_packet( iobuf_t inp, PACKET *pkt );
766 gpg_error_t gpg_mpi_write (iobuf_t out, gcry_mpi_t a);
767 gpg_error_t gpg_mpi_write_nohdr (iobuf_t out, gcry_mpi_t a);
768 u32 calc_packet_length( PACKET *pkt );
769 void build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
770 const byte *buffer, size_t buflen );
771 void build_sig_subpkt_from_sig (PKT_signature *sig, PKT_public_key *pksk);
772 int delete_sig_subpkt(subpktarea_t *buffer, sigsubpkttype_t type );
773 void build_attribute_subpkt(PKT_user_id *uid,byte type,
774 const void *buf,u32 buflen,
775 const void *header,u32 headerlen);
776 struct notation *string_to_notation(const char *string,int is_utf8);
777 struct notation *blob_to_notation(const char *name,
778 const char *data, size_t len);
779 struct notation *sig_to_notation(PKT_signature *sig);
780 void free_notation(struct notation *notation);
782 /*-- free-packet.c --*/
783 void free_symkey_enc( PKT_symkey_enc *enc );
784 void free_pubkey_enc( PKT_pubkey_enc *enc );
785 void free_seckey_enc( PKT_signature *enc );
786 void release_public_key_parts( PKT_public_key *pk );
787 void free_public_key( PKT_public_key *key );
788 void free_attributes(PKT_user_id *uid);
789 void free_user_id( PKT_user_id *uid );
790 void free_comment( PKT_comment *rem );
791 void free_packet( PACKET *pkt );
792 prefitem_t *copy_prefs (const prefitem_t *prefs);
793 PKT_public_key *copy_public_key( PKT_public_key *d, PKT_public_key *s );
794 PKT_signature *copy_signature( PKT_signature *d, PKT_signature *s );
795 PKT_user_id *scopy_user_id (PKT_user_id *sd );
796 int cmp_public_keys( PKT_public_key *a, PKT_public_key *b );
797 int cmp_signatures( PKT_signature *a, PKT_signature *b );
798 int cmp_user_ids( PKT_user_id *a, PKT_user_id *b );
801 /*-- sig-check.c --*/
802 /* Check a signature. This is shorthand for check_signature2 with
803 the unnamed arguments passed as NULL. */
804 int check_signature (PKT_signature *sig, gcry_md_hd_t digest);
806 /* Check a signature. Looks up the public key from the key db. (If
807 * R_PK is not NULL, it is stored at RET_PK.) DIGEST contains a
808 * valid hash context that already includes the signed data. This
809 * function adds the relevant meta-data to the hash before finalizing
810 * it and verifying the signature. */
811 gpg_error_t check_signature2 (PKT_signature *sig, gcry_md_hd_t digest,
812 u32 *r_expiredate, int *r_expired, int *r_revoked,
813 PKT_public_key **r_pk);
816 /*-- pubkey-enc.c --*/
817 gpg_error_t get_session_key (ctrl_t ctrl, PKT_pubkey_enc *k, DEK *dek);
818 gpg_error_t get_override_session_key (DEK *dek, const char *string);
821 int handle_compressed (ctrl_t ctrl, void *ctx, PKT_compressed *cd,
822 int (*callback)(iobuf_t, void *), void *passthru );
824 /*-- encr-data.c --*/
825 int decrypt_data (ctrl_t ctrl, void *ctx, PKT_encrypted *ed, DEK *dek );
827 /*-- plaintext.c --*/
828 gpg_error_t get_output_file (const byte *embedded_name, int embedded_namelen,
829 iobuf_t data, char **fnamep, estream_t *fpp);
830 int handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
831 int nooutput, int clearsig );
832 int ask_for_detached_datafile( gcry_md_hd_t md, gcry_md_hd_t md2,
833 const char *inname, int textmode );
836 int make_keysig_packet( PKT_signature **ret_sig, PKT_public_key *pk,
837 PKT_user_id *uid, PKT_public_key *subpk,
838 PKT_public_key *pksk, int sigclass, int digest_algo,
839 u32 timestamp, u32 duration,
840 int (*mksubpkt)(PKT_signature *, void *),
842 const char *cache_nonce);
843 gpg_error_t update_keysig_packet (PKT_signature **ret_sig,
844 PKT_signature *orig_sig,
847 PKT_public_key *subpk,
848 PKT_public_key *pksk,
849 int (*mksubpkt)(PKT_signature *, void *),
853 PKT_user_id *generate_user_id (kbnode_t keyblock, const char *uidstr);
855 #endif /*G10_PACKET_H*/