Hides url preview content from matrix homeserver
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-04-19 17:25:57 +09:30
lib Update encrypted_url_preview.dart 2024-04-19 15:38:51 +09:30
test update api to discourage key re-use 2024-04-19 15:29:52 +09:30
.gitattributes Initial Commit 2024-01-21 18:17:48 +10:30
.gitignore Initial Commit 2024-01-21 18:17:48 +10:30
ABOUT.md Update to new server 2024-04-18 15:32:18 +09:30
analysis_options.yaml Initial Commit 2024-01-21 18:17:48 +10:30
CHANGELOG.md Initial Commit 2024-01-21 18:17:48 +10:30
LICENSE Initial Commit 2024-01-21 18:17:48 +10:30
pubspec.yaml Add test 2024-01-22 09:21:10 +10:30
README.md Update README.md 2024-04-19 17:25:57 +09:30

Provides a Utility to construct and handle encryption for Commet's encrypted url previews.

This is still experimental and should not be used in a production project.

Getting started

This package is intended to be used in conjunction with a matrix client.

Usage

    final encryptedPreviewGetter = EncryptedUrlPreview(
        proxyServerUrl: Uri.parse("https://telescope.commet.chat"),
        // Server public key
        publicKeyPem: """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+sAi8PsT4QwjV/+xXK0
vwavZJEjkwJyFODGWkoo7qB87Y2yU6/C4csul6kQpxBFu9ID7mCavAlr93/c70Qm
sgX791W7oOSpvyeffJe5iluzaglZ/KWYo6Bc0QajKT8rLdI5vUljVMyx/nR9rIhY
PvSJhSFLC2ZyUhhTb/ZeLm0arEtGeyfo1V3nLGsJZJx12UK8E0FpKP14S7Wke9zM
e05PDCU/llEQpUgQOJI9Vnji71Fgocii76aSULhXalGjQIzBGKib5MIYlb0Zgf8k
wKkRg6IrNt5kjad4PoRKocxj3ylvuxEtMN582ni3lO4gi1uzzVvFtJBzrhNMjTPC
pQIDAQAB
-----END PUBLIC KEY-----""");

    var contentKey = urlGetter.getNextKey();
    var proxyUrl = encryptedPreviewGetter!.getProxyUrl(url, contentKey);

    var response = await client.request(
        matrix.RequestType.GET, "/media/v3/preview_url",
        query: {"url": proxyUrl.toString()});

    var title = response['og:title'] as String?;
    var imageUrl = response['og:image'] as String?;

    ImageProvider? image;

    if (imageUrl != null) {
      var mxcUri = Uri.parse(imageUrl);
      if (mxcUri.scheme == "mxc") {
        var response =
            await client.httpClient.get(mxcUri.getDownloadLink(client));

        var bytes = response.bodyBytes;
        var decrypted = encryptedPreviewGetter!.decryptContent(bytes, contentKey);

        image = Image.memory(decrypted).image;
      }
    }

    if (title != null)
      title = encryptedPreviewGetter!.decryptContentString(title, contentKey);

How does it work?

See ABOUT.md