Jump to content

Recommended Posts

Posted (edited)
In the context of a complex project with stringent TLS requirements and various technical constraints, I decided to dive into the core of security mechanisms. While many off-the-shelf solutions exist for handling security contexts, I wanted to explore the fundamentals directly. Here, I’m sharing a raw and isolated excerpt of an AutoIt script that initializes a TLS security context using the Schannel API. This code is functional but deliberately minimal, providing a solid foundation for optimization and enhanced robustness.
 
image.thumb.png.e9adc1899b2c16da21af9deb98343cf6.png
 
#include-once
#include <WinAPI.au3>
#include <WinAPIError.au3>
#include <AutoItConstants.au3>
#include <Date.au3>

; Constantes Schannel
Global Const $SEC_E_OK = 0x00000000
Global Const $SEC_I_CONTINUE_NEEDED = 0x00090312
Global Const $SEC_E_INCOMPLETE_MESSAGE = 0x80090318
Global Const $SEC_E_INVALID_TOKEN = 0x80090308
Global Const $SECPKG_CRED_OUTBOUND = 2
Global Const $UNISP_NAME = "Microsoft Unified Security Protocol Provider"
Global Const $SCHANNEL_CRED_VERSION = 4
Global Const $SCH_CRED_NO_DEFAULT_CREDS = 0x00000010
Global Const $SCH_CRED_AUTO_CRED_VALIDATION = 0x00000020

; Flags pour InitializeSecurityContext
Global Const $ISC_REQ_SEQUENCE_DETECT = 0x00000008
Global Const $ISC_REQ_REPLAY_DETECT = 0x00000004
Global Const $ISC_REQ_CONFIDENTIALITY = 0x00000010
Global Const $ISC_REQ_ALLOCATE_MEMORY = 0x00000100
Global Const $ISC_REQ_STREAM = 0x00008000

; Types buffers
Global Const $SECBUFFER_TOKEN = 2
Global Const $SECBUFFER_EMPTY = 0

; Attributes QueryContextAttributes
Global Const $SECPKG_ATTR_REMOTE_CERT_CONTEXT = 0x53
Global Const $SECPKG_ATTR_CONNECTION_INFO = 0x5A

; Structures
Global Const $tagCRED_HANDLE = "struct;ULONG_PTR dwLower;ULONG_PTR dwUpper;endstruct;"
Global Const $tagSCHANNEL_CRED = "struct;" & _
        "dword dwVersion;" & _
        "dword dwCredFormat;" & _
        "dword cCreds;" & _
        "ptr paCred;" & _
        "ptr hRootStore;" & _
        "dword cMappers;" & _
        "ptr aphMappers;" & _
        "byte reserved[4];" & _
        "dword dwSessionLifespan;" & _
        "dword dwFlags;" & _
        "dword cTlsParameters;" & _
        "ptr pTlsParameters;" & _
        "endstruct;"
Global Const $tagSEC_BUFFER = "struct;dword cbBuffer;dword BufferType;ptr pvBuffer;endstruct;"
Global Const $tagSEC_BUFFER_DESC = "struct;dword ulVersion;dword cBuffers;ptr pBuffers;endstruct;"
Global Const $tagCERT_CONTEXT = "struct;" & _
        "dword dwCertEncodingType;" & _
        "ptr pbCertEncoded;" & _
        "dword cbCertEncoded;" & _
        "ptr pCertInfo;" & _
        "ptr hCertStore;" & _
        "endstruct;"
Global Const $tagCERT_INFO = "struct;" & _
        "dword dwVersion;" & _
        "dword cbSerialNumber;ptr pbSerialNumber;" & _
        "ptr pszObjId;dword cbData;ptr pbData;" & _
        "dword cbIssuer;ptr pbIssuer;" & _
        "dword NotBeforeLow;dword NotBeforeHigh;" & _
        "dword NotAfterLow;dword NotAfterHigh;" & _
        "dword cbSubject;ptr pbSubject;" & _
        "ptr pSubjectPublicKeyInfo;" & _
        "dword cbIssuerUniqueId;ptr pbIssuerUniqueId;" & _
        "dword cbSubjectUniqueId;ptr pbSubjectUniqueId;" & _
        "dword cExtension;" & _
        "ptr rgExtension;" & _
        "endstruct;"

; Variables globales
Global $iSocket = -1
Global $tCredHandle, $tCtxtHandle
Global $sHost = "www.google.com"
Global $g_iDetectedTLSVersion = 0

Func InitializeTLS()
    TCPStartup()
    Sleep(100) ; Initial delay to stabilize the network

    Local $sIP = TCPNameToIP($sHost)
    If @error Then
        ConsoleWrite("Error: Failed to establish TCP connection to " & $sHost & @CRLF)
        Cleanup()
        Return False
    EndIf

    $iSocket = TCPConnect($sIP, 443)
    If $iSocket = -1 Then
        ConsoleWrite("Error: Failed to establish TCP connection to " & $sHost & @CRLF)
        Cleanup()
        Return False
    EndIf

    $tCredHandle = _AcquireCredentialsHandle()
    If @error Then
        Cleanup()
        Return False
    EndIf

    Local $bResult = EstablishSecurityContext()
    If Not $bResult Then
        Cleanup()
    EndIf
    Return $bResult
EndFunc   ;==>InitializeTLS

Func _AcquireCredentialsHandle()
    Local $tCred = DllStructCreate($tagSCHANNEL_CRED)
    Local $tTimeStamp = DllStructCreate("dword;dword")
    Local $tHandle = DllStructCreate($tagCRED_HANDLE)

    DllStructSetData($tCred, "dwVersion", $SCHANNEL_CRED_VERSION)
    DllStructSetData($tCred, "dwCredFormat", 0)
    DllStructSetData($tCred, "cCreds", 0)
    DllStructSetData($tCred, "paCred", 0)
    DllStructSetData($tCred, "hRootStore", 0)
    DllStructSetData($tCred, "cMappers", 0)
    DllStructSetData($tCred, "aphMappers", 0)
    DllStructSetData($tCred, "dwSessionLifespan", 0)
    DllStructSetData($tCred, "dwFlags", BitOR($SCH_CRED_NO_DEFAULT_CREDS, $SCH_CRED_AUTO_CRED_VALIDATION))
    DllStructSetData($tCred, "cTlsParameters", 0)
    DllStructSetData($tCred, "pTlsParameters", 0)
    DllStructSetData($tCred, "grbitEnabledProtocols", BitOR(0x00000800, 0x00002000)) ; TLS 1.2 et 1.3

    Local $aRet = DllCall("secur32.dll", "long", "AcquireCredentialsHandleW", _
            "wstr", "", _
            "wstr", $UNISP_NAME, _
            "dword", $SECPKG_CRED_OUTBOUND, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($tCred), _
            "ptr", 0, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($tHandle), _
            "ptr", DllStructGetPtr($tTimeStamp))

    If @error Or $aRet[0] <> $SEC_E_OK Then
        ConsoleWrite("Error AcquireCredentialsHandle: " & Hex($aRet[0]) & @CRLF)
        Return SetError(1, 0, 0)
    EndIf

    ConsoleWrite("Credentials acquired successfully" & @CRLF)
    Return $tHandle
EndFunc   ;==>_AcquireCredentialsHandle

