mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
fixed yet another endianess problem, now always using the raw key values for export, sotrage and checksum calculation
This commit is contained in:
@@ -52,7 +52,7 @@ int pcp_storekey (pcp_key_t *key) {
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
}
|
||||
|
||||
if(pcpvault_addkey(vault, key, sizeof(pcp_key_t), key->type) == 0) {
|
||||
if(pcpvault_addkey(vault, key, key->type) == 0) {
|
||||
if(vault->isnew)
|
||||
fprintf(stderr, "new vault created, ");
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", key->id, vault->filename);
|
||||
@@ -360,14 +360,15 @@ int pcp_importsecret (vault_t *vault, FILE *in) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(clen != sizeof(pcp_key_t)) {
|
||||
if(clen != PCP_RAW_KEYSIZE) {
|
||||
fatal("Error: decoded input didn't result to a proper sized key! (got %d bytes)\n", clen);
|
||||
free(z85decoded);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// all good now
|
||||
pcp_key_t *key = (pcp_key_t *)z85decoded;
|
||||
// all good now, import the blob
|
||||
pcp_key_t *key = ucmalloc(sizeof(pcp_key_t));
|
||||
memcpy(key, z85decoded, PCP_RAW_KEYSIZE);
|
||||
key2native(key);
|
||||
|
||||
if(debug)
|
||||
@@ -385,8 +386,7 @@ int pcp_importsecret (vault_t *vault, FILE *in) {
|
||||
if(nkeys == 0)
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
|
||||
if(pcpvault_addkey(vault, (void *)key, sizeof(pcp_key_t),
|
||||
PCP_KEY_TYPE_SECRET) == 0) {
|
||||
if(pcpvault_addkey(vault, (void *)key, PCP_KEY_TYPE_SECRET) == 0) {
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", key->id, vault->filename);
|
||||
return 0;
|
||||
}
|
||||
@@ -411,20 +411,21 @@ int pcp_importpublic (vault_t *vault, FILE *in) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(clen != sizeof(pcp_pubkey_t)) {
|
||||
if(clen != PCP_RAW_PUBKEYSIZE) {
|
||||
fatal("Error: decoded input didn't result to a proper sized key!\n", clen);
|
||||
free(z85decoded);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// all good now
|
||||
pcp_pubkey_t *pub = (pcp_pubkey_t *)z85decoded;
|
||||
pcp_pubkey_t *pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||
memcpy(pub, z85decoded, PCP_RAW_PUBKEYSIZE);
|
||||
pubkey2native(pub);
|
||||
|
||||
if(debug)
|
||||
pcp_dumppubkey(pub);
|
||||
if(pcp_sanitycheck_pub(pub) == 0) {
|
||||
if(pcpvault_addkey(vault, (void *)pub, sizeof(pcp_pubkey_t), PCP_KEY_TYPE_PUBLIC) == 0) {
|
||||
if(pcpvault_addkey(vault, (void *)pub, PCP_KEY_TYPE_PUBLIC) == 0) {
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", pub->id, vault->filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -59,13 +59,16 @@ int pcptext_infile(char *infile) {
|
||||
size_t clen;
|
||||
unsigned char *bin = pcp_z85_decode((char *)z85, &clen);
|
||||
free(z85);
|
||||
|
||||
|
||||
if(bin == NULL) {
|
||||
fprintf(stdout, "%s isn't properly Z85 encoded - unknown file type.\n", infile);
|
||||
goto errtinf1;
|
||||
}
|
||||
|
||||
if(clen == sizeof(pcp_key_t)) {
|
||||
//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);
|
||||
@@ -82,7 +85,7 @@ int pcptext_infile(char *infile) {
|
||||
}
|
||||
}
|
||||
|
||||
if(clen == sizeof(pcp_pubkey_t)) {
|
||||
if(clen == PCP_RAW_PUBKEYSIZE) {
|
||||
// public key?
|
||||
pcp_pubkey_t *key = (pcp_pubkey_t *)bin;
|
||||
pubkey2native(key);
|
||||
@@ -203,9 +206,13 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
|
||||
void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
size_t zlen;
|
||||
key2be(key);
|
||||
char *z85encoded = pcp_z85_encode((unsigned char*)key, sizeof(pcp_key_t), &zlen);
|
||||
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);
|
||||
@@ -237,9 +244,14 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
size_t zlen;
|
||||
pubkey2be(key);
|
||||
char *z85encoded = pcp_z85_encode((unsigned char*)key, sizeof(pcp_pubkey_t), &zlen);
|
||||
|
||||
void *blob = ucmalloc(PCP_RAW_PUBKEYSIZE);
|
||||
pcp_pubkeyblob(blob, key);
|
||||
char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_PUBKEYSIZE, &zlen);
|
||||
pubkey2native(key);
|
||||
|
||||
free(blob);
|
||||
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
@@ -331,7 +343,7 @@ void pcp_dumpkey(pcp_key_t *k) {
|
||||
|
||||
printf(" id: %s\n", k->id);
|
||||
|
||||
printf(" ctime: %ld\n", k->ctime);
|
||||
printf(" ctime: %ld\n", (long int)k->ctime);
|
||||
|
||||
printf(" version: 0x%08X\n", k->version);
|
||||
|
||||
@@ -358,7 +370,7 @@ void pcp_dumppubkey(pcp_pubkey_t *k) {
|
||||
|
||||
printf(" id: %s\n", k->id);
|
||||
|
||||
printf(" ctime: %ld\n", k->ctime);
|
||||
printf(" ctime: %ld\n", (long int)k->ctime);
|
||||
|
||||
printf(" version: 0x%08X\n", k->version);
|
||||
|
||||
@@ -436,7 +448,7 @@ void pcpexport_yaml(char *outfile) {
|
||||
fprintf(out, " id: %s\n", s->id);
|
||||
fprintf(out, " owner: %s\n", s->owner);
|
||||
fprintf(out, " mail: %s\n", s->mail);
|
||||
fprintf(out, " ctime: %ld\n", s->ctime);
|
||||
fprintf(out, " ctime: %ld\n", (long int)s->ctime);
|
||||
fprintf(out, " version: %08x\n", s->version);
|
||||
fprintf(out, " serial: %08x\n", s->serial);
|
||||
fprintf(out, " type: %s\n",
|
||||
@@ -461,7 +473,7 @@ void pcpexport_yaml(char *outfile) {
|
||||
fprintf(out, " id: %s\n", p->id);
|
||||
fprintf(out, " owner: %s\n", p->owner);
|
||||
fprintf(out, " mail: %s\n", p->mail);
|
||||
fprintf(out, " ctime: %ld\n", p->ctime);
|
||||
fprintf(out, " ctime: %ld\n", (long int)p->ctime);
|
||||
fprintf(out, " version: %08x\n", p->version);
|
||||
fprintf(out, " serial: %08x\n", p->serial);
|
||||
fprintf(out, " type: public\n");
|
||||
|
||||
Reference in New Issue
Block a user