Using Javascript to connect with server using protocol other than HTTP - javascript

Can Javascript be used to connect with a server with a protocol other than HTTP or FILE? Ideally, I would like to connect to an SMTP server using Javascript.

Not possible due to security constraints in the browser. Can be done in flash or java as far as I know. The upcoming WebSockets won't help you either.
Your best option is probably to call a script on your server which makes the socket connections to the final destination, i.e the SMTP server and then passes data back to the client over HTTP.

You do not have socket access with browser-integrated JavaScript, it would violate the sandbox security model. So no, no SMTP, or any other protocol. Even file:// should be rather difficult.
Server based JavaScript like node.js can do things like this.
Accessing e.g. SMTP via the browser is usually done through a proxy script that runs on the server and speaks HTTP to the client.

Related

Validate WebSocket data

I have a WebSocket server written in javascript and send data to it from my CSharp application. Now how can I make sure that these are correct? I thought I could do something with hash values but I don't know how to do that. Does anyone have an idea or code example?
The first thing to understand is the types of WebSocket protocol/transports. WebSocket ws:// transport is basically unusable in terms of security as it uses HTTP. The wss:// protocol establishes a secure connection over TCP/HTTPS. The wss protocol, therefore, protects against man-in-the-middle attacks.
There is multiple methods to authenticate a user when setting up a WebSocket connection, and none are perfect. Since the standard WebSocket usage prevents additional headers from being set such as custom authentication headers, tried and true methods that would be used in a standard HTTPS request to verify the validity of a client can't be used.
The link here outlines some common methods to keep the client and server in sync while setting up a WebSocket connection, and still add some security so the server can keep track of what clients are opening WebSocket connections. There are a lot of workarounds listed for the server to safely receive sensitive, authentication data from the client.

WebSocket to Ldap

I am trying to etablish a websocket connection to an ldap server. That I can simply send binary data to and receive binary data.
But it fails on the handshake whatever I do.
var socket = new WebSocket("ws://ads.de:PORT")
Yours sincerely
Skeec
Web sockets is a specific protocol, like HTTP, and it has "nothing" to do with a TCP/UPD socket.
You cannot connect with web-sockets to an LDAP-server, let alone connect to a different domain without receiving the appropriate CORS http-headers (and the browser supporting CORS).
You need to write a proxy WebSocket server application so that you can communicate with the LDAP-directory. You cannot do it in JavaScript (unless you want to use an ActiveX object, which will be incompatible with non-Microsoft browsers (and newer Microsoft browsers).
You better do it with plain-old AJAX with an asynchronous handler.
You don't need WebSockets for that, you're only wasting bandwidth.

how to send a message from client web page to 0mq server

Is it possible to send directly message from JavaScript in client browser to 0mq?
If not in JavaScript, then I should use Flash or setup some http proxy server?
0mq is not meant for Internet facing ports. There is a project called nullmq which does what you want though by translating from web protocols to zmq behind the firewall, while retaining zeromq like api on the browser.
I suspect it would be easiest to have your client browser make an XMLHttpRequest() to your web application and then have your web application talk to your 0MQ infrastructure.
There is a javascript/flash binding for 0MQ, but I've never worked with it myself so I can't comment on stability or anything.
If you tell us more about what you're trying to accomplish we might be able to suggest viable alternatives.
You can use websockets on the client-side if you want a persistent connection and use a websocket server like tornado or socket.io to relay the messages to zmq and back.

JavaScript Socket connection to port 43 (whois)

I have a problem I want to use socket to connect to whois servers through port 43, but it seems it's not possible or I'm doing it wrong. I've tested socketio and jsXMLsocket, but no luck.
With PHP is easy to do it by using fsockopen('whois.crsnit.net',43);
Then fputs with domain name and fgets to retrieve the result from the whois server.
But I want the whois lookup to be possible at browser side, so that the server is not that much under load.
Is it possible to do it? If so, can you include some code snippet?
Thanks.
JavaScript can only send HTTP requests and make WebSocket connections. If you can run a small server, you could use a server-side WebSocket-to-TCP proxy using websockify.
It's also possible to use Flash or a trusted Java applet for this, but JavaScript alone can't do it. Sorry.
jsXMLsocket use a swf (flash) file in background for open a socket connection. Unfortunately, for security reasons, in Flash Player 9.0 and later, the target host must serve a socket policy file. No policy file, no connection.

Is it possible to connect to SSH using JavaScript?

I know there is an implementation of VNC using WebSockets (http://novnc.com) but that still requires a server. I am looking to create a simple client-side JavaScript only (no Flash) connection to a port running SSH. I am guessing WebSockets is the only way to go since it does TCP. Any example code? Any other way?
Sorry, given your constraints (client-side Javascript only), there is no way to connect to a plain old SSH server.
WebSockets is not plain TCP. It's a framed protocol with a HTTP-like handshake between the client and server that includes origin policy.
Flash can make plain TCP connections, but it also has origin policy enforcement. The way it does this is by making a connection to the same server on port 843 and asking for a special XML file that contains the origin policy.
If you are willing to relax your constraints slightly such that you are willing to run a generic WebSockets to TCP proxy either on a server (any server) or on the client then you can do what you are wanting to do. noVNC includes a C and python WebSockets to TCP proxy: http://github.com/kanaka/noVNC/tree/master/utils/.
Other info you might find useful:
Current WebSocket draft: https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76
Simple (insecure) way of running a flash policy server (Linux/UNIX with socat) is described here: http://github.com/kanaka/noVNC/blob/master/docs/flash_policy.txt
More info about the flash policy file: http://code.google.com/p/doctype/wiki/ArticleFlashSecurity
You can take a look at serfish. It's a solution to access a SSH server. But if you're hosting your web application on the same server as your ssh, there are other solutions such as shell in a box.
For those still searching, paramikojs could be the answer.
I'm currently having a similar issue:I need a SSH JS client-side implementation, and I need it to be BSD licensed. Alas paramikojs seems to be GPL licensed.
It's definitely possible using a Linux emulator with full network support like the great OpenRISC emulator jor1k.
Note that I've created browser-tools.net, a collection of in-browser tools from number of different projects.
Yes you can
Install SSH server on your server
Write a server side program (could be in PHP) that uses SSH
client in the background
Redirect messages between the SSH client (that probably has been residing in the same server as SSH server) and the JavaScript program in the web browser other side of the internet.
That server side program acts like a postman only and the java script program in the browser is just another postman between the user and server program.
(SSH server)<->(SSH client)<->(PHP e.g)<->(JavaScript)
Also don't forget that in the JavaScript program could have use Ajax for better mechanism. Also SSH client might be not completely and absolutely necessary because that PHP server side program could directly connect to SSH server

Categories