Func EstablishSecurityContext()
    Local $tInBufferDesc = DllStructCreate($tagSEC_BUFFER_DESC)
    Local $tOutBufferDesc = DllStructCreate($tagSEC_BUFFER_DESC)
    Local $tInBuffer = DllStructCreate($tagSEC_BUFFER)
    Local $tOutBuffer = DllStructCreate($tagSEC_BUFFER)
    Local $tCtxtNew = DllStructCreate($tagCRED_HANDLE)
    Local $tAttributes = DllStructCreate("dword")
    Local $tTimeStamp = DllStructCreate("dword;dword")

    DllStructSetData($tInBufferDesc, "ulVersion", 0)
    DllStructSetData($tInBufferDesc, "cBuffers", 1)
    DllStructSetData($tInBufferDesc, "pBuffers", DllStructGetPtr($tInBuffer))
    DllStructSetData($tInBuffer, "BufferType", $SECBUFFER_EMPTY)
    DllStructSetData($tInBuffer, "cbBuffer", 0)
    DllStructSetData($tInBuffer, "pvBuffer", 0)

    DllStructSetData($tOutBufferDesc, "ulVersion", 0)
    DllStructSetData($tOutBufferDesc, "cBuffers", 1)
    DllStructSetData($tOutBufferDesc, "pBuffers", DllStructGetPtr($tOutBuffer))
    DllStructSetData($tOutBuffer, "BufferType", $SECBUFFER_TOKEN)
    DllStructSetData($tOutBuffer, "cbBuffer", 0)
    DllStructSetData($tOutBuffer, "pvBuffer", 0)

    Local $dwFlags = BitOR($ISC_REQ_SEQUENCE_DETECT, $ISC_REQ_REPLAY_DETECT, _
            $ISC_REQ_CONFIDENTIALITY, $ISC_REQ_ALLOCATE_MEMORY, $ISC_REQ_STREAM)

    Local $scRet = $SEC_I_CONTINUE_NEEDED
    Local $bFirstCall = True

    While $scRet = $SEC_I_CONTINUE_NEEDED Or $scRet = $SEC_E_INCOMPLETE_MESSAGE
        ConsoleWrite("Calling InitializeSecurityContext (" & ($bFirstCall ? "first" : "subsequent") & ")" & @CRLF)

        Local $aRet = DllCall("secur32.dll", "long", "InitializeSecurityContextW", _
                "ptr", DllStructGetPtr($tCredHandle), _
                "ptr", ($bFirstCall ? 0 : DllStructGetPtr($tCtxtNew)), _
                "wstr", $sHost, _
                "dword", $dwFlags, _
                "dword", 0, _
                "dword", 0, _
                "ptr", ($bFirstCall ? 0 : DllStructGetPtr($tInBufferDesc)), _
                "dword", 0, _
                "ptr", DllStructGetPtr($tCtxtNew), _
                "ptr", DllStructGetPtr($tOutBufferDesc), _
                "ptr", DllStructGetPtr($tAttributes), _
                "ptr", DllStructGetPtr($tTimeStamp))

        If @error Then
            ConsoleWrite("DLL Call ERROR: " & @CRLF)
            Return False
        EndIf

        $scRet = $aRet[0]
        ConsoleWrite("hResult: " & Hex($scRet) & @CRLF)

        If $scRet = $SEC_E_OK Then
            ConsoleWrite("TLS connection successfully established!" & @CRLF)
            $tCtxtHandle = $tCtxtNew
            Return True
        ElseIf $scRet = $SEC_I_CONTINUE_NEEDED Or $scRet = $SEC_E_INCOMPLETE_MESSAGE Then
            If Not SendOutBuffer($tOutBuffer) Then
                Return False
            EndIf
            If Not ReceiveInputBuffer($tInBufferDesc, $tInBuffer) Then
                Return False
            EndIf
            If $bFirstCall Then $bFirstCall = False
        Else
            ConsoleWrite("Error InitializeSecurityContext: " & Hex($scRet) & @CRLF)
            Return False
        EndIf
    WEnd

    Return False
EndFunc   ;==>EstablishSecurityContext

Func SendOutBuffer(ByRef $tBuffer)
    Local $cbBuffer = DllStructGetData($tBuffer, "cbBuffer")
    If $cbBuffer <= 0 Then Return True

    Local $pvBuffer = DllStructGetData($tBuffer, "pvBuffer")
    Local $tData = DllStructCreate("byte[" & $cbBuffer & "]", $pvBuffer)
    Local $bData = DllStructGetData($tData, 1)
    ConsoleWrite("Send " & $cbBuffer & " octets (hex): " & StringLeft($bData, 100) & "..." & @CRLF)
    ConsoleWrite("Send (text) : " & StringLeft(BinaryToString($bData), 50) & "..." & @CRLF)

    TCPSend($iSocket, $bData)
    If @error Then
        ConsoleWrite("Errorr TCPSend: " & @error & @CRLF)
        Return False
    EndIf

    DllCall("secur32.dll", "long", "FreeContextBuffer", "ptr", $pvBuffer)
    DllStructSetData($tBuffer, "pvBuffer", 0)
    DllStructSetData($tBuffer, "cbBuffer", 0)

    Return True
EndFunc   ;==>SendOutBuffer

Func ReceiveInputBuffer(ByRef $tBufferDesc, ByRef $tBuffer)
    Local $bData = ""
    Local $iTimeout = TimerInit()

    While BinaryLen($bData) < 5 And TimerDiff($iTimeout) < 5000
        $bData = TCPRecv($iSocket, 8192, 1)
        If @error Then
            ConsoleWrite("Error TCPRecv: " & @error & @CRLF)
            Return False
        EndIf
        If BinaryLen($bData) > 0 Then ExitLoop
        Sleep(10)
    WEnd

    Local $iLen = BinaryLen($bData)
    If $iLen = 0 Then
        ConsoleWrite("Error: No data received after timeout" & @CRLF)
        Return False
    EndIf

    ConsoleWrite("Received " & $iLen & " bytes (hex): " & StringLeft($bData, 50) & "..." & @CRLF)
    ConsoleWrite("Received (text): " & StringLeft(BinaryToString($bData), 50) & "..." & @CRLF)

    If BinaryMid($bData, 1, 1) = 0x15 And $iLen >= 7 Then
        Local $iVersion = Number(BinaryMid($bData, 2, 2))
        Local $iLengthHi = Number(BinaryMid($bData, 4, 1))
        Local $iLengthLo = Number(BinaryMid($bData, 5, 1))
        Local $iLength = $iLengthHi * 256 + $iLengthLo
        Local $iLevel = Number(BinaryMid($bData, 6, 1))
        Local $iDesc = Number(BinaryMid($bData, 7, 1))
        ConsoleWrite("Alerte TLS détected: " & _
                "Version=0x" & Hex($iVersion, 4) & ", " & _
                "Length=" & $iLength & ", " & _
                "Level=" & ($iLevel = 2 ? "Fatal" : "Warning") & ", " & _
                "Description=" & $iDesc & " (" & GetAlertDescription($iDesc) & ")" & @CRLF)
    EndIf

    Local $tData = DllStructCreate("byte[" & $iLen & "]")
    DllStructSetData($tData, 1, $bData)

    DllStructSetData($tBuffer, "BufferType", $SECBUFFER_TOKEN)
    DllStructSetData($tBuffer, "cbBuffer", $iLen)
    DllStructSetData($tBuffer, "pvBuffer", DllStructGetPtr($tData))

    Return True
EndFunc   ;==>ReceiveInputBuffer

Func GetAlertDescription($iDesc)
    Switch $iDesc
        Case 0
            Return "Close Notify"
        Case 10
            Return "Unexpected Message"
        Case 40
            Return "Handshake Failure"
        Case 70
            Return "Protocol Version"
        Case 112
            Return "Unrecognized Name"
        Case Else
            Return "Unknown Alert"
    EndSwitch
EndFunc   ;==>GetAlertDescription

Func DisplayCertInfo()
    Local $tCertContextPtr = DllStructCreate("ptr")

    Local $aRet = DllCall("secur32.dll", "long", "QueryContextAttributesW", _
            "ptr", DllStructGetPtr($tCtxtHandle), _
            "dword", $SECPKG_ATTR_REMOTE_CERT_CONTEXT, _
            "ptr", DllStructGetPtr($tCertContextPtr))

    If @error Or $aRet[0] <> $SEC_E_OK Then
        ConsoleWrite("Error QueryContextAttributesW (cert): " & Hex($aRet[0]) & @CRLF)
        Return
    EndIf

    Local $pCertContext = DllStructGetData($tCertContextPtr, 1)
    If $pCertContext = 0 Then
        ConsoleWrite("Error: No certificate retrieved" & @CRLF)
        Return
    EndIf

    Local $tCertContext = DllStructCreate($tagCERT_CONTEXT, $pCertContext)
    Local $pCertInfo = DllStructGetData($tCertContext, "pCertInfo")
    Local $tCertInfo = DllStructCreate($tagCERT_INFO, $pCertInfo)

    Local $tConnInfo = DllStructCreate("struct;dword dwProtocol;dword aiCipher;dword dwCipherStrength;dword aiHash;dword dwHashStrength;dword aiExch;dword dwExchStrength;endstruct;")
    $aRet = DllCall("secur32.dll", "long", "QueryContextAttributesW", _
            "ptr", DllStructGetPtr($tCtxtHandle), _
            "dword", $SECPKG_ATTR_CONNECTION_INFO, _
            "ptr", DllStructGetPtr($tConnInfo))

    If @error Or $aRet[0] <> $SEC_E_OK Then
        ConsoleWrite("Error QueryContextAttributesW (conn): " & Hex($aRet[0]) & @CRLF)
    EndIf

    ConsoleWrite("🔒 SSL CERTIFICATE INFO" & @CRLF)
    ConsoleWrite("======================================" & @CRLF)

    ConsoleWrite("🏷️  Subject: " & GetCertNameString($pCertContext, False) & @CRLF)
    ConsoleWrite("🏛️  Issued by: " & GetCertNameString($pCertContext, True) & @CRLF)

    Local $tNotAfter = DllStructCreate($tagFILETIME)
    DllStructSetData($tNotAfter, "Lo", DllStructGetData($tCertInfo, "NotAfterLow"))
    DllStructSetData($tNotAfter, "Hi", DllStructGetData($tCertInfo, "NotAfterHigh"))
    Local $sExpiration = FileTimeToString($tNotAfter)
    ConsoleWrite("📅 Expiration: " & $sExpiration & @CRLF)

    Local $tNotBefore = DllStructCreate($tagFILETIME)
    DllStructSetData($tNotBefore, "Lo", DllStructGetData($tCertInfo, "NotBeforeLow"))
    DllStructSetData($tNotBefore, "Hi", DllStructGetData($tCertInfo, "NotBeforeHigh"))
    Local $sValidFrom = FileTimeToString($tNotBefore)
    ConsoleWrite("📅 Valid from: " & $sValidFrom & @CRLF)

    ConsoleWrite("ConnInfo: " & _
            "Protocol=0x" & Hex(DllStructGetData($tConnInfo, "dwProtocol"), 4) & ", " & _
            "Cipher=0x" & Hex(DllStructGetData($tConnInfo, "aiCipher"), 4) & ", " & _
            "Strength=" & DllStructGetData($tConnInfo, "dwCipherStrength") & ", " & _
            "Hash=0x" & Hex(DllStructGetData($tConnInfo, "aiHash"), 4) & ", " & _
            "HashStrength=" & DllStructGetData($tConnInfo, "dwHashStrength") & ", " & _
            "Exch=0x" & Hex(DllStructGetData($tConnInfo, "aiExch"), 4) & ", " & _
            "ExchStrength=" & DllStructGetData($tConnInfo, "dwExchStrength") & @CRLF)

    Local $dwProtocol = DllStructGetData($tConnInfo, "dwProtocol")
    Local $sProtocol = GetProtocolName($dwProtocol)
    ConsoleWrite("🔒 SSL Protocol: " & $sProtocol & " (raw value: 0x" & Hex($dwProtocol, 4) & ")" & @CRLF)
    ConsoleWrite("CERT_INFO Data: Version=" & DllStructGetData($tCertInfo, "dwVersion") & ", pszObjId=" & DllStructGetData($tCertInfo, "pszObjId") & @CRLF)
    ConsoleWrite("🖊️  Signature Algorithm: " & GetSignatureAlgorithm($pCertInfo) & @CRLF)
    Local $sCipher = GetCipherName(DllStructGetData($tConnInfo, "aiCipher"))
    ConsoleWrite("🔑 Encryption Algorithm: " & $sCipher & @CRLF)
    Local $iCipherStrength = DllStructGetData($tConnInfo, "dwCipherStrength")
    ConsoleWrite("🛠️  Key Size: " & $iCipherStrength & " bits" & @CRLF)

    DllCall("crypt32.dll", "bool", "CertFreeCertificateContext", "ptr", $pCertContext)
EndFunc   ;==>DisplayCertInfo

Func GetCertNameString($pCertContext, $bIssuer = False)
    Local Const $CERT_NAME_SIMPLE_DISPLAY_TYPE = 4
    Local Const $CERT_NAME_ISSUER_FLAG = 0x1

    Local $dwFlags = ($bIssuer ? $CERT_NAME_ISSUER_FLAG : 0)
    Local $aRet = DllCall("crypt32.dll", "dword", "CertGetNameStringW", _
            "ptr", $pCertContext, _
            "dword", $CERT_NAME_SIMPLE_DISPLAY_TYPE, _
            "dword", $dwFlags, _
            "ptr", 0, _
            "wstr", 0, _
            "dword", 0)

    If @error Then
        Return "Error DLL: " & @error
    EndIf

    Local $iLength = $aRet[0]
    If $iLength <= 1 Then
        Return ""
    EndIf

    Local $tBuffer = DllStructCreate("wchar[" & $iLength & "]")
    $aRet = DllCall("crypt32.dll", "dword", "CertGetNameStringW", _
            "ptr", $pCertContext, _
            "dword", $CERT_NAME_SIMPLE_DISPLAY_TYPE, _
            "dword", $dwFlags, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($tBuffer), _
            "dword", $iLength)

    If @error Or $aRet[0] <= 1 Then
        Return ""
    EndIf

    Return DllStructGetData($tBuffer, 1)
EndFunc   ;==>GetCertNameString

Func GetProtocolName($dwProtocol)
    Switch $dwProtocol
        Case 0x0080
            Return "SSL 2.0"
        Case 0x0300
            Return "SSL 3.0"
        Case 0x0301
            Return "TLS 1.0"
        Case 0x0302
            Return "TLS 1.1"
        Case 0x0800
            Return "TLS 1.2"
        Case 0x1000
            Return "TLS 1.3"
        Case Else
            Return "Inconnu (0x" & Hex($dwProtocol, 4) & ")"
    EndSwitch
EndFunc   ;==>GetProtocolName

Func GetSignatureAlgorithm($pCertInfo)
    Local $tCertInfo = DllStructCreate($tagCERT_INFO, $pCertInfo)
    Local $pszObjId = DllStructGetData($tCertInfo, "pszObjId")
    ConsoleWrite("OID brut : " & $pszObjId & @CRLF)
    Switch $pszObjId
        Case "1.2.840.113549.1.1.11"
            Return "SHA256withRSA"
        Case "1.2.840.113549.1.1.12"
            Return "SHA384withRSA"
        Case "1.2.840.10045.4.3.2"
            Return "ECDSAwithSHA256"
        Case "1.2.840.10045.4.3.3"
            Return "ECDSAwithSHA384"
        Case Else
            Return "Inconnu (OID: " & $pszObjId & ")"
    EndSwitch
EndFunc   ;==>GetSignatureAlgorithm

Func GetCipherName($aiCipher)
    Switch $aiCipher
        Case 0x0000660E
            Return "AES-128"
        Case 0x0000660F
            Return "AES-256"
        Case 0x00000002
            Return "RC4"
        Case 0x00000005
            Return "3DES"
        Case Else
            Return "Inconnu (0x" & Hex($aiCipher, 4) & ")"
    EndSwitch
EndFunc   ;==>GetCipherName

Func Cleanup()
    If IsDllStruct($tCtxtHandle) Then
        DllCall("secur32.dll", "long", "DeleteSecurityContext", "ptr", DllStructGetPtr($tCtxtHandle))
        $tCtxtHandle = 0
    EndIf
    If IsDllStruct($tCredHandle) Then
        DllCall("secur32.dll", "long", "FreeCredentialsHandle", "ptr", DllStructGetPtr($tCredHandle))
        $tCredHandle = 0
    EndIf
    If $iSocket <> -1 Then
        TCPCloseSocket($iSocket)
        $iSocket = -1
    EndIf
    TCPShutdown()
EndFunc   ;==>Cleanup

Func FileTimeToString($tFileTime)
    Local $tSystemTime = DllStructCreate("word wYear;word wMonth;word wDayOfWeek;word wDay;word wHour;word wMinute;word wSecond;word wMilliseconds")
    Local $aRet = DllCall("kernel32.dll", "none", "FileTimeToSystemTime", _
            "ptr", DllStructGetPtr($tFileTime), _
            "ptr", DllStructGetPtr($tSystemTime))

    If @error Or $aRet[0] <> 0 Then
        ConsoleWrite("Erreur FileTimeToSystemTime: " & @error & @CRLF)
        Return "Erreur"
    EndIf

    Return StringFormat("%04d/%02d/%02d %02d:%02d:%02d UTC", _
            DllStructGetData($tSystemTime, "wYear"), _
            DllStructGetData($tSystemTime, "wMonth"), _
            DllStructGetData($tSystemTime, "wDay"), _
            DllStructGetData($tSystemTime, "wHour"), _
            DllStructGetData($tSystemTime, "wMinute"), _
            DllStructGetData($tSystemTime, "wSecond"))
EndFunc   ;==>FileTimeToString



; Execution
If InitializeTLS() Then
    ConsoleWrite("TLS connection successful!" & @CRLF)
    Sleep(300)
    DisplayCertInfo()
Else
    ConsoleWrite("TLS connection failed" & @CRLF)
EndIf
Cleanup()

 

 
Edited by Numeric1
Posted
#include <Print.au3> ; I'd like that too
Credentials acquired successfully
Calling InitializeSecurityContext (first)
hResult: 00090312
Send 196 octets (hex): 0x16FEFD000000000000000000B7010000AB00000000000000ABFEFD685ED6BBEADE75B6F57B4AE8946D5DB4C1F8D86F4B37...
Send (text) : þýReceived 7 bytes (hex): 0x15030100020246...
Received (text): Alerte TLS détected: Version=0x0103, Length=2, Level=Fatal, Description=70 (Protocol Version)
Calling InitializeSecurityContext (subsequent)
hResult: 80090308
Error InitializeSecurityContext: 80090308
TLS connection failed

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
4 minutes ago, argumentum said:
#include <Print.au3> ; I'd like that too
Credentials acquired successfully
Calling InitializeSecurityContext (first)
hResult: 00090312
Send 196 octets (hex): 0x16FEFD000000000000000000B7010000AB00000000000000ABFEFD685ED6BBEADE75B6F57B4AE8946D5DB4C1F8D86F4B37...
Send (text) : þýReceived 7 bytes (hex): 0x15030100020246...
Received (text): Alerte TLS détected: Version=0x0103, Length=2, Level=Fatal, Description=70 (Protocol Version)
Calling InitializeSecurityContext (subsequent)
hResult: 80090308
Error InitializeSecurityContext: 80090308
TLS connection failed

 

PSS!  Automatic reconnection attempts are not handled in this code snippet. If the connection fails, you will need to retry manually.
I do not recommend using a simple loop for retrying, as successful reconnection may depend on other external factors (e.g., timing, network state, server readiness).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...