fynx-proto 0.1.0-alpha.3

Production-ready SSH and IPSec/IKEv2 protocol implementations with comprehensive testing and high-level APIs
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
# Fynx Proto - Network Security Protocols


[![Crates.io](https://img.shields.io/crates/v/fynx-proto)](https://crates.io/crates/fynx-proto)
[![Documentation](https://docs.rs/fynx-proto/badge.svg)](https://docs.rs/fynx-proto)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue)](LICENSE-MIT)

Production-ready SSH and IPSec protocol implementations in Rust, designed for the Fynx security ecosystem.

## 🎯 Protocols


### SSH (Secure Shell) ✅ Production Ready


Complete SSH protocol implementation with modern cryptography:

- **SSH Transport Layer** (RFC 4253): Version exchange, key exchange, packet encryption
- **Key Exchange**: Curve25519 (curve25519-sha256), DH Groups 14/15
- **Host Keys**: Ed25519, RSA, ECDSA (P-256/384/521)
- **Authentication**: Password, public key (Ed25519, RSA, ECDSA)
- **Encryption**: ChaCha20-Poly1305, AES-128/256-GCM
- **Advanced**: Private key loading (PEM, OpenSSH), known_hosts, authorized_keys
- **Testing**: 178 tests passing (100%)

### IPSec/IKEv2 (IP Security) ✅ Production Ready


Enterprise-grade VPN protocol with comprehensive features:

- **IKEv2 Protocol** (RFC 7296): IKE_SA_INIT, IKE_AUTH, CREATE_CHILD_SA
- **ESP Protocol** (RFC 4303): Transport & Tunnel modes
- **Encryption**: AES-128/256-GCM, ChaCha20-Poly1305 (AEAD)
- **Authentication**: Pre-Shared Keys (PSK)
- **Advanced**: NAT-T (RFC 3948), Dead Peer Detection (DPD), SA Rekeying
- **High-Level APIs**: IpsecClient, IpsecServer with builder pattern
- **Production**: Structured logging (tracing), metrics (18 counters), error handling
- **Testing**: 567 tests passing + 12 benchmarks + 10 interop tests

## ⚡ Quick Start


### SSH Client


Add to your `Cargo.toml`:
```toml
[dependencies]
fynx-proto = { version = "0.1.0-alpha.2", features = ["ssh"] }
tokio = { version = "1.35", features = ["full"] }
```

Connect to an SSH server:
```rust
use fynx_proto::ssh::client::SshClient;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect and authenticate
    let mut client = SshClient::connect("127.0.0.1:22").await?;
    client.authenticate_password("username", "password").await?;

    // Execute command
    let output = client.execute("whoami").await?;
    println!("Output: {}", String::from_utf8_lossy(&output));

    Ok(())
}
```

### IPSec VPN Client


Add to your `Cargo.toml`:
```toml
[dependencies]
fynx-proto = { version = "0.1.0-alpha.2", features = ["ipsec"] }
tokio = { version = "1.35", features = ["full"] }
```

Create a VPN connection:
```rust
use fynx_proto::ipsec::{IpsecClient, ClientConfig};

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Configure client
    let config = ClientConfig::builder()
        .with_local_id("client@example.com")
        .with_remote_id("server@example.com")
        .with_psk(b"my-secret-key")
        .build()?;

    // Connect to VPN server
    let mut client = IpsecClient::new(config);
    client.connect("10.0.0.1:500".parse()?).await?;

    // Send encrypted data
    client.send_packet(b"Hello, VPN!").await?;
    let response = client.recv_packet().await?;
    println!("Received: {:?}", response);

    // Graceful shutdown
    client.shutdown().await?;
    Ok(())
}
```

## 📚 Features


### SSH Protocol Features


#### Core Protocol

- ✅ RFC 4253: SSH Transport Layer Protocol
- ✅ RFC 4252: Authentication Protocol
- ✅ RFC 4254: Connection Protocol
- ✅ Version exchange and algorithm negotiation
- ✅ Key exchange with signature verification
- ✅ Encrypted packet transport

#### Key Exchange

- ✅ Curve25519-SHA256 (modern, recommended)
- ✅ Diffie-Hellman Group 14 (2048-bit)
- ✅ Diffie-Hellman Group 15 (3072-bit)

#### Host Key Algorithms

- ✅ ssh-ed25519 (Ed25519 signatures)
- ✅ rsa-sha2-256, rsa-sha2-512 (RSA with SHA-2)
- ✅ ecdsa-sha2-nistp256/384/521 (ECDSA)

#### Authentication

- ✅ Password authentication (RFC 4252)
- ✅ Public key authentication (Ed25519, RSA, ECDSA)
- ✅ Private key loading (PEM, PKCS#1, PKCS#8, OpenSSH formats)
- ✅ Encrypted private keys (AES-128/192/256, bcrypt-pbkdf)
- ✅ authorized_keys file parsing
- ✅ known_hosts management (add, verify, update)
- ✅ StrictHostKeyChecking modes

#### Encryption (AEAD)

- chacha20-poly1305@openssh.com (recommended)
-aes128-gcm@openssh.com
-aes256-gcm@openssh.com

#### MAC Algorithms

- ✅ hmac-sha2-256
- ✅ hmac-sha2-512

### IPSec Protocol Features


#### IKEv2 Protocol (RFC 7296)

- ✅ IKE_SA_INIT: Initial handshake + DH key exchange
- ✅ IKE_AUTH: PSK authentication + first Child SA
- ✅ CREATE_CHILD_SA: Rekeying and new tunnels
- ✅ INFORMATIONAL: DELETE notifications, DPD

#### ESP Protocol (RFC 4303)

- ✅ Transport mode (host-to-host)
- ✅ Tunnel mode (network-to-network VPN)
- ✅ Anti-replay protection (sequence numbers)
- ✅ Automatic rekeying before SA expiration

#### Encryption Algorithms

- ✅ AES-128-GCM (AEAD)
- ✅ AES-256-GCM (AEAD)
- ✅ ChaCha20-Poly1305 (AEAD, RFC 8750)

#### Key Exchange

- ✅ Diffie-Hellman Group 14 (2048-bit MODP)
- ✅ Diffie-Hellman Group 15 (3072-bit MODP)
- ✅ Curve25519 (ECDH)

#### Advanced Features

- ✅ NAT Traversal (NAT-T, RFC 3948)
- ✅ Dead Peer Detection (DPD)
- ✅ Traffic Selectors (subnet-based tunnels)
- ✅ Multiple cipher suite negotiation
- ✅ Cookie-based DoS protection

#### Production Features

- ✅ High-level APIs (IpsecClient, IpsecServer)
- ✅ Configuration builders with validation
- ✅ Structured logging (tracing, 20+ instrumented functions)
- ✅ Metrics collection (18 atomic counters)
- ✅ Enhanced error handling (error codes, context, retry detection)
- ✅ Comprehensive documentation (500+ lines user guide)

## 🏗️ Architecture


```
fynx-proto/
├── src/
│   ├── ssh/                    # SSH Protocol (178 tests)
│   │   ├── client.rs           # SSH client with host key verification
│   │   ├── server.rs           # SSH server with authentication
│   │   ├── transport.rs        # Transport layer state machine
│   │   ├── kex.rs              # Key exchange (Curve25519, DH)
│   │   ├── hostkey.rs          # Host keys (Ed25519, RSA, ECDSA)
│   │   ├── auth.rs             # Authentication (password, pubkey)
│   │   ├── privatekey.rs       # Private key loading
│   │   ├── known_hosts.rs      # known_hosts file management
│   │   ├── authorized_keys.rs  # authorized_keys parsing
│   │   └── crypto.rs           # Cryptographic primitives
│   │
│   └── ipsec/                  # IPSec Protocol (567 tests)
│       ├── client.rs           # High-level IpsecClient API
│       ├── server.rs           # High-level IpsecServer API
│       ├── config.rs           # Configuration builders
│       ├── ikev2/              # IKEv2 protocol implementation
│       ├── esp/                # ESP protocol implementation
│       ├── crypto/             # AEAD ciphers, key derivation
│       ├── logging.rs          # Structured logging
│       └── metrics.rs          # Performance metrics
│
├── tests/
│   ├── ssh_integration.rs      # SSH integration tests (6 tests)
│   ├── ipsec_integration.rs    # IPSec integration tests (25 tests)
│   ├── ipsec_client_server.rs  # API tests (6 tests)
│   └── interop_strongswan.rs   # strongSwan interop (10 tests, ignored)
│
├── benches/
│   └── ipsec_bench.rs          # IPSec benchmarks (12 benchmarks)
│
└── docs/
    ├── ssh/                    # SSH documentation
    └── ipsec/                  # IPSec documentation
```

## 🧪 Testing


Comprehensive test coverage with 745+ tests:

```bash
# Run all tests

cargo test --all-features

# SSH tests (178 passing)

cargo test --features ssh

# IPSec tests (567 passing)

cargo test --features ipsec

# Run benchmarks

cargo bench --features ipsec

# With output

cargo test -- --nocapture
```

### Test Breakdown


| Category | Tests | Status |
|----------|-------|--------|
| **SSH Unit Tests** | 172 | ✅ 100% |
| **SSH Integration** | 6 | ✅ 100% |
| **IPSec Unit Tests** | 536 | ✅ 100% |
| **IPSec Integration** | 25 | ✅ 100% |
| **IPSec API Tests** | 6 | ✅ 100% |
| **Total Library Tests** | **745** | **✅ 100%** |
| **IPSec Benchmarks** | 12+ | ✅ Running |
| **Interop Tests** | 10 | 📋 Framework ready |

## 🔒 Security


### Memory Safety

- **Zero unsafe code**: 100% safe Rust
- **Zeroization**: Sensitive data (keys, passwords) securely wiped
- **No memory leaks**: RAII and automatic cleanup

### Cryptographic Security

- **Modern algorithms**: Curve25519, Ed25519, ChaCha20-Poly1305
- **Constant-time operations**: Timing attack resistant
- **Strong RNG**: Using `ring` for cryptographic randomness
- **Anti-replay protection**: Sequence number validation in ESP

### Protocol Security

- **Host key verification**: Prevent MITM attacks (SSH)
- **Signature verification**: Authenticate server identity (SSH, IKEv2)
- **Cookie-based DoS protection**: Resist resource exhaustion (IKEv2)
- **Dead Peer Detection**: Detect unresponsive peers (IPSec)

## 📖 Documentation


- **API Documentation**: [docs.rs/fynx-proto]https://docs.rs/fynx-proto
- **SSH User Guide**: [docs/ssh/README.md]https://github.com/Rx947getrexp/fynx/blob/main/docs/ssh/README.md
- **IPSec User Guide**: [docs/ipsec/USER_GUIDE.md]https://github.com/Rx947getrexp/fynx/blob/main/docs/ipsec/USER_GUIDE.md
- **IPSec Architecture**: [docs/ipsec/ARCHITECTURE.md]https://github.com/Rx947getrexp/fynx/blob/main/docs/ipsec/ARCHITECTURE.md
- **Examples**: See `examples/` directory

### Examples


Run examples with:
```bash
# SSH client example

cargo run --example simple_client --features ssh

# IPSec client example

cargo run --example ipsec_client --features ipsec -- 10.0.0.1:500 client@example.com server@example.com "my-secret-key"

# IPSec server example (requires root/administrator for port 500)

cargo run --example ipsec_server --features ipsec -- 0.0.0.0:500 server@example.com "my-secret-key"
```

## ⚙️ Feature Flags


```toml
[features]
default = ["ssh"]

# SSH protocol support (RFC 4253/4252/4254)

# - 178 tests, production-ready

# - Client, server, authentication

ssh = []

# IPSec/IKEv2 VPN protocol (RFC 7296, RFC 4303)

# - 567 tests, production-ready

# - IKEv2 key exchange, ESP encryption

# - High-level APIs, metrics, logging

ipsec = []

# DTLS protocol (planned)

dtls = []

# TTY password input for SSH

tty-password = ["rpassword"]
```

## 🚀 Performance


### Benchmarks (IPSec)


Run with: `cargo bench --features ipsec --bench ipsec_bench`

- **IKE Handshake**: Complete IKE_SA_INIT + IKE_AUTH exchange
- **ESP Encryption**: 64B, 512B, 1500B packet throughput
- **ESP Decryption**: 64B, 1500B packet throughput
- **Key Derivation**: IKE SA and Child SA key generation
- **Serialization**: Packet encoding/decoding performance

### Async Runtime

- Built on Tokio for efficient async I/O
- Non-blocking operations throughout
- Supports thousands of concurrent connections

### Memory Efficiency

- Zero-copy buffer operations with `bytes` crate
- Efficient packet parsing
- Automatic cleanup with RAII

## 📋 Roadmap


### Completed ✅

- [x] SSH Transport Layer (RFC 4253)
- [x] SSH Authentication (password, public key)
- [x] SSH Connection Protocol (command execution)
- [x] Private key loading (PEM, OpenSSH formats)
- [x] known_hosts management
- [x] authorized_keys parsing
- [x] IKEv2 Protocol (RFC 7296)
- [x] ESP Protocol (RFC 4303)
- [x] NAT Traversal (NAT-T)
- [x] Dead Peer Detection (DPD)
- [x] High-level IPSec APIs
- [x] Production hardening (logging, metrics)

### Planned 📋

- [ ] SSH: Port forwarding (Local, Remote, Dynamic)
- [ ] SSH: SFTP protocol
- [ ] SSH: Session management (multiplexing, connection pool)
- [ ] SSH: ssh-agent support
- [ ] SSH: SCP support
- [ ] IPSec: X.509 certificate authentication
- [ ] IPSec: Additional cipher suites
- [ ] IPSec: MOBIKE (RFC 4555)
- [ ] DTLS: Protocol implementation

## 🤝 Contributing


Contributions are welcome! Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for guidelines.

### Development Setup


```bash
# Clone repository

git clone https://github.com/Rx947getrexp/fynx
cd fynx/crates/proto

# Build

cargo build --all-features

# Run tests

cargo test --all-features

# Run specific protocol tests

cargo test --features ssh
cargo test --features ipsec

# Run clippy

cargo clippy --all-features

# Format code

cargo fmt

# Generate documentation

cargo doc --all-features --open
```

## 📄 License


Dual-licensed under MIT or Apache-2.0.

- MIT License: [LICENSE-MIT]LICENSE-MIT
- Apache License 2.0: [LICENSE-APACHE]LICENSE-APACHE

## 🔗 References


### SSH

- [RFC 4253]https://tools.ietf.org/html/rfc4253 - SSH Transport Layer Protocol
- [RFC 4252]https://tools.ietf.org/html/rfc4252 - SSH Authentication Protocol
- [RFC 4254]https://tools.ietf.org/html/rfc4254 - SSH Connection Protocol
- [RFC 8709]https://tools.ietf.org/html/rfc8709 - Ed25519 for SSH

### IPSec

- [RFC 7296]https://tools.ietf.org/html/rfc7296 - IKEv2 Protocol
- [RFC 4303]https://tools.ietf.org/html/rfc4303 - ESP Protocol
- [RFC 3948]https://tools.ietf.org/html/rfc3948 - NAT Traversal
- [RFC 4106]https://tools.ietf.org/html/rfc4106 - AES-GCM for ESP
- [RFC 8750]https://tools.ietf.org/html/rfc8750 - ChaCha20-Poly1305 for IPSec

## 💬 Support


- **Issues**: [GitHub Issues]https://github.com/Rx947getrexp/fynx/issues
- **Documentation**: [docs.rs/fynx-proto]https://docs.rs/fynx-proto
- **Repository**: [github.com/Rx947getrexp/fynx]https://github.com/Rx947getrexp/fynx

---

**Note**: This is an alpha release. While extensively tested, please conduct security audits before production deployment.