started with experimental pk export writer

This commit is contained in:
TLINDEN
2014-02-07 20:07:30 +01:00
parent 607f2be281
commit 2d7a0d834c
6 changed files with 117 additions and 2 deletions

View File

@@ -7,7 +7,6 @@ extern "C" {
#include "pcp/base85.h" #include "pcp/base85.h"
#include "pcp/buffer.h" #include "pcp/buffer.h"
#include "pcp/config.h"
#include "pcp/crypto.h" #include "pcp/crypto.h"
#include "pcp/defines.h" #include "pcp/defines.h"
#include "pcp/digital_crc32.h" #include "pcp/digital_crc32.h"

View File

@@ -94,4 +94,16 @@ uint64_t buffer_last64(Buffer *b);
/* read from a file directly into a buffer object */ /* read from a file directly into a buffer object */
size_t buffer_fd_read(Buffer *b, FILE *in, size_t len); size_t buffer_fd_read(Buffer *b, FILE *in, size_t len);
/* write numbers as binary into the buffer */
void buffer_add8(Buffer *b, uint8_t v);
void buffer_add16(Buffer *b, uint16_t v);
void buffer_add32(Buffer *b, uint32_t v);
void buffer_add64(Buffer *b, uint64_t v);
/* the same, but convert to big-endian before doing so */
void buffer_add16be(Buffer *b, uint16_t v);
void buffer_add32be(Buffer *b, uint32_t v);
void buffer_add64be(Buffer *b, uint64_t v);
#endif // HAVE_PCP_BUFFER_H #endif // HAVE_PCP_BUFFER_H

View File

@@ -89,6 +89,8 @@ typedef unsigned int qbyte; /* Quad byte = 32 bits */
/* used for self encryption only */ /* used for self encryption only */
#define PBP_COMPAT_SALT "qa~t](84z<1t<1oz:ik.@IRNyhG=8q(on9}4#!/_h#a7wqK{Nt$T?W>,mt8NqYq&6U<GB1$,<$j>,rSYI2GRDd:Bcm" #define PBP_COMPAT_SALT "qa~t](84z<1t<1oz:ik.@IRNyhG=8q(on9}4#!/_h#a7wqK{Nt$T?W>,mt8NqYq&6U<GB1$,<$j>,rSYI2GRDd:Bcm"
#define PCP_RFC_CIPHER 0x21 /* curve25519+ed25519+poly1305+salsa20+blake2 */
/* error handling */ /* error handling */
extern char *PCP_ERR; extern char *PCP_ERR;
extern byte PCP_ERRSET; extern byte PCP_ERRSET;

View File

@@ -38,6 +38,7 @@
#include "uthash.h" #include "uthash.h"
#include "jenhash.h" #include "jenhash.h"
#include "scrypt.h" #include "scrypt.h"
#include "buffer.h"
/* /*
PCP private key structure. Most fields are self explanatory. PCP private key structure. Most fields are self explanatory.

View File

@@ -149,10 +149,44 @@ size_t buffer_fd_read(Buffer *b, FILE *in, size_t len) {
size_t s = fread(data, 1, len, in); size_t s = fread(data, 1, len, in);
if(s < len) { if(s < len) {
fatal("[buffer %s] attemt to read %ld bytes from FILE, but got %ld only\n", b->name, len, s); fatal("[buffer %s] attempt to read %ld bytes from FILE, but got %ld bytes only\n", b->name, len, s);
return 0; return 0;
} }
buffer_add(b, data, len); buffer_add(b, data, len);
return len; return len;
} }
void buffer_add8(Buffer *b, uint8_t v) {
buffer_add(b, &v, 1);
}
void buffer_add16(Buffer *b, uint16_t v) {
buffer_add(b, &v, 2);
}
void buffer_add32(Buffer *b, uint32_t v) {
buffer_add(b, &v, 4);
}
void buffer_add64(Buffer *b, uint64_t v) {
buffer_add(b, &v, 8);
}
void buffer_add16be(Buffer *b, uint16_t v) {
uint16_t e = v;
htobe16(e);
buffer_add(b, &e, 2);
}
void buffer_add32be(Buffer *b, uint32_t v) {
uint32_t e = v;
htobe32(e);
buffer_add(b, &v, 4);
}
void buffer_add64be(Buffer *b, uint64_t v) {
uint64_t e = v;
htobe64(e);
buffer_add(b, &v, 8);
}

View File

@@ -394,3 +394,70 @@ int pcp_sanitycheck_key(pcp_key_t *key) {
return 0; return 0;
} }
int pcp_get_rfc_pub (pcp_pubkey_t *key) {
Buffer *out = buffer_new(1024, "bo1");
Buffer *raw = buffer_new(1024, "bs1");
/* add the header */
buffer_add8(out, PCP_KEY_VERSION);
buffer_add32(out, key->ctime);
buffer_add8(out, PCP_RFC_CIPHER);
/* add the keys */
buffer_add(raw, key->edpub, 32);
buffer_add(raw, key->edpub, 32);
buffer_add(raw, key->pub, 32);
/* add the sig header */
buffer_add8(raw, PCP_KEY_VERSION);
buffer_add8(raw, 0x1F); // FIXME: define
buffer_add8(raw, PCP_RFC_CIPHER);
buffer_add8(raw, PCP_RFC_CIPHER);
buffer_add16(raw, 5);
/* add sig ctime */
buffer_add32be(raw, 4);
buffer_add8(raw, 2);
buffer_add32be(raw, time(0));
/* add sig expire time */
buffer_add32be(raw, 4);
buffer_add8(raw, 3);
buffer_add32be(raw, time(0) + 31536000);
/* add key expire time */
buffer_add32be(raw, 4);
buffer_add8(raw, 9);
buffer_add32be(raw, key->ctime);
/* add name */
size_t notation_size = strlen(key->owner) + 4 + 5;
buffer_add32be(raw, notation_size);
buffer_add8(raw, 20);
buffer_add16be(raw, 5);
buffer_add16be(raw, strlen(key->owner));
buffer_add(raw, "owner", 5);
buffer_add(raw, key->owner, strlen(key->owner));
/* add mail */
notation_size = strlen(key->mail) + 4 + 4;
buffer_add32be(raw, notation_size);
buffer_add8(raw, 20);
buffer_add16be(raw, 4);
buffer_add16be(raw, strlen(key->mail));
buffer_add(raw, "mail", 4);
buffer_add(raw, key->mail, strlen(key->mail));
/* add key flags */
buffer_add32be(raw, 1);
buffer_add8(raw, 27);
buffer_add8(raw, 0x02 & 0x08 & 0x80);
/* FIXME:
Now, calculate the signature from the raw buffer,
add it to the output buffer, add the sig to the
output buffer and finally return it. */
return 0;
}