SSLOn (Socket function)

From m204wiki
Revision as of 18:37, 11 June 2012 by JAL2 (talk | contribs)
Jump to navigation Jump to search

Turn on SSL processing (Socket class)

This callable method turns on SSL processing, that is, starts an SSL handshake as a client on a connection. SSLOn has an effect similar to $Sock_Ssl_On.

Syntax

[%number =] socket:SSLOn

Syntax terms

%number This is a numeric variable to contain the returned indicator of success of the function. The possible return values are listed in "Return codes" below.
socket A variable or an expression that is a reference to a Socket object.

Return codes

The method's return value (%number) is one of these:

  0 Successfully switched to SSL.
-110 Attempted on non-SSL port. SSLOn can only be attempted on a port with SSL and SSLOPT on the JANUS DEFINE command.
-111 SSL handshake error. Likely result of trying to use the SSLOn method against a non-SSL port.
-112 Have pending incoming data. The SSLOn method is invalid until all incoming (presumably) non-SSL data has been received.
-149 Other error during connection.

Usage notes

  • SSLOn makes it possible to:
    1. Make an initial connection from a Janus Sockets client application to a proxy server
    2. Issue the HTTP CONNECT method/command to connect to a server through the proxy
    3. Communicate via SSL with the back end server, simply having the proxy server act as a "tunnel" for the SSL data

    As shown in "Examples" below, the SSLOn method should be used after a positive response has been received for a CONNECT method request on a Janus Sockets client socket.

Examples

The following code shows the use of the SSLOn method;

%sock is Object Socket %sock = New('WEBDROPS', 'proxy') %r = %sock:Set('LINEND', '0D0A') %r = %sock:Set('PRSTOK', '0D0A') %r = %sock:Send('CONNECT ') %r = %sock:Send('sirius-software.com:443') %r = %sock:SendWithLineEnd(' HTTP/1.0') %r = %sock:SendWithLineEnd() %r = %sock:ReceiveAndParse(%s) If $WORD(%s, , 2) Ne '200' Then Call CONNECT_ERROR End If Repeat Forever %r = %sock:ReceiveAndParse(%s) If $LSTR_LEN(%s) Eq 0 Then Loop End End If End Repeat %r = %sock:SSLOn If %r Then Call SSL_ERROR End If %r = %sock:Send('GET ') %r = %sock:Send(%URL) %r = %sock:SendWithLineEnd(' HTTP/1.0') %r = %sock:SendWithLineEnd() ...

For more information about HTTP tunneling and the CONNECT method, see http://www.ietf.org/rfc/rfc2817.txt. Many other references are also available on the web.

See also