Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrapCrossSigning() failing with "Error: the signing key is missing from the object that signed the message" #4625

Closed
Crazypersonalph opened this issue Jan 17, 2025 · 6 comments

Comments

@Crazypersonalph
Copy link

Good afternoon,
I am writing a simple program to send encrypted messages to a matrix room.
I am currently trying to setup cross-signing, but am erroring out with

import * as sdk from "matrix-js-sdk";
import "fake-indexeddb/auto";
import bs58 from "bs58";


const recoveryKeyString = process.env.BACKUP_KEY_MATRIX

const client = sdk.createClient({ 
 baseUrl: "https://matrix.org", 
 accessToken: process.env.MATRIX_ACCESS_TOKEN, 
 userId: process.env.MATRIX_USER,
 deviceId: "frigate-server",
 cryptoCallbacks: {
    getSecretStorageKey: async (keys) => {
        const key = sdk.Crypto.decodeRecoveryKey(recoveryKeyString);
        return [Object.keys(keys.keys)[0], key];
    },
},
});

await client.initRustCrypto();
client.getCrypto().bootstrapSecretStorage({
    // This function will be called if a new secret storage key (aka recovery key) is needed.
    // You should prompt the user to save the key somewhere, because they will need it to unlock secret storage in future.
    createSecretStorageKey: async () => {
        return key;
    }
    
});

await client.getCrypto().bootstrapCrossSigning({
    authUploadDeviceSigningKeys: async (makeRequest) => {
        return makeRequest(authDict);
    },
});

client.startClient({ initialSyncLimit: 10});

const content = {
    body: "message text",
    msgtype: "m.text",
};

client.getCrypto().prepareToEncrypt(process.env.MATRIX_ROOM_ID);

await client.sendEvent(process.env.MATRIX_ROOM_ID, "m.room.message", content, "", (err, res) => {
    console.log(err);
});

All messages sent to the room aren't encrypted either.
The account was originally setup with Element, in which secure backup, encryption, and cross-signing were also setup.
All values provided in process.env are correct.

It is erroring out with:

bootstrapCrossSigning: starting {
  setupNewCrossSigning: undefined,
  olmDeviceHasMaster: false,
  olmDeviceHasUserSigning: false,
  olmDeviceHasSelfSigning: false,
  privateKeysInSecretStorage: true
}
bootstrapCrossSigning: Cross-signing private keys not found locally, but they are available in secret storage, reading storage and caching locally
WARN matrix_sdk_crypto::store: No public identity found while importing cross-signing keys, a /keys/query needs to be done

Error: the signing key is missing from the object that signed the message

Does anybody have any input?

Kind Regards

@Crazypersonalph
Copy link
Author

Crazypersonalph commented Jan 17, 2025

Also noticed this in the logs, not sure if it's related.
Key backup present on server but not trusted: not enabling key backup

@florianduros
Copy link
Contributor

I strongly encourage to come to https://matrix.to/#/#element-dev:matrix.org in order to seek help for using the js-sdk

@chermme
Copy link

chermme commented Feb 1, 2025

I seem to be getting exactly the same error message. Did you manage to solve it @Crazypersonalph?

bootstrapCrossSigning: Cross-signing private keys not found locally, but they are available in secret storage, reading storage and caching locally
WARN matrix_sdk_crypto::store: No public identity found while importing cross-signing keys, a /keys/query needs to be done
    at /home/runner/.cargo/git/checkouts/matrix-rust-sdk-1f4927f82a3d27bb/b18e7d7/crates/matrix-sdk-crypto/src/store/mod.rs:1325
Failed to initialize RustCrypto: Error: the signing key is missing from the object that signed the message

@Crazypersonalph
Copy link
Author

I seem to be getting exactly the same error message. Did you manage to solve it @Crazypersonalph?

bootstrapCrossSigning: Cross-signing private keys not found locally, but they are available in secret storage, reading storage and caching locally
WARN matrix_sdk_crypto::store: No public identity found while importing cross-signing keys, a /keys/query needs to be done
    at /home/runner/.cargo/git/checkouts/matrix-rust-sdk-1f4927f82a3d27bb/b18e7d7/crates/matrix-sdk-crypto/src/store/mod.rs:1325
Failed to initialize RustCrypto: Error: the signing key is missing from the object that signed the message

No, I didn't. I eventually gave up. The encryption library is really finicky for some reason.

@richvdh
Copy link
Member

richvdh commented Feb 3, 2025

 deviceId: "frigate-server",

don't do this. You need to pass in the device ID returned by /login (and allow /login to choose a device ID for you.)

@richvdh
Copy link
Member

richvdh commented Feb 3, 2025

import "fake-indexeddb/auto";

Also: if you're not using persistent storage, there is nowhere for the encryption library to store the device keys; so, each time you start the application, it has to create new device keys. Obviously, that is going to confuse every other client belonging to you or anyone you talk to.

In short: if you really can't use a persistent database, you'll need to create a new "device" with /login each time the application starts, so you probably need to pass in the login creds rather than an existing access token.

I'm going to go ahead and close this issue because I assume the main problem is this mismatch of ephemeral storage but persistent device IDs, but if anyone still has problems once those issues are fixed, we can reopen.

@richvdh richvdh closed this as completed Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants