The SPTPS protocol is designed to address the weaknesses in the legacy protocol. SPTPS is based on TLS 1.2, but has been simplified: there is no support for exchanging public keys, and there is no cipher suite negotiation. Instead, SPTPS always uses a very strong cipher suite: peers authenticate each other using 521 bits ECC keys, Diffie-Hellman using ephemeral 521 bits ECC keys is used to provide perfect forward secrecy (PFS), AES-256-CTR is used for encryption, and HMAC-SHA-256 for message authentication.
Similar to TLS, messages are split up in records. A complete logical record contains the following information:
Depending on whether SPTPS records are sent via TCP or UDP, either the seqno or the length field is omitted on the wire (but they are still included in the calculation of the HMAC); for TCP packets are guaranteed to arrive in-order so we can infer the seqno, but packets can be split or merged, so we still need the length field to determine the boundaries between records; for UDP packets we know that there is exactly one record per packet, and we know the length of a packet, but packets can be dropped, duplicated and/or reordered, so we need to include the seqno.
The type field is used to distinguish between application records or handshake records. Types 0 to 127 are application records, type 128 is a handshake record, and types 129 to 255 are reserved.
Before the initial handshake, no fields are encrypted, and the HMAC field is not present. After the authentication handshake, the length (if present), type and data fields are encrypted, and the HMAC field is present. For UDP packets, the seqno field is not encrypted, as it is used to determine the value of the counter used for encryption.
The authentication consists of an exchange of Key EXchange, SIGnature and ACKnowledge messages, transmitted using type 128 records.
Initiator Responder --------------------- KEX -> <- KEX SIG -> <- SIG ...encrypt and HMAC using session keys from now on... App -> <- App ... ... ...key renegotiation starts here... KEX -> <- KEX SIG -> <- SIG ACK -> <- ACK ...encrypt and HMAC using new session keys from now on... App -> <- App ... ... ---------------------
Note that the responder does not need to wait before it receives the first KEX message, it can immediately send its own once it has accepted an incoming connection.
Key EXchange message:
The signature is calculated over this string:
The PRF is calculated as follows:
The seed is as follows:
The expanded key is used as follows:
Where initiator_cipher_key is the key used by session initiator to encrypt messages sent to the responder.
When using 256 bits Ed25519 keys, the AES-256-CTR cipher and HMAC-SHA-256 digest algorithm, the sizes are as follows:
ECDH_SIZE: 32 (= 256/8) ECDSA_SIZE: 64 (= 2 * 256/8) CIPHER_KEYSIZE: 48 (= 256/8 + 128/8) DIGEST_KEYSIZE: 32 (= 256/8)
Note that the cipher key also includes the initial value for the counter.