SSLCreateFlags Example for C#
// This sample creates an ILEADDicomNet object with security
// The ILEADDicomNet object is configured so that if a client connects:
// 1. it requires and verifies the client certificate
// 2. it will support SSL version 3 or TLS Version 1 for the handshake
// 3. it uses trusted certificate authority CA_CERT_NAME to verify the
client certificate
// 4. it verifies the client certificate chain to a maximum depth of 2
//
// The ILEADDicomNet object is assigned the certificate SERVER_CERT_NAME,
// which contains a password encrypted private key
// The DicomNet_SSLPrivateKeyPasswordEvent
is used
// to supply the encryption password of the private key
private LTDicomKernelLib.LEADDicomKernel DicomKernel = new LTDicomKernelLib.LEADDicomKernel();
public LTDNCLib.LEADDicomNet LEADDICOMNet1 = null ;
private const string CA_CERT_NAME = "e:\\certificates\\ca.pem";
private const string SERVER_CERT_NAME = "e:\\certificates\\server.pem";
private void TestSSLCreateFlags()
{
string szMsg = null;
short nRet = 0;
LEADDICOMNet1.UseSSLOptions
= true;
LEADDICOMNet1.SSLCreateFlags
= LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_CAFILE | LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_METHOD_TYPE
| LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_OPTIONS | LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_VERIFY_DEPTH
| LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_VERIFY_MODE;
LEADDICOMNet1.SSLCAFile
= CA_CERT_NAME;
LEADDICOMNet1.SSLVerifyMode
= LTDNCLib.DicomSSLVerifyMode.DICOM_SSL_VERIFY_PEER | LTDNCLib.DicomSSLVerifyMode.DICOM_SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
LEADDICOMNet1.SSLVerifyDepth = 2;
LEADDICOMNet1.SSLOptions
= LTDNCLib.DicomSSLOptions.DICOM_SSL_OP_NO_SSLv2 | LTDNCLib.DicomSSLOptions.DICOM_SSL_OP_ALL;
LEADDICOMNet1.NetworkSecurityMode
= (int)LTDNCLib.DicomSecurityModes.DICOM_SECURE_TLS;
LEADDICOMNet1.StartUp();
nRet = LEADDICOMNet1.SetServerCertificateTLS(LEADDICOMNet1.hNet,
SERVER_CERT_NAME, (int)LTDNCLib.DicomTLSCertType.L_TLS_FILETYPE_PEM, SERVER_CERT_NAME);
if (nRet == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
szMsg = SERVER_CERT_NAME + " loaded
successfully";
else
szMsg = SERVER_CERT_NAME + " could
not be loaded successfully -- error " + System.Convert.ToString(nRet);
MessageBox.Show(szMsg);
//
// Use the hNet
//
}