@@ -883,4 +883,138 @@ describe("Cross Signing", function() {
883883 expect ( bobTrust3 . isCrossSigningVerified ( ) ) . toBeTruthy ( ) ;
884884 expect ( bobTrust3 . isTofu ( ) ) . toBeTruthy ( ) ;
885885 } ) ;
886+
887+ it (
888+ "should observe that our own device is cross-signed, even if this device doesn't trust the key" ,
889+ async function ( ) {
890+ const { client : alice } = await makeTestClient (
891+ { userId : "@alice:example.com" , deviceId : "Osborne2" } ,
892+ ) ;
893+ alice . uploadDeviceSigningKeys = async ( ) => { } ;
894+ alice . uploadKeySignatures = async ( ) => { } ;
895+
896+ // Generate Alice's SSK etc
897+ const aliceMasterSigning = new global . Olm . PkSigning ( ) ;
898+ const aliceMasterPrivkey = aliceMasterSigning . generate_seed ( ) ;
899+ const aliceMasterPubkey = aliceMasterSigning . init_with_seed ( aliceMasterPrivkey ) ;
900+ const aliceSigning = new global . Olm . PkSigning ( ) ;
901+ const alicePrivkey = aliceSigning . generate_seed ( ) ;
902+ const alicePubkey = aliceSigning . init_with_seed ( alicePrivkey ) ;
903+ const aliceSSK = {
904+ user_id : "@alice:example.com" ,
905+ usage : [ "self_signing" ] ,
906+ keys : {
907+ [ "ed25519:" + alicePubkey ] : alicePubkey ,
908+ } ,
909+ } ;
910+ const sskSig = aliceMasterSigning . sign ( anotherjson . stringify ( aliceSSK ) ) ;
911+ aliceSSK . signatures = {
912+ "@alice:example.com" : {
913+ [ "ed25519:" + aliceMasterPubkey ] : sskSig ,
914+ } ,
915+ } ;
916+
917+ // Alice's device downloads the keys, but doesn't trust them yet
918+ alice . crypto . deviceList . storeCrossSigningForUser ( "@alice:example.com" , {
919+ keys : {
920+ master : {
921+ user_id : "@alice:example.com" ,
922+ usage : [ "master" ] ,
923+ keys : {
924+ [ "ed25519:" + aliceMasterPubkey ] : aliceMasterPubkey ,
925+ } ,
926+ } ,
927+ self_signing : aliceSSK ,
928+ } ,
929+ firstUse : 1 ,
930+ unsigned : { } ,
931+ } ) ;
932+
933+ // Alice has a second device that's cross-signed
934+ const aliceCrossSignedDevice = {
935+ user_id : "@alice:example.com" ,
936+ device_id : "Dynabook" ,
937+ algorithms : [ "m.olm.curve25519-aes-sha256" , "m.megolm.v1.aes-sha" ] ,
938+ keys : {
939+ "curve25519:Dynabook" : "somePubkey" ,
940+ "ed25519:Dynabook" : "someOtherPubkey" ,
941+ } ,
942+ } ;
943+ const sig = aliceSigning . sign ( anotherjson . stringify ( aliceCrossSignedDevice ) ) ;
944+ aliceCrossSignedDevice . signatures = {
945+ "@alice:example.com" : {
946+ [ "ed25519:" + alicePubkey ] : sig ,
947+ } ,
948+ } ;
949+ alice . crypto . deviceList . storeDevicesForUser ( "@alice:example.com" , {
950+ Dynabook : aliceCrossSignedDevice ,
951+ } ) ;
952+
953+ // We don't trust the cross-signing keys yet...
954+ expect ( alice . checkDeviceTrust ( aliceCrossSignedDevice . device_id ) . isCrossSigningVerified ( ) ) . toBeFalsy ( ) ;
955+ // ... but we do acknowledge that the device is signed by them
956+ expect ( alice . checkIfOwnDeviceCrossSigned ( aliceCrossSignedDevice . device_id ) ) . toBeTruthy ( ) ;
957+ } ,
958+ ) ;
959+
960+ it ( "should observe that our own device isn't cross-signed" , async function ( ) {
961+ const { client : alice } = await makeTestClient (
962+ { userId : "@alice:example.com" , deviceId : "Osborne2" } ,
963+ ) ;
964+ alice . uploadDeviceSigningKeys = async ( ) => { } ;
965+ alice . uploadKeySignatures = async ( ) => { } ;
966+
967+ // Generate Alice's SSK etc
968+ const aliceMasterSigning = new global . Olm . PkSigning ( ) ;
969+ const aliceMasterPrivkey = aliceMasterSigning . generate_seed ( ) ;
970+ const aliceMasterPubkey = aliceMasterSigning . init_with_seed ( aliceMasterPrivkey ) ;
971+ const aliceSigning = new global . Olm . PkSigning ( ) ;
972+ const alicePrivkey = aliceSigning . generate_seed ( ) ;
973+ const alicePubkey = aliceSigning . init_with_seed ( alicePrivkey ) ;
974+ const aliceSSK = {
975+ user_id : "@alice:example.com" ,
976+ usage : [ "self_signing" ] ,
977+ keys : {
978+ [ "ed25519:" + alicePubkey ] : alicePubkey ,
979+ } ,
980+ } ;
981+ const sskSig = aliceMasterSigning . sign ( anotherjson . stringify ( aliceSSK ) ) ;
982+ aliceSSK . signatures = {
983+ "@alice:example.com" : {
984+ [ "ed25519:" + aliceMasterPubkey ] : sskSig ,
985+ } ,
986+ } ;
987+
988+ // Alice's device downloads the keys
989+ alice . crypto . deviceList . storeCrossSigningForUser ( "@alice:example.com" , {
990+ keys : {
991+ master : {
992+ user_id : "@alice:example.com" ,
993+ usage : [ "master" ] ,
994+ keys : {
995+ [ "ed25519:" + aliceMasterPubkey ] : aliceMasterPubkey ,
996+ } ,
997+ } ,
998+ self_signing : aliceSSK ,
999+ } ,
1000+ firstUse : 1 ,
1001+ unsigned : { } ,
1002+ } ) ;
1003+
1004+ // Alice has a second device that's also not cross-signed
1005+ const aliceNotCrossSignedDevice = {
1006+ user_id : "@alice:example.com" ,
1007+ device_id : "Dynabook" ,
1008+ algorithms : [ "m.olm.curve25519-aes-sha256" , "m.megolm.v1.aes-sha" ] ,
1009+ keys : {
1010+ "curve25519:Dynabook" : "somePubkey" ,
1011+ "ed25519:Dynabook" : "someOtherPubkey" ,
1012+ } ,
1013+ } ;
1014+ alice . crypto . deviceList . storeDevicesForUser ( "@alice:example.com" , {
1015+ Dynabook : aliceNotCrossSignedDevice ,
1016+ } ) ;
1017+
1018+ expect ( alice . checkIfOwnDeviceCrossSigned ( aliceNotCrossSignedDevice . device_id ) ) . toBeFalsy ( ) ;
1019+ } ) ;
8861020} ) ;
0 commit comments