fixed scrypt() call and pbp pk export signature

This commit is contained in:
git@daemon.de
2014-02-03 12:19:17 +01:00
parent 71013ac03d
commit 777fa01c74
7 changed files with 42 additions and 28 deletions

View File

@@ -36,7 +36,7 @@
#include "mem.h" #include "mem.h"
#include "defines.h" #include "defines.h"
unsigned char * pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce); unsigned char * pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen);
#endif // _HAVE_PCP_SCRYPT_H #endif // _HAVE_PCP_SCRYPT_H

View File

@@ -246,7 +246,6 @@ pcp_pubkey_t *pcp_ed_verify_buffered(FILE *in, pcp_pubkey_t *p) {
} }
// else: if unarmored, sighash is already filled // else: if unarmored, sighash is already filled
// huh, how did we made it til here? // huh, how did we made it til here?
unsigned char *verifiedhash = NULL; unsigned char *verifiedhash = NULL;
if(p == NULL) { if(p == NULL) {

View File

@@ -25,7 +25,7 @@
/* /*
* AS of 16/01/2014 I'm using scrypt() instead of my crafted key * AS of 16/01/2014 I'm using scrypt() instead of my crafted key
* derivation function. However, I create a hash from the pcp_script() * derivation function. However, I create a hash from the pcp_scrypt()
* result anyway because I need a cure25519 secret. * result anyway because I need a cure25519 secret.
*/ */
unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) { unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) {
@@ -33,7 +33,7 @@ unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce) {
size_t plen = strnlen(passphrase, 255); size_t plen = strnlen(passphrase, 255);
// create the scrypt hash // create the scrypt hash
unsigned char *scrypted = pcp_scrypt(passphrase, plen, nonce); unsigned char *scrypted = pcp_scrypt(passphrase, plen, nonce, crypto_secretbox_NONCEBYTES);
// make a hash from the scrypt() result // make a hash from the scrypt() result
crypto_hash_sha256(key, (unsigned char*)scrypted, 64); crypto_hash_sha256(key, (unsigned char*)scrypted, 64);

View File

@@ -21,7 +21,7 @@
#include "scrypt.h" #include "scrypt.h"
unsigned char* pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce) { unsigned char* pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen) {
uint8_t *dk = ucmalloc(64); // resulting hash uint8_t *dk = ucmalloc(64); // resulting hash
// constants // constants
@@ -30,7 +30,7 @@ unsigned char* pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce)
uint32_t p = 1; uint32_t p = 1;
size_t buflen = 64; size_t buflen = 64;
if (crypto_scrypt(passwd, passwdlen, (uint8_t *)nonce, crypto_secretbox_NONCEBYTES, N, r, p, dk, buflen) == 0) { if (crypto_scrypt(passwd, passwdlen, (uint8_t *)nonce, noncelen, N, r, p, dk, buflen) == 0) {
return dk; return dk;
} }
else { else {

View File

@@ -69,7 +69,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
strncpy(passphrase, passwd, strlen(passwd)+1); strncpy(passphrase, passwd, strlen(passwd)+1);
} }
symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt); symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt, 90);
free(salt); free(salt);
} }
else { else {
@@ -154,10 +154,10 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
passphrase = ucmalloc(strlen(passwd)+1); passphrase = ucmalloc(strlen(passwd)+1);
strncpy(passphrase, passwd, strlen(passwd)+1); strncpy(passphrase, passwd, strlen(passwd)+1);
} }
unsigned char *salt = ucmalloc(90); unsigned char *salt = ucmalloc(90); // FIXME: use random salt, concat it with result afterwards
char stsalt[] = PBP_COMPAT_SALT; char stsalt[] = PBP_COMPAT_SALT;
memcpy(salt, stsalt, 90); memcpy(salt, stsalt, 90);
symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt); symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt, 90);
free(salt); free(salt);
} }
else if(id != NULL) { else if(id != NULL) {

View File

@@ -398,24 +398,24 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
} }
klen = (nlen / 5) * 4; klen = (nlen / 5) * 4;
if(decode_85((char *)bin, (char *)buf, klen) != 0) if(decode_85((char *)bin, (char *)buf, klen) != 0)
goto errimp1; goto errimp1;
/*
FILE *o = fopen("out", "wb+");
fwrite(bin, 1, klen, o);
*/
if(klen < sizeof(pbp_pubkey_t) - 1024 - crypto_sign_BYTES) { 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", 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); klen, sizeof(pbp_pubkey_t) - 1024);
goto errimp1; goto errimp1;
} }
// FIXME: or use first part as sig and verify // unpad result, if any
for(i=klen; i>0; --i) {
if(bin[i] != '\0' && i < klen) {
klen = i + 1;
break;
}
}
// use first part as sig and verify
memcpy(b, &bin[crypto_sign_BYTES], klen - crypto_sign_BYTES); memcpy(b, &bin[crypto_sign_BYTES], klen - crypto_sign_BYTES);
// parse the name // parse the name
@@ -446,6 +446,13 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
memcpy(pub->pub, b->pub, crypto_box_PUBLICKEYBYTES); memcpy(pub->pub, b->pub, crypto_box_PUBLICKEYBYTES);
memcpy(pub->edpub, b->edpub, crypto_sign_PUBLICKEYBYTES); memcpy(pub->edpub, b->edpub, crypto_sign_PUBLICKEYBYTES);
fprintf(stderr, "edpub: "); pcpprint_bin(stderr, pub->edpub, crypto_sign_PUBLICKEYBYTES); fprintf(stderr, "\n");
fprintf(stderr, " sig: "); pcpprint_bin(stderr, bin, klen); fprintf(stderr, "\n");
unsigned char *sig = pcp_ed_verify(bin, klen, pub);
if(sig == NULL)
goto errimp1;
free(sig);
free(b); free(b);
free(buf); free(buf);
free(bin); free(bin);

