mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 20:00:58 +01:00
continue new pk-expoert format
This commit is contained in:
@@ -336,7 +336,7 @@ int pcp_importsecret (vault_t *vault, FILE *in) {
|
||||
}
|
||||
|
||||
if(clen != PCP_RAW_KEYSIZE) {
|
||||
fatal("Error: decoded input didn't result to a proper sized key! (got %d bytes)\n", clen);
|
||||
fatal("Error: decoded input didn't result to a proper sized key! (got %ld bytes, expected %ld)\n", clen, PCP_RAW_KEYSIZE);
|
||||
free(z85decoded);
|
||||
return 1;
|
||||
}
|
||||
@@ -624,3 +624,69 @@ char *pcp_find_id_byrec(char *recipient) {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Experimental RFC4880-alike public key export. Once stable and
|
||||
flexible enough, this will become the PCP default, I hope. */
|
||||
void pcp_exportpublic2(char *passwd, char *outfile, int armor) {
|
||||
pcp_pubkey_t *key = NULL;
|
||||
|
||||
pcp_key_t *s = NULL;
|
||||
s = pcp_find_primary_secret();
|
||||
if(s == NULL) {
|
||||
fatal("There's no primary secret key in the vault %s!\n", vault->filename);
|
||||
free(s);
|
||||
}
|
||||
else {
|
||||
key = pcpkey_pub_from_secret(s);
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
FILE *out;
|
||||
if(outfile == NULL) {
|
||||
out = stdout;
|
||||
}
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not create output file %s", outfile);
|
||||
out = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(out != NULL) {
|
||||
pcp_key_t *sk = pcp_find_primary_secret();
|
||||
if(sk != NULL) {
|
||||
char *passphrase;
|
||||
pcp_readpass(&passphrase, "Enter passphrase to decrypt your secret key for signing the export", NULL, 1);
|
||||
|
||||
sk = pcpkey_decrypt(sk, passphrase);
|
||||
if(sk != NULL) {
|
||||
Buffer *exported_pk = pcp_get_rfc_pub(key, sk);
|
||||
if(exported_pk != NULL) {
|
||||
if(armor == 1) {
|
||||
size_t zlen;
|
||||
char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen);
|
||||
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_PK_HEADER, z85, EXP_PK_FOOTER);
|
||||
free(z85);
|
||||
}
|
||||
else
|
||||
fwrite(buffer_get(exported_pk), 1, buffer_size(exported_pk), out);
|
||||
|
||||
fclose(out);
|
||||
if(debug) {
|
||||
buffer_dump(exported_pk);
|
||||
buffer_info(exported_pk);
|
||||
pcp_dumppubkey(key);
|
||||
}
|
||||
buffer_free(exported_pk);
|
||||
}
|
||||
}
|
||||
|
||||
free(passphrase);
|
||||
}
|
||||
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "keyhash.h"
|
||||
#include "util.h"
|
||||
#include "base85.h"
|
||||
#include "buffer.h"
|
||||
#include "mgmt.h"
|
||||
|
||||
#define _WITH_GETLINE
|
||||
|
||||
@@ -58,4 +60,7 @@ int pcp_importsecret (vault_t *vault, FILE *in);
|
||||
void pcpdelete_key(char *keyid);
|
||||
char *pcp_find_id_byrec(char *recipient);
|
||||
|
||||
/* Experimental: new rfc4880 style pk export */
|
||||
void pcp_exportpublic2(char *passwd, char *outfile, int armor);
|
||||
|
||||
#endif /* _HAVE_KEYMGMT_H */
|
||||
|
||||
38
src/pcp.c
38
src/pcp.c
@@ -46,7 +46,7 @@ char *default_vault() {
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int opt, mode, usevault, useid, userec, lo, armor, detach, signcrypt, pbpcompat;
|
||||
int opt, mode, usevault, useid, userec, lo, armor, detach, signcrypt, pbpcompat, rfc;
|
||||
char *vaultfile = default_vault();
|
||||
char *outfile = NULL;
|
||||
char *infile = NULL;
|
||||
@@ -70,6 +70,7 @@ int main (int argc, char **argv) {
|
||||
detach = 0;
|
||||
signcrypt = 0;
|
||||
pbpcompat = 0;
|
||||
rfc = 0;
|
||||
|
||||
static struct option longopts[] = {
|
||||
/* generics */
|
||||
@@ -92,6 +93,7 @@ int main (int argc, char **argv) {
|
||||
{ "edit-key", no_argument, NULL, 'E' },
|
||||
{ "export-yaml", no_argument, NULL, 'y' },
|
||||
{ "pbpcompat", no_argument, NULL, 'b' },
|
||||
{ "rfc-format", no_argument, NULL, '1' }, /* no short option */
|
||||
|
||||
/* crypto */
|
||||
{ "encrypt", no_argument, NULL, 'e' },
|
||||
@@ -114,7 +116,7 @@ int main (int argc, char **argv) {
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPRtEx:DzZr:gcymf:b",
|
||||
while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPRtEx:DzZr:gcymf:b1",
|
||||
longopts, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
@@ -151,6 +153,9 @@ int main (int argc, char **argv) {
|
||||
mode += PCP_MODE_IMPORT_SECRET;
|
||||
usevault = 1;
|
||||
break;
|
||||
case '1':
|
||||
rfc = 1;
|
||||
break;
|
||||
case 'R':
|
||||
mode += PCP_MODE_DELETE_KEY;
|
||||
usevault = 1;
|
||||
@@ -372,19 +377,24 @@ int main (int argc, char **argv) {
|
||||
break;
|
||||
|
||||
case PCP_MODE_EXPORT_PUBLIC:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id == NULL)
|
||||
break;
|
||||
if(rfc) {
|
||||
pcp_exportpublic2(xpass, outfile, armor);
|
||||
}
|
||||
else {
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id == NULL)
|
||||
break;
|
||||
}
|
||||
if (recipient != NULL)
|
||||
pcp_exportpublic(id, recipient->value, xpass, outfile, pbpcompat);
|
||||
else
|
||||
pcp_exportpublic(id, NULL, xpass, outfile, pbpcompat);
|
||||
if(xpass != NULL)
|
||||
free(xpass);
|
||||
if(recipient != NULL)
|
||||
free(recipient);
|
||||
}
|
||||
if (recipient != NULL)
|
||||
pcp_exportpublic(id, recipient->value, xpass, outfile, pbpcompat);
|
||||
else
|
||||
pcp_exportpublic(id, NULL, xpass, outfile, pbpcompat);
|
||||
if(xpass != NULL)
|
||||
free(xpass);
|
||||
if(recipient != NULL)
|
||||
free(recipient);
|
||||
break;
|
||||
|
||||
case PCP_MODE_IMPORT_PUBLIC:
|
||||
|
||||
Reference in New Issue
Block a user