diff --git a/include/pcp.h b/include/pcp.h index fb0d6c6..8b16eae 100644 --- a/include/pcp.h +++ b/include/pcp.h @@ -8,7 +8,6 @@ extern "C" { #include "pcp/config.h" #include "pcp/base85.h" #include "pcp/buffer.h" -#include "pcp/config.h" #include "pcp/crypto.h" #include "pcp/defines.h" #include "pcp/digital_crc32.h" diff --git a/include/pcp/z85.h b/include/pcp/z85.h index de3d3b8..3dba20f 100644 --- a/include/pcp/z85.h +++ b/include/pcp/z85.h @@ -163,7 +163,7 @@ int z85_isend(Buffer *buf); int z85_isbegin(Buffer *buf); int z85_iscomment(Buffer *buf); int z85_isempty(Buffer *line); - +int z85_isencoded(Buffer *line); #endif /* _HAVE_PCP_Z85_H */ diff --git a/libpcp/ed.c b/libpcp/ed.c index 7654e04..9d744a2 100644 --- a/libpcp/ed.c +++ b/libpcp/ed.c @@ -105,7 +105,7 @@ size_t pcp_ed_sign_buffered(Pcpstream *in, Pcpstream* out, pcp_key_t *s, int z85 size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; if(z85) { - ps_print(out, "\r\n%s\r\n~ Version: PCP v%d.%d.%d ~\r\n\r\n", PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); + ps_print(out, "\r\n%s\r\nVersion: PCP v%d.%d.%d \r\n\r\n", PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); size_t zlen; char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen); ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END); @@ -258,6 +258,8 @@ pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { if(z85block == NULL) goto errvb1; + //fprintf(stderr, "ZBLOCK: <%s>\n", z85block); + size_t dstlen; byte *z85decoded = pcp_z85_decode(z85block, &dstlen); if(dstlen != mlen) { @@ -316,12 +318,14 @@ size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s) { crypto_generichash_update(st, in_buf, cur_bufsize); } + /* FIXME: error checking! */ + crypto_generichash_final(st, hash, crypto_generichash_BYTES_MAX); byte *signature = pcp_ed_sign(hash, crypto_generichash_BYTES_MAX, s); size_t mlen = + crypto_sign_BYTES + crypto_generichash_BYTES_MAX; - ps_print(out, "\r\n%s\r\n~ Version: PCP v%d.%d.%d ~\r\n\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); size_t zlen; char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen); diff --git a/libpcp/z85.c b/libpcp/z85.c index 52474dc..df9a67e 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -301,6 +301,7 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) { } else if(z85_isend(line)){ /* an end header */ + buffer_clear(line); end = 1; break; } @@ -321,7 +322,7 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) { } } - if(buffer_size(line) > 0 && end != 1) { + if(buffer_size(line) > 0 && end != 1 && z85_isencoded(line)) { /* something left in line buffer, probably newline at eof missing or no multiline input */ buffer_add_buf(z, line); @@ -347,7 +348,17 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) { return NULL; } - +int z85_isencoded(Buffer *line) { + /* we don't look for begin header here, do it separately! */ + if(!z85_isend(line) && + !z85_isempty(line) && + !z85_iscomment(line)) { + return 1; /* z85 encoded */ + } + else { + return 0; + } +} int z85_isheader(Buffer *buf) { size_t len = buffer_size(buf); @@ -385,7 +396,6 @@ long int z85_header_startswith(Buffer *buf, char *what) { } int z85_isend(Buffer *buf) { - if(! z85_isheader(buf)) return 0; @@ -428,10 +438,12 @@ int z85_isbegin(Buffer *buf) { int z85_iscomment(Buffer *buf) { char *line = buffer_get_str(buf); - if(strchr(line, ' ') == NULL || strchr(line, '\t') == NULL) + if(buffer_size(buf) > 0 && strchr(line, ' ') == NULL && strchr(line, '\t') == NULL) { return 0; /* non whitespace */ - else + } + else { return 1; /* true */ + } } int z85_isempty(Buffer *buf) {