Fix non-journal, non-block based payload encryption

This commit is contained in:
Jeremy Lakeman 2013-07-26 15:13:22 +09:30
parent fa012347a8
commit 94381bab49
3 changed files with 22 additions and 13 deletions

View File

@ -602,6 +602,10 @@ static void add_nonce(unsigned char *nonce, int64_t value){
*/
int rhizome_crypt_xor_block(unsigned char *buffer, int buffer_size, int64_t stream_offset,
const unsigned char *key, const unsigned char *nonce){
if (stream_offset<0)
return WHY("Invalid stream offset");
int64_t nonce_offset = stream_offset & ~(RHIZOME_CRYPT_PAGE_SIZE -1);
int offset=0;

View File

@ -591,7 +591,8 @@ static int rhizome_write_derive_key(rhizome_manifest *m, rhizome_bk_t *bsk, stru
DEBUGF("Encrypting payload contents for %s, %"PRId64, alloca_tohex_bid(m->cryptoSignPublic), m->version);
write->crypt=1;
write->tail = m->journalTail;
if (m->journalTail>0)
write->tail = m->journalTail;
bcopy(m->payloadKey, write->key, sizeof(write->key));
bcopy(m->payloadNonce, write->nonce, sizeof(write->nonce));
@ -852,7 +853,8 @@ static int read_derive_key(rhizome_manifest *m, rhizome_bk_t *bsk, struct rhizom
if (config.debug.rhizome)
DEBUGF("Decrypting payload contents for %s, %"PRId64, alloca_tohex_bid(m->cryptoSignPublic), m->version);
read_state->tail = m->journalTail;
if (m->journalTail>0)
read_state->tail = m->journalTail;
bcopy(m->payloadKey, read_state->key, sizeof(read_state->key));
bcopy(m->payloadNonce, read_state->nonce, sizeof(read_state->nonce));
}

View File

@ -52,35 +52,28 @@ test_MessageDelivery() {
# 3. append a second message and list them both
executeOk_servald meshms send message $SIDA1 $SIDA2 "How are you"
executeOk_servald meshms list messages $SIDA1 $SIDA2
tfw_cat --stdout
assertStdoutGrep --stdout --matches=1 "::How are you\$"
assertStdoutGrep --stdout --matches=1 "::Hi\$"
assertStdoutLineCount '==' 4
# 4. list the messages from the receivers point of view (which ACKs them)
executeOk_servald meshms list messages $SIDA2 $SIDA1
tfw_cat --stdout --stderr
assertStdoutGrep --stdout --matches=1 "^0:19:$SIDA1:unread:How are you\$"
assertStdoutGrep --stdout --matches=1 "^1:5:$SIDA1:unread:Hi\$"
assertStdoutLineCount '==' 4
# 5. mark the first message as read
executeOk_servald meshms read messages $SIDA2 $SIDA1 5
tfw_cat --stdout --stderr
executeOk_servald meshms list messages $SIDA2 $SIDA1
tfw_cat --stdout --stderr
assertStdoutGrep --stdout --matches=1 ":unread:How are you\$"
assertStdoutGrep --stdout --matches=1 "::Hi\$"
assertStdoutLineCount '==' 4
# 6. mark all messages as read
executeOk_servald meshms read messages $SIDA2
tfw_cat --stdout --stderr
executeOk_servald meshms list messages $SIDA2 $SIDA1
tfw_cat --stdout --stderr
assertStdoutGrep --stdout --matches=1 "::How are you\$"
assertStdoutGrep --stdout --matches=1 "::Hi\$"
assertStdoutLineCount '==' 4
# 7. list messages from the senders point of view after they have been delivered
executeOk_servald meshms list messages $SIDA1 $SIDA2
tfw_cat --stdout --stderr
assertStdoutGrep --stdout --matches=1 ":delivered:How are you\$"
assertStdoutGrep --stdout --matches=1 ":delivered:Hi\$"
assertStdoutLineCount '==' 4
@ -117,7 +110,6 @@ test_MessageThreading() {
set_instance +B
wait_until has_unread_messages $SIDB
executeOk_servald meshms list messages $SIDB $SIDA
tfw_cat --stdout
assertStdoutGrep --stdout --matches=1 "^0:40:$SIDA:unread:Still waiting\$"
assertStdoutGrep --stdout --matches=1 "^1:24:$SIDA:unread:Hello can you hear me\$"
assertStdoutGrep --stdout --matches=1 "^2:54:$SIDB::Never mind\$"
@ -128,7 +120,6 @@ test_MessageThreading() {
wait_until has_unread_messages $SIDA
wait_until messages_delivered $SIDA $SIDB
executeOk_servald meshms list messages $SIDA $SIDB
tfw_cat --stdout
assertStdoutGrep --stdout --matches=1 "^0:54:$SIDB:unread:Never mind\$"
assertStdoutGrep --stdout --matches=1 "^1:41:$SIDB:unread:Help Im trapped in a test case factory\$"
assertStdoutGrep --stdout --matches=1 "^2:40:$SIDA:delivered:Still waiting\$"
@ -145,7 +136,7 @@ setup_listConversations() {
set debug.rhizome on \
set debug.meshms on \
set log.console.level debug
#cheating, adding fake message logs to the same servald
# create 3 threads, with all permutations of incoming and outgoing messages
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message1"
executeOk_servald meshms send message $SIDA3 $SIDA1 "Message2"
executeOk_servald meshms send message $SIDA1 $SIDA4 "Message3"
@ -153,7 +144,7 @@ setup_listConversations() {
}
test_listConversations() {
executeOk_servald meshms list conversations $SIDA1
tfw_cat --stdout
tfw_cat --stderr
assertStdoutIs --stderr --line=1 -e '2\n'
assertStdoutIs --stderr --line=2 -e 'sid:read\n'
assertStdoutGrep --stderr --matches=1 "^$SIDA2:\$"
@ -161,9 +152,21 @@ test_listConversations() {
assertStdoutGrep --stderr --matches=1 "^$SIDA4:unread\$"
assertStdoutLineCount '==' 5
executeOk_servald meshms list conversations $SIDA1 1
tfw_cat --stderr
assertStdoutLineCount '==' 4
executeOk_servald meshms list conversations $SIDA1 1 1
tfw_cat --stderr
assertStdoutLineCount '==' 3
# mark all incoming messages as read
executeOk_servald meshms read messages $SIDA1
tfw_cat --stderr
executeOk_servald meshms list conversations $SIDA1
assertStdoutIs --stderr --line=1 -e '2\n'
assertStdoutIs --stderr --line=2 -e 'sid:read\n'
assertStdoutGrep --stderr --matches=1 "^$SIDA2:\$"
assertStdoutGrep --stderr --matches=1 "^$SIDA3:\$"
assertStdoutGrep --stderr --matches=1 "^$SIDA4:\$"
assertStdoutLineCount '==' 5
}
runTests "$@"