Skip to content

Commit

Permalink
Merge pull request #13 from smswithoutborders/refactor/v0.1.0
Browse files Browse the repository at this point in the history
Refactor/v0.1.0
  • Loading branch information
PromiseFru authored Nov 29, 2024
2 parents 2e3eb43 + 2de6519 commit 8055661
Show file tree
Hide file tree
Showing 99 changed files with 24,252 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,26 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
57 changes: 57 additions & 0 deletions Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { app } = require("electron");
const fs = require("fs");
const path = require("path");

const logFilePath = path.join(app.getPath("logs"), "app.log");

const maxLogSize = 5 * 1024 * 1024;

const rotateLogs = () => {
if (
fs.existsSync(logFilePath) &&
fs.statSync(logFilePath).size >= maxLogSize
) {
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const archivePath = logFilePath.replace(".log", `-${timestamp}.log`);
fs.renameSync(logFilePath, archivePath);
}
};

rotateLogs();

const logFile = fs.createWriteStream(logFilePath, { flags: "a" });

const originalLog = console.log;
const originalError = console.error;

const logger = {
info: (...args) => {
const timestamp = new Date().toISOString();
const formattedArgs = args.map((arg) =>
typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg
);
const message = `[${timestamp}] [INFO] ${formattedArgs.join(" ")}\n`;
logFile.write(message);
originalLog(...formattedArgs);
},
warn: (...args) => {
const timestamp = new Date().toISOString();
const formattedArgs = args.map((arg) =>
typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg
);
const message = `[${timestamp}] [WARN] ${formattedArgs.join(" ")}\n`;
logFile.write(message);
originalLog(...formattedArgs);
},
error: (...args) => {
const timestamp = new Date().toISOString();
const formattedArgs = args.map((arg) =>
typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg
);
const message = `[${timestamp}] [ERROR] ${formattedArgs.join(" ")}\n`;
logFile.write(message);
originalError(...formattedArgs);
},
};

module.exports = logger;
167 changes: 166 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,166 @@
# relaysms-desktop
# RelaySMS - Desktop
--------

![relay-sms-screenshot](public/homepage.png)

Connecting the world, one SMS at a time.

## Contents

* [About](#about)
* [Encryption and Security](#encryption-and-security)
* [Token Storage and Vault](#token-storage-and-vault)
* [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Build Instructions](#build-instructions)
* [Building from Source](#building-from-source)
* [Contribution Guidelines](#contribution-guidelines)
* [Publishing Payload](#publishing-payload)
* [Platform Specific Publications](#platform-specific-publications)
* [Resources and Further Reading](#resources-and-further-reading)
* [Contact](#contact)

## <a name="about"></a> About

RelaySMS (also known as swob, short for SMSWithoutBorders) is a tool that lets you send secure online messages via SMS without needing an internet connection. RelaySMS allows you to stay connected even when offline by securely storing OAuth2 tokens for services like Gmail, Twitter, and Telegram in encrypted online Vaults.

**Gateway Clients**

RelaySMS utilizes gateway clients (identified by their MSISDN) to route SMS messages. You can manage these gateway clients within the app, allowing you to add new clients or switch between existing ones. To learn more about gateway clients and how they work, refer to the following resources:

* [Contributing: Gateway Client](https://docs.smswithoutborders.com/docs/contributing/gateway-client)
* [Gateway Clients Guide](https://docs.smswithoutborders.com/docs/Gateway%20Clients%20Guide/GatewayClientsGuide)
* [API V3: Get Gateway Clients](https://github.com/smswithoutborders/SMSWithoutBorders-Gateway-Server/blob/main/docs/api_v3.md#get-gateway-clients)

## <a name="encryption-and-security"></a> Encryption and Security

RelaySMS employs robust encryption methods to protect your data and ensure secure communication. For a detailed explanation of the cryptographic methods used in the vault, please refer to the [security documentation](https://github.com/smswithoutborders/SMSwithoutborders-BE/blob/main/docs/security.md#cryptographic-methods-used-in-the-vault).

* **AES (Advanced Encryption Standard):** Encrypts and decrypts data at rest in the vault.

* **Fernet Encryption:** Fernet encryption with a 32-byte key is used for encrypting and decrypting identity tokens used by the vault.

* **HMAC (Hash-based Message Authentication Code):** Generates and verifies HMACs for unique values in the vault.

* **Double Ratchet Algorithm:** The [Double Ratchet algorithm](https://github.com/smswithoutborders/py_double_ratchet_cli) is used to provide end-to-end encryption with perfect forward secrecy for secure messaging.

These cryptographic methods work together to provide a layered security approach, safeguarding your data and communications within the RelaySMS ecosystem.

## <a name="token-storage-and-vault"></a> Token Storage and Vault

RelaySMS utilizes a secure vault to store OAuth2 tokens for various services. These tokens allow you to access your accounts and send messages through these services without repeatedly entering your credentials.

**Here's how the vault works:**

1. **Token Encryption:** When you grant RelaySMS access to a platform (e.g., Gmail), the app receives an OAuth2 token. This token is immediately encrypted using AES-256 with a unique key.

2. **Vault Storage:** The encrypted token is then stored in the RelaySMS vault. The vault itself is protected by various security measures, including access controls and encryption. You can learn more about the vault specifications in the [documentation](https://github.com/smswithoutborders/SMSwithoutborders-BE/blob/main/docs/specifications.md).

3. **Token Retrieval:** When you need to send a message through a service/platform, RelaySMS retrieves the encrypted token from the vault. It then decrypts the token and uses it to authenticate with the platform (e.g Gmail).

This secure token storage and retrieval process ensures that your sensitive credentials are never stored in plain text and are protected from unauthorized access.

## <a name="getting-started"></a> Getting Started

### <a name="prerequisites"></a> Prerequisites

* Linux System
* An active modem
* Git
* Basic understanding of Electron JS and Node

### <a name="installation"></a> Installation

You can install RelaySMS directly from the following sources:

* **GitHub tags:** [release](https://github.com/smswithoutborders/RelaySMS-Desktop/releases)

## <a name="build-instructions"></a> Build Instructions

### <a name="building-from-source"></a> Building from Source

1. Clone the repository:
```
git clone https://github.com/smswithoutborders/RelaySMS-Desktop.git
```
2. Open the project in Visual Studio.

3. Install dependencies
```
yarn install
```
4. Bundle .deb files for linux
```
yarn electron:package:linux
```


## <a name="contribution-guidelines"></a> Contribution Guidelines
We welcome contributions from the community! Here's how you can get involved:
1. Clone the repository.
2. Create a new branch from the `dev` branch for your feature or bug fix.
3. Make your changes and commit them with descriptive messages.
4. Push your changes and submit a pull request to the `dev` branch

Please ensure your code follows our coding style guidelines and includes appropriate tests.

## <a name="publishing-payload"></a> Publishing Payload

RelaySMS uses a specific payload structure for publishing messages. Refer to the code snippet below for details on packing and unpacking the payload:
```python
import struct
import base64

platform_letter = b'g'
encrypted_content=b'...'
device_id=b'...'

payload = struct.pack("<i", len(encrypted_content)) + pl + encrypted_content + device_id
incoming_payload = base64.b64encode(payload)

# unpacking in Python
payload = base64.b64decode(incoming_payload)
len_enc_content = struct.unpack("<i", payload[:4])[0]
platform_letter = chr(payload[4])
encrypted_content = payload[5 : 5 + len_enc_content]
device_id = payload[5 + len_enc_content :]

# getting header from published messages
encrypted_payload = base64.b64decode(encrypted_content)
len_header = struct.unpack("<i", encrypted_payload[0:4])[0]
header = encrypted_payload[4: 4 + len_header]
content_ciphertext = encrypted_payload[4 + len_header:]
```

## <a name="platform-specific-publications"></a> Platform Specific Publications (Encrypted Content)

RelaySMS supports publishing encrypted content to various platforms with specific formatting:
```python3
""" Email (Gmail etc)
"""
# to:cc:bcc:subject:body

""" Messages (Telegram etc)
"""
# to:body

""" Text (X; Twitter etc)
"""
# body
```

## <a name="resources-and-further-reading"></a> Resources and Further Reading

* **Official Documentation:** [https://docs.smswithoutborders.com/](https://docs.smswithoutborders.com/)
* **Blog:** [https://blog.smswithoutborders.com/](https://blog.smswithoutborders.com/)
* **GitHub Repository (Backend):** [https://github.com/smswithoutborders/SMSwithoutborders-BE](https://github.com/smswithoutborders/SMSwithoutborders-BE)

## <a name="contact"></a> Contact

* **Website:** [https://relay.smswithoutborders.com/](https://relay.smswithoutborders.com/)
* **Email:** [[email protected]](mailto:[email protected])
* **X(Formerly Twitter):** [@RelaySMS](https://x.com/relaysms)

We appreciate your interest in RelaySMS. Don't forget star this repo :)

Loading

0 comments on commit 8055661

Please sign in to comment.