Corrected signed-to-unsigned comparisons
[gnutls.git] / doc / protocol / draft-hickman-netscape-ssl-00.txt
blob5658bdff89a20c00c8b6bb51d226cfdad991f91f
2                                                  Kipp E.B. Hickman
3 Internet Draft                            Netscape Communications Corp
4                                             April 1995 (Expires 10/95)
6                            The SSL Protocol
7                     <draft-hickman-netscape-ssl-00.txt>
9 1. STATUS OF THIS MEMO
11 This document is an Internet-Draft.Internet-Drafts are working documents 
12 of the Internet Engineering Task Force (IETF), its areas, and its working 
13 groups. Note that other groups may also distribute working documents as 
14 Internet-Drafts.
16 Internet-Drafts are draft documents valid for a maximum of six months 
17 and may be updated, replaced, or obsoleted by other documents at any 
18 time. It is inappropriate to use Internet-Drafts as reference material or to 
19 cite them other than as "work in progress."
21 To learn the current status of any Internet-Draft, please check the "1id-
22 abstracts.txt" listing contained in the Internet- Drafts Shadow Directories 
23 on ds.internic.net (US East Coast), nic.nordu.net (Europe), ftp.isi.edu (US 
24 West Coast), or munnari.oz.au (Pacific Rim).
25 2. ABSTRACT
27 This document specifies the Secure Sockets Layer (SSL) protocol, a 
28 security protocol that provides privacy over the Internet. The protocol 
29 allows client/server applications to communicate in a way that cannot be 
30 eavesdropped. Server's are always authenticated and clients are optionally 
31 authenticated.
33 3. INTRODUCTION
35 The SSL Protocol is designed to provide privacy between two 
36 communicating applications (a client and a server). Second, the protocol is 
37 designed to authenticate the server, and optionally the client. SSL requires 
38 a reliable transport protocol (e.g. TCP) for data transmission and 
39 reception.
41 The advantage of the SSL Protocol is that it is application protocol 
42 independent. A "higher level" application protocol (e.g. HTTP, FTP, 
43 TELNET, etc.) can layer on top of the SSL Protocol transparently. The 
44 SSL Protocol can negotiate an encryption algorithm and session key as 
45 well as authenticate a server before the application protocol transmits or 
46 receives its first byte of data. All of the application protocol data is 
47 transmitted encrypted, ensuring privacy.
49 The SSL protocol provides "channel security" which has three basic 
50 properties:
52   The channel is private. Encryption is used for all messages after a 
53 simple handshake is used to define a secret key. Symmetric 
54 cryptography is used for data encryption (e.g. DES, RC4, etc.)
56   The channel is authenticated. The server endpoint of the conversation 
57 is always authenticated, while the client endpoint is optionally 
58 authenticated. Asymmetric cryptography is used for authentication 
60 Hickman                                                 [page  1]
62 (e.g. Public Key Cryptography).
64   The channel is reliable. The message transport includes a message 
65 integrity check (using a MAC). Secure hash functions (e.g. MD2, 
66 MD5) are used for MAC computations.
68 The SSL protocol is actually composed of two protocols. At the lowest 
69 level, layered on top of some reliable transport protocol, is the "SSL 
70 Record Protocol". The SSL Record Protocol is used for encapsulation of 
71 all transmitted and received data, including the SSL Handshake Protocol, 
72 which is used to establish security parameters.
73 4. SSL Record Protocol Specification
75 4.1 SSL Record Header Format
77 In SSL, all data sent is encapsulated in a record, an object which is 
78 composed of a header and some non-zero amount of data. Each record 
79 header contains a two or three byte length code. If the most significant bit 
80 is set in the first byte of the record length code then the record has no 
81 padding and the total header length will be 2 bytes, otherwise the record 
82 has padding and the total header length will be 3 bytes. The record header 
83 is transmitted before the data portion of the record.
85 Note that in the long header case (3 bytes total), the second most 
86 significant bit in the first byte has special meaning. When zero, the record 
87 being sent is a data record. When one, the record being sent is a security 
88 escape (there are currently no examples of security escapes; this is 
89 reserved for future versions of the protocol). In either case, the length code 
90 describes how much data is in the record.
92 The record length code does not include the number of bytes consumed by 
93 the record header (2 or 3). For the 2 byte header, the record length is 
94 computed by (using a "C"-like notation):
96 RECORD-LENGTH = ((byte[0] & 0x7f) << 8)) | byte[1];
98 Where byte[0] represents the first byte received and byte[1] the second 
99 byte received. When the 3 byte header is used, the record length is 
100 computed as follows (using a "C"-like notation):
102 RECORD-LENGTH = ((byte[0] & 0x3f) << 8)) | byte[1];
103 IS-ESCAPE = (byte[0] & 0x40) != 0;
104 PADDING = byte[2];
106 The record header defines a value called PADDING. The PADDING 
107 value specifies how many bytes of data were appended to the original 
108 record by the sender. The padding data is used to make the record length 
109 be a multiple of the block ciphers block size when a block cipher is used 
110 for encryption.
112 The sender of a "padded" record appends the padding data to the end of its 
113 normal data and then encrypts the total amount (which is now a multiple 
114 of the block cipher's block size). The actual value of the padding data is 
115 unimportant, but the encrypted form of it must be transmitted for the 
116 receiver to properly decrypt the record. Once the total amount being 
118 Hickman                                                 [page  2]
120 transmitted is known the header can be properly constructed with the 
121 PADDING value set appropriately.
123 The receiver of a padded record decrypts the entire record data (sans 
124 record length and the optional padding) to get the clear data, then subtracts 
125 the PADDING value from the RECORD-LENGTH to determine the 
126 final RECORD-LENGTH. The clear form of the padding data must be 
127 discarded.
129 4.1.1 SSL Record Data Format
131 The data portion of an SSL record is composed of three components 
132 (transmitted and received in the order shown):
134 MAC-DATA[MAC-SIZE]
135 ACTUAL-DATA[N]
136 PADDING-DATA[PADDING]
138 ACTUAL-DATA is the actual data being transmitted (the message 
139 payload). PADDING-DATA is the padding data sent when a block cipher 
140 is used and padding is needed. Finally, MAC-DATA is the "Message 
141 Authentication Code".
143 When SSL records are sent in the clear, no cipher is used.Consequently the 
144 amount of PADDING-DATA will be zero and the amount of MAC-
145 DATA will be zero. When encryption is in effect, the PADDING-DATA 
146 will be a function of the cipher block size. The MAC-DATA is a function 
147 of the CIPHER-CHOICE (more about that later).
149 The MAC-DATA is computed as follows:
151 MAC-DATA = HASH[ SECRET, ACTUAL-DATA, PADDING-DATA,
152 SEQUENCE-NUMBER ]
154 Where the SECRET data is fed to the hash function first, followed by the 
155 ACTUAL-DATA, which is followed by the PADDING-DATA which is 
156 finally followed by the SEQUENCE-NUMBER. The SEQUENCE-
157 NUMBER is a 32 bit value which is presented to the hash function as four 
158 bytes, with the first byte being the most significant byte of the sequence 
159 number, the second byte being the next most significant byte of the 
160 sequence number, the third byte being the third most significant byte, and 
161 the fourth byte being the least significant byte (that is, in network byte 
162 order or "big endian" order).
164 MAC-SIZE is a function of the digest algorithm being used. For MD2 and 
165 MD5 the MAC-SIZE will be 16 bytes (128 bits).
167 The SECRET value is a function of which party is sending the message. If 
168 the client is sending the message then the SECRET is the CLIENT-
169 WRITE-KEY (the server will use the SERVER-READ-KEY to verify 
170 the MAC). If the client is receiving the message then the SECRET is the 
171 CLIENT-READ-KEY (the server will use the SERVER-WRITE-KEY 
173 generate the MAC).
175 Hickman                                                 [page  3]
177 The SEQUENCE-NUMBER is a counter which is incremented by both 
178 the sender and the receiver. For each transmission direction, a pair of 
179 counters is kept (one by the sender, one by the receiver). Every time a 
180 message is sent by a sender the counter is incremented. Sequence numbers 
181 are 32 bit unsigned quantities and must wrap to zero after incrementing 
182 past 0xFFFFFFFF.
184 The receiver of a message uses the expected value of the sequence number 
185 as input into the MAC HASH function (the HASH function is chosen from 
186 the CIPHER-CHOICE). The computed MAC-DATA must agree bit for 
187 bit with the transmitted MAC-DATA. If the comparison is not identity 
188 then the record is considered damaged, and it is to be treated as if an "I/O 
189 Error" had occurred (i.e. an unrecoverable error is asserted and the 
190 connection is closed).
192 A final consistency check is done when a block cipher is used and the 
193 protocol is using encryption. The amount of data present in a record 
194 (RECORD-LENGTH))must be a multiple of the cipher's block size. If 
195 the received record is not a multiple of the cipher's block size then the 
196 record is considered damaged, and it is to be treated as if an "I/O Error" 
197 had occurred (i.e. an unrecoverable error is asserted and the connection is 
198 closed).
200 The SSL Record Layer is used for all SSL communications, including 
201 handshake messages, security escapes and application data transfers. The 
202 SSL Record Layer is used by both the client and the server at all times.
204 For a two byte header, the maximum record length is 32767 bytes. For the 
205 three byte header, the maximum record length is 16383 bytes. The SSL 
206 Handshake Protocol messages are constrained to fit in a single SSL Record 
207 Protocol record. Application protocol messages are allowed to consume 
208 multiple SSL Record Protocol record's.
210 Before the first record is sent using SSL all sequence numbers are 
211 initialized to zero. The transmit sequence number is incremented after 
212 every message sent, starting with the CLIENT-HELLO and SERVER-
213 HELLO messages.
215 5. SSL Handshake Protocol Specification
217 5.1 SSL Handshake Protocol Flow
219 The SSL Handshake Protocol is used to negotiate security enhancements 
220 to data sent using the SSL Record Protocol. The security enhancements 
221 consist of authentication, symmetric encryption, and message integrity.
223 The SSL Handshake Protocol has two major phases. The first phase is 
224 used to establish private communications. The second phase is used for 
225 client authentication.
227 5.1.1 Phase 1
229 The first phase is the initial connection phase where both parties 
230 communicate their "hello" messages. The client initiates the conversation 
231 by sending the CLIENT-HELLO message. The server receives the 
233 Hickman                                                 [page  4]
235 CLIENT-HELLO message and processes it responding with the 
236 SERVER-HELLO message.
238 At this point both the client and server have enough information to know 
239 whether or not a new "master key" is needed (The master key is used for 
240 production of the symmetric encryption session keys). When a new master 
241 key is not needed, both the client and the server proceed immediately to 
242 phase 2.
244 When a new master key is needed, the SERVER-HELLO message will 
245 contain enough information for the client to generate it. This includes the 
246 server's signed certificate (more about that later), a list of bulk cipher 
247 specifications (see below), and a connection-id (a connection-id is a 
248 randomly generated value generated by the server that is used by the client 
249 and server during a single connection). The client generates the master key 
250 and responds with a CLIENT-MASTER-KEY message (or an ERROR 
251 message if the server information indicates that the client and server 
252 cannot agree on a bulk cipher).
254 It should be noted here that each SSL endpoint uses a pair of ciphers per 
255 connection (for a total of four ciphers). At each endpoint, one cipher is 
256 used for outgoing communications, and one is used for incoming 
257 communications. When the client or server generate a session key, they 
258 actually generate two keys, the SERVER-READ-KEY (also known as the 
259 CLIENT-WRITE-KEY) and the SERVER-WRITE-KEY (also known 
260 as the CLIENT-READ-KEY). The master key is used by the client and 
261 server to generate the various session keys (more about that later).
263 Finally, the server sends a SERVER-VERIFY message to the client after 
264 the master key has been determined. This final step authenticates the 
265 server, because only a server which has the appropriate public key can 
266 know the master key.
268 5.1.2 Phase 2
270 The second phase is the client authentication phase. The server has already 
271 been authenticated by the client in the first phase, so this phase is primarily 
272 used to authenticate the client. In a typical scenario, the server will require 
273 authentication of  the client and send a REQUEST-CERTIFICATE 
274 message. The client will answer in the positive if it has the needed 
275 information, or send an ERROR message if it does not. This protocol 
276 specification does not define the semantics of an ERROR response to a 
277 server request (e.g., an implementation can ignore the error, close the 
278 connection, etc. and still conform to this specification). In addition, it is 
279 permissable for a server to cache client authentication information with the 
280 "session-id" cache. The server is not required to re-authenticate the client 
281 on every connection.
283 When a party is done authenticating the other party, it sends its finished 
284 message. For the client, the CLIENT-FINISHED message contains the 
285 encrypted form of the CONNECTION-ID for the server to verify. If the 
286 verification fails, the server sends an ERROR message.
288 Once a party has sent its finished message it must continue to listen to its 
289 peers messages until it too receives a finished message. Once a party has 
291 Hickman                                                 [page  5]
293 both sent a finished message and received its peers finished message, the 
294 SSL handshake protocol is done. At this point the application protocol 
295 begins to operate (Note: the application protocol continues to be layered 
296 on the SSL Record Protocol).
298 5.2 Typical Protocol Message Flow
300 The following sequences define several typical protocol message flows for 
301 the SSL Handshake Protocol. In these examples we have two principals in 
302 the conversation: the client and the server. We use a notation commonly 
303 found in the literature [10]. When something is enclosed in curly braces 
304 "{something}key" then the something has been encrypted using "key".
306 5.2.1 Assuming no session-identifier
308 client-hello            C -> S: challenge, cipher_specs
309 server-hello            S -> C: connection-id, server_certificate,
310                                   cipher_specs
311 client-master-key       C -> S: {master_key}server_public_key
312 client-finish           C -> S: {connection-id}client_write_key
313 server-verify           S -> C: {challenge}server_write_key
314 server-finish           S -> C: {new_session_id}server_write_key
316 5.2.2 Assuming a session-identifier was found by both client & server
318 client-hello            C -> S: challenge, session_id, cipher_specs
319 server-hello            S -> C: connection-id, session_id_hit
320 client-finish           C -> S: {connection-id}client_write_key
321 server-verify           S -> C: {challenge}server_write_key
322 server-finish           S -> C: {session_id}server_write_key
324 5.2.3 Assuming a session-identifier was used and client authentication 
325 is used
327 client-hello            C -> S: challenge, session_id, cipher_specs
328 server-hello            S -> C: connection-id, session_id_hit
329 client-finish           C -> S: {connection-id}client_write_key
330 server-verify           S -> C: {challenge}server_write_key
331 request-certificate     S -> C: {auth_type,challenge'}
332                                   server_write_key
333 client-certificate      C -> S: {cert_type,client_cert,
334                                    response_data}client_write_key
335 server-finish           S -> C: {session_id}server_write_key
337 In this last exchange, the response_data is a function of the auth_type.
339 5.3 Errors
341 Error handling in the SSL connection protocol is very simple. When an 
342 error is detected, the detecting party sends a message to the other party. 
343 Errors that are not recoverable cause the client and server to abort the 
344 secure connection. Servers and client are required to "forget" any session-
345 identifiers associated with a failing connection.
347 The SSL Handshake Protocol defines the following errors:
350 Hickman                                                 [page  6]
352 NO-CIPHER-ERROR
353 This error is returned by the client to the server when it cannot find 
354 a cipher or key size that it supports that is also supported by the 
355 server. This error is not recoverable.
357 NO-CERTIFICATE-ERROR
358 When a REQUEST-CERTIFICATE message is sent, this error may 
359 be returned if the client has no certificate to reply with. This error 
360 is recoverable (for client authentication only).
362 BAD-CERTIFICATE-ERROR
363 This error is returned when a certificate is deemed bad by the 
364 receiving party. Bad means that either the signature of the 
365 certificate was bad or that the values in the certificate were 
366 inappropriate (e.g. a name in the certificate did not match the 
367 expected name). This error is recoverable (for client authentication 
368 only).
370 UNSUPPORTED-CERTIFICATE-TYPE-ERROR
371 This error is returned when a client/server receives a certificate 
372 type that it can't support. This error is recoverable (for client 
373 authentication only).
375 5.4 SSL Handshake Protocol Messages
377 The SSL Handshake Protocol messages are encapsulated using the SSL 
378 Record Protocol and are composed of two parts: a single byte message 
379 type code, and some data. The client and server exchange messages until 
380 both ends have sent their "finished" message, indicating that they are 
381 satisfied with the SSL Handshake Protocol conversation. While one end 
382 may be finished, the other may not, therefore the finished end must 
383 continue to receive SSL Handshake Protocol messages until it receives a 
384 "finished" message from its peer.
386 After the pair of session keys has been determined by each party, the 
387 message bodies are encrypted. For the client, this happens after it verifies 
388 the session-identifier or creates a new master key and has sent it to the 
389 server. For the server, this happens after the session-identifier is found to 
390 be good, or the server receives the client's master key message.
392 The following notation is used for SSLHP messages:
394 char MSG-EXAMPLE
395 char FIELD1
396 char FIELD2
397 char THING-MSB
398 char THING-LSB
399 char THING-DATA[(MSB<<8)|LSB];
402 This notation defines the data in the protocol message, including the 
403 message type code. The order is presented top to bottom, with the top most 
404 element being transmitted first, and the bottom most element transferred 
405 last.
408 Hickman                                                 [page  7]
410 For the "THING-DATA" entry, the MSB and LSB values are actually 
411 THING-MSB and THING-LSB (respectively) and define the number of 
412 bytes of data actually present in the message. For example, if THING-
413 MSB were zero and THING-LSB were 8 then the THING-DATA array 
414 would be exactly 8 bytes long. This shorthand is used below.
416 Length codes are unsigned values, and when the MSB and LSB are 
417 combined the result is an unsigned value. Unless otherwise specified 
418 lengths values are "length in bytes".
420 5.5 Client Only Protocol Messages
422 There are several messages that are only generated by clients. These 
423 messages are never generated by correctly functioning servers. A client 
424 receiving such a message closes the connection to the server and returns an 
425 error status to the application through some unspecified mechanism.
427 5.5.1 CLIENT-HELLO (Phase 1; Sent in the clear)
429 char MSG-CLIENT-HELLO
430 char CLIENT-VERSION-MSB
431 char CLIENT-VERSION-LSB
432 char CIPHER-SPECS-LENGTH-MSB
433 char CIPHER-SPECS-LENGTH-LSB
434 char SESSION-ID-LENGTH-MSB
435 char SESSION-ID-LENGTH-LSB
436 char CHALLENGE-LENGTH-MSB
437 char CHALLENGE-LENGTH-LSB
438 char CIPHER-SPECS-DATA[(MSB<<8)|LSB]
439 char SESSION-ID-DATA[(MSB<<8)|LSB]
440 char CHALLENGE-DATA[(MSB<<8)|LSB]
442 When a client first connects to a server it is required to send the CLIENT-
443 HELLO message. The server is expecting this message from the client as 
444 its first message. It is an error for a client to send anything else as its
445 first 
446 message.
448 The client sends to the server its SSL version, its cipher specs (see below), 
449 some challenge data, and the session-identifier data. The session-identifier 
450 data is only sent if the client found a session-identifier in its cache for the 
451 server, and the SESSION-ID-LENGTH will be non-zero. When there is 
452 no session-identifier for the server SESSION-ID-LENGTH must be zero. 
453 The challenge data is used to authenticate the server. After the client and 
454 server agree on a pair of session keys, the server returns a SERVER-
455 VERIFY message with the encrypted form of the CHALLENGE-DATA.
457 Also note that the server will not send its SERVER-HELLO message 
458 until it has received the CLIENT-HELLO message. This is done so that 
459 the server can indicate the status of the client's session-identifier back to 
460 the client in the server's first message (i.e. to increase protocol efficiency 
461 and reduce the number of round trips required).
463 The server examines the CLIENT-HELLO message and will verify that it 
464 can support the client version and one of the client cipher specs. The 
465 server can optionally edit the cipher specs, removing any entries it doesn't 
467 Hickman                                                 [page  8]
469 choose to support. The edited version will be returned in the SERVER-
470 HELLO message if the session-identifier is not in the server's cache.
472 The CIPHER-SPECS-LENGTH must be greater than zero and a 
473 multiple of 3. The SESSION-ID-LENGTH must either be zero or 16. 
474 The CHALLENGE-LENGTH must be greater than or equal to 16 and 
475 less than or equal to 32.
477 This message must be the first message sent by the client to the server. 
478 After the message is sent the client waits for a SERVER-HELLO 
479 message. Any other message returned by the server (other than ERROR) 
480 is disallowed.
482 5.5.2 CLIENT-MASTER-KEY (Phase 1; Sent primarily in the clear)
484 char MSG-CLIENT-MASTER-KEY
485 char CIPHER-KIND[3]
486 char CLEAR-KEY-LENGTH-MSB
487 char CLEAR-KEY-LENGTH-LSB
488 char ENCRYPTED-KEY-LENGTH-MSB
489 char ENCRYPTED-KEY-LENGTH-LSB
490 char KEY-ARG-LENGTH-MSB
491 char KEY-ARG-LENGTH-LSB
492 char CLEAR-KEY-DATA[MSB<<8|LSB]
493 char ENCRYPTED-KEY-DATA[MSB<<8|LSB]
494 char KEY-ARG-DATA[MSB<<8|LSB]
496 The client sends this message when it has determined a master key for the 
497 server to use. Note that when a session-identifier has been agreed upon, 
498 this message is not sent.
500 The CIPHER-KIND field indicates which cipher was chosen from the 
501 server's CIPHER-SPECS.
503 The CLEAR-KEY-DATA contains the clear portion of the MASTER-
504 KEY. The CLEAR-KEY-DATA is combined with the SECRET-KEY-
505 DATA (described shortly) to form the MASTER-KEY, with the 
506 SECRET-KEY-DATA being the least significant bytes of the final 
507 MASTER-KEY. The ENCRYPTED-KEY-DATA contains the secret 
508 portions of the MASTER-KEY, encrypted using the server's public key. 
509 The encryption block is formatted using block type 2 from PKCS#1 [5]. 
510 The data portion of the block is formatted as follows:
512 char SECRET-KEY-DATA[SECRET-LENGTH]
514 SECRET-LENGTH is the number of bytes of each session key that is 
515 being transmitted encrypted. The SECRET-LENGTH plus the CLEAR-
516 KEY-LENGTH equals the number of bytes present in the cipher key (as 
517 defined by the CIPHER-KIND). It is an error if the SECRET-LENGTH 
518 found after decrypting the PKCS#1 formatted encryption block doesn't 
519 match the expected value. It is also an error if CLEAR-KEY-LENGTH is 
520 non-zero and the CIPHER-KIND is not an export cipher.
522 If the key algorithm needs an argument (for example, DES-CBC's 
523 initialization vector) then the KEY-ARG-LENGTH fields will be non-
525 Hickman                                                 [page 9]
527 zero and the KEY-ARG-DATA will contain the relevant data. For the 
528 SSL_CK_RC2_128_CBC_WITH_MD5, 
529 SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5, 
530 SSL_CK_IDEA_128_CBC_WITH_MD5, 
531 SSL_CK_DES_64_CBC_WITH_MD5 and 
532 SSL_CK_DES_192_EDE3_CBC_WITH_MD5 algorithms the KEY-ARG 
533 data must be present and be exactly 8 bytes long.
535 Client and server session key production is a function of the CIPHER-
536 CHOICE:
538 SSL_CK_RC4_128_WITH_MD5
539 SSL_CK_RC4_128_EXPORT40_WITH_MD5
540 SSL_CK_RC2_128_CBC_WITH_MD5
541 SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5
542 SSL_CK_IDEA_128_CBC_WITH_MD5
544 KEY-MATERIAL-0 = MD5[ MASTER-KEY, "0", CHALLENGE, 
545 CONNECTION-ID ]
546 KEY-MATERIAL-1 = MD5[ MASTER-KEY, "1", CHALLENGE, 
547 CONNECTION-ID ]
549 CLIENT-READ-KEY = KEY-MATERIAL-0[0-15]
550 CLIENT-WRITE-KEY = KEY-MATERIAL-1[0-15]
552 Where KEY-MATERIAL-0[0-15] means the first 16 bytes of the KEY-
553 MATERIAL-0 data, with KEY-MATERIAL-0[0] becoming the  most 
554 significant byte of the CLIENT-READ-KEY.
556 Data is fed to the MD5 hash function in the order shown, from left to 
557 right: first the MASTER-KEY, then the "0" or "1", then the 
558 CHALLENGE and then finally the CONNECTION-ID.
560 Note that the "0" means the ascii zero character (0x30), not a zero value. 
561 "1" means the ascii 1 character (0x31). MD5 produces 128 bits of output 
562 data which are used directly as the key to the cipher algorithm (The most 
563 significant byte of the MD5 output becomes the most significant byte of 
564 the key material).
566 SSL_CK_DES_64_CBC_WITH_MD5
568  KEY-MATERIAL-0 = MD5[ MASTER-KEY, CHALLENGE, 
569 CONNECTION-ID ]
571  CLIENT-READ-KEY = KEY-MATERIAL-0[0-7]
572  CLIENT-WRITE-KEY = KEY-MATERIAL-0[8-15]
574 For DES-CBC, a single 16 bytes of key material are produced using MD5. 
575 The first 8 bytes of the MD5 digest are used as the CLIENT-READ-KEY 
576 while the remaining 8 bytes are used as the CLIENT-WRITE-KEY. The 
577 initialization vector is provided in the KEY-ARG-DATA. Note that the 
578 raw key data is not parity adjusted and that this step must be performed 
579 before the keys are legitimate DES keys.
581 SSL_CK_DES_192_EDE3_CBC_WITH_MD5
584 Hickman                                                 [page  10]
586  KEY-MATERIAL-0 = MD5[ MASTER-KEY, "0", CHALLENGE, 
587 CONNECTION-ID ]
588  KEY-MATERIAL-1 = MD5[ MASTER-KEY, "1", CHALLENGE, 
589 CONNECTION-ID ]
590  KEY-MATERIAL-2 = MD5[ MASTER-KEY, "2", CHALLENGE, 
591 CONNECTION-ID ]
593  CLIENT-READ-KEY-0 = KEY-MATERIAL-0[0-7]
594  CLIENT-READ-KEY-1 = KEY-MATERIAL-0[8-15]
595  CLIENT-READ-KEY-2 = KEY-MATERIAL-1[0-7]
596  CLIENT-WRITE-KEY-0 = KEY-MATERIAL-1[8-15]
597  CLIENT-WRITE-KEY-1 = KEY-MATERIAL-2[0-7]
598  CLIENT-WRITE-KEY-2 = KEY-MATERIAL-2[8-15]
600 Data is fed to the MD5 hash function in the order shown, from left to 
601 right: first the MASTER-KEY, then the "0", "1" or "2", then the 
602 CHALLENGE and then finally the CONNECTION-ID. Note that the 
603 "0" means the ascii zero character (0x30), not a zero value. "1" means the 
604 ascii 1 character (0x31). "2" means the ascii 2 character (0x32).
606 A total of 6 keys are produced, 3 for the read side DES-EDE3 cipher and 3 
607 for the write side DES-EDE3 function. The initialization vector is 
608 provided in the KEY-ARG-DATA. The keys that are produced are not 
609 parity adjusted. This step must be performed before proper DES keys are 
610 usable.
612 Recall that the MASTER-KEY is given to the server in the CLIENT-
613 MASTER-KEY message. The CHALLENGE is given to the server by 
614 the client in the CLIENT-HELLO message. The CONNECTION-ID is 
615 given to the client by the server in the SERVER-HELLO message. This 
616 makes the resulting cipher keys a function of the original session and the 
617 current session. Note that the master key is never directly used to encrypt 
618 data, and therefore cannot be easily discovered.
620 The CLIENT-MASTER-KEY message must be sent after the CLIENT-
621 HELLO message and before the CLIENT-FINISHED message. The 
622 CLIENT-MASTER-KEY message must be sent if the SERVER-
623 HELLO message contains a SESSION-ID-HIT value of 0.
625 5.5.3 CLIENT-CERTIFICATE (Phase 2; Sent encrypted)
627 char MSG-CLIENT-CERTIFICATE
628 char CERTIFICATE-TYPE
629 char CERTIFICATE-LENGTH-MSB
630 char CERTIFICATE-LENGTH-LSB
631 char RESPONSE-LENGTH-MSB
632 char RESPONSE-LENGTH-LSB
633 char CERTIFICATE-DATA[MSB<<8|LSB]
634 char RESPONSE-DATA[MSB<<8|LSB]
636 This message is sent by one an SSL client in response to a server 
637 REQUEST-CERTIFICATE message. The CERTIFICATE-DATA 
638 contains data defined by the CERTIFICATE-TYPE value. An ERROR 
639 message is sent with error code NO-CERTIFICATE-ERROR when this 
640 request cannot be answered properly (e.g. the receiver of the message has 
642 Hickman                                                 [page 11]
644 no registered certificate).
646 CERTIFICATE-TYPE is one of:
648 SSL_X509_CERTIFICATE
649 The CERTIFICATE-DATA contains an X.509 (1988) [3] signed 
650 certificate.
652 The RESPONSE-DATA contains the authentication response data. This 
653 data is a function of the AUTHENTICATION-TYPE value sent by the 
654 server.
656 When AUTHENTICATION-TYPE is 
657 SSL_AT_MD5_WITH_RSA_ENCRYPTION then the RESPONSE-
658 DATA contains a digital signature of the following components (in the 
659 order shown):
661   the KEY-MATERIAL-0
662   the KEY-MATERIAL-1 (only if defined by the cipher kind)
663   the KEY-MATERIAL-2 (only if defined by the cipher kind)
664   the CERTIFICATE-CHALLENGE-DATA (from the 
665 REQUEST-CERTIFICATE message)
666   the server's signed certificate (from the SERVER-HELLO 
667 message)
669 The digital signature is constructed using MD5 and then encrypted using 
670 the clients private key, formatted according to PKCS#1's digital signature 
671 standard [5]. The server authenticates the client by verifying the digital 
672 signature using standard techniques. Note that other digest functions are 
673 supported. Either a new AUTHENTICATION-TYPE can be added, or 
674 the algorithm-id in the digital signature can be changed.
676 This message must be sent by the client only in response to a REQUEST-
677 CERTIFICATE message.
679 5.5.4 CLIENT-FINISHED (Phase 2; Sent encrypted)
681 char MSG-CLIENT-FINISHED
682 char CONNECTION-ID[N-1]
684 The client sends this message when it is satisfied with the server. Note that 
685 the client must continue to listen for server messages until it receives a 
686 SERVER-FINISHED message. The CONNECTION-ID data is the 
687 original connection-identifier the server sent with its SERVER-HELLO 
688 message, encrypted using the agreed upon session key.
690 "N" is the number of bytes in the message that was sent, so "N-1" is the 
691 number of bytes in the message without the message header byte.
693 For version 2 of the protocol, the client must send this message after it has 
694 received the SERVER-HELLO message. If the SERVER-HELLO 
695 message SESSION-ID-HIT flag is non-zero then the CLIENT-
696 FINISHED message is sent immediately, otherwise the CLIENT-
697 FINISHED message is sent after the CLIENT-MASTER-KEY message.
700 Hickman                                                 [page 12]
707 5.6 Server Only Protocol Messages
709 There are several messages that are only generated by servers. The 
710 messages are never generated by correctly functioning clients.
712 5.6.1 SERVER-HELLO (Phase 1; Sent in the clear)
714 char MSG-SERVER-HELLO
715 char SESSION-ID-HIT
716 char CERTIFICATE-TYPE
717 char SERVER-VERSION-MSB
718 char SERVER-VERSION-LSB
719 char CERTIFICATE-LENGTH-MSB
720 char CERTIFICATE-LENGTH-LSB
721 char CIPHER-SPECS-LENGTH-MSB
722 char CIPHER-SPECS-LENGTH-LSB
723 char CONNECTION-ID-LENGTH-MSB
724 char CONNECTION-ID-LENGTH-LSB
725 char CERTIFICATE-DATA[MSB<<8|LSB]
726 char CIPHER-SPECS-DATA[MSB<<8|LSB]
727 char CONNECTION-ID-DATA[MSB<<8|LSB]
729 The server sends this message after receiving the clients CLIENT-
730 HELLO message. The server returns the SESSION-ID-HIT flag 
731 indicating whether or not the received session-identifier is known by the 
732 server (i.e. in the server's session-identifier cache). The SESSION-ID-
733 HIT flag will be non-zero if the client sent the server a session-identifier 
734 (in the CLIENT-HELLO message with SESSION-ID-LENGTH != 0) 
735 and the server found the client's session-identifier in its cache. If the 
736 SESSION-ID-HIT flag is non-zero then the CERTIFICATE-TYPE, 
737 CERTIFICATE-LENGTH and CIPHER-SPECS-LENGTH fields will 
738 be zero.
740 The CERTIFICATE-TYPE value, when non-zero, has one of the values 
741 described above (see the information on the CLIENT-CERTIFICATE 
742 message).
744 When the SESSION-ID-HIT flag is zero, the server packages up its 
745 certificate, its cipher specs and a connection-id to send to the client. Using 
746 this information the client can generate a session key and return it to the 
747 server with the CLIENT-MASTER-KEY message.
749 When the SESSION-ID-HIT flag is non-zero, both the server and the 
750 client compute a new pair of session keys for the current session derived 
751 from the MASTER-KEY that was exchanged when the SESSION-ID 
752 was created. The SERVER-READ-KEY and SERVER-WRITE-KEY 
753 are derived from the original MASTER-KEY keys in the same manner as 
754 the CLIENT-READ-KEY and CLIENT-WRITE-KEY:
756 SERVER-READ-KEY = CLIENT-WRITE-KEY
757 SERVER-WRITE-KEY = CLIENT-READ-KEY
759 Note that when keys are being derived and the SESSION-ID-HIT flag is 
760 set and the server discovers the client's session-identifier in the servers 
761 cache, then the KEY-ARG-DATA is used from the time when the 
763 Hickman                                                 [page 13]
765 SESSION-ID was established. This is because the client does not send 
766 new KEY-ARG-DATA (recall that the KEY-ARG-DATA is sent only in 
767 the CLIENT-MASTER-KEY message).
769 The CONNECTION-ID-DATA is a string of randomly generated bytes 
770 used by the server and client at various points in the protocol. The 
771 CLIENT-FINISHED message contains an encrypted version of the 
772 CONNECTION-ID-DATA. The length of the CONNECTION-ID must 
773 be between 16 and than 32 bytes, inclusive.
775 The CIPHER-SPECS-DATA define a cipher type and key length (in bits) 
776 that the receiving end supports. Each SESSION-CIPHER-SPEC is 3 
777 bytes long and looks like this:
779 char CIPHER-KIND-0
780 char CIPHER-KIND-1
781 char CIPHER-KIND-2
783 Where CIPHER-KIND is one of:
785 SSL_CK_RC4_128_WITH_MD5
786 SSL_CK_RC4_128_EXPORT40_WITH_MD5
787 SSL_CK_RC2_128_CBC_WITH_MD5
788 SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5
789 SSL_CK_IDEA_128_CBC_WITH_MD5
790 SSL_CK_DES_64_CBC_WITH_MD5
791 SSL_CK_DES_192_EDE3_CBC_WITH_MD5
793 This list is not exhaustive and may be changed in the future.
795 The SSL_CK_RC4_128_EXPORT40_WITH_MD5 cipher is an RC4 
796 cipher where some of the session key is sent in the clear and the rest is sent 
797 encrypted (exactly 40 bits of it). MD5 is used as the hash function for 
798 production of MAC's and session key's. This cipher type is provided to 
799 support "export" versions (i.e. versions of the protocol that can be 
800 distributed outside of the United States) of the client or server.
802 An exportable implementation of the SSL Handshake Protocol will have 
803 secret key lengths restricted to 40 bits. For non-export implementations 
804 key lengths can be more generous (we recommend at least 128 bits). It is 
805 permissible for the client and server to have a non-intersecting set of 
806 stream ciphers. This, simply put, means they cannot communicate.
808 Version 2 of the SSL Handshake Protocol defines the 
809 SSL_CK_RC4_128_WITH_MD5 to have a key length of 128 bits. The 
810 SSL_CK_RC4_128_EXPORT40_WITH_MD5 also has a key length of 
811 128 bits. However, only 40 of the bits are secret (the other 88 bits are sent 
812 in the clear by the client to the server).
814 The SERVER-HELLO message is sent after the server receives the 
815 CLIENT-HELLO message, and before the server sends the SERVER-
816 VERIFY message.
817 5.6.2 SERVER-VERIFY (Phase 1; Sent encrypted)
819 char MSG-SERVER-VERIFY
821 Hickman                                                 [page 14]
823 char CHALLENGE-DATA[N-1]
825 The server sends this message after a pair of session keys (SERVER-
826 READ-KEY and SERVER-WRITE-KEY) have been agreed upon either 
827 by a session-identifier or by explicit specification with the CLIENT-
828 MASTER-KEY message. The message contains an encrypted copy of the 
829 CHALLENGE-DATA sent by the client in the CLIENT-HELLO 
830 message.
832 "N" is the number of bytes in the message that was sent, so "N-1" is the 
833 number of bytes in the CHALLENGE-DATA without the message 
834 header byte.
836 This message is used to verify the server as follows. A legitimate server 
837 will have the private key that corresponds to the public key contained in 
838 the server certificate that was transmitted in the SERVER-HELLO 
839 message. Accordingly, the legitimate server will be able to extract and 
840 reconstruct the pair of session keys (SERVER-READ-KEY and 
841 SERVER-WRITE-KEY). Finally, only a server that has done the 
842 extraction and decryption properly can correctly encrypt the 
843 CHALLENGE-DATA. This, in essence, "proves" that the server has the 
844 private key that goes with the public key in the server's certificate.
846 The CHALLENGE-DATA must be the exact same length as originally 
847 sent by the client in the CLIENT-HELLO message. Its value must match 
848 exactly the value sent in the clear by the client in the CLIENT-HELLO 
849 message. The client must decrypt this message and compare the value 
850 received with the value sent, and only if the values are identical is the 
851 server to be "trusted". If the lengths do not match or the value doesn't 
852 match then the connection is to be closed by the client.
854 This message must be sent by the server to the client after either detecting 
855 a session-identifier hit (and replying with a SERVER-HELLO message 
856 with SESSION-ID-HIT not equal to zero) or when the server receives the 
857 CLIENT-MASTER-KEY message. This message must be sent before 
858 any Phase 2 messages or a SERVER-FINISHED message.
860 5.6.3 SERVER-FINISHED (Phase 2; Sent encrypted)
862 char MSG-SERVER-FINISHED
863 char SESSION-ID-DATA[N-1]
865 The server sends this message when it is satisfied with the clients security 
866 handshake and is ready to proceed with transmission/reception of the 
867 higher level protocols data. The SESSION-ID-DATA is used by the client 
868 and the server at this time to add entries to their respective session-
869 identifier caches. The session-identifier caches must contain a copy of the 
870 MASTER-KEY sent in the CLIENT-MASTER-KEY message as the 
871 master key is used for all subsequent session key generation.
873 "N" is the number of bytes in the message that was sent, so "N-1" is the 
874 number of bytes in the SESSION-ID-DATA without the message header 
875 byte.
877 This message must be sent after the SERVER-VERIFY message.
879 Hickman                                                 [page 15]
881 5.6.4 REQUEST-CERTIFICATE (Phase 2; Sent encrypted)
883 char MSG-REQUEST-CERTIFICATE
884 char AUTHENTICATION-TYPE
885 char CERTIFICATE-CHALLENGE-DATA[N-2]
887 A server may issue this request at any time during the second phase of the 
888 connection handshake, asking for the client's certificate. The client 
889 responds with a CLIENT-CERTIFICATE message immediately if it has 
890 one, or an ERROR message (with error code NO-CERTIFICATE-
891 ERROR) if it doesn't. The CERTIFICATE-CHALLENGE-DATA is a 
892 short byte string (whose length is greater than or equal to 16 bytes and less 
893 than or equal to 32 bytes) that the client will use to respond to this 
894 message.
896 The AUTHENTICATION-TYPE value is used to choose a particular 
897 means of authenticating the client. The following types are defined:
899 SSL_AT_MD5_WITH_RSA_ENCRYPTION
901 The SSL_AT_MD5_WITH_RSA_ENCRYPTION type requires that the 
902 client construct an MD5 message digest using information as described 
903 above in the section on the CLIENT-CERTIFICATE message. Once the 
904 digest is created, the client encrypts it using its private key (formatted 
905 according to the digital signature standard defined in PKCS#1). The server 
906 authenticates the client when it receives the CLIENT-CERTIFICATE 
907 message.
909 This message may be sent after a SERVER-VERIFY message and before 
910 a SERVER-FINISHED message.
912 5.7 Client/Server Protocol Messages
914 These messages are generated by both the client and the server.
916 5.7.1 ERROR (Sent clear or encrypted)
918 char MSG-ERROR
919 char ERROR-CODE-MSB
920 char ERROR-CODE-LSB
922 This message is sent when an error is detected. After the message is sent, 
923 the sending party shuts the connection down. The receiving party records 
924 the error and then shuts its connection down.
926 This message is sent in the clear if an error occurs during session key 
927 negotiation. After a session key has been agreed upon, errors are sent 
928 encrypted like all other messages.
930 Appendix A: ASN.1 Syntax For Certificates
932 Certificates are used by SSL to authenticate servers and clients. SSL 
933 Certificates are based largely on the X.509 [3] certificates. An X.509 
934 certificate contains the following information (in ASN.1 [1] notation):
936 Hickman                                                 [page 16]
938 X.509-Certificate ::= SEQUENCE {
939   certificateInfo CertificateInfo,
940   signatureAlgorithm AlgorithmIdentifier,
941   signature BIT STRING
944 CertificateInfo ::= SEQUENCE {
945   version [0] Version DEFAULT v1988,
946   serialNumber CertificateSerialNumber,
947   signature AlgorithmIdentifier,
948   issuer Name,
949   validity Validity,
950   subject Name,
951   subjectPublicKeyInfo SubjectPublicKeyInfo
954 Version ::= INTEGER { v1988(0) }
956 CertificateSerialNumber ::= INTEGER
958 Validity ::= SEQUENCE {
959   notBefore UTCTime,
960   notAfter UTCTime
963 SubjectPublicKeyInfo ::= SEQUENCE {
964   algorithm AlgorithmIdentifier,
965   subjectPublicKey BIT STRING
968 AlgorithmIdentifier ::= SEQUENCE {
969   algorithm OBJECT IDENTIFIER,
970   parameters ANY DEFINED BY ALGORITHM OPTIONAL
973 For SSL's purposes we restrict the values of some of the X.509 fields:
975   The X.509-Certificate::signatureAlgorithm and 
976 CertificateInfo::signature fields must be identical in value.
978   The issuer name must resolve to a name that is deemed acceptable by 
979 the application using SSL. How the application using SSL does this is 
980 outside the scope of this memo.
982 Certificates are validated using a few straightforward steps. First, the 
983 signature on the certificate is checked and if invalid, the certificate is 
984 invalid (either a transmission error or an attempted forgery occurred). 
985 Next, the CertificateInfo::issuer field is verified to be an issuer that the 
986 application trusts (using an unspecified mechanism). The 
987 CertificateInfo::validity field is checked against the current date and 
988 verified.
990 Finally, the CertificateInfo::subject field is checked. This check is 
991 optional and depends on the level of trust required by the application using 
992 SSL.
994 Hickman                                                 [page 17]
996 Appendix B: Attribute Types and Object Identifiers
998 SSL uses a subset of the X.520 selected attribute types as well as a
999 few specific object identifiers. Future revisions of the SSL protocol
1000 may include support for more attribute types and more object
1001 identifiers.
1003 B.1 Selected attribute types
1005 commonName { attributeType 3 }
1006 The common name contained in the distinguished name contained 
1007 within a certificate issuer or certificate subject.
1009 countryName { attributeType 6 }
1010 The country name contained in the distinguished name contained 
1011 within a certificate issuer or certificate subject.
1013 localityName { attributeType 7 }
1014 The locality name contained in the distinguished name contained 
1015 within a certificate issuer or certificate subject.
1017 stateOrProvinceName { attributeType 8 }
1018 The state or province name contained in the distinguished name 
1019 contained within a certificate issuer or certificate subject.
1021 organizationName { attributeType 10 }
1022 The organization name contained in the distinguished name contained 
1023 within a certificate issuer or certificate subject.
1025 organizationalUnitName { attributeType 11 }
1026 The organizational unit name contained in the distinguished name 
1027 contained within a certificate issuer or certificate subject.
1029 B.2 Object identifiers
1031 md2withRSAEncryption { ... pkcs(1) 1 2 }
1032 The object identifier for digital signatures that use both MD2 and RSA 
1033 encryption. Used by SSL for certificate signature verification.
1035 md5withRSAEncryption { ... pkcs(1) 1 4 }
1036 The object identifier for digital signatures that use both MD5 and RSA 
1037 encryption. Used by SSL for certificate signature verification.
1039 rc4 { ... rsadsi(113549) 3 4 }
1040 The RC4 symmetric stream cipher algorithm used by SSL for bulk 
1041 encryption.
1043 Appendix C: Protocol Constant Values
1045 This section describes various protocol constants. A special value needs 
1046 mentioning - the IANA reserved port number for "https" (HTTP using 
1047 SSL). IANA has reserved port number 443 (decimal) for "https". IANA 
1048 has also reserved port number 465 for "ssmtp" and port number 563 for 
1049 "snntp".
1051 Hickman                                                 [page 18]
1053 C.1 Protocol Version Codes
1055 #define SSL_CLIENT_VERSION 0x0002
1056 #define SSL_SERVER_VERSION 0x0002
1058 C.2 Protocol Message Codes
1060 The following values define the message codes that are used by version
1061 2 of the SSL Handshake Protocol.
1063 #define SSL_MT_ERROR                    0
1064 #define SSL_MT_CLIENT_HELLO             1
1065 #define SSL_MT_CLIENT_MASTER_KEY        2
1066 #define SSL_MT_CLIENT_FINISHED          3
1067 #define SSL_MT_SERVER_HELLO             4
1068 #define SSL_MT_SERVER_VERIFY            5
1069 #define SSL_MT_SERVER_FINISHED          6
1070 #define SSL_MT_REQUEST_CERTIFICATE      7
1071 #define SSL_MT_CLIENT_CERTIFICATE       8
1073 C.3 Error Message Codes
1075 The following values define the error codes used by the ERROR message.
1077 #define SSL_PE_NO_CIPHER                        0x0001
1078 #define SSL_PE_NO_CERTIFICATE                   0x0002
1079 #define SSL_PE_BAD_CERTIFICATE                  0x0004
1080 #define SSL_PE_UNSUPPORTED_CERTIFICATE_TYPE     0x0006
1082 C.4 Cipher Kind Values
1084 The following values define the CIPHER-KIND codes used in the 
1085 CLIENT-HELLO and SERVER-HELLO messages.
1087 #define SSL_CK_RC4_128_WITH_MD5         
1088         0x01,0x00,0x80
1089 #define SSL_CK_RC4_128_EXPORT40_WITH_MD5        
1090         0x02,0x00,0x80
1091 #define SSL_CK_RC2_128_CBC_WITH_MD5             
1092         0x03,0x00,0x80
1093 #define SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5
1094         0x04,0x00,0x80
1095 #define SSL_CK_IDEA_128_CBC_WITH_MD5    
1096         0x05,0x00,0x80
1097 #define SSL_CK_DES_64_CBC_WITH_MD5              
1098         0x06,0x00,0x40
1099 #define SSL_CK_DES_192_EDE3_CBC_WITH_MD5        
1100         0x07,0x00,0xC0
1102 C.5 Certificate Type Codes
1104 The following values define the certificate type codes used in the 
1105 SERVER-HELLO and CLIENT-CERTIFICATE messages.
1107 #define SSL_CT_X509_CERTIFICATE         0x01
1109 Hickman                                                 [page 19]
1111 C.6 Authentication Type Codes
1113 The following values define the authentication type codes used in the 
1114 REQUEST-CERTIFICATE message.
1116 #define SSL_AT_MD5_WITH_RSA_ENCRYPTION 0x01
1118 C.7 Upper/Lower Bounds
1120 The following values define upper/lower bounds for various protocol 
1121 parameters.
1123 #define SSL_MAX_MASTER_KEY_LENGTH_IN_BITS       256
1124 #define SSL_MAX_SESSION_ID_LENGTH_IN_BYTES      16
1125 #define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES     64
1126 #define SSL_MAX_RECORD_LENGTH_2_BYTE_HEADER     32767
1127 #define SSL_MAX_RECORD_LENGTH_3_BYTE_HEADER     16383
1129 C.8 Recommendations
1131 Because protocols have to be implemented to be of value, we recommend 
1132 the following values for various operational parameters. This is only a 
1133 recommendation, and not a strict requirement for conformance to the 
1134 protocol.
1136 Session-identifier Cache Timeout
1138 Session-identifiers are kept in SSL clients and SSL servers. Session-
1139 identifiers should have a lifetime that serves their purpose (namely, 
1140 reducing the number of expensive public key operations for a single 
1141 client/server pairing). Consequently, we recommend a maximum session-
1142 identifier cache timeout value of 100 seconds. Given a server that can 
1143 perform N private key operations per second, this reduces the server load 
1144 for a particular client by a factor of 100.
1146 Appendix D: Attacks
1148 In this section we attempt to describe various attacks that might be used 
1149 against the SSL protocol. This list is not guaranteed to be exhaustive. SSL 
1150 was defined to thwart these attacks.
1152 D.1 Cracking Ciphers
1154 SSL depends on several cryptographic technologies. RSA Public Key 
1155 encryption [5] is used for the exchange of the session key and client/server 
1156 authentication. Various cryptographic algorithms are used for the session 
1157 cipher. If successful cryptographic attacks are made against these 
1158 technologies then SSL is no longer secure.
1160 Attacks against a specific communications session can be made by 
1161 recording the session, and then spending some large number of compute 
1162 cycles to crack either the session key or the RSA public key until the 
1163 communication can be seen in the clear. This approach is easier than 
1164 cracking the cryptographic technologies for all possible messages. Note 
1165 that SSL tries to make the cost of such of an attack greater than the 
1167 Hickman                                                 [page 20]
1169 benefits gained from a successful attack, thus making it a waste of 
1170 money/time to perform such an attack.
1172 There have been many books [9] and papers [10] written on cryptography. 
1173 This document does not attempt to reference them all.
1175 D.2 Clear Text Attack
1177 A clear text attack is done when the attacker has an idea of what kind of 
1178 message is being sent using encryption. The attacker can generate a data 
1179 base whose keys are the encrypted value of the known text (or clear text), 
1180 and whose values are the session cipher key (we call this a "dictionary"). 
1181 Once this data base is constructed, a simple lookup function identifies the 
1182 session key that goes with a particular encrypted value. Once the session 
1183 key is known, the entire message stream can be decrypted. Custom 
1184 hardware can be used to make this cost effective and very fast.
1186 Because of the very nature of SSL clear text attacks are possible. For 
1187 example, the most common byte string sent by an HTTP client application 
1188 to an HTTP server is "GET". SSL attempts to address this attack by using 
1189 large session cipher keys. First, the client generates a key which is larger 
1190 than allowed by export, and sends some of it in the clear to the server (this 
1191 is allowed by United States government export rules). The clear portion of 
1192 the key concatenated with the secret portion make a key which is very 
1193 large (for RC4, exactly 128 bits).
1195 The way that this "defeats" a clear text attack is by making the amount of 
1196 custom hardware needed prohibitively large. Every bit added to the length 
1197 of the session cipher key increases the dictionary size by a factor of 2. By 
1198 using a 128 bit session cipher key length the size of the dictionary required 
1199 is beyond the ability of anyone to fabricate (it would require more atoms to 
1200 construct than exist in the entire universe). Even if a smaller dictionary is 
1201 to be used, it must first be generated using the clear key bits. This is a time 
1202 consumptive process and also eliminates many possible custom hardware 
1203 architectures (e.g. static prom arrays).
1205 The second way that SSL attacks this problem is by using large key 
1206 lengths when permissible (e.g. in the non-export version). Large key sizes 
1207 require larger dictionaries (just one more bit of key size doubles the size of 
1208 the dictionary). SSL attempts to use keys that are 128 bits in length.
1210 Note that the consequence of the SSL defense is that a brute force attack 
1211 becomes the cheapest way to attack the key. Brute force attacks have well 
1212 known space/time tradeoffs and so it becomes possible to define a cost of 
1213 the attack. For the 128 bit secret key, the known cost is essentially infinite. 
1214 For the 40 bit secret key, the cost is much smaller, but still outside the 
1215 range of the "random hacker".
1217 D.3 Replay
1219 The replay attack is simple. A bad-guy records a communication session 
1220 between a client and server. Later, it reconnects to the server, and plays 
1221 back the previously recorded client messages.  SSL defeats this attack 
1222 using a "nonce" (the connection-id) which is "unique" to the connection. In 
1223 theory the bad-guy cannot predict the nonce in advance as it is based on a 
1225 Hickman                                                 [page 21]
1227 set of random events outside the bad-guys control, and therefore the bad-
1228 guy cannot respond properly to server requests.
1230 A bad-guy with large resources can record many sessions between a client 
1231 and a server, and attempt to choose the right session based on the nonce 
1232 the server sends initially in its SERVER-HELLO message. However, SSL 
1233 nonces are at least 128 bits long, so a bad-guy would need to record 
1234 approximately 2^64 nonces to even have a 50% chance of choosing the 
1235 right session. This number is sufficiently large that one cannot 
1236 economically construct a device to record 2^64 messages, and therefore 
1237 the odds are overwhelmingly against the replay attack ever being 
1238 successful.
1240 D.4 The Man In The Middle
1242 The man in the middle attack works by having three people in a 
1243 communications session: the client, the server, and the bad guy. The bad 
1244 guy sits between the client and the server on the network and intercepts 
1245 traffic that the client sends to the server, and traffic that the server
1246 sends to 
1247 the client.
1249 The man in the middle operates by pretending to be the real server to the 
1250 client. With SSL this attack is impossible because of the usage of server 
1251 certificates. During the security connection handshake the server is 
1252 required to provide a certificate that is signed by a certificate authority. 
1253 Contained in the certificate is the server's public key as well as its name 
1254 and the name of the certificate issuer. The client verifies the certificate by 
1255 first checking the signature and then verifying that the name of the issuer 
1256 is somebody that the client trusts.
1258 In addition, the server must encrypt something with the private key that 
1259 goes with the public key mentioned in the certificate. This in essence is a 
1260 single pass "challenge response" mechanism. Only a server that has both 
1261 the certificate and the private key can respond properly to the challenge.
1263 If the man in the middle provides a phony certificate, then the signature 
1264 check will fail. If the certificate provided by the bad guy is legitimate, but 
1265 for the bad guy instead of for the real server, then the signature will pass 
1266 but the name check will fail (note that the man in the middle cannot forge 
1267 certificates without discovering a certificate authority's private key).
1269 Finally, if the bad guy provides the real server's certificate then the 
1270 signature check will pass and the name check will pass. However, because 
1271 the bad guy does not have the real server's private key, the bad guy cannot 
1272 properly encode the response to the challenge code, and this check will 
1273 fail.
1275 In the unlikely case that a bad guy happens to guess the response code to 
1276 the challenge, the bad guy still cannot decrypt the session key and 
1277 therefore cannot examine the encrypted data.
1280 Hickman                                                 [page 22]
1282 Appendix E: Terms
1284 Application Protocol
1285 An application protocol is a protocol that normally layers directly on 
1286 top of TCP/IP. For example: HTTP, TELNET, FTP, and SMTP.
1288 Authentication
1289 Authentication is the ability of one entity to determine the identity of 
1290 another entity. Identity is defined by this document to mean the 
1291 binding between a public key and a name and the implicit ownership 
1292 of the corresponding private key.
1294 Bulk Cipher
1295 This term is used to describe a cryptographic technique with certain 
1296 performance properties. Bulk ciphers are used when large quantities of 
1297 data are to be encrypted/decrypted in a timely manner. Examples 
1298 include RC2, RC4, and IDEA.
1300 Client
1301 In this document client refers to the application entity that is initiates a 
1302 connection to a server.
1304 CLIENT-READ-KEY
1305 The session key that the client uses to initialize the client read cipher. 
1306 This key has the same value as the SERVER-WRITE-KEY.
1308 CLIENT-WRITE-KEY
1309 The session key that the client uses to initialize the client write cipher. 
1310 This key has the same value as the SERVER-READ-KEY.
1312 MASTER-KEY
1313 The master key that the client and server use for all session key 
1314 generation. The CLIENT-READ-KEY, CLIENT-WRITE-KEY, 
1315 SERVER-READ-KEY and SERVER-WRITE-KEY are generated 
1316 from the MASTER-KEY.
1319 MD2 [8] is a hashing function that converts an arbitrarily long data 
1320 stream into a digest of fixed size. This function predates MD5 [7] 
1321 which is viewed as a more robust hash function [9].
1324 MD5 [7] is a hashing function that converts an arbitrarily long data 
1325 stream into a digest of fixed size. The function has certain properties 
1326 that make it useful for security, the most important of which is it's 
1327 inability to be reversed.
1329 Nonce
1330 A randomly generated value used to defeat "playback" attacks. One 
1331 party randomly generates a nonce and sends it to the other party. The 
1332 receiver encrypts it using the agreed upon secret key and returns it to 
1333 the sender. Because the nonce was randomly generated by the sender 
1334 this defeats playback attacks because the replayer can't know in 
1335 advance the nonce the sender will generate. The receiver denies 
1336 connections that do not have the correctly encrypted nonce.
1338 Hickman                                                 [page 23]
1340 Non-repudiable Information Exchange
1341 When two entities exchange information it is sometimes valuable to 
1342 have a record of the communication that is non-repudiable. Neither 
1343 party can then deny that the information exchange occurred. Version 2 
1344 of the SSL protocol does not support Non-repudiable information 
1345 exchange.
1347 Public Key Encryption
1348 Public key encryption is a technique that leverages asymmetric ciphers. 
1349 A public key system consists of two keys: a public key and a private 
1350 key. Messages encrypted with the public key can only be decrypted 
1351 with the associated private key. Conversely, messages encrypted with 
1352 the private key can only be decrypted with the public key. Public key 
1353 encryption tends to be extremely compute intensive and so is not 
1354 suitable as a bulk cipher.
1356 Privacy
1357 Privacy is the ability of two entities to communicate without fear of 
1358 eavesdropping. Privacy is often implemented by encrypting the 
1359 communications stream between the two entities.
1361 RC2, RC4
1362 Proprietary bulk ciphers invented by RSA (There is no good reference 
1363 to these as they are unpublished works; however, see [9]). RC2 is 
1364 block cipher and RC4 is a stream cipher.
1366 Server
1367 The server is the application entity that responds to requests for 
1368 connections from clients. The server is passive, waiting for requests 
1369 from clients.
1371 Session cipher
1372 A session cipher is a "bulk" cipher that is capable of encrypting or 
1373 decrypting arbitrarily large amounts of data. Session ciphers are used 
1374 primarily for performance reasons. The session ciphers used by this 
1375 protocol are symmetric. Symmetric ciphers have the property of using 
1376 a single key for encryption and decryption.
1378 Session identifier
1379 A session identifier is a random value generated by a client that 
1380 identifies itself to a particular server. The session identifier can be 
1381 thought of as a handle that both parties use to access a recorded secret 
1382 key (in our case a session key). If both parties remember the session 
1383 identifier then the implication is that the secret key is already known 
1384 and need not be negotiated.
1386 Session key
1387 The key to the session cipher. In SSL there are four keys that are called 
1388 session keys: CLIENT-READ-KEY, CLIENT-WRITE-KEY, 
1389 SERVER-READ-KEY, and SERVER-WRITE-KEY.
1391 SERVER-READ-KEY
1392 The session key that the server uses to initialize the server read cipher. 
1393 This key has the same value as the CLIENT-WRITE-KEY.
1396 Hickman                                                 [page 24]
1398 SERVER-WRITE-KEY
1399 The session key that the server uses to initialize the server write cipher. 
1400 This key has the same value as the CLIENT-READ-KEY.
1402 Symmetric Cipher
1403 A symmetric cipher has the property that the same key can be used for 
1404 decryption and encryption. An asymmetric cipher does not have this 
1405 behavior. Some examples of symmetric ciphers: IDEA, RC2, RC4.
1409 References
1411 [1] CCITT. Recommendation X.208: "Specification of Abstract Syntax 
1412 Notation One (ASN.1). 1988.
1414 [2] CCITT. Recommendation X.209: "Specification of Basic Encoding 
1415 Rules for Abstract Syntax Notation One (ASN.1). 1988.
1417 [3] CCITT. Recommendation X.509: "The Directory - Authentication 
1418 Framework". 1988.
1420 [4] CCITT. Recommendation X.520: "The Directory - Selected Attribute 
1421 Types". 1988.
1423 [5] RSA Laboratories. PKCS #1: RSA Encryption Standard, Version 1.5, 
1424 November 1993.
1426 [6] RSA Laboratories. PKCS #6: Extended-Certificate Syntax Standard, 
1427 Version 1.5, November 1993.
1429 [7] R. Rivest. RFC 1321: The MD5 Message Digest Algorithm. April 
1430 1992.
1432 [8] R. Rivest. RFC 1319: The MD2 Message Digest Algorithm. April 
1433 1992.
1435 [9] B. Schneier. Applied Cryptography: Protocols, Algorithms, and Source 
1436 Code in C, Published by John Wiley & Sons, Inc. 1994.
1438 [10] M. Abadi and R. Needham. Prudent engineering practice for 
1439 cryptographic protocols. 1994.
1441 Patent Statement
1443 This version of the SSL protocol relies on the use of patented public key 
1444 encryption technology for authentication and encryption. The Internet 
1445 Standards Process as defined in RFC 1310 requires a written statement 
1446 from the Patent holder that a license will be made available to applicants 
1447 under reasonable terms and conditions prior to approving a specification as 
1448 a Proposed, Draft or Internet Standard.
1450 The Massachusetts Institute of Technology and the Board of Trustees of 
1451 the Leland Stanford Junior University have granted Public Key Partners 
1452 (PKP) exclusive sub-licensing rights to the following patents issued in the 
1454 Hickman                                                 [page 25]
1456 United States, and all of their corresponding foreign patents:
1458 Cryptographic Apparatus and Method ("Diffie-Hellman")           
1459         No. 4,200,770
1461 Public Key Cryptographic Apparatus and Method ("Hellman-Merkle")        
1462         No. 4,218,582
1464 Cryptographic Communications System and Method ("RSA")          
1465         No. 4,405,829
1467 Exponential Cryptographic Apparatus and Method ("Hellman-Pohlig")       
1468         No. 4,424,414
1470 These patents are stated by PKP to cover all known methods of practicing 
1471 the art of Public Key encryption, including the variations collectively 
1472 known as ElGamal.
1474 Public Key Partners has provided written assurance to the Internet Society 
1475 that parties will be able to obtain, under reasonable, nondiscriminatory 
1476 terms, the right to use the technology covered by these patents. This 
1477 assurance is documented in RFC 1170 titled "Public Key Standards and 
1478 Licenses". A copy of the written assurance dated April 20, 1990, may be 
1479 obtained from the Internet Assigned Number Authority (IANA).
1481 The Internet Society, Internet Architecture Board, Internet Engineering 
1482 Steering Group and the Corporation for National Research Initiatives take 
1483 no position on the validity or scope of the patents and patent applications, 
1484 nor on the appropriateness of the terms of the assurance. The Internet 
1485 Society and other groups mentioned above have not made any 
1486 determination as to any other intellectual property rights which may apply 
1487 to the practice of this standard. Any further consideration of these matters 
1488 is the user's own responsibility.
1490 Security Considerations
1492 This entire document is about security.
1494 Author's Address
1496 Kipp E.B. Hickman
1497 Netscape Communications Corp.
1498 501 East Middlefield Rd.
1499 Mountain View, CA 94043
1500 kipp@netscape.com
1503 Hickman                                                 [page 26]