diff options
author | marha <marha@users.sourceforge.net> | 2009-06-28 22:07:26 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2009-06-28 22:07:26 +0000 |
commit | 3562e78743202e43aec8727005182a2558117eca (patch) | |
tree | 8f9113a77d12470c5c851a2a8e4cb02e89df7d43 /openssl/demos/eay | |
download | vcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.gz vcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.bz2 vcxsrv-3562e78743202e43aec8727005182a2558117eca.zip |
Checked in the following released items:
xkeyboard-config-1.4.tar.gz
ttf-bitstream-vera-1.10.tar.gz
font-alias-1.0.1.tar.gz
font-sun-misc-1.0.0.tar.gz
font-sun-misc-1.0.0.tar.gz
font-sony-misc-1.0.0.tar.gz
font-schumacher-misc-1.0.0.tar.gz
font-mutt-misc-1.0.0.tar.gz
font-misc-misc-1.0.0.tar.gz
font-misc-meltho-1.0.0.tar.gz
font-micro-misc-1.0.0.tar.gz
font-jis-misc-1.0.0.tar.gz
font-isas-misc-1.0.0.tar.gz
font-dec-misc-1.0.0.tar.gz
font-daewoo-misc-1.0.0.tar.gz
font-cursor-misc-1.0.0.tar.gz
font-arabic-misc-1.0.0.tar.gz
font-winitzki-cyrillic-1.0.0.tar.gz
font-misc-cyrillic-1.0.0.tar.gz
font-cronyx-cyrillic-1.0.0.tar.gz
font-screen-cyrillic-1.0.1.tar.gz
font-xfree86-type1-1.0.1.tar.gz
font-adobe-utopia-type1-1.0.1.tar.gz
font-ibm-type1-1.0.0.tar.gz
font-bitstream-type1-1.0.0.tar.gz
font-bitstream-speedo-1.0.0.tar.gz
font-bh-ttf-1.0.0.tar.gz
font-bh-type1-1.0.0.tar.gz
font-bitstream-100dpi-1.0.0.tar.gz
font-bh-lucidatypewriter-100dpi-1.0.0.tar.gz
font-bh-100dpi-1.0.0.tar.gz
font-adobe-utopia-100dpi-1.0.1.tar.gz
font-adobe-100dpi-1.0.0.tar.gz
font-util-1.0.1.tar.gz
font-bitstream-75dpi-1.0.0.tar.gz
font-bh-lucidatypewriter-75dpi-1.0.0.tar.gz
font-adobe-utopia-75dpi-1.0.1.tar.gz
font-bh-75dpi-1.0.0.tar.gz
bdftopcf-1.0.1.tar.gz
font-adobe-75dpi-1.0.0.tar.gz
mkfontscale-1.0.6.tar.gz
openssl-0.9.8k.tar.gz
bigreqsproto-1.0.2.tar.gz
xtrans-1.2.2.tar.gz
resourceproto-1.0.2.tar.gz
inputproto-1.4.4.tar.gz
compositeproto-0.4.tar.gz
damageproto-1.1.0.tar.gz
zlib-1.2.3.tar.gz
xkbcomp-1.0.5.tar.gz
freetype-2.3.9.tar.gz
pthreads-w32-2-8-0-release.tar.gz
pixman-0.12.0.tar.gz
kbproto-1.0.3.tar.gz
evieext-1.0.2.tar.gz
fixesproto-4.0.tar.gz
recordproto-1.13.2.tar.gz
randrproto-1.2.2.tar.gz
scrnsaverproto-1.1.0.tar.gz
renderproto-0.9.3.tar.gz
xcmiscproto-1.1.2.tar.gz
fontsproto-2.0.2.tar.gz
xextproto-7.0.3.tar.gz
xproto-7.0.14.tar.gz
libXdmcp-1.0.2.tar.gz
libxkbfile-1.0.5.tar.gz
libfontenc-1.0.4.tar.gz
libXfont-1.3.4.tar.gz
libX11-1.1.5.tar.gz
libXau-1.0.4.tar.gz
libxcb-1.1.tar.gz
xorg-server-1.5.3.tar.gz
Diffstat (limited to 'openssl/demos/eay')
-rw-r--r-- | openssl/demos/eay/Makefile | 24 | ||||
-rw-r--r-- | openssl/demos/eay/base64.c | 49 | ||||
-rw-r--r-- | openssl/demos/eay/conn.c | 105 | ||||
-rw-r--r-- | openssl/demos/eay/loadrsa.c | 53 |
4 files changed, 231 insertions, 0 deletions
diff --git a/openssl/demos/eay/Makefile b/openssl/demos/eay/Makefile new file mode 100644 index 000000000..2d22eaca5 --- /dev/null +++ b/openssl/demos/eay/Makefile @@ -0,0 +1,24 @@ +CC=cc +CFLAGS= -g -I../../include +#LIBS= -L../.. -lcrypto -lssl +LIBS= -L../.. ../../libssl.a ../../libcrypto.a + +# the file conn.c requires a file "proxy.h" which I couldn't find... +#EXAMPLES=base64 conn loadrsa +EXAMPLES=base64 loadrsa + +all: $(EXAMPLES) + +base64: base64.o + $(CC) -o base64 base64.o $(LIBS) +# +# sorry... can't find "proxy.h" +#conn: conn.o +# $(CC) -o conn conn.o $(LIBS) + +loadrsa: loadrsa.o + $(CC) -o loadrsa loadrsa.o $(LIBS) + +clean: + rm -f $(EXAMPLES) *.o + diff --git a/openssl/demos/eay/base64.c b/openssl/demos/eay/base64.c new file mode 100644 index 000000000..4b8b0627d --- /dev/null +++ b/openssl/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 <openssl/bio.h> +#include <openssl/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/openssl/demos/eay/conn.c b/openssl/demos/eay/conn.c new file mode 100644 index 000000000..c4b8f5163 --- /dev/null +++ b/openssl/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 <openssl/err.h> +#include <openssl/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/openssl/demos/eay/loadrsa.c b/openssl/demos/eay/loadrsa.c new file mode 100644 index 000000000..79f1885ca --- /dev/null +++ b/openssl/demos/eay/loadrsa.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <openssl/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); + } |