24
23
#include <stdlib.h>
25
24
#include <string.h>
26
25
#include <assert.h>
29
29
#include "packet.h"
34
33
#include "cipher.h"
36
35
#include "options.h"
39
static int do_comment( iobuf_t out, int ctb, PKT_comment *rem );
40
static int do_user_id( iobuf_t out, int ctb, PKT_user_id *uid );
41
static int do_public_key( iobuf_t out, int ctb, PKT_public_key *pk );
42
static int do_secret_key( iobuf_t out, int ctb, PKT_secret_key *pk );
43
static int do_symkey_enc( iobuf_t out, int ctb, PKT_symkey_enc *enc );
44
static int do_pubkey_enc( iobuf_t out, int ctb, PKT_pubkey_enc *enc );
37
static int do_user_id( IOBUF out, int ctb, PKT_user_id *uid );
38
static int do_public_key( IOBUF out, int ctb, PKT_public_key *pk );
39
static int do_secret_key( IOBUF out, int ctb, PKT_secret_key *pk );
40
static int do_symkey_enc( IOBUF out, int ctb, PKT_symkey_enc *enc );
41
static int do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc );
45
42
static u32 calc_plaintext( PKT_plaintext *pt );
46
static int do_plaintext( iobuf_t out, int ctb, PKT_plaintext *pt );
47
static int do_encrypted( iobuf_t out, int ctb, PKT_encrypted *ed );
48
static int do_encrypted_mdc( iobuf_t out, int ctb, PKT_encrypted *ed );
49
static int do_compressed( iobuf_t out, int ctb, PKT_compressed *cd );
50
static int do_signature( iobuf_t out, int ctb, PKT_signature *sig );
51
static int do_onepass_sig( iobuf_t out, int ctb, PKT_onepass_sig *ops );
43
static int do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt );
44
static int do_encrypted( IOBUF out, int ctb, PKT_encrypted *ed );
45
static int do_encrypted_mdc( IOBUF out, int ctb, PKT_encrypted *ed );
46
static int do_compressed( IOBUF out, int ctb, PKT_compressed *cd );
47
static int do_signature( IOBUF out, int ctb, PKT_signature *sig );
48
static int do_onepass_sig( IOBUF out, int ctb, PKT_onepass_sig *ops );
53
50
static int calc_header_length( u32 len, int new_ctb );
54
static int write_16(iobuf_t inp, u16 a);
55
static int write_32(iobuf_t inp, u32 a);
56
static int write_header( iobuf_t out, int ctb, u32 len );
57
static int write_sign_packet_header( iobuf_t out, int ctb, u32 len );
58
static int write_header2( iobuf_t out, int ctb, u32 len, int hdrlen, int blkmode );
59
static int write_new_header( iobuf_t out, int ctb, u32 len, int hdrlen );
60
static int write_version( iobuf_t out, int ctb );
51
static int write_16(IOBUF inp, u16 a);
52
static int write_32(IOBUF inp, u32 a);
53
static int write_header( IOBUF out, int ctb, u32 len );
54
static int write_sign_packet_header( IOBUF out, int ctb, u32 len );
55
static int write_header2( IOBUF out, int ctb, u32 len, int hdrlen );
56
static int write_new_header( IOBUF out, int ctb, u32 len, int hdrlen );
57
static int write_version( IOBUF out, int ctb );
63
60
* Build a packet and write it to INP
183
write_fake_data( iobuf_t out, gcry_mpi_t a )
189
assert( gcry_mpi_get_flag (a, GCRYMPI_FLAG_OPAQUE));
190
p = gcry_mpi_get_opaque (a, &n);
191
iobuf_write (out, p, (n+7)/8);
197
do_comment (iobuf_t out, int ctb, PKT_comment *rem)
203
write_header(out, ctb, rem->len);
204
rc = iobuf_write( out, rem->data, rem->len );
210
do_user_id( iobuf_t out, int ctb, PKT_user_id *uid )
214
if (uid->attrib_data)
216
write_header (out, ctb, uid->attrib_len);
217
rc = iobuf_write (out, uid->attrib_data, uid->attrib_len );
221
write_header (out, ctb, uid->len);
222
rc = iobuf_write (out, uid->name, uid->len );
228
do_public_key( iobuf_t out, int ctb, PKT_public_key *pk )
232
iobuf_t a = iobuf_temp();
237
iobuf_put( a, pk->version );
238
write_32(a, pk->timestamp );
239
if( pk->version < 4 ) {
242
ndays = (u16)((pk->expiredate - pk->timestamp) / 86400L);
247
iobuf_put(a, pk->pubkey_algo );
248
n = pubkey_get_npkey( pk->pubkey_algo );
250
write_fake_data( a, pk->pkey[0] );
251
for(i=0; i < n; i++ )
252
mpi_write(a, pk->pkey[i] );
254
write_header2(out, ctb, iobuf_get_temp_length(a), pk->hdrbytes, 1 );
255
rc = iobuf_write_temp (out, a);
263
* Make a hash value from the public key certificate
266
hash_public_key( MD_HANDLE md, PKT_public_key *pk )
273
iobuf_t a = iobuf_temp();
275
FILE *fp = fopen("dump.pk", "a");
278
fprintf(fp, "\nHashing PK (v%d):\n", pk->version);
281
/* build the packet */
283
pkt.pkttype = PKT_PUBLIC_KEY;
284
pkt.pkt.public_key = pk;
285
if( (rc = build_packet( a, &pkt )) )
286
log_fatal("build public_key for hashing failed: %s\n", gpg_strerror (rc));
288
if( !(pk->version == 3 && pk->pubkey_algo == 16) ) {
289
/* skip the constructed header but don't do this for our very old
291
ctb = iobuf_get_noeof(a);
294
c = iobuf_get_noeof(a);
298
pktlen = (c - 192) * 256;
299
c = iobuf_get_noeof(a);
302
else if( c == 255 ) {
303
pktlen = iobuf_get_noeof(a) << 24;
304
pktlen |= iobuf_get_noeof(a) << 16;
305
pktlen |= iobuf_get_noeof(a) << 8;
306
pktlen |= iobuf_get_noeof(a);
310
int lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
311
for( ; lenbytes; lenbytes-- ) {
313
pktlen |= iobuf_get_noeof(a);
317
gcry_md_putc ( md, 0x99 );
318
pktlen &= 0xffff; /* can't handle longer packets */
319
gcry_md_putc ( md, pktlen >> 8 );
320
gcry_md_putc ( md, pktlen & 0xff );
322
/* hash the packet body */
323
while( (c=iobuf_get(a)) != -1 ) {
325
fprintf( fp," %02x", c );
331
gcry_md_putc ( md, c );
342
do_secret_key( iobuf_t out, int ctb, PKT_secret_key *sk )
346
iobuf_t a = iobuf_temp(); /* build in a self-enlarging buffer */
348
/* Write the version number - if none is specified, use 3 */
352
iobuf_put( a, sk->version );
353
write_32(a, sk->timestamp );
355
/* v3 needs the expiration time */
356
if( sk->version < 4 ) {
359
ndays = (u16)((sk->expiredate - sk->timestamp) / 86400L);
365
iobuf_put(a, sk->pubkey_algo );
367
/* get number of secret and public parameters. They are held in
368
one array first the public ones, then the secret ones */
369
nskey = pubkey_get_nskey( sk->pubkey_algo );
370
npkey = pubkey_get_npkey( sk->pubkey_algo );
372
/* If we don't have any public parameters - which is the case if
373
we don't know the algorithm used - the parameters are stored as
374
one blob in a faked (opaque) gcry_mpi_t */
376
write_fake_data( a, sk->skey[0] );
379
assert( npkey < nskey );
381
/* Writing the public parameters is easy */
382
for(i=0; i < npkey; i++ )
383
mpi_write(a, sk->skey[i] );
385
/* build the header for protected (encrypted) secret parameters */
386
if( sk->is_protected ) {
387
if( is_RSA(sk->pubkey_algo) && sk->version < 4
388
&& !sk->protect.s2k.mode ) {
389
/* the simple rfc1991 (v3) way */
390
iobuf_put(a, sk->protect.algo );
391
iobuf_write(a, sk->protect.iv, sk->protect.ivlen );
394
/* OpenPGP protection according to rfc2440 */
395
iobuf_put(a, sk->protect.sha1chk? 0xfe : 0xff );
396
iobuf_put(a, sk->protect.algo );
397
if( sk->protect.s2k.mode >= 1000 ) {
398
/* These modes are not possible in OpenPGP, we use them
399
to implement our extensions, 101 can be seen as a
400
private/experimental extension (this is not
401
specified in rfc2440 but the same scheme is used
402
for all other algorithm identifiers) */
404
iobuf_put(a, sk->protect.s2k.hash_algo );
405
iobuf_write(a, "GNU", 3 );
406
iobuf_put(a, sk->protect.s2k.mode - 1000 );
409
iobuf_put(a, sk->protect.s2k.mode );
410
iobuf_put(a, sk->protect.s2k.hash_algo );
412
if( sk->protect.s2k.mode == 1
413
|| sk->protect.s2k.mode == 3 )
414
iobuf_write(a, sk->protect.s2k.salt, 8 );
415
if( sk->protect.s2k.mode == 3 )
416
iobuf_put(a, sk->protect.s2k.count );
418
/* For our special modes 1001 and 1002 we do not need an IV */
419
if( sk->protect.s2k.mode != 1001
420
&& sk->protect.s2k.mode != 1002 )
421
iobuf_write(a, sk->protect.iv, sk->protect.ivlen );
427
if( sk->protect.s2k.mode == 1001 )
428
; /* GnuPG extension - don't write a secret key at all */
429
else if( sk->protect.s2k.mode == 1002 )
430
{ /* GnuPG extension - divert to OpenPGP smartcard. */
431
iobuf_put(a, sk->protect.ivlen ); /* length of the serial
432
number or 0 for no serial
434
/* The serial number gets stored in the IV field. */
435
iobuf_write(a, sk->protect.iv, sk->protect.ivlen);
437
else if( sk->is_protected && sk->version >= 4 ) {
438
/* The secret key is protected - write it out as it is */
440
assert( gcry_mpi_get_flag( sk->skey[npkey], GCRYMPI_FLAG_OPAQUE ) );
441
p = gcry_mpi_get_opaque( sk->skey[npkey], &i );
442
iobuf_write(a, p, (i+7)/8 );
444
else if( sk->is_protected ) {
445
/* The secret key is protected the old v4 way. */
446
for( ; i < nskey; i++ ) {
450
assert( gcry_mpi_get_flag (sk->skey[i], GCRYMPI_FLAG_OPAQUE));
451
p = gcry_mpi_get_opaque( sk->skey[i], &n );
452
iobuf_write (a, p, (n+7)/8);
215
write_fake_data (IOBUF out, gcry_mpi_t a)
222
p = gcry_mpi_get_opaque ( a, &n );
223
iobuf_write (out, p, (n+7)/8 );
228
do_user_id( IOBUF out, int ctb, PKT_user_id *uid )
232
if( uid->attrib_data )
234
write_header(out, ctb, uid->attrib_len);
235
rc = iobuf_write( out, uid->attrib_data, uid->attrib_len );
239
write_header2( out, ctb, uid->len, 2 );
240
rc = iobuf_write( out, uid->name, uid->len );
246
do_public_key( IOBUF out, int ctb, PKT_public_key *pk )
250
IOBUF a = iobuf_temp();
255
iobuf_put( a, pk->version );
256
write_32(a, pk->timestamp );
257
if ( pk->version < 4 )
260
if ( pk->expiredate )
261
ndays = (u16)((pk->expiredate - pk->timestamp) / 86400L);
266
iobuf_put (a, pk->pubkey_algo );
267
n = pubkey_get_npkey ( pk->pubkey_algo );
269
write_fake_data( a, pk->pkey[0] );
270
for (i=0; i < n && !rc ; i++ )
271
rc = mpi_write(a, pk->pkey[i] );
275
write_header2 (out, ctb, iobuf_get_temp_length(a), pk->hdrbytes);
276
rc = iobuf_write_temp ( out, a );
285
do_secret_key( IOBUF out, int ctb, PKT_secret_key *sk )
289
IOBUF a = iobuf_temp(); /* Build in a self-enlarging buffer. */
291
/* Write the version number - if none is specified, use 3 */
295
iobuf_put ( a, sk->version );
296
write_32 (a, sk->timestamp );
298
/* v3 needs the expiration time. */
299
if ( sk->version < 4 )
302
if ( sk->expiredate )
303
ndays = (u16)((sk->expiredate - sk->timestamp) / 86400L);
309
iobuf_put (a, sk->pubkey_algo );
311
/* Get number of secret and public parameters. They are held in one
312
array first the public ones, then the secret ones. */
313
nskey = pubkey_get_nskey ( sk->pubkey_algo );
314
npkey = pubkey_get_npkey ( sk->pubkey_algo );
316
/* If we don't have any public parameters - which is the case if we
317
don't know the algorithm used - the parameters are stored as one
318
blob in a faked (opaque) MPI. */
321
write_fake_data( a, sk->skey[0] );
324
assert ( npkey < nskey );
326
/* Writing the public parameters is easy. */
327
for (i=0; i < npkey; i++ )
328
if ((rc = mpi_write (a, sk->skey[i])))
331
/* Build the header for protected (encrypted) secret parameters. */
332
if ( sk->is_protected )
334
if ( is_RSA(sk->pubkey_algo)
336
&& !sk->protect.s2k.mode )
338
/* The simple rfc1991 (v3) way. */
339
iobuf_put (a, sk->protect.algo );
340
iobuf_write (a, sk->protect.iv, sk->protect.ivlen );
344
/* OpenPGP protection according to rfc2440. */
345
iobuf_put(a, sk->protect.sha1chk? 0xfe : 0xff );
346
iobuf_put(a, sk->protect.algo );
347
if ( sk->protect.s2k.mode >= 1000 )
349
/* These modes are not possible in OpenPGP, we use them
350
to implement our extensions, 101 can be seen as a
351
private/experimental extension (this is not specified
352
in rfc2440 but the same scheme is used for all other
353
algorithm identifiers) */
355
iobuf_put(a, sk->protect.s2k.hash_algo );
356
iobuf_write(a, "GNU", 3 );
357
iobuf_put(a, sk->protect.s2k.mode - 1000 );
361
iobuf_put(a, sk->protect.s2k.mode );
362
iobuf_put(a, sk->protect.s2k.hash_algo );
364
if ( sk->protect.s2k.mode == 1
365
|| sk->protect.s2k.mode == 3 )
366
iobuf_write (a, sk->protect.s2k.salt, 8 );
368
if ( sk->protect.s2k.mode == 3 )
369
iobuf_put (a, sk->protect.s2k.count );
371
/* For our special modes 1001, 1002 we do not need an IV. */
372
if ( sk->protect.s2k.mode != 1001
373
&& sk->protect.s2k.mode != 1002 )
374
iobuf_write (a, sk->protect.iv, sk->protect.ivlen );
380
if ( sk->protect.s2k.mode == 1001 )
381
; /* GnuPG extension - don't write a secret key at all. */
382
else if ( sk->protect.s2k.mode == 1002 )
384
/* GnuPG extension - divert to OpenPGP smartcard. */
385
iobuf_put(a, sk->protect.ivlen ); /* Length of the serial number
388
/* The serial number gets stored in the IV field. */
389
iobuf_write(a, sk->protect.iv, sk->protect.ivlen);
391
else if ( sk->is_protected && sk->version >= 4 )
393
/* The secret key is protected - write it out as it is. */
395
unsigned int ndatabits;
397
assert (gcry_mpi_get_flag (sk->skey[npkey], GCRYMPI_FLAG_OPAQUE));
398
p = gcry_mpi_get_opaque (sk->skey[npkey], &ndatabits );
399
iobuf_write (a, p, (ndatabits+7)/8 );
401
else if ( sk->is_protected )
403
/* The secret key is protected the old v4 way. */
404
for ( ; i < nskey; i++ )
407
unsigned int ndatabits;
409
assert (gcry_mpi_get_flag (sk->skey[i], GCRYMPI_FLAG_OPAQUE));
410
p = gcry_mpi_get_opaque (sk->skey[i], &ndatabits);
411
iobuf_write (a, p, (ndatabits+7)/8);
454
write_16(a, sk->csum );
457
/* non-protected key */
458
for( ; i < nskey; i++ )
459
mpi_write(a, sk->skey[i] );
460
write_16(a, sk->csum );
464
/* Build the header of the packet - which we must do after writing all
465
the other stuff, so that we know the length of the packet */
466
write_header2(out, ctb, iobuf_get_temp_length(a), sk->hdrbytes, 1 );
467
/* And finally write it out the real stream */
468
rc = iobuf_write_temp (out, a );
470
iobuf_close(a); /* close the remporary buffer */
413
write_16(a, sk->csum );
417
/* Non-protected key. */
418
for ( ; i < nskey; i++ )
419
if ( (rc = mpi_write (a, sk->skey[i])))
421
write_16 (a, sk->csum );
427
/* Build the header of the packet - which we must do after
428
writing all the other stuff, so that we know the length of
430
write_header2(out, ctb, iobuf_get_temp_length(a), sk->hdrbytes);
431
/* And finally write it out the real stream */
432
rc = iobuf_write_temp( out, a );
435
iobuf_close(a); /* Close the remporary buffer */
475
do_symkey_enc( iobuf_t out, int ctb, PKT_symkey_enc *enc )
440
do_symkey_enc( IOBUF out, int ctb, PKT_symkey_enc *enc )
478
iobuf_t a = iobuf_temp();
443
IOBUF a = iobuf_temp();
480
445
assert( enc->version == 4 );
481
446
switch( enc->s2k.mode ) {
495
460
iobuf_write(a, enc->seskey, enc->seskeylen );
497
462
write_header(out, ctb, iobuf_get_temp_length(a) );
498
rc = iobuf_write_temp (out, a);
463
rc = iobuf_write_temp( out, a );
508
do_pubkey_enc( iobuf_t out, int ctb, PKT_pubkey_enc *enc )
471
do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
512
iobuf_t a = iobuf_temp();
514
write_version( a, ctb );
515
if( enc->throw_keyid ) {
516
write_32(a, 0 ); /* don't tell Eve who can decrypt the message */
520
write_32(a, enc->keyid[0] );
521
write_32(a, enc->keyid[1] );
523
iobuf_put(a,enc->pubkey_algo );
524
n = pubkey_get_nenc( enc->pubkey_algo );
526
write_fake_data( a, enc->data[0] );
527
for(i=0; i < n; i++ )
528
mpi_write(a, enc->data[i] );
530
write_header(out, ctb, iobuf_get_temp_length(a) );
531
rc = iobuf_write_temp (out, a);
475
IOBUF a = iobuf_temp();
477
write_version( a, ctb );
478
if ( enc->throw_keyid )
480
write_32(a, 0 ); /* Don't tell Eve who can decrypt the message. */
485
write_32(a, enc->keyid[0] );
486
write_32(a, enc->keyid[1] );
488
iobuf_put(a,enc->pubkey_algo );
489
n = pubkey_get_nenc( enc->pubkey_algo );
491
write_fake_data( a, enc->data[0] );
492
for (i=0; i < n && !rc ; i++ )
493
rc = mpi_write(a, enc->data[i] );
497
write_header(out, ctb, iobuf_get_temp_length(a) );
498
rc = iobuf_write_temp( out, a );
541
506
calc_plaintext( PKT_plaintext *pt )
543
return pt->len? (1 + 1 + pt->namelen + 4 + pt->len) : 0;
508
/* Truncate namelen to the maximum 255 characters. Note this means
509
that a function that calls build_packet with an illegal literal
510
packet will get it back legalized. */
515
return pt->len? (1 + 1 + pt->namelen + 4 + pt->len) : 0;
547
do_plaintext( iobuf_t out, int ctb, PKT_plaintext *pt )
519
do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
551
523
byte buf[1000]; /* this buffer has the plaintext! */
554
/* Truncate namelen to the maximum 255 characters. This does mean
555
that a function that calls build_packet with an illegal literal
556
packet will get it back legalized. */
560
526
write_header(out, ctb, calc_plaintext( pt ) );
561
527
iobuf_put(out, pt->mode );
562
528
iobuf_put(out, pt->namelen );
563
529
for(i=0; i < pt->namelen; i++ )
564
530
iobuf_put(out, pt->name[i] );
565
rc = write_32 (out, pt->timestamp);
531
rc = write_32(out, pt->timestamp );
568
536
while( (nbytes=iobuf_read(pt->buf, buf, 1000)) != -1 ) {
569
rc = iobuf_write(out, buf, nbytes);
537
rc = iobuf_write (out, buf, nbytes);
574
542
wipememory(buf,1000); /* burn the buffer */
576
iobuf_set_block_mode(out, 0 ); /* write end marker */
577
else if( n != pt->len )
578
log_error("do_plaintext(): wrote %lu bytes but expected %lu bytes\n",
579
(ulong)n, (ulong)pt->len );
543
if( (ctb&0x40) && !pt->len )
544
iobuf_set_partial_block_mode(out, 0 ); /* turn off partial */
545
if( pt->len && n != pt->len )
546
log_error("do_plaintext(): wrote %lu bytes but expected %lu bytes\n",
547
(ulong)n, (ulong)pt->len );
966
938
uid->attrib_len+=idx+headerlen+buflen;
970
do_signature( iobuf_t out, int ctb, PKT_signature *sig )
974
iobuf_t a = iobuf_temp();
979
iobuf_put( a, sig->version );
980
if( sig->version < 4 )
981
iobuf_put(a, 5 ); /* constant */
982
iobuf_put(a, sig->sig_class );
983
if( sig->version < 4 ) {
984
write_32(a, sig->timestamp );
985
write_32(a, sig->keyid[0] );
986
write_32(a, sig->keyid[1] );
988
iobuf_put(a, sig->pubkey_algo );
989
iobuf_put(a, sig->digest_algo );
990
if( sig->version >= 4 ) {
992
/* timestamp and keyid must have been packed into the
993
* subpackets prior to the call of this function, because
994
* these subpackets are hashed */
995
nn = sig->hashed? sig->hashed->len : 0;
998
iobuf_write( a, sig->hashed->data, nn );
999
nn = sig->unhashed? sig->unhashed->len : 0;
1002
iobuf_write( a, sig->unhashed->data, nn );
1004
iobuf_put(a, sig->digest_start[0] );
1005
iobuf_put(a, sig->digest_start[1] );
1006
n = pubkey_get_nsig( sig->pubkey_algo );
1008
write_fake_data( a, sig->data[0] );
1009
for(i=0; i < n; i++ )
1010
mpi_write(a, sig->data[i] );
1012
if( is_RSA(sig->pubkey_algo) && sig->version < 4 )
1013
write_sign_packet_header(out, ctb, iobuf_get_temp_length(a) );
1015
write_header(out, ctb, iobuf_get_temp_length(a) );
1016
rc = iobuf_write_temp (out, a);
1024
do_onepass_sig( iobuf_t out, int ctb, PKT_onepass_sig *ops )
1027
iobuf_t a = iobuf_temp();
942
string_to_notation(const char *string,int is_utf8)
946
struct notation *notation;
948
notation=xmalloc_clear(sizeof(*notation));
952
notation->flags.ignore=1;
958
notation->flags.critical=1;
962
/* If and when the IETF assigns some official name tags, we'll have
965
for( s=string ; *s != '='; s++ )
970
/* -notationname is legal without an = sign */
971
if(!*s && notation->flags.ignore)
974
if( !*s || !isascii (*s) || (!isgraph(*s) && !isspace(*s)) )
976
log_error(_("a notation name must have only printable characters"
977
" or spaces, and end with an '='\n") );
982
notation->name=xmalloc((s-string)+1);
983
strncpy(notation->name,string,s-string);
984
notation->name[s-string]='\0';
986
if(!saw_at && !opt.expert)
988
log_error(_("a user notation name must contain the '@' character\n"));
994
log_error(_("a notation name must not contain more than"
995
" one '@' character\n"));
1004
/* we only support printable text - therefore we enforce the use
1005
of only printable characters (an empty value is valid) */
1008
if ( !isascii (*s) )
1010
else if (iscntrl(*s))
1012
log_error(_("a notation value must not use any"
1013
" control characters\n"));
1018
if(!highbit || is_utf8)
1019
notation->value=xstrdup(i);
1021
notation->value=native_to_utf8(i);
1027
free_notation(notation);
1032
sig_to_notation(PKT_signature *sig)
1037
struct notation *list=NULL;
1039
while((p=enum_sig_subpkt(sig->hashed,SIGSUBPKT_NOTATION,&len,&seq,&crit)))
1042
struct notation *n=NULL;
1046
log_info(_("WARNING: invalid notation data found\n"));
1055
log_info(_("WARNING: invalid notation data found\n"));
1059
n=xmalloc_clear(sizeof(*n));
1060
n->name=xmalloc(n1+1);
1062
memcpy(n->name,&p[8],n1);
1067
n->value=xmalloc(n2+1);
1068
memcpy(n->value,&p[8+n1],n2);
1073
n->bdat=xmalloc(n2);
1075
memcpy(n->bdat,&p[8+n1],n2);
1077
n->value=xmalloc(2+strlen(_("not human readable"))+2+1);
1078
strcpy(n->value,"[ ");
1079
strcat(n->value,_("not human readable"));
1080
strcat(n->value," ]");
1083
n->flags.critical=crit;
1093
free_notation(struct notation *notation)
1097
struct notation *n=notation;
1109
do_signature( IOBUF out, int ctb, PKT_signature *sig )
1113
IOBUF a = iobuf_temp();
1115
if ( !sig->version )
1118
iobuf_put( a, sig->version );
1119
if ( sig->version < 4 )
1120
iobuf_put (a, 5 ); /* Constant */
1121
iobuf_put (a, sig->sig_class );
1122
if ( sig->version < 4 )
1124
write_32(a, sig->timestamp );
1125
write_32(a, sig->keyid[0] );
1126
write_32(a, sig->keyid[1] );
1128
iobuf_put(a, sig->pubkey_algo );
1129
iobuf_put(a, sig->digest_algo );
1130
if ( sig->version >= 4 )
1133
/* Timestamp and keyid must have been packed into the subpackets
1134
prior to the call of this function, because these subpackets
1136
nn = sig->hashed? sig->hashed->len : 0;
1139
iobuf_write( a, sig->hashed->data, nn );
1140
nn = sig->unhashed? sig->unhashed->len : 0;
1143
iobuf_write( a, sig->unhashed->data, nn );
1145
iobuf_put(a, sig->digest_start[0] );
1146
iobuf_put(a, sig->digest_start[1] );
1147
n = pubkey_get_nsig( sig->pubkey_algo );
1149
write_fake_data( a, sig->data[0] );
1150
for (i=0; i < n && !rc ; i++ )
1151
rc = mpi_write(a, sig->data[i] );
1155
if ( is_RSA(sig->pubkey_algo) && sig->version < 4 )
1156
write_sign_packet_header(out, ctb, iobuf_get_temp_length(a) );
1158
write_header(out, ctb, iobuf_get_temp_length(a) );
1159
rc = iobuf_write_temp( out, a );
1168
do_onepass_sig( IOBUF out, int ctb, PKT_onepass_sig *ops )
1171
IOBUF a = iobuf_temp();
1029
1173
write_version( a, ctb );
1030
1174
iobuf_put(a, ops->sig_class );