Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡²πŸ‡¦ SecureVPN - Open Source VPN for Morocco

License: MIT Go Version Made in Morocco Security Legal Use Only

A secure, high-performance VPN system written in Go with modern cryptography and clean architecture.

** Perfect for Moroccan TPE/PME (Small & Medium Businesses)**


πŸ‡²πŸ‡¦ Pourquoi ce VPN? / Why This VPN?

Pour les Entreprises Marocaines / For Moroccan Businesses

Ce VPN open-source est idΓ©al pour:

  • TPE/PME - Petites et moyennes entreprises
  • SΓ©curitΓ© - Protection des donnΓ©es sensibles
  • Γ‰conomique - Solution gratuite et open-source
  • TΓ©lΓ©travail - AccΓ¨s sΓ©curisΓ© pour employΓ©s distants
  • πŸ‡²πŸ‡¦ Local - DΓ©veloppΓ© avec les besoins marocains en tΓͺte

This open-source VPN is perfect for:

  • Small & Medium Businesses - TPE/PME
  • Security - Protect sensitive business data
  • Cost-Effective - Free and open-source solution
  • Remote Work - Secure access for remote employees
  • πŸ‡²πŸ‡¦ Local - Built with Moroccan needs in mind

πŸŽ“ Use Cases / Cas d'Usage

  • βœ… Personal VPN Usage - Protection personnelle
  • βœ… Corporate Deployments - DΓ©ploiements d'entreprise
  • βœ… Educational Purposes - Objectifs Γ©ducatifs
  • βœ… Learning Go & Cryptography - Apprendre Go et la cryptographie
  • βœ… Building Custom VPN Solutions - Solutions VPN personnalisΓ©es
  • βœ… Open-Source Contributions - Contributions open-source

⚠️ SECURITY & LEGAL WARNING

🚨 IMPORTANT: READ BEFORE USE 🚨

πŸ›‘οΈ This Project is Designed For:

βœ… Legitimate Use Only:

  • Secure business communications
  • Private corporate networks
  • Educational and research purposes
  • Protecting sensitive data on untrusted networks
  • Secure remote access to private resources
  • Professional VPN deployments

🚫 STRICTLY PROHIBITED:

❌ DO NOT USE FOR:

  • Illegal activities of any kind
  • Bypassing legal restrictions or regulations
  • Unauthorized access to networks or systems
  • Circumventing content protection or copyright laws
  • Malicious traffic routing or attacks
  • Any activity that violates local, national, or international laws

βš–οΈ Legal Compliance:

YOU ARE RESPONSIBLE FOR:

  • βœ… Compliance with all applicable laws in Morocco and your jurisdiction
  • βœ… Obtaining necessary permissions and authorizations
  • βœ… Respecting intellectual property rights
  • βœ… Following your organization's security policies
  • βœ… Ensuring legitimate use at all times

πŸ‡²πŸ‡¦ Morocco Specific:

  • VPN usage is legal in Morocco for legitimate purposes
  • Users must comply with Moroccan telecommunications regulations
  • Businesses should consult with legal counsel for compliance

πŸ”’ Security Responsibilities:

AS A USER, YOU MUST:

  • πŸ”‘ Keep private keys secure and never share them
  • πŸ” Use strong passwords and secure key storage
  • πŸ“Š Monitor logs for suspicious activity
  • πŸ”„ Keep software updated with security patches
  • πŸ›‘οΈ Follow security best practices
  • πŸ“‹ Implement proper access controls

⚠️ Disclaimer:

THE AUTHORS AND CONTRIBUTORS:

  • Are NOT responsible for misuse of this software
  • Do NOT endorse or support illegal activities
  • Provide this software "AS IS" without warranties
  • Are NOT liable for any damages or legal consequences
  • Strongly condemn any misuse of this technology

BY USING THIS SOFTWARE, YOU AGREE:

  • To use it only for lawful purposes
  • To comply with all applicable laws and regulations
  • To take full responsibility for your use
  • That the authors are not liable for your actions

