À partir de sgcWebSockets 4.4.7, l'utilisation de certificats avec SChannel comme bibliothèque cryptographique est prise en charge.
L'implémentation SChannel prend en charge 2 types d'authentification par certificat :
1. Avec un certificat PFX
2. En définissant le Hash Thumbprint d'un certificat déjà installé dans le système Windows.
Certificat PFX
Le certificat PFX est un fichier qui contient le certificat et la clé privée ; parfois, tu as un certificat au format PEM, et avant de l'utiliser, tu dois le convertir en PFX.
Utilise la commande openssl suivante pour convertir un certificat PEM en PFX :
openssl pkcs12 -inkey certificate-pem.key -in certificate-pem.crt -export -out certificate.pfx
Une fois le certificat au format PFX, il suffit de déployer le certificat et de définir dans la propriété TLSOptions.Certificate son chemin.
TLSOptions.IOHandler := iohSChannel; TLSOptions.CertFile := '<certificate path>'; TLSOptions.Password := '<certificate optional password>';
Hash Thumbprint
Si le certificat est déjà installé dans le magasin de certificats Windows, tu n'as qu'à connaître l'empreinte du certificat et la définir dans la propriété TLSOptions.SChannel_Options.
Trouver l'empreinte d'un certificat est aussi simple en PowerShell que d'exécuter une commande dir sur le conteneur des certificats.
dir cert:\localmachine\my
L'empreinte est la valeur hexadécimale Thumbprint.
Directory: Microsoft.PowerShell.Security\Certificate::localmachine\myThumbprint Subject---------- -------C12A8FC8AE668F866B48F23E753C93D357E9BE10 CN=*.mydomain.com
Une fois la valeur Thumbprint en ta possession, tu dois définir dans la propriété TLSOptions.SChannel_Options l'empreinte et l'emplacement du certificat.
TLSOptions.IOHandler := iohSChannel; TLSOptions.SChannel_Options.CertHash := '<certificate thumbprint>'; TLSOptions.SChannel_Options.CertStoreName := '<certificate store name>'; TLSOptions.SChannel_Options.CertStorePath := '<certificate store path>'; TLSOptions.Password := '<certificate optional password>';
