Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Don't use the buffer BIO in TLS. On the TLS side, we introduce a running buffer of ciphertext. Queuing up pending data consists of encrypting the record into the buffer. This effectively reimplements what the buffer BIO was doing previously, but this resizes to fit the whole flight. As part of this, rename all the functions to add to the pending flight to be more uniform. This CL proposes "add_foo" to add to the pending flight and "flush_flight" to drain it. We add an add_alert hook for alerts but, for now, only the SSL 3.0 warning alert (sent mid-handshake) uses this mechanism. Later work will push this down to the rest of the write path so closure alerts use it too, as in DTLS. The intended end state is that all the ssl_buffer.c and wpend_ret logic will only be used for application data and eventually optionally replaced by the in-place API, while all "incidental" data will be handled internally. For now, the two buffers are mutually exclusive. Moving closure alerts to "incidentals" will change this, but flushing application data early is tricky due to wpend_ret. (If we call ssl_write_buffer_flush, do_ssl3_write doesn't realize it still has a wpend_ret to replay.) That too is all left alone in this change. To keep the diff down, write_message is retained for now and will be removed from the state machines in a follow-up change. BUG=72 Change-Id: Ibce882f5f7196880648f25d5005322ca4055c71d Reviewed-on: https://boringssl-review.googlesource.com/13224 Reviewed-by: Adam Langley <agl@google.com>
7 лет назад
Simplify handshake message size limits. A handshake message can go up to 2^24 bytes = 16MB which is a little large for the peer to force us to buffer. Accordingly, we bound the size of a handshake message. Rather than have a global limit, the existing logic uses a different limit at each state in the handshake state machine and, for certificates, allows configuring the maximum certificate size. This is nice in that we engage larger limits iff the relevant state is reachable from the handshake. Servers without client auth get a tighter limit "for free". However, this doesn't work for DTLS due to out-of-order messages and we use a simpler scheme for DTLS. This scheme also is tricky on optional messages and makes the handshake <-> message layer communication complex. Apart from an ignored 20,000 byte limit on ServerHello, the largest non-certificate limit is the common 16k limit on ClientHello. So this complexity wasn't buying us anything. Unify everything on the DTLS scheme except, so as not to regress bounds on client-auth-less servers, also correctly check for whether client auth is configured. The value of 16k was chosen based on this value. (The 20,000 byte ServerHello limit makes no sense. We can easily bound the ServerHello because servers may not send extensions we don't implement. But it gets overshadowed by the certificate anyway.) Change-Id: I00309b16d809a3c2a1543f99fd29c4163e3add81 Reviewed-on: https://boringssl-review.googlesource.com/7941 Reviewed-by: David Benjamin <davidben@google.com>
8 лет назад
Simplify handshake message size limits. A handshake message can go up to 2^24 bytes = 16MB which is a little large for the peer to force us to buffer. Accordingly, we bound the size of a handshake message. Rather than have a global limit, the existing logic uses a different limit at each state in the handshake state machine and, for certificates, allows configuring the maximum certificate size. This is nice in that we engage larger limits iff the relevant state is reachable from the handshake. Servers without client auth get a tighter limit "for free". However, this doesn't work for DTLS due to out-of-order messages and we use a simpler scheme for DTLS. This scheme also is tricky on optional messages and makes the handshake <-> message layer communication complex. Apart from an ignored 20,000 byte limit on ServerHello, the largest non-certificate limit is the common 16k limit on ClientHello. So this complexity wasn't buying us anything. Unify everything on the DTLS scheme except, so as not to regress bounds on client-auth-less servers, also correctly check for whether client auth is configured. The value of 16k was chosen based on this value. (The 20,000 byte ServerHello limit makes no sense. We can easily bound the ServerHello because servers may not send extensions we don't implement. But it gets overshadowed by the certificate anyway.) Change-Id: I00309b16d809a3c2a1543f99fd29c4163e3add81 Reviewed-on: https://boringssl-review.googlesource.com/7941 Reviewed-by: David Benjamin <davidben@google.com>
8 лет назад
Simplify handshake message size limits. A handshake message can go up to 2^24 bytes = 16MB which is a little large for the peer to force us to buffer. Accordingly, we bound the size of a handshake message. Rather than have a global limit, the existing logic uses a different limit at each state in the handshake state machine and, for certificates, allows configuring the maximum certificate size. This is nice in that we engage larger limits iff the relevant state is reachable from the handshake. Servers without client auth get a tighter limit "for free". However, this doesn't work for DTLS due to out-of-order messages and we use a simpler scheme for DTLS. This scheme also is tricky on optional messages and makes the handshake <-> message layer communication complex. Apart from an ignored 20,000 byte limit on ServerHello, the largest non-certificate limit is the common 16k limit on ClientHello. So this complexity wasn't buying us anything. Unify everything on the DTLS scheme except, so as not to regress bounds on client-auth-less servers, also correctly check for whether client auth is configured. The value of 16k was chosen based on this value. (The 20,000 byte ServerHello limit makes no sense. We can easily bound the ServerHello because servers may not send extensions we don't implement. But it gets overshadowed by the certificate anyway.) Change-Id: I00309b16d809a3c2a1543f99fd29c4163e3add81 Reviewed-on: https://boringssl-review.googlesource.com/7941 Reviewed-by: David Benjamin <davidben@google.com>
8 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. * are met:
  63. *
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. *
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in
  69. * the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3. All advertising materials mentioning features or use of this
  73. * software must display the following acknowledgment:
  74. * "This product includes software developed by the OpenSSL Project
  75. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  76. *
  77. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  78. * endorse or promote products derived from this software without
  79. * prior written permission. For written permission, please contact
  80. * openssl-core@openssl.org.
  81. *
  82. * 5. Products derived from this software may not be called "OpenSSL"
  83. * nor may "OpenSSL" appear in their names without prior written
  84. * permission of the OpenSSL Project.
  85. *
  86. * 6. Redistributions of any form whatsoever must retain the following
  87. * acknowledgment:
  88. * "This product includes software developed by the OpenSSL Project
  89. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  90. *
  91. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  92. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  93. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  94. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  95. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  96. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  97. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  98. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  100. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  101. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  102. * OF THE POSSIBILITY OF SUCH DAMAGE.
  103. * ====================================================================
  104. *
  105. * This product includes cryptographic software written by Eric Young
  106. * (eay@cryptsoft.com). This product includes software written by Tim
  107. * Hudson (tjh@cryptsoft.com). */
  108. /* ====================================================================
  109. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  110. * ECC cipher suite support in OpenSSL originally developed by
  111. * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. */
  112. #include <openssl/ssl.h>
  113. #include <assert.h>
  114. #include <limits.h>
  115. #include <string.h>
  116. #include <openssl/buf.h>
  117. #include <openssl/bytestring.h>
  118. #include <openssl/err.h>
  119. #include <openssl/evp.h>
  120. #include <openssl/mem.h>
  121. #include <openssl/md5.h>
  122. #include <openssl/nid.h>
  123. #include <openssl/rand.h>
  124. #include <openssl/sha.h>
  125. #include "../crypto/internal.h"
  126. #include "internal.h"
  127. SSL_HANDSHAKE *ssl_handshake_new(SSL *ssl) {
  128. SSL_HANDSHAKE *hs = OPENSSL_malloc(sizeof(SSL_HANDSHAKE));
  129. if (hs == NULL) {
  130. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  131. return NULL;
  132. }
  133. OPENSSL_memset(hs, 0, sizeof(SSL_HANDSHAKE));
  134. hs->ssl = ssl;
  135. hs->wait = ssl_hs_ok;
  136. hs->state = SSL_ST_INIT;
  137. if (!SSL_TRANSCRIPT_init(&hs->transcript)) {
  138. ssl_handshake_free(hs);
  139. return NULL;
  140. }
  141. return hs;
  142. }
  143. void ssl_handshake_free(SSL_HANDSHAKE *hs) {
  144. if (hs == NULL) {
  145. return;
  146. }
  147. OPENSSL_cleanse(hs->secret, sizeof(hs->secret));
  148. OPENSSL_cleanse(hs->early_traffic_secret, sizeof(hs->early_traffic_secret));
  149. OPENSSL_cleanse(hs->client_handshake_secret,
  150. sizeof(hs->client_handshake_secret));
  151. OPENSSL_cleanse(hs->server_handshake_secret,
  152. sizeof(hs->server_handshake_secret));
  153. OPENSSL_cleanse(hs->client_traffic_secret_0,
  154. sizeof(hs->client_traffic_secret_0));
  155. OPENSSL_cleanse(hs->server_traffic_secret_0,
  156. sizeof(hs->server_traffic_secret_0));
  157. SSL_ECDH_CTX_cleanup(&hs->ecdh_ctx);
  158. SSL_TRANSCRIPT_cleanup(&hs->transcript);
  159. OPENSSL_free(hs->cookie);
  160. OPENSSL_free(hs->key_share_bytes);
  161. OPENSSL_free(hs->ecdh_public_key);
  162. SSL_SESSION_free(hs->new_session);
  163. SSL_SESSION_free(hs->early_session);
  164. OPENSSL_free(hs->peer_sigalgs);
  165. OPENSSL_free(hs->peer_supported_group_list);
  166. OPENSSL_free(hs->peer_key);
  167. OPENSSL_free(hs->server_params);
  168. OPENSSL_free(hs->peer_psk_identity_hint);
  169. sk_CRYPTO_BUFFER_pop_free(hs->ca_names, CRYPTO_BUFFER_free);
  170. hs->ssl->ctx->x509_method->hs_flush_cached_ca_names(hs);
  171. OPENSSL_free(hs->certificate_types);
  172. if (hs->key_block != NULL) {
  173. OPENSSL_cleanse(hs->key_block, hs->key_block_len);
  174. OPENSSL_free(hs->key_block);
  175. }
  176. OPENSSL_free(hs->hostname);
  177. EVP_PKEY_free(hs->peer_pubkey);
  178. EVP_PKEY_free(hs->local_pubkey);
  179. OPENSSL_free(hs);
  180. }
  181. int ssl_check_message_type(SSL *ssl, int type) {
  182. if (ssl->s3->tmp.message_type != type) {
  183. ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
  184. OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
  185. ERR_add_error_dataf("got type %d, wanted type %d",
  186. ssl->s3->tmp.message_type, type);
  187. return 0;
  188. }
  189. return 1;
  190. }
  191. static int add_record_to_flight(SSL *ssl, uint8_t type, const uint8_t *in,
  192. size_t in_len) {
  193. /* We'll never add a flight while in the process of writing it out. */
  194. assert(ssl->s3->pending_flight_offset == 0);
  195. if (ssl->s3->pending_flight == NULL) {
  196. ssl->s3->pending_flight = BUF_MEM_new();
  197. if (ssl->s3->pending_flight == NULL) {
  198. return 0;
  199. }
  200. }
  201. size_t max_out = in_len + SSL_max_seal_overhead(ssl);
  202. size_t new_cap = ssl->s3->pending_flight->length + max_out;
  203. if (max_out < in_len || new_cap < max_out) {
  204. OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW);
  205. return 0;
  206. }
  207. size_t len;
  208. if (!BUF_MEM_reserve(ssl->s3->pending_flight, new_cap) ||
  209. !tls_seal_record(ssl, (uint8_t *)ssl->s3->pending_flight->data +
  210. ssl->s3->pending_flight->length,
  211. &len, max_out, type, in, in_len)) {
  212. return 0;
  213. }
  214. ssl->s3->pending_flight->length += len;
  215. return 1;
  216. }
  217. int ssl3_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type) {
  218. /* Pick a modest size hint to save most of the |realloc| calls. */
  219. if (!CBB_init(cbb, 64) ||
  220. !CBB_add_u8(cbb, type) ||
  221. !CBB_add_u24_length_prefixed(cbb, body)) {
  222. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  223. CBB_cleanup(cbb);
  224. return 0;
  225. }
  226. return 1;
  227. }
  228. int ssl3_finish_message(SSL *ssl, CBB *cbb, uint8_t **out_msg,
  229. size_t *out_len) {
  230. if (!CBB_finish(cbb, out_msg, out_len)) {
  231. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  232. return 0;
  233. }
  234. return 1;
  235. }
  236. int ssl3_add_message(SSL *ssl, uint8_t *msg, size_t len) {
  237. /* Add the message to the current flight, splitting into several records if
  238. * needed. */
  239. int ret = 0;
  240. size_t added = 0;
  241. do {
  242. size_t todo = len - added;
  243. if (todo > ssl->max_send_fragment) {
  244. todo = ssl->max_send_fragment;
  245. }
  246. if (!add_record_to_flight(ssl, SSL3_RT_HANDSHAKE, msg + added, todo)) {
  247. goto err;
  248. }
  249. added += todo;
  250. } while (added < len);
  251. ssl_do_msg_callback(ssl, 1 /* write */, SSL3_RT_HANDSHAKE, msg, len);
  252. /* TODO(svaldez): Move this up a layer to fix abstraction for SSL_TRANSCRIPT
  253. * on hs. */
  254. if (ssl->s3->hs != NULL &&
  255. !SSL_TRANSCRIPT_update(&ssl->s3->hs->transcript, msg, len)) {
  256. goto err;
  257. }
  258. ret = 1;
  259. err:
  260. OPENSSL_free(msg);
  261. return ret;
  262. }
  263. int ssl3_add_change_cipher_spec(SSL *ssl) {
  264. static const uint8_t kChangeCipherSpec[1] = {SSL3_MT_CCS};
  265. if (!add_record_to_flight(ssl, SSL3_RT_CHANGE_CIPHER_SPEC, kChangeCipherSpec,
  266. sizeof(kChangeCipherSpec))) {
  267. return 0;
  268. }
  269. ssl_do_msg_callback(ssl, 1 /* write */, SSL3_RT_CHANGE_CIPHER_SPEC,
  270. kChangeCipherSpec, sizeof(kChangeCipherSpec));
  271. return 1;
  272. }
  273. int ssl3_add_alert(SSL *ssl, uint8_t level, uint8_t desc) {
  274. uint8_t alert[2] = {level, desc};
  275. if (!add_record_to_flight(ssl, SSL3_RT_ALERT, alert, sizeof(alert))) {
  276. return 0;
  277. }
  278. ssl_do_msg_callback(ssl, 1 /* write */, SSL3_RT_ALERT, alert, sizeof(alert));
  279. ssl_do_info_callback(ssl, SSL_CB_WRITE_ALERT, ((int)level << 8) | desc);
  280. return 1;
  281. }
  282. int ssl_add_message_cbb(SSL *ssl, CBB *cbb) {
  283. uint8_t *msg;
  284. size_t len;
  285. if (!ssl->method->finish_message(ssl, cbb, &msg, &len) ||
  286. !ssl->method->add_message(ssl, msg, len)) {
  287. return 0;
  288. }
  289. return 1;
  290. }
  291. int ssl3_flush_flight(SSL *ssl) {
  292. if (ssl->s3->pending_flight == NULL) {
  293. return 1;
  294. }
  295. if (ssl->s3->pending_flight->length > 0xffffffff ||
  296. ssl->s3->pending_flight->length > INT_MAX) {
  297. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  298. return -1;
  299. }
  300. /* If there is pending data in the write buffer, it must be flushed out before
  301. * any new data in pending_flight. */
  302. if (ssl_write_buffer_is_pending(ssl)) {
  303. int ret = ssl_write_buffer_flush(ssl);
  304. if (ret <= 0) {
  305. ssl->rwstate = SSL_WRITING;
  306. return ret;
  307. }
  308. }
  309. /* Write the pending flight. */
  310. while (ssl->s3->pending_flight_offset < ssl->s3->pending_flight->length) {
  311. int ret = BIO_write(
  312. ssl->wbio,
  313. ssl->s3->pending_flight->data + ssl->s3->pending_flight_offset,
  314. ssl->s3->pending_flight->length - ssl->s3->pending_flight_offset);
  315. if (ret <= 0) {
  316. ssl->rwstate = SSL_WRITING;
  317. return ret;
  318. }
  319. ssl->s3->pending_flight_offset += ret;
  320. }
  321. if (BIO_flush(ssl->wbio) <= 0) {
  322. ssl->rwstate = SSL_WRITING;
  323. return -1;
  324. }
  325. BUF_MEM_free(ssl->s3->pending_flight);
  326. ssl->s3->pending_flight = NULL;
  327. ssl->s3->pending_flight_offset = 0;
  328. return 1;
  329. }
  330. int ssl3_send_finished(SSL_HANDSHAKE *hs) {
  331. SSL *const ssl = hs->ssl;
  332. const SSL_SESSION *session = SSL_get_session(ssl);
  333. uint8_t finished[EVP_MAX_MD_SIZE];
  334. size_t finished_len;
  335. if (!SSL_TRANSCRIPT_finish_mac(&hs->transcript, finished, &finished_len,
  336. session, ssl->server,
  337. ssl3_protocol_version(ssl))) {
  338. return 0;
  339. }
  340. /* Log the master secret, if logging is enabled. */
  341. if (!ssl_log_secret(ssl, "CLIENT_RANDOM",
  342. session->master_key,
  343. session->master_key_length)) {
  344. return 0;
  345. }
  346. /* Copy the Finished so we can use it for renegotiation checks. */
  347. if (ssl->version != SSL3_VERSION) {
  348. if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
  349. finished_len > sizeof(ssl->s3->previous_server_finished)) {
  350. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  351. return -1;
  352. }
  353. if (ssl->server) {
  354. OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
  355. ssl->s3->previous_server_finished_len = finished_len;
  356. } else {
  357. OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
  358. ssl->s3->previous_client_finished_len = finished_len;
  359. }
  360. }
  361. CBB cbb, body;
  362. if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_FINISHED) ||
  363. !CBB_add_bytes(&body, finished, finished_len) ||
  364. !ssl_add_message_cbb(ssl, &cbb)) {
  365. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  366. CBB_cleanup(&cbb);
  367. return -1;
  368. }
  369. return 1;
  370. }
  371. int ssl3_get_finished(SSL_HANDSHAKE *hs) {
  372. SSL *const ssl = hs->ssl;
  373. int ret = ssl->method->ssl_get_message(ssl);
  374. if (ret <= 0) {
  375. return ret;
  376. }
  377. if (!ssl_check_message_type(ssl, SSL3_MT_FINISHED)) {
  378. return -1;
  379. }
  380. /* Snapshot the finished hash before incorporating the new message. */
  381. uint8_t finished[EVP_MAX_MD_SIZE];
  382. size_t finished_len;
  383. if (!SSL_TRANSCRIPT_finish_mac(&hs->transcript, finished, &finished_len,
  384. SSL_get_session(ssl), !ssl->server,
  385. ssl3_protocol_version(ssl)) ||
  386. !ssl_hash_current_message(hs)) {
  387. return -1;
  388. }
  389. int finished_ok = ssl->init_num == finished_len &&
  390. CRYPTO_memcmp(ssl->init_msg, finished, finished_len) == 0;
  391. #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
  392. finished_ok = 1;
  393. #endif
  394. if (!finished_ok) {
  395. ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
  396. OPENSSL_PUT_ERROR(SSL, SSL_R_DIGEST_CHECK_FAILED);
  397. return -1;
  398. }
  399. /* Copy the Finished so we can use it for renegotiation checks. */
  400. if (ssl->version != SSL3_VERSION) {
  401. if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
  402. finished_len > sizeof(ssl->s3->previous_server_finished)) {
  403. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  404. return -1;
  405. }
  406. if (ssl->server) {
  407. OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
  408. ssl->s3->previous_client_finished_len = finished_len;
  409. } else {
  410. OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
  411. ssl->s3->previous_server_finished_len = finished_len;
  412. }
  413. }
  414. return 1;
  415. }
  416. int ssl3_output_cert_chain(SSL *ssl) {
  417. CBB cbb, body;
  418. if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CERTIFICATE) ||
  419. !ssl_add_cert_chain(ssl, &body) ||
  420. !ssl_add_message_cbb(ssl, &cbb)) {
  421. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  422. CBB_cleanup(&cbb);
  423. return 0;
  424. }
  425. return 1;
  426. }
  427. size_t ssl_max_handshake_message_len(const SSL *ssl) {
  428. /* kMaxMessageLen is the default maximum message size for handshakes which do
  429. * not accept peer certificate chains. */
  430. static const size_t kMaxMessageLen = 16384;
  431. if (SSL_in_init(ssl)) {
  432. if ((!ssl->server || (ssl->verify_mode & SSL_VERIFY_PEER)) &&
  433. kMaxMessageLen < ssl->max_cert_list) {
  434. return ssl->max_cert_list;
  435. }
  436. return kMaxMessageLen;
  437. }
  438. if (ssl3_protocol_version(ssl) < TLS1_3_VERSION) {
  439. /* In TLS 1.2 and below, the largest acceptable post-handshake message is
  440. * a HelloRequest. */
  441. return 0;
  442. }
  443. if (ssl->server) {
  444. /* The largest acceptable post-handshake message for a server is a
  445. * KeyUpdate. We will never initiate post-handshake auth. */
  446. return 1;
  447. }
  448. /* Clients must accept NewSessionTicket and CertificateRequest, so allow the
  449. * default size. */
  450. return kMaxMessageLen;
  451. }
  452. static int extend_handshake_buffer(SSL *ssl, size_t length) {
  453. if (!BUF_MEM_reserve(ssl->init_buf, length)) {
  454. return -1;
  455. }
  456. while (ssl->init_buf->length < length) {
  457. int ret = ssl3_read_handshake_bytes(
  458. ssl, (uint8_t *)ssl->init_buf->data + ssl->init_buf->length,
  459. length - ssl->init_buf->length);
  460. if (ret <= 0) {
  461. return ret;
  462. }
  463. ssl->init_buf->length += (size_t)ret;
  464. }
  465. return 1;
  466. }
  467. static int read_v2_client_hello(SSL *ssl) {
  468. /* Read the first 5 bytes, the size of the TLS record header. This is
  469. * sufficient to detect a V2ClientHello and ensures that we never read beyond
  470. * the first record. */
  471. int ret = ssl_read_buffer_extend_to(ssl, SSL3_RT_HEADER_LENGTH);
  472. if (ret <= 0) {
  473. return ret;
  474. }
  475. const uint8_t *p = ssl_read_buffer(ssl);
  476. /* Some dedicated error codes for protocol mixups should the application wish
  477. * to interpret them differently. (These do not overlap with ClientHello or
  478. * V2ClientHello.) */
  479. if (strncmp("GET ", (const char *)p, 4) == 0 ||
  480. strncmp("POST ", (const char *)p, 5) == 0 ||
  481. strncmp("HEAD ", (const char *)p, 5) == 0 ||
  482. strncmp("PUT ", (const char *)p, 4) == 0) {
  483. OPENSSL_PUT_ERROR(SSL, SSL_R_HTTP_REQUEST);
  484. return -1;
  485. }
  486. if (strncmp("CONNE", (const char *)p, 5) == 0) {
  487. OPENSSL_PUT_ERROR(SSL, SSL_R_HTTPS_PROXY_REQUEST);
  488. return -1;
  489. }
  490. if ((p[0] & 0x80) == 0 || p[2] != SSL2_MT_CLIENT_HELLO ||
  491. p[3] != SSL3_VERSION_MAJOR) {
  492. /* Not a V2ClientHello. */
  493. return 1;
  494. }
  495. /* Determine the length of the V2ClientHello. */
  496. size_t msg_length = ((p[0] & 0x7f) << 8) | p[1];
  497. if (msg_length > (1024 * 4)) {
  498. OPENSSL_PUT_ERROR(SSL, SSL_R_RECORD_TOO_LARGE);
  499. return -1;
  500. }
  501. if (msg_length < SSL3_RT_HEADER_LENGTH - 2) {
  502. /* Reject lengths that are too short early. We have already read
  503. * |SSL3_RT_HEADER_LENGTH| bytes, so we should not attempt to process an
  504. * (invalid) V2ClientHello which would be shorter than that. */
  505. OPENSSL_PUT_ERROR(SSL, SSL_R_RECORD_LENGTH_MISMATCH);
  506. return -1;
  507. }
  508. /* Read the remainder of the V2ClientHello. */
  509. ret = ssl_read_buffer_extend_to(ssl, 2 + msg_length);
  510. if (ret <= 0) {
  511. return ret;
  512. }
  513. CBS v2_client_hello;
  514. CBS_init(&v2_client_hello, ssl_read_buffer(ssl) + 2, msg_length);
  515. /* The V2ClientHello without the length is incorporated into the handshake
  516. * hash. This is only ever called at the start of the handshake, so hs is
  517. * guaranteed to be non-NULL. */
  518. if (!SSL_TRANSCRIPT_update(&ssl->s3->hs->transcript,
  519. CBS_data(&v2_client_hello),
  520. CBS_len(&v2_client_hello))) {
  521. return -1;
  522. }
  523. ssl_do_msg_callback(ssl, 0 /* read */, 0 /* V2ClientHello */,
  524. CBS_data(&v2_client_hello), CBS_len(&v2_client_hello));
  525. uint8_t msg_type;
  526. uint16_t version, cipher_spec_length, session_id_length, challenge_length;
  527. CBS cipher_specs, session_id, challenge;
  528. if (!CBS_get_u8(&v2_client_hello, &msg_type) ||
  529. !CBS_get_u16(&v2_client_hello, &version) ||
  530. !CBS_get_u16(&v2_client_hello, &cipher_spec_length) ||
  531. !CBS_get_u16(&v2_client_hello, &session_id_length) ||
  532. !CBS_get_u16(&v2_client_hello, &challenge_length) ||
  533. !CBS_get_bytes(&v2_client_hello, &cipher_specs, cipher_spec_length) ||
  534. !CBS_get_bytes(&v2_client_hello, &session_id, session_id_length) ||
  535. !CBS_get_bytes(&v2_client_hello, &challenge, challenge_length) ||
  536. CBS_len(&v2_client_hello) != 0) {
  537. OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
  538. return -1;
  539. }
  540. /* msg_type has already been checked. */
  541. assert(msg_type == SSL2_MT_CLIENT_HELLO);
  542. /* The client_random is the V2ClientHello challenge. Truncate or
  543. * left-pad with zeros as needed. */
  544. size_t rand_len = CBS_len(&challenge);
  545. if (rand_len > SSL3_RANDOM_SIZE) {
  546. rand_len = SSL3_RANDOM_SIZE;
  547. }
  548. uint8_t random[SSL3_RANDOM_SIZE];
  549. OPENSSL_memset(random, 0, SSL3_RANDOM_SIZE);
  550. OPENSSL_memcpy(random + (SSL3_RANDOM_SIZE - rand_len), CBS_data(&challenge),
  551. rand_len);
  552. /* Write out an equivalent SSLv3 ClientHello. */
  553. size_t max_v3_client_hello = SSL3_HM_HEADER_LENGTH + 2 /* version */ +
  554. SSL3_RANDOM_SIZE + 1 /* session ID length */ +
  555. 2 /* cipher list length */ +
  556. CBS_len(&cipher_specs) / 3 * 2 +
  557. 1 /* compression length */ + 1 /* compression */;
  558. CBB client_hello, hello_body, cipher_suites;
  559. CBB_zero(&client_hello);
  560. if (!BUF_MEM_reserve(ssl->init_buf, max_v3_client_hello) ||
  561. !CBB_init_fixed(&client_hello, (uint8_t *)ssl->init_buf->data,
  562. ssl->init_buf->max) ||
  563. !CBB_add_u8(&client_hello, SSL3_MT_CLIENT_HELLO) ||
  564. !CBB_add_u24_length_prefixed(&client_hello, &hello_body) ||
  565. !CBB_add_u16(&hello_body, version) ||
  566. !CBB_add_bytes(&hello_body, random, SSL3_RANDOM_SIZE) ||
  567. /* No session id. */
  568. !CBB_add_u8(&hello_body, 0) ||
  569. !CBB_add_u16_length_prefixed(&hello_body, &cipher_suites)) {
  570. CBB_cleanup(&client_hello);
  571. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  572. return -1;
  573. }
  574. /* Copy the cipher suites. */
  575. while (CBS_len(&cipher_specs) > 0) {
  576. uint32_t cipher_spec;
  577. if (!CBS_get_u24(&cipher_specs, &cipher_spec)) {
  578. CBB_cleanup(&client_hello);
  579. OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
  580. return -1;
  581. }
  582. /* Skip SSLv2 ciphers. */
  583. if ((cipher_spec & 0xff0000) != 0) {
  584. continue;
  585. }
  586. if (!CBB_add_u16(&cipher_suites, cipher_spec)) {
  587. CBB_cleanup(&client_hello);
  588. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  589. return -1;
  590. }
  591. }
  592. /* Add the null compression scheme and finish. */
  593. if (!CBB_add_u8(&hello_body, 1) || !CBB_add_u8(&hello_body, 0) ||
  594. !CBB_finish(&client_hello, NULL, &ssl->init_buf->length)) {
  595. CBB_cleanup(&client_hello);
  596. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  597. return -1;
  598. }
  599. /* Consume and discard the V2ClientHello. */
  600. ssl_read_buffer_consume(ssl, 2 + msg_length);
  601. ssl_read_buffer_discard(ssl);
  602. ssl->s3->is_v2_hello = 1;
  603. return 1;
  604. }
  605. int ssl3_get_message(SSL *ssl) {
  606. /* Re-create the handshake buffer if needed. */
  607. if (ssl->init_buf == NULL) {
  608. ssl->init_buf = BUF_MEM_new();
  609. if (ssl->init_buf == NULL) {
  610. return -1;
  611. }
  612. }
  613. if (ssl->server && !ssl->s3->v2_hello_done) {
  614. /* Bypass the record layer for the first message to handle V2ClientHello. */
  615. int ret = read_v2_client_hello(ssl);
  616. if (ret <= 0) {
  617. return ret;
  618. }
  619. ssl->s3->v2_hello_done = 1;
  620. }
  621. if (ssl->s3->tmp.reuse_message) {
  622. /* There must be a current message. */
  623. assert(ssl->init_msg != NULL);
  624. ssl->s3->tmp.reuse_message = 0;
  625. } else {
  626. ssl3_release_current_message(ssl, 0 /* don't free buffer */);
  627. }
  628. /* Read the message header, if we haven't yet. */
  629. int ret = extend_handshake_buffer(ssl, SSL3_HM_HEADER_LENGTH);
  630. if (ret <= 0) {
  631. return ret;
  632. }
  633. /* Parse out the length. Cap it so the peer cannot force us to buffer up to
  634. * 2^24 bytes. */
  635. const uint8_t *p = (uint8_t *)ssl->init_buf->data;
  636. size_t msg_len = (((uint32_t)p[1]) << 16) | (((uint32_t)p[2]) << 8) | p[3];
  637. if (msg_len > ssl_max_handshake_message_len(ssl)) {
  638. ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
  639. OPENSSL_PUT_ERROR(SSL, SSL_R_EXCESSIVE_MESSAGE_SIZE);
  640. return -1;
  641. }
  642. /* Read the message body, if we haven't yet. */
  643. ret = extend_handshake_buffer(ssl, SSL3_HM_HEADER_LENGTH + msg_len);
  644. if (ret <= 0) {
  645. return ret;
  646. }
  647. /* We have now received a complete message. */
  648. ssl_do_msg_callback(ssl, 0 /* read */, SSL3_RT_HANDSHAKE, ssl->init_buf->data,
  649. ssl->init_buf->length);
  650. ssl->s3->tmp.message_type = ((const uint8_t *)ssl->init_buf->data)[0];
  651. ssl->init_msg = (uint8_t*)ssl->init_buf->data + SSL3_HM_HEADER_LENGTH;
  652. ssl->init_num = ssl->init_buf->length - SSL3_HM_HEADER_LENGTH;
  653. return 1;
  654. }
  655. void ssl3_get_current_message(const SSL *ssl, CBS *out) {
  656. CBS_init(out, (uint8_t *)ssl->init_buf->data, ssl->init_buf->length);
  657. }
  658. int ssl_hash_current_message(SSL_HANDSHAKE *hs) {
  659. /* V2ClientHellos are hashed implicitly. */
  660. if (hs->ssl->s3->is_v2_hello) {
  661. return 1;
  662. }
  663. CBS cbs;
  664. hs->ssl->method->get_current_message(hs->ssl, &cbs);
  665. return SSL_TRANSCRIPT_update(&hs->transcript, CBS_data(&cbs), CBS_len(&cbs));
  666. }
  667. void ssl3_release_current_message(SSL *ssl, int free_buffer) {
  668. if (ssl->init_msg != NULL) {
  669. /* |init_buf| never contains data beyond the current message. */
  670. assert(SSL3_HM_HEADER_LENGTH + ssl->init_num == ssl->init_buf->length);
  671. /* Clear the current message. */
  672. ssl->init_msg = NULL;
  673. ssl->init_num = 0;
  674. ssl->init_buf->length = 0;
  675. ssl->s3->is_v2_hello = 0;
  676. }
  677. if (free_buffer) {
  678. BUF_MEM_free(ssl->init_buf);
  679. ssl->init_buf = NULL;
  680. }
  681. }
  682. int ssl_parse_extensions(const CBS *cbs, uint8_t *out_alert,
  683. const SSL_EXTENSION_TYPE *ext_types,
  684. size_t num_ext_types, int ignore_unknown) {
  685. /* Reset everything. */
  686. for (size_t i = 0; i < num_ext_types; i++) {
  687. *ext_types[i].out_present = 0;
  688. CBS_init(ext_types[i].out_data, NULL, 0);
  689. }
  690. CBS copy = *cbs;
  691. while (CBS_len(&copy) != 0) {
  692. uint16_t type;
  693. CBS data;
  694. if (!CBS_get_u16(&copy, &type) ||
  695. !CBS_get_u16_length_prefixed(&copy, &data)) {
  696. OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
  697. *out_alert = SSL_AD_DECODE_ERROR;
  698. return 0;
  699. }
  700. const SSL_EXTENSION_TYPE *ext_type = NULL;
  701. for (size_t i = 0; i < num_ext_types; i++) {
  702. if (type == ext_types[i].type) {
  703. ext_type = &ext_types[i];
  704. break;
  705. }
  706. }
  707. if (ext_type == NULL) {
  708. if (ignore_unknown) {
  709. continue;
  710. }
  711. OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION);
  712. *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
  713. return 0;
  714. }
  715. /* Duplicate ext_types are forbidden. */
  716. if (*ext_type->out_present) {
  717. OPENSSL_PUT_ERROR(SSL, SSL_R_DUPLICATE_EXTENSION);
  718. *out_alert = SSL_AD_ILLEGAL_PARAMETER;
  719. return 0;
  720. }
  721. *ext_type->out_present = 1;
  722. *ext_type->out_data = data;
  723. }
  724. return 1;
  725. }