> I believe that both HTTPS_CA_FILE and HTTPS_CA_DIR need to be set
> correctly for the CA to be verified. So if cacerts.pem is a file in
> the currrent directory when you are running your script, you might set
> HTTPS_CA_DIR to ./ for example.
Unfortunately this does not work. After looking at openssl docs, it
would appear that CA_DIR is optional and is only searched after CA_FILE.
> If there is some openssl function that should be called in particular
> to help set up the connection with this CA_FILE, we might be able to
> patch Crypt::SSLeay to do what you need. The relevant files for this
> would be SSLeay.xs which creates the glue to the OpenSSL functions,
> and lib/Net/SSL.pm which is the actual perl library that calls the
> configure_certs() setup routine.
Since I was successful in connecting with s_client, I looked in
s_client.c and found this:
SSL_CTX_set_verify(ctx,verify,verify_callback);
if (!set_cert_stuff(ctx,cert_file,key_file))
goto end;
if ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||
(!SSL_CTX_set_default_verify_paths(ctx)))
{
/* BIO_printf(bio_err,"error setting default verify locations\n"); */
ERR_print_errors(bio_err);
/* goto end; */
}
store = SSL_CTX_get_cert_store(ctx);
X509_STORE_set_flags(store, vflags);
con=SSL_new(ctx);
So it would appear that SSL_CTX_load_verify_locations is the openssl
function that needs to get called before the SSL context is established.
Looking in SSLeay.xs I find:
MODULE = Crypt::SSLeay PACKAGE = Crypt::SSLeay::CTX PREFIX = SSL_CTX_
[snip]
SV*
SSL_CTX_set_verify(ctx)
SSL_CTX* ctx
PREINIT:
char* CAfile;
char* CAdir;
CODE:
CAfile=getenv("HTTPS_CA_FILE");
CAdir =getenv("HTTPS_CA_DIR");
if(!CAfile && !CAdir) {
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
RETVAL = newSViv(0);
} else {
SSL_CTX_load_verify_locations(ctx,CAfile,CAdir);
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
RETVAL = newSViv(1);
}
OUTPUT:
RETVAL
This appears to be doing the right thing since it calls
SSL_CTX_load_verify_locations, but I am unsure that I understand Perl XS
well enough to confirm this. Looking in Net/SSL.pm reveals that
set_verify gets called in the connect sub:
eval { $self->configure_certs(); };
if($@) {
$@ = "configure certs failed: $@, $!";
$self->die_with_error($@);
}
# finished, update set_verify status
if(my $rv = *$self->{'ssl_ctx'}->set_verify()) {
*$self->{'ssl_peer_verify'} = $rv;
}
It may be unimportant, but the only suspicious thing I can see is that
s_client calls SSL_CTX_set_verify before calling
SSL_CTX_load_verify_locations whereas SSLeay.xs reverses the order of
those calls.
I am not a Perl XS expert by any stretch of the imagination. Can someone
confirm my reading of the Perl involved?
Thanks,
--
Sean Evans