Skip to content

Documentation of TLSSocket behavior on AUTH_FAILURE #9392

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

Merged

Conversation

michalpasztamobica
Copy link
Contributor

Description

It is not possible to store TLS certificate after opening a TLSSocket, due to mbedTLS limitation. We update the documentation to warn users and explain the reason.
(Internal JIRA with the full discussion is ONME-4121)

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[x] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@SeppoTakalo
@VeijoPesonen

@kjbracey
Copy link
Contributor

Surely this is nothing to do with "AUTH_FAILURE"? It's a general restriction that the socket can only be used for one connection (attempt).

That limitation is not that unusual for connection-type sockets in general, but may be worth noting here.

(POSIX says: "If connect() fails, the state of the socket is unspecified. Conforming applications should close the file descriptor and create a new socket before attempting to reconnect.")

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 16, 2019

Note: Travis failure is fixed on master (#9391) , if you can rebase to resolve the error

@michalpasztamobica michalpasztamobica force-pushed the tlssocket_documentation_update branch from bd07ade to ade5624 Compare January 16, 2019 15:51
@michalpasztamobica
Copy link
Contributor Author

@0xc0170 , thanks, I rebased.
@kjbracey-arm , thank you for your remark. I modified the comment. I guess if we warn users that after close() they need to create the socket from scratch, we can also warn them that they should do so in case connect() fails. Is the current comment content acceptable?

@@ -75,6 +75,9 @@ class TLSSocket : public TLSSocketWrapper {
* Initiates a connection to a remote server specified by either
* a domain name or an IP address and a port.
*
* @note: In case connect() returns an error, the state of the socket is
* unspecified. A new socket should be created before reconnecting.
Copy link
Contributor

Choose a reason for hiding this comment

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

unspecified is not quite accurate.

See the documentation for mbedtls_ssl_handshake()
https://tls.mbed.org/api/ssl_8h.html#a4a37e497cd08c896870a42b1b618186e

We should reflect that in our documentation. So if this function returns failures other than what we specify, user should stop using the TLS context and free it. We don't support the mbedtls_ssl_session_reset() but maybe we should.

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be hard to reflect, but basically we could try the connect() as long as it is the TCP session that fails the connection.

Basically, if SSL handshake fails, we return NSAPI_ERROR_AUTH_FAILURE and after that, the socket cannot be used anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically, if SSL handshake fails, we return NSAPI_ERROR_AUTH_FAILURE

I noticed we sometimes return PARAMETER_ERROR instead, but I saw no reason to do that and I modified the return value. Please take a look and if you agree with that change, I will amend the test's expectations (the tests documentation just says "must return an error", without specifying the exact error code, so that's fine).
If we always return AUTH_ERROR on ssl-related errors we can safaely tell the users that if they see this error, then they must get a new socket before retrying (which means they don't have to do that if they just want to retry the TCP connection).
Is that ok?

@SeppoTakalo
Copy link
Contributor

Do we actually need to reflect this connect() thing in the main Socket.h?

We seem to allow TCPSocket::connect() to be retried, but that is not necessary always the case. Therefore I propose that we amend the Socket::connect() documentation as well.

@michalpasztamobica michalpasztamobica force-pushed the tlssocket_documentation_update branch from ade5624 to 9bb47d6 Compare January 21, 2019 08:49
@0xc0170
Copy link
Contributor

0xc0170 commented Jan 21, 2019

@michalpasztamobica All reviews addressed (we can see a new commit here)

@michalpasztamobica
Copy link
Contributor Author

I think they are addressed, although I would prefer to see an explicit OK from @SeppoTakalo regarding the error code returns ;-)
I checked - no test code modification are needed because we don't check for a particular error code (as the documentation suggests).

@michalpasztamobica
Copy link
Contributor Author

@0xc0170 , Travis passed and I think that the builds which were failing so far should now pass (as they don't really compile anything any more). Could you trigger the CI, please?

Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

Looks good

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 22, 2019

Ready for CI, please rebase first to resolve conflicts (documentation update was merged recently)

@michalpasztamobica
Copy link
Contributor Author

Rebased and conflicts resolved.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 22, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jan 22, 2019

Test run: FAILED

Summary: 1 of 1 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_unittests

@michalpasztamobica michalpasztamobica force-pushed the tlssocket_documentation_update branch from dbd00f5 to a4ba6aa Compare January 22, 2019 11:09
@michalpasztamobica
Copy link
Contributor Author

Sorry, I checked Icetea tests and greentea tests, but forgot about the unit tests - latest push fixes the expected error return values.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 22, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jan 22, 2019

Test run: FAILED

Summary: 1 of 1 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_unittests

@michalpasztamobica michalpasztamobica force-pushed the tlssocket_documentation_update branch from a4ba6aa to 2cda5d2 Compare January 22, 2019 11:41
@michalpasztamobica
Copy link
Contributor Author

Now the CI pointed out that I should also modify the DTLSSocketWrapper tests. I hope nothing more will come up...

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 22, 2019

CI restarted

@michalpasztamobica
Copy link
Contributor Author

michalpasztamobica commented Jan 22, 2019

I doubt my changes are causing the dynamic-memory-usage failure as I can see the same is happening in @VeijoPesonen 's Pull Request...

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 22, 2019

Yes, test team is investigating.

@mbed-ci
Copy link

mbed-ci commented Jan 22, 2019

Test run: FAILED

Summary: 2 of 11 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_dynamic-memory-usage
  • jenkins-ci/mbed-os-ci_greentea-test

@michalpasztamobica
Copy link
Contributor Author

I can see that 4 out of 5 failing greentea tests are not even related to ipcore.
The error seems to be that the resource NUCLEO_F429ZI wasn't allocated correctly:

[1548175529.18][GLRM]079602210542680C3A06FEA7 - Received response
[1548175529.18][GLRM]079602210542680C3A06FEA7 - 409 Conflict

[1548175532.48][HTST][WRN] stopped to consume events due to __notify_sync_failed event

@0xc0170 , is this something I should worry about?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 23, 2019

CI restarted

@adbridge
Copy link
Contributor

I can't seem to patch this with either git am or git cherry-pick so I am bumping it to 5.12

@michalpasztamobica michalpasztamobica deleted the tlssocket_documentation_update branch January 25, 2019 15:00
@SeppoTakalo
Copy link
Contributor

5.12 is fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants