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...) 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...) 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...) 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...) 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...) 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 * 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...) 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...) 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...) 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...) 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...) 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...) 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 SECStatus |
| 1404 ssl3_CompressMACEncryptRecord(ssl3CipherSpec * cwSpec, |
| 1405 PRBool isServer, |
| 1406 PRBool isDTLS, |
| 1407 SSL3ContentType type, |
| 1408 const SSL3Opaque * pIn, |
| 1409 PRUint32 contentLen, |
| 1410 sslBuffer * wrBuf); |
| 1411 extern PRInt32 ssl3_SendRecord(sslSocket *ss, DTLSEpoch epoch, |
| 1412 SSL3ContentType type, |
| 1413 const SSL3Opaque* pIn, PRInt32 nIn, |
| 1414 PRInt32 flags); |
| 1415 |
| 1416 #ifdef NSS_ENABLE_ZLIB |
| 1417 /* |
| 1418 * The DEFLATE algorithm can result in an expansion of 0.1% + 12 bytes. For a |
| 1419 * maximum TLS record payload of 2**14 bytes, that's 29 bytes. |
| 1420 */ |
| 1421 #define SSL3_COMPRESSION_MAX_EXPANSION 29 |
| 1422 #else /* !NSS_ENABLE_ZLIB */ |
| 1423 #define SSL3_COMPRESSION_MAX_EXPANSION 0 |
| 1424 #endif |
| 1425 |
| 1426 /* |
| 1427 * make sure there is room in the write buffer for padding and |
| 1428 * other compression and cryptographic expansions. |
| 1429 */ |
| 1430 #define SSL3_BUFFER_FUDGE 100 + SSL3_COMPRESSION_MAX_EXPANSION |
1324 | 1431 |
1325 #define SSL_LOCK_READER(ss) if (ss->recvLock) PZ_Lock(ss->recvLock) | 1432 #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
) | 1433 #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) | 1434 #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
) | 1435 #define SSL_UNLOCK_WRITER(ss) if (ss->sendLock) PZ_Unlock(ss->sendLock
) |
1329 | 1436 |
1330 /* firstHandshakeLock -> recvBufLock */ | 1437 /* firstHandshakeLock -> recvBufLock */ |
1331 #define ssl_Get1stHandshakeLock(ss) \ | 1438 #define ssl_Get1stHandshakeLock(ss) \ |
1332 { if (!ss->opt.noLocks) { \ | 1439 { if (!ss->opt.noLocks) { \ |
1333 PORT_Assert(PZ_InMonitor((ss)->firstHandshakeLock) || \ | 1440 PORT_Assert(PZ_InMonitor((ss)->firstHandshakeLock) || \ |
(...skipping 76 matching lines...) Loading... |
1410 const unsigned char * cr, const unsigned char * sr, | 1517 const unsigned char * cr, const unsigned char * sr, |
1411 const SECItem * pms, PRBool isTLS, PRBool isRSA); | 1518 const SECItem * pms, PRBool isTLS, PRBool isRSA); |
1412 | 1519 |
1413 /* These functions are called from secnav, even though they're "private". */ | 1520 /* These functions are called from secnav, even though they're "private". */ |
1414 | 1521 |
1415 extern int ssl2_SendErrorMessage(struct sslSocketStr *ss, int error); | 1522 extern int ssl2_SendErrorMessage(struct sslSocketStr *ss, int error); |
1416 extern sslSocket *ssl_FindSocket(PRFileDesc *fd); | 1523 extern sslSocket *ssl_FindSocket(PRFileDesc *fd); |
1417 extern void ssl_FreeSocket(struct sslSocketStr *ssl); | 1524 extern void ssl_FreeSocket(struct sslSocketStr *ssl); |
1418 extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level, | 1525 extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level, |
1419 SSL3AlertDescription desc); | 1526 SSL3AlertDescription desc); |
| 1527 extern SECStatus ssl3_DecodeError(sslSocket *ss); |
1420 | 1528 |
1421 extern SECStatus ssl3_RestartHandshakeAfterCertReq(sslSocket * ss, | 1529 extern SECStatus ssl3_RestartHandshakeAfterCertReq(sslSocket * ss, |
1422 CERTCertificate * cert, | 1530 CERTCertificate * cert, |
1423 SECKEYPrivateKey * key, | 1531 SECKEYPrivateKey * key, |
1424 CERTCertificateList *certChain); | 1532 CERTCertificateList *certChain); |
1425 | 1533 |
1426 extern SECStatus ssl3_AuthCertificateComplete(sslSocket *ss, PRErrorCode error); | 1534 extern SECStatus ssl3_AuthCertificateComplete(sslSocket *ss, PRErrorCode error); |
1427 | 1535 |
1428 /* | 1536 /* |
1429 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos | 1537 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos |
1430 */ | 1538 */ |
1431 extern SECStatus ssl3_HandleV2ClientHello( | 1539 extern SECStatus ssl3_HandleV2ClientHello( |
1432 sslSocket *ss, unsigned char *buffer, int length); | 1540 sslSocket *ss, unsigned char *buffer, int length); |
1433 extern SECStatus ssl3_StartHandshakeHash( | 1541 extern SECStatus ssl3_StartHandshakeHash( |
1434 sslSocket *ss, unsigned char *buf, int length); | 1542 sslSocket *ss, unsigned char *buf, int length); |
1435 | 1543 |
1436 /* | 1544 /* |
1437 * SSL3 specific routines | 1545 * SSL3 specific routines |
1438 */ | 1546 */ |
1439 SECStatus ssl3_SendClientHello(sslSocket *ss); | 1547 SECStatus ssl3_SendClientHello(sslSocket *ss, PRBool resending); |
1440 | 1548 |
1441 /* | 1549 /* |
1442 * input into the SSL3 machinery from the actualy network reading code | 1550 * input into the SSL3 machinery from the actualy network reading code |
1443 */ | 1551 */ |
1444 SECStatus ssl3_HandleRecord( | 1552 SECStatus ssl3_HandleRecord( |
1445 sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out); | 1553 sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out); |
1446 | 1554 |
1447 int ssl3_GatherAppDataRecord(sslSocket *ss, int flags); | 1555 int ssl3_GatherAppDataRecord(sslSocket *ss, int flags); |
1448 int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags); | 1556 int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags); |
1449 /* | 1557 /* |
(...skipping 74 matching lines...) Loading... |
1524 extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy); | 1632 extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy); |
1525 extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy); | 1633 extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy); |
1526 | 1634 |
1527 extern void ssl2_InitSocketPolicy(sslSocket *ss); | 1635 extern void ssl2_InitSocketPolicy(sslSocket *ss); |
1528 extern void ssl3_InitSocketPolicy(sslSocket *ss); | 1636 extern void ssl3_InitSocketPolicy(sslSocket *ss); |
1529 | 1637 |
1530 extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss, | 1638 extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss, |
1531 unsigned char *cs, int *size); | 1639 unsigned char *cs, int *size); |
1532 | 1640 |
1533 extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache); | 1641 extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache); |
| 1642 extern SECStatus ssl3_HandleHandshakeMessage(sslSocket *ss, SSL3Opaque *b, |
| 1643 PRUint32 length); |
1534 | 1644 |
1535 extern void ssl3_DestroySSL3Info(sslSocket *ss); | 1645 extern void ssl3_DestroySSL3Info(sslSocket *ss); |
1536 | 1646 |
1537 extern SECStatus ssl3_NegotiateVersion(sslSocket *ss, | 1647 extern SECStatus ssl3_NegotiateVersion(sslSocket *ss, |
1538 SSL3ProtocolVersion peerVersion, | 1648 SSL3ProtocolVersion peerVersion, |
1539 PRBool allowLargerPeerVersion); | 1649 PRBool allowLargerPeerVersion); |
1540 | 1650 |
1541 extern SECStatus ssl_GetPeerInfo(sslSocket *ss); | 1651 extern SECStatus ssl_GetPeerInfo(sslSocket *ss); |
1542 | 1652 |
1543 #ifdef NSS_ENABLE_ECC | 1653 #ifdef NSS_ENABLE_ECC |
1544 /* ECDH functions */ | 1654 /* ECDH functions */ |
1545 extern SECStatus ssl3_SendECDHClientKeyExchange(sslSocket * ss, | 1655 extern SECStatus ssl3_SendECDHClientKeyExchange(sslSocket * ss, |
1546 SECKEYPublicKey * svrPubKey); | 1656 SECKEYPublicKey * svrPubKey); |
1547 extern SECStatus ssl3_HandleECDHServerKeyExchange(sslSocket *ss, | 1657 extern SECStatus ssl3_HandleECDHServerKeyExchange(sslSocket *ss, |
1548 SSL3Opaque *b, PRUint32 length); | 1658 SSL3Opaque *b, PRUint32 length); |
1549 extern SECStatus ssl3_HandleECDHClientKeyExchange(sslSocket *ss, | 1659 extern SECStatus ssl3_HandleECDHClientKeyExchange(sslSocket *ss, |
1550 SSL3Opaque *b, PRUint32 length, | 1660 SSL3Opaque *b, PRUint32 length, |
1551 SECKEYPublicKey *srvrPubKey, | 1661 SECKEYPublicKey *srvrPubKey, |
1552 SECKEYPrivateKey *srvrPrivKey); | 1662 SECKEYPrivateKey *srvrPrivKey); |
1553 extern SECStatus ssl3_SendECDHServerKeyExchange(sslSocket *ss); | 1663 extern SECStatus ssl3_SendECDHServerKeyExchange(sslSocket *ss); |
1554 #endif | 1664 #endif |
1555 | 1665 |
1556 extern SECStatus ssl3_ComputeCommonKeyHash(PRUint8 * hashBuf, | 1666 extern SECStatus ssl3_ComputeCommonKeyHash(PRUint8 * hashBuf, |
1557 unsigned int bufLen, SSL3Hashes *hashes, | 1667 unsigned int bufLen, SSL3Hashes *hashes, |
1558 PRBool bypassPKCS11); | 1668 PRBool bypassPKCS11); |
| 1669 extern void ssl3_DestroyCipherSpec(ssl3CipherSpec *spec, PRBool freeSrvName); |
1559 extern SECStatus ssl3_InitPendingCipherSpec(sslSocket *ss, PK11SymKey *pms); | 1670 extern SECStatus ssl3_InitPendingCipherSpec(sslSocket *ss, PK11SymKey *pms); |
1560 extern SECStatus ssl3_AppendHandshake(sslSocket *ss, const void *void_src, | 1671 extern SECStatus ssl3_AppendHandshake(sslSocket *ss, const void *void_src, |
1561 PRInt32 bytes); | 1672 PRInt32 bytes); |
1562 extern SECStatus ssl3_AppendHandshakeHeader(sslSocket *ss, | 1673 extern SECStatus ssl3_AppendHandshakeHeader(sslSocket *ss, |
1563 SSL3HandshakeType t, PRUint32 length); | 1674 SSL3HandshakeType t, PRUint32 length); |
1564 extern SECStatus ssl3_AppendHandshakeNumber(sslSocket *ss, PRInt32 num, | 1675 extern SECStatus ssl3_AppendHandshakeNumber(sslSocket *ss, PRInt32 num, |
1565 PRInt32 lenSize); | 1676 PRInt32 lenSize); |
1566 extern SECStatus ssl3_AppendHandshakeVariable( sslSocket *ss, | 1677 extern SECStatus ssl3_AppendHandshakeVariable( sslSocket *ss, |
1567 const SSL3Opaque *src, PRInt32 bytes, PRInt32 lenSize); | 1678 const SSL3Opaque *src, PRInt32 bytes, PRInt32 lenSize); |
1568 extern SECStatus ssl3_ConsumeHandshake(sslSocket *ss, void *v, PRInt32 bytes, | 1679 extern SECStatus ssl3_ConsumeHandshake(sslSocket *ss, void *v, PRInt32 bytes, |
(...skipping 148 matching lines...) Loading... |
1717 // Converts a CERTCertList* (A collection of CERTCertificates) into a | 1828 // Converts a CERTCertList* (A collection of CERTCertificates) into a |
1718 // CERTCertificateList* (A collection of SECItems), or returns NULL if | 1829 // CERTCertificateList* (A collection of SECItems), or returns NULL if |
1719 // it cannot be converted. | 1830 // it cannot be converted. |
1720 // This is to allow the platform-supplied chain to be created with purely | 1831 // This is to allow the platform-supplied chain to be created with purely |
1721 // public API functions, using the preferred CERTCertList mutators, rather | 1832 // public API functions, using the preferred CERTCertList mutators, rather |
1722 // pushing this hack to clients. | 1833 // pushing this hack to clients. |
1723 extern CERTCertificateList* hack_NewCertificateListFromCertList( | 1834 extern CERTCertificateList* hack_NewCertificateListFromCertList( |
1724 CERTCertList* list); | 1835 CERTCertList* list); |
1725 #endif /* NSS_PLATFORM_CLIENT_AUTH */ | 1836 #endif /* NSS_PLATFORM_CLIENT_AUTH */ |
1726 | 1837 |
| 1838 /**************** DTLS-specific functions **************/ |
| 1839 extern void dtls_FreeQueuedMessage(DTLSQueuedMessage *msg); |
| 1840 extern void dtls_FreeQueuedMessages(PRCList *lst); |
| 1841 extern void dtls_FreeHandshakeMessages(PRCList *lst); |
| 1842 |
| 1843 extern SECStatus dtls_HandleHandshake(sslSocket *ss, sslBuffer *origBuf); |
| 1844 extern SECStatus dtls_HandleHelloVerifyRequest(sslSocket *ss, |
| 1845 SSL3Opaque *b, PRUint32 length); |
| 1846 extern SECStatus dtls_StageHandshakeMessage(sslSocket *ss); |
| 1847 extern SECStatus dtls_QueueMessage(sslSocket *ss, SSL3ContentType type, |
| 1848 const SSL3Opaque *pIn, PRInt32 nIn); |
| 1849 extern SECStatus dtls_FlushHandshakeMessages(sslSocket *ss, PRInt32 flags); |
| 1850 extern SECStatus dtls_CompressMACEncryptRecord(sslSocket *ss, |
| 1851 DTLSEpoch epoch, |
| 1852 PRBool use_epoch, |
| 1853 SSL3ContentType type, |
| 1854 const SSL3Opaque *pIn, |
| 1855 PRUint32 contentLen, |
| 1856 sslBuffer *wrBuf); |
| 1857 SECStatus ssl3_DisableNonDTLSSuites(sslSocket * ss); |
| 1858 extern SECStatus dtls_StartTimer(sslSocket *ss, DTLSTimerCb cb); |
| 1859 extern SECStatus dtls_RestartTimer(sslSocket *ss, PRBool backoff, |
| 1860 DTLSTimerCb cb); |
| 1861 extern void dtls_CheckTimer(sslSocket *ss); |
| 1862 extern void dtls_CancelTimer(sslSocket *ss); |
| 1863 extern void dtls_FinishedTimerCb(sslSocket *ss); |
| 1864 extern void dtls_SetMTU(sslSocket *ss, PRUint16 advertised); |
| 1865 extern void dtls_InitRecvdRecords(DTLSRecvdRecords *records); |
| 1866 extern int dtls_RecordGetRecvd(DTLSRecvdRecords *records, PRUint64 seq); |
| 1867 extern void dtls_RecordSetRecvd(DTLSRecvdRecords *records, PRUint64 seq); |
| 1868 extern void dtls_RehandshakeCleanup(sslSocket *ss); |
| 1869 extern SSL3ProtocolVersion |
| 1870 dtls_TLSVersionToDTLSVersion(SSL3ProtocolVersion tlsv); |
| 1871 extern SSL3ProtocolVersion |
| 1872 dtls_DTLSVersionToTLSVersion(SSL3ProtocolVersion dtlsv); |
| 1873 |
1727 /********************** misc calls *********************/ | 1874 /********************** misc calls *********************/ |
1728 | 1875 |
1729 extern int ssl_MapLowLevelError(int hiLevelError); | 1876 extern int ssl_MapLowLevelError(int hiLevelError); |
1730 | 1877 |
1731 extern PRUint32 ssl_Time(void); | 1878 extern PRUint32 ssl_Time(void); |
1732 | 1879 |
1733 extern void SSL_AtomicIncrementLong(long * x); | 1880 extern void SSL_AtomicIncrementLong(long * x); |
1734 | 1881 |
1735 SECStatus SSL_DisableDefaultExportCipherSuites(void); | 1882 SECStatus SSL_DisableDefaultExportCipherSuites(void); |
1736 SECStatus SSL_DisableExportCipherSuites(PRFileDesc * fd); | 1883 SECStatus SSL_DisableExportCipherSuites(PRFileDesc * fd); |
(...skipping 20 matching lines...) Loading... |
1757 #elif defined(_WIN32_WCE) | 1904 #elif defined(_WIN32_WCE) |
1758 #define SSL_GETPID GetCurrentProcessId | 1905 #define SSL_GETPID GetCurrentProcessId |
1759 #elif defined(WIN32) | 1906 #elif defined(WIN32) |
1760 extern int __cdecl _getpid(void); | 1907 extern int __cdecl _getpid(void); |
1761 #define SSL_GETPID _getpid | 1908 #define SSL_GETPID _getpid |
1762 #else | 1909 #else |
1763 #define SSL_GETPID() 0 | 1910 #define SSL_GETPID() 0 |
1764 #endif | 1911 #endif |
1765 | 1912 |
1766 #endif /* __sslimpl_h_ */ | 1913 #endif /* __sslimpl_h_ */ |
OLD | NEW |