threat-intel 0.1.0

Comprehensive threat intelligence framework with multi-source aggregation, CVE integration, and risk assessment
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
# Configuration Guide

Comprehensive guide for configuring Threat Intelligence.

## Basic Configuration

### Default Configuration

```rust
use threat_intel::{ThreatIntelligence, Config};

// Use default settings
let config = Config::default();
let ti = ThreatIntelligence::new(config);
```

### Custom Configuration

```rust
use threat_intel::{Config, Duration};

let config = Config::new()
    .with_cache_ttl(Duration::from_secs(3600))  // 1 hour cache
    .with_timeout(Duration::from_secs(30))     // 30 second timeout
    .with_retry_attempts(3)                    // 3 retry attempts
    .with_max_sources(10);                     // Max 10 sources

let ti = ThreatIntelligence::new(config);
```

## Data Source Configuration

### MITRE ATT&CK

```rust
use threat_intel::{Config, MitreSource};

let config = Config::new()
    .with_source(MitreSource::new()
        .with_custom_url("https://attack.mitre.org/api/v2/")
        .with_rate_limit(100)  // 100 requests per minute
    );
```

### CVE Database

```rust
use threat_intel::{Config, CveSource};

let config = Config::new()
    .with_source(CveSource::new()
        .with_api_key("your-nvd-api-key")
        .with_rate_limit(50)   // 50 requests per minute
    );
```

### OSINT Feeds

```rust
use threat_intel::{Config, OsintSource, Feed};

let config = Config::new()
    .with_source(OsintSource::new()
        .add_feed(Feed::new("https://feeds.example.com/threats.json")
            .with_auth("username", "password")
            .with_interval(Duration::from_secs(3600))
        )
        .add_feed(Feed::new("https://another-feed.com/feed.xml")
            .with_format(FeedFormat::Xml)
        )
    );
```

## API Keys and Authentication

### Environment Variables

```rust
use std::env;

let config = Config::new()
    .with_api_key("mitre", &env::var("MITRE_API_KEY")?)
    .with_api_key("cve", &env::var("CVE_API_KEY")?)
    .with_api_key("osint", &env::var("OSINT_API_KEY")?);
```

### Configuration File

```toml
# config.toml
[threat_intel]
cache_ttl = 3600
timeout = 30
max_sources = 10

[threat_intel.sources.mitre]
api_key = "your-mitre-key"
base_url = "https://attack.mitre.org/api/v2/"

[threat_intel.sources.cve]
api_key = "your-cve-key"
rate_limit = 50

[threat_intel.sources.osint]
feeds = [
    { url = "https://feed1.com", auth = "user:pass" },
    { url = "https://feed2.com", format = "xml" }
]
```

```rust
use threat_intel::Config;
use std::fs;

// Load from file
let config_str = fs::read_to_string("config.toml")?;
let config: Config = toml::from_str(&config_str)?;
```

## Cache Configuration

### Memory Cache

```rust
use threat_intel::{Config, CacheConfig};

let cache_config = CacheConfig::new()
    .with_ttl(Duration::from_secs(3600))      // 1 hour TTL
    .with_max_size(1000)                       // Max 1000 entries
    .with_compression()                        // Enable compression
    .with_eviction_policy(EvictionPolicy::LRU); // LRU eviction

let config = Config::new()
    .with_cache_config(cache_config);
```

### Redis Cache

```rust
use threat_intel::{Config, RedisCache};

let redis_cache = RedisCache::new()
    .with_url("redis://localhost:6379")
    .with_ttl(Duration::from_secs(3600))
    .with_compression();

let config = Config::new()
    .with_cache(redis_cache);
```

### File Cache

```rust
use threat_intel::{Config, FileCache};

let file_cache = FileCache::new()
    .with_directory("/tmp/threat-intel-cache")
    .with_ttl(Duration::from_secs(3600))
    .with_compression();

let config = Config::new()
    .with_cache(file_cache);
```

## Network Configuration

### HTTP Client Settings

