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

SSL/TLS support #38

Closed
Overtorment opened this issue Apr 5, 2020 · 17 comments · Fixed by #40
Closed

SSL/TLS support #38

Overtorment opened this issue Apr 5, 2020 · 17 comments · Fixed by #40
Labels
feature request New feature or request released

Comments

@Overtorment
Copy link

No description provided.

@Rapsssito Rapsssito added the feature request New feature or request label Apr 6, 2020
@Rapsssito Rapsssito changed the title TLS support? SSL/TLS support Apr 6, 2020
@Rapsssito
Copy link
Owner

@Overtorment, thanks for your feature request. SSL was not planned originally, but I will take a closer look.

I might have to investigate about CocoaAsyncSockets known bugs with SSL. I will update you with any news about this topic.

@Overtorment
Copy link
Author

If this helps, I'm currently using https://github.com/wfilleman/react-native-tcp in production which has TLS for both ios and android, but I don't feel confident in this package. So I'm having hopes for this package to maybe be a superior one 🙏

@Rapsssito
Copy link
Owner

Thanks for the reference, it helps a lot. I will take a look at their implementation and perform some tests.

I'll update ASAP with more information.

@Overtorment
Copy link
Author

Overtorment commented Apr 6, 2020 via email

@Rapsssito
Copy link
Owner

Rapsssito commented Apr 7, 2020

@Overtorment, I have created a development branch for the SSL/TLS support.

If you want to check it out, you can add it to your project with the following command:

yarn add https://github.com/Rapsssito/react-native-tcp-socket#tls

@Overtorment
Copy link
Author

Is there a way to just ignore certificate check? We have a use case of users connecting to their own servers with self-signed certificates, so we don't know them in advance

@Rapsssito

This comment has been minimized.

@Rapsssito
Copy link
Owner

Rapsssito commented Apr 7, 2020

@Overtorment, there is a way to ignore all certificate checks: you must set tlsCheckValidity to false in your createConnection() options. For more info, take a look at the documentation on the tls branch.

Right now, Android and iOS TCP clients are TLS/SSL compatible. Can you test it in your project and report the problems you find? If there are no issues, I will release a new version with the client SSL/TLS support.

@Overtorment
Copy link
Author

Will do!

@Overtorment
Copy link
Author

Overtorment commented Apr 8, 2020

success. tested tls/android. didn't test clearnet tcp and ios.
seems to work okay but there are some issues:

  1. there are no methods setNoDelay, setKeepAlive, setEncoding. I commented them out, but they are available for sockets on all platforms I think.
  2. a bit annoying that lib API does not conform to the one described in nodejs documentation. no big deal but I write isomorphic code and reuse it under RN environment and under nodejs environment. that means I will have to write more workarounds. example: createConnection creates a socket and connects it, while net package exposes sockets and allows you to connect later.
    similar with nodejs tls package: it doesn't allow you to create socket, but creates connection on the spot, but method name is different (tls.connect) and arguments have different names.

PS. cant test IOS atm

@Rapsssito
Copy link
Owner

@Overtorment, glad to hear it worked! I am sorry about those issues.

The methods setNoDelay, setKeepAlive, setEncoding are not implemented yet. I will update the documentation to make it clear.

The react-native-tcp-socket available API changes significantly from node net and tls because I am limited by my free time and native code development. The objective of this library is to provide a React Native API for TCP in both Android and iOS. That is why, right now, I am merging net and tls API's surfaces into one, so it is normal to have some differences.

All the available interface is in the documentation. If you have any questions, feel free to open an issue. I hope this library is good enough to suit your project!

PS: I will change the tlsCheckValidity to rejectUnauthorized to make things easier for you ;)

@Overtorment
Copy link
Author

I think those methods you just need to proxy-call socket object on native system, you don’t need to implement anything.

So are you keeping lib api as is? Just to make sure, if it stays like this - it stays, that’s fine, just to know there won’t be any breaking changes :-)

@Rapsssito
Copy link
Owner

There won't be any breaking changes. I will release the new version in 5 minutes.

About the methods setNoDelay, setKeepAlive and setEncoding, thanks for the tip! I will investigate. As soon as they are implemented, I will release a new version.

@github-actions
Copy link

github-actions bot commented Apr 8, 2020

🎉 This issue has been resolved in version 3.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@piyush2cloud
Copy link

piyush2cloud commented Jan 31, 2022

@Overtorment @Rapsssito

Can u please help me in this. I am trying to create Android TV Remote for IOS.

Like I wan to mimic node(tls.connect) using react native. 

I need to implement a tls connection with Android TV from IOS device to send Remote Commands.

When I send below from IOS device with tls true it throws error 
operation couldn’t be completed. (kcfstreamerrordomainssl error -9807.)
const client = TcpSocket.createConnection({    port: '6467',    host: "Android TV I.P",    **tls**: true});

When I send below with no tls key from IOS device it makes connection but data returned from Android TV is not in proper format. So I was thinking this is because tls is false in below case.
const client = TcpSocket.createConnection({    port: '6467',    host: "Android TV I.P"});

Can u please help me in this. How to make a tls connection in React Nativ from IOS. Any help would be really helpful.

@Rapsssito
Copy link
Owner

@piyush2cloud, if you have a problem, you should create a new issue. However, you could check nodeJS examples or seek help in stackoverflow for this kind of questions.

@punjasin
Copy link

Hi how do i pass private key in client tls do you know how ?
const options = {
// Necessary only if using the client certificate authentication
key: fs.readFileSync('client_private_key.pem'),
cert: fs.readFileSync('client_cert.pem'),
// Necessary only if the server uses the self-signed certificate
ca: fs.readFileSync('server_cert.pem'),
}
this is what I use when I am working on nodejs what do I need to add for this to work in react-native ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants