Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * SSL3 Protocol | 2 * SSL3 Protocol |
| 3 * | 3 * |
| 4 * ***** BEGIN LICENSE BLOCK ***** | 4 * ***** BEGIN LICENSE BLOCK ***** |
| 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 6 * | 6 * |
| 7 * The contents of this file are subject to the Mozilla Public License Version | 7 * The contents of this file are subject to the Mozilla Public License Version |
| 8 * 1.1 (the "License"); you may not use this file except in compliance with | 8 * 1.1 (the "License"); you may not use this file except in compliance with |
| 9 * the License. You may obtain a copy of the License at | 9 * the License. You may obtain a copy of the License at |
| 10 * http://www.mozilla.org/MPL/ | 10 * http://www.mozilla.org/MPL/ |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 static SECStatus ssl3_ServerHandleNextProtoNegoXtn(sslSocket *ss, | 83 static SECStatus ssl3_ServerHandleNextProtoNegoXtn(sslSocket *ss, |
| 84 PRUint16 ex_type, SECItem *data); | 84 PRUint16 ex_type, SECItem *data); |
| 85 static PRInt32 ssl3_ClientSendNextProtoNegoXtn(sslSocket *ss, PRBool append, | 85 static PRInt32 ssl3_ClientSendNextProtoNegoXtn(sslSocket *ss, PRBool append, |
| 86 PRUint32 maxBytes); | 86 PRUint32 maxBytes); |
| 87 static SECStatus ssl3_ServerHandleEncryptedClientCertsXtn(sslSocket *ss, | 87 static SECStatus ssl3_ServerHandleEncryptedClientCertsXtn(sslSocket *ss, |
| 88 PRUint16 ex_type, SECItem *data); | 88 PRUint16 ex_type, SECItem *data); |
| 89 static SECStatus ssl3_ClientHandleEncryptedClientCertsXtn(sslSocket *ss, | 89 static SECStatus ssl3_ClientHandleEncryptedClientCertsXtn(sslSocket *ss, |
| 90 PRUint16 ex_type, SECItem *data); | 90 PRUint16 ex_type, SECItem *data); |
| 91 static PRInt32 ssl3_SendEncryptedClientCertsXtn(sslSocket *ss, | 91 static PRInt32 ssl3_SendEncryptedClientCertsXtn(sslSocket *ss, |
| 92 PRBool append, PRUint32 maxBytes); | 92 PRBool append, PRUint32 maxBytes); |
| 93 static SECStatus ssl3_SendUseSRTPXtn(sslSocket *ss, PRBool append, | |
| 94 PRUint32 maxBytes); | |
| 95 static SECStatus ssl3_HandleUseSRTPXtn(sslSocket * ss, PRUint16 ex_type, | |
| 96 SECItem *data); | |
| 93 | 97 |
| 94 /* | 98 /* |
| 95 * Write bytes. Using this function means the SECItem structure | 99 * Write bytes. Using this function means the SECItem structure |
| 96 * cannot be freed. The caller is expected to call this function | 100 * cannot be freed. The caller is expected to call this function |
| 97 * on a shallow copy of the structure. | 101 * on a shallow copy of the structure. |
| 98 */ | 102 */ |
| 99 static SECStatus | 103 static SECStatus |
| 100 ssl3_AppendToItem(SECItem *item, const unsigned char *buf, PRUint32 bytes) | 104 ssl3_AppendToItem(SECItem *item, const unsigned char *buf, PRUint32 bytes) |
| 101 { | 105 { |
| 102 if (bytes > item->len) | 106 if (bytes > item->len) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, | 247 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, |
| 244 #ifdef NSS_ENABLE_ECC | 248 #ifdef NSS_ENABLE_ECC |
| 245 { ssl_elliptic_curves_xtn, &ssl3_HandleSupportedCurvesXtn }, | 249 { ssl_elliptic_curves_xtn, &ssl3_HandleSupportedCurvesXtn }, |
| 246 { ssl_ec_point_formats_xtn, &ssl3_HandleSupportedPointFormatsXtn }, | 250 { ssl_ec_point_formats_xtn, &ssl3_HandleSupportedPointFormatsXtn }, |
| 247 #endif | 251 #endif |
| 248 { ssl_session_ticket_xtn, &ssl3_ServerHandleSessionTicketXtn }, | 252 { ssl_session_ticket_xtn, &ssl3_ServerHandleSessionTicketXtn }, |
| 249 { ssl_encrypted_client_certs, &ssl3_ServerHandleEncryptedClientCertsXtn }, | 253 { ssl_encrypted_client_certs, &ssl3_ServerHandleEncryptedClientCertsXtn }, |
| 250 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, | 254 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, |
| 251 { ssl_next_proto_nego_xtn, &ssl3_ServerHandleNextProtoNegoXtn }, | 255 { ssl_next_proto_nego_xtn, &ssl3_ServerHandleNextProtoNegoXtn }, |
| 252 { ssl_ob_cert_xtn, &ssl3_ServerHandleOBCertXtn }, | 256 { ssl_ob_cert_xtn, &ssl3_ServerHandleOBCertXtn }, |
| 257 { ssl_use_srtp_xtn, &ssl3_HandleUseSRTPXtn }, | |
| 253 { -1, NULL } | 258 { -1, NULL } |
| 254 }; | 259 }; |
| 255 | 260 |
| 256 /* These two tables are used by the client, to handle server hello | 261 /* These two tables are used by the client, to handle server hello |
| 257 * extensions. */ | 262 * extensions. */ |
| 258 static const ssl3HelloExtensionHandler serverHelloHandlersTLS[] = { | 263 static const ssl3HelloExtensionHandler serverHelloHandlersTLS[] = { |
| 259 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, | 264 { ssl_server_name_xtn, &ssl3_HandleServerNameXtn }, |
| 260 /* TODO: add a handler for ssl_ec_point_formats_xtn */ | 265 /* TODO: add a handler for ssl_ec_point_formats_xtn */ |
| 261 { ssl_session_ticket_xtn, &ssl3_ClientHandleSessionTicketXtn }, | 266 { ssl_session_ticket_xtn, &ssl3_ClientHandleSessionTicketXtn }, |
| 262 { ssl_encrypted_client_certs, &ssl3_ClientHandleEncryptedClientCertsXtn }, | 267 { ssl_encrypted_client_certs, &ssl3_ClientHandleEncryptedClientCertsXtn }, |
| 263 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, | 268 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, |
| 264 { ssl_next_proto_nego_xtn, &ssl3_ClientHandleNextProtoNegoXtn }, | 269 { ssl_next_proto_nego_xtn, &ssl3_ClientHandleNextProtoNegoXtn }, |
| 265 { ssl_cert_status_xtn, &ssl3_ClientHandleStatusRequestXtn }, | 270 { ssl_cert_status_xtn, &ssl3_ClientHandleStatusRequestXtn }, |
| 266 { ssl_ob_cert_xtn, &ssl3_ClientHandleOBCertXtn }, | 271 { ssl_ob_cert_xtn, &ssl3_ClientHandleOBCertXtn }, |
| 272 { ssl_use_srtp_xtn, &ssl3_HandleUseSRTPXtn}, | |
| 267 { -1, NULL } | 273 { -1, NULL } |
| 268 }; | 274 }; |
| 269 | 275 |
| 270 static const ssl3HelloExtensionHandler serverHelloHandlersSSL3[] = { | 276 static const ssl3HelloExtensionHandler serverHelloHandlersSSL3[] = { |
| 271 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, | 277 { ssl_renegotiation_info_xtn, &ssl3_HandleRenegotiationInfoXtn }, |
| 272 { -1, NULL } | 278 { -1, NULL } |
| 273 }; | 279 }; |
| 274 | 280 |
| 275 /* Tables of functions to format TLS hello extensions, one function per | 281 /* Tables of functions to format TLS hello extensions, one function per |
| 276 * extension. | 282 * extension. |
| 277 * These static tables are for the formatting of client hello extensions. | 283 * These static tables are for the formatting of client hello extensions. |
| 278 * The server's table of hello senders is dynamic, in the socket struct, | 284 * The server's table of hello senders is dynamic, in the socket struct, |
| 279 * and sender functions are registered there. | 285 * and sender functions are registered there. |
| 280 */ | 286 */ |
| 281 static const | 287 static const |
| 282 ssl3HelloExtensionSender clientHelloSendersTLS[SSL_MAX_EXTENSIONS] = { | 288 ssl3HelloExtensionSender clientHelloSendersTLS[SSL_MAX_EXTENSIONS] = { |
| 283 { ssl_server_name_xtn, &ssl3_SendServerNameXtn }, | 289 { ssl_server_name_xtn, &ssl3_SendServerNameXtn }, |
| 284 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn }, | 290 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn }, |
| 285 #ifdef NSS_ENABLE_ECC | 291 #ifdef NSS_ENABLE_ECC |
| 286 { ssl_elliptic_curves_xtn, &ssl3_SendSupportedCurvesXtn }, | 292 { ssl_elliptic_curves_xtn, &ssl3_SendSupportedCurvesXtn }, |
| 287 { ssl_ec_point_formats_xtn, &ssl3_SendSupportedPointFormatsXtn }, | 293 { ssl_ec_point_formats_xtn, &ssl3_SendSupportedPointFormatsXtn }, |
| 288 #endif | 294 #endif |
| 289 { ssl_session_ticket_xtn, &ssl3_SendSessionTicketXtn }, | 295 { ssl_session_ticket_xtn, &ssl3_SendSessionTicketXtn }, |
| 290 { ssl_encrypted_client_certs, &ssl3_SendEncryptedClientCertsXtn }, | 296 { ssl_encrypted_client_certs, &ssl3_SendEncryptedClientCertsXtn }, |
| 291 { ssl_next_proto_nego_xtn, &ssl3_ClientSendNextProtoNegoXtn }, | 297 { ssl_next_proto_nego_xtn, &ssl3_ClientSendNextProtoNegoXtn }, |
| 292 { ssl_cert_status_xtn, &ssl3_ClientSendStatusRequestXtn }, | 298 { ssl_cert_status_xtn, &ssl3_ClientSendStatusRequestXtn }, |
| 293 { ssl_ob_cert_xtn, &ssl3_SendOBCertXtn } | 299 { ssl_ob_cert_xtn, &ssl3_SendOBCertXtn }, |
| 300 { ssl_use_srtp_xtn, &ssl3_SendUseSRTPXtn } | |
| 294 /* any extra entries will appear as { 0, NULL } */ | 301 /* any extra entries will appear as { 0, NULL } */ |
| 295 }; | 302 }; |
| 296 | 303 |
| 297 static const | 304 static const |
| 298 ssl3HelloExtensionSender clientHelloSendersSSL3[SSL_MAX_EXTENSIONS] = { | 305 ssl3HelloExtensionSender clientHelloSendersSSL3[SSL_MAX_EXTENSIONS] = { |
| 299 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn } | 306 { ssl_renegotiation_info_xtn, &ssl3_SendRenegotiationInfoXtn } |
| 300 /* any extra entries will appear as { 0, NULL } */ | 307 /* any extra entries will appear as { 0, NULL } */ |
| 301 }; | 308 }; |
| 302 | 309 |
| 303 static PRBool | 310 static PRBool |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1861 | 1868 |
| 1862 /* The echoed extension must be empty. */ | 1869 /* The echoed extension must be empty. */ |
| 1863 if (data->len != 0) | 1870 if (data->len != 0) |
| 1864 return SECFailure; | 1871 return SECFailure; |
| 1865 | 1872 |
| 1866 /* Keep track of negotiated extensions. */ | 1873 /* Keep track of negotiated extensions. */ |
| 1867 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; | 1874 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ex_type; |
| 1868 | 1875 |
| 1869 return SECSuccess; | 1876 return SECSuccess; |
| 1870 } | 1877 } |
| 1878 | |
| 1879 static SECStatus | |
| 1880 ssl3_SendUseSRTPXtn(sslSocket *ss, PRBool append, PRUint32 maxBytes) | |
| 1881 { | |
| 1882 PRUint32 ext_data_len; | |
| 1883 PRInt16 i; | |
| 1884 SECStatus rv; | |
| 1885 | |
| 1886 if (!ss) | |
| 1887 return 0; | |
| 1888 | |
| 1889 if (!ss->sec.isServer) { | |
| 1890 /* Client */ | |
| 1891 | |
| 1892 if (!ss->ssl3.dtlsSRTPCipherCount) | |
| 1893 return 0; /* Not relevant */ | |
| 1894 | |
| 1895 ext_data_len = 2 + (2*ss->ssl3.dtlsSRTPCipherCount) + 1; | |
| 1896 | |
| 1897 if (append && ((4 + ext_data_len) <= maxBytes)) { | |
| 1898 /* Xtn type */ | |
| 1899 rv = ssl3_AppendHandshakeNumber(ss, ssl_use_srtp_xtn, 2); | |
| 1900 if (rv != SECSuccess) return -1; | |
| 1901 /* Length of extension data */ | |
| 1902 rv = ssl3_AppendHandshakeNumber(ss, ext_data_len, 2); | |
| 1903 if (rv != SECSuccess) return -1; | |
| 1904 /* Length of the SRTP cipher list */ | |
| 1905 rv = ssl3_AppendHandshakeNumber(ss, | |
| 1906 2 * ss->ssl3.dtlsSRTPCipherCount, | |
| 1907 2); | |
| 1908 if (rv != SECSuccess) return -1; | |
| 1909 /* The SRTP ciphers */ | |
| 1910 for (i = 0; i < ss->ssl3.dtlsSRTPCipherCount; i++) { | |
| 1911 rv = ssl3_AppendHandshakeNumber(ss, | |
| 1912 ss->ssl3.dtlsSRTPCiphers[i], | |
| 1913 2); | |
| 1914 } | |
| 1915 /* Empty MKI value */ | |
| 1916 ssl3_AppendHandshakeVariable(ss, NULL, 0, 1); | |
| 1917 | |
| 1918 ss->xtnData.advertised[ss->xtnData.numAdvertised++] = | |
| 1919 ssl_use_srtp_xtn; | |
| 1920 } | |
| 1921 | |
| 1922 return ext_data_len + 4; | |
| 1923 } | |
| 1924 | |
| 1925 /* Server side */ | |
| 1926 if (append && (maxBytes >= 9)) { | |
| 1927 /* Xtn type */ | |
| 1928 rv = ssl3_AppendHandshakeNumber(ss, ssl_use_srtp_xtn, 2); | |
| 1929 if (rv != SECSuccess) return -1; | |
| 1930 /* Length of extension data */ | |
| 1931 rv = ssl3_AppendHandshakeNumber(ss, 5, 2); | |
| 1932 if (rv != SECSuccess) return -1; | |
| 1933 /* Length of the SRTP cipher list */ | |
| 1934 rv = ssl3_AppendHandshakeNumber(ss, 2, 2); | |
| 1935 if (rv != SECSuccess) return -1; | |
| 1936 /* The selected cipher */ | |
| 1937 rv = ssl3_AppendHandshakeNumber(ss, ss->ssl3.dtlsSRTPCipherSuite, 2); | |
| 1938 if (rv != SECSuccess) return -1; | |
| 1939 /* Empty MKI value */ | |
| 1940 ssl3_AppendHandshakeVariable(ss, NULL, 0, 1); | |
| 1941 } | |
| 1942 | |
| 1943 return 9; | |
| 1944 } | |
| 1945 | |
| 1946 SECStatus | |
| 1947 ssl3_HandleUseSRTPXtn(sslSocket * ss, PRUint16 ex_type, SECItem *data) | |
| 1948 { | |
| 1949 SECStatus rv; | |
| 1950 PRInt16 i; | |
| 1951 PRInt16 bestIndex; | |
| 1952 PRBool found = PR_FALSE; | |
| 1953 SECItem litem; | |
| 1954 PRUint32 cipherLenBytes; | |
| 1955 PRUint32 cipher; | |
| 1956 | |
| 1957 if (!ss->sec.isServer) { | |
| 1958 /* Client side */ | |
| 1959 if (!data->data || !data->len || | |
| 1960 !ssl3_ClientExtensionAdvertised(ss, ssl_use_srtp_xtn)) { | |
|
wtc
2012/04/20 02:02:13
We don't need to check this here because
ssl3_Hand
ekr
2012/04/26 14:33:42
Agreed.
| |
| 1961 /* malformed or was not initiated by the client.*/ | |
| 1962 return SECFailure; | |
| 1963 } | |
| 1964 | |
| 1965 if (data->len != 5) { /* Must always be 9 since we don't offer MKI */ | |
| 1966 /* malformed or was not initiated by the client.*/ | |
| 1967 return SECFailure; | |
| 1968 } | |
| 1969 | |
| 1970 /* Now check that the number of ciphers listed is 1 (len = 2) */ | |
| 1971 cipherLenBytes = ssl3_ConsumeHandshakeNumber(ss, 2, | |
| 1972 &data->data, &data->len); | |
| 1973 if (cipherLenBytes != 2) | |
| 1974 return SECFailure; | |
| 1975 | |
| 1976 /* Get the selected cipher */ | |
| 1977 cipher = ssl3_ConsumeHandshakeNumber(ss, 2, &data->data, &data->len); | |
| 1978 | |
| 1979 /* Get the use_mki value */ | |
| 1980 rv = ssl3_ConsumeHandshakeVariable(ss, &litem, 1 , | |
| 1981 &data->data, &data->len); | |
| 1982 if (rv != SECSuccess) { | |
| 1983 return SECFailure; | |
| 1984 } | |
| 1985 /* We didn't offer an MKI, so this must be 0 length */ | |
| 1986 if (litem.len != 0) | |
| 1987 return SECFailure; | |
| 1988 | |
| 1989 /* Now check that this is one of the ciphers we offered */ | |
| 1990 for (i = 0; i < ss->ssl3.dtlsSRTPCipherCount; i++) { | |
| 1991 if (cipher == ss->ssl3.dtlsSRTPCiphers[i]) { | |
| 1992 found = PR_TRUE; | |
| 1993 break; | |
| 1994 } | |
| 1995 } | |
| 1996 | |
| 1997 if (!found) | |
| 1998 return SECFailure; | |
| 1999 | |
| 2000 /* OK, this looks fine. */ | |
| 2001 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ssl_use_srtp_xtn; | |
| 2002 ss->ssl3.dtlsSRTPCipherSuite = cipher; | |
| 2003 return SECSuccess; | |
| 2004 } | |
| 2005 | |
| 2006 /* Server side */ | |
| 2007 if (!IS_DTLS(ss)) { | |
| 2008 /* Ignore the extension. */ | |
|
wtc
2012/04/04 23:32:49
If the client offers the use_srtp extension in str
ekr
2012/04/19 14:29:36
I think it's best to ignore it.
In the OpenSSL c
| |
| 2009 return SECSuccess; | |
| 2010 } | |
| 2011 | |
| 2012 if (!data->data || data->len < 5) { | |
| 2013 /* malformed */ | |
| 2014 return SECFailure; | |
| 2015 } | |
| 2016 | |
| 2017 /* Get the length of the cipher list */ | |
| 2018 cipherLenBytes = ssl3_ConsumeHandshakeNumber(ss, 2, | |
| 2019 &data->data, &data->len); | |
| 2020 /* Check that there is room for the ciphers and that the list is even | |
| 2021 * length */ | |
| 2022 if ((cipherLenBytes > (data->len - 1)) || (cipherLenBytes % 2)) | |
| 2023 return SECFailure; | |
| 2024 | |
| 2025 /* Walk through the offered list one at a time and pick the most preferred | |
| 2026 * of our ciphers, if any */ | |
| 2027 while (cipherLenBytes > 0) { | |
| 2028 cipher = ssl3_ConsumeHandshakeNumber(ss, 2, &data->data, &data->len); | |
| 2029 cipherLenBytes -= 2; | |
| 2030 | |
| 2031 for (i = 0; i < ss->ssl3.dtlsSRTPCipherCount; i++) { | |
| 2032 /* Unknown ciphers just go through the entire list */ | |
| 2033 if (cipher == ss->ssl3.dtlsSRTPCiphers[i]) { | |
| 2034 if (!found) { | |
| 2035 found = PR_TRUE; | |
| 2036 bestIndex = i; | |
| 2037 } else { | |
| 2038 if (i < bestIndex) | |
| 2039 bestIndex = i; | |
| 2040 } | |
| 2041 break; | |
| 2042 } | |
| 2043 } | |
| 2044 } | |
| 2045 | |
| 2046 /* Get the use_mki value */ | |
| 2047 rv = ssl3_ConsumeHandshakeVariable(ss, &litem, 1, &data->data, &data->len); | |
| 2048 if (rv != SECSuccess) { | |
| 2049 return SECFailure; | |
| 2050 } | |
| 2051 | |
| 2052 if (data->len) | |
| 2053 return SECFailure; /* Malformed */ | |
| 2054 | |
| 2055 /* Now figure out what to do */ | |
| 2056 if (!found) { | |
| 2057 /* No matching ciphers */ | |
| 2058 return SECSuccess; | |
| 2059 } | |
| 2060 | |
| 2061 /* OK, we have a valid cipher and we've selected it */ | |
| 2062 ss->ssl3.dtlsSRTPCipherSuite = ss->ssl3.dtlsSRTPCiphers[bestIndex]; | |
| 2063 ss->xtnData.negotiated[ss->xtnData.numNegotiated++] = ssl_use_srtp_xtn; | |
| 2064 | |
| 2065 rv = ssl3_RegisterServerHelloExtensionSender(ss, ssl_use_srtp_xtn, | |
| 2066 ssl3_SendUseSRTPXtn); | |
| 2067 if (rv != SECSuccess) | |
| 2068 return rv; | |
| 2069 | |
| 2070 return SECSuccess; | |
| 2071 } | |
| OLD | NEW |