diff options
author | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 11:00:56 +0000 |
---|---|---|
committer | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 11:00:56 +0000 |
commit | 31b8d8684441e6cd5138832bb1b2ddb10acd6ba6 (patch) | |
tree | bd2486e342980b19b92cff888ae6206d906a089d /demos | |
parent | 7dfb0b774e6592dcbfe47015168a0ac8b44e2a17 (diff) | |
parent | dfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c (diff) |
This commit was generated by cvs2svn to track changes on a CVS vendor
branch.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/bio/sconnect.c | 2 | ||||
-rw-r--r-- | demos/eay/base64.c | 49 | ||||
-rw-r--r-- | demos/eay/conn.c | 105 | ||||
-rw-r--r-- | demos/eay/loadrsa.c | 53 |
4 files changed, 208 insertions, 1 deletions
diff --git a/demos/bio/sconnect.c b/demos/bio/sconnect.c index 8a667f5911..68296da806 100644 --- a/demos/bio/sconnect.c +++ b/demos/bio/sconnect.c @@ -48,7 +48,7 @@ char *argv[]; /* Lets use a connect BIO under the SSL BIO */ out=BIO_new(BIO_s_connect()); - BIO_set_hostname(out,host); + BIO_set_conn_hostname(out,host); BIO_set_nbio(out,1); out=BIO_push(ssl_bio,out); diff --git a/demos/eay/base64.c b/demos/eay/base64.c new file mode 100644 index 0000000000..de080f617a --- /dev/null +++ b/demos/eay/base64.c @@ -0,0 +1,49 @@ +/* This is a simple example of using the base64 BIO to a memory BIO and then + * getting the data. + */ +#include <stdio.h> +#include "bio.h" +#include "evp.h" + +main() + { + int i; + BIO *mbio,*b64bio,*bio; + char buf[512]; + char *p; + + mbio=BIO_new(BIO_s_mem()); + b64bio=BIO_new(BIO_f_base64()); + + bio=BIO_push(b64bio,mbio); + /* We now have bio pointing at b64->mem, the base64 bio encodes on + * write and decodes on read */ + + for (;;) + { + i=fread(buf,1,512,stdin); + if (i <= 0) break; + BIO_write(bio,buf,i); + } + /* We need to 'flush' things to push out the encoding of the + * last few bytes. There is special encoding if it is not a + * multiple of 3 + */ + BIO_flush(bio); + + printf("We have %d bytes available\n",BIO_pending(mbio)); + + /* We will now get a pointer to the data and the number of elements. */ + /* hmm... this one was not defined by a macro in bio.h, it will be for + * 0.9.1. The other option is too just read from the memory bio. + */ + i=(int)BIO_ctrl(mbio,BIO_CTRL_INFO,0,(char *)&p); + + printf("%d\n",i); + fwrite("---\n",1,4,stdout); + fwrite(p,1,i,stdout); + fwrite("---\n",1,4,stdout); + + /* This call will walk the chain freeing all the BIOs */ + BIO_free_all(bio); + } diff --git a/demos/eay/conn.c b/demos/eay/conn.c new file mode 100644 index 0000000000..f44fc7f536 --- /dev/null +++ b/demos/eay/conn.c @@ -0,0 +1,105 @@ +/* NOCW */ +/* demos/eay/conn.c */ + +/* A minimal program to connect to a port using the sock4a protocol. + * + * cc -I../../include conn.c -L../.. -lcrypto + */ +#include <stdio.h> +#include <stdlib.h> +#include "err.h" +#include "bio.h" +#include "proxy.h" + +extern int errno; + +int main(argc,argv) +int argc; +char *argv[]; + { + PROXY *pxy; + char *host; + char buf[1024*10],*p; + BIO *bio; + int i,len,off,ret=1; + + if (argc <= 1) + host="localhost:4433"; + else + host=argv[1]; + + /* Lets get nice error messages */ + ERR_load_crypto_strings(); + + /* First, configure proxy settings */ + pxy=PROXY_new(); + PROXY_add_server(pxy,PROXY_PROTOCOL_SOCKS,"gromit:1080"); + + bio=BIO_new(BIO_s_socks4a_connect()); + + BIO_set_conn_hostname(bio,host); + BIO_set_proxies(bio,pxy); + BIO_set_socks_userid(bio,"eay"); + BIO_set_nbio(bio,1); + + p="GET / HTTP/1.0\r\n\r\n"; + len=strlen(p); + + off=0; + for (;;) + { + i=BIO_write(bio,&(p[off]),len); + if (i <= 0) + { + if (BIO_should_retry(bio)) + { + fprintf(stderr,"write DELAY\n"); + sleep(1); + continue; + } + else + { + goto err; + } + } + off+=i; + len-=i; + if (len <= 0) break; + } + + for (;;) + { + i=BIO_read(bio,buf,sizeof(buf)); + if (i == 0) break; + if (i < 0) + { + if (BIO_should_retry(bio)) + { + fprintf(stderr,"read DELAY\n"); + sleep(1); + continue; + } + goto err; + } + fwrite(buf,1,i,stdout); + } + + ret=1; + + if (0) + { +err: + if (ERR_peek_error() == 0) /* system call error */ + { + fprintf(stderr,"errno=%d ",errno); + perror("error"); + } + else + ERR_print_errors_fp(stderr); + } + BIO_free_all(bio); + if (pxy != NULL) PROXY_free(pxy); + exit(!ret); + return(ret); + } + diff --git a/demos/eay/loadrsa.c b/demos/eay/loadrsa.c new file mode 100644 index 0000000000..91e62d74fe --- /dev/null +++ b/demos/eay/loadrsa.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include "rsa.h" + +/* This is a simple program to generate an RSA private key. It then + * saves both the public and private key into a char array, then + * re-reads them. It saves them as DER encoded binary data. + */ + +void callback(stage,count,arg) +int stage,count; +char *arg; + { + FILE *out; + + out=(FILE *)arg; + fprintf(out,"%d",stage); + if (stage == 3) + fprintf(out,"\n"); + fflush(out); + } + +main() + { + RSA *rsa,*pub_rsa,*priv_rsa; + int len; + unsigned char buf[1024],*p; + + rsa=RSA_generate_key(512,RSA_F4,callback,(char *)stdout); + + p=buf; + + /* Save the public key into buffer, we know it will be big enough + * but we should really check how much space we need by calling the + * i2d functions with a NULL second parameter */ + len=i2d_RSAPublicKey(rsa,&p); + len+=i2d_RSAPrivateKey(rsa,&p); + + printf("The public and private key are now both in a char array\n"); + printf("and are taking up %d bytes\n",len); + + RSA_free(rsa); + + p=buf; + pub_rsa=d2i_RSAPublicKey(NULL,&p,(long)len); + len-=(p-buf); + priv_rsa=d2i_RSAPrivateKey(NULL,&p,(long)len); + + if ((pub_rsa == NULL) || (priv_rsa == NULL)) + ERR_print_errors_fp(stderr); + + RSA_free(pub_rsa); + RSA_free(priv_rsa); + } |