moved the actual public key export code out into the lib (mgmt.c). cmdline client does only armor the blobs, if neccessary. Also, armored pubkey exports don't contain any comments anymore.

This commit is contained in:
TLINDEN
2014-02-10 11:37:42 +01:00
parent 79392eb6c7
commit efdf2987ae
6 changed files with 234 additions and 275 deletions

View File

@@ -22,20 +22,72 @@
#include "mgmt.h"
Buffer *pcp_export_pbp_pub(pcp_key_t *sk) {
struct tm *v, *c;
unsigned char *signature = NULL;
char *date = NULL;
Buffer *pcp_get_rfc_pub (pcp_pubkey_t *key, pcp_key_t *sk) {
Buffer *out = buffer_new(320, "pbp01");
Buffer *sig = buffer_new(320, "pbsig01");
/* add raw key material */
buffer_add(sig, sk->edpub, crypto_sign_PUBLICKEYBYTES);
buffer_add(sig, sk->edpub, crypto_sign_PUBLICKEYBYTES);
buffer_add(sig, sk->pub, crypto_box_PUBLICKEYBYTES);
/* add creatioin and expire time as 32byte iso time string */
time_t t = (time_t)sk->ctime;
c = localtime(&t);
time_t vt = t + 31536000;
v = localtime(&vt);
date = ucmalloc(65);
sprintf(date, "%04d-%02d-%02dT%02d:%02d:%02d.000000 %04d-%02d-%02dT%02d:%02d:%02d.000000 ",
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);
buffer_add(sig, date, 64);
/* add owner */
buffer_add(sig, sk->owner, strlen(sk->owner));
/* calculate the signed key blob */
signature = pcp_ed_sign(buffer_get(sig), buffer_size(sig), sk);
if(signature == NULL)
goto exppbperr01;
/* put it out */
buffer_add_buf(out, sig);
free(date);
buffer_free(sig);
free(v);
return out;
exppbperr01:
buffer_free(sig);
buffer_free(out);
free(date);
free(v);
return NULL;
}
Buffer *pcp_export_rfc_pub (pcp_key_t *sk) {
Buffer *out = buffer_new(320, "bo1");
Buffer *raw = buffer_new(256, "bs1");
/* add the header */
buffer_add8(out, PCP_KEY_VERSION);
buffer_add32(out, key->ctime);
buffer_add32(out, sk->ctime);
buffer_add8(out, EXP_PK_CIPHER);
/* add the keys */
buffer_add(raw, key->edpub, 32);
buffer_add(raw, key->edpub, 32);
buffer_add(raw, key->pub, 32);
buffer_add(raw, sk->masterpub, 32);
buffer_add(raw, sk->edpub, 32);
buffer_add(raw, sk->pub, 32);
/* add the sig header */
buffer_add8(raw, EXP_SIG_VERSION);
@@ -57,25 +109,25 @@ Buffer *pcp_get_rfc_pub (pcp_pubkey_t *key, pcp_key_t *sk) {
/* add key expire time */
buffer_add32be(raw, 4);
buffer_add8(raw, EXP_SIG_SUB_KEYEXPIRE);
buffer_add32be(raw, key->ctime + 31536000);
buffer_add32be(raw, sk->ctime + 31536000);
/* add name notation sub*/
size_t notation_size = strlen(key->owner) + 4 + 5;
size_t notation_size = strlen(sk->owner) + 4 + 5;
buffer_add32be(raw, notation_size);
buffer_add8(raw, EXP_SIG_SUB_NOTATION);
buffer_add16be(raw, 5);
buffer_add16be(raw, strlen(key->owner));
buffer_add16be(raw, strlen(sk->owner));
buffer_add(raw, "owner", 5);
buffer_add(raw, key->owner, strlen(key->owner));
buffer_add(raw, sk->owner, strlen(sk->owner));
/* add mail notation sub */
notation_size = strlen(key->mail) + 4 + 4;
notation_size = strlen(sk->mail) + 4 + 4;
buffer_add32be(raw, notation_size);
buffer_add8(raw, EXP_SIG_SUB_NOTATION);
buffer_add16be(raw, 4);
buffer_add16be(raw, strlen(key->mail));
buffer_add16be(raw, strlen(sk->mail));
buffer_add(raw, "mail", 4);
buffer_add(raw, key->mail, strlen(key->mail));
buffer_add(raw, sk->mail, strlen(sk->mail));
/* add key flags */
buffer_add32be(raw, 1);
@@ -91,7 +143,7 @@ Buffer *pcp_get_rfc_pub (pcp_pubkey_t *key, pcp_key_t *sk) {
crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX);
/* sign the hash */
unsigned char *sig = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, sk->secret);
unsigned char *sig = pcp_ed_sign_key(hash, crypto_generichash_BYTES_MAX, sk);
/* append the signature packet to the output */
buffer_add(out, buffer_get(raw), buffer_size(raw));