I managed to reproduce the issue with a TLS connection to a local TCP server.
I generate a self-signed certificate with this command:
openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt -days 365 -nodes
I run the TLS server with this python script:
import socket
import ssl
import time
import os
# Server configuration
HOST = '0.0.0.0'
PORT = 443 # Port to listen on
CERT_FILE = 'server.crt' # Path to the server's certificate file
KEY_FILE = 'server.key' # Path to the server's private key file
def generate_random_bytes(size):
"""Generate random bytes of the specified size."""
return os.urandom(size)
def run_tls_server():
# Create a regular socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((HOST, PORT))
server_socket.listen(5)
print(f"Server listening on {HOST}:{PORT}")
# Accept connections
with ssl.wrap_socket(server_socket, server_side=True, certfile=CERT_FILE, keyfile=KEY_FILE, cert_reqs=ssl.CERT_NONE) as tls_server_socket:
print("Waiting for a connection...")
client_socket, addr = tls_server_socket.accept()
print(f"Connection established with {addr}")
# Wait for 10 seconds
print("Waiting for 10 seconds...")
time.sleep(10)
# Generate random bytes
random_bytes = generate_random_bytes(2400)
client_socket.sendall(random_bytes)
print(f"Sent random bytes to {addr}")
# Close the connection
print("Waiting for 30 seconds...")
time.sleep(30)
client_socket.shutdown()
if __name__ == "__main__":
run_tls_server()
I write the self-signed certificate to the modem with AT+KCERTSTORE
I select this cert with AT+KSSLCRYPTO=0,8,3,25392,12,4,1,0
// connection to the server
AT+KTCPCFG=1,3,\"IPADDRESSOFSERVER\",443,,,,0,0,0
+KTCPCFG: 1
AT+KTCPCNX=1
+KTCP_IND: 1
// the server sends 2400 bytes, we get an URC for 1629 bytes only
+KTCP_DATA: 1,1629
AT+KTCPSTAT
+KTCPSTAT: 1,3,-1,0,1629
// I read 1629 bytes
AT+KTCPRCV=1,1629
// no URC coming, no data pending to read in the socket
AT+KTCPSTAT
+KTCPSTAT: 1,3,-1,0,0
// server closes the connection, and the pending 771 bytes are never read
+KTCP_NOTIF: 1,4
AT+KTCPSTAT
+KTCPSTAT: 1,5,4,0,0
So it seems the issue is related to TLS client.
If the server sends less than 1629 bytes, the client can read them. Anything above 1629 is truncated and the remaining bytes are not received.