How to connect to a heroku rendezvous url from a tcp socket? - sockets

I am creating a new on-off dyno with the Heroku Platform API and getting back an url with the format rendezvous://rendezvous.runtime.heroku.com:5000/{rendezvous-id}.
Now I want to establish a connection to this url with the chrome.socket.tcp API.
chrome.sockets.tcp.create({}, function(createInfo) {
chrome.sockets.tcp.connect(createInfo.socketId, IP, PORT, onConnectedCallback);
});
where IP is 'rendezvous.runtime.heroku.com' and PORT is 5000, but how could i specify the rendezvous-id or do I need to do this?
I found a Ruby implementation of this: https://github.com/heroku/heroku/blob/master/lib/heroku/client/rendezvous.rb
Is it possible to do this in a chrome app?
Edit
I read the Ruby implementation. It uses a ssl_socket instance from a OpenSSL library and then just sends the rendezvous-id. Can I just use chrome.socket.tcp.secure to get an openssl secure socket?

Related

How do I open a secure WSS websocket in KDB?

I'm trying to figure out how to connect to a data feed.
The data feed is at
wss: ":wss://stream.data.alpaca.markets/v2/iex"
.z.ws:{0N!x;}
r:(`$wss)""
I have set up TLS in KDB and can access https endpoints just fine. This says OS reports: No route to host.
The documentation refers to using stunnel, but doesn't clarify whether that's for securing KDB as a server (which is what stunnel looks like it's mainly for), or decrypting a feed as a client.
https://code.kx.com/q/kb/websockets/#simple-websocket-client-example
What am I doing wrong?
Stunnel can be used to encrypt or decrypt any TCP SSL connection, including websockets.
To get KDB to connect to a secure websocket, you need to use stunnel in client mode.
This is the config that worked for me. You can then open the decrypted websocket on your localhost at ws://localhost:80
foreground = yes
debug = 7
[alpaca websocket]
accept = 80
client = yes
connect = stream.data.alpaca.markets:443
CApath = /etc/ssl/certs/
checkHost = stream.data.alpaca.markets
OCSPaia = no
verifyChain=yes

How to change port of Dart HTTP request?

I'm writing a Flutter application which involves getting some data from an HTTP server. Here's my code:
// the local IP of my testing server
final String SERVER = 'http://192.168.1.13:5000';
class Database {
Future<String> _getJob(int jobID) async {
var response = http.get('$SERVER?jobID=$jobID');
return response.body;
}
}
Currently this is the output:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception:
SocketException: OS Error: Connection refused, errno = 111, address =
192.168.1.13, port = 41966
Obviously this is happening because there isn't anything on port 41966, but the request shouldn't be going to that port, it should be going to port 5000. Is there a different way of specifying the port?
(my async code probably isn't very good, i'm going to work on it once i've figured this out)
Please specify which platform (Web, iOS, Android, Windows, Linux, mac, Flutter is amazing 😅) you're using. Its probably because Android/ iOS do not allow HTTP connections as they can be read by others on the same network. You need to use HTTPS.
I think for debugging, its better if you just called an API that already exists. Pick one from here: https://apilist.fun/ Then in the future, you can figure out how to get a TLS/SSL certificate assigned to your server (e.g. Using LetsEncrypt)
Alternatively you can go into the configuration of your application (platform specific config) to allow insecure connections (HTTP). For example, on Android and on iOS. However, Android and iOS default to this to make sure you consider security, not just send your data in plain text.
Note: its not actually because the server doesn't exist or the port is wrong. If the server didn't exist, it would say something like connection timed out or server unreachable. In your case, your OS/ platform immediately tells you OS Error: Connection refused, because it can see you're using HTTP.
I had the same issue.
Try using ngrok or a similar proxy. I think the dart HTTP client picks a random port when the host is not resolvable.
If you are pushing to an mobile device for testing your app, there is probably no reason a local IP address will be resolved.

Paw returns wrong web page compared to browsers

The requests appear to be sent to the wrong host (not entirely sure which host they're being sent to as that response can be sent by 4 different servers).
Chrome returns the right JSON response:
Paw's NSURLConnection library too :
But the default Paw HTTP Library returns a 404 Not Found :
You have actually 2 local servers listening on port 8000, one listens only IPv6 connections (note: it's the default for PHP apps) and another one listening for IPv4 connections.
When you connect to "localhost" you don't specify which IP protocol you want to use, and it sounds like most clients (including Chrome, ASIHTTPRequest and NSURLConnection in Paw) choose to connect to the IPv6 first. Whereas the Paw HTTP Library chooses to connect to IPv4 (we made that choice as IPv4 is still widely used, and wanted to avoid bugs as much as possible).
So when you run your main web app specifying localhost:8000 the server (PHP in your case) actually listens to [::1]:8000 (which is the IPv6 equivalent to 127.0.0.1:8000), and I guess your other server listens to the actual IPv4 127.0.0.1:8000. Chrome and the other libraries connect to [::1]:8000 (IPv6) and get your main PHP application, whereas "Paw HTTP Library" connect to 127.0.0.1:8000 (IPv4) that hits your other server, which returns the 404 we can see in the video.
What you need to do is to specify the actual IP instead of localhost. Use http://[::1]:8000/plans to connect to your main app that listens for IPv6.

send data between two server sockets

I have to make an app using C/PHP sockets on linux that sends data from one socket to other socket, like this.
I have server (server_hosted) hosted somewhere with an IP or domain name. It is running web application.
I have another server (unknown_server) running at my home (unknown IP).
Client send some information through web application hosted in server_hosted to another server running at my home (unknown IP).
I need a way to established a connection between server_hosted and unknown_server.
I was able to make connection between both using TCP socket. I made server_hosted as server listen to certain port says 8080 and unknown_server as client, which make open connection to server_hosted.
The problem comes when I have multiple unknown_server at my home. How can I made connection to same port? How many client can TCP/IP support?
Any ides how to make tunnel or connection between server_hosted and unknown_server.
Is possible to do with curl or socket any better ideas?

How to programmatically set up a ssh tunnel on iPhone to access remote service?

I am developing an iPhone application which is communicating with a remote service over a tcp socket connection (the service actually listens on telnet and takes telnet commands too). The connection is of course insecure and all requests (with quite a bit of sensitive data, such as passwords) and responses are transmitted as plain text. My first reaction was to consider a web service with ssl, but developing a web service from scratch seems too lengthy.
Because of that I have been thinking of using an ssh tunnel in order to secure the traffic. Is it possible to set up an ssh tunnel in an iPhone application (with libssh2 for example) and then use that tunnel to securely connect to the remote service? If so, how should I set up the tunnel and most importantly, how should I connect to the remote service and give commands/receive responses? Lastly, what should I keep in mind regarding the tunnel?
EDIT: I forgot to mention that the server running the service is using Windows. SSH is achieved via Cygwin.
I am sorry if the question is too basic but this is really my first real brush with ssh.
I think you may have more security issues by using an ssh tunnel because there isn't a secure way to tie down the authentication information in the app and well, if someone can get that login information they could conceivably connect to your ssh session and start trying to issue arbitrary commands. Of course there are ways to lock down an ssh session, but still, I'd be very wary of that. At least with a web service, it acts as a "broker" between the iPhone app and the telnet session so you can add an extra layer of protection.