cipherrun 0.3.0

A fast, modular, and scalable TLS/SSL security scanner written in Rust
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
// API Response Models

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Scan response (returned when creating a scan)
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ScanResponse {
    /// Unique scan ID
    pub scan_id: String,

    /// Current scan status
    pub status: ScanStatus,

    /// Target being scanned
    pub target: String,

    /// WebSocket URL for real-time progress
    #[serde(skip_serializing_if = "Option::is_none")]
    pub websocket_url: Option<String>,

    /// When the scan was queued
    pub queued_at: DateTime<Utc>,

    /// Estimated completion time
    #[serde(skip_serializing_if = "Option::is_none")]
    pub estimated_completion: Option<DateTime<Utc>>,
}

/// Scan status response
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ScanStatusResponse {
    /// Unique scan ID
    pub scan_id: String,

    /// Current status
    pub status: ScanStatus,

    /// Progress percentage (0-100)
    pub progress: u8,

    /// Current stage being executed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_stage: Option<String>,

    /// Estimated seconds until completion
    #[serde(skip_serializing_if = "Option::is_none")]
    pub eta_seconds: Option<u64>,

    /// When scan started
    #[serde(skip_serializing_if = "Option::is_none")]
    pub started_at: Option<DateTime<Utc>>,

    /// When scan completed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub completed_at: Option<DateTime<Utc>>,

    /// Error message if failed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,

    /// Link to results (if completed)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub results_url: Option<String>,
}

/// Scan status enumeration
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub enum ScanStatus {
    /// Scan is queued waiting for execution
    Queued,

    /// Scan is currently running
    Running,

    /// Scan completed successfully
    Completed,

    /// Scan failed with error
    Failed,

    /// Scan was cancelled
    Cancelled,
}

/// Health check response
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct HealthResponse {
    /// Service status
    pub status: String,

    /// Service version
    pub version: String,

    /// Uptime in seconds
    pub uptime_seconds: u64,

    /// Current number of active scans
    pub active_scans: usize,

    /// Queued scans
    pub queued_scans: usize,

    /// Database connection status
    #[serde(skip_serializing_if = "Option::is_none")]
    pub database: Option<String>,
}

/// Statistics response
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct StatsResponse {
    /// Total scans performed
    pub total_scans: u64,

    /// Completed scans
    pub completed_scans: u64,

    /// Failed scans
    pub failed_scans: u64,

    /// Average scan duration in seconds
    pub avg_scan_duration_seconds: f64,

    /// Scans in last 24 hours
    pub scans_last_24h: u64,

    /// Scans in last 7 days
    pub scans_last_7d: u64,

    /// Most scanned domains (top 10)
    pub top_domains: Vec<DomainStats>,

    /// Current API usage statistics
    pub api_usage: ApiUsageStats,
}

/// Domain statistics
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct DomainStats {
    /// Domain name
    pub domain: String,

    /// Number of scans
    pub scan_count: u64,

    /// Last scan time
    pub last_scan: DateTime<Utc>,
}

/// API usage statistics
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ApiUsageStats {
    /// Requests in last hour
    pub requests_last_hour: u64,

    /// Requests in last day
    pub requests_last_day: u64,

    /// Average response time in milliseconds
    pub avg_response_time_ms: f64,
}

/// Certificate list response
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CertificateListResponse {
    /// Total count of certificates
    pub total: usize,

    /// Current page offset
    pub offset: usize,

    /// Page size limit
    pub limit: usize,

    /// Certificate summaries
    pub certificates: Vec<CertificateSummary>,
}

/// Certificate summary
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CertificateSummary {
    /// SHA-256 fingerprint
    pub fingerprint: String,

    /// Subject common name
    pub common_name: String,

    /// Subject alternative names
    pub san: Vec<String>,

    /// Issuer
    pub issuer: String,

    /// Valid from
    pub valid_from: DateTime<Utc>,

    /// Valid until
    pub valid_until: DateTime<Utc>,

    /// Days until expiry
    pub days_until_expiry: i64,

    /// Certificate is expired
    pub is_expired: bool,

    /// Certificate is expiring soon (< 30 days)
    pub is_expiring_soon: bool,

    /// Associated hostnames
    pub hostnames: Vec<String>,
}

