Inhaltsverzeichnis

Scenario 2.1: Creare CSR server

Categoria: Richieste di certificato (CSR)
Complessita: ⭐⭐ (Media)
Prerequisiti: Coppia di chiavi disponibile
Tempo stimato: 5-10 minuti


Descrizione

Questo scenario descrive la creazione di un Certificate Signing Request (CSR) per un certificato server TLS. Il CSR contiene tutte le informazioni necessarie a una CA per emettere un certificato server.

Cosa viene creato:

Casi d'uso:


Workflow

flowchart LR KEY[Generare coppia chiavi] --> DN[Creare DN] DN --> EXT[Impostare Extensions] EXT --> CSR[Creare CSR] CSR --> SIGN[Firmare CSR] SIGN --> EXPORT[Esportare come PEM] style CSR fill:#e8f5e9


Funzioni coinvolte

Passo Funzione FFI Descrizione
1 wvds_sec_crypto_x509_keypair_generate_mldsa(65) Generare coppia di chiavi
2 wvds_sec_crypto_x509_dn_create() Creare handle DN
3 wvds_sec_crypto_x509_dn_add_component() Aggiungere CN, O, C
4 wvds_sec_crypto_x509_ext_set_san_dns() Aggiungere nomi DNS
5 wvds_sec_crypto_x509_ext_set_key_usage() digitalSignature, keyEncipherment
6 wvds_sec_crypto_x509_ext_set_eku() serverAuth
7 wvds_sec_crypto_x509_csr_create() Creare CSR
8 wvds_sec_crypto_x509_csr_sign() Firmare CSR con chiave privata
9 wvds_sec_crypto_x509_csr_to_pem() Esportare come PEM

Esempio di codice (C#)

using WvdS.Security.Cryptography.X509Certificates.Extensions.PQ;
 
// 1. Inizializzare contesto
using var ctx = PqCryptoContext.Initialize();
 
// 2. Generare coppia di chiavi per server
using var serverKey = ctx.GenerateKeyPair(PqAlgorithm.MlDsa65);
 
// 3. Distinguished Name
var dn = new DnBuilder()
    .AddCN("www.example.com")
    .AddO("Example SRL")
    .AddOU("Reparto IT")
    .AddC("IT")
    .AddL("Milano")
    .Build();
 
// 4. Extensions per certificato server
var extensions = new ExtBuilder()
    .SubjectAlternativeName(new[] {
        "www.example.com",
        "example.com",
        "api.example.com"
    })
    .KeyUsage(KeyUsageFlags.DigitalSignature | KeyUsageFlags.KeyEncipherment)
    .ExtendedKeyUsage(ExtKeyUsage.ServerAuth)
    .Build();
 
// 5. Creare e firmare CSR
var csr = ctx.CreateCertificateRequest(serverKey, dn, extensions);
 
// 6. Salvare come PEM
File.WriteAllText("server.csr.pem", csr.ToPem());
File.WriteAllText("server.key.pem", serverKey.ToEncryptedPem("SecurePassword123!"));
 
Console.WriteLine("CSR creato: server.csr.pem");
Console.WriteLine($"Subject: {csr.Subject}");
Console.WriteLine($"SANs: {string.Join(", ", csr.SubjectAlternativeNames)}");

Parametri

Subject Alternative Names

Tipo Prefisso Esempio
Nome DNS dns: www.example.com
Indirizzo IP ip: 192.168.1.100
E-Mail email: admin@example.com
URI uri: https://example.com

Key Usage per server

Flag Descrizione Obbligatorio
digitalSignature Firmare TLS-Handshake
keyEncipherment RSA Key Exchange (non per ECDHE) Opzionale
keyAgreement ECDH Key Exchange Opzionale

File di output

server.csr.pem

-----BEGIN CERTIFICATE REQUEST-----
MIICxjCCAi0CAQAwgYExCz... (Base64 DER)
-----END CERTIFICATE REQUEST-----
Campo Valore
Version 1 (0x00)
Subject CN=www.example.com, O=Example SRL, C=IT
Public Key ML-DSA-65 (~1.952 Bytes)
Attributes Extension Request (SAN, Key Usage, EKU)
Signature ML-DSA-65 (Self-Proof-of-Possession)

Errori comuni

Problema Causa Soluzione
CSR rifiutato CN non in SAN Aggiungere sempre CN anche come SAN
CA non accetta CSR Formato errato Verificare formato PEM
Key Usage mancante Extensions non impostate Utilizzare ExtBuilder

Scenari correlati

Relazione Scenario Descrizione
Passo successivo 3.1 Certificato server Far firmare CSR dalla CA
Alternativo 2.3 CSR Multi-SAN Piu domini
Correlato 2.2 CSR client Per autenticazione client

« ← Panoramica CSR | ↑ Scenari | 2.2 CSR client → »


Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional