A location-based secure messaging system that enables encrypted communication between military officers. Messages can only be decrypted when the receiver is physically present at a specific location.
- Location-Based Encryption: Messages are encrypted using AES with a key derived from password + message + GPS coordinates
- Real-time Communication: WebSocket-based real-time message delivery
- Interactive Map: Leaflet.js integration for location selection
- Geolocation Validation: GPS tolerance radius ensures receiver must be at target location
- Secure by Design: SHA-256 hashing + AES encryption
- React (with Vite)
- Tailwind CSS
- Leaflet.js for maps
- crypto-js for encryption
- Socket.io-client for real-time communication
- Node.js + Express
- Socket.io for WebSocket communication
- Built-in crypto module
- CORS enabled for cross-origin requests
cd military-secure-messagingcd backend
npm install
npm startServer will run on http://localhost:3001
cd frontend
npm install
npm run devFrontend will run on http://localhost:5173
Since geolocation API requires HTTPS on mobile devices when accessing from external networks:
cd frontend
npm run dev:httpsThis starts the development server with HTTPS enabled. Accept the self-signed certificate warning in your browser.
To access from mobile devices on your local network:
-
Find your local IP address:
- Linux/Mac:
ip addr showorifconfig - Windows:
ipconfig
- Linux/Mac:
-
Start services:
# Backend (in one terminal) cd backend npm start # Frontend with HTTPS (in another terminal) cd frontend npm run dev:https
-
Access from mobile:
- Frontend:
https://YOUR_LOCAL_IP:5173 - Accept certificate warning when prompted
- Frontend:
- Navigate to "Send Message" tab
- Enter your secure message
- Enter a shared password (known to both officers)
- Select target location on map or use "Get Current Location"
- Click "Send Encrypted Message"
- Navigate to "Receive Message" tab
- Click "Get Current Location" to obtain your GPS coordinates
- Select a message from the available messages list
- Enter the shared password
- Click "Decrypt Message" (only works if you're within 100m of target location)
Key = SHA-256(password + message + latitude + longitude)
Encrypted Message = AES(message, key)
- GPS tolerance radius: 100 meters
- Haversine formula for distance calculation
- High-accuracy geolocation required
- Default location set to Pune, India (18.5204°N, 73.8567°E)
- Messages are stored temporarily on server
- Automatically deleted after successful decryption
- Real-time updates via WebSocket
military-secure-messaging/
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── MapComponent.jsx # Leaflet map integration
│ │ │ ├── SenderInterface.jsx # Message creation UI
│ │ │ └── ReceiverInterface.jsx # Message decryption UI
│ │ ├── utils/
│ │ │ ├── crypto.js # Encryption/decryption utilities
│ │ │ └── geolocation.js # GPS utilities
│ │ ├── App.jsx # Main application
│ │ └── index.css # Tailwind styles
│ ├── package.json
│ └── tailwind.config.js
└── backend/
├── server.js # Express + Socket.io server
└── package.json
- Local Network Only: Designed for local military network deployment
- Temporary Storage: Messages are not persisted to disk
- Location Privacy: GPS coordinates are only used for encryption/validation
- Password Security: Shared passwords should follow military security protocols
- Start both backend and frontend servers
- Open two browser windows/tabs
- Use one as sender, one as receiver
- Test with different locations to verify location-based decryption
- "Only secure origins are allowed": Use HTTPS by running
npm run dev:https - Location access denied: Enable location permissions in your browser
- Location unavailable: Ensure GPS is enabled on mobile devices
- Mobile can't connect: Use your local IP address, not localhost
- CORS errors: Backend is configured to allow all origins for development
- Configure CORS settings for production environment
- Use HTTPS in production
- Consider adding user authentication
- Implement proper logging and monitoring
- Add rate limiting for API endpoints
This project is intended for military/defense applications and should be used in accordance with relevant security protocols.# Military-Encrypted-Messaging