Browse Source

Fixed seckey export (wrong length, missing 16bit checksum)

master
Edouard Tisserant 7 years ago
parent
commit
2d87b92412
3 changed files with 70 additions and 4 deletions
  1. +12
    -4
      dist/src/lib/create.c
  2. +54
    -0
      dist/src/lib/writer.c
  3. +4
    -0
      dist/src/lib/writer.h

+ 12
- 4
dist/src/lib/create.c View File

@ -450,6 +450,8 @@ write_seckey_body(const pgp_seckey_t *key,
(void) fprintf(stderr, "\nturning encryption on...\n");
}
pgp_push_enc_crypt(output, &crypted);
}else{
pgp_push_sum16_writer(output);
}
switch (key->pubkey.alg) {
@ -475,12 +477,18 @@ write_seckey_body(const pgp_seckey_t *key,
return 0;
}
if (!pgp_write(output, key->checkhash, PGP_CHECKHASH_SIZE)) {
return 0;
}
if (key->s2k_usage != PGP_S2KU_NONE) {
if (!pgp_write(output, key->checkhash, PGP_CHECKHASH_SIZE)) {
return 0;
}
pgp_writer_pop(output);
}else{
uint16_t checksum = pgp_pop_sum16_writer(output);
if (!pgp_write_scalar(output, checksum, 2)) {
return 0;
}
}
return 1;
@ -757,7 +765,7 @@ pgp_write_struct_seckey_ptag(const pgp_seckey_t *key,
/* Ref: RFC4880 Section 5.5.3 */
/* pubkey, excluding MPIs */
length += 1 + 4 + 1 + 1;
length += 1 + 4 + 1;
/* s2k usage */
length += 1;


+ 54
- 0
dist/src/lib/writer.c View File

@ -1406,6 +1406,60 @@ pgp_push_checksum_writer(pgp_output_t *output, pgp_seckey_t *seckey)
/**************************************************************************/
typedef struct {
uint16_t sum;
} sum16_t;
static unsigned
sum16_writer(const uint8_t *src,
const unsigned len,
pgp_error_t **errors,
pgp_writer_t *writer)
{
sum16_t *arg;
unsigned ret = 1;
int n;
arg = pgp_writer_get_arg(writer);
for (n = 0; n < len; ++n) {
arg->sum = (arg->sum + src[n]) & 0xffff;
}
/* write to next stacked writer */
ret = stacked_write(writer, src, len, errors);
/* tidy up and return */
return ret;
}
void
pgp_push_sum16_writer(pgp_output_t *output)
{
sum16_t *sum;
if ((sum = calloc(1, sizeof(*sum))) == NULL) {
(void) fprintf(stderr,
"pgp_push_sum16_writer: bad alloc\n");
} else {
pgp_writer_push(output, sum16_writer,
NULL, NULL, sum);
}
}
uint16_t
pgp_pop_sum16_writer(pgp_output_t *output)
{
uint16_t sum;
sum16_t *arg;
arg = pgp_writer_get_arg(&output->writer);
sum = arg->sum;
pgp_writer_pop(output);
free(arg);
return sum;
}
/**************************************************************************/
#define MAX_PARTIAL_DATA_LENGTH 1073741824
typedef struct {


+ 4
- 0
dist/src/lib/writer.h View File

@ -116,4 +116,8 @@ unsigned pgp_writer_info_finalise(pgp_error_t **, pgp_writer_t *);
void pgp_push_stream_enc_se_ip(pgp_output_t *, const pgp_key_t *, const char *);
void pgp_push_sum16_writer(pgp_output_t *output);
uint16_t pgp_pop_sum16_writer(pgp_output_t *output);
#endif /* WRITER_H_ */

Loading…
Cancel
Save