holecard-cli 0.4.0

A secure CLI password manager with dual-key encryption and TOTP support
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
# Contributing to Holecard

Thank you for your interest in contributing to Holecard! This document provides guidelines and instructions for contributing.

## Table of Contents

- [Code of Conduct]#code-of-conduct
- [Getting Started]#getting-started
- [Development Workflow]#development-workflow
- [Coding Standards]#coding-standards
- [Testing]#testing
- [Submitting Changes]#submitting-changes
- [Reporting Issues]#reporting-issues

## Code of Conduct

This project adheres to a simple code of conduct:

- Be respectful and considerate
- Welcome newcomers and help them get started
- Focus on what is best for the project and community
- Accept constructive criticism gracefully

## Getting Started

### Prerequisites

- **Rust**: Install via [rustup]https://rustup.rs/
- **Git**: Version control
- **macOS/Linux**: Development primarily targets Unix-like systems

### Fork and Clone

```bash
# Fork the repository on GitHub, then:
git clone https://github.com/YOUR-USERNAME/holecard
cd holecard

# Add upstream remote
git remote add upstream https://github.com/shabarba/holecard
```

### Build and Test

```bash
# Build
cargo build

# Run tests
cargo test

# Run clippy (linter)
cargo clippy

# Format code
cargo fmt
```

### Development Build

```bash
# Build and install locally for testing
cargo install --path .

# Test your changes
hc --version
```

## Development Workflow

### Branching Strategy

```bash
# Create feature branch
git checkout -b feat/my-feature

# Create fix branch
git checkout -b fix/bug-description

# Keep your branch updated
git fetch upstream
git rebase upstream/main
```

### Commit Messages

Follow [Conventional Commits](https://www.conventionalcommits.org/):

```
<type>(<scope>): <description>

[optional body]

[optional footer]
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation changes
- `style`: Code style changes (formatting, missing semicolons, etc.)
- `refactor`: Code refactoring
- `test`: Adding or updating tests
- `chore`: Maintenance tasks

**Examples:**
```
feat(ssh): add SSH key fingerprint display

fix(crypto): correct nonce generation for export

docs(readme): update installation instructions

test(deck): add test cases for hand CRUD operations
```

### Development Tips

**Run tests on file change:**
```bash
cargo watch -x test
```

**Run specific test:**
```bash
cargo test test_encryption
```

**Debug logging:**
```bash
RUST_LOG=debug cargo run -- <command>
```

## Coding Standards

### Rust Style

- Follow [Rust API Guidelines]https://rust-lang.github.io/api-guidelines/
- Use `rustfmt` for formatting (enforced in CI)
- Address all `clippy` warnings
- Prefer idiomatic Rust patterns

### Code Organization

Follow the project architecture:

```
src/
├── main.rs              # CLI entry point
├── cli/                 # Command definitions and input
├── handlers/            # Command handlers (application layer)
├── domain/              # Business logic (no I/O)
└── infrastructure/      # I/O implementations (crypto, storage, keyring)
```

**Principles:**
- **Single Responsibility**: Each module/function has one clear purpose
- **Dependency Injection**: Pass dependencies explicitly (especially `CryptoService`)
- **Error Handling**: Use `Result` and custom error types
- **No Panics**: Avoid `.unwrap()` in production code (use `?` operator)

### File Size

Keep files under 200 lines when possible. Split large files into logical modules.

### Documentation

**Public APIs:**
```rust
/// Encrypts data using AES-256-GCM with the provided key.
///
/// # Arguments
/// * `data` - The plaintext data to encrypt
/// * `derived_key` - The 32-byte encryption key
///
/// # Returns
/// Encrypted data with format: [nonce][ciphertext+tag]
///
/// # Errors
/// Returns `CryptoError` if encryption fails
pub fn encrypt_with_key(
    &self,
    data: &[u8],
    derived_key: &[u8; 32],
) -> Result<Vec<u8>, CryptoError>
```

**Complex logic:**
```rust
// Combine master password and secret key before derivation
// This provides defense-in-depth: both keys required for decryption
let mut combined = Vec::new();
combined.extend_from_slice(master_password.as_bytes());
combined.extend_from_slice(b"|");
combined.extend_from_slice(secret_key.as_bytes());
```

### Security Considerations

When contributing security-related code:

✅ **DO:**
- Use established cryptographic libraries (don't roll your own)
- Zero sensitive data after use (`zeroize` crate)
- Use constant-time comparison for secrets
- Add tests for security properties
- Document security assumptions

❌ **DON'T:**
- Log sensitive data (passwords, keys, decrypted content)
- Write sensitive data to disk unencrypted
- Use deprecated/weak cryptographic primitives
- Ignore security warnings from dependencies

## Testing

### Writing Tests

**Unit tests** - test individual functions:
```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_encrypt_decrypt_roundtrip() {
        let crypto = CryptoServiceImpl::new();
        let key = [0u8; 32];
        let data = b"secret data";

        let encrypted = crypto.encrypt_with_key(data, &key).unwrap();
        let decrypted = crypto.decrypt_with_key(&encrypted, &key).unwrap();

        assert_eq!(data, decrypted.as_slice());
    }
}
```

**Integration tests** - test full workflows:
```rust
// tests/integration_test.rs
#[test]
fn test_deck_lifecycle() {
    // Setup
    let temp_dir = tempfile::tempdir().unwrap();
    let deck_path = temp_dir.path().join("vault.enc");

    // Initialize deck
    // Add hand
    // Get hand
    // Verify
}
```

### Running Tests

```bash
# All tests
cargo test

# Specific test
cargo test test_encryption

# With output
cargo test -- --nocapture

# Integration tests only
cargo test --test '*'
```

### Test Coverage

Aim for:
- **80%+ coverage** for cryptographic code
- **60%+ coverage** for business logic
- **100% coverage** for critical security paths

## Submitting Changes

### Before Submitting

1. **Ensure tests pass:**
   ```bash
   cargo test
   ```

2. **Run clippy:**
   ```bash
   cargo clippy -- -D warnings
   ```

3. **Format code:**
   ```bash
   cargo fmt
   ```

4. **Update documentation:**
   - Update README.md if adding user-facing features
   - Add/update doc comments for public APIs
   - Update CHANGELOG.md (for maintainers)

### Pull Request Process

1. **Push your branch:**
   ```bash
   git push origin feat/my-feature
   ```

2. **Create Pull Request** on GitHub with:
   - Clear title (following conventional commit format)
   - Description of changes and motivation
   - Link to related issues (`Fixes #123`)
   - Screenshots/examples if UI/CLI changes

3. **PR Template:**
   ```markdown
   ## Summary
   Brief description of changes

   ## Changes
   - Added feature X
   - Fixed bug Y
   - Refactored Z

   ## Testing
   - [ ] Unit tests added/updated
   - [ ] Integration tests pass
   - [ ] Manual testing completed

   ## Related Issues
   Fixes #123
   ```

4. **Review Process:**
   - Maintainer reviews code
   - CI runs tests and linters
   - Address feedback with additional commits
   - Once approved, maintainer merges

### Merge Requirements

- ✅ All tests pass
- ✅ No clippy warnings
- ✅ Code formatted with `rustfmt`
- ✅ At least one maintainer approval
- ✅ Commit messages follow conventional format

## Reporting Issues

### Bug Reports

Use the [Bug Report template](.github/ISSUE_TEMPLATE/bug_report.md):

**Include:**
- Holecard version: `hc --version`
- Operating system and version
- Steps to reproduce
- Expected vs. actual behavior
- Relevant logs (remove sensitive data!)

**Example:**
```markdown
## Bug Description
`hc get` fails with "decryption error" after system reboot

## Environment
- Holecard: 0.3.0
- OS: macOS 14.2 (23C64)
- Shell: zsh 5.9

## Steps to Reproduce
1. `hc init`
2. `hc hand add test -f password=test`
3. Reboot system
4. `hc hand get test` → Error

## Expected Behavior
Hand should be retrieved successfully

## Actual Behavior
Error: Failed to decrypt deck: decryption failed
```

### Feature Requests

Use the [Feature Request template](.github/ISSUE_TEMPLATE/feature_request.md):

**Include:**
- Problem you're trying to solve
- Proposed solution
- Alternative solutions considered
- Additional context

### Security Issues

**DO NOT open public issues for security vulnerabilities.**

Email security concerns to: **[security@shabarba.com]**

See [SECURITY.md](docs/SECURITY.md) for details.

## Development Resources

### Project Structure

```
holecard/
├── src/
│   ├── main.rs              # CLI entry point
│   ├── cli/                 # CLI definitions
│   ├── handlers/            # Command handlers
│   ├── domain/              # Business logic
│   └── infrastructure/      # I/O implementations
├── tests/                   # Integration tests
├── docs/                    # Documentation
├── .github/                 # CI/CD workflows
└── homebrew/               # Homebrew formula
```

### Key Files

- `src/infrastructure/crypto_impl.rs` - Encryption implementation
- `src/infrastructure/storage.rs` - Deck file I/O
- `src/domain/deck.rs` - Deck data structure
- `src/handlers/deck.rs` - Hand command handlers

### Useful Commands

```bash
# Generate documentation
cargo doc --open

# Check for outdated dependencies
cargo outdated

# Security audit
cargo audit

# Benchmark (if benches exist)
cargo bench
```

## Getting Help

- **Questions**: Open a [Discussion]https://github.com/shabarba/holecard/discussions
- **Chat**: (If Discord/Slack exists)
- **Email**: (If public email exists)

## Recognition

Contributors will be recognized in:
- GitHub contributors list
- Release notes
- CHANGELOG.md (for significant contributions)

Thank you for contributing to Holecard! 🎉