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

@@ -69,7 +69,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
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);
}
else {
@@ -154,10 +154,10 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
passphrase = ucmalloc(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;
memcpy(salt, stsalt, 90);
symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt);
symkey = pcp_scrypt(passphrase, crypto_secretbox_KEYBYTES, salt, 90);
free(salt);
}
else if(id != NULL) {

View File

@@ -398,24 +398,24 @@ int pcp_importpublic (vault_t *vault, FILE *in, int pbpcompat) {
}
klen = (nlen / 5) * 4;
if(decode_85((char *)bin, (char *)buf, klen) != 0)
goto errimp1;
/*
FILE *o = fopen("out", "wb+");
fwrite(bin, 1, klen, o);
*/
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
// 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);
// 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->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(buf);
free(bin);

View File

@@ -220,15 +220,6 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
c = localtime(&t);
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;
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);
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) {
size_t siglen = pbplen + crypto_sign_BYTES;
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(sig);
}
free(blob);
}
}
}