Usage of TLS 1.3 protocol using SCHANNEL in C++ language for TCP/IP

G S, Shashank 0 Reputation points
2025-07-30T09:34:50.8566667+00:00

We are trying to build one sample application using only TLS 1.3(No fallback to older TLS versions) protocol with below registries added, 

  1. [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000
  2. [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000

But when we run the client application, we are getting SEC_E_ALGORITHM_MISMATCH (0x80090331) error from AcquireCredentialsHandle API. Sample application (Socket) is to use only TLS1.3 for TCP/IP communication using SCHANNEL in C++ language

Standalone TLS 1.3 works in windows 11 or we need to use TLS 1.2 along with TLS 1.3 protocol?

Developer technologies | C++
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 795 Reputation points Microsoft External Staff
    2025-08-04T08:07:50.0733333+00:00

    Thank you for reaching out. Please find the steps below.

    Registry Configuration (Enable TLS 1.3): Run in Command Prompt as Admin or save as .reg file and double-click:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client]
    "Enabled"=dword:00000001
    "DisabledByDefault"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server]
    "Enabled"=dword:00000001
    "DisabledByDefault"=dword:00000000
    

    After applying, reboot your system.

    Enable TLS 1.3 Cipher Suites\ Run in PowerShell as Administrator:

    Enable-TlsCipherSuite -Name "TLS_AES_256_GCM_SHA384"
    Enable-TlsCipherSuite -Name "TLS_AES_128_GCM_SHA256"
    Enable-TlsCipherSuite -Name "TLS_CHACHA20_POLY1305_SHA256"
    

    Alternatively, set via registry:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002]
    "Functions"="TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256,TLS_CHACHA20_POLY1305_SHA256"
    

    Reboot after applying changes.

    Enable SChannel Logging for Debugging\ Run in PowerShell as Administrator:

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL" `
    -Name "EventLogging" -Value 7 -PropertyType "DWord" -Force
    

    Logs will appear in Event Viewer → Applications and Services Logs → Microsoft → Windows → Schannel

    C++ Code Using SCH_CREDENTIALS for TLS 1.3

    #
    #
    #
    #
    
    int main() {
        SCH_CREDENTIALS schCred = {};
        schCred.dwVersion = SCH_CREDENTIALS_VERSION;
        schCred.dwFlags = SCH_CRED_NO_DEFAULT_CREDS | SCH_CRED_MANUAL_CRED_VALIDATION;
    
        CredHandle hCred;
        TimeStamp tsExpiry;
    
        SECURITY_STATUS status = AcquireCredentialsHandle(
            NULL,
            UNISP_NAME,
            SECPKG_CRED_OUTBOUND,
            NULL,
            &schCred,
            NULL,
            NULL,
            &hCred,
            &tsExpiry
        );
    
        if (status != SEC_E_OK) {
            printf("TLS handshake failed with error: 0x%08lx\n", status);
            return 1;
        }
    
        printf("TLS credentials acquired successfully.\n");
        return 0;
    }
    

    Note:\ Do not set grbitEnabledProtocols unless debugging.\ To temporarily allow TLS 1.2 during development, add:

    schCred.grbitEnabledProtocols = SP_PROT_TLS1_3 | SP_PROT_TLS1_2;
    

    Remove TLS 1.2 once TLS 1.3 works reliably.

    Testing TLS 1.3 Connection

    Use OpenSSL to verify TLS 1.3 handshake:

    openssl s_client -connect yourserver.com:443 -tls1_3
    

    Use Wireshark to inspect TLS versions in Client Hello and Server Hello packets.

    Let us know if the issue persists after following these steps. We’ll be happy to assist further if needed.
    If this helps, please mark as Answered.


  2. Susmitha T (INFOSYS LIMITED) 160 Reputation points Microsoft External Staff
    2025-08-04T10:30:54.81+00:00

    Thank you for reaching out Please find the solution below.

    Registry Configuration (Enable TLS 1.3) \ Run in Command Prompt as Admin or save as .reg file and double-click:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client]"Enabled"=dword:00000001"DisabledByDefault"=dword:00000000[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server]"Enabled"=dword:00000001"DisabledByDefault"=dword:00000000
    

    After applying, reboot your system.

    Enable TLS 1.3 Cipher Suites\ Run in PowerShell as Administrator:

    Enable-TlsCipherSuite -Name "TLS_AES_256_GCM_SHA384"Enable-TlsCipherSuite -Name "TLS_AES_128_GCM_SHA256"Enable-TlsCipherSuite -Name "TLS_CHACHA20_POLY1305_SHA256"
    

    Alternatively, set via registry:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002]"Functions"="TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256,TLS_CHACHA20_POLY1305_SHA256"
    

    Reboot after applying changes.

    Enable SChannel Logging for Debugging\ Run in PowerShell as Administrator:

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL" `-Name "EventLogging" -Value 7 -PropertyType "DWord" -Force
    

    Logs will appear in Event Viewer → Applications and Services Logs → Microsoft → Windows → Schannel

    **C++ Code Using SCH_CREDENTIALS for TLS 1.3
    **
    #include <windows.h>

     

    #include <sspi.h>

     

    #include <schannel.h>

     

    #include <security.h> 

     

    int main() {

     

        SCH_CREDENTIALS schCred = {};

     

        schCred.dwVersion = SCH_CREDENTIALS_VERSION;

     

        schCred.dwFlags = SCH_CRED_NO_DEFAULT_CREDS | SCH_CRED_MANUAL_CRED_VALIDATION;

     

        CredHandle hCred;

     

        TimeStamp tsExpiry;

     

        SECURITY_STATUS status = AcquireCredentialsHandle(

     

            NULL,

     

            UNISP_NAME,

     

            SECPKG_CRED_OUTBOUND,

     

            NULL,

     

            &schCred,

     

            NULL,

     

            NULL,

     

            &hCred,

     

            &tsExpiry

     

        );

     

        if (status != SEC_E_OK) {

     

            printf("TLS handshake failed with error: 0x%08lx\n", status);

     

            return 1;

     

        }

     

        printf("TLS credentials acquired successfully.\n");

     

        return 0;

     

    }

     

    Note: Do not set grbitEnabledProtocols unless debugging.\ To temporarily allow TLS 1.2 during development, add:

    schCred.grbitEnabledProtocols = SP_PROT_TLS1_3 | SP_PROT_TLS1_2;
    

    Remove TLS 1.2 once TLS 1.3 works reliably.

    Testing TLS 1.3 Connection

    Use OpenSSL to verify TLS 1.3 handshake:

    openssl s_client -connect yourserver.com:443 -tls1_3
    

    Use Wireshark to inspect TLS versions in Client Hello and Server Hello packets.

    Let us know if the issue persists after following these steps. We’ll be happy to assist further if needed.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.