Skip to content

nnkhanhduy/ChatNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ ChatNet

Secure Peer-to-Peer Chat Application with Advanced Encryption

React Native TypeScript Node License

Features β€’ Architecture β€’ Installation β€’ Usage β€’ Security


πŸ“– Introduction

ChatNet is a modern, cross-platform peer-to-peer chat application built with React Native. It enables secure, real-time communication over local networks (LAN/WiFi) with enterprise-grade encryption and authentication mechanisms.

Unlike traditional chat applications that rely on centralized servers, ChatNet establishes direct TCP connections between devices, ensuring privacy, low latency, and complete control over your data.

Why ChatNet?

  • πŸ”’ Privacy-First: No servers, no data collection, no third parties
  • πŸš€ Real-Time: Direct P2P connections with minimal latency
  • πŸ›‘οΈ Military-Grade Encryption: Multiple encryption algorithms (AES-256, RSA, DES, etc.)
  • πŸ” Cryptographic Authentication: ECDSA digital signatures prevent message tampering
  • πŸ“± Cross-Platform: Works on Android and iOS
  • 🎨 Rich Media: Send text, images, and voice messages
  • πŸ”‘ Secure Key Exchange: Automated Diffie-Hellman key negotiation

✨ Key Features

πŸ” Multiple Encryption Modes

Algorithm Type Key Size Use Case
AES-256 Symmetric 256-bit Production-ready, high security
RSA Hybrid Asymmetric + Symmetric 2048-bit RSA + 256-bit AES Maximum security with perfect forward secrecy
Triple DES Symmetric 168-bit Legacy compatibility
Playfair Classical Variable Educational purposes
Caesar Classical 1-25 shift Educational purposes

πŸ›‘οΈ Advanced Security Features

  • ECDSA Digital Signatures: Verify message authenticity and integrity
  • ECDH Key Exchange: Secure automated key negotiation over insecure channels
  • Perfect Forward Secrecy: Each message uses a unique encryption key (RSA mode)
  • Anti-Tampering: Automatic detection of modified messages

πŸ“± Rich Communication

  • πŸ’¬ Text Messaging: Encrypted real-time chat
  • πŸ–ΌοΈ Image Sharing: Send photos with automatic compression
  • 🎀 Voice Messages: Record and send audio clips
  • ⏱️ Timestamps: Track message history
  • πŸ“Š Delivery Status: Real-time connection monitoring

πŸ—οΈ Architecture Overview

System Architecture

System Architecture

Message Flow (Full Security Mode)

Message Flow

Technology Stack

Technology Stack


πŸ“‹ Prerequisites

Development Environment

Requirement Version Purpose
Node.js β‰₯ 20.x JavaScript runtime
npm or yarn Latest Package manager
Git Latest Version control

Android Development

Tool Version Notes
Android Studio Godzilla (2024)+ IDE
JDK 17 or 21 Java Development Kit
Android SDK API 35 Build Tools 35.0.0
Gradle 8.10.2 Build system
Android Gradle Plugin 8.7.3 Build plugin

Minimum Device Requirements:

  • Android 5.0+ (API 21+)
  • 100MB free storage
  • WiFi or LAN connectivity

iOS Development (macOS only)

Tool Version Notes
macOS Ventura (13.0)+ Operating system
Xcode 14.0+ IDE
CocoaPods Latest Dependency manager
iOS Deployment Target 13.4+ Minimum iOS version

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/nnkhanhduy/ChatNet.git
cd ChatNet

2. Install Dependencies

# Using npm
npm install

# Or using yarn
yarn install

3. iOS Setup (macOS only)

cd ios
pod install
cd ..

4. Android Configuration

Ensure android/local.properties exists with your SDK path:

sdk.dir=C:\\Users\\YourUsername\\AppData\\Local\\Android\\sdk

Note: Replace YourUsername with your actual Windows username.


πŸ“± Running the Application

Start Metro Bundler

In your terminal, start the Metro development server:

npm start

# Or with network access for physical devices
npm run start:network

Keep this terminal running throughout development.

Run on Android

Open a new terminal and execute:

# Run on connected device or emulator
npm run android

# Or using React Native CLI
npx react-native run-android

Troubleshooting:

  • Enable USB Debugging on your Android device
  • Check connected devices: adb devices
  • For multiple devices: adb -s <device_id> install app.apk

Run on iOS (macOS only)

# Default simulator
npm run ios

# Specific simulator
npx react-native run-ios --simulator="iPhone 15 Pro"

# Physical device (requires Apple Developer Account)
npx react-native run-ios --device

πŸ“¦ Building for Production

Android APK

Debug Build

# Using npm script
npm run build:apk

# Or manually
cd android
./gradlew assembleDebug
cd ..

# Output: android/app/build/outputs/apk/debug/app-debug.apk

Release Build (Signed)

npm run build:release

# Output: android/app/build/outputs/apk/release/app-release.apk

Configure Signing in android/app/build.gradle:

signingConfigs {
    release {
        storeFile file('my-release-key.keystore')
        storePassword 'your-store-password'
        keyAlias 'my-key-alias'
        keyPassword 'your-key-password'
    }
}

Install APK on Device

# Debug APK
npm run install:apk

# Release APK
npm run install:release

# Manual installation
adb install -r path/to/app.apk

πŸ’‘ Usage

Initial Setup

  1. Launch the app on both devices
  2. Ensure both devices are on the same WiFi/LAN network
  3. Tap the βš™οΈ Settings icon in the top-right corner

Configuration

Device A:

  1. Note your IP address (e.g., 192.168.1.100)
  2. Enter Device B's IP in "🌐 Recipient IP"
  3. Choose encryption mode (recommended: AES or RSA)
  4. Set encryption key (for AES/DES) or exchange RSA keys

Device B:

  1. Note your IP address (e.g., 192.168.1.101)
  2. Enter Device A's IP in "🌐 Recipient IP"
  3. Use the same encryption settings as Device A

Encryption Modes Setup

AES/DES Mode (Shared Key)

Device A: Key = "my_secret_key_123"
Device B: Key = "my_secret_key_123" (must match)

RSA Hybrid Mode (Public Key Exchange)

Device A:
1. Tap "Generate RSA Keys"
2. Copy your public key
3. Share with Device B (via QR code, text, etc.)
4. Paste Device B's public key in settings

Device B:
1. Tap "Generate RSA Keys"
2. Copy your public key
3. Share with Device A
4. Paste Device A's public key in settings

ECDH Key Exchange (Automated)

Device A:
1. Tap "Generate ECDH Keys"
2. Tap "Start Key Exchange"
3. Wait for Device B to respond

Device B:
1. Tap "Generate ECDH Keys"
2. Receive key exchange request
3. Shared key automatically configured βœ“

Sending Messages

  • Text: Type in the input field and tap send βœ‰οΈ
  • Images: Tap πŸ“· icon and select from gallery
  • Voice: Tap and hold 🎀 to record, release to send

Example Scenario

Device A (192.168.1.100):
β”œβ”€ Recipient IP: 192.168.1.101
β”œβ”€ Encryption: AES
β”œβ”€ Key: "secure_key_2024"
└─ Message: "Hello, World!"
    └─ Encrypted: "U2FsdGVkX1+..."
        └─ Sent via TCP

Device B (192.168.1.101):
β”œβ”€ Recipient IP: 192.168.1.100
β”œβ”€ Encryption: AES
β”œβ”€ Key: "secure_key_2024" (matches Device A)
└─ Received: "U2FsdGVkX1+..."
    └─ Decrypted: "Hello, World!" βœ“

πŸ”’ Security Features

ChatNet implements multiple layers of security. For detailed cryptographic specifications, see SECURITY.md.

Encryption Algorithms

1. AES-256 (Recommended)

  • Type: Symmetric block cipher
  • Key Size: 256 bits
  • Mode: CBC with PKCS7 padding
  • Use Case: Production environments

2. RSA Hybrid Encryption

  • Type: Asymmetric + Symmetric
  • RSA Key Size: 2048 bits
  • AES Key Size: 256 bits
  • Features: Perfect forward secrecy, unlimited message length
  • Use Case: Maximum security requirements

3. Triple DES

  • Type: Symmetric block cipher
  • Key Size: 168 bits (3 Γ— 56-bit keys)
  • Mode: CBC
  • Use Case: Legacy system compatibility

4. Playfair Cipher

  • Type: Classical digraph substitution
  • Use Case: Educational purposes

5. Caesar Cipher

  • Type: Classical substitution
  • Shift: 1-25 positions
  • Use Case: Educational purposes

Authentication & Key Exchange

ECDSA Digital Signatures

  • Curve: secp256k1 (Bitcoin curve)
  • Hash: SHA-256
  • Purpose: Message authentication and integrity verification

ECDH Key Exchange

  • Curve: secp256k1
  • Purpose: Secure shared secret generation
  • Feature: Automated key negotiation

Security Best Practices

Important

  • Always use AES-256 or RSA Hybrid for production
  • Enable Digital Signatures to prevent message tampering
  • Use ECDH Key Exchange instead of manual key sharing
  • Never share private keys or encryption keys over insecure channels
  • Regularly regenerate RSA key pairs

Warning

Caesar and Playfair ciphers are NOT secure for real-world use. They are included for educational purposes only.


πŸ“ Project Structure

ChatNet/
β”œβ”€β”€ android/                    # Android native code
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ build.gradle       # App-level Gradle config
β”‚   β”‚   └── src/               # Android source files
β”‚   └── build.gradle           # Project-level Gradle config
β”‚
β”œβ”€β”€ ios/                        # iOS native code
β”‚   β”œβ”€β”€ ChatNET/               # iOS app files
β”‚   β”œβ”€β”€ ChatNET.xcodeproj/     # Xcode project
β”‚   └── Podfile                # CocoaPods dependencies
β”‚
β”œβ”€β”€ src/                        # Application source code
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ ChatInput.tsx      # Message input component
β”‚   β”‚   β”œβ”€β”€ ChatMessage.tsx    # Message display component
β”‚   β”‚   β”œβ”€β”€ Header.tsx         # App header
β”‚   β”‚   └── SettingsModal.tsx  # Settings & configuration
β”‚   β”‚
β”‚   β”œβ”€β”€ hooks/                 # Custom React hooks
β”‚   β”‚   └── useTcpSocket.ts    # TCP socket management
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/                 # Utility functions
β”‚   β”‚   β”œβ”€β”€ aesCipher.ts       # AES-256 encryption
β”‚   β”‚   β”œβ”€β”€ caesarCipher.ts    # Caesar cipher
β”‚   β”‚   β”œβ”€β”€ desCipher.ts       # Triple DES encryption
β”‚   β”‚   β”œβ”€β”€ playfairCipher.ts  # Playfair cipher
β”‚   β”‚   β”œβ”€β”€ rsaCipher.ts       # RSA hybrid encryption
β”‚   β”‚   β”œβ”€β”€ security.ts        # ECDSA & ECDH implementation
β”‚   β”‚   β”œβ”€β”€ cryptoPolyfill.ts  # Crypto polyfills
β”‚   β”‚   └── responsive.ts      # Responsive scaling utilities
β”‚   β”‚
β”‚   β”œβ”€β”€ types.ts               # TypeScript type definitions
β”‚   └── constants.ts           # App constants
β”‚
β”œβ”€β”€ assets/                     # Static assets
β”‚   └── Logo.jpg               # App logo
β”‚
β”œβ”€β”€ App.tsx                     # Root component
β”œβ”€β”€ index.js                    # App entry point
β”œβ”€β”€ package.json                # Dependencies & scripts
β”œβ”€β”€ tsconfig.json               # TypeScript configuration
β”œβ”€β”€ babel.config.js             # Babel configuration
β”œβ”€β”€ metro.config.js             # Metro bundler config
β”œβ”€β”€ README.md                   # This file
└── SECURITY.md                 # Security documentation

🀝 Contributing

We welcome contributions from the community! Here's how you can help:

Reporting Bugs

  1. Check if the issue already exists in Issues
  2. Create a new issue with:
    • Clear title and description
    • Steps to reproduce
    • Expected vs actual behavior
    • Screenshots (if applicable)
    • Device info (OS, version, etc.)

Suggesting Features

  1. Open an issue with the enhancement label
  2. Describe the feature and its use case
  3. Explain why it would benefit users

Pull Requests

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Test thoroughly on both Android and iOS
  5. Commit with clear messages: git commit -m 'Add amazing feature'
  6. Push to your fork: git push origin feature/amazing-feature
  7. Open a Pull Request

Development Guidelines

  • Follow existing code style (TypeScript, ESLint)
  • Add comments for complex logic
  • Update documentation for new features
  • Ensure backward compatibility
  • Test on multiple devices

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 ChatNet Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

πŸ™ Acknowledgments

ChatNet is built with amazing open-source technologies:

Special thanks to all contributors and the open-source community.


⭐ If you find ChatNet useful, please star this repository! ⭐

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •