Import of old SSLeay release: SSLeay 0.9.1b (unreleased)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
49
demos/eay/base64.c
Normal file
49
demos/eay/base64.c
Normal file
@@ -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);
|
||||
}
|
||||
105
demos/eay/conn.c
Normal file
105
demos/eay/conn.c
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
53
demos/eay/loadrsa.c
Normal file
53
demos/eay/loadrsa.c
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user