mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 20:00:58 +01:00
changed z85 header and comment syntax and parser
This commit is contained in:
@@ -65,43 +65,7 @@ int pcptext_infile(char *infile) {
|
||||
goto errtinf1;
|
||||
}
|
||||
|
||||
/* fprintf(stdout, "have: %d, secret: %d, public: %d, sig: %d, hh: %d\n", (int)clen, */
|
||||
/* (int)sizeof(pcp_key_t), (int)sizeof(pcp_pubkey_t), (int)sizeof(pcp_sig_t), (int)sizeof(UT_hash_handle)); */
|
||||
|
||||
if(clen == PCP_RAW_KEYSIZE) {
|
||||
/* secret key? */
|
||||
pcp_key_t *key = (pcp_key_t *)bin;
|
||||
key2native(key);
|
||||
if(pcp_sanitycheck_key(key) == 0) {
|
||||
fprintf(stdout, "%s is a secret key file:\n", infile);
|
||||
pcpkey_print(key, stdout);
|
||||
free(key);
|
||||
goto tdone;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, "%s looks like a secret key but failed sanity checking.\n", infile);
|
||||
free(key);
|
||||
goto errtinf1;
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: can't determine keytype by using its size */
|
||||
if(clen == PCP_RAW_PUBKEYSIZE) {
|
||||
/* public key? */
|
||||
pcp_pubkey_t *key = (pcp_pubkey_t *)bin;
|
||||
pubkey2native(key);
|
||||
if(pcp_sanitycheck_pub(key) == 0) {
|
||||
fprintf(stdout, "%s is a public key file:\n", infile);
|
||||
// pcppubkey_print(key, stdout, 0);
|
||||
free(key);
|
||||
goto tdone;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, "%s looks like a publickey but failed sanity checking.\n", infile);
|
||||
free(key);
|
||||
goto errtinf1;
|
||||
}
|
||||
}
|
||||
/* FIXME: try to import pk or sk */
|
||||
|
||||
/* still there? */
|
||||
fprintf(stdout, "%s looks Z85 encoded but otherwise unknown and is possibly encrypted.\n", infile);
|
||||
@@ -182,16 +146,13 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
|
||||
fprintf(out, " Generated by: %s Version %d.%d.%d\n",
|
||||
PCP_ME, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
||||
|
||||
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
||||
fprintf(out, " Owner: %s\n", key->owner);
|
||||
fprintf(out, " Mail: %s\n", key->mail);
|
||||
|
||||
fprintf(out, " Owner: %s\n", key->owner);
|
||||
fprintf(out, " Mail: %s\n", key->mail);
|
||||
|
||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||
fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen));
|
||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||
fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen));
|
||||
|
||||
/* 2004-06-14T23:34:30. */
|
||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||
@@ -199,23 +160,23 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
|
||||
unsigned char *hash = pcppubkey_getchecksum(key);
|
||||
fprintf(out, " Checksum: ");
|
||||
fprintf(out, " Checksum: ");
|
||||
|
||||
int i;
|
||||
for ( i = 0;i <15 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]);
|
||||
fprintf(out, "%02X", hash[15]);
|
||||
fprintf(out, "\n ");
|
||||
fprintf(out, "\n ");
|
||||
for ( i = 16;i <31 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]);
|
||||
fprintf(out, "%02X", hash[31]);
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
|
||||
char *r = pcppubkey_get_art(key);
|
||||
fprintf(out, " Random Art ID: ");
|
||||
for (i=0; i<strlen(r); ++i) {
|
||||
if(r[i] == '\n') {
|
||||
fprintf(out, "\n ");
|
||||
fprintf(out, "\n ");
|
||||
}
|
||||
else {
|
||||
fprintf(out, "%c", r[i]);
|
||||
@@ -228,44 +189,24 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
}
|
||||
|
||||
void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
size_t zlen;
|
||||
key2be(key);
|
||||
void *blob = ucmalloc(PCP_RAW_KEYSIZE);
|
||||
pcp_seckeyblob(blob, key);
|
||||
char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_KEYSIZE, &zlen);
|
||||
key2native(key);
|
||||
|
||||
free(blob);
|
||||
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
|
||||
fprintf(out, "%s\n", PCP_KEY_HEADER);
|
||||
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
||||
|
||||
fprintf(out, " Generated by: %s Version %d.%d.%d\n",
|
||||
PCP_ME, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
|
||||
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
||||
|
||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||
|
||||
/* 2004-06-14T23:34:30. */
|
||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
|
||||
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
|
||||
fprintf(out, "\n%s\n", z85encoded);
|
||||
|
||||
fprintf(out, "%s\n", PCP_KEY_FOOTER);
|
||||
|
||||
free(z85encoded);
|
||||
}
|
||||
|
||||
|
||||
void pcpkey_printshortinfo(pcp_key_t *key) {
|
||||
int i;
|
||||
printf(" Key-ID: 0x%s\n", key->id);
|
||||
|
||||
Reference in New Issue
Block a user