mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 20:00:58 +01:00
last update was wrong, since pbp exported keys are base85 encoded, fixed that. incorporated the git/base85.c and added source padding to it
This commit is contained in:
@@ -381,13 +381,26 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
||||
int pnum;
|
||||
pbp_pubkey_t *b = ucmalloc(sizeof(pbp_pubkey_t));
|
||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||
|
||||
// fetch the key from the file
|
||||
if(fread(b, 1, sizeof(pbp_pubkey_t), in) < sizeof(pbp_pubkey_t) - 1024) {
|
||||
fatal("PBP key seems to be too small, maybe it's not a PBP key\n");
|
||||
unsigned char *buf = ucmalloc(2048);
|
||||
unsigned char *bin = ucmalloc(2048);
|
||||
size_t buflen;
|
||||
size_t klen;
|
||||
|
||||
buflen = fread(buf, 1, 2048, in); // base85 encoded
|
||||
klen = (buflen / 5) * 4;
|
||||
|
||||
if(decode_85(bin, (char *)buf, klen) != 0)
|
||||
goto errimp1;
|
||||
|
||||
if(klen < sizeof(pbp_pubkey_t) - 1024 - crypto_sign_BYTES) {
|
||||
fatal("PBP key seems to be too small, maybe it's not a PBP key (got %ld, expected %ld)\n",
|
||||
klen, sizeof(pbp_pubkey_t) - 1024);
|
||||
goto errimp1;
|
||||
}
|
||||
|
||||
// FIXME: or use first part as sig and verify
|
||||
memcpy(b, &bin[crypto_sign_BYTES], klen - crypto_sign_BYTES);
|
||||
|
||||
// parse the date
|
||||
date = ucmalloc(19);
|
||||
memcpy(date, b->iso_ctime, 18);
|
||||
@@ -395,7 +408,7 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
||||
struct tm c;
|
||||
if(strptime(date, "%Y-%m-%dT%H:%M:%S", &c) == NULL) {
|
||||
fatal("Failed to parse creation time in PBP public key file (<%s>)\n", date);
|
||||
goto errimp1;
|
||||
goto errimp2;
|
||||
}
|
||||
|
||||
// parse the name
|
||||
@@ -422,12 +435,18 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
|
||||
|
||||
free(b);
|
||||
free(date);
|
||||
free(buf);
|
||||
free(bin);
|
||||
goto kimp;
|
||||
|
||||
errimp2:
|
||||
free(bin);
|
||||
|
||||
errimp1:
|
||||
free(date);
|
||||
free(pub);
|
||||
free(b);
|
||||
free(buf);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -226,39 +226,29 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
|
||||
// >>> dates='{:<32}{:<32}'.format(c.isoformat(), c.isoformat())
|
||||
// >>> dates
|
||||
// '2014-01-28T13:30:32.674394 2014-01-28T13:30:32.674394 '
|
||||
size_t namelen = strlen(key->owner) + 3 + strlen(key->mail);
|
||||
size_t rawsize = (crypto_box_PUBLICKEYBYTES * 2) + crypto_sign_PUBLICKEYBYTES +\
|
||||
64 + namelen;
|
||||
size_t pos = 0;
|
||||
unsigned char *raw = ucmalloc(rawsize);
|
||||
char *dates = ucmalloc(65);
|
||||
char *name = ucmalloc(strlen(key->owner) + 3 + strlen(key->mail));
|
||||
|
||||
memcpy(raw, key->pub, crypto_box_PUBLICKEYBYTES);
|
||||
pos += crypto_box_PUBLICKEYBYTES;
|
||||
|
||||
memcpy(&raw[pos], key->edpub, crypto_sign_PUBLICKEYBYTES);
|
||||
pos += crypto_sign_PUBLICKEYBYTES;
|
||||
|
||||
memcpy(&raw[pos], key->pub, crypto_box_PUBLICKEYBYTES);
|
||||
pos += crypto_box_PUBLICKEYBYTES;
|
||||
size_t namelen = strlen(key->owner) + 2 + strlen(key->mail);
|
||||
pbp_pubkey_t *b = ucmalloc(sizeof(pbp_pubkey_t));
|
||||
memcpy(b->pub, key->pub, crypto_box_PUBLICKEYBYTES);
|
||||
memcpy(b->edpub, key->edpub, crypto_sign_PUBLICKEYBYTES);
|
||||
memcpy(b->sigpub, key->pub, crypto_box_PUBLICKEYBYTES);
|
||||
sprintf(b->name, "%s<%s>", key->owner, key->mail);
|
||||
|
||||
struct tm *v;
|
||||
time_t vt = t + 31536000;
|
||||
v = localtime(&vt);
|
||||
|
||||
sprintf(dates, "%04d-%02d-%02dT%02d:%02d:%02d %04d-%02d-%02dT%02d:%02d:%02d ",
|
||||
char *date = ucmalloc(65);
|
||||
|
||||
sprintf(date, "%04d-%02d-%02dT%02d:%02d:%02d %04d-%02d-%02dT%02d:%02d:%02d ",
|
||||
c->tm_year+1900-1, c->tm_mon+1, c->tm_mday, // wtf? why -1?
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
v->tm_year+1900-1, v->tm_mon+1, v->tm_mday,
|
||||
v->tm_hour, v->tm_min, v->tm_sec);
|
||||
|
||||
sprintf(name, "%s<%s>", key->owner, key->mail);
|
||||
memcpy(b->iso_ctime, date, 32);
|
||||
memcpy(b->iso_expire, &date[32], 32);
|
||||
|
||||
memcpy(&raw[pos], dates, 64);
|
||||
pos += 64;
|
||||
|
||||
memcpy(&raw[pos], name, namelen);
|
||||
size_t pbplen = sizeof(pbp_pubkey_t) - (1024 - namelen);
|
||||
|
||||
pcp_key_t *secret = NULL;
|
||||
secret = pcp_find_primary_secret();
|
||||
@@ -273,10 +263,16 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
|
||||
|
||||
secret = pcpkey_decrypt(secret, passphrase);
|
||||
if(secret != NULL) {
|
||||
size_t siglen = rawsize + crypto_sign_BYTES;
|
||||
unsigned char *sig = pcp_ed_sign(raw, rawsize, secret);
|
||||
if(sig != NULL)
|
||||
fwrite(sig, 1, siglen, out);
|
||||
unsigned char *sig = pcp_ed_sign((unsigned char*)b, pbplen, secret);
|
||||
if(sig != NULL) {
|
||||
size_t siglen = pbplen + crypto_sign_BYTES;
|
||||
size_t blen = ((siglen / 4) * 5) + siglen + 1;
|
||||
char *b85sig = ucmalloc(blen);
|
||||
encode_85(b85sig, sig, siglen);
|
||||
fprintf(out, "%s", b85sig);
|
||||
free(b85sig);
|
||||
free(sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "pcp.h"
|
||||
#include "keymgmt.h"
|
||||
#include "keyhash.h"
|
||||
#include "base85.h"
|
||||
|
||||
void pcp_dumpkey(pcp_key_t *k);
|
||||
void pcp_dumppubkey(pcp_pubkey_t *k);
|
||||
|
||||
Reference in New Issue
Block a user