Manual Pages for UNIX Darwin command on man BIO_f_ssl
MyWebUniversity

Manual Pages for UNIX Darwin command on man BIO_f_ssl

BIOfssl(3) OpenSSL BIOfssl(3)

NAME

BIOfssl, BIOsetssl, BIOgetssl, BIOsetsslmode, BIOsetsslrenegotiatebytes, BIOgetnumrenegotiates, BIOsetsslrenegotiatetimeout, BIOnewssl, BIOnewsslconnect,

BIOnewbuffersslconnect, BIOsslcopysessionid, BIOsslshutdown -

SSL BIO

SYNOPSIS

#include

#include

BIOMETHOD *BIOfssl(void);

#define BIOsetssl(b,ssl,c) BIOctrl(b,BIOCSETSSL,c,(char *)ssl)

#define BIOgetssl(b,sslp) BIOctrl(b,BIOCGETSSL,0,(char *)sslp)

#define BIOsetsslmode(b,client) BIOctrl(b,BIOCSSLMODE,client,NULL)

#define BIOsetsslrenegotiatebytes(b,num) \

BIOctrl(b,BIOCSETSSLRENEGOTIATEBYTES,num,NULL);

#define BIOsetsslrenegotiatetimeout(b,seconds) \

BIOctrl(b,BIOCSETSSLRENEGOTIATETIMEOUT,seconds,NULL);

#define BIOgetnumrenegotiates(b) \

BIOctrl(b,BIOCSETSSLNUMRENEGOTIATES,0,NULL); BIO *BIOnewssl(SSLCTX *ctx,int client); BIO *BIOnewsslconnect(SSLCTX *ctx); BIO *BIOnewbuffersslconnect(SSLCTX *ctx); int BIOsslcopysessionid(BIO *to,BIO *from); void BIOsslshutdown(BIO *bio);

#define BIOdohandshake(b) BIOctrl(b,BIOCDOSTATEMACHINE,0,NULL)

DESCRIPTION

BIOfssl() returns the SSL BIO method. This is a filter BIO which is a wrapper round the OpenSSL SSL routines adding a BIO "flavour" to SSL I/O. I/O performed on an SSL BIO communicates using the SSL protocol with the SSLs read and write BIOs. If an SSL connection is not established then an attempt is made to establish one on the first I/O call. If a BIO is appended to an SSL BIO using BIOpush() it is automatically used as the SSL BIOs read and write BIOs. Calling BIOreset() on an SSL BIO closes down any current SSL connection by calling SSLshutdown(). BIOreset() is then sent to the next BIO in the chain: this will typically disconnect the underlying transport. The SSL BIO is then reset to the initial accept or connect state. If the close flag is set when an SSL BIO is freed then the internal SSL structure is also freed using SSLfree(). BIOsetssl() sets the internal SSL pointer of BIO bb to ssssll using the close flag cc. BIOgetssl() retrieves the SSL pointer of BIO bb, it can then be manipulated using the standard SSL library functions. BIOsetsslmode() sets the SSL BIO mode to cclliieenntt. If cclliieenntt is 1 client mode is set. If cclliieenntt is 0 server mode is set. BIOsetsslrenegotiatebytes() sets the renegotiate byte count to nnuumm. When set after every nnuumm bytes of I/O (read and write) the SSL session is automatically renegotiated. nnuumm must be at least 512 bytes. BIOsetsslrenegotiatetimeout() sets the renegotiate timeout to sseeccoonnddss. When the renegotiate timeout elapses the session is automatically renegotiated. BIOgetnumrenegotiates() returns the total number of session renegotiations due to I/O or timeout. BIOnewssl() allocates an SSL BIO using SSLCTX ccttxx and using client mode if cclliieenntt is non zero. BIOnewsslconnect() creates a new BIO chain consisting of an SSL BIO (using ccttxx) followed by a connect BIO. BIOnewbuffersslconnect() creates a new BIO chain consisting of a buffering BIO, an SSL BIO (using ccttxx) and a connect BIO. BIOsslcopysessionid() copies an SSL session id between BIO chains ffrroomm and ttoo. It does this by locating the SSL BIOs in each chain and calling SSLcopysessionid() on the internal SSL pointer. BIOsslshutdown() closes down an SSL connection on BIO chain bbiioo. It does this by locating the SSL BIO in the chain and calling SSLshutdown() on its internal SSL pointer. BIOdohandshake() attempts to complete an SSL handshake on the supplied BIO and establish the SSL connection. It returns 1 if the connection was established successfully. A zero or negative value is returned if the connection could not be established, the call BIOshouldretry() should be used for non blocking connect BIOs to determine if the call should be retried. If an SSL connection has already been established this call has no effect. NNOOTTEESS SSL BIOs are exceptional in that if the underlying transport is non blocking they can still request a retry in exceptional circumstances. Specifically this will happen if a session renegotiation takes place during a BIOread() operation, one case where this happens is when SGC or step up occurs. In OpenSSL 0.9.6 and later the SSL flag SSLAUTORETRY can be set to disable this behaviour. That is when this flag is set an SSL BIO using a blocking transport will never request a retry. Since unknown BIOctrl() operations are sent through filter BIOs the servers name and port can be set using BIOsethost() on the BIO returned by BIOnewsslconnect() without having to locate the connect BIO first. Applications do not have to call BIOdohandshake() but may wish to do so to separate the handshake process from other I/O processing.

RETURN VALUES

TBA EEXXAAMMPPLLEE This SSL/TLS client example, attempts to retrieve a page from an SSL/TLS web server. The I/O routines are identical to those of the unencrypted example in BIOsconnect(3). BIO *sbio, *out; int len; char tmpbuf[1024]; SSLCTX *ctx; SSL *ssl; ERRloadcryptostrings(); ERRloadSSLstrings(); OpenSSLaddallalgorithms(); /* We would seed the PRNG here if the platform didn't * do it automatically */ ctx = SSLCTXnew(SSLv23clientmethod()); /* We'd normally set some stuff like the verify paths and * mode here because as things stand this will connect to * any server whose certificate is signed by any CA. */ sbio = BIOnewsslconnect(ctx); BIOgetssl(sbio, &ssl); if(!ssl) { fprintf(stderr, "Can't locate SSL pointer\n"); /* whatever ... */ } /* Don't want any retries */ SSLsetmode(ssl, SSLMODEAUTORETRY); /* We might want to do other things with ssl here */ BIOsetconnhostname(sbio, "localhost:https"); out = BIOnewfp(stdout, BIONOCLOSE); if(BIOdoconnect(sbio) <= 0) { fprintf(stderr, "Error connecting to server\n"); ERRprinterrorsfp(stderr); /* whatever ... */ } if(BIOdohandshake(sbio) <= 0) { fprintf(stderr, "Error establishing SSL connection\n"); ERRprinterrorsfp(stderr); /* whatever ... */ } /* Could examine ssl here to get connection info */ BIOputs(sbio, "GET / HTTP/1.0\n\n"); for(;;) { len = BIOread(sbio, tmpbuf, 1024); if(len <= 0) break; BIOwrite(out, tmpbuf, len); } BIOfreeall(sbio); BIOfree(out); Here is a simple server example. It makes use of a buffering BIO to allow lines to be read from the SSL BIO using BIOgets. It creates a pseudo web page containing the actual request from a client and also echoes the request to standard output. BIO *sbio, *bbio, *acpt, *out; int len; char tmpbuf[1024]; SSLCTX *ctx; SSL *ssl; ERRloadcryptostrings(); ERRloadSSLstrings(); OpenSSLaddallalgorithms(); /* Might seed PRNG here */ ctx = SSLCTXnew(SSLv23servermethod()); if (!SSLCTXusecertificatefile(ctx,"server.pem",SSLFILETYPEPEM) || !SSLCTXusePrivateKeyfile(ctx,"server.pem",SSLFILETYPEPEM) || !SSLCTXcheckprivatekey(ctx)) { fprintf(stderr, "Error setting up SSLCTX\n"); ERRprinterrorsfp(stderr); return 0; } /* Might do other things here like setting verify locations and * DH and/or RSA temporary key callbacks */ /* New SSL BIO setup as server */ sbio=BIOnewssl(ctx,0); BIOgetssl(sbio, &ssl); if(!ssl) { fprintf(stderr, "Can't locate SSL pointer\n"); /* whatever ... */ } /* Don't want any retries */ SSLsetmode(ssl, SSLMODEAUTORETRY); /* Create the buffering BIO */ bbio = BIOnew(BIOfbuffer()); /* Add to chain */ sbio = BIOpush(bbio, sbio); acpt=BIOnewaccept("4433"); /* By doing this when a new connection is established * we automatically have sbio inserted into it. The * BIO chain is now 'swallowed' by the accept BIO and * will be freed when the accept BIO is freed. */ BIOsetacceptbios(acpt,sbio); out = BIOnewfp(stdout, BIONOCLOSE); /* Setup accept BIO */ if(BIOdoaccept(acpt) <= 0) { fprintf(stderr, "Error setting up accept BIO\n"); ERRprinterrorsfp(stderr); return 0; } /* Now wait for incoming connection */ if(BIOdoaccept(acpt) <= 0) { fprintf(stderr, "Error in connection\n"); ERRprinterrorsfp(stderr); return 0; } /* We only want one connection so remove and free * accept BIO */ sbio = BIOpop(acpt); BIOfreeall(acpt); if(BIOdohandshake(sbio) <= 0) { fprintf(stderr, "Error in SSL handshake\n"); ERRprinterrorsfp(stderr); return 0; }

BIOputs(sbio, "HTTP/1.0 200 OK\r\nContent-type: text/plain\r\n\r\n");

BIOputs(sbio, "\r\nConnection Established\r\nRequest headers:\r\n");

BIOputs(sbio, "-------------------------\r\n");

for(;;) { len = BIOgets(sbio, tmpbuf, 1024); if(len <= 0) break; BIOwrite(sbio, tmpbuf, len); BIOwrite(out, tmpbuf, len); /* Look for blank line signifying end of headers*/ if((tmpbuf[0] == '\r') || (tmpbuf[0] == '\n')) break; }

BIOputs(sbio, "-------------------------\r\n");

BIOputs(sbio, "\r\n"); /* Since there is a buffering BIO present we had better flush it */ BIOflush(sbio); BIOfreeall(sbio);

SEE ALSO

TBA

0.9.7l 2003-11-28 BIOfssl(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™