unfortunately my tab/spc config was wrong for a couple of years. fixed all tabs=>spaces+re-indent

This commit is contained in:
TLINDEN
2016-05-09 22:24:13 +02:00
parent a67149229f
commit 671352bc29
34 changed files with 1031 additions and 1031 deletions

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -41,12 +41,12 @@ namespace pcp {
std::string msg; std::string msg;
PCPCTX *ptx = P->ptx; PCPCTX *ptx = P->ptx;
if(ptx->pcp_errset == 1) { if(ptx->pcp_errset == 1) {
msg = ptx->pcp_err; msg = ptx->pcp_err;
} }
if(errno) { if(errno) {
msg += std::string("\nError: ") msg += std::string("\nError: ")
+ std::string(strerror(errno)) + std::string(strerror(errno))
+ std::string("\n"); + std::string("\n");
} }
return msg; return msg;
} }

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -83,8 +83,8 @@ namespace pcp {
Key(PcpContext *P, bool generate); Key(PcpContext *P, bool generate);
Key(PcpContext *P, const std::string& passphrase); Key(PcpContext *P, const std::string& passphrase);
Key(PcpContext *P, const std::string& passphrase, Key(PcpContext *P, const std::string& passphrase,
const std::string& owner, const std::string& owner,
const std::string& mail); const std::string& mail);
Key(PcpContext *P, pcp_key_t *k); Key(PcpContext *P, pcp_key_t *k);
Key(PcpContext *P, pcp_key_t *k, bool store); Key(PcpContext *P, pcp_key_t *k, bool store);
Key(PcpContext *P, std::string &z85encoded, std::string& passphrase); Key(PcpContext *P, std::string &z85encoded, std::string& passphrase);

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -53,8 +53,8 @@ Key::Key(PcpContext *P, const string& passphrase) {
} }
Key::Key(PcpContext *P, const string& passphrase, Key::Key(PcpContext *P, const string& passphrase,
const string& owner, const string& owner,
const string& mail) { const string& mail) {
stored = false; stored = false;
pcp_key_t *_K = pcpkey_new(); pcp_key_t *_K = pcpkey_new();
K = pcpkey_encrypt(P->ptx, _K, (char *)passphrase.c_str()); K = pcpkey_encrypt(P->ptx, _K, (char *)passphrase.c_str());

View File

@@ -2,28 +2,28 @@
use Data::Dumper; use Data::Dumper;
my %sobytes = ( my %sobytes = (
'crypto_box_NONCEBYTES' => 24, 'crypto_box_NONCEBYTES' => 24,
'crypto_box_PUBLICKEYBYTES' => 32, 'crypto_box_PUBLICKEYBYTES' => 32,
'crypto_box_SECRETKEYBYTES' => 32, 'crypto_box_SECRETKEYBYTES' => 32,
'crypto_box_ZEROBYTES' => 32, 'crypto_box_ZEROBYTES' => 32,
'crypto_box_BOXZEROBYTES' => 16, 'crypto_box_BOXZEROBYTES' => 16,
'crypto_box_MACBYTES' => 16, 'crypto_box_MACBYTES' => 16,
'crypto_secretbox_KEYBYTES' => 32, 'crypto_secretbox_KEYBYTES' => 32,
'crypto_secretbox_NONCEBYTES' => 24, 'crypto_secretbox_NONCEBYTES' => 24,
'crypto_secretbox_ZEROBYTES' => 32, 'crypto_secretbox_ZEROBYTES' => 32,
'crypto_secretbox_BOXZEROBYTES' => 16, 'crypto_secretbox_BOXZEROBYTES' => 16,
'crypto_secretbox_MACBYTES' => 16, 'crypto_secretbox_MACBYTES' => 16,
'crypto_sign_PUBLICKEYBYTES' => 32, 'crypto_sign_PUBLICKEYBYTES' => 32,
'crypto_sign_SECRETKEYBYTES' => 64, 'crypto_sign_SECRETKEYBYTES' => 64,
'crypto_sign_SEEDBYTES' => 32, 'crypto_sign_SEEDBYTES' => 32,
'crypto_sign_BYTES' => 64, 'crypto_sign_BYTES' => 64,
'crypto_stream_KEYBYTES' => 32, 'crypto_stream_KEYBYTES' => 32,
'crypto_stream_NONCEBYTES' => 24, 'crypto_stream_NONCEBYTES' => 24,
'crypto_generichash_BYTES' => 32, 'crypto_generichash_BYTES' => 32,
'crypto_scalarmult_curve25519_BYTES' => 32, 'crypto_scalarmult_curve25519_BYTES' => 32,
'crypto_scalarmult_BYTES' => 32, 'crypto_scalarmult_BYTES' => 32,
'crypto_generichash_BYTES_MAX' => 64, 'crypto_generichash_BYTES_MAX' => 64,
); );
my @ignore = qw(uthash.h); my @ignore = qw(uthash.h);
@@ -87,19 +87,19 @@ foreach my $head (@ARGV) {
print "PCP_RAW_CODE = '''\n"; print "PCP_RAW_CODE = '''\n";
print qq( print qq(
typedef enum { typedef enum {
JSON_OBJECT, JSON_OBJECT,
JSON_ARRAY, JSON_ARRAY,
JSON_STRING, JSON_STRING,
JSON_INTEGER, JSON_INTEGER,
JSON_REAL, JSON_REAL,
JSON_TRUE, JSON_TRUE,
JSON_FALSE, JSON_FALSE,
JSON_NULL JSON_NULL
} json_type; } json_type;
typedef struct json_t { typedef struct json_t {
json_type type; json_type type;
size_t refcount; size_t refcount;
} json_t; } json_t;
); );
print join "\n", @typedefs; print join "\n", @typedefs;

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.Linden. Copyright (C) 2013-2016 T.Linden.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -141,7 +141,7 @@
*/ */
byte *pcp_box_encrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub, byte *pcp_box_encrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
byte *message, size_t messagesize, byte *message, size_t messagesize,
size_t *csize); size_t *csize);
/** Asymmetrically decrypt a message. /** Asymmetrically decrypt a message.
@@ -167,7 +167,7 @@ byte *pcp_box_encrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
*/ */
byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub, byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
byte *cipher, size_t ciphersize, byte *cipher, size_t ciphersize,
size_t *dsize); size_t *dsize);
/** Asymmetrically encrypt a file or a buffer stream. /** Asymmetrically encrypt a file or a buffer stream.
@@ -196,7 +196,7 @@ byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
\return Returns the size of the output written to the output stream or 0 in case of errors. \return Returns the size of the output written to the output stream or 0 in case of errors.
*/ */
size_t pcp_encrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t *s, size_t pcp_encrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t *s,
pcp_key_t *ss, pcp_pubkey_t *p, int signcrypt, int anon); pcp_key_t *ss, pcp_pubkey_t *p, int signcrypt, int anon);
/** Symmetrically encrypt a file or a buffer stream. /** Symmetrically encrypt a file or a buffer stream.

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.Linden. Copyright (C) 2013-2016 T.Linden.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@
Also, don't free() the keyhash or the temporary key pointer Also, don't free() the keyhash or the temporary key pointer
yourself. Use pcphash_clean() instead when done. yourself. Use pcphash_clean() instead when done.
*/ */
#define pcphash_iterate(ptx, key) \ #define pcphash_iterate(ptx, key) \
pcp_key_t *__k = NULL; \ pcp_key_t *__k = NULL; \
HASH_ITER(hh, ptx->pcpkey_hash, key, __k) HASH_ITER(hh, ptx->pcpkey_hash, key, __k)
@@ -73,7 +73,7 @@
Also, don't free() the keyhash or the temporary key pointer Also, don't free() the keyhash or the temporary key pointer
yourself. Use pcphash_clean() instead when done. yourself. Use pcphash_clean() instead when done.
*/ */
#define pcphash_iteratepub(ptx, key) \ #define pcphash_iteratepub(ptx, key) \
pcp_pubkey_t *__p = NULL; \ pcp_pubkey_t *__p = NULL; \
HASH_ITER(hh, ptx->pcppubkey_hash, key, __p) HASH_ITER(hh, ptx->pcppubkey_hash, key, __p)
@@ -142,7 +142,7 @@ int pcphash_countpub(PCPCTX *ptx);
#define pcphash_iteratekeysig(ptx, key) \ #define pcphash_iteratekeysig(ptx, key) \
pcp_keysig_t *__s = NULL; \ pcp_keysig_t *__s = NULL; \
HASH_ITER(hh, ptx->pcpkeysig_hash, key, __s) HASH_ITER(hh, ptx->pcpkeysig_hash, key, __s)

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -39,24 +39,24 @@
# endif # endif
# else /* no sys/endian.h */ # else /* no sys/endian.h */
# ifdef __CPU_IS_BIG_ENDIAN # ifdef __CPU_IS_BIG_ENDIAN
# define be16toh(x) (x) # define be16toh(x) (x)
# define htobe16(x) (x) # define htobe16(x) (x)
# define be32toh(x) (x) # define be32toh(x) (x)
# define htobe32(x) (x) # define htobe32(x) (x)
# define be64toh(x) (x) # define be64toh(x) (x)
# define htobe64(x) (x) # define htobe64(x) (x)
# elif defined(__APPLE__) /* from https://gist.github.com/panzi/6856583 */ # elif defined(__APPLE__) /* from https://gist.github.com/panzi/6856583 */
# include <libkern/OSByteOrder.h> # include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x) # define htobe16(x) OSSwapHostToBigInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x) # define be16toh(x) OSSwapBigToHostInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x) # define htobe32(x) OSSwapHostToBigInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x) # define be32toh(x) OSSwapBigToHostInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x) # define htobe64(x) OSSwapHostToBigInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x) # define be64toh(x) OSSwapBigToHostInt64(x)
# define __BYTE_ORDER BYTE_ORDER # define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN # define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN # define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN # define __PDP_ENDIAN PDP_ENDIAN
# else # else
# ifdef HAVE_ARPA_INET_H # ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> # include <arpa/inet.h>
@@ -67,12 +67,12 @@
# error Need either netinet/in.h or arpa/inet.h for ntohl() and htonl() # error Need either netinet/in.h or arpa/inet.h for ntohl() and htonl()
# endif # endif
# endif # endif
# define be16toh(x) ((uint16_t)ntohl((uint16_t)(x))) # define be16toh(x) ((uint16_t)ntohl((uint16_t)(x)))
# define htobe16(x) ((uint16_t)htonl((uint16_t)(x))) # define htobe16(x) ((uint16_t)htonl((uint16_t)(x)))
# define be32toh(x) ((uint32_t)ntohl((uint32_t)(x))) # define be32toh(x) ((uint32_t)ntohl((uint32_t)(x)))
# define htobe32(x) ((uint32_t)htonl((uint32_t)(x))) # define htobe32(x) ((uint32_t)htonl((uint32_t)(x)))
# define be64toh(x) ((uint64_t)ntohl((uint64_t)(x))) # define be64toh(x) ((uint64_t)ntohl((uint64_t)(x)))
# define htobe64(x) ((uint64_t)htonl((uint64_t)(x))) # define htobe64(x) ((uint64_t)htonl((uint64_t)(x)))
# endif # endif
# endif /* HAVE_SYS_ENDIAN_H */ # endif /* HAVE_SYS_ENDIAN_H */
#endif /* HAVE_ENDIAN_H */ #endif /* HAVE_ENDIAN_H */

View File

@@ -58,7 +58,7 @@
* getpass / readpass / readpassphrase / etc. functions in various libraries. * getpass / readpass / readpassphrase / etc. functions in various libraries.
*/ */
int pcp_readpass(PCPCTX *ptx, char **passwd, const char *prompt, int pcp_readpass(PCPCTX *ptx, char **passwd, const char *prompt,
const char *confirmprompt, int devtty, char *readfromfile); const char *confirmprompt, int devtty, char *readfromfile);
/** /**
from encfs getUserKey(). from encfs getUserKey().

View File

@@ -311,6 +311,7 @@ struct _pcp_stream_t {
Buffer *cache; /**< The caching Buffer object (for look ahead read) */ Buffer *cache; /**< The caching Buffer object (for look ahead read) */
Buffer *next; /**< The caching Next-Buffer object (for look ahead read) */ Buffer *next; /**< The caching Next-Buffer object (for look ahead read) */
Buffer *save; /**< Temporary buffer to backup overflow data */ Buffer *save; /**< Temporary buffer to backup overflow data */
byte *xb; /**< Temporary byte buffer for reading/writing data */
uint8_t is_buffer; /**< Set to 1 if the backend is a Buffer */ uint8_t is_buffer; /**< Set to 1 if the backend is a Buffer */
uint8_t eof; /**< Set to 1 if EOF reached */ uint8_t eof; /**< Set to 1 if EOF reached */
uint8_t err; /**< Set to 1 if an error occured */ uint8_t err; /**< Set to 1 if an error occured */

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -62,7 +62,7 @@ void buffer_free(Buffer *b) {
if(b->allocated == 1) { if(b->allocated == 1) {
/* free the underlying data pointer only if we allocated it */ /* free the underlying data pointer only if we allocated it */
if(b->end > 0) { if(b->end > 0) {
buffer_clear(b); buffer_clear(b);
} }
free(b->buf); free(b->buf);
b->allocated = 0; b->allocated = 0;
@@ -132,7 +132,7 @@ byte *buffer_get(Buffer *b) {
size_t buffer_get_chunk(Buffer *b, void *buf, size_t len) { size_t buffer_get_chunk(Buffer *b, void *buf, size_t len) {
if(len > b->end - b->offset) { if(len > b->end - b->offset) {
final("[buffer %s] attempt to read %ld bytes data from buffer with %ld bytes left at offset %ld\n", final("[buffer %s] attempt to read %ld bytes data from buffer with %ld bytes left at offset %ld\n",
b->name, len, b->end - b->offset, b->offset); b->name, len, b->end - b->offset, b->offset);
} }
else if(len == 0) { else if(len == 0) {
/* FIXME: check how this happens */ /* FIXME: check how this happens */
@@ -148,7 +148,7 @@ size_t buffer_get_chunk(Buffer *b, void *buf, size_t len) {
size_t buffer_fwd_offset(Buffer *b, size_t fwdby) { size_t buffer_fwd_offset(Buffer *b, size_t fwdby) {
if(fwdby > b->end - b->offset) { if(fwdby > b->end - b->offset) {
final("[buffer %s] attempt to set offset %ld bytes forward data from buffer with %ld bytes left at offset %ld\n", final("[buffer %s] attempt to set offset %ld bytes forward data from buffer with %ld bytes left at offset %ld\n",
b->name, fwdby, b->end - b->offset, b->offset); b->name, fwdby, b->end - b->offset, b->offset);
} }
else if(fwdby == 0) { else if(fwdby == 0) {
return 0; return 0;
@@ -161,7 +161,7 @@ size_t buffer_fwd_offset(Buffer *b, size_t fwdby) {
size_t buffer_get_chunk_tobuf(Buffer *b, Buffer *dst, size_t len) { size_t buffer_get_chunk_tobuf(Buffer *b, Buffer *dst, size_t len) {
if(len > b->end - b->offset) { if(len > b->end - b->offset) {
final("[buffer %s] attempt to read %ld bytes data from buffer with %ld bytes left at offset %ld\n", final("[buffer %s] attempt to read %ld bytes data from buffer with %ld bytes left at offset %ld\n",
b->name, len, b->end - b->offset, b->offset); b->name, len, b->end - b->offset, b->offset);
} }
else if(len == 0) { else if(len == 0) {
/* FIXME: check how this happens */ /* FIXME: check how this happens */

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -27,8 +27,8 @@
/* asym encr */ /* asym encr */
byte *pcp_box_encrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub, byte *pcp_box_encrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
byte *message, size_t messagesize, byte *message, size_t messagesize,
size_t *csize) { size_t *csize) {
byte *nonce = pcp_gennonce(); byte *nonce = pcp_gennonce();
@@ -66,8 +66,8 @@ byte *pcp_box_encrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
/* asym decr */ /* asym decr */
byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub, byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
byte *cipher, size_t ciphersize, byte *cipher, size_t ciphersize,
size_t *dsize) { size_t *dsize) {
byte *message = NULL; byte *message = NULL;
@@ -76,11 +76,11 @@ byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
memcpy(nonce, cipher, LNONCE); memcpy(nonce, cipher, LNONCE);
memcpy(cipheronly, &cipher[LNONCE], memcpy(cipheronly, &cipher[LNONCE],
ciphersize - LNONCE); ciphersize - LNONCE);
message = ucmalloc(ciphersize - LNONCE - crypto_box_MACBYTES); message = ucmalloc(ciphersize - LNONCE - crypto_box_MACBYTES);
if(crypto_box_open_easy(message, cipheronly, ciphersize - LNONCE, if(crypto_box_open_easy(message, cipheronly, ciphersize - LNONCE,
nonce, pub->pub, secret->secret) != 0) { nonce, pub->pub, secret->secret) != 0) {
fatal(ptx, "failed to decrypt message!\n"); fatal(ptx, "failed to decrypt message!\n");
goto errbed; goto errbed;
} }
@@ -104,10 +104,10 @@ byte *pcp_box_decrypt(PCPCTX *ptx, pcp_key_t *secret, pcp_pubkey_t *pub,
/* sym encr */ /* sym encr */
size_t pcp_sodium_mac(byte **cipher, size_t pcp_sodium_mac(byte **cipher,
byte *cleartext, byte *cleartext,
size_t clearsize, size_t clearsize,
byte *nonce, byte *nonce,
byte *key) { byte *key) {
*cipher = ucmalloc(clearsize + LMAC); *cipher = ucmalloc(clearsize + LMAC);
crypto_secretbox_easy(*cipher, cleartext, clearsize, nonce, key); crypto_secretbox_easy(*cipher, cleartext, clearsize, nonce, key);
@@ -117,8 +117,8 @@ size_t pcp_sodium_mac(byte **cipher,
/* sym decr */ /* sym decr */
int pcp_sodium_verify_mac(byte **cleartext, byte* message, int pcp_sodium_verify_mac(byte **cleartext, byte* message,
size_t messagesize, byte *nonce, size_t messagesize, byte *nonce,
byte *key) { byte *key) {
return crypto_secretbox_open_easy(*cleartext, message, messagesize, nonce, key); return crypto_secretbox_open_easy(*cleartext, message, messagesize, nonce, key);
} }
@@ -146,32 +146,32 @@ size_t pcp_decrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t
cur_bufsize = ps_read(in, head, 1); /* fread(head, 1, 1, in); */ cur_bufsize = ps_read(in, head, 1); /* fread(head, 1, 1, in); */
if(cur_bufsize == 1 && !ps_end(in) && !ps_err(in)) { if(cur_bufsize == 1 && !ps_end(in) && !ps_err(in)) {
if(head[0] == PCP_SYM_CIPHER) { if(head[0] == PCP_SYM_CIPHER) {
if(symkey != NULL) if(symkey != NULL)
self = 1; self = 1;
else { else {
fatal(ptx, "Input is symetrically encrypted but no key have been specified (lib usage failure)\n"); fatal(ptx, "Input is symetrically encrypted but no key have been specified (lib usage failure)\n");
goto errdef1; goto errdef1;
} }
} }
else if(head[0] == PCP_ASYM_CIPHER_ANON) { else if(head[0] == PCP_ASYM_CIPHER_ANON) {
self = 0; self = 0;
anon = 1; anon = 1;
} }
else if(head[0] == PCP_ASYM_CIPHER_ANON_SIG) { else if(head[0] == PCP_ASYM_CIPHER_ANON_SIG) {
self = 0; self = 0;
anon = 1; anon = 1;
verify = 1; verify = 1;
} }
else if(head[0] == PCP_ASYM_CIPHER) { else if(head[0] == PCP_ASYM_CIPHER) {
self = 0; self = 0;
} }
else if(head[0] == PCP_ASYM_CIPHER_SIG) { else if(head[0] == PCP_ASYM_CIPHER_SIG) {
self = 0; self = 0;
verify = 1; verify = 1;
} }
else { else {
fatal(ptx, "Unknown file header (got: %02x)\n", head[0]); fatal(ptx, "Unknown file header (got: %02x)\n", head[0]);
goto errdef1; goto errdef1;
} }
} }
} }
@@ -212,7 +212,7 @@ size_t pcp_decrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t
cur_bufsize = ps_read(in, rec_buf, PCP_ASYM_RECIPIENT_SIZE); cur_bufsize = ps_read(in, rec_buf, PCP_ASYM_RECIPIENT_SIZE);
if(cur_bufsize != PCP_ASYM_RECIPIENT_SIZE && !ps_end(in) && !ps_err(in)) { if(cur_bufsize != PCP_ASYM_RECIPIENT_SIZE && !ps_end(in) && !ps_err(in)) {
fatal(ptx, "Error: input file corrupted, incomplete or no recipients (got %ld, exp %ld)\n", fatal(ptx, "Error: input file corrupted, incomplete or no recipients (got %ld, exp %ld)\n",
cur_bufsize, PCP_ASYM_RECIPIENT_SIZE ); cur_bufsize, PCP_ASYM_RECIPIENT_SIZE );
ucfree(rec_buf, PCP_ASYM_RECIPIENT_SIZE); ucfree(rec_buf, PCP_ASYM_RECIPIENT_SIZE);
goto errdef1; goto errdef1;
} }
@@ -223,58 +223,58 @@ size_t pcp_decrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t
byte *recipient; byte *recipient;
recipient = pcp_box_decrypt(ptx, s, senderpub, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size); recipient = pcp_box_decrypt(ptx, s, senderpub, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size);
if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) { if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) {
/* found a match */ /* found a match */
recmatch = 1; recmatch = 1;
symkey = smalloc(crypto_secretbox_KEYBYTES); symkey = smalloc(crypto_secretbox_KEYBYTES);
memcpy(symkey, recipient, crypto_secretbox_KEYBYTES); memcpy(symkey, recipient, crypto_secretbox_KEYBYTES);
free(recipient); free(recipient);
ucfree(senderpub, sizeof(pcp_pubkey_t)); ucfree(senderpub, sizeof(pcp_pubkey_t));
if(verify) { if(verify) {
memcpy(reccipher, rec_buf, PCP_ASYM_RECIPIENT_SIZE); memcpy(reccipher, rec_buf, PCP_ASYM_RECIPIENT_SIZE);
} }
nrec++; /* otherwise missing */ nrec++; /* otherwise missing */
break; break;
} }
free(recipient); free(recipient);
} }
else { else {
/* dig through our list of known public keys for a match */ /* dig through our list of known public keys for a match */
pcphash_iteratepub(ptx, cur) { pcphash_iteratepub(ptx, cur) {
byte *recipient; byte *recipient;
recipient = pcp_box_decrypt(ptx, s, cur, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size); recipient = pcp_box_decrypt(ptx, s, cur, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size);
if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) { if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) {
/* found a match */ /* found a match */
recmatch = 1; recmatch = 1;
symkey = smalloc(crypto_secretbox_KEYBYTES); symkey = smalloc(crypto_secretbox_KEYBYTES);
memcpy(symkey, recipient, crypto_secretbox_KEYBYTES); memcpy(symkey, recipient, crypto_secretbox_KEYBYTES);
free(recipient); free(recipient);
break; break;
} }
free(recipient); free(recipient);
} }
/* do the same with our secret keys, just in case the sender used -M */ /* do the same with our secret keys, just in case the sender used -M */
if(recmatch == 0) { if(recmatch == 0) {
pcp_key_t *k; pcp_key_t *k;
pcphash_iterate(ptx, k) { pcphash_iterate(ptx, k) {
if(fromsec != NULL) if(fromsec != NULL)
ucfree(fromsec, sizeof(pcp_pubkey_t)); /* avoid overwrite of used mem */ ucfree(fromsec, sizeof(pcp_pubkey_t)); /* avoid overwrite of used mem */
fromsec = pcpkey_pub_from_secret(k); fromsec = pcpkey_pub_from_secret(k);
byte *recipient; byte *recipient;
recipient = pcp_box_decrypt(ptx, s, fromsec, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size); recipient = pcp_box_decrypt(ptx, s, fromsec, rec_buf, PCP_ASYM_RECIPIENT_SIZE, &rec_size);
if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) { if(recipient != NULL && rec_size == crypto_secretbox_KEYBYTES) {
/* found a match */ /* found a match */
recmatch = 1; recmatch = 1;
symkey = smalloc(crypto_secretbox_KEYBYTES); symkey = smalloc(crypto_secretbox_KEYBYTES);
memcpy(symkey, recipient, crypto_secretbox_KEYBYTES); memcpy(symkey, recipient, crypto_secretbox_KEYBYTES);
free(recipient); free(recipient);
cur = fromsec; cur = fromsec;
break; break;
} }
} }
} }
} }
if(verify) { if(verify) {
@@ -316,7 +316,7 @@ size_t pcp_decrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t
} }
size_t pcp_encrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream *out, pcp_key_t *secret, size_t pcp_encrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream *out, pcp_key_t *secret,
pcp_key_t *signsecret, pcp_pubkey_t *p, int sign, int anon) { pcp_key_t *signsecret, pcp_pubkey_t *p, int sign, int anon) {
byte *symkey; byte *symkey;
int recipient_count; int recipient_count;
byte *recipients_cipher; byte *recipients_cipher;
@@ -349,7 +349,7 @@ size_t pcp_encrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream *out, pcp_key_t
if(es != rec_size) { if(es != rec_size) {
fatal(ptx, "invalid rec_size, expected %dl, got %dl\n", rec_size, es); fatal(ptx, "invalid rec_size, expected %dl, got %dl\n", rec_size, es);
if(rec_cipher != NULL) if(rec_cipher != NULL)
free(rec_cipher); free(rec_cipher);
goto errec1; goto errec1;
} }
@@ -530,7 +530,7 @@ size_t pcp_encrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream *out, byte *
} }
size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out,
byte *symkey, pcp_rec_t *recverify) { byte *symkey, pcp_rec_t *recverify) {
byte *buf_nonce; byte *buf_nonce;
byte *buf_cipher; byte *buf_cipher;
byte *buf_clear; byte *buf_clear;
@@ -569,9 +569,9 @@ size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out,
if(recverify != NULL) { if(recverify != NULL) {
if(cur_bufsize < PCP_BLOCK_SIZE_IN || ps_end(in)) { if(cur_bufsize < PCP_BLOCK_SIZE_IN || ps_end(in)) {
/* pull out signature */ /* pull out signature */
memcpy(signature_cr, &in_buf[cur_bufsize - siglen_cr], siglen_cr); memcpy(signature_cr, &in_buf[cur_bufsize - siglen_cr], siglen_cr);
cur_bufsize -= siglen_cr; cur_bufsize -= siglen_cr;
} }
} }
@@ -585,7 +585,7 @@ size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out,
ctr = _get_nonce_ctr(buf_nonce); ctr = _get_nonce_ctr(buf_nonce);
if(ctr -1 != pastctr) { if(ctr -1 != pastctr) {
fatal(ptx, "Mangled packet order, bailing out (got: %ld, expected: %ld)!\n", fatal(ptx, "Mangled packet order, bailing out (got: %ld, expected: %ld)!\n",
ctr, pastctr+1); ctr, pastctr+1);
out_size = 0; out_size = 0;
break; break;
} }
@@ -598,12 +598,12 @@ size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out,
ps_write(out, buf_clear, ciphersize - LMAC); ps_write(out, buf_clear, ciphersize - LMAC);
if(recverify != NULL) if(recverify != NULL)
crypto_generichash_update(st, buf_cipher, ciphersize); crypto_generichash_update(st, buf_cipher, ciphersize);
if(ps_err(out) != 0) { if(ps_err(out) != 0) {
fatal(ptx, "Failed to write decrypted output!\n"); fatal(ptx, "Failed to write decrypted output!\n");
out_size = 0; out_size = 0;
break; break;
} }
} }
else { else {
@@ -622,7 +622,7 @@ size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out,
memcpy(buf_nonce, signature_cr, LNONCE); memcpy(buf_nonce, signature_cr, LNONCE);
es = pcp_sodium_verify_mac(&signature, &signature_cr[LNONCE], es = pcp_sodium_verify_mac(&signature, &signature_cr[LNONCE],
siglen_cr - LNONCE, buf_nonce, symkey); siglen_cr - LNONCE, buf_nonce, symkey);
if(es == 0) { if(es == 0) {
/* add encrypted recipient list to the hash */ /* add encrypted recipient list to the hash */
crypto_generichash_update(st, recverify->cipher, recverify->ciphersize); crypto_generichash_update(st, recverify->cipher, recverify->ciphersize);
@@ -631,28 +631,28 @@ size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out,
byte *verifiedhash = NULL; byte *verifiedhash = NULL;
if(recverify->pub == NULL) { if(recverify->pub == NULL) {
/* anonymous encrypted but with known pub signed, /* anonymous encrypted but with known pub signed,
dig through our list of known public keys for a match */ dig through our list of known public keys for a match */
pcp_pubkey_t *cur; pcp_pubkey_t *cur;
pcphash_iteratepub(ptx, cur) { pcphash_iteratepub(ptx, cur) {
verifiedhash = pcp_ed_verify(ptx, signature, siglen, cur); verifiedhash = pcp_ed_verify(ptx, signature, siglen, cur);
if(verifiedhash != NULL) if(verifiedhash != NULL)
break; break;
} }
} }
else { else {
verifiedhash = pcp_ed_verify(ptx, signature, siglen, recverify->pub); verifiedhash = pcp_ed_verify(ptx, signature, siglen, recverify->pub);
} }
if(verifiedhash == NULL) if(verifiedhash == NULL)
out_size = 0; out_size = 0;
else { else {
if(cst_time_memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) { if(cst_time_memcmp(verifiedhash, hash, crypto_generichash_BYTES_MAX) != 0) {
/* sig verified, but the hash doesn't match */ /* sig verified, but the hash doesn't match */
fatal(ptx, "signed hash doesn't match actual hash of signed decrypted file content\n"); fatal(ptx, "signed hash doesn't match actual hash of signed decrypted file content\n");
out_size = 0; out_size = 0;
} }
free(verifiedhash); free(verifiedhash);
} }
} }
else { else {

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -212,11 +212,11 @@ pcp_pubkey_t *pcp_ed_verify_buffered(PCPCTX *ptx, Pcpstream *in, pcp_pubkey_t *p
cur_bufsize = offset; cur_bufsize = offset;
gotsig = 1; gotsig = 1;
if(z85) { if(z85) {
cur_bufsize -= 1; cur_bufsize -= 1;
memcpy(z85encoded, &in_full[offset], zlen); memcpy(z85encoded, &in_full[offset], zlen);
} }
else else
memcpy(sighash, &in_full[offset + strlen(binsigstart)], mlen); memcpy(sighash, &in_full[offset + strlen(binsigstart)], mlen);
} }
else if(full_bufsize - offset == siglen) { else if(full_bufsize - offset == siglen) {
/* sig fits within the 2nd half */ /* sig fits within the 2nd half */
@@ -225,11 +225,11 @@ pcp_pubkey_t *pcp_ed_verify_buffered(PCPCTX *ptx, Pcpstream *in, pcp_pubkey_t *p
next_bufsize -= siglen; next_bufsize -= siglen;
gotsig = 1; gotsig = 1;
if(z85) { if(z85) {
cur_bufsize -= 1; cur_bufsize -= 1;
memcpy(z85encoded, &in_full[full_bufsize - siglen], siglen); memcpy(z85encoded, &in_full[full_bufsize - siglen], siglen);
} }
else else
memcpy(sighash, &in_full[full_bufsize - mlen], mlen); memcpy(sighash, &in_full[full_bufsize - mlen], mlen);
} }
else else
offset = 0; offset = 0;
@@ -276,7 +276,7 @@ pcp_pubkey_t *pcp_ed_verify_buffered(PCPCTX *ptx, Pcpstream *in, pcp_pubkey_t *p
pcphash_iteratepub(ptx, p) { pcphash_iteratepub(ptx, p) {
verifiedhash = pcp_ed_verify(ptx, sighash, mlen, p); verifiedhash = pcp_ed_verify(ptx, sighash, mlen, p);
if(verifiedhash != NULL) if(verifiedhash != NULL)
break; break;
} }
/* no pubkey found yet, try our own */ /* no pubkey found yet, try our own */
@@ -284,13 +284,13 @@ pcp_pubkey_t *pcp_ed_verify_buffered(PCPCTX *ptx, Pcpstream *in, pcp_pubkey_t *p
pcp_pubkey_t *pub; pcp_pubkey_t *pub;
pcphash_iterate(ptx, k) { pcphash_iterate(ptx, k) {
if(k->type == PCP_KEY_TYPE_MAINSECRET) { if(k->type == PCP_KEY_TYPE_MAINSECRET) {
pub = pcpkey_pub_from_secret(k); pub = pcpkey_pub_from_secret(k);
verifiedhash = pcp_ed_verify(ptx, sighash, mlen, pub); verifiedhash = pcp_ed_verify(ptx, sighash, mlen, pub);
if(verifiedhash != NULL) { if(verifiedhash != NULL) {
/* good, self-signed */ /* good, self-signed */
p = pub; p = pub;
break; break;
} }
} }
} }
} }
@@ -341,7 +341,7 @@ size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s) {
size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX;
ps_print(out, "%s\r\nVersion: PCP v%d.%d.%d\r\n", ps_print(out, "%s\r\nVersion: PCP v%d.%d.%d\r\n",
PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
size_t zlen; size_t zlen;
char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen, 1); char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen, 1);
ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END); ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END);
@@ -416,7 +416,7 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(PCPCTX *ptx, Pcpstream *in, Pcpstream
pcphash_iteratepub(ptx, p) { pcphash_iteratepub(ptx, p) {
verifiedhash = pcp_ed_verify(ptx, sighash, mlen, p); verifiedhash = pcp_ed_verify(ptx, sighash, mlen, p);
if(verifiedhash != NULL) if(verifiedhash != NULL)
break; break;
} }
/* no pubkey found yet, try our own */ /* no pubkey found yet, try our own */
@@ -424,13 +424,13 @@ pcp_pubkey_t *pcp_ed_detachverify_buffered(PCPCTX *ptx, Pcpstream *in, Pcpstream
pcp_pubkey_t *pub; pcp_pubkey_t *pub;
pcphash_iterate(ptx, k) { pcphash_iterate(ptx, k) {
if(k->type == PCP_KEY_TYPE_MAINSECRET) { if(k->type == PCP_KEY_TYPE_MAINSECRET) {
pub = pcpkey_pub_from_secret(k); pub = pcpkey_pub_from_secret(k);
verifiedhash = pcp_ed_verify(ptx, sighash, mlen, pub); verifiedhash = pcp_ed_verify(ptx, sighash, mlen, pub);
if(verifiedhash != NULL) { if(verifiedhash != NULL) {
/* good, self-signed */ /* good, self-signed */
p = pub; p = pub;
break; break;
} }
} }
} }
} }

View File

@@ -9,14 +9,14 @@ unsigned jen_hash ( unsigned char *k, unsigned length, unsigned initval ) {
while ( len >= 12 ) { while ( len >= 12 ) {
a += ( k[0] + ( (unsigned)k[1] << 8 ) a += ( k[0] + ( (unsigned)k[1] << 8 )
+ ( (unsigned)k[2] << 16 ) + ( (unsigned)k[2] << 16 )
+ ( (unsigned)k[3] << 24 ) ); + ( (unsigned)k[3] << 24 ) );
b += ( k[4] + ( (unsigned)k[5] << 8 ) b += ( k[4] + ( (unsigned)k[5] << 8 )
+ ( (unsigned)k[6] << 16 ) + ( (unsigned)k[6] << 16 )
+ ( (unsigned)k[7] << 24 ) ); + ( (unsigned)k[7] << 24 ) );
c += ( k[8] + ( (unsigned)k[9] << 8 ) c += ( k[8] + ( (unsigned)k[9] << 8 )
+ ( (unsigned)k[10] << 16 ) + ( (unsigned)k[10] << 16 )
+ ( (unsigned)k[11] << 24 ) ); + ( (unsigned)k[11] << 24 ) );
jen_mix ( a, b, c ); jen_mix ( a, b, c );

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -367,13 +367,13 @@ int pcp_sanitycheck_pub(PCPCTX *ptx, pcp_pubkey_t *key) {
if(key->type != PCP_KEY_TYPE_PUBLIC) { if(key->type != PCP_KEY_TYPE_PUBLIC) {
fatal(ptx, "Pubkey sanity check: key type is not PUBLIC (expected: %02x, got: %02x)!\n", fatal(ptx, "Pubkey sanity check: key type is not PUBLIC (expected: %02x, got: %02x)!\n",
PCP_KEY_TYPE_PUBLIC, key->type); PCP_KEY_TYPE_PUBLIC, key->type);
return 1; return 1;
} }
if(key->version != PCP_KEY_VERSION) { if(key->version != PCP_KEY_VERSION) {
fatal(ptx, "Pubkey sanity check: unknown key version (expected: %08X, got: %08X)!\n", fatal(ptx, "Pubkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
PCP_KEY_VERSION, key->version); PCP_KEY_VERSION, key->version);
return 1; return 1;
} }
@@ -418,13 +418,13 @@ int pcp_sanitycheck_key(PCPCTX *ptx, pcp_key_t *key) {
if(key->type != PCP_KEY_TYPE_SECRET && key->type != PCP_KEY_TYPE_MAINSECRET) { if(key->type != PCP_KEY_TYPE_SECRET && key->type != PCP_KEY_TYPE_MAINSECRET) {
fatal(ptx, "Secretkey sanity check: key type is not SECRET (expected: %02x, got: %02x)!\n", fatal(ptx, "Secretkey sanity check: key type is not SECRET (expected: %02x, got: %02x)!\n",
PCP_KEY_TYPE_SECRET, key->type); PCP_KEY_TYPE_SECRET, key->type);
return 1; return 1;
} }
if(key->version != PCP_KEY_VERSION) { if(key->version != PCP_KEY_VERSION) {
fatal(ptx, "Secretkey sanity check: unknown key version (expected: %08X, got: %08X)!\n", fatal(ptx, "Secretkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
PCP_KEY_VERSION, key->version); PCP_KEY_VERSION, key->version);
return 1; return 1;
} }

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -42,17 +42,17 @@ int _check_keysig_h(PCPCTX *ptx, Buffer *blob, rfc_pub_sig_h *h) {
if(h->version != EXP_SIG_VERSION) { if(h->version != EXP_SIG_VERSION) {
fatal(ptx, "Unsupported pubkey signature version %d, expected %d\n", fatal(ptx, "Unsupported pubkey signature version %d, expected %d\n",
h->version, EXP_SIG_VERSION); h->version, EXP_SIG_VERSION);
return 1; return 1;
} }
if(h->type != EXP_SIG_TYPE) { if(h->type != EXP_SIG_TYPE) {
fatal(ptx, "Unsupported pubkey signature type %d, expected %d\n", fatal(ptx, "Unsupported pubkey signature type %d, expected %d\n",
h->type, EXP_SIG_TYPE); h->type, EXP_SIG_TYPE);
return 1; return 1;
} }
if(h->pkcipher != EXP_SIG_CIPHER) { if(h->pkcipher != EXP_SIG_CIPHER) {
fatal(ptx, "Unsupported pubkey signature cipher %d, expected %d\n", fatal(ptx, "Unsupported pubkey signature cipher %d, expected %d\n",
h->pkcipher, EXP_SIG_CIPHER); h->pkcipher, EXP_SIG_CIPHER);
return 1; return 1;
} }
if(h->hashcipher != EXP_HASH_CIPHER) { if(h->hashcipher != EXP_HASH_CIPHER) {
@@ -61,7 +61,7 @@ int _check_keysig_h(PCPCTX *ptx, Buffer *blob, rfc_pub_sig_h *h) {
} }
if(h->numsubs > 0 && buffer_left(blob) < sizeof(rfc_pub_sig_s) * h->numsubs) { if(h->numsubs > 0 && buffer_left(blob) < sizeof(rfc_pub_sig_s) * h->numsubs) {
fatal(ptx, "Signature size specification invalid (sig: %ld, bytes left: %ld, numsubs: %ld\n", fatal(ptx, "Signature size specification invalid (sig: %ld, bytes left: %ld, numsubs: %ld\n",
sizeof(rfc_pub_sig_s) * h->numsubs, buffer_left(blob), h->numsubs); sizeof(rfc_pub_sig_s) * h->numsubs, buffer_left(blob), h->numsubs);
return 1; return 1;
} }
return 0; return 0;
@@ -107,14 +107,14 @@ int _check_sigsubs(PCPCTX *ptx, Buffer *blob, pcp_pubkey_t *p, rfc_pub_sig_s *su
if(strncmp(notation, "owner", 5) == 0) { if(strncmp(notation, "owner", 5) == 0) {
if(buffer_get_chunk(blob, p->owner, vsize) == 0) { if(buffer_get_chunk(blob, p->owner, vsize) == 0) {
fatal(ptx, "Invalid 'owner' notation, expected %ld bytes, but got 0\n", vsize); fatal(ptx, "Invalid 'owner' notation, expected %ld bytes, but got 0\n", vsize);
goto sgcerr; goto sgcerr;
} }
} }
else if(strncmp(notation, "mail", 4) == 0) { else if(strncmp(notation, "mail", 4) == 0) {
if(buffer_get_chunk(blob, p->mail, vsize) == 0) { if(buffer_get_chunk(blob, p->mail, vsize) == 0) {
fatal(ptx, "Invalid 'mail' notation, expected %ld bytes, but got 0\n", vsize); fatal(ptx, "Invalid 'mail' notation, expected %ld bytes, but got 0\n", vsize);
goto sgcerr; goto sgcerr;
} }
} }
else if(strncmp(notation, "serial", 6) == 0) { else if(strncmp(notation, "serial", 6) == 0) {
@@ -487,10 +487,10 @@ Buffer *pcp_export_pbp_pub(pcp_key_t *sk) {
v = localtime(&vt); v = localtime(&vt);
date = ucmalloc(65); date = ucmalloc(65);
sprintf(date, "%04d-%02d-%02dT%02d:%02d:%02d.000000 %04d-%02d-%02dT%02d:%02d:%02d.000000 ", sprintf(date, "%04d-%02d-%02dT%02d:%02d:%02d.000000 %04d-%02d-%02dT%02d:%02d:%02d.000000 ",
c->tm_year+1900-1, c->tm_mon+1, c->tm_mday, // wtf? why -1? c->tm_year+1900-1, c->tm_mon+1, c->tm_mday, // wtf? why -1?
c->tm_hour, c->tm_min, c->tm_sec, c->tm_hour, c->tm_min, c->tm_sec,
v->tm_year+1900-1, v->tm_mon+1, v->tm_mday, v->tm_year+1900-1, v->tm_mon+1, v->tm_mday,
v->tm_hour, v->tm_min, v->tm_sec); v->tm_hour, v->tm_min, v->tm_sec);
buffer_add(sig, date, 64); buffer_add(sig, date, 64);
/* add owner */ /* add owner */
@@ -781,15 +781,15 @@ pcp_key_t *pcp_import_secret_native(PCPCTX *ptx, Buffer *cipher, char *passphras
cipherlen = buffer_left(cipher); cipherlen = buffer_left(cipher);
if(cipherlen < minlen) { if(cipherlen < minlen) {
fatal(ptx, "failed to decrypt the secret key file:\n" fatal(ptx, "failed to decrypt the secret key file:\n"
"expected encrypted secret key size %ld is less than minimum len %ld\n", "expected encrypted secret key size %ld is less than minimum len %ld\n",
cipherlen, minlen); cipherlen, minlen);
goto impserr1; goto impserr1;
} }
/* decrypt the blob */ /* decrypt the blob */
clear = ucmalloc(cipherlen - LMAC); clear = ucmalloc(cipherlen - LMAC);
if(pcp_sodium_verify_mac(&clear, buffer_get_remainder(cipher), if(pcp_sodium_verify_mac(&clear, buffer_get_remainder(cipher),
cipherlen, nonce, symkey) != 0) { cipherlen, nonce, symkey) != 0) {
fatal(ptx, "failed to decrypt the secret key file\n"); fatal(ptx, "failed to decrypt the secret key file\n");
goto impserr1; goto impserr1;
@@ -914,20 +914,20 @@ json_t *pcp_sk2json(pcp_key_t *sk, byte *sig, size_t siglen) {
} }
jout = json_pack(jformat, jout = json_pack(jformat,
"id", sk->id, "id" , sk->id,
"owner", sk->owner, "owner" , sk->owner,
"mail", sk->mail, "mail" , sk->mail,
"ctime", (json_int_t)sk->ctime, "ctime" , (json_int_t)sk->ctime,
"expire", (json_int_t)sk->ctime+31536000, "expire" , (json_int_t)sk->ctime+31536000,
"version", (json_int_t)sk->version, "version" , (json_int_t)sk->version,
"serial", (json_int_t)sk->serial, "serial" , (json_int_t)sk->serial,
"type", "public", "type" , "public",
"cipher", EXP_PK_CIPHER_NAME, "cipher" , EXP_PK_CIPHER_NAME,
"cryptpub", cryptpub, "cryptpub" , cryptpub,
"sigpub", sigpub, "sigpub" , sigpub,
"masterpub", masterpub, "masterpub" , masterpub,
"signature", ssig "signature" , ssig
); );
free(cryptpub); free(cryptpub);
free(sigpub); free(sigpub);

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -109,12 +109,12 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) {
if(buffer_left(stream->save) >= readbytes) { if(buffer_left(stream->save) >= readbytes) {
gotbytes = buffer_get_chunk(stream->save, buf, readbytes); gotbytes = buffer_get_chunk(stream->save, buf, readbytes);
if(buffer_left(stream->save) == 0) if(buffer_left(stream->save) == 0)
buffer_clear(stream->save); buffer_clear(stream->save);
goto rawdone; goto rawdone;
} }
else { else {
/* fetch the remainder of the save buffer, remember how much /* fetch the remainder of the save buffer, remember how much
to fetch from source next */ to fetch from source next */
idx = buffer_get_chunk(stream->save, buf, buffer_left(stream->save)); idx = buffer_get_chunk(stream->save, buf, buffer_left(stream->save));
buffer_clear(stream->save); buffer_clear(stream->save);
readbytes -= idx; readbytes -= idx;
@@ -159,10 +159,10 @@ size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes) {
size_t ps_read_cached(Pcpstream *stream, void *buf, size_t readbytes) { size_t ps_read_cached(Pcpstream *stream, void *buf, size_t readbytes) {
/* /*
fprintf(stderr, "%ld <= %ld && %ld <= %ld\n", fprintf(stderr, "%ld <= %ld && %ld <= %ld\n",
readbytes, buffer_left(stream->cache), readbytes, stream->blocksize) ; readbytes, buffer_left(stream->cache), readbytes, stream->blocksize) ;
fprintf(stderr, "%d == 1 && %ld >= %ld\n", fprintf(stderr, "%d == 1 && %ld >= %ld\n",
ps_end(stream), readbytes, buffer_left(stream->cache)); ps_end(stream), readbytes, buffer_left(stream->cache));
*/ */
if(readbytes <= buffer_left(stream->cache) && readbytes <= stream->blocksize) { if(readbytes <= buffer_left(stream->cache) && readbytes <= stream->blocksize) {
/* enough left in current cache */ /* enough left in current cache */
@@ -194,35 +194,35 @@ size_t ps_read_cached(Pcpstream *stream, void *buf, size_t readbytes) {
/* not enough cached, fetch the next chunk */ /* not enough cached, fetch the next chunk */
// fprintf(stderr, " fetch next read_next\n"); // fprintf(stderr, " fetch next read_next\n");
if(ps_read_next(stream) == 0) if(ps_read_next(stream) == 0)
break; break;
// fprintf(stderr, " fetch next read_continue\n"); // fprintf(stderr, " fetch next read_continue\n");
/* need to fetch more? */ /* need to fetch more? */
left = readbytes - (buffer_size(tmp) + buffer_size(stream->next)); left = readbytes - (buffer_size(tmp) + buffer_size(stream->next));
if(left < 0) { if(left < 0) {
/* no more to fetch, in fact there's more than we need */ /* no more to fetch, in fact there's more than we need */
/* determine overlapping bytes */ /* determine overlapping bytes */
size_t overlap = readbytes - buffer_size(tmp); size_t overlap = readbytes - buffer_size(tmp);
/* avoid overflow */ /* avoid overflow */
if(overlap > buffer_size(stream->next)) if(overlap > buffer_size(stream->next))
overlap = buffer_size(stream->next); overlap = buffer_size(stream->next);
/* add the overlap from next to tmp */ /* add the overlap from next to tmp */
buffer_get_chunk_tobuf(stream->next, tmp, overlap); buffer_get_chunk_tobuf(stream->next, tmp, overlap);
/* move the rest of stream->next into cache */ /* move the rest of stream->next into cache */
buffer_clear(stream->cache); buffer_clear(stream->cache);
buffer_get_chunk_tobuf(stream->next, stream->cache, buffer_left(stream->next)); buffer_get_chunk_tobuf(stream->next, stream->cache, buffer_left(stream->next));
buffer_clear(stream->next); buffer_clear(stream->next);
} }
else { else {
/* we've got precisely what we need, no need to calculate any overlap /* we've got precisely what we need, no need to calculate any overlap
OR there's more to fetch, we don't have enough stuff yet, OR there's more to fetch, we don't have enough stuff yet,
put next into tmp, reset next and loop again - same behavior */ put next into tmp, reset next and loop again - same behavior */
buffer_add_buf(tmp, stream->next); buffer_add_buf(tmp, stream->next);
buffer_clear(stream->next); buffer_clear(stream->next);
} }
} }
@@ -278,7 +278,7 @@ size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes) {
} }
else if(stream->armor == 1) { else if(stream->armor == 1) {
/* z85 encoding has already been determined, therefore the cache /* z85 encoding has already been determined, therefore the cache
is now filled, use it then */ is now filled, use it then */
got = ps_read_cached(stream, buf, readbytes); got = ps_read_cached(stream, buf, readbytes);
// fprintf(stderr, "%ld = ps_read_cached(stream, buf, readbytes);\n", got); // fprintf(stderr, "%ld = ps_read_cached(stream, buf, readbytes);\n", got);
} }
@@ -395,49 +395,49 @@ size_t ps_read_decode(Pcpstream *stream) {
while(buffer_size(z) < stream->blocksize) { while(buffer_size(z) < stream->blocksize) {
buffer_clear(line); buffer_clear(line);
if(ps_readline(stream, line) >= 0) { if(ps_readline(stream, line) >= 0) {
//fprintf(stderr, "got: <%s>\n", buffer_get_str(line)); //fprintf(stderr, "got: <%s>\n", buffer_get_str(line));
if(z85_isbegin(line) && stream->have_begin == 0) { if(z85_isbegin(line) && stream->have_begin == 0) {
/* begin header encountered */ /* begin header encountered */
stream->have_begin = 1; /* otherwise ignore it */ stream->have_begin = 1; /* otherwise ignore it */
continue; continue;
} }
else if(z85_isend(line)) { else if(z85_isend(line)) {
/* end header encountered */ /* end header encountered */
break; break;
} }
else if(z85_isempty(line)) { else if(z85_isempty(line)) {
/* ignore empty lines */ /* ignore empty lines */
continue; continue;
} }
else { else {
/* regular z85 encoded content */ /* regular z85 encoded content */
// fprintf(stderr, "regular\n"); // fprintf(stderr, "regular\n");
// fprintf(stderr, " %ld + %ld > %ld\n", buffer_size(z), buffer_size(line), stream->blocksize); // fprintf(stderr, " %ld + %ld > %ld\n", buffer_size(z), buffer_size(line), stream->blocksize);
if(buffer_size(z) + buffer_size(line) > stream->blocksize) { if(buffer_size(z) + buffer_size(line) > stream->blocksize) {
/* we've got more than needed. /* we've got more than needed.
put what we need into z and the remainder put what we need into z and the remainder
into the save buffer for further reading. */ into the save buffer for further reading. */
/* fprintf(stderr, "overflow %ld + %ld > %ld\n", /* fprintf(stderr, "overflow %ld + %ld > %ld\n",
buffer_size(z), buffer_size(line), stream->blocksize); buffer_size(z), buffer_size(line), stream->blocksize);
*/ */
buffer_get_chunk_tobuf(line, z, stream->blocksize - buffer_size(z)); buffer_get_chunk_tobuf(line, z, stream->blocksize - buffer_size(z));
buffer_get_chunk_tobuf(line, stream->save, buffer_left(line)); buffer_get_chunk_tobuf(line, stream->save, buffer_left(line));
if(!ps_left(stream)) { if(!ps_left(stream)) {
/* only add the newline if there's no more to follow */ /* only add the newline if there's no more to follow */
buffer_add8(stream->save, '\n'); buffer_add8(stream->save, '\n');
} }
break; break;
} }
else { else {
/* not enough yet, store it and go on */ /* not enough yet, store it and go on */
buffer_add_buf(z, line); buffer_add_buf(z, line);
} }
} }
} }
else { else {
// fprintf(stderr, " ps_read_next readline returned 0\n"); // fprintf(stderr, " ps_read_next readline returned 0\n");
/* eof or err */ /* eof or err */
break; break;
} }
} }
} }
@@ -503,15 +503,15 @@ size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes) {
buffer_add_buf(tmp, stream->cache); buffer_add_buf(tmp, stream->cache);
while (buffer_left(tmp) > stream->blocksize) { while (buffer_left(tmp) > stream->blocksize) {
/* iterate over tmp blockwise, encode each block, write it out until there's a rest */ /* iterate over tmp blockwise, encode each block, write it out until there's a rest */
buffer_clear(stream->cache); buffer_clear(stream->cache);
buffer_get_chunk_tobuf(tmp, stream->cache, stream->blocksize); buffer_get_chunk_tobuf(tmp, stream->cache, stream->blocksize);
ps_write_encode(stream, z); ps_write_encode(stream, z);
} }
/* now, z contains a couple of z85 encoded blocks, tmp contains the /* now, z contains a couple of z85 encoded blocks, tmp contains the
remainder of the write buffer, store the rest in the cache and remainder of the write buffer, store the rest in the cache and
go on as nothing did happen */ go on as nothing did happen */
buffer_clear(stream->cache); buffer_clear(stream->cache);
buffer_add(stream->cache, buffer_get_remainder(tmp), buffer_left(tmp)); buffer_add(stream->cache, buffer_get_remainder(tmp), buffer_left(tmp));
buffer_free(tmp); buffer_free(tmp);
@@ -523,14 +523,14 @@ size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes) {
void *aside = NULL; void *aside = NULL;
size_t overlap = (buffer_size(stream->cache) + writebytes) - stream->blocksize; size_t overlap = (buffer_size(stream->cache) + writebytes) - stream->blocksize;
if(overlap > 0) { if(overlap > 0) {
/* yes, store the overlap, put the left part into the cache */ /* yes, store the overlap, put the left part into the cache */
aside = ucmalloc(overlap); aside = ucmalloc(overlap);
memcpy(aside, buf + (writebytes - overlap), overlap); /* FIXME: check if this works */ memcpy(aside, buf + (writebytes - overlap), overlap); /* FIXME: check if this works */
buffer_add(stream->cache, buf, writebytes - overlap); buffer_add(stream->cache, buf, writebytes - overlap);
} }
else { else {
/* cache+buf == blocksize */ /* cache+buf == blocksize */
buffer_add(stream->cache, buf, writebytes); buffer_add(stream->cache, buf, writebytes);
} }
/* encode the cache into z */ /* encode the cache into z */
@@ -538,10 +538,10 @@ size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes) {
buffer_clear(stream->cache); buffer_clear(stream->cache);
if(aside != NULL) { if(aside != NULL) {
/* there is an overlapping rest, put it into the cache /* there is an overlapping rest, put it into the cache
the caller needs to call ps_finish() to put it out */ the caller needs to call ps_finish() to put it out */
buffer_add(stream->cache, aside, overlap); buffer_add(stream->cache, aside, overlap);
free(aside); free(aside);
} }
} }
} }
@@ -645,7 +645,7 @@ void ps_close(Pcpstream *stream) {
if(stream->cache != NULL) { if(stream->cache != NULL) {
if(stream->is_output == 1) { if(stream->is_output == 1) {
if(buffer_left(stream->cache) != 0) if(buffer_left(stream->cache) != 0)
buffer_info(stream->cache); buffer_info(stream->cache);
assert(buffer_left(stream->cache) == 0); /* there's something left in the cache, call ps_finish() */ assert(buffer_left(stream->cache) == 0); /* there's something left in the cache, call ps_finish() */
} }
buffer_free(stream->cache); buffer_free(stream->cache);

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -54,9 +54,9 @@ int vasprintf(char **ret, const char *format, va_list args) {
if (buffer != NULL) { if (buffer != NULL) {
count = vsnprintf(buffer, count + 1, format, copy); count = vsnprintf(buffer, count + 1, format, copy);
if (count < 0) if (count < 0)
free(buffer); free(buffer);
else else
*ret = buffer; *ret = buffer;
} }
} }
va_end(copy); /* Each va_start() or va_copy() needs a va_end() */ va_end(copy); /* Each va_start() or va_copy() needs a va_end() */
@@ -92,11 +92,11 @@ strnstr(const char *s, const char *find, size_t slen)
len = strlen(find); len = strlen(find);
do { do {
do { do {
if (slen-- < 1 || (sc = *s++) == '\0') if (slen-- < 1 || (sc = *s++) == '\0')
return (NULL); return (NULL);
} while (sc != c); } while (sc != c);
if (len > slen) if (len > slen)
return (NULL); return (NULL);
} while (strncmp(s, find, len) != 0); } while (strncmp(s, find, len) != 0);
s--; s--;
} }

View File

@@ -43,127 +43,127 @@
*/ */
int int
pcp_readpass(PCPCTX *ptx, char ** passwd, const char * prompt, pcp_readpass(PCPCTX *ptx, char ** passwd, const char * prompt,
const char * confirmprompt, int devtty, char *readfromfile) const char * confirmprompt, int devtty, char *readfromfile)
{ {
FILE * readfrom; FILE * readfrom;
char passbuf[MAXPASSLEN]; char passbuf[MAXPASSLEN];
char confpassbuf[MAXPASSLEN]; char confpassbuf[MAXPASSLEN];
struct termios term, term_old; struct termios term, term_old;
int usingtty; int usingtty;
/* /*
* If devtty != 0, try to open /dev/tty; if that fails, or if devtty * If devtty != 0, try to open /dev/tty; if that fails, or if devtty
* is zero, we'll read the password from stdin instead. * is zero, we'll read the password from stdin instead.
* *
* Added by tlinden: however, if readfromfile is defined, we'll * Added by tlinden: however, if readfromfile is defined, we'll
* read the password from there, but if it is '-' we'll use stdin * read the password from there, but if it is '-' we'll use stdin
* as well. * as well.
*/ */
if ((devtty == 0) || ((readfrom = fopen("/dev/tty", "r")) == NULL)) { if ((devtty == 0) || ((readfrom = fopen("/dev/tty", "r")) == NULL)) {
if(readfromfile != NULL) { if(readfromfile != NULL) {
// FIXME: check if readfromfile is executable, // FIXME: check if readfromfile is executable,
// if yes, call askextpass(tobewritten) and // if yes, call askextpass(tobewritten) and
// read from the returned fd somehow // read from the returned fd somehow
if(readfromfile[0] == '-') { if(readfromfile[0] == '-') {
readfrom = stdin; readfrom = stdin;
} }
else { else {
if((readfrom = fopen(readfromfile, "r")) == NULL) { if((readfrom = fopen(readfromfile, "r")) == NULL) {
fatal(ptx, "Could not open password file '%s'\n", readfromfile); fatal(ptx, "Could not open password file '%s'\n", readfromfile);
goto err1; goto err1;
} }
} }
} }
else { else {
readfrom = stdin; readfrom = stdin;
} }
} }
/* If we're reading from a terminal, try to disable echo. */ /* If we're reading from a terminal, try to disable echo. */
if ((usingtty = isatty(fileno(readfrom))) != 0) { if ((usingtty = isatty(fileno(readfrom))) != 0) {
if (tcgetattr(fileno(readfrom), &term_old)) { if (tcgetattr(fileno(readfrom), &term_old)) {
fatal(ptx, "Cannot read terminal settings\n"); fatal(ptx, "Cannot read terminal settings\n");
goto err1; goto err1;
} }
memcpy(&term, &term_old, sizeof(struct termios)); memcpy(&term, &term_old, sizeof(struct termios));
term.c_lflag = (term.c_lflag & ~ECHO) | ECHONL; term.c_lflag = (term.c_lflag & ~ECHO) | ECHONL;
if (tcsetattr(fileno(readfrom), TCSANOW, &term)) { if (tcsetattr(fileno(readfrom), TCSANOW, &term)) {
fatal(ptx, "Cannot set terminal settings\n"); fatal(ptx, "Cannot set terminal settings\n");
goto err1; goto err1;
} }
} }
retry: retry:
/* If we have a terminal, prompt the user to enter the password. */ /* If we have a terminal, prompt the user to enter the password. */
if (usingtty) if (usingtty)
fprintf(stderr, "%s: ", prompt); fprintf(stderr, "%s: ", prompt);
/* Read the password. */ /* Read the password. */
if (fgets(passbuf, MAXPASSLEN, readfrom) == NULL) { if (fgets(passbuf, MAXPASSLEN, readfrom) == NULL) {
fatal(ptx, "Cannot read password\n"); fatal(ptx, "Cannot read password\n");
goto err2; goto err2;
} }
/* Confirm the password if necessary. */ /* Confirm the password if necessary. */
if (confirmprompt != NULL) { if (confirmprompt != NULL) {
if (usingtty) if (usingtty)
fprintf(stderr, "%s: ", confirmprompt); fprintf(stderr, "%s: ", confirmprompt);
if (fgets(confpassbuf, MAXPASSLEN, readfrom) == NULL) { if (fgets(confpassbuf, MAXPASSLEN, readfrom) == NULL) {
fatal(ptx, "Cannot read password\n"); fatal(ptx, "Cannot read password\n");
goto err2; goto err2;
} }
if (strcmp(passbuf, confpassbuf)) { if (strcmp(passbuf, confpassbuf)) {
fprintf(stderr, fprintf(stderr,
"Passwords mismatch, please try again\n"); "Passwords mismatch, please try again\n");
goto retry; goto retry;
} }
} }
/* Terminate the string at the first "\r" or "\n" (if any). */ /* Terminate the string at the first "\r" or "\n" (if any). */
passbuf[strcspn(passbuf, "\r\n")] = '\0'; passbuf[strcspn(passbuf, "\r\n")] = '\0';
/* enforce no empty passwords */ /* enforce no empty passwords */
if (strnlen(passbuf, MAXPASSLEN) == 0) { if (strnlen(passbuf, MAXPASSLEN) == 0) {
fprintf(stderr, fprintf(stderr,
"Empty password not allowed, please try again\n"); "Empty password not allowed, please try again\n");
goto retry; goto retry;
} }
/* If we changed terminal settings, reset them. */ /* If we changed terminal settings, reset them. */
if (usingtty) if (usingtty)
tcsetattr(fileno(readfrom), TCSANOW, &term_old); tcsetattr(fileno(readfrom), TCSANOW, &term_old);
/* Close /dev/tty if we opened it. /* Close /dev/tty if we opened it.
if readfromfile is defined and set to -, disable stdin */ if readfromfile is defined and set to -, disable stdin */
if (readfrom != stdin) { if (readfrom != stdin) {
fclose(readfrom); fclose(readfrom);
} }
/* Copy the password out. */ /* Copy the password out. */
char *p = smalloc(strlen(passbuf) + 1); char *p = smalloc(strlen(passbuf) + 1);
memcpy(p, passbuf, strlen(passbuf) + 1 ); memcpy(p, passbuf, strlen(passbuf) + 1 );
*passwd = p; *passwd = p;
/* Zero any stored passwords. */ /* Zero any stored passwords. */
memset(passbuf, 0, MAXPASSLEN); memset(passbuf, 0, MAXPASSLEN);
memset(confpassbuf, 0, MAXPASSLEN); memset(confpassbuf, 0, MAXPASSLEN);
/* Success! */ /* Success! */
return (0); return (0);
err2: err2:
/* Reset terminal settings if necessary. */ /* Reset terminal settings if necessary. */
if (usingtty) if (usingtty)
tcsetattr(fileno(readfrom), TCSAFLUSH, &term_old); tcsetattr(fileno(readfrom), TCSAFLUSH, &term_old);
err1: err1:
/* Close /dev/tty if we opened it. */ /* Close /dev/tty if we opened it. */
if (readfrom != stdin) if (readfrom != stdin)
fclose(readfrom); fclose(readfrom);
/* Failure! */ /* Failure! */
return (-1); return (-1);
} }

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -30,8 +30,8 @@ byte* pcp_scrypt(PCPCTX *ptx, char *passwd, size_t passwdlen, byte *nonce, size_
nonce, noncelen, NULL, 0); nonce, noncelen, NULL, 0);
int status = crypto_pwhash_scryptsalsa208sha256(dk, 64, passwd, passwdlen, salt, int status = crypto_pwhash_scryptsalsa208sha256(dk, 64, passwd, passwdlen, salt,
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE,
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE); crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
ucfree(salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); ucfree(salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
if (status == 0) { if (status == 0) {

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T. von Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -69,7 +69,7 @@ void _dump(char *n, byte *d, size_t s) {
if(i % 36 == 35 && i > 0) { if(i % 36 == 35 && i > 0) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
for(c=0; c<l; ++c) for(c=0; c<l; ++c)
fprintf(stderr, " "); fprintf(stderr, " ");
} }
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -29,15 +29,15 @@ vault_t *pcpvault_init(PCPCTX *ptx, char *filename) {
if(vault != NULL) { if(vault != NULL) {
if(vault->isnew == 1) { if(vault->isnew == 1) {
if(pcpvault_create(ptx, vault) != 0) { if(pcpvault_create(ptx, vault) != 0) {
pcpvault_close(ptx, vault); pcpvault_close(ptx, vault);
return NULL; return NULL;
} }
} }
else { else {
if(pcpvault_fetchall(ptx, vault) != 0) { if(pcpvault_fetchall(ptx, vault) != 0) {
errno = 0; /* weird, something sets it to ENOENT and it's not me */ errno = 0; /* weird, something sets it to ENOENT and it's not me */
pcpvault_close(ptx, vault); pcpvault_close(ptx, vault);
return NULL; return NULL;
} }
} }
} }
@@ -57,7 +57,7 @@ vault_t *pcpvault_new(PCPCTX *ptx, char *filename, int is_tmp) {
b = arc4random(); b = arc4random();
snprintf(vault->filename, 1024, "%s-%08x%08x", filename, a, b); snprintf(vault->filename, 1024, "%s-%08x%08x", filename, a, b);
if (stat (vault->filename, &stat_buf) != 0) if (stat (vault->filename, &stat_buf) != 0)
break; break;
} }
unlink(vault->filename); unlink(vault->filename);
vault->size = 0; vault->size = 0;
@@ -226,25 +226,25 @@ int pcpvault_writeall(PCPCTX *ptx, vault_t *vault) {
pcp_key_t *k = NULL; pcp_key_t *k = NULL;
Buffer *blob = buffer_new(PCP_RAW_PUBKEYSIZE, "bs"); Buffer *blob = buffer_new(PCP_RAW_PUBKEYSIZE, "bs");
pcphash_iterate(ptx, k) { pcphash_iterate(ptx, k) {
pcp_seckeyblob(blob, k); pcp_seckeyblob(blob, k);
if(pcpvault_additem(ptx, tmp, buffer_get(blob), PCP_RAW_KEYSIZE, PCP_KEY_TYPE_SECRET) != 0) { if(pcpvault_additem(ptx, tmp, buffer_get(blob), PCP_RAW_KEYSIZE, PCP_KEY_TYPE_SECRET) != 0) {
buffer_free(blob); buffer_free(blob);
goto errwa; goto errwa;
} }
buffer_clear(blob); buffer_clear(blob);
} }
pcp_pubkey_t *p = NULL; pcp_pubkey_t *p = NULL;
pcphash_iteratepub(ptx, p) { pcphash_iteratepub(ptx, p) {
pcp_pubkeyblob(blob, p); pcp_pubkeyblob(blob, p);
if(pcpvault_additem(ptx, tmp, buffer_get(blob), PCP_RAW_PUBKEYSIZE, PCP_KEY_TYPE_PUBLIC) != 0) { if(pcpvault_additem(ptx, tmp, buffer_get(blob), PCP_RAW_PUBKEYSIZE, PCP_KEY_TYPE_PUBLIC) != 0) {
buffer_free(blob); buffer_free(blob);
goto errwa; goto errwa;
} }
buffer_clear(blob); buffer_clear(blob);
} }
pcpvault_update_checksum(ptx, tmp); pcpvault_update_checksum(ptx, tmp);
if(pcpvault_copy(ptx, tmp, vault) == 0) { if(pcpvault_copy(ptx, tmp, vault) == 0) {
pcpvault_unlink(tmp); pcpvault_unlink(tmp);
} }
pcpvault_free(tmp); pcpvault_free(tmp);
buffer_free(blob); buffer_free(blob);
@@ -337,7 +337,7 @@ int pcpvault_copy(PCPCTX *ptx, vault_t *tmp, vault_t *vault) {
vault->fd = freopen(vault->filename, "wb+", vault->fd); vault->fd = freopen(vault->filename, "wb+", vault->fd);
if(fwrite(in, tmpsize, 1, vault->fd) != 1) { if(fwrite(in, tmpsize, 1, vault->fd) != 1) {
fatal(ptx, "Failed to copy %s to %s (write) [keeping %s]\n", fatal(ptx, "Failed to copy %s to %s (write) [keeping %s]\n",
tmp->filename, vault->filename, tmp->filename); tmp->filename, vault->filename, tmp->filename);
ucfree(in, tmpsize); ucfree(in, tmpsize);
return 1; return 1;
} }
@@ -345,7 +345,7 @@ int pcpvault_copy(PCPCTX *ptx, vault_t *tmp, vault_t *vault) {
if(fflush(vault->fd) != 0) { if(fflush(vault->fd) != 0) {
fatal(ptx, "Failed to copy %s to %s (flush) [keeping %s]\n", fatal(ptx, "Failed to copy %s to %s (flush) [keeping %s]\n",
tmp->filename, vault->filename, tmp->filename); tmp->filename, vault->filename, tmp->filename);
return 1; return 1;
} }
@@ -372,7 +372,7 @@ int pcpvault_close(PCPCTX *ptx, vault_t *vault) {
if(vault != NULL) { if(vault != NULL) {
if(vault->fd) { if(vault->fd) {
if(vault->unsafed == 1) { if(vault->unsafed == 1) {
pcpvault_writeall(ptx, vault); pcpvault_writeall(ptx, vault);
} }
fclose(vault->fd); fclose(vault->fd);
} }
@@ -437,7 +437,7 @@ int pcpvault_fetchall(PCPCTX *ptx, vault_t *vault) {
got = fread(header, 1, sizeof(vault_header_t), vault->fd); got = fread(header, 1, sizeof(vault_header_t), vault->fd);
if(got < sizeof(vault_header_t)) { if(got < sizeof(vault_header_t)) {
fatal(ptx, "empty or invalid vault header size (got %ld, expected %ld)\n", fatal(ptx, "empty or invalid vault header size (got %ld, expected %ld)\n",
got, sizeof(vault_header_t)); got, sizeof(vault_header_t));
goto err; goto err;
} }
vh2native(header); vh2native(header);
@@ -456,59 +456,59 @@ int pcpvault_fetchall(PCPCTX *ptx, vault_t *vault) {
for(;;) { for(;;) {
readpos = ftell(vault->fd); readpos = ftell(vault->fd);
if(vault->size - readpos >= sizeof(vault_item_header_t)) { if(vault->size - readpos >= sizeof(vault_item_header_t)) {
/* an item header follows */ /* an item header follows */
got = fread(item, sizeof(vault_item_header_t), 1, vault->fd); got = fread(item, sizeof(vault_item_header_t), 1, vault->fd);
ih2native(item); ih2native(item);
if(item->size > 0) { if(item->size > 0) {
/* item is valid */ /* item is valid */
readpos = ftell(vault->fd); readpos = ftell(vault->fd);
bytesleft = vault->size - readpos; bytesleft = vault->size - readpos;
if(bytesleft >= ksize) { if(bytesleft >= ksize) {
/* a key follows */ /* a key follows */
if(item->type == PCP_KEY_TYPE_MAINSECRET || if(item->type == PCP_KEY_TYPE_MAINSECRET ||
item->type == PCP_KEY_TYPE_SECRET) { item->type == PCP_KEY_TYPE_SECRET) {
/* read a secret key */ /* read a secret key */
key = ucmalloc(sizeof(pcp_key_t)); key = ucmalloc(sizeof(pcp_key_t));
got = fread(key, PCP_RAW_KEYSIZE, 1, vault->fd); got = fread(key, PCP_RAW_KEYSIZE, 1, vault->fd);
key2native(key); key2native(key);
pcphash_add(ptx, (void *)key, item->type); pcphash_add(ptx, (void *)key, item->type);
} }
else if(item->type == PCP_KEY_TYPE_PUBLIC) { else if(item->type == PCP_KEY_TYPE_PUBLIC) {
/* read a public key */ /* read a public key */
pubkey = ucmalloc(sizeof(pcp_pubkey_t)); pubkey = ucmalloc(sizeof(pcp_pubkey_t));
got = fread(pubkey, PCP_RAW_PUBKEYSIZE, 1, vault->fd); got = fread(pubkey, PCP_RAW_PUBKEYSIZE, 1, vault->fd);
pubkey2native(pubkey); pubkey2native(pubkey);
pcphash_add(ptx, (void *)pubkey, item->type); pcphash_add(ptx, (void *)pubkey, item->type);
} }
else if(item->type == PCP_KEYSIG_NATIVE || item->type == PCP_KEYSIG_PBP) { else if(item->type == PCP_KEYSIG_NATIVE || item->type == PCP_KEYSIG_PBP) {
Buffer *rawks = buffer_new(256, "keysig"); Buffer *rawks = buffer_new(256, "keysig");
buffer_fd_read(rawks, vault->fd, item->size); buffer_fd_read(rawks, vault->fd, item->size);
pcp_keysig_t *s = pcp_keysig_new(rawks); pcp_keysig_t *s = pcp_keysig_new(rawks);
pcphash_add(ptx, (void *)s, item->type); pcphash_add(ptx, (void *)s, item->type);
buffer_free(rawks); buffer_free(rawks);
} }
else { else {
fatal(ptx, "Failed to read vault - invalid key type: %02X! at %d\n", fatal(ptx, "Failed to read vault - invalid key type: %02X! at %d\n",
item->type, readpos); item->type, readpos);
goto err; goto err;
} }
} }
else { else {
fatal(ptx, "Failed to read vault - that's no pcp key at %d (size %ld)!\n", fatal(ptx, "Failed to read vault - that's no pcp key at %d (size %ld)!\n",
readpos, bytesleft); readpos, bytesleft);
goto err; goto err;
} }
} }
else { else {
fatal(ptx, "Failed to read vault - invalid key item header size at %d!\n", fatal(ptx, "Failed to read vault - invalid key item header size at %d!\n",
readpos); readpos);
goto err; goto err;
} }
} }
else { else {
/* no more items */ /* no more items */
break; break;
} }
} }
} }

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2014 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -54,8 +54,8 @@ uint8_t is_utf8(const byte *bytes) {
) || ) ||
(// straight 3-byte (// straight 3-byte
((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
bytes[0] == 0xEE || bytes[0] == 0xEE ||
bytes[0] == 0xEF) && bytes[0] == 0xEF) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) (0x80 <= bytes[2] && bytes[2] <= 0xBF)
) || ) ||
@@ -107,25 +107,25 @@ size_t _buffer_is_binary(byte *buf, size_t len) {
/* check for utf8 */ /* check for utf8 */
wide[0] = buf[pos]; wide[0] = buf[pos];
for(i=1; i<3; i++) { for(i=1; i<3; i++) {
/* check for 2, 3 or 4 byte utf8 char */ /* check for 2, 3 or 4 byte utf8 char */
if(pos+i < len) { if(pos+i < len) {
/* only if there's enough space of course */ /* only if there's enough space of course */
wide[i] = buf[pos+i]; wide[i] = buf[pos+i];
if(is_utf8(wide) > 1) { if(is_utf8(wide) > 1) {
pos += i; /* jump over the utf we already found */ pos += i; /* jump over the utf we already found */
utf = 1; utf = 1;
break; break;
} }
} }
else else
break; break;
} }
memset(wide, 0, 4); memset(wide, 0, 4);
if(utf == 1) { if(utf == 1) {
/* it's a utf8 char, continue checking, reset wide */ /* it's a utf8 char, continue checking, reset wide */
utf = 0; utf = 0;
continue; continue;
} }
break; /* if we reach this, then it's binary and not utf8, stop checking */ break; /* if we reach this, then it's binary and not utf8, stop checking */
} }
@@ -256,12 +256,12 @@ char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen, int doblock) {
while(*z != '\0') { while(*z != '\0') {
if(pos >= 71) { if(pos >= 71) {
*B++ = '\r'; *B++ = '\r';
*B++ = '\n'; *B++ = '\n';
pos = 1; pos = 1;
} }
else { else {
pos++; pos++;
} }
*B++ = *z++; *B++ = *z++;
} }
@@ -331,27 +331,27 @@ char *pcp_readz85string(PCPCTX *ptx, unsigned char *input, size_t bufsize) {
else if(input[i] == '\n') { else if(input[i] == '\n') {
/* a line is complete */ /* a line is complete */
if(z85_isbegin(line) && begin == 0) { if(z85_isbegin(line) && begin == 0) {
/* a begin header, reset whatever we've got so far in z buffer */ /* a begin header, reset whatever we've got so far in z buffer */
begin = 1; begin = 1;
buffer_clear(line); buffer_clear(line);
buffer_clear(z); buffer_clear(z);
continue; continue;
} }
else if(z85_isend(line)){ else if(z85_isend(line)){
/* an end header */ /* an end header */
buffer_clear(line); buffer_clear(line);
end = 1; end = 1;
break; break;
} }
else if(z85_isempty(line) || z85_iscomment(line)) { else if(z85_isempty(line) || z85_iscomment(line)) {
/* a comment */ /* a comment */
buffer_clear(line); buffer_clear(line);
continue; continue;
} }
else { else {
/* regular z85 encoded content */ /* regular z85 encoded content */
buffer_add_buf(z, line); buffer_add_buf(z, line);
buffer_clear(line); buffer_clear(line);
} }
} }
else { else {
@@ -469,7 +469,7 @@ int z85_isbegin(Buffer *buf) {
blen = strlen(begin); blen = strlen(begin);
if(blen <= len) if(blen <= len)
if(_findoffset(line+buf->offset, len, (char *)begin, blen) >= 0) if(_findoffset(line+buf->offset, len, (char *)begin, blen) >= 0)
isb = i; /* i = ENUM ZBEGINS */ isb = i; /* i = ENUM ZBEGINS */
} }
free(line); free(line);

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -66,12 +66,12 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
char *passphrase; char *passphrase;
if(passwd == NULL) { if(passwd == NULL) {
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase for symetric decryption", NULL, 1, NULL); "Enter passphrase for symetric decryption", NULL, 1, NULL);
} }
else { else {
passphrase = smalloc(strlen(passwd)+1); passphrase = smalloc(strlen(passwd)+1);
memcpy(passphrase, passwd, strlen(passwd) + 1); memcpy(passphrase, passwd, strlen(passwd) + 1);
} }
symkey = pcp_scrypt(ptx, passphrase, strlen(passphrase), salt, 90); symkey = pcp_scrypt(ptx, passphrase, strlen(passphrase), salt, 90);
@@ -79,48 +79,48 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
free(salt); free(salt);
} }
else if(head == PCP_ASYM_CIPHER || head == PCP_ASYM_CIPHER_SIG else if(head == PCP_ASYM_CIPHER || head == PCP_ASYM_CIPHER_SIG
|| head == PCP_ASYM_CIPHER_ANON || head == PCP_ASYM_CIPHER_ANON_SIG) { || head == PCP_ASYM_CIPHER_ANON || head == PCP_ASYM_CIPHER_ANON_SIG) {
/* asymetric mode */ /* asymetric mode */
if(useid) { if(useid) {
secret = pcphash_keyexists(ptx, id); secret = pcphash_keyexists(ptx, id);
if(secret == NULL) { if(secret == NULL) {
fatal(ptx, "Could not find a secret key with id 0x%s in vault %s!\n", fatal(ptx, "Could not find a secret key with id 0x%s in vault %s!\n",
id, vault->filename); id, vault->filename);
goto errde3; goto errde3;
} }
} }
else { else {
secret = pcp_find_primary_secret(); secret = pcp_find_primary_secret();
if(secret == NULL) { if(secret == NULL) {
fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename); fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename);
goto errde3; goto errde3;
} }
} }
char *passphrase; char *passphrase;
if(passwd == NULL) { if(passwd == NULL) {
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to decrypt your secret key", NULL, 1, NULL); "Enter passphrase to decrypt your secret key", NULL, 1, NULL);
} }
else { else {
passphrase = smalloc(strlen(passwd)+1); passphrase = smalloc(strlen(passwd)+1);
memcpy(passphrase, passwd, strlen(passwd)+1); memcpy(passphrase, passwd, strlen(passwd)+1);
} }
secret = pcpkey_decrypt(ptx, secret, passphrase); secret = pcpkey_decrypt(ptx, secret, passphrase);
sfree(passphrase); sfree(passphrase);
if(secret == NULL) if(secret == NULL)
goto errde3; goto errde3;
if(head == PCP_ASYM_CIPHER_ANON) if(head == PCP_ASYM_CIPHER_ANON)
anon = 1; anon = 1;
if(head == PCP_ASYM_CIPHER_SIG) if(head == PCP_ASYM_CIPHER_SIG)
verify = 1; verify = 1;
if(head == PCP_ASYM_CIPHER_ANON_SIG) { if(head == PCP_ASYM_CIPHER_ANON_SIG) {
anon = 1; anon = 1;
verify = 1; verify = 1;
} }
} }
else { else {
@@ -164,7 +164,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
plist_t *recipient, int signcrypt, int armor, int anon) { plist_t *recipient, int signcrypt, int armor, int anon) {
FILE *in = NULL; FILE *in = NULL;
FILE *out = NULL; FILE *out = NULL;
pcp_pubkey_t *pubhash = NULL; /* FIXME: add free() */ pcp_pubkey_t *pubhash = NULL; /* FIXME: add free() */
@@ -201,15 +201,15 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
/* self-encryption: look if its a secret one */ /* self-encryption: look if its a secret one */
pcp_key_t *s = pcphash_keyexists(ptx, id); pcp_key_t *s = pcphash_keyexists(ptx, id);
if(s != NULL) { if(s != NULL) {
tmp = pcpkey_pub_from_secret(s); tmp = pcpkey_pub_from_secret(s);
pub = ucmalloc(sizeof(pcp_pubkey_t)); pub = ucmalloc(sizeof(pcp_pubkey_t));
memcpy(pub, tmp, sizeof(pcp_pubkey_t)); memcpy(pub, tmp, sizeof(pcp_pubkey_t));
HASH_ADD_STR( pubhash, id, pub); HASH_ADD_STR( pubhash, id, pub);
} }
else { else {
fatal(ptx, "Could not find a public key with id 0x%s in vault %s!\n", fatal(ptx, "Could not find a public key with id 0x%s in vault %s!\n",
id, vault->filename); id, vault->filename);
goto erren3; goto erren3;
} }
} }
else { else {
@@ -227,15 +227,15 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
pcphash_iteratepub(ptx, tmp) { pcphash_iteratepub(ptx, tmp) {
rec = recipient->first; rec = recipient->first;
while (rec != NULL) { while (rec != NULL) {
_lc(rec->value); _lc(rec->value);
if(strnstr(tmp->mail, rec->value, 255) != NULL if(strnstr(tmp->mail, rec->value, 255) != NULL
|| strnstr(tmp->owner, rec->value, 255) != NULL) { || strnstr(tmp->owner, rec->value, 255) != NULL) {
pub = ucmalloc(sizeof(pcp_pubkey_t)); pub = ucmalloc(sizeof(pcp_pubkey_t));
memcpy(pub, tmp, sizeof(pcp_pubkey_t)); memcpy(pub, tmp, sizeof(pcp_pubkey_t));
HASH_ADD_STR( pubhash, id, pub); HASH_ADD_STR( pubhash, id, pub);
/* fprintf(stderr, " => found a matching key %s\n", tmp->id); */ /* fprintf(stderr, " => found a matching key %s\n", tmp->id); */
} }
rec = rec->next; rec = rec->next;
} }
} }
@@ -243,10 +243,10 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
rec = recipient->first; rec = recipient->first;
while (rec != NULL) { while (rec != NULL) {
if(strnstr("__self__", rec->value, 13) != NULL) { if(strnstr("__self__", rec->value, 13) != NULL) {
pcp_key_t *s = pcp_find_primary_secret(); pcp_key_t *s = pcp_find_primary_secret();
pcp_pubkey_t *p = pcpkey_pub_from_secret(s); pcp_pubkey_t *p = pcpkey_pub_from_secret(s);
HASH_ADD_STR( pubhash, id, p); HASH_ADD_STR( pubhash, id, p);
break; break;
} }
rec = rec->next; rec = rec->next;
} }
@@ -264,22 +264,22 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
secret = pcp_find_primary_secret(); secret = pcp_find_primary_secret();
if(secret == NULL) { if(secret == NULL) {
fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename); fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename);
goto erren2; goto erren2;
} }
char *passphrase; char *passphrase;
if(passwd == NULL) { if(passwd == NULL) {
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to decrypt your secret key", NULL, 1, NULL); "Enter passphrase to decrypt your secret key", NULL, 1, NULL);
} }
else { else {
passphrase = smalloc(strlen(passwd)+1); passphrase = smalloc(strlen(passwd)+1);
memcpy(passphrase, passwd, strlen(passwd)+1); memcpy(passphrase, passwd, strlen(passwd)+1);
} }
secret = pcpkey_decrypt(ptx, secret, passphrase); secret = pcpkey_decrypt(ptx, secret, passphrase);
sfree(passphrase); sfree(passphrase);
if(secret == NULL) if(secret == NULL)
goto erren2; goto erren2;
signsecret = secret; signsecret = secret;
} }
@@ -341,7 +341,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
fprintf(stderr, "Encrypted %"FMT_SIZE_T" bytes for:\n", (SIZE_T_CAST)clen); fprintf(stderr, "Encrypted %"FMT_SIZE_T" bytes for:\n", (SIZE_T_CAST)clen);
pcp_pubkey_t *cur, *t; pcp_pubkey_t *cur, *t;
HASH_ITER(hh, pubhash, cur, t) { HASH_ITER(hh, pubhash, cur, t) {
fprintf(stderr, " 0x%s - %s <%s>\n", cur->id, cur->owner, cur->mail); fprintf(stderr, " 0x%s - %s <%s>\n", cur->id, cur->owner, cur->mail);
} }
} }
if(signcrypt) if(signcrypt)
@@ -381,8 +381,8 @@ void pcpchecksum(char **files, int filenum, char *key) {
} }
else { else {
if((in = fopen(files[i], "rb")) == NULL) { if((in = fopen(files[i], "rb")) == NULL) {
fatal(ptx, "Could not open input file %s\n", files[i]); fatal(ptx, "Could not open input file %s\n", files[i]);
break; break;
} }
} }
Pcpstream *pin = ps_new_file(in); Pcpstream *pin = ps_new_file(in);

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.v.Dein. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -78,8 +78,8 @@ void pcp_keygen(char *passwd) {
char *passphrase; char *passphrase;
if(passwd == NULL) { if(passwd == NULL) {
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase for key encryption", "Enter passphrase for key encryption",
"Enter the passphrase again", 1, NULL); "Enter the passphrase again", 1, NULL);
} }
else { else {
passphrase = passwd; passphrase = passwd;
@@ -91,7 +91,7 @@ void pcp_keygen(char *passwd) {
fprintf(stderr, "WARNING: you are using a weak passphrase (entropy: %lf)!\n", ent); fprintf(stderr, "WARNING: you are using a weak passphrase (entropy: %lf)!\n", ent);
char *yes = pcp_getstdin("Are you sure to use it [yes|NO]?"); char *yes = pcp_getstdin("Are you sure to use it [yes|NO]?");
if(strncmp(yes, "yes", 1024) != 0) { if(strncmp(yes, "yes", 1024) != 0) {
goto errkg1; goto errkg1;
} }
} }
key = pcpkey_encrypt(ptx, k, passphrase); key = pcpkey_encrypt(ptx, k, passphrase);
@@ -167,7 +167,7 @@ char *pcp_normalize_id(char *keyid) {
if(keyid[0] == '0' && keyid[1] == 'x' && len == 18) { if(keyid[0] == '0' && keyid[1] == 'x' && len == 18) {
int i; int i;
for(i=0; i<16; ++i) { for(i=0; i<16; ++i) {
id[i] = keyid[i+2]; id[i] = keyid[i+2];
} }
id[16] = 0; id[16] = 0;
} }
@@ -238,18 +238,18 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile, int armor, char *pa
if(passwd == NULL) { if(passwd == NULL) {
char *passphrase; char *passphrase;
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to decrypt your secret key", NULL, 1, NULL); "Enter passphrase to decrypt your secret key", NULL, 1, NULL);
key = pcpkey_decrypt(ptx, key, passphrase); key = pcpkey_decrypt(ptx, key, passphrase);
if(key == NULL) { if(key == NULL) {
sfree(passphrase); sfree(passphrase);
goto errexpse1; goto errexpse1;
} }
sfree(passphrase); sfree(passphrase);
} }
else { else {
key = pcpkey_decrypt(ptx, key, passwd); key = pcpkey_decrypt(ptx, key, passwd);
if(key == NULL) { if(key == NULL) {
goto errexpse1; goto errexpse1;
} }
} }
@@ -262,20 +262,20 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile, int armor, char *pa
char *passphrase; char *passphrase;
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to encrypt the exported secret key", "Enter passphrase to encrypt the exported secret key",
"Repeat passphrase", 1, NULL); "Repeat passphrase", 1, NULL);
exported_sk = pcp_export_secret(ptx, key, passphrase); exported_sk = pcp_export_secret(ptx, key, passphrase);
sfree(passphrase); sfree(passphrase);
} }
if(exported_sk != NULL) { if(exported_sk != NULL) {
if(armor == 1) { if(armor == 1) {
size_t zlen; size_t zlen;
char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen, 1); char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen, 1);
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_SK_HEADER, z85, EXP_SK_FOOTER); fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_SK_HEADER, z85, EXP_SK_FOOTER);
free(z85); free(z85);
} }
else { else {
fwrite(buffer_get(exported_sk), 1, buffer_size(exported_sk), out); fwrite(buffer_get(exported_sk), 1, buffer_size(exported_sk), out);
} }
buffer_free(exported_sk); buffer_free(exported_sk);
fprintf(stderr, "secret key exported.\n"); fprintf(stderr, "secret key exported.\n");
@@ -318,13 +318,13 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
/* ok, so, then look for a secret key with that id */ /* ok, so, then look for a secret key with that id */
sk = pcphash_keyexists(ptx, keyid); sk = pcphash_keyexists(ptx, keyid);
if(sk == NULL) { if(sk == NULL) {
fatal(ptx, "Could not find a key with id 0x%s in vault %s!\n", fatal(ptx, "Could not find a key with id 0x%s in vault %s!\n",
keyid, vault->filename); keyid, vault->filename);
goto errpcpexpu1; goto errpcpexpu1;
} }
else { else {
/* ok, so it's our own key */ /* ok, so it's our own key */
is_foreign = 0; is_foreign = 0;
} }
} }
else { else {
@@ -351,7 +351,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
else { else {
char *passphrase; char *passphrase;
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to decrypt your secret key", NULL, 1, NULL); "Enter passphrase to decrypt your secret key", NULL, 1, NULL);
sk = pcpkey_decrypt(ptx, sk, passphrase); sk = pcpkey_decrypt(ptx, sk, passphrase);
sfree(passphrase); sfree(passphrase);
} }
@@ -365,16 +365,16 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
if(is_foreign == 0) { if(is_foreign == 0) {
exported_pk = pcp_export_rfc_pub(ptx, sk); exported_pk = pcp_export_rfc_pub(ptx, sk);
if(exported_pk != NULL) { if(exported_pk != NULL) {
if(armor == 1) { if(armor == 1) {
size_t zlen; size_t zlen;
char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1); char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1);
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_PK_HEADER, z85, EXP_PK_FOOTER); fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_PK_HEADER, z85, EXP_PK_FOOTER);
free(z85); free(z85);
} }
else else
fwrite(buffer_get(exported_pk), 1, buffer_size(exported_pk), out); fwrite(buffer_get(exported_pk), 1, buffer_size(exported_pk), out);
buffer_free(exported_pk); buffer_free(exported_pk);
fprintf(stderr, "public key exported.\n"); fprintf(stderr, "public key exported.\n");
} }
} }
else { else {
@@ -387,13 +387,13 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
if(is_foreign == 0) { if(is_foreign == 0) {
exported_pk = pcp_export_pbp_pub(sk); exported_pk = pcp_export_pbp_pub(sk);
if(exported_pk != NULL) { if(exported_pk != NULL) {
/* PBP format requires armoring always */ /* PBP format requires armoring always */
size_t zlen; size_t zlen;
char *z85pbp = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1); char *z85pbp = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1);
fprintf(out, "%s", z85pbp); fprintf(out, "%s", z85pbp);
free(z85pbp); free(z85pbp);
buffer_free(exported_pk); buffer_free(exported_pk);
fprintf(stderr, "public key exported in PBP format.\n"); fprintf(stderr, "public key exported in PBP format.\n");
} }
} }
else { else {
@@ -446,63 +446,63 @@ void pcpedit_key(char *keyid) {
fprintf(stderr, "Current owner: %s\n", key->owner); fprintf(stderr, "Current owner: %s\n", key->owner);
char *owner = pcp_getstdin(" enter new name or press enter to keep current"); char *owner = pcp_getstdin(" enter new name or press enter to keep current");
if(strlen(owner) > 0) if(strlen(owner) > 0)
memcpy(key->owner, owner, strlen(owner) + 1); memcpy(key->owner, owner, strlen(owner) + 1);
fprintf(stderr, "Current mail: %s\n", key->mail); fprintf(stderr, "Current mail: %s\n", key->mail);
char *mail = pcp_getstdin(" enter new email or press enter to keep current"); char *mail = pcp_getstdin(" enter new email or press enter to keep current");
if(strlen(mail) > 0) if(strlen(mail) > 0)
memcpy(key->mail, mail, strlen(mail) + 1); memcpy(key->mail, mail, strlen(mail) + 1);
free(owner); free(owner);
free(mail); free(mail);
if(key->type != PCP_KEY_TYPE_MAINSECRET) { if(key->type != PCP_KEY_TYPE_MAINSECRET) {
pcp_key_t *other = NULL; pcp_key_t *other = NULL;
uint8_t haveprimary = 0; uint8_t haveprimary = 0;
pcphash_iterate(ptx, other) { pcphash_iterate(ptx, other) {
if(other->type == PCP_KEY_TYPE_MAINSECRET) { if(other->type == PCP_KEY_TYPE_MAINSECRET) {
haveprimary = 1; haveprimary = 1;
break; break;
} }
} }
char *yes = NULL; char *yes = NULL;
if(! haveprimary) { if(! haveprimary) {
fprintf(stderr, "There is currently no primary secret in your vault,\n"); fprintf(stderr, "There is currently no primary secret in your vault,\n");
yes = pcp_getstdin("want to make this one the primary [yes|NO]?"); yes = pcp_getstdin("want to make this one the primary [yes|NO]?");
} }
else { else {
fprintf(stderr, "The key %s is currently the primary secret,\n", other->id); fprintf(stderr, "The key %s is currently the primary secret,\n", other->id);
yes = pcp_getstdin("want to make this one the primary instead [yes|NO]?"); yes = pcp_getstdin("want to make this one the primary instead [yes|NO]?");
} }
if(strncmp(yes, "yes", 1024) == 0) { if(strncmp(yes, "yes", 1024) == 0) {
key->type = PCP_KEY_TYPE_MAINSECRET; key->type = PCP_KEY_TYPE_MAINSECRET;
if(haveprimary) { if(haveprimary) {
fprintf(stderr, "other type: %d\n", other->type); fprintf(stderr, "other type: %d\n", other->type);
other->type = PCP_KEY_TYPE_SECRET; other->type = PCP_KEY_TYPE_SECRET;
fprintf(stderr, " new type: %d\n", other->type); fprintf(stderr, " new type: %d\n", other->type);
} }
} }
free(yes); free(yes);
} }
char *passphrase; char *passphrase;
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter new passphrase for key encryption (press enter to keep current)", "Enter new passphrase for key encryption (press enter to keep current)",
"Enter the passphrase again", 1, NULL); "Enter the passphrase again", 1, NULL);
if(strnlen(passphrase, 1024) > 0) { if(strnlen(passphrase, 1024) > 0) {
key = pcpkey_encrypt(ptx, key, passphrase); key = pcpkey_encrypt(ptx, key, passphrase);
sfree(passphrase); sfree(passphrase);
} }
if(key != NULL) { if(key != NULL) {
if(debug) if(debug)
pcp_dumpkey(key); pcp_dumpkey(key);
vault->unsafed = 1; /* will be safed automatically */ vault->unsafed = 1; /* will be safed automatically */
fprintf(stderr, "Key %s changed.\n", key->id); fprintf(stderr, "Key %s changed.\n", key->id);
} }
} }
} }
@@ -564,26 +564,26 @@ int pcp_import (vault_t *vault, FILE *in, char *passwd) {
fatals_ifany(ptx); fatals_ifany(ptx);
char *yes = pcp_getstdin("WARNING: signature doesn't verify, import anyway [yes|NO]?"); char *yes = pcp_getstdin("WARNING: signature doesn't verify, import anyway [yes|NO]?");
if(strncmp(yes, "yes", 1024) != 0) { if(strncmp(yes, "yes", 1024) != 0) {
free(yes); free(yes);
goto errimp2; goto errimp2;
} }
free(yes); free(yes);
} }
if(pcp_sanitycheck_pub(ptx, pub) == 0) { if(pcp_sanitycheck_pub(ptx, pub) == 0) {
if(pcpvault_addkey(ptx, vault, (void *)pub, PCP_KEY_TYPE_PUBLIC) == 0) { if(pcpvault_addkey(ptx, vault, (void *)pub, PCP_KEY_TYPE_PUBLIC) == 0) {
fprintf(stderr, "key 0x%s added to %s.\n", pub->id, vault->filename); fprintf(stderr, "key 0x%s added to %s.\n", pub->id, vault->filename);
/* avoid double free */ /* avoid double free */
success = 0; success = 0;
} }
else else
goto errimp2; goto errimp2;
if(keysig != NULL) { if(keysig != NULL) {
if(pcpvault_addkey(ptx, vault, keysig, keysig->type) != 0) { if(pcpvault_addkey(ptx, vault, keysig, keysig->type) != 0) {
/* FIXME: remove pubkey if storing the keysig failed */ /* FIXME: remove pubkey if storing the keysig failed */
goto errimp2; goto errimp2;
} }
} }
} }
else else
@@ -599,7 +599,7 @@ int pcp_import (vault_t *vault, FILE *in, char *passwd) {
else { else {
char *passphrase; char *passphrase;
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to decrypt the secret key file", NULL, 1, NULL); "Enter passphrase to decrypt the secret key file", NULL, 1, NULL);
sk = pcp_import_secret(ptx, buf, bufsize, passphrase); sk = pcp_import_secret(ptx, buf, bufsize, passphrase);
sfree(passphrase); sfree(passphrase);
} }
@@ -624,33 +624,33 @@ int pcp_import (vault_t *vault, FILE *in, char *passwd) {
else { else {
char *passphrase; char *passphrase;
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase for key encryption", "Enter passphrase for key encryption",
"Enter the passphrase again", 1, NULL); "Enter the passphrase again", 1, NULL);
if(strnlen(passphrase, 1024) > 0) { if(strnlen(passphrase, 1024) > 0) {
/* encrypt the key */ /* encrypt the key */
sk = pcpkey_encrypt(ptx, sk, passphrase); sk = pcpkey_encrypt(ptx, sk, passphrase);
sfree(passphrase); sfree(passphrase);
} }
else { else {
/* ask for confirmation if we shall store it in the clear */ /* ask for confirmation if we shall store it in the clear */
char *yes = pcp_getstdin( char *yes = pcp_getstdin(
"WARNING: secret key will be stored unencrypted. Are you sure [yes|NO]?"); "WARNING: secret key will be stored unencrypted. Are you sure [yes|NO]?");
if(strncmp(yes, "yes", 1024) != 0) { if(strncmp(yes, "yes", 1024) != 0) {
free(yes); free(yes);
goto errimp1; goto errimp1;
} }
free(yes); free(yes);
} }
} }
if(sk != NULL) { if(sk != NULL) {
/* store it to the vault if we got it til here */ /* store it to the vault if we got it til here */
if(pcp_sanitycheck_key(ptx, sk) == 0) { if(pcp_sanitycheck_key(ptx, sk) == 0) {
if(pcp_storekey(sk) == 0) { if(pcp_storekey(sk) == 0) {
pcpkey_printshortinfo(sk); pcpkey_printshortinfo(sk);
success = 0; success = 0;
} }
} }
} }
} }

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden. Copyright (C) 2013-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -92,13 +92,13 @@ void pcptext_key(char *keyid) {
pcp_pubkey_t *p = pcphash_pubkeyexists(ptx, keyid); pcp_pubkey_t *p = pcphash_pubkeyexists(ptx, keyid);
if(p != NULL) { if(p != NULL) {
if(debug) { if(debug) {
pcp_dumppubkey(p); pcp_dumppubkey(p);
pcp_keysig_t *s = pcphash_keysigexists(ptx, keyid); pcp_keysig_t *s = pcphash_keysigexists(ptx, keyid);
if(s != NULL) { if(s != NULL) {
printf("\n"); printf("\n");
pcp_dumpkeysig(s); pcp_dumpkeysig(s);
} }
printf("\n"); printf("\n");
} }
pcppubkey_print(p, stdout); pcppubkey_print(p, stdout);
} }
@@ -119,11 +119,11 @@ void pcptext_vault(vault_t *vault) {
checksum = _bin2hex(vault->checksum, LSHA); checksum = _bin2hex(vault->checksum, LSHA);
jout = json_pack("{sssisssisi}", jout = json_pack("{sssisssisi}",
"keyvaultfile", vault->filename, "keyvaultfile" , vault->filename,
"version", vault->version, "version" , vault->version,
"checksum", checksum, "checksum" , checksum,
"secretkeys", pcphash_count(ptx), "secretkeys" , pcphash_count(ptx),
"publickey", pcphash_countpub(ptx)); "publickey" , pcphash_countpub(ptx));
jkeys = json_array(); jkeys = json_array();
@@ -174,11 +174,11 @@ void pcpkey_printlineinfo(pcp_key_t *key) {
time_t t = (time_t)key->ctime; time_t t = (time_t)key->ctime;
c = localtime(&t); c = localtime(&t);
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n", printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
key->id, key->id,
(key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary secret" : "secret ", (key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary secret" : "secret ",
c->tm_year+1900, c->tm_mon+1, c->tm_mday, c->tm_year+1900, c->tm_mon+1, c->tm_mday,
c->tm_hour, c->tm_min, c->tm_sec, c->tm_hour, c->tm_min, c->tm_sec,
key->owner, key->mail); key->owner, key->mail);
if(ptx->verbose) { if(ptx->verbose) {
printf(" "); printf(" ");
@@ -186,14 +186,14 @@ void pcpkey_printlineinfo(pcp_key_t *key) {
int i, y; int i, y;
for(i=0; i<LSHA; i+=4) { for(i=0; i<LSHA; i+=4) {
for(y=0; y<4; y++) { for(y=0; y<4; y++) {
printf("%02x", hash[i+y]); printf("%02x", hash[i+y]);
} }
printf(" "); printf(" ");
} }
free(hash); free(hash);
printf("\n encrypted: %s, serial: %08x, version: %d\n", printf("\n encrypted: %s, serial: %08x, version: %d\n",
(key->secret[0] == '\0') ? "yes" : " no", (key->secret[0] == '\0') ? "yes" : " no",
key->serial, (int)key->version); key->serial, (int)key->version);
printf("\n"); printf("\n");
} }
} }
@@ -203,11 +203,11 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
time_t t = (time_t)key->ctime; time_t t = (time_t)key->ctime;
c = localtime(&t); c = localtime(&t);
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n", printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
key->id, key->id,
(key->valid == 1) ? "valid public " : "public ", (key->valid == 1) ? "valid public " : "public ",
c->tm_year+1900, c->tm_mon+1, c->tm_mday, c->tm_year+1900, c->tm_mon+1, c->tm_mday,
c->tm_hour, c->tm_min, c->tm_sec, c->tm_hour, c->tm_min, c->tm_sec,
key->owner, key->mail); key->owner, key->mail);
if(ptx->verbose) { if(ptx->verbose) {
printf(" "); printf(" ");
@@ -215,23 +215,23 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
int i, y; int i, y;
for(i=0; i<LSHA; i+=4) { for(i=0; i<LSHA; i+=4) {
for(y=0; y<4; y++) { for(y=0; y<4; y++) {
printf("%02x", hash[i+y]); printf("%02x", hash[i+y]);
} }
printf(" "); printf(" ");
} }
free(hash); free(hash);
printf("\n signed: %s, serial: %08x, version: %d, ", printf("\n signed: %s, serial: %08x, version: %d, ",
(key->valid == 1) ? "yes" : " no", (key->valid == 1) ? "yes" : " no",
key->serial, (int)key->version); key->serial, (int)key->version);
pcp_keysig_t *sig = pcphash_keysigexists(ptx, key->id); pcp_keysig_t *sig = pcphash_keysigexists(ptx, key->id);
if(sig != NULL) { if(sig != NULL) {
printf("signature fingerprint:\n "); printf("signature fingerprint:\n ");
byte *checksum = sig->checksum; byte *checksum = sig->checksum;
for(i=0; i<LSHA; i+=4) { for(i=0; i<LSHA; i+=4) {
for(y=0; y<4; y++) { for(y=0; y<4; y++) {
printf("%02x", checksum[i+y]); printf("%02x", checksum[i+y]);
} }
printf(" "); printf(" ");
} }
printf("\n"); printf("\n");
} }
@@ -278,8 +278,8 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
/* 2004-06-14T23:34:30. */ /* 2004-06-14T23:34:30. */
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n", fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
c->tm_year+1900, c->tm_mon+1, c->tm_mday, c->tm_year+1900, c->tm_mon+1, c->tm_mday,
c->tm_hour, c->tm_min, c->tm_sec); c->tm_hour, c->tm_min, c->tm_sec);
byte *hash = pcppubkey_getchecksum(key); byte *hash = pcppubkey_getchecksum(key);
fprintf(out, " Checksum: "); fprintf(out, " Checksum: ");
@@ -298,10 +298,10 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
size_t rlen = strlen(r); size_t rlen = strlen(r);
for (i=0; i<rlen; ++i) { for (i=0; i<rlen; ++i) {
if(r[i] == '\n') { if(r[i] == '\n') {
fprintf(out, "\n "); fprintf(out, "\n ");
} }
else { else {
fprintf(out, "%c", r[i]); fprintf(out, "%c", r[i]);
} }
} }
fprintf(out, "\n"); fprintf(out, "\n");
@@ -349,8 +349,8 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
/* 2004-06-14T23:34:30. */ /* 2004-06-14T23:34:30. */
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n", fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
c->tm_year+1900, c->tm_mon+1, c->tm_mday, c->tm_year+1900, c->tm_mon+1, c->tm_mday,
c->tm_hour, c->tm_min, c->tm_sec); c->tm_hour, c->tm_min, c->tm_sec);
fprintf(out, " Serial Number: 0x%08X\n", key->serial); fprintf(out, " Serial Number: 0x%08X\n", key->serial);
fprintf(out, " Key Version: 0x%08X\n", key->version); fprintf(out, " Key Version: 0x%08X\n", key->version);
@@ -359,10 +359,10 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
size_t rlen = strlen(r); size_t rlen = strlen(r);
for (i=0; i<rlen; ++i) { for (i=0; i<rlen; ++i) {
if(r[i] == '\n') { if(r[i] == '\n') {
fprintf(out, "\n "); fprintf(out, "\n ");
} }
else { else {
fprintf(out, "%c", r[i]); fprintf(out, "%c", r[i]);
} }
} }
fprintf(out, "\n"); fprintf(out, "\n");

515
src/pcp.c
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.Linden. Copyright (C) 2013-2016 T.Linden.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ void usage(int error) {
void version() { void version() {
fprintf(stderr, "pcp version %d.%d.%d, use --help to learn how to use.\n", fprintf(stderr, "pcp version %d.%d.%d, use --help to learn how to use.\n",
PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
exit(0); exit(0);
} }
@@ -139,163 +139,162 @@ int main (int argc, char **argv) {
}; };
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcmf:b1F:0KAMX:jC", while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcmf:b1F:0KAMX:jC",
longopts, NULL)) != -1) { longopts, NULL)) != -1) {
switch (opt) { switch (opt) {
case 0: case 0:
switch(lo) { switch(lo) {
case 's': case 's':
printf("sign\n"); printf("sign\n");
break; break;
} }
break; break;
case 'k': case 'k':
mode += PCP_MODE_KEYGEN; mode += PCP_MODE_KEYGEN;
usevault = 1; usevault = 1;
break; break;
case 'L': case 'L':
ptx->verbose = 1; /* no break by purpose, turn on -l */ ptx->verbose = 1; /* no break by purpose, turn on -l */
case 'l': case 'l':
mode += PCP_MODE_LISTKEYS; mode += PCP_MODE_LISTKEYS;
usevault = 1; usevault = 1;
break; break;
case 's': case 's':
mode += PCP_MODE_EXPORT_SECRET; mode += PCP_MODE_EXPORT_SECRET;
usevault = 1; usevault = 1;
break; break;
case 'p': case 'p':
mode += PCP_MODE_EXPORT_PUBLIC; mode += PCP_MODE_EXPORT_PUBLIC;
usevault = 1; usevault = 1;
break; break;
case 'K': case 'K':
mode += PCP_MODE_IMPORT; mode += PCP_MODE_IMPORT;
usevault = 1; usevault = 1;
break; break;
case 'R': case 'R':
mode += PCP_MODE_DELETE_KEY; mode += PCP_MODE_DELETE_KEY;
usevault = 1; usevault = 1;
break; break;
case 't': case 't':
mode += PCP_MODE_TEXT; mode += PCP_MODE_TEXT;
usevault = 0; usevault = 0;
break; break;
case 'E': case 'E':
mode += PCP_MODE_EDIT; mode += PCP_MODE_EDIT;
usevault = 1; usevault = 1;
break; break;
case 'e': case 'e':
mode += PCP_MODE_ENCRYPT; mode += PCP_MODE_ENCRYPT;
usevault = 1; usevault = 1;
break; break;
case 'm': case 'm':
mode += PCP_MODE_ENCRYPT_ME; mode += PCP_MODE_ENCRYPT_ME;
break; break;
case 'd': case 'd':
mode += PCP_MODE_DECRYPT; mode += PCP_MODE_DECRYPT;
usevault = 1; usevault = 1;
break; break;
case 'z': case 'z':
case 'a': case 'a':
armor = 1; armor = 1;
break; break;
case 'Z': case 'Z':
armor = 2; armor = 2;
break; break;
case 'A': case 'A':
anon = 1; anon = 1;
break; break;
case 'F': case 'F':
if(strncmp(optarg, "pbp", 3) == 0) { if(strncmp(optarg, "pbp", 3) == 0) {
exportformat = EXP_FORMAT_PBP; exportformat = EXP_FORMAT_PBP;
} }
else if(strncmp(optarg, "pcp", 3) == 0) { else if(strncmp(optarg, "pcp", 3) == 0) {
exportformat = EXP_FORMAT_NATIVE; exportformat = EXP_FORMAT_NATIVE;
} }
else { else {
fprintf(stderr, "WARN: Unknown export format specified, using native\n"); fprintf(stderr, "WARN: Unknown export format specified, using native\n");
exportformat = EXP_FORMAT_NATIVE; exportformat = EXP_FORMAT_NATIVE;
} }
break; break;
case 'j': case 'j':
#ifdef HAVE_JSON #ifdef HAVE_JSON
ptx->json = 1; ptx->json = 1;
#else #else
fprintf(stderr, "WARN: -j set, but no JSON support compiled in. Recompile with --with-json\n"); fprintf(stderr, "WARN: -j set, but no JSON support compiled in. Recompile with --with-json\n");
#endif #endif
break; break;
case 'g': case 'g':
mode += PCP_MODE_SIGN; mode += PCP_MODE_SIGN;
usevault = 1; usevault = 1;
break; break;
case 'c': case 'c':
mode += PCP_MODE_VERIFY; mode += PCP_MODE_VERIFY;
usevault = 1; usevault = 1;
break; break;
case 'C': case 'C':
mode += PCP_MODE_CHECKSUM; mode += PCP_MODE_CHECKSUM;
break; break;
case 'f': case 'f':
sigfile = ucmalloc(strlen(optarg)+1); sigfile = ucmalloc(strlen(optarg)+1);
strncpy(sigfile, optarg, strlen(optarg)+1); strncpy(sigfile, optarg, strlen(optarg)+1);
detach = 1; detach = 1;
break; break;
case 'V': case 'V':
strncpy(vaultfile, optarg, 1024); strncpy(vaultfile, optarg, 1024);
break; break;
case 'O': case 'O':
if(strncmp(optarg, "-", 2) > 0) { if(strncmp(optarg, "-", 2) > 0) {
outfile = ucmalloc(strlen(optarg)+1); outfile = ucmalloc(strlen(optarg)+1);
strncpy(outfile, optarg, strlen(optarg)+1); strncpy(outfile, optarg, strlen(optarg)+1);
} }
break; break;
case 'I': case 'I':
if(strncmp(optarg, "-", 2) > 0) { if(strncmp(optarg, "-", 2) > 0) {
infile = ucmalloc(strlen(optarg)+1); infile = ucmalloc(strlen(optarg)+1);
strncpy(infile, optarg, strlen(optarg)+1); strncpy(infile, optarg, strlen(optarg)+1);
} }
break; break;
case 'X': case 'X':
xpassfile = ucmalloc(strlen(optarg)+1); xpassfile = ucmalloc(strlen(optarg)+1);
strncpy(xpassfile, optarg, strlen(optarg)+1); strncpy(xpassfile, optarg, strlen(optarg)+1);
xpf = 1; xpf = 1;
break; break;
case 'i': case 'i':
keyid = ucmalloc(19); keyid = ucmalloc(19);
strncpy(keyid, optarg, 19); strncpy(keyid, optarg, 19);
useid = 1; useid = 1;
break; break;
case 'x': case 'x':
xpass = smalloc(strlen(optarg)+1); xpass = smalloc(strlen(optarg)+1);
strncpy(xpass, optarg, strlen(optarg)+1); strncpy(xpass, optarg, strlen(optarg)+1);
break; break;
case LONG_EXTPASS: case LONG_EXTPASS:
askpass = malloc(strlen(optarg)+1); askpass = malloc(strlen(optarg)+1);
strncpy(askpass, optarg, strlen(optarg)+1); strncpy(askpass, optarg, strlen(optarg)+1);
break; break;
case 'r': case 'r':
p_add(&recipient, optarg); p_add(&recipient, optarg);
userec = 1; userec = 1;
break; break;
case 'M': case 'M':
p_add_me(&recipient); p_add_me(&recipient);
userec = 1; userec = 1;
break; break;
case 'D': case 'D':
debug = 1; debug = 1;
break; break;
case '0': case '0':
version(); version();
case 'v': case 'v':
ptx->verbose = 1; ptx->verbose = 1;
break; break;
case 'h': case 'h':
usage(0); usage(0);
default: default:
usage(1); usage(1);
} }
} }
@@ -350,65 +349,65 @@ int main (int argc, char **argv) {
switch (mode) { switch (mode) {
case PCP_MODE_DECRYPT: case PCP_MODE_DECRYPT:
if(infile == NULL) { if(infile == NULL) {
infile = extra; infile = extra;
useex = 1; useex = 1;
} }
break; break;
case PCP_MODE_ENCRYPT: case PCP_MODE_ENCRYPT:
if(infile == NULL) { if(infile == NULL) {
infile = extra; infile = extra;
useex = 1; useex = 1;
} }
else if(userec == 0 && useid == 0) { else if(userec == 0 && useid == 0) {
userec = 1; userec = 1;
int i; int i;
for (i=0; i<argc; i++) { for (i=0; i<argc; i++) {
p_add(&recipient, argv[i]); p_add(&recipient, argv[i]);
} }
} }
break; break;
case PCP_MODE_IMPORT: case PCP_MODE_IMPORT:
if(infile == NULL) { if(infile == NULL) {
infile = extra; infile = extra;
useex = 1; useex = 1;
} }
break; break;
case PCP_MODE_EXPORT_SECRET: case PCP_MODE_EXPORT_SECRET:
case PCP_MODE_EXPORT_PUBLIC: case PCP_MODE_EXPORT_PUBLIC:
if(outfile == NULL) { if(outfile == NULL) {
outfile = extra; outfile = extra;
useex = 1; useex = 1;
} }
else if(useid == 0 && userec == 0) { else if(useid == 0 && userec == 0) {
p_add(&recipient, extra); p_add(&recipient, extra);
useex = 1; useex = 1;
userec = 1; userec = 1;
} }
break; break;
case PCP_MODE_VERIFY: case PCP_MODE_VERIFY:
if(infile == NULL) { if(infile == NULL) {
infile = extra; infile = extra;
useex = 1; useex = 1;
} }
else if (useid == 0) { else if (useid == 0) {
id = extra; id = extra;
useid = 1; useid = 1;
useex = 1; useex = 1;
} }
break; break;
case PCP_MODE_SIGN: case PCP_MODE_SIGN:
if(infile == NULL) { if(infile == NULL) {
infile = extra; infile = extra;
useex = 1; useex = 1;
} }
else if(outfile == NULL && detach == 0) { else if(outfile == NULL && detach == 0) {
outfile = extra; outfile = extra;
useex = 1; useex = 1;
} }
break; break;
} }
@@ -457,128 +456,128 @@ int main (int argc, char **argv) {
if(vault != NULL) { if(vault != NULL) {
switch (mode) { switch (mode) {
case PCP_MODE_KEYGEN: case PCP_MODE_KEYGEN:
pcp_keygen(xpass); pcp_keygen(xpass);
break; break;
case PCP_MODE_LISTKEYS: case PCP_MODE_LISTKEYS:
pcp_listkeys(); pcp_listkeys();
break; break;
case PCP_MODE_EXPORT_SECRET: case PCP_MODE_EXPORT_SECRET:
if(useid) { if(useid) {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id != NULL) { if(id != NULL) {
pcp_exportsecret(id, useid, outfile, armor, xpass); pcp_exportsecret(id, useid, outfile, armor, xpass);
} }
} }
else { else {
pcp_exportsecret(NULL, useid, outfile, armor, xpass); pcp_exportsecret(NULL, useid, outfile, armor, xpass);
} }
break; break;
case PCP_MODE_EXPORT_PUBLIC: case PCP_MODE_EXPORT_PUBLIC:
if(useid) { if(useid) {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id == NULL) if(id == NULL)
break; break;
} }
pcp_exportpublic(id, xpass, outfile, exportformat, armor); pcp_exportpublic(id, xpass, outfile, exportformat, armor);
break; break;
case PCP_MODE_IMPORT: case PCP_MODE_IMPORT:
if(infile == NULL) { if(infile == NULL) {
altin(NULL, xpf); altin(NULL, xpf);
in = stdin; in = stdin;
} }
else { else {
if((in = fopen(infile, "rb")) == NULL) { if((in = fopen(infile, "rb")) == NULL) {
fatal(ptx, "Could not open input file %s\n", infile); fatal(ptx, "Could not open input file %s\n", infile);
break; break;
} }
} }
pcp_import(vault, in, xpass); pcp_import(vault, in, xpass);
break; break;
case PCP_MODE_DELETE_KEY: case PCP_MODE_DELETE_KEY:
if(useid) { if(useid) {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id != NULL) { if(id != NULL) {
pcpdelete_key(id); pcpdelete_key(id);
} }
} }
else { else {
fatal(ptx, "You need to specify a key id (--keyid)!\n"); fatal(ptx, "You need to specify a key id (--keyid)!\n");
} }
break; break;
case PCP_MODE_EDIT: case PCP_MODE_EDIT:
if(useid) { if(useid) {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id != NULL) { if(id != NULL) {
pcpedit_key(id); pcpedit_key(id);
} }
} }
else { else {
fatal(ptx, "You need to specify a key id (--keyid)!\n"); fatal(ptx, "You need to specify a key id (--keyid)!\n");
} }
break; break;
case PCP_MODE_ENCRYPT: case PCP_MODE_ENCRYPT:
if(useid == 1 && userec == 0) { if(useid == 1 && userec == 0) {
/* one dst, FIXME: make id a list as well */ /* one dst, FIXME: make id a list as well */
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
pcpencrypt(id, altin(infile, xpf), outfile, xpass, NULL, signcrypt, armor, anon); pcpencrypt(id, altin(infile, xpf), outfile, xpass, NULL, signcrypt, armor, anon);
} }
else if(useid == 0 && userec == 1) { else if(useid == 0 && userec == 1) {
/* multiple dst */ /* multiple dst */
pcpencrypt(NULL, altin(infile, xpf), outfile, xpass, recipient, signcrypt, armor, anon); pcpencrypt(NULL, altin(infile, xpf), outfile, xpass, recipient, signcrypt, armor, anon);
} }
else { else {
/* -i and -r specified */ /* -i and -r specified */
fatal(ptx, "You can't specify both -i and -r, use either -i or -r!\n"); fatal(ptx, "You can't specify both -i and -r, use either -i or -r!\n");
} }
break; break;
case PCP_MODE_DECRYPT: case PCP_MODE_DECRYPT:
if(useid) { if(useid) {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id != NULL) { if(id != NULL) {
pcpdecrypt(id, useid, altin(infile, xpf), outfile, xpass, signcrypt); pcpdecrypt(id, useid, altin(infile, xpf), outfile, xpass, signcrypt);
} }
} }
else { else {
pcpdecrypt(NULL, useid, altin(infile, xpf), outfile, xpass, signcrypt); pcpdecrypt(NULL, useid, altin(infile, xpf), outfile, xpass, signcrypt);
} }
break; break;
case PCP_MODE_SIGN: case PCP_MODE_SIGN:
if(detach) { if(detach) {
if(outfile != NULL && sigfile != NULL) if(outfile != NULL && sigfile != NULL)
fatal(ptx, "You can't both specify -O and -f, use -O for std signatures and -f for detached ones\n"); fatal(ptx, "You can't both specify -O and -f, use -O for std signatures and -f for detached ones\n");
else else
pcpsign(altin(infile, xpf), sigfile, xpass, armor, detach); pcpsign(altin(infile, xpf), sigfile, xpass, armor, detach);
} }
else else
pcpsign(altin(infile, xpf), outfile, xpass, armor, detach); pcpsign(altin(infile, xpf), outfile, xpass, armor, detach);
break; break;
case PCP_MODE_VERIFY: case PCP_MODE_VERIFY:
if(useid) { if(useid) {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id != NULL) { if(id != NULL) {
pcpverify(altin(infile, xpf), sigfile, id, detach); pcpverify(altin(infile, xpf), sigfile, id, detach);
} }
} }
else { else {
pcpverify(altin(infile, xpf), sigfile, NULL, detach); pcpverify(altin(infile, xpf), sigfile, NULL, detach);
} }
break; break;
default: default:
/* */ /* */
goto ELSEMODE; goto ELSEMODE;
break; break;
} }
pcpvault_close(ptx, vault); pcpvault_close(ptx, vault);
} }
@@ -600,37 +599,37 @@ int main (int argc, char **argv) {
case PCP_MODE_TEXT: case PCP_MODE_TEXT:
if(infile != NULL) { if(infile != NULL) {
pcptext_infile(infile); pcptext_infile(infile);
} }
else { else {
vault = pcpvault_init(ptx, vaultfile); vault = pcpvault_init(ptx, vaultfile);
if(! useid && infile == NULL) { if(! useid && infile == NULL) {
pcptext_vault(vault); pcptext_vault(vault);
} }
else { else {
id = pcp_normalize_id(keyid); id = pcp_normalize_id(keyid);
if(id != NULL) { if(id != NULL) {
pcptext_key(id); pcptext_key(id);
} }
} }
pcpvault_close(ptx, vault); pcpvault_close(ptx, vault);
} }
break; break;
case PCP_MODE_CHECKSUM: case PCP_MODE_CHECKSUM:
if(infile == NULL) { if(infile == NULL) {
if(argc == 0) { if(argc == 0) {
char *list[1]; char *list[1];
list[0] = NULL; list[0] = NULL;
pcpchecksum(list, 1, xpass); pcpchecksum(list, 1, xpass);
} }
else { else {
pcpchecksum(argv, argc, xpass); pcpchecksum(argv, argc, xpass);
} }
} }
else { else {
char *list[1]; char *list[1];
list[0] = infile; list[0] = infile;
pcpchecksum(list, 1, xpass); pcpchecksum(list, 1, xpass);
} }
break; break;

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of Pretty Curved Privacy (pcp1). This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013-2015 T.Linden. Copyright (C) 2013-2016 T.Linden.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -57,7 +57,7 @@ int pcpsign(char *infile, char *outfile, char *passwd, int z85, int detach) {
char *passphrase; char *passphrase;
if(passwd == NULL) { if(passwd == NULL) {
pcp_readpass(ptx, &passphrase, pcp_readpass(ptx, &passphrase,
"Enter passphrase to decrypt your secret key", NULL, 1, NULL); "Enter passphrase to decrypt your secret key", NULL, 1, NULL);
} }
else { else {
passphrase = smalloc(strlen(passwd)+1); passphrase = smalloc(strlen(passwd)+1);

View File

@@ -65,10 +65,10 @@ void test0() {
DECRYPTED = _openrd("testcppdecrypted", CA); DECRYPTED = _openrd("testcppdecrypted", CA);
char *got = (char *)ucmalloc(10); char *got = (char *)ucmalloc(10);
if(fread(got, 1, 6, DECRYPTED) < 6) { if(fread(got, 1, 6, DECRYPTED) < 6) {
throw pcp::exception(CA, "read error, could not read decrypted content"); throw pcp::exception(CA, "read error, could not read decrypted content");
} }
if(strncmp(got, "HALLO", 5) != 0) { if(strncmp(got, "HALLO", 5) != 0) {
throw pcp::exception(CA); throw pcp::exception(CA);
} }
free(got); free(got);
} }

View File

@@ -118,22 +118,22 @@ int main(int argc, char **argv) {
back = pcp_z85_decode(ptx, raw, &zlen); back = pcp_z85_decode(ptx, raw, &zlen);
if(back == NULL) { if(back == NULL) {
if(mode > 3) { if(mode > 3) {
/* expected fail */ /* expected fail */
ret = TRUE; ret = TRUE;
} }
else { else {
/* expected ok */ /* expected ok */
ret = FALSE; ret = FALSE;
} }
} }
else { else {
if(mode > 3) { if(mode > 3) {
/* expected fail */ /* expected fail */
ret = FALSE; ret = FALSE;
} }
else { else {
/* expected ok */ /* expected ok */
ret = TRUE; ret = TRUE;
} }
} }
} }
@@ -143,7 +143,7 @@ int main(int argc, char **argv) {
if(mode <= 3 && memcmp(back, clear, 256) != 0) { if(mode <= 3 && memcmp(back, clear, 256) != 0) {
ret = FALSE; ret = FALSE;
if(ptx->pcp_errset == 0) { if(ptx->pcp_errset == 0) {
fatal(ptx, "decoded content doesn't match\n"); fatal(ptx, "decoded content doesn't match\n");
} }
} }
} }