bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
859 stars 164 forks source link

[Bug]: remote error: tls: unexpected message #131

Closed idX401 closed 2 weeks ago

idX401 commented 2 months ago

TLS client version

tls-client-xgo-1.7.8-windows-amd64.dll

System information

Windows 10 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz 2.11 GHz

Issue description

the "customTlsClient" parameter in the examples for other programming languages works very poorly and accepts "ja3String" without fail, although the golang example can accept "CipherSuites" and at the same time works perfectly

If you try to simply replace the request url in the example, then on most sites there will be an error "remote error: tls: unexpected message", this can be partially solved if the additional fields in "supportedSignatureAlgorithms" and others are accurate, but this may work for one resource, but still may not work on another

Steps to reproduce / Code Sample

const ffi = require('ffi-napi');

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./tls-client-xgo-1.7.8-windows-amd64.dll', {
    'request': ['string', ['string']],
    'getCookiesFromSession': ['string', ['string']],
    'addCookiesToSession': ['string', ['string']],
    'freeMemory': ["void", ['string']],
    'destroyAll': ['string', []],
    'destroySession': ['string', ['string']]
});

const requestPayload = {
    "followRedirects": false,
    "insecureSkipVerify": false,
    "withoutCookieJar": false,
    "withDefaultCookieJar": false,
    "isByteRequest": false,
    "catchPanics": false,
    "forceHttp1": false,
    "withDebug": false,
    "withRandomTLSExtensionOrder": false,
    "timeoutSeconds": 30,
    "timeoutMilliseconds": 0,
    "sessionId": "my-session-id",
    "certificatePinningHosts": {},
    "customTlsClient": {
        "ja3String": "771,2570-4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,2570-0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513-2570-21,2570-29-23-24,0",
        "h2Settings": {
            "HEADER_TABLE_SIZE": 65536,
            "MAX_CONCURRENT_STREAMS": 1000,
            "INITIAL_WINDOW_SIZE": 6291456,
            "MAX_HEADER_LIST_SIZE": 262144
        },
        "h2SettingsOrder": [
            "HEADER_TABLE_SIZE",
            "MAX_CONCURRENT_STREAMS",
            "INITIAL_WINDOW_SIZE",
            "MAX_HEADER_LIST_SIZE"
        ],
        "supportedSignatureAlgorithms": [
            "PKCS1WithSHA256",
            "PKCS1WithSHA384",
            "PKCS1WithSHA512",
            "PSSWithSHA256",
            "PSSWithSHA384",
            "PSSWithSHA512",
            "ECDSAWithP256AndSHA256",
            "ECDSAWithP384AndSHA384",
            "ECDSAWithP521AndSHA512",
            "PKCS1WithSHA1",
            "ECDSAWithSHA1",
            "Ed25519",
            "SHA224_RSA",
            "SHA224_ECDSA",
        ],
        "supportedVersions": ["GREASE", "1.3", "1.2"],
        "keyShareCurves": ["GREASE", "X25519"],
        "certCompressionAlgo": "brotli",
        "alpnProtocols": ["h2", "http/1.1"],
        "alpsProtocols": ["h2"],
        "pseudoHeaderOrder": [
            ":method",
            ":authority",
            ":scheme",
            ":path"
        ],
        "connectionFlow": 15663105,
        "priorityFrames": [{
            "streamID": 1,
            "priorityParam": {
                "streamDep": 1,
                "exclusive": true,
                "weight": 1
            }
        }],
        "headerPriority": {
            "streamDep": 1,
            "exclusive": true,
            "weight": 1
        },
    },
    "proxyUrl": "",
    "isRotatingProxy": false,
    "headers": {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
        "accept-encoding": "gzip, deflate, br",
        "accept-language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
    },
    "headerOrder": [
        "accept",
        "user-agent",
        "accept-encoding",
        "accept-language"
    ],
    "requestUrl": "https://tls.browserleaks.com/tls",
    "requestMethod": "GET",
    "requestBody": "",
    "requestCookies": []
}

// call the library with the requestPayload as string
const response = tlsClientLibrary.request(JSON.stringify(requestPayload));

// convert response string to json
const responseObject = JSON.parse(response)

console.log(responseObject)

const payload = {
    sessionId: 'my-session-id',
    url: "https://tls.browserleaks.com/tls",
}

const cookiesResponse = tlsClientLibrary.getCookiesFromSession(JSON.stringify(payload))

const cookiesInSession = JSON.parse(cookiesResponse)

console.log(cookiesInSession)

selected "customTlsClient" parameters so that the request is successful

const ffi = require('ffi-napi');

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./tls-client-xgo-1.7.8-windows-amd64.dll', {
    'request': ['string', ['string']],
    'getCookiesFromSession': ['string', ['string']],
    'addCookiesToSession': ['string', ['string']],
    'freeMemory': ["void", ['string']],
    'destroyAll': ['string', []],
    'destroySession': ['string', ['string']]
});

const requestPayload = {
    "followRedirects": false,
    "insecureSkipVerify": false,
    "withoutCookieJar": false,
    "withDefaultCookieJar": false,
    "isByteRequest": false,
    "catchPanics": false,
    "forceHttp1": false,
    "withDebug": false,
    "withRandomTLSExtensionOrder": false,
    "timeoutSeconds": 30,
    "timeoutMilliseconds": 0,
    "sessionId": "my-session-id",
    "certificatePinningHosts": {},
    "customTlsClient": {
        "cipherSuites":[],
        "ja3String": "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,5-51-35-23-13-18-45-11-43-16-17513-65281-27-65037-0-10-21,29-23-24,0",
        "h2Settings": {
            "HEADER_TABLE_SIZE": 65536,
            "MAX_CONCURRENT_STREAMS": 1000,
            "INITIAL_WINDOW_SIZE": 6291456,
            "MAX_HEADER_LIST_SIZE": 262144
        },
        "h2SettingsOrder": [
            "HEADER_TABLE_SIZE",
            "MAX_CONCURRENT_STREAMS",
            "INITIAL_WINDOW_SIZE",
            "MAX_HEADER_LIST_SIZE"
        ],
        "supportedSignatureAlgorithms": [
            "PKCS1WithSHA256",
            "PKCS1WithSHA384",
            "PKCS1WithSHA512",
            "PSSWithSHA256",
            "PSSWithSHA384",
            "PSSWithSHA512",
            "ECDSAWithP256AndSHA256",
            "ECDSAWithP384AndSHA384",
            "ECDSAWithP521AndSHA512",
            "PKCS1WithSHA1",
            "ECDSAWithSHA1",
            "Ed25519",
            "SHA224_RSA",
            "SHA224_ECDSA",
        ],
        "supportedVersions": ["GREASE", "1.3", "1.2"],
        "keyShareCurves": ["GREASE", "X25519"],
        "certCompressionAlgo": "brotli",
        "alpnProtocols": ["h2", "http/1.1"],
        "alpsProtocols": ["h2", "http/1.1"],
        "pseudoHeaderOrder": [
            ":method",
            ":authority",
            ":scheme",
            ":path"
        ],
        "connectionFlow": 15663105,
        "priorityFrames": [{
            "streamID": 1,
            "priorityParam": {
                "streamDep": 1,
                "exclusive": true,
                "weight": 1
            }
        }],
        "headerPriority": {
            "streamDep": 1,
            "exclusive": true,
            "weight": 1
        },
    },
    "proxyUrl": "",
    "isRotatingProxy": false,
    "headers": {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
        "accept-encoding": "gzip, deflate, br",
        "accept-language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
    },
    "headerOrder": [
        "accept",
        "user-agent",
        "accept-encoding",
        "accept-language"
    ],
    "requestUrl": "https://tls.browserleaks.com/tls",
    "requestMethod": "GET",
    "requestBody": "",
    "requestCookies": []
}

// call the library with the requestPayload as string
const response = tlsClientLibrary.request(JSON.stringify(requestPayload));

// convert response string to json
const responseObject = JSON.parse(response)

console.log(responseObject)

const payload = {
    sessionId: 'my-session-id',
    url: "https://tls.browserleaks.com/tls",
}

const cookiesResponse = tlsClientLibrary.getCookiesFromSession(JSON.stringify(payload))

const cookiesInSession = JSON.parse(cookiesResponse)

console.log(cookiesInSession)
LyonSquad commented 2 months ago

@idX401 how do we open this 1.7.8 on windows 11 can you compile a .exe for this or gimme a tutorial @jsnjack anyone help meeeeeeee!

LyonSquad commented 2 months ago

image currently have an old version i want the latest 1.78 cuz there are new features like ios 17/18 user agents updated etc @bogdanfinn could you please compile a .exe and add it in your release builds sir.

bogdanfinn commented 2 months ago

@LyonSquad please stop spamming the issues with your personal requests. this is not what they are meant to be.