• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

Socket connection from HTTP to HTTPS

Started by rexxer, 2010.07.21, 20:33:49

Previous topic - Next topic

rexxer

Hi,

I am running my rexx application on z/OS webserver (z/OS USS). The server application is residing on a UNIX server.

I am trying to connect my rexx client application to a SSL enabled server (my server is not SSL enabled).

When I execute my code, I get the following output:

Socket initialized
EBCDIC to ASCII conversion set.
Socket status is: 0 CLIENT Connected Free 1 Used 1
CONNECTION ESTABLISED
IOCTL failed with info 45 EOPNOTSUPP Operation not supported on socket
SOCKET TERMINATED

I have spent a long time searching and trying some things but to no avail. I would really appreciate your help.

Here is the REXX code:

/*rexx*/
/*Rexx program to simulate a HTTP GET operation.*/

rc = 0;

fc = SOCKET('Terminate');

Call !HTTP_Write '<html><head><title>REXX HTTP GET.</title></head>';
Call !HTTP_Write '<body>';

fc = SOCKET('Initialize','CLIENT',2);
parse var fc socket_rc .


if socket_rc <> 0 then
Do;
Call !HTTP_Write 'INITIALIZE failed with return info ' fc '<br />';
Call http_end;
Exit 200;
End;

Call !HTTP_Write 'Socket initialized<br />';

fc = SOCKET('SOCKET',2,'SOCK_STREAM','TCP');
parse var fc socket_rc newsocketid .

if socket_rc <> 0 then
Do;
Call !HTTP_Write 'SOCKET failed with return info ' fc '<br />';
fc = SOCKET('TERMINATE');
Call http_end;
Exit 200;
End;

/* Setup the mainframe TCP/IP to use EBCDIC to ASCII conversion */
fc = SOCKET('Setsockopt',newsocketid,'SOL_SOCKET','SO_ASCII','On');
parse var fc asciirc .

if asciirc <> 0 then
Do;
Call !HTTP_Write 'EBCDIC to ASCII conversion failed with<br />';
Call !HTTP_Write 'rc = ' fc '<br />';
Call SHUTDOWN_LABEL;
Call http_end;
Exit 200;
End;

Call !HTTP_Write 'EBCDIC to ASCII conversion set.<br />';

fc = SOCKET('Socketsetstatus','CLIENT');
Call !HTTP_Write 'Socket status is: ' fc '<br />';

CR = D2C(13);
lf = '25'x;
cr = '0d'x;

httpreq="GET" url "HTTP/1.0"||cr||lf ,
"Accept: text/plain, text/html, text/*"||cr||lf||cr||lf;

fc = SOCKET('CONNECT',newsocketid,'AF_INET' 443 XX.XX.X.XX);
parse var fc connect_rc rest

if connect_rc <> 0 then
Do;
Call !HTTP_Write 'CONNECT failed with return info ' fc '<br />';
rc = 99;
Call SHUTDOWN_LABEL;
Call http_end;
Exit 200;
End;

Call !HTTP_Write 'CONNECTION ESTABLISED <br />';

fc = SOCKET('IOCTL',newsocketid,'SIOCTTLSCTL','INITCONNECTION');

if ioctlrc <> 0 then
Do;
Call !HTTP_Write 'IOCTL failed with info ' fc '<br />';
Call SHUTDOWN_LABEL;
Call http_end;
Exit 200;
End;

Call !HTTP_Write 'Sending string: ' httpreq '<br />';

fc = SOCKET('Write',newsocketid,httpreq);
parse var fc send_rc num_sent_bytes

if send_rc <> 0 then
Do;
Call !HTTP_Write 'WRITE failed with return info ' fc '<br />';
rc = 99;
Call SHUTDOWN_LABEL;
Call http_end;
Exit 200;
End;

received_string = read_from_socket();


Call !HTTP_Write 'Received string: <br />' received_string '<br />';
Call SHUTDOWN_LABEL;
Call http_end;

Return 200;

/*SHUTDOWN_LABEL
Call this function to close the socket.*/

SHUTDOWN_LABEL:

fc = SOCKET('CLOSE',newsocketid);
parse var fc close_rc rest

if close_rc <> 0 then
Do;
Call !HTTP_Write 'CLOSE failed with return info ' fc '<br />';
fc = SOCKET('TERMINATE');
End;

Call !HTTP_Write 'SOCKET TERMINATED <br />';

return;

/*read_from_socket
Call this function to read from socket.*/
read_from_socket:

Response = '';

fc =  Socket('Recv',newsocketid,10000);
parse var fc s_rc s_type s_port s_ip s_results
parse var fc s_rc s_data_len s_data_text

if s_rc <> 0 then
Do;
Call !HTTP_Write 'Receive failed. fc = ' fc '<br />';
Call http_end;
Exit 200;
End;

Response = translate(s_data_text,'   ',x2c('0D1525'));
Response = '<XMP>'||Response||'</XMP>';

Return Response;

/*http_end
Function to end the html tags.*/
http_end:

Call !HTTP_Write '</body></html>';
Return;

/*!HTTP_Write
Call the HTTP Write service*/

!HTTP_Write:
  Parse arg pout
  ADDRESS LINKMVS 'IMWXWRT pout'
Return;

IBManners

Hi,

Do you have an SSL client library rexx can call as rexx needs a method to connect on port 443 to establish the secure handshake and connection. I have no idea if a REXX SSL client lib is available for z/OS, your probably better off asking this question in the IBM non OS/2 newsgroups.

Cheers
I am the computer, it is me.

RobertM

Agreed with IBManners. Though I am guessing one could write an SSL module for/in REXX, it would be a daunting task. I, for instance, once wrote http, newsgroup and ftp clients and daemons for OS/2 in strictly REXX code relying on the REXX Sockets API - and that was with the help of some sample IBM code from "ages ago" to use as base templates. It was not fun, not in the least. Finding a DLL to do the job made life much easier. Thus, on OS/2, it is offloaded to various support DLLs (depending on user choice and need).

Also, I seem to recall that z/OS (or maybe it's predecessors - and possibly dependant on particular hardware) had an OS/2 subsystem, but am unsure if it is solely to run certain hardware components or if it's also usable by the programmer/end user.

You may wish to find the maintainer of one of the REXX SSL packages and see if the source code could be made available for recompile/modification to run under z/OS.

Best,
Robert


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|