Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/41end-to-end-keys/01-upload-key.pl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@

push our @EXPORT, qw( matrix_put_e2e_keys matrix_get_e2e_keys );

=head2 matrix_put_e2e_keys

matrix_put_e2e_keys( $user, device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => {
"curve25519:".$user->device_id => "base64publicidentitykey",
"ed25519:".$user->device_id => "base64publicidentitykey2"
},
signatures => {}
})

Upload device keys and one time keys for a user.

The `user_id` and `device_id` fields in `device_keys` will be set automatically
by this function.
=cut

sub matrix_put_e2e_keys
{
# TODO(paul): I don't really know what's parametric about this
Expand Down
11 changes: 10 additions & 1 deletion tests/41end-to-end-keys/04-query-key-federation.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
check => sub {
my ( $user, $remote_user ) = @_;

matrix_put_e2e_keys( $user )
my $device_keys = {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => {
"curve25519:".$user->device_id => "base64publicidentitykey",
"ed25519:".$user->device_id => "base64publicidentitykey2"
},
signatures => {}
};

matrix_put_e2e_keys( $user, device_keys => $device_keys )
->SyTest::pass_on_done( "Uploaded key" )
->then( sub {
matrix_set_device_display_name( $user, $user->device_id, "test display name" ),
Expand Down
140 changes: 125 additions & 15 deletions tests/41end-to-end-keys/06-device-lists.pl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ sub sync_until_user_in_device_list_id
device_keys => {
user_id => $user2->user_id,
device_id => $user2->device_id,
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => {
"curve25519:".$user2->device_id => "base64publicidentitykey",
"ed25519:".$user2->device_id => "base64publicidentitykey2"
},
signatures => {}
},
one_time_keys => {
"my_algorithm:my_id_1" => "my+base64+key"
Expand Down Expand Up @@ -181,7 +187,17 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $user1 );
})->then( sub {
matrix_put_e2e_keys( $user2 )
matrix_put_e2e_keys(
$user2,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => {
"curve25519:".$user2->device_id => "base64publicidentitykey",
"ed25519:".$user2->device_id => "base64publicidentitykey2"
},
signatures => {}
}
)
})->then( sub {
sync_until_user_in_device_list( $user1, $user2 );
})->then( sub {
Expand Down Expand Up @@ -244,7 +260,17 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $user1 );
})->then( sub {
matrix_put_e2e_keys( $user2 )
matrix_put_e2e_keys(
$user2,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => {
"curve25519:".$user2->device_id => "base64publicidentitykey",
"ed25519:".$user2->device_id => "base64publicidentitykey2"
},
signatures => {}
}
)
})->then( sub {
sync_until_user_in_device_list( $user1, $user2 );
})->then( sub {
Expand Down Expand Up @@ -306,13 +332,27 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $creator );
})->then( sub {
matrix_put_e2e_keys( $remote_leaver )
matrix_put_e2e_keys(
$remote_leaver,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => {
"curve25519:".$remote_leaver->device_id => "base64publicidentitykey",
"ed25519:".$remote_leaver->device_id => "base64publicidentitykey2"
},
signatures => {}
}
)
})->then( sub {
sync_until_user_in_device_list( $creator, $remote_leaver );
})->then( sub {
matrix_leave_room_synced( $remote_leaver, $room_id )
})->then( sub {
matrix_put_e2e_keys( $remote_leaver, device_keys => { keys => { "ed25519:test" => "cmltKURmLTRV86hBT_jh8AFH9RAdz0yAZOfvlBUQqP8" } } )
matrix_put_e2e_keys( $remote_leaver, device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_leaver->device_id => "cmltKURmLTRV86hBT_jh8AFH9RAdz0yAZOfvlBUQqP8" },
signatures => {},
} );
})->then( sub {
# It takes a while for the leave to propagate so lets just hammer this
# endpoint...
Expand Down Expand Up @@ -366,9 +406,23 @@ sub sync_until_user_in_device_list_id
sync_until_user_in_device_list( $creator, $remote_leaver );
})->then( sub {
# there must be e2e keys for the devices, otherwise they don't appear in /query.
matrix_put_e2e_keys( $remote2, device_keys => { keys => { "ed25519:test" => "aI2BUUeIQ0Y8T7Tv7jJh2ADagpoWdtHf4XipFPvjXI8" } } );
matrix_put_e2e_keys(
$remote2,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote2->device_id => "aI2BUUeIQ0Y8T7Tv7jJh2ADagpoWdtHf4XipFPvjXI8" },
signatures => {},
}
);
})->then( sub {
matrix_put_e2e_keys( $remote_leaver, device_keys => { keys => { "ed25519:test" => "j9eIBhARnZg5vhKzp8zm1A6up1LmSiDoXuDqTTIvkcI" } } );
matrix_put_e2e_keys(
$remote_leaver,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_leaver->device_id => "j9eIBhARnZg5vhKzp8zm1A6up1LmSiDoXuDqTTIvkcI" },
signatures => {},
}
);
})->then( sub {
sync_until_user_in_device_list( $creator, $remote_leaver );

Expand All @@ -387,7 +441,7 @@ sub sync_until_user_in_device_list_id
log_if_fail "keys after remote_leaver uploaded keys", $body;
assert_json_keys( $body, qw( device_keys ));
my $update = $body->{device_keys}->{ $remote_leaver->user_id }->{ $remote_leaver->device_id };
assert_eq( $update->{keys}{"ed25519:test"}, "j9eIBhARnZg5vhKzp8zm1A6up1LmSiDoXuDqTTIvkcI" );
assert_eq( $update->{keys}{"ed25519:".$remote_leaver->device_id}, "j9eIBhARnZg5vhKzp8zm1A6up1LmSiDoXuDqTTIvkcI" );
Future->done;
});
})->then( sub {
Expand Down Expand Up @@ -415,10 +469,24 @@ sub sync_until_user_in_device_list_id
})->then( sub {
# now /finally/ we can test what we came here for. Both remote users update their
# device keys, and we check that we only get an update for one of them.
matrix_put_e2e_keys( $remote_leaver, device_keys => { keys => { "ed25519:test" => "2NNgAXoqO06lZc3FOOKj76daZT8CmbHmmJKr29Jv85g" } } )
matrix_put_e2e_keys(
$remote_leaver,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_leaver->device_id => "2NNgAXoqO06lZc3FOOKj76daZT8CmbHmmJKr29Jv85g" },
signatures => {},
}
)
})->then( sub {
log_if_fail "Remote_leaver " . $remote_leaver->user_id . " updated keys";
matrix_put_e2e_keys( $remote2, device_keys => { keys => { "ed25519:test" => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" } } )
matrix_put_e2e_keys(
$remote2,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote2->device_id => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" },
signatures => {},
}
)
})->then( sub {
log_if_fail "Remote user 2 " . $remote2->user_id . " updated keys";

Expand Down Expand Up @@ -476,6 +544,9 @@ sub sync_until_user_in_device_list_id
device_keys => {
user_id => $user2->user_id,
device_id => $user2->device_id,
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:test" => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" },
signatures => {},
},
one_time_keys => {
"my_algorithm:my_id_1" => "my+base64+key"
Expand Down Expand Up @@ -578,7 +649,14 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $creator );
})->then( sub {
matrix_put_e2e_keys( $remote_leaver )
matrix_put_e2e_keys(
$remote_leaver,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_leaver->device_id => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" },
signatures => {},
}
)
})->then( sub {
sync_until_user_in_device_list( $creator, $remote_leaver );
})->then( sub {
Expand All @@ -587,7 +665,11 @@ sub sync_until_user_in_device_list_id

matrix_leave_room_synced( $remote_leaver, $room_id )
})->then( sub {
matrix_put_e2e_keys( $remote_leaver, device_keys => { keys => { "ed25519:test" => "72Fyh13X3itrbsWXHGQkqozmasfNRE6AEQPGbQFIykc" } } )
matrix_put_e2e_keys( $remote_leaver, device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_leaver->device_id => "72Fyh13X3itrbsWXHGQkqozmasfNRE6AEQPGbQFIykc" },
signatures => {},
} )
})->then( sub {
# It takes a while for the leave to propagate so lets just hammer this
# endpoint...
Expand Down Expand Up @@ -642,7 +724,14 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $creator );
})->then( sub {
matrix_put_e2e_keys( $other_user )
matrix_put_e2e_keys(
$other_user,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$other_user->device_id => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" },
signatures => {},
}
)
})->then( sub {
sync_until_user_in_device_list( $creator, $other_user );
})->then( sub {
Expand Down Expand Up @@ -701,7 +790,14 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $creator );
})->then( sub {
matrix_put_e2e_keys( $other_user )
matrix_put_e2e_keys(
$other_user,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$other_user->device_id => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" },
signatures => {},
}
)
})->then( sub {
matrix_set_device_display_name( $other_user, $other_user->device_id, "test display name" )
})->then( sub {
Expand Down Expand Up @@ -761,7 +857,14 @@ sub sync_until_user_in_device_list_id
})->then( sub {
matrix_sync( $creator );
})->then( sub {
matrix_put_e2e_keys( $remote_user )
matrix_put_e2e_keys(
$remote_user,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_user->device_id => "c3op6BJi8aUnDGA541Q6TbTPmbiy1GqGv-zzXDQM9Us" },
signatures => {},
}
)
})->then( sub {
sync_until_user_in_device_list(
$creator, $remote_user, msg => 'First body',
Expand All @@ -772,7 +875,14 @@ sub sync_until_user_in_device_list_id

matrix_leave_room_synced( $creator, $room_id )
})->then( sub {
matrix_put_e2e_keys( $remote_user, device_keys => { keys => { "ed25519:test" => "jAV9juztEM6Fjda60eut1GYyaP6QFlkfCd609celbwo" } } )
matrix_put_e2e_keys(
$remote_user,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$remote_user->device_id => "jAV9juztEM6Fjda60eut1GYyaP6QFlkfCd609celbwo" },
signatures => {},
}
)
})->then( sub {
# It takes a while for the leave to propagate so lets just hammer this
# endpoint...
Expand Down
5 changes: 3 additions & 2 deletions tests/41end-to-end-keys/08-cross-signing.pl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@
"keys" => {
"curve25519:$user2_device" => "IQ/Hu4GGOaxIpMavovFYGouVJeIP2miSfysv+Db3NXg",
"ed25519:$user2_device" => "MKkClRdltZlOHyCzxiDrm7MsDAsohXmAyeu2cYO6how",
}
},
"signatures" => {},
};
my $cross_signature;

