feat: paper key use module log system

This commit is contained in:
saturneric 2024-09-28 14:37:53 +02:00
parent 8d7546ad5b
commit 5b5e450b8f
3 changed files with 32 additions and 32 deletions

View File

@ -20,6 +20,7 @@
#include <cstdio>
#include "GFModuleCommonUtils.hpp"
#include "output.h"
#include "packets.h"
#include "parse.h"
@ -34,14 +35,14 @@ int extract(FILE *input, FILE *output, enum data_type output_type) {
packet = parse(input, 5, 0);
if (!packet) {
fprintf(stderr, "Unable to find secret key packet\n");
LOG_ERROR("Unable to find secret key packet");
return 1;
}
offset = extract_secrets(packet);
if (offset == -1) return 1;
if (verbose > 1) fprintf(stderr, "Secret offset is %d\n", offset);
if (verbose > 1) FLOG_DEBUG("Secret offset is %d", offset);
calculate_fingerprint(packet, offset, fingerprint);
@ -64,7 +65,7 @@ int extract(FILE *input, FILE *output, enum data_type output_type) {
offset = extract_secrets(packet);
if (offset == -1) return 1;
if (verbose > 1) fprintf(stderr, "Secret subkey offset is %d\n", offset);
if (verbose > 1) FLOG_DEBUG("Secret subkey offset is %d\n", offset);
calculate_fingerprint(packet, offset, fingerprint);

View File

@ -24,6 +24,7 @@
#include <cstdlib>
#include <cstring>
#include "GFModuleCommonUtils.hpp"
#include "GFSDKBasic.h"
#include "output.h"
#include "packets.h"
@ -74,7 +75,7 @@ struct packet *parse(FILE *input, unsigned char want, unsigned char stop) {
} else if (byte >= 224) {
/* Partial body length, so fail (keys can't use
partial body) */
fprintf(stderr, "Invalid partial packet encoding\n");
LOG_ERROR("Invalid partial packet encoding");
goto fail;
} else if (byte >= 192) {
/* 2-byte length */
@ -120,17 +121,16 @@ struct packet *parse(FILE *input, unsigned char want, unsigned char stop) {
break;
default:
fprintf(stderr, "Error: unable to parse old-style length\n");
LOG_ERROR("unable to parse old-style length");
goto fail;
}
}
if (verbose > 1)
fprintf(stderr, "Found packet of type %d, length %d\n", type, length);
if (verbose > 1) {
FLOG_DEBUG("Found packet of type %d, length %d", type, length);
}
} else {
fprintf(stderr,
"Error: unable to parse OpenPGP packets"
" (is this armored data?)\n");
LOG_ERROR("unable to parse OpenPGP packets (is this armored data?)");
goto fail;
}
@ -142,7 +142,7 @@ struct packet *parse(FILE *input, unsigned char want, unsigned char stop) {
packet->len = length;
packet->size = length;
if (fread(packet->buf, 1, packet->len, input) < packet->len) {
fprintf(stderr, "Short read on packet type %d\n", type);
FLOG_ERROR("Short read on packet type %d", type);
goto fail;
}
break;
@ -201,7 +201,7 @@ ssize_t extract_secrets(struct packet *packet) {
public stuff. */
if (packet->buf[0] == 3) {
fprintf(stderr, "Version 3 (PGP 2.x style) keys are not supported.\n");
LOG_ERROR("Version 3 (PGP 2.x style) keys are not supported.");
return -1;
} else if (packet->buf[0] == 4) {
/* Jump 5 bytes in. That gets us past 1 byte of version, and 4
@ -268,8 +268,7 @@ ssize_t extract_secrets(struct packet *packet) {
default:
/* What algorithm? */
fprintf(stderr, "Unable to parse algorithm %u\n",
packet->buf[offset - 1]);
FLOG_ERROR("Unable to parse algorithm %u", packet->buf[offset - 1]);
return -1;
}
@ -289,7 +288,7 @@ struct packet *read_secrets_file(FILE *secrets, enum data_type input_type) {
packet = append_packet(packet, buffer, got);
if (got == 0 && !feof(secrets)) {
fprintf(stderr, "Error: unable to read secrets file\n");
LOG_ERROR("unable to read secrets file");
free_packet(packet);
return NULL;
}
@ -315,8 +314,8 @@ struct packet *read_secrets_file(FILE *secrets, enum data_type input_type) {
linenum = atoi(line);
if (linenum != next_linenum) {
fprintf(stderr, "Error: missing line number %u (saw %u)\n",
next_linenum, linenum);
FLOG_ERROR("missing line number %u (saw %u)", next_linenum,
linenum);
free_packet(packet);
return NULL;
} else
@ -340,10 +339,9 @@ struct packet *read_secrets_file(FILE *secrets, enum data_type input_type) {
if (sscanf(tok, "%06lX", &new_crc)) {
if (did_digit) {
if ((new_crc & 0xFFFFFFL) != (line_crc & 0xFFFFFFL)) {
fprintf(stderr,
"CRC on line %d does not"
" match (%06lX!=%06lX)\n",
linenum, new_crc & 0xFFFFFFL, line_crc & 0xFFFFFFL);
FLOG_ERROR("CRC on line %d does not match (%06lX!=%06lX)",
linenum, new_crc & 0xFFFFFFL,
line_crc & 0xFFFFFFL);
if (!ignore_crc_error) {
free_packet(packet);
return NULL;
@ -368,7 +366,7 @@ struct packet *read_secrets_file(FILE *secrets, enum data_type input_type) {
tok = next;
}
} else {
fprintf(stderr, "No colon ':' found in line %u\n", linenum);
FLOG_ERROR("No colon ':' found in line %u", linenum);
free_packet(packet);
return NULL;
}
@ -381,7 +379,7 @@ struct packet *read_secrets_file(FILE *secrets, enum data_type input_type) {
do_crc24(&all_crc, packet->buf, packet->len);
if ((my_crc & 0xFFFFFFL) != (all_crc & 0xFFFFFFL)) {
fprintf(stderr, "CRC of secret does not match (%06lX!=%06lX)\n",
FLOG_ERROR("CRC of secret does not match (%06lX!=%06lX)",
my_crc & 0xFFFFFFL, all_crc & 0xFFFFFFL);
if (!ignore_crc_error) {
free_packet(packet);
@ -389,7 +387,7 @@ struct packet *read_secrets_file(FILE *secrets, enum data_type input_type) {
}
}
} else {
fprintf(stderr, "CRC of secret is missing\n");
LOG_ERROR("CRC of secret is missing");
if (!ignore_crc_error) {
free_packet(packet);
return NULL;

View File

@ -24,6 +24,7 @@
#include <cstdlib>
#include <cstring>
#include "GFModuleCommonUtils.hpp"
#include "GFSDKBasic.h"
#include "output.h"
#include "packets.h"
@ -41,7 +42,7 @@ static auto extract_keys(struct packet *packet) -> struct key * {
/* Check the version */
if (packet->len && packet->buf[0] != 0) {
fprintf(stderr, "Cannot handle secrets file version %d\n", packet->buf[0]);
FLOG_ERROR("Cannot handle secrets file version %d", packet->buf[0]);
return NULL;
}
@ -68,7 +69,7 @@ static auto extract_keys(struct packet *packet) -> struct key * {
newkey->packet = append_packet(NULL, &packet->buf[idx], len);
idx += len;
} else {
fprintf(stderr, "Warning: Short data in secret image\n");
LOG_WARN("Short data in secret image");
free(newkey);
break;
}
@ -76,11 +77,11 @@ static auto extract_keys(struct packet *packet) -> struct key * {
newkey->next = key;
key = newkey;
} else {
fprintf(stderr, "Warning: Corrupt data in secret image\n");
LOG_WARN("Corrupt data in secret image");
break;
}
} else {
fprintf(stderr, "Warning: Short header in secret image\n");
LOG_WARN("Short header in secret image");
break;
}
}
@ -105,7 +106,7 @@ auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
int test = fgetc(secrets);
if (test == EOF) {
fprintf(stderr, "Unable to check type of secrets file\n");
LOG_ERROR("Unable to check type of secrets file");
return 1;
} else if (isascii(test) && isprint(test))
input_type = BASE16;
@ -170,11 +171,11 @@ auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
free_keys(keys);
output_end();
} else {
fprintf(stderr, "Unable to parse secret data\n");
LOG_ERROR("Unable to parse secret data");
return 1;
}
} else {
fprintf(stderr, "Unable to read secrets file\n");
LOG_ERROR("Unable to read secrets file");
return 1;
}