
SRO PKCS11 – SSH Agent CNG è un agente Windows sovrano, ultra‑leggero e zero‑dipendenze che unifica PKCS#11, SSH-agent, Pageant e CNG/Smartcard in un unico binario robusto. Progettato per ambienti esigenti, offre crittografia hardware nativa, isolamento service/userland, supporto completo per smartcard.
Unificazione sovrana PKCS#11 + SSH-agent + Pageant + CNG/Smartcard
Un unico eseguibile Windows che unifica quattro funzioni tradizionalmente separate:
Sovrano. Nessuna dipendenza dalla CRT. Tutte le operazioni di memoria passano attraverso RtlCopyMemory, RtlZeroMemory, RtlEqualMemory (FreeCRT.h). Unicode ovunque (Win32 nativo). Nessun malloc, memcpy, strlen, printf.
Sicuro. Le chiavi private non vengono mai esportate. Nessun PIN transita. CNG/KSP gestisce l'interfaccia PIN nativa di Windows. Isolamento rigoroso servizio ↔ userland tramite pipe sicuri.
Minimalista. Un singolo binario. Nessuna DLL esterna. Nessun gonfiamento del registro. Installazione semplice (regsvr32 o -install).
Versatile. Supporto simultaneo di PKCS#11, SSH-agent, Pageant e WSL2 nello stesso processo.
┌──────────────────────────────────────────────────────────────┐ │ Clients (Git, VS, WSL, OpenSSH, PuTTY, Firefox) │ └────────────────────────┬─────────────────────────────────────┘ │ ┌───────────────┼───────────────┬─────────────────┐ │ │ │ │ SSH-agent Pageant (WM_COPYDATA) PKCS#11 WSL2 (TCP) │ │ │ │ v v v v ┌──────────────────────────────────────────────────────────────┐ │ Service Stub (session 0, SYSTEM) │ │ - Accepte connexions sur \.\pipe\openssh-ssh-agent │ │ - Crée pipe interne par client (GUID unique) │ │ - Lance helper userland avec token interactif │ │ - Forwarde messages sans manipuler de secrets │ └────────────────────────┬─────────────────────────────────────┘ │ lancé par le service v ┌──────────────────────────────────────────────────────────────┐ │ Helper Userland (session interactive) │ │ - Connecte au pipe interne │ │ - Décode protocole SSH-agent/Pageant │ │ - Invoque CNG/KSP pour signature │ │ - UI PIN native Windows (pas de relay) │ │ - Renvoie signature au service │ │ - Fenêtre Pageant cachée pour WM_COPYDATA │ │ - Listener TCP 127.0.0.1:10022 pour WSL2 │ │ - Tray icon avec menu contextuel │ └────────────────────────┬─────────────────────────────────────┘ │ v ┌──────────────────────────────────────────────────────────────┐ │ CNG/KSP Backend │ │ - NCryptSignHash avec PKCS#1/PSS padding │ │ - Enumération certificats Windows Store │ │ - Filtrage SmartCardOnly / AllowedKSP │ │ - Support RSA + ECDSA (P-256, P-384, P-521) │ │ - Support EdDSA (Ed25519, Ed448) │ │ - Support Brainpool (P256r1, P384r1, P512r1) │ │ - Cache clés + providers (4h timeout) │ └──────────────────────────────────────────────────────────────┘
---
## Modalità di esecuzione
### 1. Modalità PKCS#11 (automatica)
Caricato da:
- `ssh -I ssh-agent.exe user@host`
- Firefox (Dispositivi di sicurezza → Carica modulo PKCS#11)
- `pkcs11-tool --module ssh-agent.exe --list-objects`
Espone le esportazioni PKCS#11 standard:
- `C_Initialize`, `C_Finalize`, `C_GetInfo`
- `C_GetSlotList`, `C_GetSlotInfo`, `C_GetTokenInfo`
- `C_GetMechanismList`, `C_GetMechanismInfo`
- `C_OpenSession`, `C_CloseSession`, `C_Login`, `C_Logout`
- `C_FindObjectsInit`, `C_FindObjects`, `C_FindObjectsFinal`
- `C_GetAttributeValue`
- `C_SignInit`, `C_Sign`
- `C_VerifyInit`, `C_Verify`
- `C_DecryptInit`, `C_Decrypt`
- `C_GenerateRandom`, `C_SeedRandom`
**Meccanismi supportati (14 in totale):**
- `CKM_RSA_PKCS` (raw con padding)
- `CKM_RSA_X_509` (raw senza padding)
- `CKM_SHA1_RSA_PKCS` (legacy ssh-rsa)
- `CKM_SHA256_RSA_PKCS` (rsa-sha2-256)
- `CKM_SHA384_RSA_PKCS` (rsa-sha2-384)
- `CKM_SHA512_RSA_PKCS` (rsa-sha2-512)
- `CKM_SHA256_RSA_PKCS_PSS` (RSA-PSS SHA-256)
- `CKM_SHA384_RSA_PKCS_PSS` (RSA-PSS SHA-384)
- `CKM_SHA512_RSA_PKCS_PSS` (RSA-PSS SHA-512)
- `CKM_ECDSA` (raw)
- `CKM_ECDSA_SHA1` (legacy)
- `CKM_ECDSA_SHA256` (ecdsa-sha2-nistp256/384/521)
- `CKM_ECDSA_SHA384`
- `CKM_ECDSA_SHA512`
### 2. Modalità agente userland (standalone)```bash
ssh-agent.exe
\\.\pipe\openssh-ssh-agent nella sessione utenteCompatibile con :
set SSH_AUTH_SOCK=\\.\pipe\openssh-ssh-agent)ssh-agent.exe -install net start SROSSHAgentCNG
- Gira in sessione 0 (SYSTEM)
- Accetta connessioni su pipe globale
- Crea un pipe interno per client (protetto da SID)
- Avvia un helper userland con `CreateProcessAsUserW`
- Inoltra i messaggi senza toccare i segreti
- Pool di helper con timeout 4h (riutilizzo automatico)
- Espulsione LRU se pool pieno
**Vantaggi:**
- PIN UI nella sessione utente (non in sessione 0)
- Compatibile con ambienti rinforzati
- Isolamento stretto servizio ↔ crypto
- Multiplexing multi-utenti
### 4. Modalità helper crypto userland```bash
ssh-agent.exe -useragent -pipe \\.\pipe\ssh-ksp-helper-{GUID}
Avviato automaticamente dal servizio:
NCryptSignHash (interfaccia PIN nativa)regsvr32 ssh-agent.exe
Crea le chiavi:
- `HKLM\SOFTWARE\San@sro Inc\PKCS11-SSH-Agent`
- `HKCU\SOFTWARE\San@sro Inc\PKCS11-SSH-Agent`
- `HKCU\SOFTWARE\Mozilla\Firefox\PKCS11Modules\SROSSHAgent`