renamed 'public' to 'pub' to avoid conflict with c++ api

This commit is contained in:
TLINDEN
2013-11-29 20:01:42 +01:00
parent 2fdbf8e1be
commit a9b2796af2
10 changed files with 165 additions and 162 deletions

View File

@@ -25,7 +25,7 @@
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
FILE *in = NULL;
FILE *out = NULL;
pcp_pubkey_t *public = NULL;
pcp_pubkey_t *pub = NULL;
pcp_key_t *secret = NULL;
if(useid) {
@@ -93,24 +93,24 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
unsigned char *check = ucmalloc(crypto_hash_BYTES);
memcpy(hash, combined, crypto_hash_BYTES);
pcphash_iteratepub(public) {
crypto_hash(check, (unsigned char*)public->id, 16);
pcphash_iteratepub(pub) {
crypto_hash(check, (unsigned char*)pub->id, 16);
if(memcmp(check, hash, crypto_hash_BYTES) == 0) {
// found one
break;
}
}
if(public == NULL) {
if(pub == NULL) {
// maybe self encryption, try secrets
pcp_key_t *s = NULL;
pcphash_iterate(s) {
crypto_hash(check, (unsigned char*)s->id, 16);
if(memcmp(check, hash, crypto_hash_BYTES) == 0) {
// matching secret
public = pcpkey_pub_from_secret(s);
pub = pcpkey_pub_from_secret(s);
}
}
if(public == NULL) {
if(pub == NULL) {
fatal("Could not find a usable public key in vault %s!\n",
vault->filename);
goto errde0;
@@ -121,33 +121,33 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
fprintf(stderr, "Using secret key:\n");
pcpkey_printshortinfo(secret);
fprintf(stderr, "Using publickey:\n");
pcppubkey_printshortinfo(public);
pcppubkey_printshortinfo(pub);
}
unsigned char *encrypted = ucmalloc(clen - crypto_hash_BYTES);
memcpy(encrypted, &combined[crypto_hash_BYTES], clen - crypto_hash_BYTES);
size_t dlen;
unsigned char *decrypted = pcp_box_decrypt(secret, public,
unsigned char *decrypted = pcp_box_decrypt(secret, pub,
encrypted,
clen - crypto_hash_BYTES, &dlen);
if(decrypted == NULL) {
// try it with a derived secret from the sender id
pcp_key_t *s = pcp_derive_pcpkey(secret, public->id);
decrypted = pcp_box_decrypt(s, public,
pcp_key_t *s = pcp_derive_pcpkey(secret, pub->id);
decrypted = pcp_box_decrypt(s, pub,
encrypted,
clen - crypto_hash_BYTES, &dlen);
if(decrypted == NULL) {
// now try the senders key mail address
s = pcp_derive_pcpkey(secret, public->mail);
decrypted = pcp_box_decrypt(s, public,
s = pcp_derive_pcpkey(secret, pub->mail);
decrypted = pcp_box_decrypt(s, pub,
encrypted,
clen - crypto_hash_BYTES, &dlen);
if(decrypted == NULL) {
// try the name
s = pcp_derive_pcpkey(secret, public->owner);
decrypted = pcp_box_decrypt(s, public,
s = pcp_derive_pcpkey(secret, pub->owner);
decrypted = pcp_box_decrypt(s, pub,
encrypted,
clen - crypto_hash_BYTES, &dlen);
}
@@ -164,7 +164,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
free(decrypted);
fprintf(stderr, "Decrypted %d bytes from 0x%s successfully\n",
(int)dlen, public->id);
(int)dlen, pub->id);
}
free(encrypted);
@@ -186,17 +186,17 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, char *recipient) {
FILE *in = NULL;
FILE *out = NULL;
pcp_pubkey_t *public = NULL;
pcp_pubkey_t *pub = NULL;
pcp_key_t *secret = NULL;
// look if we've got that key
HASH_FIND_STR(pcppubkey_hash, id, public);
if(public == NULL) {
HASH_FIND_STR(pcppubkey_hash, id, pub);
if(pub == NULL) {
// self-encryption: look if its a secret one
pcp_key_t *s = NULL;
HASH_FIND_STR(pcpkey_hash, id, s);
if(s != NULL) {
public = pcpkey_pub_from_secret(s);
pub = pcpkey_pub_from_secret(s);
}
else {
fatal("Could not find a public key with id 0x%s in vault %s!\n",
@@ -255,7 +255,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, char *recipi
fprintf(stderr, "Using secret key:\n");
pcp_dumpkey(secret);
fprintf(stderr, "Using publickey:\n");
pcp_dumppubkey(public);
pcp_dumppubkey(pub);
}
unsigned char *input = NULL;
@@ -278,7 +278,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, char *recipi
}
size_t ciphersize;
unsigned char *cipher = pcp_box_encrypt(secret, public, input,
unsigned char *cipher = pcp_box_encrypt(secret, pub, input,
inputBufSize, &ciphersize);
if(cipher == NULL)
goto erren1;

View File

@@ -444,107 +444,6 @@ int pcp_importpublic (vault_t *vault, FILE *in) {
return 1;
}
int pcp_sanitycheck_pub(pcp_pubkey_t *key) {
if(key->public[0] == 0) {
fatal("Pubkey sanity check: public key contained in key seems to be empty!\n");
return 1;
}
if(key->type != PCP_KEY_TYPE_PUBLIC) {
fatal("Pubkey sanity check: key type is not PUBLIC (expected: %02x, got: %02x)!\n",
PCP_KEY_TYPE_PUBLIC, key->type);
return 1;
}
if(key->version != PCP_KEY_VERSION) {
fatal("Pubkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
PCP_KEY_VERSION, key->version);
return 1;
}
if(key->serial <= 0) {
fatal("Pubkey sanity check: invalid serial number: %08X!\n", key->serial);
return 1;
}
if(key->id[16] != '\0') {
char *got = ucmalloc(17);
memcpy(got, key->id, 17);
got[16] = '\0';
fatal("Pubkey sanity check: invalid key id (expected 16 bytes, got: %s)!\n", got);
free(got);
return 1;
}
struct tm *c;
time_t t = (time_t)key->ctime;
c = localtime(&t);
if(c->tm_year <= 0 || c->tm_year > 1100) {
// well, I'm perhaps overacting here :)
fatal("Pubkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
return 1;
}
pcp_pubkey_t *maybe = pcphash_pubkeyexists(key->id);
if(maybe != NULL) {
fatal("Pubkey sanity check: there already exists a key with the id 0x%s\n", key->id);
return 1;
}
return 0;
}
int pcp_sanitycheck_key(pcp_key_t *key) {
if(key->encrypted[0] == 0) {
fatal("Secretkey sanity check: secret key contained in key seems to be empty!\n");
return 1;
}
if(key->type != PCP_KEY_TYPE_SECRET && key->type != PCP_KEY_TYPE_MAINSECRET) {
fatal("Secretkey sanity check: key type is not SECRET (expected: %02x, got: %02x)!\n",
PCP_KEY_TYPE_SECRET, key->type);
return 1;
}
if(key->version != PCP_KEY_VERSION) {
fatal("Secretkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
PCP_KEY_VERSION, key->version);
return 1;
}
if(key->serial <= 0) {
fatal("Secretkey sanity check: invalid serial number: %08X!\n", key->serial);
return 1;
}
if(key->id[16] != '\0') {
char *got = ucmalloc(17);
memcpy(got, key->id, 17);
got[16] = '\0';
fatal("Secretkey sanity check: invalid key id (expected 16 bytes, got: %s)!\n", got);
free(got);
return 1;
}
struct tm *c;
time_t t = (time_t)key->ctime;
c = localtime(&t);
if(c->tm_year <= 0 || c->tm_year > 1100) {
// well, I'm perhaps overacting here :)
fatal("Secretkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
return 1;
}
pcp_key_t *maybe = pcphash_keyexists(key->id);
if(maybe != NULL) {
fatal("Secretkey sanity check: there already exists a key with the id 0x%s\n", key->id);
return 1;
}
return 0;
}
void pcpdelete_key(char *keyid) {
pcp_pubkey_t *p = pcphash_pubkeyexists(keyid);

View File

@@ -52,9 +52,7 @@ void pcp_exportpublic(char *keyid, char *recipient, char *passwd, char *outfile)
char *pcp_normalize_id(char *keyid);
pcp_key_t *pcp_find_primary_secret();
int pcp_importpublic (vault_t *vault, FILE *in);
int pcp_sanitycheck_pub(pcp_pubkey_t *key);
int pcp_importsecret (vault_t *vault, FILE *in);
int pcp_sanitycheck_key(pcp_key_t *key);
void pcpdelete_key(char *keyid);
char *pcp_find_id_byrec(char *recipient);
char *_lc(char *in);

View File

@@ -270,7 +270,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
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->public, 32, &zlen));
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",
@@ -317,7 +317,7 @@ void pcp_dumpkey(pcp_key_t *k) {
printf("Dumping pcp_key_t raw values:\n");
printf(" public: ");
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->public[i]);
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->pub[i]);
printf("\n");
printf(" secret: ");
@@ -360,7 +360,7 @@ void pcp_dumppubkey(pcp_pubkey_t *k) {
int i;
printf("Dumping pcp_pubkey_t raw values:\n");
printf(" public: ");
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->public[i]);
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->pub[i]);
printf("\n");
printf(" edpub: ");
@@ -456,7 +456,7 @@ void pcpexport_yaml(char *outfile) {
fprintf(out, " serial: %08x\n", s->serial);
fprintf(out, " type: %s\n",
(s->type == PCP_KEY_TYPE_MAINSECRET) ? "primary" : " secret");
fprintf(out, " public: "); pcpprint_bin(out, s->public, 32); fprintf(out, "\n");
fprintf(out, " public: "); pcpprint_bin(out, s->pub, 32); fprintf(out, "\n");
if(s->secret[0] == 0) {
fprintf(out, " encrypted: yes\n");
fprintf(out, " nonce: "); pcpprint_bin(out, s->nonce, 24); fprintf(out, "\n");
@@ -480,7 +480,7 @@ void pcpexport_yaml(char *outfile) {
fprintf(out, " version: %08x\n", p->version);
fprintf(out, " serial: %08x\n", p->serial);
fprintf(out, " type: public\n");
fprintf(out, " public: "); pcpprint_bin(out, p->public, 32); fprintf(out, "\n");
fprintf(out, " public: "); pcpprint_bin(out, p->pub, 32); fprintf(out, "\n");
fprintf(out, " edpub: "); pcpprint_bin(out, p->edpub, 32); fprintf(out, "\n");
}
}

View File

@@ -147,7 +147,7 @@ int pcpsign(char *infile, char *outfile, char *recipient, char *passwd) {
int pcpverify(char *infile, char *sigfile) {
FILE *in = NULL;
FILE *sigin = NULL;
pcp_pubkey_t *public = NULL;
pcp_pubkey_t *pub = NULL;
if(infile == NULL)
in = stdin;
@@ -181,9 +181,9 @@ int pcpverify(char *infile, char *sigfile) {
pcp_sig_t *sig = (pcp_sig_t *)decoded;
sig2native(sig);
HASH_FIND_STR(pcppubkey_hash, sig->id, public);
HASH_FIND_STR(pcppubkey_hash, sig->id, pub);
if(public == NULL) {
if(pub == NULL) {
fatal("Could not find a usable public key in vault %s!\n",
vault->filename);
goto errv3;
@@ -209,7 +209,7 @@ int pcpverify(char *infile, char *sigfile) {
}
if(pcp_ed_verify(input, inputBufSize, sig, public) == 0) {
if(pcp_ed_verify(input, inputBufSize, sig, pub) == 0) {
fprintf(stderr, "Signature verified.\n");
}