View File

@@ -220,15 +220,6 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
c = localtime(&t); c = localtime(&t);
if(pbpcompat == 1) { if(pbpcompat == 1) {
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->edpub, crypto_sign_PUBLICKEYBYTES);
sprintf(b->name, "%s<%s>", key->owner, key->mail);
size_t pbplen = sizeof(pbp_pubkey_t) - (1024 - namelen);
pcp_key_t *secret = NULL; pcp_key_t *secret = NULL;
secret = pcp_find_primary_secret(); secret = pcp_find_primary_secret();
@@ -242,7 +233,23 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
secret = pcpkey_decrypt(secret, passphrase); secret = pcpkey_decrypt(secret, passphrase);
if(secret != NULL) { if(secret != NULL) {
unsigned char *sig = pcp_ed_sign((unsigned char*)b, pbplen, secret); size_t pbplen = crypto_sign_PUBLICKEYBYTES+crypto_box_PUBLICKEYBYTES+crypto_sign_PUBLICKEYBYTES+strlen(key->owner);
unsigned char *blob = ucmalloc(pbplen);
fprintf(stderr, "edpub: "); pcpprint_bin(stderr, key->edpub, crypto_sign_PUBLICKEYBYTES); fprintf(stderr, "\n");
fprintf(stderr, " pub: "); pcpprint_bin(stderr, key->pub, crypto_box_PUBLICKEYBYTES); fprintf(stderr, "\n");
fprintf(stderr, "edpub: "); pcpprint_bin(stderr, key->edpub, crypto_sign_PUBLICKEYBYTES); fprintf(stderr, "\n");
memcpy(blob, key->edpub, crypto_sign_PUBLICKEYBYTES);
memcpy(&blob[crypto_sign_PUBLICKEYBYTES], key->pub, crypto_box_PUBLICKEYBYTES);
memcpy(&blob[crypto_sign_PUBLICKEYBYTES+crypto_box_PUBLICKEYBYTES], key->edpub, crypto_sign_PUBLICKEYBYTES);
memcpy(&blob[crypto_sign_PUBLICKEYBYTES+crypto_box_PUBLICKEYBYTES+crypto_sign_PUBLICKEYBYTES],
key->owner, strlen(key->owner));
unsigned char *sig = pcp_ed_sign(blob, pbplen, secret);
fprintf(stderr, " sig: "); pcpprint_bin(stderr, sig, pbplen+crypto_sign_BYTES); fprintf(stderr, "\n");
fprintf(stderr, "siglen: %ld, inlen: %ld\n", crypto_sign_BYTES, pbplen);
if(sig != NULL) { if(sig != NULL) {
size_t siglen = pbplen + crypto_sign_BYTES; size_t siglen = pbplen + crypto_sign_BYTES;
size_t blen = ((siglen / 4) * 5) + siglen; size_t blen = ((siglen / 4) * 5) + siglen;
@@ -252,6 +259,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
free(b85sig); free(b85sig);
free(sig); free(sig);
} }
free(blob);
} }
} }
} }