Manual Pages for UNIX Darwin command on man SSL_CTX_set_verify
MyWebUniversity

Manual Pages for UNIX Darwin command on man SSL_CTX_set_verify

SSLCTXsetverify(3) OpenSSL SSLCTXsetverify(3)

NAME

SSLCTXsetverify, SSLsetverify, SSLCTXsetverifydepth,

SSLsetverifydepth - set peer certificate verification parameters

SYNOPSIS

#include

void SSLCTXsetverify(SSLCTX *ctx, int mode, int (*verifycallback)(int, X509STORECTX *)); void SSLsetverify(SSL *s, int mode, int (*verifycallback)(int, X509STORECTX *)); void SSLCTXsetverifydepth(SSLCTX *ctx,int depth); void SSLsetverifydepth(SSL *s, int depth); int verifycallback(int preverifyok, X509STORECTX *x509ctx);

DESCRIPTION

SSLCTXsetverify() sets the verification flags for ccttxx to be mmooddee and specifies the vveerriiffyyccaallllbbaacckk function to be used. If no callback function shall be specified, the NULL pointer can be used for vveerriiffyyccaallllbbaacckk. SSLsetverify() sets the verification flags for ssssll to be mmooddee and specifies the vveerriiffyyccaallllbbaacckk function to be used. If no callback function shall be specified, the NULL pointer can be used for vveerriiffyyccaallllbbaacckk. In this case last vveerriiffyyccaallllbbaacckk set specifically for this ssssll remains. If no special ccaallllbbaacckk was set before, the default callback for the underlying ccttxx is used, that was valid at the the time ssssll was created with SSLnew(3). SSLCTXsetverifydepth() sets the maximum ddeepptthh for the certificate

chain verification that shall be allowed for ccttxx. (See the BUGS

section.) SSLsetverifydepth() sets the maximum ddeepptthh for the certificate chain

verification that shall be allowed for ssssll. (See the BUGS section.)

NNOOTTEESS The verification of certificates can be controlled by a set of logically or'ed mmooddee flags: SSLVERIFYNONE SSeerrvveerr mmooddee:: the server will not send a client certificate request to the client, so the client will not send a certificate. CClliieenntt mmooddee:: if not using an anonymous cipher (by default disabled), the server will send a certificate which will be checked. The result of the certificate verification process can be checked after the TLS/SSL handshake using the SSLgetverifyresult(3) function. The handshake will be continued regardless of the verification result. SSLVERIFYPEER SSeerrvveerr mmooddee:: the server sends a client certificate request to the client. The certificate returned (if any) is checked. If the verification process fails, the TLS/SSL handshake is immediately terminated with an alert message containing the reason for the verification failure. The behaviour can be controlled by the additional SSLVERIFYFAILIFNOPEERCERT and SSLVERIFYCLIENTONCE flags. CClliieenntt mmooddee:: the server certificate is verified. If the verification process fails, the TLS/SSL handshake is immediately terminated with an alert message containing the reason for the verification failure. If no server certificate is sent, because an anonymous cipher is used, SSLVERIFYPEER is ignored. SSLVERIFYFAILIFNOPEERCERT SSeerrvveerr mmooddee:: if the client did not return a certificate, the TLS/SSL handshake is immediately terminated with a "handshake failure" alert. This flag must be used together with SSLVERIFYPEER. CClliieenntt mmooddee:: ignored SSLVERIFYCLIENTONCE SSeerrvveerr mmooddee:: only request a client certificate on the initial TLS/SSL handshake. Do not ask for a client certificate again in case of a renegotiation. This flag must be used together with SSLVERIFYPEER. CClliieenntt mmooddee:: ignored Exactly one of the mmooddee flags SSLVERIFYNONE and SSLVERIFYPEER must be set at any time.

The actual verification procedure is performed either using the built-

in verification procedure or using another application provided verification function set with SSLCTXsetcertverifycallback(3).

The following descriptions apply in the case of the built-in procedure.

An application provided procedure also has access to the verify depth information and the verifycallback() function, but the way this information is used may be different. SSLCTXsetverifydepth() and SSLsetverifydepth() set the limit up to which depth certificates in a chain are used during the verification procedure. If the certificate chain is longer than allowed, the certificates above the limit are ignored. Error messages are generated as if these certificates would not be present, most likely a X509VERRUNABLETOGETISSUERCERTLOCALLY will be issued. The depth count is "level 0:peer certificate", "level 1: CA certificate", "level 2: higher level CA certificate", and so on. Setting the maximum depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9, allowing for the peer certificate and additional 9 CA certificates. The vveerriiffyyccaallllbbaacckk function is used to control the behaviour when the SSLVERIFYPEER flag is set. It must be supplied by the application and receives two arguments: pprreevveerriiffyyookk indicates, whether the verification of the certificate in question was passed (preverifyok=1) or not (preverifyok=0). xx550099ccttxx is a pointer to the complete context used for the certificate chain verification. The certificate chain is checked starting with the deepest nesting level (the root CA certificate) and worked upward to the peer's certificate. At each level signatures and issuer attributes are checked. Whenever a verification error is found, the error number is stored in xx550099ccttxx and vveerriiffyyccaallllbbaacckk is called with pprreevveerriiffyyookk=0. By applying X509CTXstore* functions vveerriiffyyccaallllbbaacckk can locate the

certificate in question and perform additional steps (see EXAMPLES). If

no error is found for a certificate, vveerriiffyyccaallllbbaacckk is called with pprreevveerriiffyyookk=1 before advancing to the next level. The return value of vveerriiffyyccaallllbbaacckk controls the strategy of the further verification process. If vveerriiffyyccaallllbbaacckk returns 0, the verification process is immediately stopped with "verification failed" state. If SSLVERIFYPEER is set, a verification failure alert is sent to the peer and the TLS/SSL handshake is terminated. If vveerriiffyyccaallllbbaacckk returns 1, the verification process is continued. If vveerriiffyyccaallllbbaacckk always returns 1, the TLS/SSL handshake will not be terminated with respect to verification failures and the connection will be established. The calling process can however retrieve the error code of the last verification error using SSLgetverifyresult(3) or by maintaining its own error storage managed by vveerriiffyyccaallllbbaacckk. If no vveerriiffyyccaallllbbaacckk is specified, the default callback will be used. Its return value is identical to pprreevveerriiffyyookk, so that any verification failure will lead to a termination of the TLS/SSL handshake with an alert message, if SSLVERIFYPEER is set.

BUGS

In client mode, it is not checked whether the SSLVERIFYPEER flag is set, but whether SSLVERIFYNONE is not set. This can lead to unexpected behaviour, if the SSLVERIFYPEER and SSLVERIFYNONE are not used as required (exactly one must be set at any time). The certificate verification depth set with SSL[CTX]verifydepth() stops the verification at a certain depth. The error message produced will be that of an incomplete certificate chain and not X509VERRCERTCHAINTOOLONG as may be expected.

RETURN VALUES

The SSL*setverify*() functions do not provide diagnostic information. EEXXAAMMPPLLEESS The following code sequence realizes an example vveerriiffyyccaallllbbaacckk function that will always continue the TLS/SSL handshake regardless of verification failure, if wished. The callback realizes a verification depth limit with more informational output. All verification errors are printed, informations about the certificate chain are printed on request. The example is realized for a server that does allow but not require client certificates. The example makes use of the exdata technique to store application data into/retrieve application data from the SSL structure (see SSLgetexnewindex(3), SSLgetexdataX509STORECTXidx(3)). ... typedef struct { int verbosemode; int verifydepth; int alwayscontinue; } mydatat; int mydataindex; ... static int verifycallback(int preverifyok, X509STORECTX *ctx) { char buf[256]; X509 *errcert; int err, depth; SSL *ssl; mydatat *mydata; errcert = X509STORECTXgetcurrentcert(ctx); err = X509STORECTXgeterror(ctx); depth = X509STORECTXgeterrordepth(ctx); /* * Retrieve the pointer to the SSL of the connection currently treated * and the application specific data stored into the SSL object. */ ssl = X509STORECTXgetexdata(ctx, SSLgetexdataX509STORECTXidx()); mydata = SSLgetexdata(ssl, mydataindex);

X509NAMEoneline(X509getsubjectname(errcert), buf, 256);

/* * Catch a too long certificate chain. The depth limit set using * SSLCTXsetverifydepth() is by purpose set to "limit+1" so * that whenever the "depth>verifydepth" condition is met, we * have violated the limit and want to log this error condition. * We must do it here, because the CHAINTOOLONG error would not * be found explicitly; only errors introduced by cutting off the * additional certificates would be logged. */

if (depth > mydata->verifydepth) {

preverifyok = 0; err = X509VERRCERTCHAINTOOLONG; X509STORECTXseterror(ctx, err); } if (!preverifyok) {

printf("verify error:num=%d:%s:depth=%d:%s\n", err,

X509verifycerterrorstring(err), depth, buf); }

else if (mydata->verbosemode)

{

printf("depth=%d:%s\n", depth, buf);

} /* * At this point, err contains the last verification error. We can use * it for something special */ if (!preverifyok && (err == X509VERRUNABLETOGETISSUERCERT)) {

X509NAMEoneline(X509getissuername(ctx->currentcert), buf, 256);

printf("issuer= %s\n", buf);

}

if (mydata->alwayscontinue)

return 1; else return preverifyok; } ... mydatat mydata; ... mydataindex = SSLgetexnewindex(0, "mydata index", NULL, NULL, NULL); ... SSLCTXsetverify(ctx, SSLVERIFYPEER|SSLVERIFYCLIENTONCE, verifycallback); /* * Let the verifycallback catch the verifydepth error so that we get * an appropriate error in the logfile. */ SSLCTXsetverifydepth(verifydepth + 1); /* * Set up the SSL specific data into "mydata" and store it into th SSL * structure. */ mydata.verifydepth = verifydepth; ... SSLsetexdata(ssl, mydataindex, &mydata); ... SSLaccept(ssl); /* check of success left out for clarity */ if (peer = SSLgetpeercertificate(ssl)) { if (SSLgetverifyresult(ssl) == X509VOK) { /* The client sent a certificate which verified OK */ } }

SEE ALSO

ssl(3), SSLnew(3), SSLCTXgetverifymode(3), SSLgetverifyresult(3), SSLCTXloadverifylocations(3), SSLgetpeercertificate(3), SSLCTXsetcertverifycallback(3), SSLgetexdataX509STORECTXidx(3), SSLgetexnewindex(3)

0.9.7l 2003-06-26 SSLCTXsetverify(3)




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