|
|
@ -208,6 +208,7 @@ read_partial_data(pgp_stream_t *stream, |
|
|
|
pgp_reader_t *readinfo, |
|
|
|
void *dest, size_t length) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
unsigned n; |
|
|
|
|
|
|
|
if (pgp_get_debug_level(__FILE__)) { |
|
|
@ -259,6 +260,7 @@ static int |
|
|
|
sub_base_read(pgp_stream_t *stream, void *dest, size_t length, pgp_error_t **errors, |
|
|
|
pgp_reader_t *readinfo, pgp_cbdata_t *cbinfo) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
size_t n; |
|
|
|
|
|
|
|
/* reading more than this would look like an error */ |
|
|
@ -271,9 +273,8 @@ sub_base_read(pgp_stream_t *stream, void *dest, size_t length, pgp_error_t **err |
|
|
|
if (!readinfo->coalescing && readinfo->virtualc && readinfo->virtualoff < readinfo->virtualc) { |
|
|
|
r = read_partial_data(stream, readinfo, (char*) dest + n, length - n); |
|
|
|
}else{ |
|
|
|
r = readinfo->reader(stream, (char *) dest + n, |
|
|
|
length - n, errors, |
|
|
|
readinfo, cbinfo); |
|
|
|
printf("%s miau\n",__FUNCTION__); |
|
|
|
r = readinfo->reader(stream, (char *) dest + n, length - n, errors, readinfo, cbinfo); |
|
|
|
} |
|
|
|
if (r > (int)(length - n)) { |
|
|
|
(void) fprintf(stderr, "sub_base_read: bad read\n"); |
|
|
@ -312,8 +313,7 @@ sub_base_read(pgp_stream_t *stream, void *dest, size_t length, pgp_error_t **err |
|
|
|
(void) fprintf(stderr, "sub_base_read: bad realloc\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
(void) memcpy(readinfo->accumulated + readinfo->alength, dest, |
|
|
|
n); |
|
|
|
(void) memcpy(readinfo->accumulated + readinfo->alength, dest, n); |
|
|
|
} |
|
|
|
/* we track length anyway, because it is used for packet offsets */ |
|
|
|
readinfo->alength += (unsigned)n; |
|
|
@ -350,23 +350,20 @@ full_read(pgp_stream_t *stream, uint8_t *dest, |
|
|
|
pgp_error_t **errors, |
|
|
|
pgp_reader_t *readinfo, |
|
|
|
pgp_cbdata_t *cbinfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
size_t t; |
|
|
|
int r = 0; /* preset in case some loon calls with length |
|
|
|
* == 0 */ |
|
|
|
|
|
|
|
* == 0 */ |
|
|
|
for (t = 0; t < length;) { |
|
|
|
r = sub_base_read(stream, dest + t, length - t, errors, readinfo, |
|
|
|
cbinfo); |
|
|
|
r = sub_base_read(stream, dest + t, length - t, errors, readinfo, cbinfo); |
|
|
|
if (r <= 0) { |
|
|
|
*last_read = r; |
|
|
|
return t; |
|
|
|
} |
|
|
|
t += (size_t)r; |
|
|
|
} |
|
|
|
|
|
|
|
*last_read = r; |
|
|
|
|
|
|
|
return t; |
|
|
|
} |
|
|
|
|
|
|
@ -443,6 +440,7 @@ pgp_limited_read(pgp_stream_t *stream, uint8_t *dest, |
|
|
|
pgp_reader_t *readinfo, |
|
|
|
pgp_cbdata_t *cbinfo) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
size_t r; |
|
|
|
int lr; |
|
|
|
|
|
|
@ -492,8 +490,8 @@ static unsigned |
|
|
|
limread(uint8_t *dest, unsigned length, |
|
|
|
pgp_region_t *region, pgp_stream_t *info) |
|
|
|
{ |
|
|
|
return pgp_limited_read(info, dest, length, region, &info->errors, |
|
|
|
&info->readinfo, &info->cbinfo); |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
return pgp_limited_read(info, dest, length, region, &info->errors, &info->readinfo, &info->cbinfo); |
|
|
|
} |
|
|
|
|
|
|
|
#if 0 |
|
|
@ -643,6 +641,7 @@ static int |
|
|
|
limited_read_time(time_t *dest, pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
uint8_t c; |
|
|
|
time_t mytime = 0; |
|
|
|
int i; |
|
|
@ -696,6 +695,7 @@ limread_mpi(BIGNUM **pbn, pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
limread_mpi(gsk_buffer *pbn, pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
#endif |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
uint8_t buf[NETPGP_BUFSIZ] = ""; |
|
|
|
/* an MPI has a 2 byte length part. |
|
|
|
* Length is given in bits, so the |
|
|
@ -866,6 +866,7 @@ static int |
|
|
|
limited_read_new_length(unsigned *length, pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
uint8_t c = 0x0; |
|
|
|
pgp_reader_t *readinfo = &stream->readinfo; |
|
|
|
|
|
|
@ -1025,7 +1026,8 @@ copy_sig_info(pgp_sig_info_t *dst, const pgp_sig_info_t *src) |
|
|
|
(void) memcpy(dst, src, sizeof(*src)); |
|
|
|
|
|
|
|
printf("%s: src->v4_hashlen %d\n",__FUNCTION__,src->v4_hashlen); |
|
|
|
if ((dst->v4_hashed = calloc(1, src->v4_hashlen)) == NULL) { |
|
|
|
//if ((dst->v4_hashed = calloc(1, src->v4_hashlen)) == NULL) { |
|
|
|
if ((dst->v4_hashed = calloc(1, 20)) == NULL) { |
|
|
|
(void) fprintf(stderr, "copy_sig_info: bad alloc\n"); |
|
|
|
} else { |
|
|
|
(void) memcpy(dst->v4_hashed, src->v4_hashed, src->v4_hashlen); |
|
|
@ -1403,6 +1405,7 @@ static int |
|
|
|
parse_pubkey_data(pgp_pubkey_t *key, pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
uint8_t c = 0x0; |
|
|
|
|
|
|
|
if (region->readc != 0) { |
|
|
@ -1498,6 +1501,7 @@ static int |
|
|
|
parse_pubkey(pgp_content_enum tag, pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
|
|
|
|
if (!parse_pubkey_data(&pkt.u.pubkey, region, stream)) { |
|
|
@ -2071,6 +2075,7 @@ parse_sig_subpkts(pgp_sig_t *sig, |
|
|
|
pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_region_t subregion; |
|
|
|
pgp_packet_t pkt; |
|
|
|
|
|
|
@ -2118,6 +2123,7 @@ parse_sig_subpkts(pgp_sig_t *sig, |
|
|
|
static int |
|
|
|
parse_v4_sig(pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
uint8_t c = 0x0; |
|
|
|
|
|
|
@ -2302,6 +2308,7 @@ error_unalloc_v4_hashed: |
|
|
|
static int |
|
|
|
parse_sig(pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
uint8_t c = 0x0; |
|
|
|
|
|
|
@ -2333,6 +2340,7 @@ parse_sig(pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
static int |
|
|
|
parse_compressed(pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
uint8_t c = 0x0; |
|
|
|
|
|
|
@ -2387,6 +2395,7 @@ parse_hash_init(pgp_stream_t *stream, pgp_hash_alg_t type, |
|
|
|
static int |
|
|
|
parse_one_pass(pgp_region_t * region, pgp_stream_t * stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
uint8_t c = 0x0; |
|
|
|
|
|
|
@ -2465,6 +2474,7 @@ parse_hash_data(pgp_stream_t *stream, const void *data, |
|
|
|
static int |
|
|
|
parse_litdata(pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_memory_t *mem; |
|
|
|
pgp_packet_t pkt; |
|
|
|
uint8_t c = 0x0; |
|
|
@ -2618,6 +2628,7 @@ consume_packet(pgp_region_t *region, pgp_stream_t *stream, unsigned warn) |
|
|
|
static int |
|
|
|
parse_seckey(pgp_content_enum tag, pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
pgp_region_t encregion; |
|
|
|
pgp_region_t *saved_region = NULL; |
|
|
@ -3001,6 +3012,7 @@ static int |
|
|
|
parse_pk_sesskey(pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
const pgp_seckey_t *secret; |
|
|
|
pgp_packet_t sesskey; |
|
|
|
pgp_packet_t pkt; |
|
|
@ -3176,68 +3188,6 @@ parse_pk_sesskey(pgp_region_t *region, |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
#if 0 |
|
|
|
static int |
|
|
|
decrypt_se_data(pgp_content_enum tag, pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
|
{ |
|
|
|
pgp_crypt_t *decrypt; |
|
|
|
const int printerrors = 1; |
|
|
|
int r = 1; |
|
|
|
|
|
|
|
decrypt = pgp_get_decrypt(stream); |
|
|
|
if (decrypt) { |
|
|
|
pgp_region_t encregion; |
|
|
|
unsigned b = (unsigned)decrypt->blocksize; |
|
|
|
uint8_t buf[PGP_MAX_BLOCK_SIZE + 2] = ""; |
|
|
|
|
|
|
|
pgp_reader_push_decrypt(stream, decrypt, region); |
|
|
|
|
|
|
|
pgp_init_subregion(&encregion, NULL); |
|
|
|
encregion.length = b + 2; |
|
|
|
|
|
|
|
if (!exact_limread(buf, b + 2, &encregion, stream)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if (buf[b - 2] != buf[b] || buf[b - 1] != buf[b + 1]) { |
|
|
|
pgp_reader_pop_decrypt(stream); |
|
|
|
PGP_ERROR_4(&stream->errors, |
|
|
|
PGP_E_PROTO_BAD_SYMMETRIC_DECRYPT, |
|
|
|
"Bad symmetric decrypt (%02x%02x vs %02x%02x)", |
|
|
|
buf[b - 2], buf[b - 1], buf[b], buf[b + 1]); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if (tag == PGP_PTAG_CT_SE_DATA_BODY) { |
|
|
|
decrypt->decrypt_resync(decrypt); |
|
|
|
decrypt->block_encrypt(decrypt, decrypt->civ, |
|
|
|
decrypt->civ); |
|
|
|
} |
|
|
|
r = pgp_parse(stream, !printerrors); |
|
|
|
|
|
|
|
pgp_reader_pop_decrypt(stream); |
|
|
|
} else { |
|
|
|
pgp_packet_t pkt; |
|
|
|
|
|
|
|
while (region->readc < region->length) { |
|
|
|
unsigned len; |
|
|
|
|
|
|
|
len = region->length - region->readc; |
|
|
|
if (len > sizeof(pkt.u.se_data_body.data)) |
|
|
|
len = sizeof(pkt.u.se_data_body.data); |
|
|
|
|
|
|
|
if (!limread(pkt.u.se_data_body.data, len, |
|
|
|
region, stream)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
pkt.u.se_data_body.length = len; |
|
|
|
CALLBACK(tag, &stream->cbinfo, &pkt); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return r; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
static int |
|
|
|
decrypt_se_ip_data(pgp_content_enum tag, pgp_region_t *region, |
|
|
|
pgp_stream_t *stream) |
|
|
@ -3377,6 +3327,7 @@ parse_mdc(pgp_region_t *region, pgp_stream_t *stream) |
|
|
|
static int |
|
|
|
parse_packet(pgp_stream_t *stream, uint32_t *pktlen) |
|
|
|
{ |
|
|
|
printf("%s\n",__FUNCTION__); |
|
|
|
pgp_packet_t pkt; |
|
|
|
pgp_region_t region; |
|
|
|
uint8_t ptag; |
|
|
|