fixed annoying error in _buffer_is_binary() which returned false sometimes even when the input were in fact binary. This fixes those 2 annoying unittests which failed from time to time.

This commit is contained in:
git@daemon.de
2014-02-17 17:03:55 +01:00
parent 3f03f97992
commit 1afb5cc3d7
5 changed files with 52 additions and 31 deletions

View File

@@ -58,6 +58,16 @@
c and yaml code. A programmer can use this to c and yaml code. A programmer can use this to
put a public key in a small program. put a public key in a small program.
Finally found the bug that leaded to the unittests
sometimes fail as previously described in the TODO
file: the function libpcp/z85.c:_buffer_is_binary()
shall return a non-zero value if it finds a binary
character in the input. However, if the first char
of the input was binary it returned 0, which was then
interpreted later such that the input is ascii.
To fix this, the function now starts at position 1
to search.
0.2.0 ED25519 and Curve25519 keys are now generated 0.2.0 ED25519 and Curve25519 keys are now generated
separately (previously they were generated from separately (previously they were generated from
one random seed, the curve had been derived from one random seed, the curve had been derived from

13
TODO
View File

@@ -17,19 +17,6 @@ vault checksum: add keysigs as well
enable formats for secret key exports as well enable formats for secret key exports as well
Unitttests:
- sometimes "no matching pub key in vault, while it's there
Cause:
echo HALLO | ../src/pcp1 -V vcl -e -O testencrypted -i 0xA907B927849B39F9
ok 28 - check-crypto-unencrypted-secret-message
public key exported. <=== ???
- sometimes secret key is empty
Possible causes: the unittest segfaults and unittest.pl doesn't
catch it, esp. if the prepare call segfaults. Or, there's some bug
in unittest.pl, however the issue started as I switched to the
pcpstream api.
Python binding, e.g.: Python binding, e.g.:

View File

@@ -184,6 +184,7 @@ pcp_ks_bundle_t *pcp_import_pub(unsigned char *raw, size_t rawsize) {
/* first, try to decode the input */ /* first, try to decode the input */
z85 = pcp_readz85string(raw, rawsize); z85 = pcp_readz85string(raw, rawsize);
if(z85 != NULL) if(z85 != NULL)
bin = pcp_z85_decode(z85, &clen); bin = pcp_z85_decode(z85, &clen);

View File

@@ -24,7 +24,9 @@
size_t _buffer_is_binary(unsigned char *buf, size_t len) { size_t _buffer_is_binary(unsigned char *buf, size_t len) {
size_t pos; size_t pos;
for (pos=0; pos<len; ++pos) { /* start at 1, to circumvent returning 0 if we find a match at position 0,
which would lead the caller to believe the buffer is not binary */
for (pos=1; pos<len; ++pos) {
if(buf[pos] == '\0' || (buf[pos] != '\r' && buf[pos] != '\n' && isprint(buf[pos]) == 0)) { if(buf[pos] == '\0' || (buf[pos] != '\r' && buf[pos] != '\n' && isprint(buf[pos]) == 0)) {
break; break;
} }

View File

@@ -189,26 +189,47 @@ temporarily disabled
# #
# check usage of unencrypted secret key # check usage of unencrypted secret key
<test check-crypto-unencrypted-secret> <test vcl>
prepare = rm -f vb2 vcl
<test check-vcl-crypto-unencrypted-secret>
cmd = (echo dau; echo foo; echo yes) | $pcp -V vcl -k -x "n/a" cmd = (echo dau; echo foo; echo yes) | $pcp -V vcl -k -x "n/a"
expect = /added to/ expect = /added to/
</test> </test>
<test check-crypto-unencrypted-secret-yaml> <test check-vcl-crypto-unencrypted-secret-yaml>
cmd = $pcp -V vcl -y cmd = $pcp -V vcl -y
expect = /encrypted: no/ expect = /encrypted: no/
</test> </test>
<test check-crypto-unencrypted-secret-message> <test check-vcl-prepare-import-bpub>
prepare = $pcp -V vcl -I key-bobby-pub -P cmd = $pcp -V vcl -I key-bobby-pub -P
expect = /added/
</test>
<test check-vcl-export-unencrypted-pubkey>
cmd = $pcp -V vcl -p -O testkeyvcl
expect = /exported/
</test>
<test check-vcl-import-bsecret>
cmd = $pcp -V vb2 -S -I key-bobby-sec -x b
expect = /${idbobby}/
</test>
<test check-vcl-import-unencrypted-pubkey>
cmd = $pcp -V vb2 -P -I testkeyvcl
expect = /added/
</test>
<test check-vcl-crypto-unencrypted-secret-message>
cmd = echo HALLO | $pcp -V vcl -e -O testencrypted -i ${idbobby} cmd = echo HALLO | $pcp -V vcl -e -O testencrypted -i ${idbobby}
expect = /success/ expect = /success/
</test> </test>
<test check-crypto-unencrypted-secret-read> <test check-vcl-crypto-unencrypted-secret-read>
prepare = $pcp -V vcl -p | $pcp -V vb -P cmd = $pcp -V vb2 -d -I testencrypted -x b
cmd = $pcp -V vb -d -I testencrypted -x b
expect = /HALLO/ expect = /HALLO/
</test>
</test> </test>
# #