πŸ“ž Report Abuse:

If you discover misuse of this software, please report it to:

  • GitHub Issues: Report Here
  • Local authorities if illegal activity is suspected

πŸ”΄ REMEMBER: With great power comes great responsibility. Use this tool ethically and legally. πŸ”΄


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client    │◄──── Encrypted ───►│   Server    β”‚
β”‚  (TUN Dev)  β”‚      Tunnel        β”‚  (TUN Dev)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚                                    β”‚
      β–Ό                                    β–Ό
  Local Apps                         Internet Gateway

Components

  • Server: VPN server handling multiple concurrent clients
  • Client: VPN client establishing secure tunnels
  • Crypto: X25519 key exchange + ChaCha20-Poly1305 encryption
  • Tunnel: TUN device management and packet handling
  • Network: Routing, NAT traversal, DNS forwarding

πŸ” Security Features

  • Mutual Authentication: Public/private key pairs (X25519)
  • Modern Encryption: ChaCha20-Poly1305 AEAD cipher
  • Key Exchange: Noise Protocol Framework (Noise_XX pattern)
  • Replay Protection: Nonce-based anti-replay mechanism
  • Perfect Forward Secrecy: Ephemeral key exchange per session

πŸš€ Quick Start

Prerequisites

  • Go 1.21 or higher
  • Linux/macOS (TUN device support)
  • Root/sudo privileges (for network interface management)

Installation

# Clone the repository
git clone https://github.com/lahcenassmira/open-source-vpn.git
cd open-source-vpn

# Build server and client
make build

# Or build manually
go build -o bin/vpn-server ./cmd/server
go build -o bin/vpn-client ./cmd/client

Generate Keys

# Generate server keys
./bin/vpn-server keygen --output server-keys.json

# Generate client keys
./bin/vpn-client keygen --output client-keys.json

Start Server

# Edit server configuration
cp configs/server.example.yaml configs/server.yaml
# Add client public keys to server.yaml

# Start server (requires root)
sudo ./bin/vpn-server start --config configs/server.yaml

Connect Client

# Edit client configuration
cp configs/client.example.yaml configs/client.yaml
# Add server public key and endpoint to client.yaml

# Connect (requires root)
sudo ./bin/vpn-client connect --config configs/client.yaml

πŸ“ Project Structure

open-source-vpn/
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ server/          # Server CLI entry point
β”‚   └── client/          # Client CLI entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ crypto/          # Cryptography and key exchange
β”‚   β”œβ”€β”€ tunnel/          # TUN device management
β”‚   β”œβ”€β”€ network/         # Routing and packet handling
β”‚   β”œβ”€β”€ protocol/        # VPN protocol implementation
β”‚   └── config/          # Configuration management
β”œβ”€β”€ pkg/
β”‚   β”œβ”€β”€ logger/          # Structured logging
β”‚   └── metrics/         # Performance metrics
β”œβ”€β”€ configs/             # Example configurations
β”œβ”€β”€ docker/              # Docker deployment files
β”œβ”€β”€ scripts/             # Utility scripts
└── docs/                # Additional documentation

βš™οΈ Configuration

Server Configuration (YAML)

server:
  listen_address: "0.0.0.0:51820"
  protocol: "udp"
  
network:
  interface: "tun0"
  address: "10.8.0.1/24"
  mtu: 1420
  
crypto:
  private_key: "server_private_key_base64"
  
clients:
  - public_key: "client1_public_key_base64"
    allowed_ips: ["10.8.0.2/32"]
  - public_key: "client2_public_key_base64"
    allowed_ips: ["10.8.0.3/32"]
    
routing:
  forward_all_traffic: false
  allowed_networks: ["10.8.0.0/24"]
  
dns:
  enabled: true
  servers: ["8.8.8.8", "8.8.4.4"]
  
logging:
  level: "info"
  format: "json"
  output: "/var/log/vpn-server.log"