Expand Down Expand Up @@ -673,7 +674,7 @@
exists $sigs->{$user2_id}
&& exists $sigs->{$user2_id}{$user2_device_key_id}
&& $sigs->{$user2_id}{$user2_device_key_id} eq $cross_signature
or die "Expected cross-signature ($user2_device_key_id}->$cross_signature not visible";
or die "Expected cross-signature ($user2_device_key_id)->$cross_signature not visible";

Future->done( $content );
});
Expand Down
42 changes: 37 additions & 5 deletions tests/50federation/40devicelists.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@

Future->done(1);
}),
matrix_put_e2e_keys( $user )
matrix_put_e2e_keys(
$user,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$user->device_id => "base64publicidentitykey" },
signatures => {},
}
)
)
})->then( sub {
Future->needs_all(
Expand All @@ -49,7 +56,11 @@

Future->done(1);
}),
matrix_put_e2e_keys( $user, device_keys => { updated => "keys" } )
matrix_put_e2e_keys( $user, device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$user->device_id => "newkey" },
signatures => {},
} )
)
});
};
Expand Down Expand Up @@ -424,7 +435,14 @@

Future->done(1);
}),
matrix_put_e2e_keys( $user1 )
matrix_put_e2e_keys(
$user1,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$user1->device_id => "base64publicidentitykey" },
signatures => {},
}
)
)
})->then( sub {
Future->needs_all(
Expand All @@ -439,7 +457,14 @@

Future->done(1);
}),
matrix_put_e2e_keys( $user2 )
matrix_put_e2e_keys(
$user2,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$user2->device_id => "base64publicidentitykey" },
signatures => {},
}
)
)
})->then( sub {
Future->needs_all(
Expand All @@ -455,7 +480,14 @@

Future->done(1);
}),
matrix_put_e2e_keys( $user1, device_keys => { updated => "keys" } )
matrix_put_e2e_keys(
$user1,
device_keys => {
algorithms => [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ],
keys => { "ed25519:".$user1->device_id => "newkey" },
signatures => {},
}
)
)
});
};
Expand Down
Loading