```rust
use threat_intel::{Config, HttpClientConfig};

let http_config = HttpClientConfig::new()
    .with_timeout(Duration::from_secs(30))
    .with_connect_timeout(Duration::from_secs(10))
    .with_user_agent("ThreatIntel/1.0")
    .with_proxy("http://proxy.company.com:8080")
    .with_retry_policy(RetryPolicy::exponential_backoff(3));

let config = Config::new()
    .with_http_config(http_config);
```

### Rate Limiting

```rust
use threat_intel::{Config, RateLimit};

let config = Config::new()
    .with_global_rate_limit(RateLimit::new(100, Duration::from_secs(60)))  // 100 req/min
    .with_source_rate_limit("mitre", RateLimit::new(50, Duration::from_secs(60)))
    .with_source_rate_limit("cve", RateLimit::new(25, Duration::from_secs(60)));
```

### SSL/TLS Configuration

```rust
use threat_intel::{Config, SslConfig};

let ssl_config = SslConfig::new()
    .with_verify_certificates(true)
    .with_custom_ca_bundle("/path/to/ca-bundle.pem")
    .with_client_certificate("/path/to/client.pem", "/path/to/client.key");

let config = Config::new()
    .with_ssl_config(ssl_config);
```

## Filtering Configuration

### Data Filters

```rust
use threat_intel::{Config, Filter, FilterType};

let config = Config::new()
    .with_filter(Filter::new(FilterType::Severity)
        .with_values(vec!["High", "Critical"])
    )
    .with_filter(Filter::new(FilterType::Confidence)
        .with_minimum(Confidence::Medium)
    )
    .with_filter(Filter::new(FilterType::TimeRange)
        .with_start_date(chrono::Utc::now() - chrono::Duration::days(30))
    );
```

### Source Filters

```rust
use threat_intel::{Config, SourceFilter};

let config = Config::new()
    .with_source_filter(SourceFilter::new()
        .include_sources(vec!["mitre", "cve"])
        .exclude_sources(vec!["osint"])
        .with_priority("mitre", 1)
        .with_priority("cve", 2)
    );
```

## Performance Tuning

### Concurrent Requests

```rust
use threat_intel::{Config, ConcurrencyConfig};

let concurrency_config = ConcurrencyConfig::new()
    .with_max_concurrent_requests(10)
    .with_max_concurrent_sources(5)
    .with_request_queue_size(100);

let config = Config::new()
    .with_concurrency_config(concurrency_config);
```

### Memory Management

```rust
use threat_intel::{Config, MemoryConfig};

let memory_config = MemoryConfig::new()
    .with_max_memory_usage(1024 * 1024 * 1024)  // 1GB
    .with_compression_threshold(1024)            // Compress > 1KB
    .with_gc_interval(Duration::from_secs(300)); // GC every 5 minutes

let config = Config::new()
    .with_memory_config(memory_config);
```

### Batch Processing

```rust
use threat_intel::{Config, BatchConfig};

let batch_config = BatchConfig::new()
    .with_batch_size(100)
    .with_batch_timeout(Duration::from_secs(5))
    .with_max_batch_delay(Duration::from_secs(1));

let config = Config::new()
    .with_batch_config(batch_config);
```

## Logging Configuration

### Log Levels

```rust
use threat_intel::{Config, LogConfig, LogLevel};

let log_config = LogConfig::new()
    .with_level(LogLevel::Info)
    .with_structured_logging(true)
    .with_include_sensitive_data(false)
    .with_log_file("/var/log/threat-intel.log");

let config = Config::new()
    .with_log_config(log_config);
```

### Metrics

```rust
use threat_intel::{Config, MetricsConfig};

let metrics_config = MetricsConfig::new()
    .with_enabled(true)
    .with_export_interval(Duration::from_secs(60))
    .with_metrics_endpoint("http://metrics.company.com:9090");

let config = Config::new()
    .with_metrics_config(metrics_config);
```

## Security Configuration

### Authentication

```rust
use threat_intel::{Config, AuthConfig};

let auth_config = AuthConfig::new()
    .with_api_key_rotation(Duration::from_secs(3600))
    .with_secure_storage(true)
    .with_encryption_key("your-encryption-key");

let config = Config::new()
    .with_auth_config(auth_config);
```

### Data Privacy

```rust
use threat_intel::{Config, PrivacyConfig};

let privacy_config = PrivacyConfig::new()
    .with_anonymize_ips(true)
    .with_remove_pii(true)
    .with_data_retention(Duration::from_secs(86400 * 30)); // 30 days

let config = Config::new()
    .with_privacy_config(privacy_config);
```

## Environment-Specific Configuration

### Development

```rust
use threat_intel::{Config, Environment};

let config = Config::new()
    .with_environment(Environment::Development)
    .with_debug_logging(true)
    .with_mock_sources(true)
    .with_short_timeouts();
```

### Production

```rust
use threat_intel::{Config, Environment};

let config = Config::new()
    .with_environment(Environment::Production)
    .with_high_availability(true)
    .with_monitoring(true)
    .with_security_hardening(true);
```

### Testing

```rust
use threat_intel::{Config, Environment};

let config = Config::new()
    .with_environment(Environment::Testing)
    .with_mock_sources(true)
    .with_deterministic_results(true)
    .with_fast_timeouts();
```

## Configuration Validation

### Schema Validation

```rust
use threat_intel::{Config, ConfigValidator};

let validator = ConfigValidator::new()
    .with_required_fields(vec!["api_key", "timeout"])
    .with_value_ranges("timeout", 1..=300)
    .with_enum_values("log_level", vec!["debug", "info", "warn", "error"]);

let config = Config::new()
    .with_validator(validator);
```

### Runtime Validation

```rust
use threat_intel::{Config, RuntimeValidator};

let runtime_validator = RuntimeValidator::new()
    .with_connectivity_check(true)
    .with_api_key_validation(true)
    .with_source_health_check(true);

let config = Config::new()
    .with_runtime_validator(runtime_validator);
```

## Best Practices

### 1. Use Environment Variables

```rust
use std::env;

let config = Config::new()
    .with_api_key("mitre", &env::var("MITRE_API_KEY").unwrap_or_default())
    .with_timeout(Duration::from_secs(
        env::var("TIMEOUT_SECS")
            .unwrap_or_default()
            .parse()
            .unwrap_or(30)
    ));
```

### 2. Validate Configuration

```rust
fn validate_config(config: &Config) -> Result<(), String> {
    if config.timeout().as_secs() < 1 {
        return Err("Timeout must be at least 1 second".to_string());
    }
    
    if config.max_sources() == 0 {
        return Err("At least one source must be configured".to_string());
    }
    
    Ok(())
}
```

### 3. Use Configuration Profiles

```rust
use threat_intel::{Config, Profile};

let config = match env::var("ENVIRONMENT").unwrap_or_default().as_str() {
    "production" => Config::production(),
    "staging" => Config::staging(),
    "development" => Config::development(),
    _ => Config::default(),
};
```

## Troubleshooting

### Common Issues

**1. API Key Errors**
```rust
// Check API key configuration
if config.api_keys().is_empty() {
    eprintln!("No API keys configured");
}

// Validate API keys
for (source, key) in config.api_keys() {
    if key.is_empty() {
        eprintln!("Empty API key for source: {}", source);
    }
}
```

**2. Timeout Issues**
```rust
// Increase timeout for slow sources
let config = Config::new()
    .with_timeout(Duration::from_secs(60))  // Increase from default 30s
    .with_retry_attempts(5);                 // More retries
```

**3. Rate Limiting**
```rust
// Configure rate limits per source
let config = Config::new()
    .with_source_rate_limit("mitre", RateLimit::new(10, Duration::from_secs(60)))
    .with_source_rate_limit("cve", RateLimit::new(5, Duration::from_secs(60)));
```

## Next Steps

- Review [Data Sources]./data-sources.md for available sources
- Check [Integration Guide]./integration.md for system integration
- See [Performance Tuning]./performance.md for optimization tips