import ssl, socket, os, sys

def test_cert(name, certfile, keyfile):
    ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    ctx.set_ciphers('AES256-SHA')
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    try:
        ctx.load_cert_chain(certfile, keyfile)
    except Exception as e:
        print(f"{name}: LOAD FAIL {e}")
        return
    try:
        sock = socket.create_connection(('193.194.119.131', 443), timeout=15)
        ss = ctx.wrap_socket(sock, server_hostname='vpn-nl.exness.com')
        # Send GET request
        req = b'GET /+CSCOE+/logon.html HTTP/1.1\r\nHost: vpn-nl.exness.com\r\nConnection: close\r\n\r\n'
        ss.sendall(req)
        data = b''
        while True:
            chunk = ss.recv(4096)
            if not chunk: break
            data += chunk
        ss.close()
        # Parse response
        lines = data.split(b'\r\n')
        status = lines[0] if lines else b'?'
        # Find body after headers
        hdr_end = data.find(b'\r\n\r\n')
        body = data[hdr_end+4:] if hdr_end >= 0 else b''
        print(f"{name}: {status.decode(errors='replace')} BODY_LEN={len(body)}")
        print(f"  first 300B: {body[:300].decode(errors='replace')}")
    except Exception as e:
        print(f"{name}: CONN FAIL {e}")

# Test each
tests = [
    ("hostapd_p12", "/tmp/p12_cert.pem", "/tmp/p12_key.pem"),
    ("ll_1_digicert", "/tmp/ll_1.pem", "/tmp/ll_1.pem"),  # single file has both
    ("exness_shustov", "/tmp/cert.pem", "/tmp/cert.pem"),  # self-signed, single file
]
for name, c, k in tests:
    if os.path.exists(c):
        test_cert(name, c, k)
    else:
        print(f"{name}: FILE MISSING {c}")
