SSLCreateFlags Example for VB.NET

' 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
Dim DicomKernel As New LTDicomKernelLib.LEADDicomKernel

Public WithEvents LEADDICOMNET1 As LTDNCLib.LEADDicomNet
Const CA_CERT_NAME As String = "e:\certificates\ca.pem"
Const SERVER_CERT_NAME As String = "e:\certificates\server.pem"
Private Sub TestSSLCreateFlags()
   Dim szMsg As String
   Dim nRet As Short
   LEADDICOMNET1.UseSSLOptions = True
   LEADDICOMNET1.SSLCreateFlags = LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_CAFILE Or LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_METHOD_TYPE Or LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_OPTIONS Or LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_VERIFY_DEPTH Or LTDNCLib.DicomSSLCreateFlags.DICOM_SSL_CTX_CREATE_VERIFY_MODE
   LEADDICOMNET1.SSLCAFile = CA_CERT_NAME
   LEADDICOMNET1.SSLVerifyMode = LTDNCLib.DicomSSLVerifyMode.DICOM_SSL_VERIFY_PEER Or LTDNCLib.DicomSSLVerifyMode.DICOM_SSL_VERIFY_FAIL_IF_NO_PEER_CERT
   LEADDICOMNET1.SSLVerifyDepth = 2
   LEADDICOMNET1.SSLOptions = LTDNCLib.DicomSSLOptions.DICOM_SSL_OP_NO_SSLv2 Or LTDNCLib.DicomSSLOptions.DICOM_SSL_OP_ALL
   LEADDICOMNET1.NetworkSecurityMode = LTDNCLib.DicomSecurityModes.DICOM_SECURE_TLS
   LEADDICOMNET1.StartUp()
   nRet = LEADDICOMNET1.SetServerCertificateTLS(LEADDICOMNET1.hNet, SERVER_CERT_NAME, LTDNCLib.DicomTLSCertType.L_TLS_FILETYPE_PEM, SERVER_CERT_NAME)
   If nRet = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
      szMsg = SERVER_CERT_NAME & " loaded successfully"
   Else
      szMsg = SERVER_CERT_NAME & " could not be loaded successfully -- error " & CStr(nRet)
   End If
   MessageBox.Show(szMsg)
   '
   ' Use the hNet

End Sub