1 Simple Peer-to-Peer Security
2 ----------------------------
4 SPTPS is a protocol that, like TLS, aims to provide a secure transport layer
5 for applications. However, it is specifically aimed at peer-to-peer
6 applications. Specifically, peers have each other's credentials beforehand,
7 they need not negotiate certificates. Also, the security parameters of the
8 application is also known beforehand, so they need not negotiate cipher suites.
9 Only one cipher suite is available, and only one authentication method is used.
10 This not only greatly simplifies the protocol, it also gets rid of an entire
11 class of attacks and possible programming mistakes.
13 SPTPS can be used both on top of reliable stream protocols such as TCP or on
14 top of datagram protocols such as UDP.
19 A record consists of these fields:
21 - uint32_t seqno (network byte order)
22 - uint16_t length (network byte order)
25 - opaque hmac[HMAC_SIZE] (HMAC over all preceding fields)
29 - The seqno field is never sent to the peer, but is included in the calculation
31 - At the start of the session, the HMAC field does not appear until after the
32 SIGnature records have been exchanged.
33 - After the authentication phase, the type and data fields are encrypted before
34 the HMAC is calculated.
38 - 0..127 represent application records. The meaning of the value is application
40 - 128 is a handshake record.
41 - 129..255 are reserved and never to be used for application records.
46 A record consists of these fields:
48 - uint16_t length (network byte order)
49 - uint32_t seqno (network byte order)
52 - opaque hmac[HMAC_SIZE] (HMAC over all preceding fields)
56 - The length field is never sent to the peer, but is included in the calculation
58 - The rest is the same as the stream record layer.
60 Authentication protocol
61 -----------------------
63 The authentication consists of an exchange of Key EXchange, SIGnature and
64 ACKnowledge messages, transmitted using type 128 records.
75 ...encrypt and HMAC using session keys from now on...
82 ...key renegotiation starts here...
91 ...encrypt and HMAC using new session keys from now on...
99 Note that the responder does not need to wait before it receives the first KEX
100 message, it can immediately send its own once it has accepted an incoming
103 Key EXchange message:
105 - uint8_t kex_version (always 0 in this version of SPTPS)
106 - opaque nonce[32] (random number)
107 - opaque ecdh_key[ECDH_SIZE]
111 - opaque ecdsa_signature[ECDSA_SIZE]
115 - empty (only sent after key renegotiation)
119 - At the start, both peers generate a random nonce and an Elliptic Curve public
120 key and send it to the other in the KEX message.
121 - After receiving the other's KEX message, both KEX messages are concatenated
122 (see below), and the result is signed using ECDSA. The result is sent to the
124 - After receiving the other's SIG message, the signature is verified. If it is
125 correct, the shared secret is calculated from the public keys exchanged in the
126 KEX message using the Elliptic Curve Diffie-Helman algorithm.
127 - The shared secret key is expanded using a PRF. Both nonces and the application
128 specific label are also used as input for the PRF.
129 - An ACK message is sent only when doing key renegotiation, and is sent using
130 the old encryption keys.
131 - The expanded key is used to key the encryption and HMAC algorithms.
133 The signature is calculated over this string:
135 - uint8_t initiator (0 = local peer, 1 = remote peer is initiator)
136 - opaque remote_kex_message[1 + 32 + ECDH_SIZE]
137 - opaque local_kex_message[1 + 32 + ECDH_SIZE]
138 - opaque label[label_length]
140 The PRF is calculated as follows:
142 - A HMAC using SHA512 is used, the shared secret is used as the key.
143 - For each block of 64 bytes, a HMAC is calculated. For block n: hmac[n] =
144 HMAC_SHA512(hmac[n - 1] + seed)
145 - For the first block (n = 1), hmac[0] is given by HMAC_SHA512(zeroes + seed),
146 where zeroes is a block of 64 zero bytes.
148 The seed is as follows:
150 - const char[13] "key expansion"
151 - opaque responder_nonce[32]
152 - opaque initiator_nonce[32]
153 - opaque label[label_length]
155 The expanded key is used as follows:
157 - opaque responder_cipher_key[CIPHER_KEYSIZE]
158 - opaque responder_digest_key[DIGEST_KEYSIZE]
159 - opaque initiator_cipher_key[CIPHER_KEYSIZE]
160 - opaque initiator_digest_key[DIGEST_KEYSIZE]
162 Where initiator_cipher_key is the key used by session initiator to encrypt
163 messages sent to the responder.
168 - Document format of ECDH public key, ECDSA signature
169 - Document how CTR mode is used
170 - Refer to TLS RFCs where appropriate