qssh 0.0.1-alpha

Experimental quantum-safe SSH using post-quantum crypto. Research project - NOT for production. See LIMITATIONS.md
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# QSSH - Quantum Secure Shell

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE-MIT)
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE-APACHE)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-blue.svg)](https://www.rust-lang.org)

Quantum-resistant SSH replacement using post-quantum cryptography. Your encrypted connections remain secure even against quantum computers.

## Why QSSH?

**The Timeline Problem**: IBM's quantum roadmap shows 100,000+ qubit systems by 2033. China claims quantum supremacy breakthroughs yearly. Meanwhile, your SSH traffic is being harvested today for retroactive decryption when RSA/ECDSA fall.

**Who Needs This Now**:
- Financial institutions with 10+ year data retention requirements
- Healthcare systems bound by HIPAA's 6-year minimum
- Government contractors already under NIST mandate for PQC migration
- Blockchain validators protecting long-lived keys
- Anyone SSH'ing to critical infrastructure

**For Everyone Else**: You're probably fine with OpenSSH for now. But if you're curious about post-quantum crypto or want to experiment with QKD hardware, QSSH is here as an open-source playground. We're not claiming to replace OpenSSH - we're offering an alternative for specific threat models.

## OSI Layer Positioning

QSSH operates across multiple OSI layers, just like SSH:

- **Layer 7 (Application)**: Shell access, file transfer (SFTP), Git, tunneled applications
- **Layer 6 (Presentation)**: Terminal emulation, X11 forwarding, encoding
- **Layer 5 (Session)**: Connection management, channels, multiplexing
- **Layer 4 (Transport)**: Uses TCP port 42 (configurable)

QSSH is a **session-layer protocol** that provides secure remote access and can tunnel any application protocol - from X11 and databases to blockchain RPC - all with post-quantum security.

## Quick Start

```bash
# Install
cargo install qssh

# Generate quantum-safe keys
qssh-keygen

# Connect (just like SSH)
qssh user@server
```

That's it! You're now quantum-safe with zero configuration.

## Table of Contents

- [Features]#features
- [Installation]#installation
- [Basic Usage]#basic-usage
- [Architecture]#architecture
- [Security Model]#security-model
- [Advanced Configuration]#advanced-configuration
- [P2P Mode]#p2p-mode
- [Testing]#testing
- [Development]#development
- [Performance]#performance
- [Contributing]#contributing

## OpenSSH Feature Status

**Current: v0.0.1-alpha - Early Experimental Implementation**

### ✅ Implemented (Phase 1 - Core)
- [x] Basic SSH connection and authentication
- [x] Interactive shell sessions with PTY support
- [x] Command execution (`qssh user@host -c "command"`)
- [x] Post-quantum key exchange (Falcon-512, SPHINCS+, Kyber)
- [x] **SFTP subsystem** (file transfer protocol)
- [x] **Port forwarding** (-L local, -R remote, -D dynamic/SOCKS)
- [x] **Config file parsing** (~/.qssh/config compatible with SSH format)
- [x] Public key authentication
- [x] Key generation (qssh-keygen)

### ✅ Implemented (Phase 2 - Extended)
- [x] **Password authentication** (with qssh-passwd utility)
- [x] **SSH agent support** (qssh-agent and qssh-add utilities)
- [x] **X11 forwarding** (-X for untrusted, -Y for trusted)

### ✅ Implemented (Phase 2 - Extended Continued)
- [x] **Connection multiplexing** (ControlMaster/ControlPath support)
- [x] **ProxyJump support** (multi-hop connections through jump hosts)

### ✅ Implemented (Phase 3 - Security)
- [x] **Known hosts management** (host key verification with TOFU)

### ✅ Implemented (Phase 3 - Advanced)
- [x] **Compression** (zlib, zstd, lz4 with adaptive compression)
- [x] **Session resumption** (fast reconnection for mobile networks)

### ⏳ Not Yet Implemented
- [ ] **Certificate-based authentication** (Planned for v2.0)
- [ ] **GSSAPI/Kerberos authentication** (Returns 'not implemented' errors)
- [ ] **SSH Agent Forwarding** (Security review needed)

## Known Limitations

### Production Status
- **Experimental Software** - v1.0.0 is for research and testing
- **Not audited** - No formal security audit has been performed
- **Limited testing** - Primarily tested on Linux/macOS

### Feature Limitations
- **GSSAPI/Kerberos** - Returns 'not implemented' errors
- **Multiplexing** - Returns proper error instead of creating channels
- **No SSH Agent Forwarding** - Keys must be present on each server
- **Certificate auth** - Not yet integrated

### Security Notes
- All placeholder implementations have been replaced with proper errors
- No dummy data or zero-filled buffers returned
- Debug output uses proper logging framework
- **Performance** - Falcon-512 signatures are slower than RSA/Ed25519
- **Compatibility** - Not a drop-in replacement for all OpenSSH use cases
- **Code Quality** - Needs security audit before production use

## Features

### Core Security
- **Post-Quantum Algorithms**: Falcon-512 (default), SPHINCS+, custom providers
- **Quantum Integration**: QKD networks, QRNG devices, hardware security modules
- **Forward Secrecy**: Double Ratchet protocol with automatic key rotation
- **Zero-Trust**: No default trust, all peers authenticated

### Compatibility
- **Drop-in Replacement**: Works like SSH, same commands
- **Cross-Platform**: Linux, macOS, Windows
- **Standard Protocols**: SSH-compatible authorized_keys format

### Advanced Features
- **P2P Mode**: Direct peer connections without central servers
- **Modular Crypto**: Plug in any post-quantum algorithm
- **Blockchain Integration**: QuantumHarmony validator discovery
- **Hardware Support**: TPM, HSM, PKCS#11 tokens

## Installation

### From Source
```bash
git clone https://github.com/QuantumVerseProtocols/qssh
cd qssh
cargo build --release
sudo cp target/release/qssh* /usr/local/bin/
```

### Package Managers
```bash
# Arch Linux
yay -S qssh

# macOS
brew install qssh

# Debian/Ubuntu
sudo apt install qssh
```

## Basic Usage

### Configuration File

QSSH supports configuration files similar to OpenSSH. Place your config at `~/.qssh/config`:

```ssh-config
# Example ~/.qssh/config
Host myserver
    Hostname server.example.com
    User myuser
    Port 22222
    PqAlgorithm falcon
    LocalForward 8080:localhost:80

Host *.internal
    User admin
    PqAlgorithm kyber1024
```

Then connect simply with:
```bash
qssh myserver
```

See [example.qssh.config](example.qssh.config) for a complete configuration example.

## Basic Commands

### Generate Keys
```bash
# Default (Falcon-512)
qssh-keygen

# SPHINCS+ for maximum security
qssh-keygen -t sphincs+

# Custom output location
qssh-keygen -f ~/.qssh/id_production
```

### Password Management
```bash
# Set password for user (server-side)
sudo qssh-passwd username

# Verify password
qssh-passwd -c username
```

### Connect to Server
```bash
# Standard connection (with public key)
qssh user@quantum.example.com

# Password authentication
qssh -P user@quantum.example.com

# Custom port
qssh user@quantum.example.com:42

# Execute command
qssh user@server "df -h"

# Interactive shell with verbosity
qssh -v user@server
```

### File Transfer
```bash
# Copy local to remote
qscp report.pdf user@server:/home/user/

# Copy remote to local
qscp user@server:/data/results.csv ./

# Recursive copy
qscp -r ./project user@server:/deploy/
```

### Server Setup
```bash
# Start daemon (default port 42)
qsshd

# Custom configuration
qsshd --listen :22 --max-connections 1000

# With quantum devices
qsshd --qkd qkd://alice.local --qrng /dev/qrandom
```

## Architecture

### Quantum Pipeline
```
┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│ Quantum Devices │     │   QKD Network   │     │  QRNG Sources   │
├─────────────────┤     ├─────────────────┤     ├─────────────────┤
│ • Photon pairs  │     │ • Alice node    │     │ • Quantum decay │
│ • Entangled     │────▶│ • Bob node      │     │ • Shot noise    │
│ • Single photon │     │ • ETSI API      │     │ • Vacuum noise  │
└────────┬────────┘     └────────┬────────┘     └────────┬────────┘
         │                       │                         │
         └───────────────────────┴─────────────────────────┘
                    ┌────────────▼────────────┐
                    │      QSSH Protocol      │
                    ├─────────────────────────┤
                    │ • Falcon-512 (default)  │
                    │ • SPHINCS+ (optional)   │
                    │ • Custom providers      │
                    └────────────┬────────────┘
         ┌───────────────────────┴─────────────────────────┐
         │                                                 │
┌────────▼────────┐                              ┌─────────▼────────┐
│   Your Device   │                              │  Remote Server   │
├─────────────────┤                              ├──────────────────┤
│ qssh client     │◄────── Encrypted Channel ───►│ qsshd daemon     │
└─────────────────┘         (TCP Port 42)        └──────────────────┘
```

### OSI Model Integration
```
┌─────────────────────────────────────────────────────┐
│ Layer 7 - Application │ Shell, SFTP, Port Forward   │
├───────────────────────┼─────────────────────────────┤
│ Layer 6 - Presentation│ QSSH Protocol               │
│                       │ • Post-quantum crypto       │
│                       │ • Key exchange & auth       │
├───────────────────────┼─────────────────────────────┤
│ Layer 5 - Session     │ Channel multiplexing        │
├───────────────────────┼─────────────────────────────┤
│ Layer 4 - Transport   │ TCP (Port 42 default)       │
├───────────────────────┼─────────────────────────────┤
│ Layer 3 - Network     │ IP (IPv4/IPv6)              │
├───────────────────────┼─────────────────────────────┤
│ Layer 2 - Data Link   │ Ethernet/WiFi               │
├───────────────────────┼─────────────────────────────┤
│ Layer 1 - Physical    │ Cable/Radio/Fiber           │
└─────────────────────────────────────────────────────┘
```

### Protocol Flow
1. **TCP Connection**: Client connects to server port 42
2. **Version Exchange**: Protocol version negotiation
3. **Algorithm Selection**: Choose quantum-safe algorithms
4. **Key Exchange**: Falcon-512 signed ephemeral keys
5. **Authentication**: SPHINCS+ signature verification
6. **Session Establishment**: AES-256-GCM encrypted channel
7. **Key Rotation**: Double Ratchet for forward secrecy

## Security Model

### Cryptographic Algorithms

| Component | Default | Alternative | Purpose |
|-----------|---------|-------------|---------|
| Key Exchange | Falcon-512 | SPHINCS+, Custom | Fast ephemeral keys |
| Signatures | Falcon-512 | SPHINCS+, Lamport | Authentication |
| Encryption | AES-256-GCM | ChaCha20-Poly1305 | Channel encryption |
| KDF | SHA3-256 | SHAKE256 | Key derivation |
| Random | QRNG→System | /dev/urandom | Nonce generation |

### Security Levels

- **Level 1 (128-bit)**: Falcon-512, AES-128
- **Level 3 (192-bit)**: Falcon-768, AES-192  
- **Level 5 (256-bit)**: Falcon-1024, AES-256, SPHINCS+

### Threat Model

QSSH protects against:
- **Quantum attacks**: Shor's algorithm (RSA/ECDSA break)
- **Classical attacks**: Lattice reduction, collision finding
- **Implementation attacks**: Side channels, timing attacks
- **Network attacks**: MITM, replay, downgrade

## Advanced Configuration

### Configuration Files

`~/.qssh/config.toml`:
```toml
[defaults]
algorithm = "falcon-512"
port = 42
compression = true
keepalive = 60

[hosts."*.quantum.net"]
algorithm = "sphincs+"
use_qkd = true
forward_agent = true

[hosts."critical.server"]
require_qkd = true
require_lamport = true
min_entropy = 256
```

### Environment Variables
```bash
export QSSH_ALGORITHM=falcon-512
export QSSH_QKD_ENDPOINT=qkd://alice.quantum.net
export QSSH_QRNG_SOURCE=/dev/qrandom
export QSSH_LOG_LEVEL=debug
```

### Quantum Device Integration

#### QKD (Quantum Key Distribution)
```bash
# Connect with QKD
qssh --qkd qkd://alice.local/api user@server

# Require QKD
qssh --require-qkd user@critical.server

# QKD with fallback
qssh --qkd-fallback user@server
```

#### QRNG (Quantum Random Number Generator)
```bash
# Local quantum device
qsshd --qrng /dev/qrandom

# Network QRNG
qsshd --qrng kirq://entropy.hub:8080

# Multiple sources
qsshd --qrng /dev/qrandom,kirq://backup.net
```

### Port Forwarding

```bash
# Local forward (access remote service locally)
qssh -L 5432:db.internal:5432 user@gateway

# Remote forward (expose local service remotely)  
qssh -R 8080:localhost:3000 user@public.server

# Dynamic SOCKS proxy
qssh -D 1080 user@gateway

# Multiple forwards
qssh -L 3306:mysql:3306 -L 5432:postgres:5432 user@server
```

## P2P Mode

Decentralized operation without daemons:

### Basic P2P
```bash
# Start P2P listener
qssh --p2p --listen

# Connect to peer
qssh --p2p alice@192.168.1.100

# Discover peers
qssh --p2p --discover
```

### P2P with NAT Traversal
```bash
# Enable STUN
qssh --p2p --stun stun.l.google.com:19302

# Use TURN relay
qssh --p2p --turn turn.example.com --turn-user alice
```

### Blockchain Discovery
```bash
# Use QuantumHarmony validators
qssh --p2p --blockchain harmony://mainnet
```

## Testing

### Running Tests
```bash
# All tests
cargo test

# Unit tests only
cargo test --lib

# Integration tests
cargo test --test integration

# Specific test
cargo test test_handshake

# With output
cargo test -- --nocapture

# Parallel tests
cargo test -- --test-threads=8
```

### Test Categories

#### Unit Tests (`src/*/mod.rs`)
- Crypto primitives
- Protocol messages  
- Key derivation
- Serialization

#### Integration Tests (`tests/`)
- Client-server handshake
- Key exchange protocols
- Channel multiplexing
- Error handling

#### Quantum Tests (`tests/quantum_tests.rs`)
- QKD integration
- QRNG functionality
- Lamport signatures
- Double Ratchet

#### Performance Tests (`benches/`)
```bash
# Run benchmarks
cargo bench

# Specific benchmark
cargo bench handshake

# Compare implementations
cargo bench --bench crypto_bench
```

### Test Coverage
```bash
# Generate coverage report
cargo tarpaulin --out Html

# With branch coverage
cargo tarpaulin --branch --out Lcov
```

## Development

### Building from Source

```bash
# Development build
cargo build

# Release build (optimized)
cargo build --release

# All targets
cargo build --all-targets

# With features
cargo build --features "qkd,hardware"
```

### Adding Custom Algorithms

1. **Implement CryptoProvider trait**:
```rust
use qssh::crypto::{CryptoProvider, AlgorithmInfo};

pub struct MyAlgorithm;

#[async_trait]
impl CryptoProvider for MyAlgorithm {
    fn name(&self) -> &str { "my-algo" }
    
    async fn generate_keypair(&self, algorithm: &str) -> Result<KeyPair> {
        // Your implementation
    }
    
    async fn sign(&self, key: &[u8], data: &[u8]) -> Result<Vec<u8>> {
        // Your implementation
    }
}
```

2. **Register provider**:
```rust
let mut registry = CryptoRegistry::new();
registry.register(Box::new(MyAlgorithm));
```

3. **Use it**:
```bash
qssh --algorithm my-algo user@server
```

### Debugging

```bash
# Verbose output
qssh -vvv user@server

# Debug specific subsystem
QSSH_DEBUG=handshake,crypto qssh user@server

# Protocol trace
qssh --trace protocol.log user@server

# Analyze core dumps
gdb qssh core
```

## Performance

### Benchmarks (Intel i7-10700K)

| Operation | Falcon-512 | SPHINCS+ | RSA-2048 |
|-----------|------------|----------|----------|
| Keygen | 0.8ms | 3.2ms | 84ms |
| Sign | 0.4ms | 5.1ms | 1.2ms |
| Verify | 0.1ms | 2.4ms | 0.04ms |
| Handshake | 3.2ms | 14ms | 5.6ms |

### Optimization Tips

1. **Use Falcon for speed**: 10x faster than SPHINCS+
2. **Enable compression**: For slow networks
3. **Reuse connections**: Connection pooling
4. **Hardware acceleration**: AES-NI, SHA extensions

## Troubleshooting

### Connection Issues

```bash
# Test connectivity
qssh-diag test user@server

# Check algorithms
qssh-diag algorithms

# Verify quantum devices
qssh-diag quantum
```

### Common Problems

**"No quantum entropy available"**
- Install QRNG driver or use `--no-qrng`

**"Algorithm negotiation failed"**  
- Update both client and server
- Check `--algorithms` match

**"QKD key exhausted"**
- Increase key generation rate
- Enable QKD cache



### Quick Guide
1. Fork the repository
2. Create feature branch
3. Write tests
4. Submit PR

### Code Style
```bash
# Format code
cargo fmt

# Lint
cargo clippy

# Security audit
cargo audit
```

## License

Licensed under either:
- MIT license ([LICENSE-MIT]LICENSE-MIT)
- Apache License 2.0 ([LICENSE-APACHE]LICENSE-APACHE)

at your option.

## Acknowledgments

- NIST Post-Quantum Cryptography project
- QuantumHarmony blockchain team
- PQClean reference implementations
- Signal Protocol (Double Ratchet)

---

*Building quantum-safe infrastructure for the next generation of secure communications.*