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

G S, Shashank 5 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} vote

5 answers

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 1,110 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. Varsha Dundigalla(INFOSYS LIMITED) 1,110 Reputation points Microsoft External Staff
    2025-08-28T12:06:16.82+00:00

    Thank you for your response.

    Could you please share a sample of the code you're running? I’d like to try reproducing the issue and check if it’s environment specific.

    please make sure it does not have any confidential info, then we can try to execute it.

    0 comments No comments

  3. Susmitha T (INFOSYS LIMITED) 575 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

  4. Varsha Dundigalla(INFOSYS LIMITED) 1,110 Reputation points Microsoft External Staff
    2025-08-13T12:26:52.2833333+00:00

    Thank you for sharing details.

    I didn’t know this before now I understand why my grbitEnabledProtocols approach for TLS 1.3 failed.

    Windows ignores grbitEnabledProtocols for TLS 1.3. Instead, protocol selection is controlled by system registry settings and cipher suite configuration.

    This is why my previous method didn’t work even though it’s valid for older TLS versions, it has no effect for TLS 1.3.

    Step-by-Step Setup

    1. Enable TLS 1.3 in the Registry (Run as Admin)
    reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client" /v Enabled /t REG_DWORD /d 1 /f
    reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f
    

    Reboot your system after running these commands — SCHANNEL must reload its configuration.

    1. Configure TLS 1.3 Cipher Suites in Code
    #include <windows.h>
    #include <wincrypt.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;
    
        // TLS 1.3 cipher suites
        TLS_PARAMETERS tlsParams = {};
        ALG_ID tls13Ciphers[] = {
            TLS_AES_256_GCM_SHA384,
            TLS_AES_128_GCM_SHA256
        };
    
        tlsParams.cEnabledCrypto = 2;
        tlsParams.pEnabledCrypto = tls13Ciphers;
    
        schCred.cTlsParameters = 1;
        schCred.pTlsParameters = &tlsParams;
    
        CredHandle hCred;
        TimeStamp tsExpiry;
    
        SECURITY_STATUS status = AcquireCredentialsHandle(
            NULL,
            UNISP_NAME_W,
            SECPKG_CRED_OUTBOUND,
            NULL,
            &schCred,
            NULL,
            NULL,
            &hCred,
            &tsExpiry
        );
    
        if (status != SEC_E_OK) {
            printf("AcquireCredentialsHandle failed with error: 0x%08lx\n", status);
            return 1;
        }
    
        printf("TLS 1.3 credentials acquired successfully.\n");
        return 0;
    }
    
    1. Handshake Process

    Once the registry and cipher suites are set:

    • Windows will negotiate TLS 1.3 automatically.
    • The server must support TLS 1.3.
    • At least one common cipher suite must exist.
    1. Verification

    Run this command to verify TLS 1.3 handshake:

    openssl s_client -connect yourserver:443 -tls1_3
    

    Look for output like:

    Protocol : TLSv1.3 
    Cipher : TLS_AES_256_GCM_SHA384
    

    Notes

    • Works on Windows 11 and Windows Server 2022+.
    • On Windows 10, TLS 1.3 is experimental — additional registry tweaks may be needed.
    • No grbitEnabledProtocols flag is required for TLS 1.3.
    • Use SCH_CREDENTIALS and TLS_PARAMETERS for TLS 1.3 — not SCHANNEL_CRED.

    Let us know if you need further help with this. We’ll be happy to assist further if needed.


  5. Remini APK 0 Reputation points
    2025-08-13T15:27:21.9+00:00

    Recommended Approach Enable both TLS 1.2 and TLS 1.3 in the registry:

    reg Copy Edit [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000 Use TLS 1.3 in your application explicitly via SCHANNEL_CRED:

    cpp Copy Edit SCHANNEL_CRED schannelCred = {}; schannelCred.dwVersion = SCHANNEL_CRED_VERSION; schannelCred.grbitEnabledProtocols = SP_PROT_TLS1_3_CLIENT; schannelCred.dwFlags = SCH_CRED_MANUAL_CRED_VALIDATION; schannelCred.cCreds = 0; schannelCred.paCred = NULL; schannelCred.hRootStore = NULL; Call AcquireCredentialsHandle normally. SCHANNEL will negotiate TLS 1.3 if supported by both client and server. TLS 1.2 will act as a fallback automatically.

    Avoid exclusive TLS 1.3-only configuration unless you are absolutely sure you are on Windows 11+ and server supports TLS 1.3 only. Otherwise, you risk handshake failures. For more details you can visit our website.

    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.