Meccanismi di Sicurezza

Il WvdS Crypto Service implementa diversi meccanismi di protezione che sono automaticamente attivi. Non dovete configurare nulla.


Rate Limiting

Protegge da attacchi Denial-of-Service (DoS) tramite sovraccarico.

Parametro Valore
Max richieste/secondo 1000
Tolleranza burst 100
Cooldown 100 ms

Comportamento al superamento:

Richiesta --> [Rate Limiter] --> Stato: 0x07 (RATE_LIMITED)
                             --> Nessuna operazione crypto eseguita

Raccomandazione per i client:

int send_with_retry(const uint8_t* request, size_t len) {
    int retry = 0;
    int delay_ms = 100;
 
    while (retry < 5) {
        send_request(request, len);
        int status = get_response_status();
 
        if (status != 0x07) return status;  // Non rate-limited
 
        usleep(delay_ms * 1000);
        delay_ms *= 2;  // Backoff esponenziale
        retry++;
    }
    return -1;  // Timeout
}

Nonce Tracking

Riutilizzo Nonce = Catastrofe

Con AES-GCM, il riutilizzo di una nonce porta alla compromissione completa di entrambi i testi in chiaro!

Il Crypto Service protegge attivamente dal riutilizzo nonce:

Per Encrypt

Per Decrypt

Nota: Il tracking nonce è per Key-ID. Il tracker viene resettato alla rotazione chiavi.


Validazione Input

Tutti gli input vengono validati prima dell'elaborazione:

Controllo Codice errore
Magic Byte != 0xC7 0x01 (INVALID_HEADER)
Request-Type sconosciuto 0x02 (INVALID_TYPE)
Lunghezza payload errata 0x03 (INVALID_PAYLOAD)
Key-ID non esiste 0x04 (KEY_NOT_FOUND)
Payload > 64 KB 0x09 (PAYLOAD_TOO_LARGE)

Nessuna eccezione:

Il servizio non lancia eccezioni. Tutti gli errori vengono restituiti tramite codici di stato.


Dimensione Massima Payload

Limite 64 KB (65536 byte)

Motivi:

Cifrare dati grandi:

// Chunked Encryption per file grandi
#define CHUNK_SIZE (60 * 1024)  // 60 KB per chunk
 
int encrypt_large_file(FILE* in, FILE* out) {
    uint8_t buffer[CHUNK_SIZE];
    size_t bytes_read;
    uint32_t chunk_id = 0;
 
    while ((bytes_read = fread(buffer, 1, CHUNK_SIZE, in)) > 0) {
        // AAD contiene Chunk-ID per protezione ordine
        char aad[32];
        snprintf(aad, sizeof(aad), "chunk:%u", chunk_id++);
 
        uint8_t ct[CHUNK_SIZE + 28];
        size_t ct_len;
        uint8_t nonce[12], tag[16];
 
        encrypt_message(buffer, bytes_read, aad, strlen(aad),
                       ct, &ct_len, nonce, tag);
 
        fwrite(nonce, 1, 12, out);
        fwrite(tag, 1, 16, out);
        fwrite(ct, 1, ct_len, out);
    }
    return 0;
}

Azzeramento al Rilascio

Tutti i dati critici per la sicurezza vengono sovrascritti dopo l'uso:

Implementazione:

// Impedisce ottimizzazione del compilatore
static void secure_zero(void* ptr, size_t len) {
    volatile uint8_t* p = (volatile uint8_t*)ptr;
    while (len--) *p++ = 0;
}

Isolamento L4Re

Il Crypto Service gira come task L4Re isolato:

+---------------------------------------------------------------+
|                    L4Re Microkernel                           |
+---------------------------------------------------------------+
|     |              |              |              |            |
|  +--+--+       +---+---+      +---+---+      +---+---+        |
|  | Sigma0 |    | Moe   |      | Crypto |     | OEM   |        |
|  | (Root) |    | (Mem) |      | Service|     | Gateway|       |
|  +--------+    +-------+      +--------+     +--------+        |
|                                   |              |             |
|                                   +--------------+             |
|                                   SOLO questo IPC              |
+---------------------------------------------------------------+

Garanzie di sicurezza:


Risoluzione Problemi

Sintomo Possibile causa Soluzione
Stato 0x04 persistente Key-Storage corrotto Rigenerare le chiavi
Stato 0x07 frequente Rate richieste troppo alto Batching, caching
Stato 0x08 Rotazione chiavi dimenticata Generare nuova chiave
Performance lente Modo FIPS + Debug Usare build release
Memory leak Risposte non elaborate Pulire memoria condivisa

< Riferimento API | Continua: Conformità >