TsgcWebSocketClient | Certificados SChannel

Cuando el servidor requiere que el cliente se conecte usando un certificado SSL, utilice la propiedad TLSOptions de TsgcWebSocketClient para establecer los archivos de certificado.

 

La conexión a través de SChannel requiere que TLSOptions.IOHandler = iohSChannel.

 

SChannel admite 2 tipos de autenticación de certificados:

 

1. Uso de un certificado PFX

2. Establecer el Hash del Certificado de un certificado ya instalado en el sistema Windows.

 

Certificado PFX

Un certificado PFX es un archivo que contiene el certificado y la clave privada. En ocasiones dispone de un certificado en formato PEM, por lo que antes de utilizarlo debe convertirlo a PFX.

Use el siguiente comando openssl para convertir un certificado PEM a PFX

 


openssl pkcs12 -inkey certificate-pem.key -in certificate-pem.crt -export -out certificate.pfx

Una vez que el certificado está en formato PFX, solo necesita desplegar el certificado y establecer la propiedad TLSOptions.CertFile con su ruta.

 


TLSOptions.IOHandler = iohSChannel
TLSOptions.CertFile = <certificate path>
TLSOptions.Password = <certificate optional password>

 

Hash Certificate

Si el certificado ya está instalado en el almacén de certificados de Windows, solo necesita conocer la huella digital del certificado y establecerla en la propiedad TLSOptions.SChannel_Options.

 

Encontrar el hash de un certificado es tan sencillo en powershell como ejecutar un comando dir en el contenedor de certificados.

dir cert:\localmachine\my

El hash es el valor hexadecimal Thumbprint.


Directory: Microsoft.PowerShell.Security\Certificate::localmachine\my
Thumbprint                                Subject
----------                                -------
C12A8FC8AE668F866B48F23E753C93D357E9BE10  CN=*.mydomain.com

Una vez que tenga el valor Thumbprint, debe establecer el hash y la ubicación del certificado en la propiedad TLSOptions.SChannel_Options.


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>