OLD | NEW |
1 /* | 1 /* |
2 * This file is PRIVATE to SSL and should be the first thing included by | 2 * This file is PRIVATE to SSL and should be the first thing included by |
3 * any SSL implementation file. | 3 * any SSL implementation file. |
4 * | 4 * |
5 * ***** BEGIN LICENSE BLOCK ***** | 5 * ***** BEGIN LICENSE BLOCK ***** |
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
7 * | 7 * |
8 * The contents of this file are subject to the Mozilla Public License Version | 8 * The contents of this file are subject to the Mozilla Public License Version |
9 * 1.1 (the "License"); you may not use this file except in compliance with | 9 * 1.1 (the "License"); you may not use this file except in compliance with |
10 * the License. You may obtain a copy of the License at | 10 * the License. You may obtain a copy of the License at |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "sslerr.h" | 55 #include "sslerr.h" |
56 #include "ssl3prot.h" | 56 #include "ssl3prot.h" |
57 #include "hasht.h" | 57 #include "hasht.h" |
58 #include "nssilock.h" | 58 #include "nssilock.h" |
59 #include "pkcs11t.h" | 59 #include "pkcs11t.h" |
60 #if defined(XP_UNIX) || defined(XP_BEOS) | 60 #if defined(XP_UNIX) || defined(XP_BEOS) |
61 #include "unistd.h" | 61 #include "unistd.h" |
62 #endif | 62 #endif |
63 #include "nssrwlk.h" | 63 #include "nssrwlk.h" |
64 #include "prthread.h" | 64 #include "prthread.h" |
| 65 #include "prclist.h" |
65 | 66 |
66 #include "sslt.h" /* for some formerly private types, now public */ | 67 #include "sslt.h" /* for some formerly private types, now public */ |
67 | 68 |
68 #ifdef NSS_PLATFORM_CLIENT_AUTH | 69 #ifdef NSS_PLATFORM_CLIENT_AUTH |
69 #if defined(XP_WIN32) | 70 #if defined(XP_WIN32) |
70 #include <windows.h> | 71 #include <windows.h> |
71 #include <wincrypt.h> | 72 #include <wincrypt.h> |
72 #elif defined(XP_MACOSX) | 73 #elif defined(XP_MACOSX) |
73 #include <Security/Security.h> | 74 #include <Security/Security.h> |
74 #endif | 75 #endif |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 #else | 189 #else |
189 #define SSL3_SUPPORTED_CURVES_MASK 0x3fffffe | 190 #define SSL3_SUPPORTED_CURVES_MASK 0x3fffffe |
190 #endif | 191 #endif |
191 | 192 |
192 #ifndef BPB | 193 #ifndef BPB |
193 #define BPB 8 /* Bits Per Byte */ | 194 #define BPB 8 /* Bits Per Byte */ |
194 #endif | 195 #endif |
195 | 196 |
196 #define EXPORT_RSA_KEY_LENGTH 64 /* bytes */ | 197 #define EXPORT_RSA_KEY_LENGTH 64 /* bytes */ |
197 | 198 |
| 199 #define INITIAL_DTLS_TIMEOUT_MS 1000 /* Default value from RFC 4347 = 1s*/ |
| 200 #define MAX_DTLS_TIMEOUT_MS 60000 /* 1 minute */ |
| 201 #define DTLS_FINISHED_TIMER_MS 120000 /* Time to wait in FINISHED state */ |
| 202 |
198 typedef struct sslBufferStr sslBuffer; | 203 typedef struct sslBufferStr sslBuffer; |
199 typedef struct sslConnectInfoStr sslConnectInfo; | 204 typedef struct sslConnectInfoStr sslConnectInfo; |
200 typedef struct sslGatherStr sslGather; | 205 typedef struct sslGatherStr sslGather; |
201 typedef struct sslSecurityInfoStr sslSecurityInfo; | 206 typedef struct sslSecurityInfoStr sslSecurityInfo; |
202 typedef struct sslSessionIDStr sslSessionID; | 207 typedef struct sslSessionIDStr sslSessionID; |
203 typedef struct sslSocketStr sslSocket; | 208 typedef struct sslSocketStr sslSocket; |
204 typedef struct sslSocketOpsStr sslSocketOps; | 209 typedef struct sslSocketOpsStr sslSocketOps; |
205 | 210 |
206 typedef struct ssl3StateStr ssl3State; | 211 typedef struct ssl3StateStr ssl3State; |
207 typedef struct ssl3CertNodeStr ssl3CertNode; | 212 typedef struct ssl3CertNodeStr ssl3CertNode; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int (*read) (sslSocket *, unsigned char *, int); | 285 int (*read) (sslSocket *, unsigned char *, int); |
281 int (*write) (sslSocket *, const unsigned char *, int); | 286 int (*write) (sslSocket *, const unsigned char *, int); |
282 | 287 |
283 int (*getpeername)(sslSocket *, PRNetAddr *); | 288 int (*getpeername)(sslSocket *, PRNetAddr *); |
284 int (*getsockname)(sslSocket *, PRNetAddr *); | 289 int (*getsockname)(sslSocket *, PRNetAddr *); |
285 }; | 290 }; |
286 | 291 |
287 /* Flags interpreted by ssl send functions. */ | 292 /* Flags interpreted by ssl send functions. */ |
288 #define ssl_SEND_FLAG_FORCE_INTO_BUFFER 0x40000000 | 293 #define ssl_SEND_FLAG_FORCE_INTO_BUFFER 0x40000000 |
289 #define ssl_SEND_FLAG_NO_BUFFER 0x20000000 | 294 #define ssl_SEND_FLAG_NO_BUFFER 0x20000000 |
| 295 #define ssl_SEND_FLAG_USE_EPOCH 0x10000000 /* DTLS only */ |
| 296 #define ssl_SEND_FLAG_NO_RETRANSMIT 0x08000000 /* DTLS only */ |
290 #define ssl_SEND_FLAG_MASK 0x7f000000 | 297 #define ssl_SEND_FLAG_MASK 0x7f000000 |
291 | 298 |
292 /* | 299 /* |
293 ** A buffer object. | 300 ** A buffer object. |
294 */ | 301 */ |
295 struct sslBufferStr { | 302 struct sslBufferStr { |
296 unsigned char * buf; | 303 unsigned char * buf; |
297 unsigned int len; | 304 unsigned int len; |
298 unsigned int space; | 305 unsigned int space; |
299 }; | 306 }; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 unsigned int writeOffset; | 448 unsigned int writeOffset; |
442 | 449 |
443 /* Buffer for ssl3 to read (encrypted) data from the socket */ | 450 /* Buffer for ssl3 to read (encrypted) data from the socket */ |
444 sslBuffer inbuf; /*recvBufLock*/ /* ssl3 only */ | 451 sslBuffer inbuf; /*recvBufLock*/ /* ssl3 only */ |
445 | 452 |
446 /* The ssl[23]_GatherData functions read data into this buffer, rather | 453 /* The ssl[23]_GatherData functions read data into this buffer, rather |
447 ** than into buf or inbuf, while in the GS_HEADER state. | 454 ** than into buf or inbuf, while in the GS_HEADER state. |
448 ** The portion of the SSL record header put here always comes off the wire | 455 ** The portion of the SSL record header put here always comes off the wire |
449 ** as plaintext, never ciphertext. | 456 ** as plaintext, never ciphertext. |
450 ** For SSL2, the plaintext portion is two bytes long. For SSl3 it is 5. | 457 ** For SSL2, the plaintext portion is two bytes long. For SSl3 it is 5. |
| 458 ** For DTLS it is 13. |
451 */ | 459 */ |
452 unsigned char hdr[5];» » » » » /* ssl 2 & 3 */ | 460 unsigned char hdr[13];» » » » /* ssl 2 & 3 or dtls */ |
| 461 |
| 462 /* Buffer for DTLS data read off the wire as a single datagram */ |
| 463 sslBuffer dtlsPacket; |
| 464 |
| 465 /* the start of the buffered DTLS record in dtlsPacket */ |
| 466 unsigned int dtlsPacketOffset; |
453 }; | 467 }; |
454 | 468 |
455 /* sslGather.state */ | 469 /* sslGather.state */ |
456 #define GS_INIT 0 | 470 #define GS_INIT 0 |
457 #define GS_HEADER 1 | 471 #define GS_HEADER 1 |
458 #define GS_MAC 2 | 472 #define GS_MAC 2 |
459 #define GS_DATA 3 | 473 #define GS_DATA 3 |
460 #define GS_PAD 4 | 474 #define GS_PAD 4 |
461 | 475 |
462 typedef SECStatus (*SSLCipher)(void * context, | 476 typedef SECStatus (*SSLCipher)(void * context, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 #define MAX_IV_LENGTH 24 | 528 #define MAX_IV_LENGTH 24 |
515 | 529 |
516 /* | 530 /* |
517 * Do not depend upon 64 bit arithmetic in the underlying machine. | 531 * Do not depend upon 64 bit arithmetic in the underlying machine. |
518 */ | 532 */ |
519 typedef struct { | 533 typedef struct { |
520 PRUint32 high; | 534 PRUint32 high; |
521 PRUint32 low; | 535 PRUint32 low; |
522 } SSL3SequenceNumber; | 536 } SSL3SequenceNumber; |
523 | 537 |
| 538 typedef PRUint16 DTLSEpoch; |
| 539 |
| 540 typedef void (*DTLSTimerCb)(sslSocket *); |
| 541 |
524 #define MAX_MAC_CONTEXT_BYTES 400 | 542 #define MAX_MAC_CONTEXT_BYTES 400 |
525 #define MAX_MAC_CONTEXT_LLONGS (MAX_MAC_CONTEXT_BYTES / 8) | 543 #define MAX_MAC_CONTEXT_LLONGS (MAX_MAC_CONTEXT_BYTES / 8) |
526 | 544 |
527 #define MAX_CIPHER_CONTEXT_BYTES 2080 | 545 #define MAX_CIPHER_CONTEXT_BYTES 2080 |
528 #define MAX_CIPHER_CONTEXT_LLONGS (MAX_CIPHER_CONTEXT_BYTES / 8) | 546 #define MAX_CIPHER_CONTEXT_LLONGS (MAX_CIPHER_CONTEXT_BYTES / 8) |
529 | 547 |
530 typedef struct { | 548 typedef struct { |
531 SSL3Opaque client_write_iv [24]; | 549 SSL3Opaque client_write_iv [24]; |
532 SSL3Opaque server_write_iv [24]; | 550 SSL3Opaque server_write_iv [24]; |
533 SSL3Opaque wrapped_master_secret [48]; | 551 SSL3Opaque wrapped_master_secret [48]; |
534 PRUint16 wrapped_master_secret_len; | 552 PRUint16 wrapped_master_secret_len; |
535 PRUint8 msIsWrapped; | 553 PRUint8 msIsWrapped; |
536 PRUint8 resumable; | 554 PRUint8 resumable; |
537 } ssl3SidKeys; /* 100 bytes */ | 555 } ssl3SidKeys; /* 100 bytes */ |
538 | 556 |
539 typedef struct { | 557 typedef struct { |
540 PK11SymKey *write_key; | 558 PK11SymKey *write_key; |
541 PK11SymKey *write_mac_key; | 559 PK11SymKey *write_mac_key; |
542 PK11Context *write_mac_context; | 560 PK11Context *write_mac_context; |
543 SECItem write_key_item; | 561 SECItem write_key_item; |
544 SECItem write_iv_item; | 562 SECItem write_iv_item; |
545 SECItem write_mac_key_item; | 563 SECItem write_mac_key_item; |
546 SSL3Opaque write_iv[MAX_IV_LENGTH]; | 564 SSL3Opaque write_iv[MAX_IV_LENGTH]; |
547 PRUint64 cipher_context[MAX_CIPHER_CONTEXT_LLONGS]; | 565 PRUint64 cipher_context[MAX_CIPHER_CONTEXT_LLONGS]; |
548 } ssl3KeyMaterial; | 566 } ssl3KeyMaterial; |
549 | 567 |
| 568 /* The DTLS anti-replay window. Defined here because we need it in |
| 569 * the cipher spec. Note that this is a ring buffer but left and |
| 570 * right represent the true window, with modular arithmetic used to |
| 571 * to map them onto the buffer. |
| 572 */ |
| 573 #define DTLS_RECVD_RECORDS_WINDOW 1024 /* Packets; approximate |
| 574 * Must be divisible by 8 |
| 575 */ |
| 576 typedef struct DTLSRecvdRecordsStr { |
| 577 unsigned char data[DTLS_RECVD_RECORDS_WINDOW/8]; |
| 578 PRUint64 left; |
| 579 PRUint64 right; |
| 580 } DTLSRecvdRecords; |
| 581 |
550 /* | 582 /* |
551 ** These are the "specs" in the "ssl3" struct. | 583 ** These are the "specs" in the "ssl3" struct. |
552 ** Access to the pointers to these specs, and all the specs' contents | 584 ** Access to the pointers to these specs, and all the specs' contents |
553 ** (direct and indirect) is protected by the reader/writer lock ss->specLock. | 585 ** (direct and indirect) is protected by the reader/writer lock ss->specLock. |
554 */ | 586 */ |
555 typedef struct { | 587 typedef struct { |
556 const ssl3BulkCipherDef *cipher_def; | 588 const ssl3BulkCipherDef *cipher_def; |
557 const ssl3MACDef * mac_def; | 589 const ssl3MACDef * mac_def; |
558 SSLCompressionMethod compression_method; | 590 SSLCompressionMethod compression_method; |
559 int mac_size; | 591 int mac_size; |
(...skipping 15 matching lines...) Expand all Loading... |
575 SSL3SequenceNumber read_seq_num; | 607 SSL3SequenceNumber read_seq_num; |
576 SSL3ProtocolVersion version; | 608 SSL3ProtocolVersion version; |
577 ssl3KeyMaterial client; | 609 ssl3KeyMaterial client; |
578 ssl3KeyMaterial server; | 610 ssl3KeyMaterial server; |
579 SECItem msItem; | 611 SECItem msItem; |
580 unsigned char key_block[NUM_MIXERS * MD5_LENGTH]; | 612 unsigned char key_block[NUM_MIXERS * MD5_LENGTH]; |
581 unsigned char raw_master_secret[56]; | 613 unsigned char raw_master_secret[56]; |
582 SECItem srvVirtName; /* for server: name that was negotiated | 614 SECItem srvVirtName; /* for server: name that was negotiated |
583 * with a client. For client - is | 615 * with a client. For client - is |
584 * always set to NULL.*/ | 616 * always set to NULL.*/ |
| 617 DTLSEpoch epoch; |
| 618 DTLSRecvdRecords recvdRecords; |
585 } ssl3CipherSpec; | 619 } ssl3CipherSpec; |
586 | 620 |
587 typedef enum { never_cached, | 621 typedef enum { never_cached, |
588 in_client_cache, | 622 in_client_cache, |
589 in_server_cache, | 623 in_server_cache, |
590 invalid_cache /* no longer in any cache. */ | 624 invalid_cache /* no longer in any cache. */ |
591 } Cached; | 625 } Cached; |
592 | 626 |
593 #define MAX_PEER_CERT_CHAIN_SIZE 8 | 627 #define MAX_PEER_CERT_CHAIN_SIZE 8 |
594 | 628 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 * Names data is not coppied from the input buffer. It can not be | 804 * Names data is not coppied from the input buffer. It can not be |
771 * used outside the scope where input buffer is defined and that | 805 * used outside the scope where input buffer is defined and that |
772 * is beyond ssl3_HandleClientHello function. */ | 806 * is beyond ssl3_HandleClientHello function. */ |
773 SECItem *sniNameArr; | 807 SECItem *sniNameArr; |
774 PRUint32 sniNameArrSize; | 808 PRUint32 sniNameArrSize; |
775 }; | 809 }; |
776 | 810 |
777 typedef SECStatus (*sslRestartTarget)(sslSocket *); | 811 typedef SECStatus (*sslRestartTarget)(sslSocket *); |
778 | 812 |
779 /* | 813 /* |
| 814 ** A DTLS queued message (potentially to be retransmitted) |
| 815 */ |
| 816 typedef struct DTLSQueuedMessageStr { |
| 817 PRCList link; /* The linked list link */ |
| 818 DTLSEpoch epoch; /* The epoch to use */ |
| 819 SSL3ContentType type; /* The message type */ |
| 820 unsigned char *data; /* The data */ |
| 821 PRUint16 len; /* The data length */ |
| 822 } DTLSQueuedMessage; |
| 823 |
| 824 /* |
780 ** This is the "hs" member of the "ssl3" struct. | 825 ** This is the "hs" member of the "ssl3" struct. |
781 ** This entire struct is protected by ssl3HandshakeLock | 826 ** This entire struct is protected by ssl3HandshakeLock |
782 */ | 827 */ |
783 typedef struct SSL3HandshakeStateStr { | 828 typedef struct SSL3HandshakeStateStr { |
784 SSL3Random server_random; | 829 SSL3Random server_random; |
785 SSL3Random client_random; | 830 SSL3Random client_random; |
786 SSL3WaitState ws; | 831 SSL3WaitState ws; |
787 PRUint64 md5_cx[MAX_MAC_CONTEXT_LLONGS]; | 832 PRUint64 md5_cx[MAX_MAC_CONTEXT_LLONGS]; |
788 PRUint64 sha_cx[MAX_MAC_CONTEXT_LLONGS]; | 833 PRUint64 sha_cx[MAX_MAC_CONTEXT_LLONGS]; |
789 PK11Context * md5; /* handshake running hashes */ | 834 PK11Context * md5; /* handshake running hashes */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 PRUint32 negotiatedECCurves; /* bit mask */ | 869 PRUint32 negotiatedECCurves; /* bit mask */ |
825 #endif /* NSS_ENABLE_ECC */ | 870 #endif /* NSS_ENABLE_ECC */ |
826 | 871 |
827 PRBool authCertificatePending; | 872 PRBool authCertificatePending; |
828 /* Which function should SSL_RestartHandshake* call if we're blocked? | 873 /* Which function should SSL_RestartHandshake* call if we're blocked? |
829 * One of NULL, ssl3_SendClientSecondRound, ssl3_FinishHandshake, | 874 * One of NULL, ssl3_SendClientSecondRound, ssl3_FinishHandshake, |
830 * or ssl3_AlwaysFail */ | 875 * or ssl3_AlwaysFail */ |
831 sslRestartTarget restartTarget; | 876 sslRestartTarget restartTarget; |
832 /* Shared state between ssl3_HandleFinished and ssl3_FinishHandshake */ | 877 /* Shared state between ssl3_HandleFinished and ssl3_FinishHandshake */ |
833 PRBool cacheSID; | 878 PRBool cacheSID; |
| 879 |
| 880 /* This group of values is used for DTLS */ |
| 881 PRUint16 sendMessageSeq; /* The sending message sequence |
| 882 * number*/ |
| 883 PRCList * lastMessageFlight; /* The last message flight we sent. |
| 884 * This is a pointer because |
| 885 * ssl_FreeSocket relocates the |
| 886 * structure in DEBUG mode which |
| 887 * messes up the list macros */ |
| 888 PRUint16 maxMessageSent; /* The largest message we sent */ |
| 889 PRUint16 recvMessageSeq; /* The receiving message sequence |
| 890 * number*/ |
| 891 sslBuffer recvdFragments; /* The fragments we have received in |
| 892 * a bitmask */ |
| 893 PRInt32 recvdHighWater; /* The high water mark for fragments |
| 894 * received. -1 means no reassembly |
| 895 * in progress. */ |
| 896 unsigned char cookie[32]; /* The cookie */ |
| 897 unsigned char cookieLen; /* The length of the cookie*/ |
| 898 PRIntervalTime rtTimerStarted; /* When the timer was started */ |
| 899 DTLSTimerCb rtTimerCb; /* The function to call on expiry */ |
| 900 PRUint32 rtTimeoutMs; /* The length of the current timeout |
| 901 * used for backoff (in ms)*/ |
| 902 PRUint32 rtRetries; /* The retry counter */ |
834 } SSL3HandshakeState; | 903 } SSL3HandshakeState; |
835 | 904 |
836 | 905 |
837 | 906 |
838 /* | 907 /* |
839 ** This is the "ssl3" struct, as in "ss->ssl3". | 908 ** This is the "ssl3" struct, as in "ss->ssl3". |
840 ** note: | 909 ** note: |
841 ** usually, crSpec == cwSpec and prSpec == pwSpec. | 910 ** usually, crSpec == cwSpec and prSpec == pwSpec. |
842 ** Sometimes, crSpec == pwSpec and prSpec == cwSpec. | 911 ** Sometimes, crSpec == pwSpec and prSpec == cwSpec. |
843 ** But there are never more than 2 actual specs. | 912 ** But there are never more than 2 actual specs. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 /* used by server. trusted CAs for this socket. */ | 944 /* used by server. trusted CAs for this socket. */ |
876 PRBool initialized; | 945 PRBool initialized; |
877 SSL3HandshakeState hs; | 946 SSL3HandshakeState hs; |
878 ssl3CipherSpec specs[2]; /* one is current, one is pending. */ | 947 ssl3CipherSpec specs[2]; /* one is current, one is pending. */ |
879 | 948 |
880 /* In a client: if the server supports Next Protocol Negotiation, then | 949 /* In a client: if the server supports Next Protocol Negotiation, then |
881 * this is the protocol that was negotiated. | 950 * this is the protocol that was negotiated. |
882 */ | 951 */ |
883 SECItem nextProto; | 952 SECItem nextProto; |
884 SSLNextProtoState nextProtoState; | 953 SSLNextProtoState nextProtoState; |
| 954 |
| 955 PRUint16 mtu; /* Our estimate of the MTU */ |
885 }; | 956 }; |
886 | 957 |
| 958 #define DTLS_MAX_MTU 1500 /* Ethernet MTU but without subtracting the |
| 959 * headers, so slightly larger than expected */ |
| 960 #define IS_DTLS(ss) (ss->protocolVariant == ssl_variant_datagram) |
| 961 |
887 typedef struct { | 962 typedef struct { |
888 SSL3ContentType type; | 963 SSL3ContentType type; |
889 SSL3ProtocolVersion version; | 964 SSL3ProtocolVersion version; |
| 965 SSL3SequenceNumber seq_num; /* DTLS only */ |
890 sslBuffer * buf; | 966 sslBuffer * buf; |
891 } SSL3Ciphertext; | 967 } SSL3Ciphertext; |
892 | 968 |
893 struct ssl3KeyPairStr { | 969 struct ssl3KeyPairStr { |
894 SECKEYPrivateKey * privKey; | 970 SECKEYPrivateKey * privKey; |
895 SECKEYPublicKey * pubKey; | 971 SECKEYPublicKey * pubKey; |
896 PRInt32 refCount; /* use PR_Atomic calls for this. */ | 972 PRInt32 refCount; /* use PR_Atomic calls for this. */ |
897 }; | 973 }; |
898 | 974 |
899 typedef struct SSLWrappedSymWrappingKeyStr { | 975 typedef struct SSLWrappedSymWrappingKeyStr { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 | 1257 |
1182 /* SSL3 state info. Formerly was a pointer */ | 1258 /* SSL3 state info. Formerly was a pointer */ |
1183 ssl3State ssl3; | 1259 ssl3State ssl3; |
1184 | 1260 |
1185 /* | 1261 /* |
1186 * TLS extension related data. | 1262 * TLS extension related data. |
1187 */ | 1263 */ |
1188 /* True when the current session is a stateless resume. */ | 1264 /* True when the current session is a stateless resume. */ |
1189 PRBool statelessResume; | 1265 PRBool statelessResume; |
1190 TLSExtensionData xtnData; | 1266 TLSExtensionData xtnData; |
| 1267 |
| 1268 /* Whether we are doing stream or datagram mode */ |
| 1269 SSLProtocolVariant protocolVariant; |
1191 }; | 1270 }; |
1192 | 1271 |
1193 | 1272 |
1194 | 1273 |
1195 /* All the global data items declared here should be protected using the | 1274 /* All the global data items declared here should be protected using the |
1196 ** ssl_global_data_lock, which is a reader/writer lock. | 1275 ** ssl_global_data_lock, which is a reader/writer lock. |
1197 */ | 1276 */ |
1198 extern NSSRWLock * ssl_global_data_lock; | 1277 extern NSSRWLock * ssl_global_data_lock; |
1199 extern char ssl_debug; | 1278 extern char ssl_debug; |
1200 extern char ssl_trace; | 1279 extern char ssl_trace; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 | 1393 |
1315 extern PRBool ssl_FdIsBlocking(PRFileDesc *fd); | 1394 extern PRBool ssl_FdIsBlocking(PRFileDesc *fd); |
1316 | 1395 |
1317 extern PRBool ssl_SocketIsBlocking(sslSocket *ss); | 1396 extern PRBool ssl_SocketIsBlocking(sslSocket *ss); |
1318 | 1397 |
1319 extern void ssl3_SetAlwaysBlock(sslSocket *ss); | 1398 extern void ssl3_SetAlwaysBlock(sslSocket *ss); |
1320 | 1399 |
1321 extern SECStatus ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled); | 1400 extern SECStatus ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled); |
1322 | 1401 |
1323 extern PRBool ssl3_CanFalseStart(sslSocket *ss); | 1402 extern PRBool ssl3_CanFalseStart(sslSocket *ss); |
| 1403 extern PRInt32 ssl3_SendRecord(sslSocket *ss, DTLSEpoch epoch, |
| 1404 SSL3ContentType type, |
| 1405 const SSL3Opaque* pIn, PRInt32 nIn, |
| 1406 PRInt32 flags); |
| 1407 |
| 1408 #ifdef NSS_ENABLE_ZLIB |
| 1409 /* |
| 1410 * The DEFLATE algorithm can result in an expansion of 0.1% + 12 bytes. For a |
| 1411 * maximum TLS record payload of 2**14 bytes, that's 29 bytes. |
| 1412 */ |
| 1413 #define SSL3_COMPRESSION_MAX_EXPANSION 29 |
| 1414 #else /* !NSS_ENABLE_ZLIB */ |
| 1415 #define SSL3_COMPRESSION_MAX_EXPANSION 0 |
| 1416 #endif |
| 1417 |
| 1418 /* |
| 1419 * make sure there is room in the write buffer for padding and |
| 1420 * other compression and cryptographic expansions. |
| 1421 */ |
| 1422 #define SSL3_BUFFER_FUDGE 100 + SSL3_COMPRESSION_MAX_EXPANSION |
1324 | 1423 |
1325 #define SSL_LOCK_READER(ss) if (ss->recvLock) PZ_Lock(ss->recvLock) | 1424 #define SSL_LOCK_READER(ss) if (ss->recvLock) PZ_Lock(ss->recvLock) |
1326 #define SSL_UNLOCK_READER(ss) if (ss->recvLock) PZ_Unlock(ss->recvLock
) | 1425 #define SSL_UNLOCK_READER(ss) if (ss->recvLock) PZ_Unlock(ss->recvLock
) |
1327 #define SSL_LOCK_WRITER(ss) if (ss->sendLock) PZ_Lock(ss->sendLock) | 1426 #define SSL_LOCK_WRITER(ss) if (ss->sendLock) PZ_Lock(ss->sendLock) |
1328 #define SSL_UNLOCK_WRITER(ss) if (ss->sendLock) PZ_Unlock(ss->sendLock
) | 1427 #define SSL_UNLOCK_WRITER(ss) if (ss->sendLock) PZ_Unlock(ss->sendLock
) |
1329 | 1428 |
1330 /* firstHandshakeLock -> recvBufLock */ | 1429 /* firstHandshakeLock -> recvBufLock */ |
1331 #define ssl_Get1stHandshakeLock(ss) \ | 1430 #define ssl_Get1stHandshakeLock(ss) \ |
1332 { if (!ss->opt.noLocks) { \ | 1431 { if (!ss->opt.noLocks) { \ |
1333 PORT_Assert(PZ_InMonitor((ss)->firstHandshakeLock) || \ | 1432 PORT_Assert(PZ_InMonitor((ss)->firstHandshakeLock) || \ |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos | 1528 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos |
1430 */ | 1529 */ |
1431 extern SECStatus ssl3_HandleV2ClientHello( | 1530 extern SECStatus ssl3_HandleV2ClientHello( |
1432 sslSocket *ss, unsigned char *buffer, int length); | 1531 sslSocket *ss, unsigned char *buffer, int length); |
1433 extern SECStatus ssl3_StartHandshakeHash( | 1532 extern SECStatus ssl3_StartHandshakeHash( |
1434 sslSocket *ss, unsigned char *buf, int length); | 1533 sslSocket *ss, unsigned char *buf, int length); |
1435 | 1534 |
1436 /* | 1535 /* |
1437 * SSL3 specific routines | 1536 * SSL3 specific routines |
1438 */ | 1537 */ |
1439 SECStatus ssl3_SendClientHello(sslSocket *ss); | 1538 SECStatus ssl3_SendClientHello(sslSocket *ss, PRBool resending); |
1440 | 1539 |
1441 /* | 1540 /* |
1442 * input into the SSL3 machinery from the actualy network reading code | 1541 * input into the SSL3 machinery from the actualy network reading code |
1443 */ | 1542 */ |
1444 SECStatus ssl3_HandleRecord( | 1543 SECStatus ssl3_HandleRecord( |
1445 sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out); | 1544 sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out); |
1446 | 1545 |
1447 int ssl3_GatherAppDataRecord(sslSocket *ss, int flags); | 1546 int ssl3_GatherAppDataRecord(sslSocket *ss, int flags); |
1448 int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags); | 1547 int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags); |
1449 /* | 1548 /* |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy); | 1623 extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy); |
1525 extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy); | 1624 extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy); |
1526 | 1625 |
1527 extern void ssl2_InitSocketPolicy(sslSocket *ss); | 1626 extern void ssl2_InitSocketPolicy(sslSocket *ss); |
1528 extern void ssl3_InitSocketPolicy(sslSocket *ss); | 1627 extern void ssl3_InitSocketPolicy(sslSocket *ss); |
1529 | 1628 |
1530 extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss, | 1629 extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss, |
1531 unsigned char *cs, int *size); | 1630 unsigned char *cs, int *size); |
1532 | 1631 |
1533 extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache); | 1632 extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache); |
| 1633 extern SECStatus ssl3_HandleHandshakeMessage(sslSocket *ss, SSL3Opaque *b, |
| 1634 PRUint32 length); |
1534 | 1635 |
1535 extern void ssl3_DestroySSL3Info(sslSocket *ss); | 1636 extern void ssl3_DestroySSL3Info(sslSocket *ss); |
1536 | 1637 |
1537 extern SECStatus ssl3_NegotiateVersion(sslSocket *ss, | 1638 extern SECStatus ssl3_NegotiateVersion(sslSocket *ss, |
1538 SSL3ProtocolVersion peerVersion, | 1639 SSL3ProtocolVersion peerVersion, |
1539 PRBool allowLargerPeerVersion); | 1640 PRBool allowLargerPeerVersion); |
1540 | 1641 |
1541 extern SECStatus ssl_GetPeerInfo(sslSocket *ss); | 1642 extern SECStatus ssl_GetPeerInfo(sslSocket *ss); |
1542 | 1643 |
1543 #ifdef NSS_ENABLE_ECC | 1644 #ifdef NSS_ENABLE_ECC |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 | 1774 |
1674 /* Decrement keypair's ref count and free if zero. */ | 1775 /* Decrement keypair's ref count and free if zero. */ |
1675 extern void ssl3_FreeKeyPair(ssl3KeyPair * keyPair); | 1776 extern void ssl3_FreeKeyPair(ssl3KeyPair * keyPair); |
1676 | 1777 |
1677 /* calls for accessing wrapping keys across processes. */ | 1778 /* calls for accessing wrapping keys across processes. */ |
1678 extern PRBool | 1779 extern PRBool |
1679 ssl_GetWrappingKey( PRInt32 symWrapMechIndex, | 1780 ssl_GetWrappingKey( PRInt32 symWrapMechIndex, |
1680 SSL3KEAType exchKeyType, | 1781 SSL3KEAType exchKeyType, |
1681 SSLWrappedSymWrappingKey *wswk); | 1782 SSLWrappedSymWrappingKey *wswk); |
1682 | 1783 |
| 1784 /* Generate an error */ |
| 1785 extern SECStatus ssl3_DecodeError(sslSocket *ss); |
| 1786 |
1683 /* The caller passes in the new value it wants | 1787 /* The caller passes in the new value it wants |
1684 * to set. This code tests the wrapped sym key entry in the file on disk. | 1788 * to set. This code tests the wrapped sym key entry in the file on disk. |
1685 * If it is uninitialized, this function writes the caller's value into | 1789 * If it is uninitialized, this function writes the caller's value into |
1686 * the disk entry, and returns false. | 1790 * the disk entry, and returns false. |
1687 * Otherwise, it overwrites the caller's wswk with the value obtained from | 1791 * Otherwise, it overwrites the caller's wswk with the value obtained from |
1688 * the disk, and returns PR_TRUE. | 1792 * the disk, and returns PR_TRUE. |
1689 * This is all done while holding the locks/semaphores necessary to make | 1793 * This is all done while holding the locks/semaphores necessary to make |
1690 * the operation atomic. | 1794 * the operation atomic. |
1691 */ | 1795 */ |
1692 extern PRBool | 1796 extern PRBool |
(...skipping 24 matching lines...) Expand all Loading... |
1717 // Converts a CERTCertList* (A collection of CERTCertificates) into a | 1821 // Converts a CERTCertList* (A collection of CERTCertificates) into a |
1718 // CERTCertificateList* (A collection of SECItems), or returns NULL if | 1822 // CERTCertificateList* (A collection of SECItems), or returns NULL if |
1719 // it cannot be converted. | 1823 // it cannot be converted. |
1720 // This is to allow the platform-supplied chain to be created with purely | 1824 // This is to allow the platform-supplied chain to be created with purely |
1721 // public API functions, using the preferred CERTCertList mutators, rather | 1825 // public API functions, using the preferred CERTCertList mutators, rather |
1722 // pushing this hack to clients. | 1826 // pushing this hack to clients. |
1723 extern CERTCertificateList* hack_NewCertificateListFromCertList( | 1827 extern CERTCertificateList* hack_NewCertificateListFromCertList( |
1724 CERTCertList* list); | 1828 CERTCertList* list); |
1725 #endif /* NSS_PLATFORM_CLIENT_AUTH */ | 1829 #endif /* NSS_PLATFORM_CLIENT_AUTH */ |
1726 | 1830 |
| 1831 /**************** DTLS-specific functions **************/ |
| 1832 extern void dtls_FreeQueuedMessage(DTLSQueuedMessage *msg); |
| 1833 extern void dtls_FreeQueuedMessages(PRCList *lst); |
| 1834 extern void dtls_FreeHandshakeMessages(PRCList *lst); |
| 1835 |
| 1836 extern SECStatus dtls_HandleHandshake(sslSocket *ss, sslBuffer *origBuf); |
| 1837 extern SECStatus dtls_HandleHelloVerifyRequest(sslSocket *ss, |
| 1838 SSL3Opaque *b, PRUint32 length); |
| 1839 extern SECStatus dtls_StageHandshakeMessage(sslSocket *ss); |
| 1840 extern SECStatus dtls_QueueMessage(sslSocket *ss, SSL3ContentType type, |
| 1841 const SSL3Opaque *pIn, PRInt32 nIn); |
| 1842 extern SECStatus dtls_FlushHandshakeMessages(sslSocket *ss, PRInt32 flags); |
| 1843 extern SECStatus dtls_CompressMACEncryptRecord(sslSocket *ss, |
| 1844 DTLSEpoch epoch, |
| 1845 PRBool use_epoch, |
| 1846 SSL3ContentType type, |
| 1847 const SSL3Opaque *pIn, |
| 1848 PRUint32 contentLen, |
| 1849 sslBuffer *wrBuf); |
| 1850 SECStatus ssl3_DisableNonDTLSSuites(sslSocket * ss); |
| 1851 extern SECStatus dtls_StartTimer(sslSocket *ss, DTLSTimerCb cb); |
| 1852 extern SECStatus dtls_RestartTimer(sslSocket *ss, PRBool backoff, |
| 1853 DTLSTimerCb cb); |
| 1854 extern void dtls_CheckTimer(sslSocket *ss); |
| 1855 extern void dtls_CancelTimer(sslSocket *ss); |
| 1856 extern void dtls_FinishedTimerCb(sslSocket *ss); |
| 1857 extern void dtls_SetMTU(sslSocket *ss, PRUint16 advertised); |
| 1858 extern void dtls_InitRecvdRecords(DTLSRecvdRecords *records); |
| 1859 extern int dtls_RecordGetRecvd(DTLSRecvdRecords *records, PRUint64 seq); |
| 1860 extern void dtls_RecordSetRecvd(DTLSRecvdRecords *records, PRUint64 seq); |
| 1861 extern SSL3ProtocolVersion |
| 1862 dtls_TLSVersionToDTLSVersion(SSL3ProtocolVersion tlsv); |
| 1863 extern SSL3ProtocolVersion |
| 1864 dtls_DTLSVersionToTLSVersion(SSL3ProtocolVersion dtlsv); |
| 1865 |
1727 /********************** misc calls *********************/ | 1866 /********************** misc calls *********************/ |
1728 | 1867 |
1729 extern int ssl_MapLowLevelError(int hiLevelError); | 1868 extern int ssl_MapLowLevelError(int hiLevelError); |
1730 | 1869 |
1731 extern PRUint32 ssl_Time(void); | 1870 extern PRUint32 ssl_Time(void); |
1732 | 1871 |
1733 extern void SSL_AtomicIncrementLong(long * x); | 1872 extern void SSL_AtomicIncrementLong(long * x); |
1734 | 1873 |
1735 SECStatus SSL_DisableDefaultExportCipherSuites(void); | 1874 SECStatus SSL_DisableDefaultExportCipherSuites(void); |
1736 SECStatus SSL_DisableExportCipherSuites(PRFileDesc * fd); | 1875 SECStatus SSL_DisableExportCipherSuites(PRFileDesc * fd); |
1737 PRBool SSL_IsExportCipherSuite(PRUint16 cipherSuite); | 1876 PRBool SSL_IsExportCipherSuite(PRUint16 cipherSuite); |
1738 | 1877 |
1739 extern SECStatus | 1878 extern SECStatus |
1740 ssl3_TLSPRFWithMasterSecret(ssl3CipherSpec *spec, | 1879 ssl3_TLSPRFWithMasterSecret(ssl3CipherSpec *spec, |
1741 const char *label, unsigned int labelLen, | 1880 const char *label, unsigned int labelLen, |
1742 const unsigned char *val, unsigned int valLen, | 1881 const unsigned char *val, unsigned int valLen, |
1743 unsigned char *out, unsigned int outLen); | 1882 unsigned char *out, unsigned int outLen); |
1744 | 1883 |
| 1884 /****************** Exposed for DTLS ********************/ |
| 1885 extern SECStatus |
| 1886 ssl3_CompressMACEncryptRecord(ssl3CipherSpec * cwSpec, |
| 1887 PRBool isServer, |
| 1888 PRBool isDTLS, |
| 1889 SSL3ContentType type, |
| 1890 const SSL3Opaque * pIn, |
| 1891 PRUint32 contentLen, |
| 1892 sslBuffer * wrBuf); |
| 1893 extern void ssl3_DestroyCipherSpec(ssl3CipherSpec *spec, PRBool freeSrvName); |
| 1894 extern const ssl3CipherSuiteDef * |
| 1895 ssl_LookupCipherSuiteDef(ssl3CipherSuite suite); |
| 1896 extern void dtls_RehandshakeCleanup(sslSocket *ss); |
| 1897 |
1745 #ifdef TRACE | 1898 #ifdef TRACE |
1746 #define SSL_TRACE(msg) ssl_Trace msg | 1899 #define SSL_TRACE(msg) ssl_Trace msg |
1747 #else | 1900 #else |
1748 #define SSL_TRACE(msg) | 1901 #define SSL_TRACE(msg) |
1749 #endif | 1902 #endif |
1750 | 1903 |
1751 void ssl_Trace(const char *format, ...); | 1904 void ssl_Trace(const char *format, ...); |
1752 | 1905 |
1753 SEC_END_PROTOS | 1906 SEC_END_PROTOS |
1754 | 1907 |
1755 #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) | 1908 #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) |
1756 #define SSL_GETPID getpid | 1909 #define SSL_GETPID getpid |
1757 #elif defined(_WIN32_WCE) | 1910 #elif defined(_WIN32_WCE) |
1758 #define SSL_GETPID GetCurrentProcessId | 1911 #define SSL_GETPID GetCurrentProcessId |
1759 #elif defined(WIN32) | 1912 #elif defined(WIN32) |
1760 extern int __cdecl _getpid(void); | 1913 extern int __cdecl _getpid(void); |
1761 #define SSL_GETPID _getpid | 1914 #define SSL_GETPID _getpid |
1762 #else | 1915 #else |
1763 #define SSL_GETPID() 0 | 1916 #define SSL_GETPID() 0 |
1764 #endif | 1917 #endif |
1765 | 1918 |
1766 #endif /* __sslimpl_h_ */ | 1919 #endif /* __sslimpl_h_ */ |
OLD | NEW |