matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript
Apache License 2.0
1.6k stars 589 forks source link

This room contains devices that are unverified #4348

Closed IAlphaOmegaI closed 2 months ago

IAlphaOmegaI commented 2 months ago

I'm new to matrix and I want to integrate to one of my existing projects for it's chat and video call functionality. While ive managed to get myself acquainted with creating users with registration tokens, creating rooms, sending messages and so on, when i actually try to communicate i always get this error:

** Unable to decrypt: DecryptionError: The sender's device has not sent us the keys for this message. **

on my messages and

UnknownDeviceError: This room contains unknown devices which have not been verified. We strongly recommend you verify them before continuing.

When I try to send a message.

Of course I may have set up something incorrectly, here is my full setup:

  const username = uuid();
      const password = uuid();
      // we do a minimal setup to initiate a session
      const setup = await axios.post(
        `${this.homeServerUrl}/_matrix/client/v3/register`,
        {
          auth: { type: 'm.login.dummy' },
        },
        {
          validateStatus: function () {
            return true; // Only treat 401 as a successful response
          },
        },
      );
      const { session } = setup.data;
      //then we register the user using the session that we initiated above
      const register = await axios.post<Matrix.Response.Authentication>(
        `${this.homeServerUrl}/_matrix/client/v3/register`,
        {
          username,
          password,
          auth: { type: 'm.login.registration_token', token: this.adminToken, session },
        },
      );
      const { user_id, access_token, device_id } = register.data;

      // Mark the device as verified
      // await this.verifyDeviceKeys(user_id, device_id, access_token);
      // await this.keyManager.setupNewAccount(user_id, access_token, device_id);

      const matrixAccount = new this.matrixAccountModel({
        username,
        password, // we can consider encrypting or not storing the password as per your security requirements
        deviceId: device_id,
        accessToken: access_token,
        userId: user_id,
        accountId,
      });
      await matrixAccount.save();

Which i use to register an account,

 const client = sdk.createClient({
    baseUrl: "http://localhost:8008",
    accessToken,
    userId,
    deviceId,
    timelineSupport: true,
    cryptoStore: new sdk.IndexedDBCryptoStore(
      indexedDB,
      "matrix-js-sdk:crypto"
    ),
  });
  await client.initCrypto();
  await client.startClient();
  await bootstrapCrossSigning(client);
  await client.setDeviceVerified(userId, deviceId, true);

Which i use to start a client in my front-end and where the bootstrapCrossSigning looks like this:


const bootstrapCrossSigning = async (client: sdk.MatrixClient) => {
  const authData: { session?: string; type: sdk.AuthType; token: string } = {
    type: sdk.AuthType.RegistrationToken,
    token: "dasjhkdasio42190-051-2",
  };

  async function attemptAuth(
    makeRequest: (
      authData: sdk.AuthDict | null
    ) => Promise<sdk.UIAResponse<unknown>>
  ) {
    try {
      await makeRequest(authData);
    } catch (error) {
      console.log("Authentication failed:", error);
      if ((error as any).httpStatus === 401 && (error as any).data?.session) {
        console.log("Received session ID, retrying with session included");
        authData.session = (error as any).data.session;
        await makeRequest(authData);
      }
      console.error("Authentication failed:", error);
      throw error;
    }
  }

  try {
    await client.getCrypto()?.bootstrapCrossSigning({
      authUploadDeviceSigningKeys: attemptAuth,
    });
    console.log("Cross-signing bootstrapped successfully");
  } catch (error) {
    console.error("Failed to bootstrap cross-signing:", error);
    // Handle the error appropriately
  }
};

Help would be really appreciated, thanks a lot!

Worth specifying that this is the network tab on the browser: ` Request URL: http://localhost:8008/_matrix/client/v3/user/%4064049031-3d0a-49e3-8ab3-29260c6388eb%3Achat.zerapy.ai/account_data/m.cross_signing.master Request Method: GET Status Code: 404 Not Found Remote Address:

Referrer Policy: no-referrer ` Not found for that

` Request URL: http://localhost:8008/_matrix/client/v3/user/%4064049031-3d0a-49e3-8ab3-29260c6388eb%3Achat.zerapy.ai/account_data/m.cross_signing.self_signing Request Method: GET Status Code: 404 Not Found Remote Address:

Referrer Policy: no-referrer ` Same goes for the self signing

And I keep getting a 401 for:

` Request URL: http://localhost:8008/_matrix/client/unstable/keys/device_signing/upload Request Method: POST Status Code: 401 Unauthorized Remote Address:

Referrer Policy: no-referrer ` even when the body has a valid auth:

{
    "master_key": {
        "user_id": "@64049031-3d0a-49e3-8ab3-29260c6388eb:chat.zerapy.ai",
        "usage": [
            "master"
        ],
        "keys": {
            "ed25519:DoI6u3ZWEdY1b7xyclFSYWIRvw5IBHFoGIOxLlbe928": "DoI6u3ZWEdY1b7xyclFSYWIRvw5IBHFoGIOxLlbe928"
        },
        "signatures": {
            "@64049031-3d0a-49e3-8ab3-29260c6388eb:chat.zerapy.ai": {
                "ed25519:GUWPMJMZQF": "wVVrsg21lyTwlrwaFM7bCFc2I8Iegwytyy7LvhBxuleUty/u1MloAok/eElWfFCjckYBmV9SFheti0ZHVereBg"
            }
        }
    },
    "self_signing_key": {
        "user_id": "@64049031-3d0a-49e3-8ab3-29260c6388eb:chat.zerapy.ai",
        "usage": [
            "self_signing"
        ],
        "keys": {
            "ed25519:Fk86L7Zj+i5d8aQPSIbfepeC5qMU+BRnOXEcRJjCYBs": "Fk86L7Zj+i5d8aQPSIbfepeC5qMU+BRnOXEcRJjCYBs"
        },
        "signatures": {
            "@64049031-3d0a-49e3-8ab3-29260c6388eb:chat.zerapy.ai": {
                "ed25519:DoI6u3ZWEdY1b7xyclFSYWIRvw5IBHFoGIOxLlbe928": "ZhrgCN3l+nJ+O9vwEXxI7aTkkPn2y2PEA9453fSo6cKAdQbAhKYRPid9lGSWJRpwUt8cNpcChxIGn87zYjtKCA"
            }
        }
    },
    "user_signing_key": {
        "user_id": "@64049031-3d0a-49e3-8ab3-29260c6388eb:chat.zerapy.ai",
        "usage": [
            "user_signing"
        ],
        "keys": {
            "ed25519:6wLiZI4xta7TLNw3Gvjy78YWiPlyUlg0YvV8hOTtuqo": "6wLiZI4xta7TLNw3Gvjy78YWiPlyUlg0YvV8hOTtuqo"
        },
        "signatures": {
            "@64049031-3d0a-49e3-8ab3-29260c6388eb:chat.zerapy.ai": {
                "ed25519:DoI6u3ZWEdY1b7xyclFSYWIRvw5IBHFoGIOxLlbe928": "wBPnD2sqb2kKHgmqzrHGu3DOPrwcufPAsCmdK4SjgmplHKWQKYu/I0menXbuKHKWiBk3go8ZbUeGq/cuehXDCQ"
            }
        }
    },
    "auth": {
        "type": "m.login.registration_token",
        "token": "dasjhkdasio42190-051-2",
        "session": "obvuTNQCtgqASlDtZTzrIEoP"
    }
}
IAlphaOmegaI commented 2 months ago

homeserver.yaml if needed:

# Configuration file for Synapse (improved version). Includes config for turn servers amongst other things.

# Configuration file for Synapse.
#
# This is a YAML file: see [1] for a quick introduction. Note in particular
# that *indentation is important*: all the elements of a list or dictionary
# should have the same indentation.
#
# [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
#
# For more information on how to configure Synapse, including a complete accounting of
# each option, go to docs/usage/configuration/config_documentation.md or
# https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html
listeners:
  - port: 8008
    tls: false
    type: http
    x_forwarded: true
    resources:
      - names: [client, federation]
        compress: false
database:
  name: sqlite3
  args:
    database: /data/homeserver.db
log_config: "/data/example.com.log.config"
media_store_path: /data/media_store
enable_registration: true
report_stats: true
registration_requires_token: true
enable_registration_without_verification: true
signing_key_path: "/data/chat.zerapy.ai.com.signing.key"
suppress_key_server_warning: true

# vim:ft=yaml
server_name: "chat.zerapy.ai"
pid_file: data/homeserver.pid
registration_shared_secret: "6d637e90deeec668e925496111621486"
macaroon_secret_key: "j&1H_xooEl3uHDsVO&&gHzPG#YKuL;LUOBDYOh8thnxcXA*Oip"
form_secret: "ZL-^Fgzta093JF~UBFh6Ut@i3nyEtrs6DF0qZq*f;Uu.t4^F;@"
trusted_key_servers:
  - server_name: "matrix.org"

#MegolmEncryption:
#  checkForUnknownDevices: false

# Enable encryption
encryption_enabled_by_default_for_room_type: all

# Enable key backups
enable_key_backup: true
# Set up a backup config
backups:
  enabled: true
  backup_location: data/backups

# Enable TURN for better connectivity
#turn_uris: [ "turn:your_turn_server:3478" ]
#turn_shared_secret: "your_turn_shared_secret"
#turn_user_lifetime: 86400000

# Enable push notifications (if needed)
#enable_push: true

# Increase ratelimiting for better performance (adjust as needed)
rc_message:
  per_second: 1000
  burst_count: 1000

rc_registration:
  per_second: 1000
  burst_count: 1000

rc_login:
  address:
    per_second: 1000
    burst_count: 1000
  account:
    per_second: 1000
    burst_count: 1000
  failed_attempts:
    per_second: 1000
    burst_count: 1000

# Enable server notices
server_notices:
  system_mxid_localpart: server
  system_mxid_display_name: "Server Notices"
  system_mxid_avatar_url: "mxc://server.com/oumMVlRDjiAtQYFmhXZOmSM"
  room_name: "Server Notices"

# Enable presence (if needed)
use_presence: true

# Enable URL previews (if needed)
#url_preview_enabled: true
max_spider_size: 10M

# Enable SAML2 authentication (if needed)
# saml2_config:
#   sp_config:
#     metadata:
#       local: ["/path/to/sp-metadata.xml"]

# Enable OpenID Connect authentication (if needed)
# oidc_providers:
#   - idp_id: google
#     idp_name: Google
#     issuer: "https://accounts.google.com/"
#     client_id: "your_client_id"
#     client_secret: "your_client_secret"
#     scopes: ["openid", "profile"]
#     authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth"
#     token_endpoint: "https://oauth2.googleapis.com/token"
#     userinfo_endpoint: "https://openidconnect.googleapis.com/v1/userinfo"

# Increase performance (adjust based on your server's capacity)
event_cache_size: "10K"
dbkr commented 2 months ago

This isn't the best place to ask for support: maybe try one of the Matrix rooms like https://matrix.to/#/#matrix-dev:matrix.org

IAlphaOmegaI commented 2 months ago

This isn't the best place to ask for support: maybe try one of the Matrix rooms like https://matrix.to/#/#matrix-dev:matrix.org

Thanks, I guess I'll try to find support there.