Client Configuration (YAML)

client:
  server_address: "vpn.example.com:51820"
  protocol: "udp"
  
network:
  interface: "tun0"
  address: "10.8.0.2/24"
  mtu: 1420
  
crypto:
  private_key: "client_private_key_base64"
  server_public_key: "server_public_key_base64"
  
routing:
  default_route: false
  routes: ["10.8.0.0/24"]
  
dns:
  enabled: true
  servers: ["10.8.0.1"]
  
logging:
  level: "info"
  format: "json"

🐳 Docker Deployment

# Build Docker image
docker build -t open-source-vpn-server -f docker/Dockerfile .

# Run server container
docker run -d \
  --name vpn-server \
  --cap-add=NET_ADMIN \
  --device=/dev/net/tun \
  -p 51820:51820/udp \
  -v $(pwd)/configs:/etc/vpn \
  open-source-vpn-server

πŸ“Š Monitoring & Logging

View Connection Status

# Server status
./bin/vpn-server status

# Client status
./bin/vpn-client status

Logs

Structured JSON logs include:

  • Connection events (connect/disconnect)
  • Data transfer statistics
  • Latency measurements
  • Error tracking

Example log entry:

{
  "timestamp": "2026-05-20T10:30:45Z",
  "level": "info",
  "component": "server",
  "event": "client_connected",
  "client_id": "abc123",
  "client_ip": "10.8.0.2",
  "remote_addr": "203.0.113.45:54321"
}

πŸ”§ CLI Commands

Server Commands

vpn-server start --config <path>     # Start VPN server
vpn-server stop                      # Stop VPN server
vpn-server status                    # Show server status
vpn-server keygen --output <path>    # Generate key pair
vpn-server logs --follow             # Tail logs

Client Commands

vpn-client connect --config <path>   # Connect to VPN
vpn-client disconnect                # Disconnect from VPN
vpn-client status                    # Show connection status
vpn-client keygen --output <path>    # Generate key pair
vpn-client logs --follow             # Tail logs

🎯 Performance

  • Latency: < 5ms overhead on local network
  • Throughput: 1+ Gbps on modern hardware
  • Concurrent Clients: 1000+ per server
  • Memory: ~50MB base + ~1MB per client
  • CPU: Efficient goroutine-based I/O

πŸ§ͺ Testing

# Run all tests
make test

# Run with coverage
make test-coverage

# Run benchmarks
make benchmark

# Integration tests
make test-integration

πŸ›‘οΈ Security Considerations

  1. Key Management: Store private keys securely, never commit to version control
  2. Firewall: Configure firewall rules to allow only VPN traffic
  3. Updates: Keep dependencies updated for security patches
  4. Monitoring: Enable logging and monitor for suspicious activity
  5. Access Control: Use allowed_ips to restrict client access

πŸ“š Protocol Details

Handshake (Noise_XX Pattern)

  1. Client β†’ Server: Ephemeral public key
  2. Server β†’ Client: Ephemeral public key + static public key (encrypted)
  3. Client β†’ Server: Static public key (encrypted) + payload

Packet Format

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Type (1) β”‚ ID (4) β”‚ Nonce (12)β”‚ Payload (N) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Type: Packet type (handshake/data/keepalive)
  • ID: Connection identifier
  • Nonce: Unique nonce for AEAD
  • Payload: Encrypted data + authentication tag

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

πŸ“„ License

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

⚠️ Disclaimer

This VPN system is designed for legitimate privacy and security use cases. Users are responsible for compliance with local laws and regulations. The authors are not responsible for misuse of this software.

πŸ™ Acknowledgments

  • Inspired by WireGuard's design principles
  • Uses Noise Protocol Framework for key exchange
  • Built with Go's excellent networking libraries

πŸ“ž Support


Built with passion for secure and open internet.

About

A secure, high-performance VPN system written in Go with modern cryptography and clean architecture.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages