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

select() support - tlsrecordlayer fileno() is not supported, required when integrating with hyper http2 client #414

Open
martyur opened this issue Jun 12, 2020 · 9 comments
Labels
complex Issues that require good knowledge of tlslite-ng internals or cryptography enhancement new feature to be implemented

Comments

@martyur
Copy link

martyur commented Jun 12, 2020

Hi,
When integrating tlslite to work with hyper http2 client we ran into an exception when sending a request.

socket.can_read calls select.select() which needs fileno ,but it's not supported according to https://github.com/tomato42/tlslite-ng/blob/09f55888603c847a0ff68f82b69f29d48c78da69/tlslite/tlsrecordlayer.py#L654 .

If can_read is removed from hyper, then a successful request can be made ,but likely to be unstable and hang sometimes according to the developer of hyper.
Fileno might not be required ,but some kind of way to check 'can_read' is needed for this to work.
Any help would be greatly appreciated

@martyur
Copy link
Author

martyur commented Jun 12, 2020

@property
    def can_read(self):
        """
        Whether or not there is more data to read from the socket.
        """
        read = select.select([self._sck], [], [], 0)[0]
        if read:
            return True

        return False

@tomato42
Copy link
Member

you can try extracting the fileno of the wrapped socket (self.sock.fileno) but that has chance of working only when read() would block

@martyur
Copy link
Author

martyur commented Jun 13, 2020

@tomato42 is this right, so read only blocks until bytes are received via the socket so if select.select is called on self.sock.fileno before any bytes have been received then this might work ?

@tomato42
Copy link
Member

tomato42 commented Jun 13, 2020

more or less, what I'm referring to is that inside tlslite-ng are 2 levels of buffering, one on record level and another on handshake/alert message processing level; if they are not cleared first (and by clear I mean "no data can be extracted from them", not "empty"; e.g. record layer buffering returns only full records to layers above in stack) then select() will block even if a read from the TLSConnection wouldn't block

@martyur
Copy link
Author

martyur commented Jun 13, 2020

that doesn't sound ideal, i would imagine this would also be a problem if we tried to integrate it to some other http clients that don't expect such a big abstraction layer that tls lite has.
The way i see it an alternative is needed in tlslite which could be used to replace select([sock]..) that outputs the same result while dealing with the tls lite abstraction, but I'm not familiar enough with this to be able to implement it.

@tomato42 tomato42 changed the title tlsrecordlayer fileno() is not supported, required when integrating with hyper http2 client select() support - tlsrecordlayer fileno() is not supported, required when integrating with hyper http2 client Jun 13, 2020
@tomato42 tomato42 added complex Issues that require good knowledge of tlslite-ng internals or cryptography enhancement new feature to be implemented labels Jun 13, 2020
@tomato42 tomato42 added this to the someday/future milestone Jun 13, 2020
@martyur
Copy link
Author

martyur commented Jun 13, 2020

@tomato42 Could you please contact me via email [email protected] , I would like to get in touch for a quick chat if you don't mind.

@tomato42
Copy link
Member

this isn't something I need tlslite-ng for so I won't work on this, at most I can offer reviewing pull requests

@HMaker
Copy link

HMaker commented Mar 18, 2022

I have integrated TLSLite to asyncio and had no issues, you need to implement an async driver for tlslite, pass to it a non blocking socket and handle the "want read" and "want write" signals from its generator coroutines.

@LennertW
Copy link

@HMaker any chance you could share an example of how you did that? I would like to use tlslite-ng with grpclib (https://github.com/vmagamedov/grpclib).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complex Issues that require good knowledge of tlslite-ng internals or cryptography enhancement new feature to be implemented
Projects
None yet
Development

No branches or pull requests

4 participants