Wait for path establishment in network scan test

This commit is contained in:
Jeremy Lakeman 2016-09-27 15:51:23 +09:30
parent ced74d0b6b
commit 62a1ca46bc
7 changed files with 33 additions and 40 deletions

View File

@ -239,7 +239,7 @@ keyring_identity *keyring_find_identity_sid(keyring_file *k, const sid_t *sidp){
keyring_identity *keyring_find_identity(keyring_file *k, const identity_t *sign){
keyring_identity *id = k->identities;
while(id && (!id->box_pk || cmp_identity_t(id->sign_pk, sign)!=0))
while(id && (!id->box_pk || cmp_identity_t(&id->sign_keypair->public_key, sign)!=0))
id = id->next;
return id;
}
@ -253,19 +253,17 @@ static void add_subscriber(keyring_identity *id)
id->subscriber->reachable = REACHABLE_SELF;
id->subscriber->identity = id;
if (id->sign_pk){
// copy our signing key, so we can pass it to peers
bcopy(id->sign_pk, &id->subscriber->id_public, sizeof id->subscriber->id_public);
id->subscriber->id_valid = 1;
// copy our signing key, so we can pass it to peers
id->subscriber->id_public = id->sign_keypair->public_key;
id->subscriber->id_valid = 1;
keypair *kp = id->keypairs;
while(kp){
if (kp->type == KEYTYPE_CRYPTOCOMBINED){
id->subscriber->id_combined = 1;
break;
}
kp = kp->next;
keypair *kp = id->keypairs;
while(kp){
if (kp->type == KEYTYPE_CRYPTOCOMBINED){
id->subscriber->id_combined = 1;
break;
}
kp = kp->next;
}
}
}
@ -1195,7 +1193,7 @@ static int keyring_finalise_identity(uint8_t *dirty, keyring_identity *id)
break;
case KEYTYPE_CRYPTOSIGN:{
const sign_keypair_t *keypair = (const sign_keypair_t *)kp->private_key;
if (!crypto_isvalid_keypair(&keypair->private_key, (const sign_public_t *)kp->public_key)){
if (!crypto_isvalid_keypair(&keypair->private_key, &keypair->public_key)){
/* SAS key is invalid (perhaps because it was a pre 0.90 format one),
so replace it */
WARN("SAS key is invalid -- regenerating.");
@ -1203,8 +1201,7 @@ static int keyring_finalise_identity(uint8_t *dirty, keyring_identity *id)
if (dirty)
*dirty = 1;
}
id->sign_sk = keypair;
id->sign_pk = (const identity_t *)kp->public_key;
id->sign_keypair = (const sign_keypair_t *)kp->private_key;
}
break;
case KEYTYPE_CRYPTOCOMBINED:{
@ -1212,8 +1209,7 @@ static int keyring_finalise_identity(uint8_t *dirty, keyring_identity *id)
struct combined_sk *sk = (struct combined_sk *)kp->private_key;
id->box_pk = &pk->box_key;
id->box_sk = sk->box_key;
id->sign_pk = &pk->sign_key;
id->sign_sk = &sk->sign_key;
id->sign_keypair = &sk->sign_key;
break;
}
}
@ -1737,7 +1733,7 @@ int keyring_sign_message(struct keyring_identity *identity, unsigned char *conte
unsigned char hash[crypto_hash_sha512_BYTES];
crypto_hash_sha512(hash, content, *content_len);
if (crypto_sign_detached(&content[*content_len], NULL, hash, crypto_hash_sha512_BYTES, identity->sign_sk->binary))
if (crypto_sign_detached(&content[*content_len], NULL, hash, crypto_hash_sha512_BYTES, identity->sign_keypair->binary))
return WHY("Signing failed");
*content_len += SIGNATURE_BYTES;
@ -1796,10 +1792,10 @@ static int keyring_respond_id(struct internal_mdp_header *header)
ob_limitsize(response_payload, sizeof buff);
ob_append_byte(response_payload, KEYTYPE_CRYPTOSIGN);
ob_append_bytes(response_payload, id->sign_pk->binary, crypto_sign_PUBLICKEYBYTES);
ob_append_bytes(response_payload, id->sign_keypair->public_key.binary, crypto_sign_PUBLICKEYBYTES);
uint8_t *sig = ob_append_space(response_payload, crypto_sign_BYTES);
if (crypto_sign_detached(sig, NULL, header->destination->sid.binary, SID_SIZE, id->sign_sk->binary))
if (crypto_sign_detached(sig, NULL, header->destination->sid.binary, SID_SIZE, id->sign_keypair->binary))
return WHY("crypto_sign() failed");
DEBUGF(keyring, "Sending SID:SAS mapping, %zd bytes, %s:%"PRImdp_port_t" -> %s:%"PRImdp_port_t,

View File

@ -50,8 +50,7 @@ typedef struct keyring_identity {
struct keyring_challenge *challenge;
const uint8_t *box_sk;
const sid_t *box_pk;
const sign_keypair_t *sign_sk;
const identity_t *sign_pk;
const sign_keypair_t *sign_keypair;
struct keyring_identity *next;
keypair *keypairs;
} keyring_identity;

View File

@ -139,7 +139,7 @@ static int app_keyring_list(const struct cli_parsed *parsed, struct cli_context
const char *name = NULL;
keyring_identity_extract(id, &did, &name);
cli_put_string(context, alloca_tohex_sid_t(*id->box_pk), ":");
cli_put_string(context, alloca_tohex_identity_t(id->sign_pk), ":");
cli_put_string(context, alloca_tohex_identity_t(&id->sign_keypair->public_key), ":");
cli_put_string(context, did, ":");
cli_put_string(context, name, "\n");
rowcount++;
@ -151,14 +151,10 @@ static int app_keyring_list(const struct cli_parsed *parsed, struct cli_context
static void cli_output_identity(struct cli_context *context, const keyring_identity *id)
{
if (id->box_pk){
cli_field_name(context, "sid", ":");
cli_put_string(context, alloca_tohex_sid_t(*id->box_pk), "\n");
}
if (id->sign_pk){
cli_field_name(context, "identity", ":");
cli_put_string(context, alloca_tohex_identity_t(id->sign_pk), "\n");
}
cli_field_name(context, "sid", ":");
cli_put_string(context, alloca_tohex_sid_t(*id->box_pk), "\n");
cli_field_name(context, "identity", ":");
cli_put_string(context, alloca_tohex_identity_t(&id->sign_keypair->public_key), "\n");
keypair *kp=id->keypairs;
while(kp){
switch(kp->type){
@ -209,10 +205,7 @@ static int app_keyring_list2(const struct cli_parsed *parsed, struct cli_context
unsigned fields=0;
// count the number of fields that we will output
keypair *kp=id->keypairs;
if (id->box_pk)
fields++;
if (id->sign_pk)
fields++;
fields+=2;
while(kp){
if (kp->type==KEYTYPE_PUBLIC_TAG)
fields++;

View File

@ -101,7 +101,7 @@ static int http_request_keyring_response_identity(struct httpd_request *r, uint1
json_id_kv[1].key = "identity";
json_id_kv[1].value = &json_sas;
json_sas.type = JSON_STRING_NULTERM;
json_sas.u.string.content = alloca_tohex_identity_t(id->sign_pk);
json_sas.u.string.content = alloca_tohex_identity_t(&id->sign_keypair->public_key);
if (did) {
json_id_kv[json_id.u.object.itemc].key = "did";
@ -183,7 +183,7 @@ static int restful_keyring_identitylist_json_content_chunk(struct http_request *
strbuf_puts(b, "\n[");
strbuf_json_string(b, alloca_tohex_sid_t(*r->u.sidlist.it.identity->box_pk));
strbuf_puts(b, ",");
strbuf_json_string(b, alloca_tohex_identity_t(r->u.sidlist.it.identity->sign_pk));
strbuf_json_string(b, alloca_tohex_identity_t(&r->u.sidlist.it.identity->sign_keypair->public_key));
strbuf_puts(b, ",");
strbuf_json_string(b, did);
strbuf_puts(b, ",");

View File

@ -14,7 +14,7 @@ static int meshmb_send(keyring_identity *id, const char *message, size_t message
struct message_ply ply;
bzero(&ply, sizeof ply);
bcopy(id->sign_pk, &ply.bundle_id, sizeof(ply.bundle_id));
ply.bundle_id = id->sign_keypair->public_key;
ply.known_bid = 1;
struct overlay_buffer *b = ob_new();

View File

@ -206,8 +206,8 @@ static enum rhizome_bundle_authorship try_author(rhizome_manifest *m, const keyr
m->keypair.private_key = test_key;
}else{
if (memcmp(&m->keypair.public_key, id->sign_pk, crypto_sign_PUBLICKEYBYTES)==0){
bcopy(id->sign_sk, m->keypair.binary, sizeof m->keypair.binary);
if (memcmp(&m->keypair.public_key, &id->sign_keypair->public_key, sizeof(sign_public_t))==0){
m->keypair = *id->sign_keypair;
}else{
DEBUGF(rhizome, " bundle has no BK field");
// TODO if sign_key.public_key == id signing key...

View File

@ -411,12 +411,17 @@ test_scan() {
set_instance +A
executeOk_servald scan
wait_until --timeout=10 scan_completed
wait_until --timeout=10 path_exists +B +A +C
wait_until --timeout=10 path_exists +C +A +B
set_instance +A
wait_until --timeout=10 has_seen_instances +B +C
executeOk_servald route print
link_matches --unicast $SIDB
link_matches --unicast $SIDC
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
set_instance +B
executeOk_servald route print
link_matches --unicast $SIDA