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

If someone was to restart Haven in 2025... #465

Open
tlaurion opened this issue Aug 26, 2023 · 15 comments
Open

If someone was to restart Haven in 2025... #465

tlaurion opened this issue Aug 26, 2023 · 15 comments

Comments

@tlaurion
Copy link

@n8fr8 what are the good choices Haven made? Which frameworks are still good and maintained?

I found those:

  • OpenCV: OpenCV is a library of programming functions mainly aimed at real-time computer vision. OpenCV can help you process images and videos from your phone's camera, and perform tasks such as face detection, object tracking, motion analysis, and more.
  • AudioRecord: AudioRecord is a class in Android that allows you to record audio from the microphone. AudioRecord can help you capture sound from your phone's environment, and perform tasks such as noise reduction, speech recognition, audio analysis, and more.
  • SensorManager: SensorManager is a class in Android that allows you to access the sensors on your phone. SensorManager can help you monitor the physical conditions of your phone, such as acceleration, orientation, temperature, light, and more.
  • NetCipher: NetCipher is a library that provides a simple way to use Tor network on Android. NetCipher can help you create a Tor hidden service for your app, and protect your data and identity from network surveillance and traffic analysis.

: How to use OpenCV
: How to use AudioRecord
: How to use SensorManager
: How to use NetCipher

@tlaurion
Copy link
Author

tlaurion commented Aug 26, 2023

If not, just update the frameworks and replace Signal integration to Matrix.

Here is what Bing would do (haven't validated):

If I dive into the code, I would propose the following plan for developers to replace Signal to Matrix Android SDK:

- First, I would fork the Haven repository on GitHub and clone it to my local machine. I would also install the required dependencies, such as Android Studio, Gradle, and NDK.
- Second, I would remove the Signal integration from the app by deleting the relevant classes, methods, and resources that use the Signal protocol or service. I would also remove any references to Signal from the app's manifest, build files, and settings. Some of the files that I would delete or modify are:

    - `SignalSender.java`: This is the class that handles sending alerts via Signal. I would delete this file and its references from other classes.
    - `SignalReceiver.java`: This is the class that handles receiving commands via Signal. I would delete this file and its references from other classes.
    - `SignalHelper.java`: This is the class that handles initializing and registering Signal. I would delete this file and its references from other classes.
    - `SignalService.java`: This is the class that runs as a background service to listen for Signal messages. I would delete this file and its references from other classes.
    - `SignalPreferencesFragment.java`: This is the class that displays the Signal settings in the app. I would delete this file and its references from other classes.
    - `strings.xml`: This is the file that contains the string resources for the app. I would remove any strings related to Signal, such as "Enable Signal", "Signal Phone Number", "Signal Verification Code", etc.
    - `build.gradle`: This is the file that defines the app's dependencies and configurations. I would remove any dependencies related to Signal, such as "org.whispersystems:signal-service-android:2.15.3".
    - `AndroidManifest.xml`: This is the file that declares the app's components and permissions. I would remove any components or permissions related to Signal, such as "org.thoughtcrime.securesms.service.RegistrationService", "org.thoughtcrime.securesms.permissions.SEND_MESSAGES", etc.

- Third, I would add the Matrix integration to the app by using the Matrix Android SDK, which provides a high-level interface to interact with the Matrix client-server API. I would create a new class that implements the MatrixService interface and handles the initialization, authentication, and synchronization of the Matrix client. I would also create a new class that implements the MatrixEventListener interface and handles the events related to messages, rooms, and commands. I would then register these classes with the Haven app and add them to the app's manifest and build files. Some of the files that I would create or modify are:

    - `MatrixSender.java`: This is the class that handles sending alerts via Matrix. I would create this file and use methods from the Matrix Android SDK to send encrypted messages, photos, videos, and audio clips to a specified room.
    - `MatrixReceiver.java`: This is the class that handles receiving commands via Matrix. I would create this file and use methods from the Matrix Android SDK to listen for messages in a specified room and execute commands accordingly.
    - `MatrixHelper.java`: This is the class that handles initializing and registering Matrix. I would create this file and use methods from the Matrix Android SDK to create a Matrix client instance, log in with a username and password, and sync with a server. `MatrixSender.java`: This is the class that handles sending alerts via Matrix. I would create this file and use methods from the Matrix Android SDK to send encrypted messages, photos, videos, and audio clips to a specified room.
    - `MatrixReceiver.java`: This is the class that handles receiving commands via Matrix. I would create this file and use methods from the Matrix Android SDK to listen for messages in a specified room and execute commands accordingly.
    - `MatrixHelper.java`: This is the class that handles initializing and registering Matrix. I would create this file and use methods from the Matrix Android SDK to create a Matrix client instance, log in with a username and password, and sync with a server.
    - `MatrixService.java`: This is the class that runs as a background service to listen for Matrix events. I would create this file and use methods from the Matrix Android SDK to register a MatrixEventListener and start a MatrixService.
    - `MatrixPreferencesFragment.java`: This is the class that displays the Matrix settings in the app. I would create this file and use methods from the Android Jetpack library to create a preference screen where the user can enter their Matrix username, password, and room name.
    - `strings.xml`: This is the file that contains the string resources for the app. I would add some strings related to Matrix, such as "Enable Matrix", "Matrix Username", "Matrix Password", "Matrix Room Name", etc.
    - `build.gradle`: This is the file that defines the app's dependencies and configurations. I would add a dependency related to Matrix, such as "org.matrix.android:matrix-android-sdk:1.1.6".
    - `AndroidManifest.xml`: This is the file that declares the app's components and permissions. I would add a component related to Matrix, such as "org.matrix.androidsdk.services.MatrixService".

- Fourth, I would modify the app's logic and UI to use the Matrix integration instead of the Signal integration. I would replace the Signal settings with Matrix settings, where the user can enter their Matrix username, password, and room name. I would also replace the Signal alerts with Matrix alerts, where the app can send encrypted messages, photos, videos, and audio clips to the Matrix room. I would also add a feature that allows the user to remotely access the sensor data and camera feed from the Matrix room by sending commands to the app.
- Fifth, I would test the app's functionality and performance on various devices and scenarios. I would also debug any errors or issues that might arise during the development process. I would also document the code and write unit tests for it.

This is how I would adapt the current codebase of Haven to use Matrix instead of Signal for encrypted alerts. If you have any other questions, please feel free to ask me. 😊

@harlo @n8fr8 : no more money from FPF? So sad. If I was an android devel....

Edit: no there could be some #460.

Contacting you

@lukeswitz
Copy link
Collaborator

Please fork this and apply your changes then report back. You’ll need to host your own server for Matrix so a solid understanding of networking is required.

@tlaurion
Copy link
Author

Please fork this and apply your changes then report back. You’ll need to host your own server for Matrix so a solid understanding of networking is required.

Why someone trying to replace signal with matrix would need to host his own server? This will require to use two accounts here, and to log one in into the phone and the room where to send the alarms. That's it.

@lukeswitz i won't start this project. I have not enough knowledge in android development unfortunately. I just try to draft what it would take for someone having the knowledge, having some funds, to entice that person to do it.

@lukeswitz
Copy link
Collaborator

lukeswitz commented Aug 31, 2023

I can’t speak for who takes this over; but money is not the issue or incentive. Sorry for the confusion. I’d love to see this done from scratch and I’d help make that happen. Thanks for the motivation

As for your own server, that was for signal as it exists now. Sure you can use existing matrix instances and just create a callback in python or even in native Android Java, or so AI thinks:

from nio import AsyncClient, RoomMessageText

async def message_callback(room, event):
    if isinstance(event, RoomMessageText):
        if event.body == "alarm":
            await client.room_send(
                room.room_id,
                "m.room.message",
                {"msgtype": "m.text", "body": "Alarm triggered!"},
            )

async def main():
    global client
    client = AsyncClient("https://your-matrix-server.org", "username")
    client.add_event_callback(message_callback, RoomMessageText)
    await client.login("password")
    await client.sync_forever()

if __name__ == "__main__":
    import asyncio

    asyncio.get_event_loop().run_until_complete(main())

# Java too, because AI right?

Add Dependencies
First, add the Matrix Android SDK to your build.gradle:

gradle
Copy code
dependencies {
    implementation 'org.matrix.android:matrix-android-sdk:0.9.29'
}
Initialize Matrix Client
Initialize the Matrix client in your MainActivity.java:

import org.matrix.androidsdk.HomeServerConnectionConfig;
import org.matrix.androidsdk.MXSession;
import org.matrix.androidsdk.RestClient;
import org.matrix.androidsdk.listeners.IMXEventListener;
import org.matrix.androidsdk.data.Room;
import org.matrix.androidsdk.rest.model.Event;

HomeServerConnectionConfig hsConfig = new HomeServerConnectionConfig.Builder()
        .withHomeServerUri(Uri.parse("https://your-matrix-server.org"))
        .build();

MXSession session = new MXSession.Builder(hsConfig, this)
        .build();

session.startEventStream(null);
Listen for Messages and Send Alarm
Implement an event listener to listen for messages in a room

IMXEventListener eventListener = new IMXEventListener() {
    @Override
    public void onLiveEventReceived(String fromRoomId, Event event) {
        if (Event.EVENT_TYPE_MESSAGE.equals(event.type)) {
            String messageBody = JsonUtils.toMessage(event.content.getAsJsonObject()).body;
            if ("alarm".equals(messageBody)) {
                Room room = session.getDataHandler().getRoom(fromRoomId);
                room.sendTextMessage("Alarm triggered!");
            }
        }
    }
};

Room room = session.getDataHandler().getRoom("your-room-id");
room.addEventListener(eventListener);

Security Considerations
Matrix: Make sure to enable end-to-end encryption in the room settings.
Authentication: This example doesn't cover authentication. You'll need to implement that based on your needs.
This is a simplified example to get you started. You'll need to add error handling, authentication, and other features for a complete implementation.

At least that’s what AI says 😆 none of this code works.

@fat-tire
Copy link
Collaborator

fat-tire commented Sep 2, 2023

Instead of matrix, maybe update w/the cDc's https://veilid.com/ ? I haven't looked into it too far (or built haven for a long, long time) but it might be worth considering.

Veilid presentation

@ttodua
Copy link

ttodua commented Sep 6, 2023

I don't fully understand, what is the main problem that prevents from integrating other platforms, beside Signal, Matrix, etc... lets say telegram. There could be an option. Not everyone and every user is equal. Whoever needs Signal/Matrix, they can use, but there are definitely part of user base, who need to use Telegram, so why not add it?
it is as easy as just sending POST data:

{
  'chat_id': chat_id, // channel id where user's bot is added as administrator (more at: https://stackoverflow.com/a/56546442/2377343 )
  'text': content,
  ...
}

to:

https://api.telegram.org/bot' +bot_key + '/sendMessage;

I understand there are more security concerns about it, but you can still add it as an option, but somewhat under "warning" message or whatever.

@lukeswitz
Copy link
Collaborator

I think @fat-tire is right. cDc Velid is a type of guardian project in and of itself. Their defcon talk this year gave me hope. With that came their code and an android app even. Lots to go off of for a reboot.

To that end, a rebuild could be quite easy and beneficial. The project was always an adaptation, a fresh start is easier than addressing each sensor problem, etc.

Granular settings overhaul, minimal UI and intuitive notifications; including the option for webhooks like @ttodua points out above. Definitely possible.

@ttodua
Copy link

ttodua commented Sep 6, 2023

but what is the current main problem with Haven, to continue its life? ( at least, before a reboot becomes a reality)

@lukeswitz
Copy link
Collaborator

but what is the current main problem with Haven, to continue its life? ( at least, before a reboot becomes a reality)

Seems an agreement on notifications, and a dev(s) with the time to take on said integration.

@bcode2
Copy link

bcode2 commented May 3, 2024

I have found this application quite interesting and would like to contribute.Are PR still accepted?. I have already forked and start upgrading things and fixing minor issues. @lukeswitz Telegram support will be the next feature I will try to include

@lazee486
Copy link

I've just discovered this so will be actively hunting forks :) for anyone else following this thread
https://github.com/caronc/apprise for notifications and alerts, will simplify instead of having to make each messaging service, or integrate web hooks so things like ntfy mattermost etc work, also it says local only recordings, I'd install syncthing from fdroid, could backup/ sync to a server at home etc with no app changes here, and a script there could alert on new files to any service you like.

The Linux mentality, kiss, let this app do the android and the recording stuff, let other apps handle the rest, keep this simple to maintain and active :)

@bcode2
Copy link

bcode2 commented May 11, 2024

hiii @lazee486 I was not aware of this library, thanks. I guess as you said we may use it to simplify the notification/alert system. I am still struggling now updating/replacing old/deprecated libraries and fixing some of those bugs listed.

@lazee486
Copy link

I'm more of a sys admin and just use self hosted apps, but if theres something I can help message me, I think this app seems like something worth keeping around, I'm thinking for just around my home :)

@lukeswitz
Copy link
Collaborator

@lukeswitz Telegram support will be the next feature I will try to include

I would avoid any app for evil maid attack mitigation that’s not using encryption. Risk appetites vary, not a chance I’d put my personal space on Telegram servers but that’s me.

“Telegram is a steaming hot mess of bad to no encryption” - someone much smarter than I in the cryptography community.

I have it working with Signal now that a linked phone number isn’t required. Ironing out the rest of the bugs vs. full rebuild is where I’m at now.

@tlaurion tlaurion changed the title If someone was to restart Haven in 2023... If someone was to restart Haven in 2025... May 17, 2024
@tlaurion
Copy link
Author

I would really vouch for matrix. You open and control a channel that is encrypted. Invite guardians if you will. Use it as a baby monitor as well. Tweak the app to detect pitch of your dogs fighting only and warn just on that.

We just need to stick with proper technologies that don't require necessarily a phone number to use. That's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants