123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <iodef.h> /* VMS IO$_ definitions */
- #include <descrip.h> /* VMS string descriptors */
- extern int SYS$QIOW(), SYS$ASSIGN();
- int LIB$INIT_TIMER(), LIB$SHOW_TIMER();
- #include <string.h> /* from ssltest.c */
- #include <errno.h>
- #include "e_os.h"
- #include <openssl/buffer.h>
- #include <openssl/x509.h>
- #include <openssl/ssl.h>
- #include <openssl/err.h>
- int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
- int error);
- BIO *bio_err = NULL;
- BIO *bio_stdout = NULL;
- BIO_METHOD *BIO_s_rtcp();
- static char *cipher = NULL;
- int verbose = 1;
- #ifdef FIONBIO
- static int s_nbio = 0;
- #endif
- #define TEST_SERVER_CERT "SSL_SERVER_CERTIFICATE"
- struct rpc_msg {
-
- char channel;
-
- char function;
-
- unsigned short int length;
-
- char data[4092];
- };
- #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
- static $DESCRIPTOR(sysnet, "SYS$NET");
- typedef unsigned short io_channel;
- struct io_status {
- unsigned short status;
- unsigned short count;
- unsigned long stsval;
- };
- int doit(io_channel chan, SSL_CTX *s_ctx);
- static int get(io_channel chan, char *buffer, int maxlen, int *length)
- {
- int status;
- struct io_status iosb;
- status = SYS$QIOW(0, chan, IO$_READVBLK, &iosb, 0, 0,
- buffer, maxlen, 0, 0, 0, 0);
- if ((status & 1) == 1)
- status = iosb.status;
- if ((status & 1) == 1)
- *length = iosb.count;
- return status;
- }
- static int put(io_channel chan, char *buffer, int length)
- {
- int status;
- struct io_status iosb;
- status = SYS$QIOW(0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
- buffer, length, 0, 0, 0, 0);
- if ((status & 1) == 1)
- status = iosb.status;
- return status;
- }
- static int general_request(io_channel chan, struct rpc_msg *msg, int length)
- {
- return 48;
- }
- int main(int argc, char **argv)
- {
- int status, length;
- io_channel chan;
- struct rpc_msg msg;
- char *CApath = NULL, *CAfile = NULL;
- int badop = 0;
- int ret = 1;
- int client_auth = 0;
- int server_auth = 0;
- SSL_CTX *s_ctx = NULL;
-
- LIB$INIT_TIMER();
- status = SYS$ASSIGN(&sysnet, &chan, 0, 0, 0);
- printf("status of assign to SYS$NET: %d\n", status);
-
- if (bio_err == NULL)
- if ((bio_err = BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_err, stderr, BIO_NOCLOSE);
- if (bio_stdout == NULL)
- if ((bio_stdout = BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_stdout, stdout, BIO_NOCLOSE);
-
- if (cipher == NULL)
- cipher = getenv("SSL_CIPHER");
- printf("cipher list: %s\n", cipher ? cipher : "{undefined}");
- SSL_load_error_strings();
- OpenSSL_add_all_algorithms();
-
- s_ctx = SSL_CTX_new(SSLv2_server_method());
- if (s_ctx == NULL)
- goto end;
- SSL_CTX_use_certificate_file(s_ctx, TEST_SERVER_CERT, SSL_FILETYPE_PEM);
- SSL_CTX_use_RSAPrivateKey_file(s_ctx, TEST_SERVER_CERT, SSL_FILETYPE_PEM);
- printf("Loaded server certificate: '%s'\n", TEST_SERVER_CERT);
-
- LIB$SHOW_TIMER();
- status = doit(chan, s_ctx);
- LIB$SHOW_TIMER();
-
- end:
- if (s_ctx != NULL)
- SSL_CTX_free(s_ctx);
- LIB$SHOW_TIMER();
- return 1;
- }
- int doit(io_channel chan, SSL_CTX *s_ctx)
- {
- int status, length, link_state;
- struct rpc_msg msg;
- SSL *s_ssl = NULL;
- BIO *c_to_s = NULL;
- BIO *s_to_c = NULL;
- BIO *c_bio = NULL;
- BIO *s_bio = NULL;
- int i;
- int done = 0;
- s_ssl = SSL_new(s_ctx);
- if (s_ssl == NULL)
- goto err;
- c_to_s = BIO_new(BIO_s_rtcp());
- s_to_c = BIO_new(BIO_s_rtcp());
- if ((s_to_c == NULL) || (c_to_s == NULL))
- goto err;
- BIO_set_fd(c_to_s, 0, chan);
- BIO_set_fd(s_to_c, 0, chan);
- c_bio = BIO_new(BIO_f_ssl());
- s_bio = BIO_new(BIO_f_ssl());
- if ((c_bio == NULL) || (s_bio == NULL))
- goto err;
- SSL_set_accept_state(s_ssl);
- SSL_set_bio(s_ssl, c_to_s, s_to_c);
- BIO_set_ssl(s_bio, s_ssl, BIO_CLOSE);
-
- printf("Begin doit main loop\n");
-
- for (link_state = 0; link_state < 3;) {
-
- while (link_state == 0) {
- status = get(chan, (char *)&msg, sizeof(msg), &length);
- if ((status & 1) == 0) {
- printf("Error in main loop get: %d\n", status);
- link_state = 3;
- break;
- }
- if (length < RPC_HDR_SIZE) {
- printf("Error in main loop get size: %d\n", length);
- break;
- link_state = 3;
- }
- if (msg.channel != 'A') {
- printf("Error in main loop, unexpected channel: %c\n",
- msg.channel);
- break;
- link_state = 3;
- }
- if (msg.function == 'G') {
- link_state = 1;
- } else if (msg.function == 'P') {
- link_state = 2;
- } else if (msg.function == 'X') {
- link_state = 3;
- } else {
- link_state = 3;
- }
- }
- if (link_state == 1) {
- i = BIO_read(s_bio, msg.data, msg.length);
- if (i < 0)
- link_state = 3;
- else {
- msg.channel = 'A';
- msg.function = 'C';
- msg.length = i;
- status = put(chan, (char *)&msg, i + RPC_HDR_SIZE);
- if ((status & 1) == 0)
- break;
- link_state = 0;
- }
- } else if (link_state == 2) {
- i = BIO_write(s_bio, msg.data, msg.length);
- if (i < 0)
- link_state = 3;
- else {
- msg.channel = 'A';
- msg.function = 'C';
- msg.length = 0;
- status = put(chan, (char *)&msg, RPC_HDR_SIZE);
- if ((status & 1) == 0)
- break;
- link_state = 0;
- }
- }
- }
- fprintf(stdout, "DONE\n");
- err:
-
- s_ssl->rbio = NULL;
- s_ssl->wbio = NULL;
- if (c_to_s != NULL)
- BIO_free(c_to_s);
- if (s_to_c != NULL)
- BIO_free(s_to_c);
- if (c_bio != NULL)
- BIO_free(c_bio);
- if (s_bio != NULL)
- BIO_free(s_bio);
- return (0);
- }
|