/// Policy response
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PolicyResponse {
    /// Policy ID
    pub id: String,

    /// Policy name
    pub name: String,

    /// Description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Rules in YAML format
    pub rules: String,

    /// Enabled status
    pub enabled: bool,

    /// Created timestamp
    pub created_at: DateTime<Utc>,

    /// Updated timestamp
    pub updated_at: DateTime<Utc>,
}

/// Policy evaluation result
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PolicyEvaluationResponse {
    /// Policy ID
    pub policy_id: String,

    /// Policy name
    pub policy_name: String,

    /// Target evaluated
    pub target: String,

    /// Overall compliance status
    pub compliant: bool,

    /// Individual check results
    pub checks: Vec<PolicyCheckResult>,

    /// Evaluation timestamp
    pub evaluated_at: DateTime<Utc>,

    /// Scan used for evaluation
    pub scan_id: String,
}

/// Individual policy check result
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PolicyCheckResult {
    /// Check name
    pub check: String,

    /// Check passed
    pub passed: bool,

    /// Severity level
    pub severity: String,

    /// Failure message if not passed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,

    /// Expected value
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expected: Option<String>,

    /// Actual value
    #[serde(skip_serializing_if = "Option::is_none")]
    pub actual: Option<String>,
}

/// Scan history response
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ScanHistoryResponse {
    /// Domain
    pub domain: String,

    /// Port
    pub port: u16,

    /// Total scans in history
    pub total_scans: usize,

    /// Historical scan records
    pub scans: Vec<ScanHistoryItem>,
}

/// Individual scan history item
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ScanHistoryItem {
    /// Scan ID
    pub scan_id: u64,

    /// Scan timestamp
    pub timestamp: DateTime<Utc>,

    /// Overall grade
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grade: Option<String>,

    /// Overall score
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score: Option<u8>,

    /// Scan duration in milliseconds
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<u64>,
}

/// Historical scan record
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct HistoricalScan {
    /// Scan ID
    pub scan_id: String,

    /// Scan timestamp
    pub timestamp: DateTime<Utc>,

    /// Overall grade
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grade: Option<String>,

    /// Overall score
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score: Option<u32>,

    /// Scan duration in milliseconds
    pub duration_ms: u64,

    /// Number of vulnerabilities found
    pub vulnerability_count: usize,

    /// Link to full results
    pub results_url: String,
}

/// WebSocket progress message
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ProgressMessage {
    /// Message type
    pub msg_type: String,

    /// Scan ID
    pub scan_id: String,

    /// Progress percentage (0-100)
    pub progress: u8,

    /// Current stage
    pub stage: String,

    /// Stage details
    #[serde(skip_serializing_if = "Option::is_none")]
    pub details: Option<String>,

    /// Timestamp
    pub timestamp: DateTime<Utc>,
}

impl ProgressMessage {
    /// Create a new progress message
    pub fn new(scan_id: impl Into<String>, progress: u8, stage: impl Into<String>) -> Self {
        Self {
            msg_type: "progress".to_string(),
            scan_id: scan_id.into(),
            progress,
            stage: stage.into(),
            details: None,
            timestamp: Utc::now(),
        }
    }

    /// Create a completion message
    pub fn completed(scan_id: impl Into<String>) -> Self {
        Self {
            msg_type: "completed".to_string(),
            scan_id: scan_id.into(),
            progress: 100,
            stage: "completed".to_string(),
            details: None,
            timestamp: Utc::now(),
        }
    }

    /// Create a failure message
    pub fn failed(scan_id: impl Into<String>, error: impl Into<String>) -> Self {
        Self {
            msg_type: "failed".to_string(),
            scan_id: scan_id.into(),
            progress: 0,
            stage: "failed".to_string(),
            details: Some(error.into()),
            timestamp: Utc::now(),
        }
    }
}