Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 0 as a valid ret value for mbedtls_ssl_write #1006

Merged

Conversation

andresag01
Copy link
Contributor

@andresag01 andresag01 commented Jul 11, 2017

This patch modifies the documentation for mbedtls_ssl_write() to allow
0 as a valid return value as this is the correct number of bytes that
should be returned when an empty TLS Application record is sent.

NOTES:

@andresag01 andresag01 changed the title Allow 0 as a valid ret value for mbedtls_ssl_write DRAFT: Allow 0 as a valid ret value for mbedtls_ssl_write Jul 11, 2017
@andresag01 andresag01 force-pushed the iotssl-1255-ssl_write_real branch from c35b56d to c0f1ad4 Compare July 11, 2017 15:16
@andresag01 andresag01 changed the title DRAFT: Allow 0 as a valid ret value for mbedtls_ssl_write Allow 0 as a valid ret value for mbedtls_ssl_write Jul 11, 2017
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but I think we should add some comments inside ssl_tls.c as well. This patch was triggered by a proposed change to ssl_tls.c which we analyzed and rejected; we should document the relevant place in ssl_write_real to explain what's happening.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without modifying ssl_tls.c, this doesn't resolve the issue. We've concluded that the code shouldn't be modified, but we should add a comment to explain the current behavior.

@andresag01
Copy link
Contributor Author

@gilles-peskine-arm: I have added more documentation to ssl_write_real() as requested.

@gilles-peskine-arm
Copy link
Contributor

Documentation-only change, so ok to merge despite the CI failed (and anyway all the CI steps suceeded??)

@andresag01
Copy link
Contributor Author

@gilles-peskine-arm: Indeed, I am not sure why the overall test reports a failure, but it seems that none of the individual pipeline stages failed.

* value or MBEDTLS_ERR_SSL_WANT_READ/WRITE, the ssl context
* becomes unusable, and you should either free it or call
* \c mbedtls_ssl_session_reset() on it before re-using it for
* a new connection; the current connection must be closed.
*
* \note When this function returns MBEDTLS_ERR_SSL_WANT_WRITE/READ,
* it must be called later with the *same* arguments,
* until it returns a positive value.
* until it returns a value greater that or equal to 0.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be greater than or here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that the sentence should be ... until it returns a value greater then or 0?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until it returns a value greater than or equal to 0

/*
* The user is trying to send a message the first time, so we need to
* copy the data into the internal buffers and setup the data structure
* to keep track of partial writes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this additional documentation 👍

Nitpicking: There are full stops missing at the end of this and the previous documentation snippet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will leave it as it is. I think the reason for this is that the doxygen documentation should be well punctuated, etc because it will ultimately end up as a formal documentation website. However, these are only in code comments, if you look at the other comments like this, you will see that (1) the style is fairly inconsistent across the library and (2) a lot of them don't have a full stop at the end either.

Copy link

@hanno-becker hanno-becker Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct it in case you add an additional commit for the other documentation fix - it's not a big thing and where we see such things we should correct them on the fly.

@hanno-becker
Copy link

I noticed we currently don't support request_size=0 in ssl_client2. I think it should be added at this occasion, together with a corresponding test in tests/ssl-opt.sh.

@hanno-becker
Copy link

hanno-becker commented Nov 29, 2017

@andresag01 While I would prefer the test changes to be done in this PR, I might open a separate PR for them to not block progress here. @gilles-peskine-arm What's your opinion on that?

Copy link

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments on grammar in the documentation, but otherwise I'm fine with the changes. I've also read the code and ran a test to confirm that it is possible to send empty AD records.

Leaving it to @gilles-peskine-arm whether or not to correct the documentation, they are not blockers.

I think we should add tests for empty AD records, which would involve a small adaption to ssl_client2.c. I could do that here if desired, or defer it to a separate PR.

Copy link

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran some more tests and noticed unexpected behavior in some cases that I need to investigate. Please don't merge, yet.

@gilles-peskine-arm
Copy link
Contributor

Sending and receiving 0-sized application records is not well-tested, but documenting it well gives the impression that it's well-supported. Therefore, I'm holding off merging this for the time being.

Tracked internally in IOTSSL-1255

@simonbutcher
Copy link
Contributor

LGTM.

@simonbutcher simonbutcher added approved Design and code approved - may be waiting for CI or backports needs-backports Backports are missing or are pending review and approval. and removed approved Design and code approved - may be waiting for CI or backports labels Jun 21, 2018
@simonbutcher
Copy link
Contributor

@andresag01 - Could you please rebase this PR and create backports?

Andres Amaya Garcia added 3 commits June 21, 2018 19:14
This patch modifies the documentation for mbedtls_ssl_write() to allow
0 as a valid return value as this is the correct number of bytes that
should be returned when an empty TLS Application record is sent.
@andresag01
Copy link
Contributor Author

@andresag01 andresag01 removed needs-backports Backports are missing or are pending review and approval. needs-work labels Jun 21, 2018
@simonbutcher simonbutcher added the approved Design and code approved - may be waiting for CI or backports label Jun 22, 2018
@simonbutcher simonbutcher merged commit 5b92352 into Mbed-TLS:development Jun 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants