Skip to content

Commit

Permalink
Add some debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Nov 12, 2023
1 parent 1f7759f commit bdaff3e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/librepgp/stream-parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,7 @@ encrypted_read_packet_data(pgp_source_encrypted_param_t *param)
static rnp_result_t
init_encrypted_src(pgp_parse_handler_t *handler, pgp_source_t *src, pgp_source_t *readsrc)
{
RNP_LOG("here");
if (!init_src_common(src, 0)) {
return RNP_ERROR_OUT_OF_MEMORY;
}
Expand All @@ -2354,11 +2355,13 @@ init_encrypted_src(pgp_parse_handler_t *handler, pgp_source_t *src, pgp_source_t
src->type = PGP_STREAM_ENCRYPTED;

/* Read the packet-related information */
RNP_LOG("here");
rnp_result_t errcode = encrypted_read_packet_data(param);
if (errcode) {
goto finish;
}

RNP_LOG("here");
src->read = (!param->use_cfb()
#ifdef ENABLE_CRYPTO_REFRESH
|| param->is_v2_seipd()
Expand All @@ -2374,11 +2377,13 @@ init_encrypted_src(pgp_parse_handler_t *handler, pgp_source_t *src, pgp_source_t
goto finish;
}

RNP_LOG("here");
/* informing handler about the available pubencs/symencs */
if (handler->on_recipients) {
handler->on_recipients(param->pubencs, param->symencs, handler->param);
}

RNP_LOG("here");
bool have_key;
have_key = false;
/* Trying public-key decryption */
Expand Down Expand Up @@ -2456,15 +2461,19 @@ init_encrypted_src(pgp_parse_handler_t *handler, pgp_source_t *src, pgp_source_t

/* Trying password-based decryption */
if (!have_key && !param->symencs.empty()) {
RNP_LOG("here");
rnp::secure_array<char, MAX_PASSWORD_LENGTH> password;
pgp_password_ctx_t pass_ctx(PGP_OP_DECRYPT_SYM);
if (!pgp_request_password(
handler->password_provider, &pass_ctx, password.data(), password.size())) {
errcode = RNP_ERROR_BAD_PASSWORD;
RNP_LOG("here");
goto finish;
}

RNP_LOG("here");
int intres = encrypted_try_password(param, password.data());
RNP_LOG("here: %d", intres);
if (intres > 0) {
have_key = true;
} else if (intres < 0) {
Expand All @@ -2475,13 +2484,16 @@ init_encrypted_src(pgp_parse_handler_t *handler, pgp_source_t *src, pgp_source_t
}

/* report decryption start to the handler */
RNP_LOG("here");
if (handler->on_decryption_info) {
RNP_LOG("here");
handler->on_decryption_info(param->auth_type == rnp::AuthType::MDC,
param->aead_hdr.aalg,
param->salg,
handler->param);
}

RNP_LOG("here");
if (!have_key) {
RNP_LOG("failed to obtain decrypting key or password");
if (!errcode) {
Expand Down Expand Up @@ -2712,6 +2724,7 @@ init_packet_sequence(pgp_processing_ctx_t &ctx, pgp_source_t &src)
pgp_source_t *lsrc = &src;
size_t srcnum = ctx.sources.size();

RNP_LOG("here");
while (1) {
uint8_t ptag = 0;
if (!src_peek_eq(lsrc, &ptag, 1)) {
Expand Down Expand Up @@ -2848,6 +2861,7 @@ process_pgp_source(pgp_parse_handler_t *handler, pgp_source_t &src)
bool closeout = true;
uint8_t * readbuf = NULL;

RNP_LOG("here");
ctx.handler = *handler;
/* Building readers sequence. Checking whether it is binary data */
if (is_pgp_source(src)) {
Expand Down Expand Up @@ -2902,6 +2916,7 @@ process_pgp_source(pgp_parse_handler_t *handler, pgp_source_t &src)
}
src_close(&datasrc);
} else {
RNP_LOG("here");
if (handler->ctx->detached) {
RNP_LOG("Detached signature expected.");
res = RNP_ERROR_BAD_STATE;
Expand All @@ -2921,6 +2936,7 @@ process_pgp_source(pgp_parse_handler_t *handler, pgp_source_t &src)
if (!handler->dest_provider ||
!handler->dest_provider(handler, &outdest, &closeout, filename, mtime)) {
res = RNP_ERROR_WRITE;
RNP_LOG("here");
goto finish;
}

Expand All @@ -2929,15 +2945,18 @@ process_pgp_source(pgp_parse_handler_t *handler, pgp_source_t &src)
size_t read = 0;
if (!src_read(decsrc, readbuf, PGP_INPUT_CACHE_SIZE, &read)) {
res = RNP_ERROR_GENERIC;
RNP_LOG("here");
break;
}
RNP_LOG("here: %zu", read);
if (!read) {
continue;
}
if (ctx.signed_src) {
signed_src_update(ctx.signed_src, readbuf, read);
}
dst_write(outdest, readbuf, read);
RNP_LOG("here");
if (outdest->werr != RNP_SUCCESS) {
RNP_LOG("failed to output data");
res = RNP_ERROR_WRITE;
Expand All @@ -2961,6 +2980,7 @@ process_pgp_source(pgp_parse_handler_t *handler, pgp_source_t &src)
}

finish:
RNP_LOG("here: %x", (int) res);
free(readbuf);
return res;
}

0 comments on commit bdaff3e

Please sign in to comment.