fixed signature headers, fixed z85 string parser, it didnt properly catch END headers

This commit is contained in:
TLINDEN
2014-03-02 10:35:51 +01:00
parent 4253e1088f
commit 93a9f2d307
4 changed files with 24 additions and 9 deletions

View File

@@ -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"

View File

@@ -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 */

View File

@@ -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);

View File

@@ -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) {