From 6ef9d8328bd09d3b6a19be83bf46724c806cb1ce Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 2 May 2001 09:09:04 +0000 Subject: [PATCH] Merge in changes from the 0.9.6-stable branch. --- CHANGES | 19 ++++++ FAQ | 8 +++ Makefile.org | 8 +-- README | 2 +- apps/dgst.c | 6 +- apps/smime.c | 1 + apps/speed.c | 4 +- crypto/bio/b_print.c | 14 +++-- crypto/evp/evp.h | 6 +- crypto/evp/evp_key.c | 6 +- crypto/opensslv.h | 4 +- crypto/rand/md_rand.c | 71 +++++++++++++++++------ doc/apps/rsautl.pod | 4 +- doc/apps/s_server.pod | 2 +- doc/crypto/bio.pod | 2 +- doc/ssl/SSL_CTX_load_verify_locations.pod | 14 ++--- doc/ssl/SSL_CTX_set_client_CA_list.pod | 24 ++++---- doc/ssl/SSL_get_peer_certificate.pod | 9 ++- doc/ssl/SSL_shutdown.pod | 2 +- test/Makefile.ssl | 2 +- test/bctest | 18 +++++- 21 files changed, 157 insertions(+), 69 deletions(-) diff --git a/CHANGES b/CHANGES index 08ef8508d8..d59baf9a57 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,25 @@ OpenSSL CHANGES _______________ + Changes between 0.9.6a and 0.9.6b [XX xxx XXXX] + + *) Move 'if (!initialized) RAND_poll()' into regions protected by + CRYPTO_LOCK_RAND. This is not strictly necessary, but avoids + having multiple threads call RAND_poll() concurrently. + [Bodo Moeller] + + *) In crypto/rand/md_rand.c, replace 'add_do_not_lock' flag by a + combination of a flag and a thread ID variable. + Otherwise while one thread is in ssleay_rand_bytes (which sets the + flag), *other* threads can enter ssleay_add_bytes without obeying + the CRYPTO_LOCK_RAND lock (and may even illegaly release the lock + that they do not hold after the first thread unsets add_do_not_lock). + [Bodo Moeller] + + *) Change bctest again: '-x' expressions are not available in all + versions of 'test'. + [Bodo Moeller] + Changes between 0.9.6 and 0.9.6a [5 Apr 2001] *) Fix a couple of memory leaks in PKCS7_dataDecode() diff --git a/FAQ b/FAQ index cd759e0202..878a779670 100644 --- a/FAQ +++ b/FAQ @@ -47,6 +47,7 @@ OpenSSL - Frequently Asked Questions * Why do I get errors about unknown algorithms? * Why can't the OpenSSH configure script detect OpenSSL? * Can I use OpenSSL's SSL library with non-blocking I/O? +* Why doesn't my server application receive a client certificate? =============================================================================== @@ -543,5 +544,12 @@ requiring a bi-directional message exchange; both SSL_read() and SSL_write() will try to continue any pending handshake. +* Why doesn't my server application receive a client certificate? + +Due to the TLS protocol definition, a client will only send a certificate, +if explicitely asked by the server. Use the SSL_VERIFY_PEER flag of the +SSL_CTX_set_verify() function to enable the use of client certificates. + + =============================================================================== diff --git a/Makefile.org b/Makefile.org index ad6a843428..f085fd2844 100644 --- a/Makefile.org +++ b/Makefile.org @@ -474,19 +474,19 @@ install_docs: $(INSTALL_PREFIX)$(MANDIR)/man3 \ $(INSTALL_PREFIX)$(MANDIR)/man5 \ $(INSTALL_PREFIX)$(MANDIR)/man7 - @echo installing man 1 and man 5 @for i in doc/apps/*.pod; do \ fn=`basename $$i .pod`; \ - sec=`[ "$$fn" = "config" ] && echo 5 || echo 1`; \ + if [ "$$fn" = "config" ]; then sec=5; else sec=1; fi; \ + echo "installing man$$sec/`basename $$i .pod`.$$sec"; \ (cd `dirname $$i`; \ $(PERL) ../../util/pod2man.pl --section=$$sec --center=OpenSSL \ --release=$(VERSION) `basename $$i`) \ > $(INSTALL_PREFIX)$(MANDIR)/man$$sec/`basename $$i .pod`.$$sec; \ done - @echo installing man 3 and man 7 @for i in doc/crypto/*.pod doc/ssl/*.pod; do \ fn=`basename $$i .pod`; \ - sec=`[ "$$fn" = "des_modes" ] && echo 7 || echo 3`; \ + if [ "$$fn" = "des_modes" ]; then sec=7; else sec=3; fi; \ + echo "installing man$$sec/`basename $$i .pod`.$$sec"; \ (cd `dirname $$i`; \ $(PERL) ../../util/pod2man.pl --section=$$sec --center=OpenSSL \ --release=$(VERSION) `basename $$i`) \ diff --git a/README b/README index 8f8202042b..0c7f8556bc 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ - OpenSSL 0.9.6a [engine] 5 Apr 2001 + OpenSSL 0.9.6b-dev [engine] XX xxx XXXX Copyright (c) 1998-2000 The OpenSSL Project Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson diff --git a/apps/dgst.c b/apps/dgst.c index ab3e2dbb02..61b2a0dc4b 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -74,7 +74,7 @@ #undef PROG #define PROG dgst_main -void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, char binout, +void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, EVP_PKEY *key, unsigned char *sigin, int siglen); int MAIN(int, char **); @@ -95,7 +95,7 @@ int MAIN(int argc, char **argv) int debug=0; const char *outfile = NULL, *keyfile = NULL; const char *sigfile = NULL, *randfile = NULL; - char out_bin = -1, want_pub = 0, do_verify = 0; + int out_bin = -1, want_pub = 0, do_verify = 0; EVP_PKEY *sigkey = NULL; unsigned char *sigbuf = NULL; int siglen = 0; @@ -365,7 +365,7 @@ end: EXIT(err); } -void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, char binout, +void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, EVP_PKEY *key, unsigned char *sigin, int siglen) { int len; diff --git a/apps/smime.c b/apps/smime.c index 16b940084b..7bf71ef868 100644 --- a/apps/smime.c +++ b/apps/smime.c @@ -299,6 +299,7 @@ int MAIN(int argc, char **argv) BIO_printf (bio_err, "-CApath dir trusted certificates directory\n"); BIO_printf (bio_err, "-CAfile file trusted certificates file\n"); BIO_printf (bio_err, "-engine e use engine e, possibly a hardware device.\n"); + BIO_printf (bio_err, "-passin arg input file pass phrase source\n"); BIO_printf(bio_err, "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); BIO_printf(bio_err, " load the file (or the files in the directory) into\n"); BIO_printf(bio_err, " the random number generator\n"); diff --git a/apps/speed.c b/apps/speed.c index 3562ea277b..9c91f718e0 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -83,12 +83,12 @@ #include #include -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) # define USE_TOD #elif !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) # define TIMES #endif -#if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(MPE) +#if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(MPE) && !defined(__NetBSD__) # define TIMEB #endif diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c index b4f7a85f2e..91a049406e 100644 --- a/crypto/bio/b_print.c +++ b/crypto/bio/b_print.c @@ -109,7 +109,11 @@ #endif #if HAVE_LONG_LONG -#define LLONG long long +# if defined(WIN32) && !defined(__GNUC__) +# define LLONG _int64 +# else +# define LLONG long long +# endif #else #define LLONG long #endif @@ -152,7 +156,7 @@ static void _dopr(char **sbuffer, char **buffer, /* some handy macros */ #define char_to_int(p) (p - '0') -#define MAX(p,q) ((p >= q) ? p : q) +#define OSSL_MAX(p,q) ((p >= q) ? p : q) static void _dopr( @@ -503,13 +507,13 @@ fmtint( convert[place] = 0; zpadlen = max - place; - spadlen = min - MAX(max, place) - (signvalue ? 1 : 0); + spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0); if (zpadlen < 0) zpadlen = 0; if (spadlen < 0) spadlen = 0; if (flags & DP_F_ZERO) { - zpadlen = MAX(zpadlen, spadlen); + zpadlen = OSSL_MAX(zpadlen, spadlen); spadlen = 0; } if (flags & DP_F_MINUS) @@ -641,7 +645,7 @@ fmtfp( (caps ? "0123456789ABCDEF" : "0123456789abcdef")[fracpart % 10]; fracpart = (fracpart / 10); - } while (fracpart && (fplace < 20)); + } while (fplace < max); if (fplace == 20) fplace--; fconvert[fplace] = 0; diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index cdf5f3cf89..0f27df4603 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -554,9 +554,9 @@ int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify); void EVP_set_pw_prompt(char *prompt); char * EVP_get_pw_prompt(void); -int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, - unsigned char *data, int datal, int count, - unsigned char *key,unsigned char *iv); +int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, + const unsigned char *salt, const unsigned char *data, int datal, + int count, unsigned char *key, unsigned char *iv); int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, unsigned char *key, unsigned char *iv); diff --git a/crypto/evp/evp_key.c b/crypto/evp/evp_key.c index 09b72bf4bd..e7434ef9b2 100644 --- a/crypto/evp/evp_key.c +++ b/crypto/evp/evp_key.c @@ -95,9 +95,9 @@ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) #endif } -int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt, - unsigned char *data, int datal, int count, unsigned char *key, - unsigned char *iv) +int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, + const unsigned char *salt, const unsigned char *data, int datal, + int count, unsigned char *key, unsigned char *iv) { EVP_MD_CTX c; unsigned char md_buf[EVP_MAX_MD_SIZE]; diff --git a/crypto/opensslv.h b/crypto/opensslv.h index dc50f6d7da..da3d185341 100644 --- a/crypto/opensslv.h +++ b/crypto/opensslv.h @@ -25,8 +25,8 @@ * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for * major minor fix final patch/beta) */ -#define OPENSSL_VERSION_NUMBER 0x0090601fL -#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.6a [engine] 5 Apr 2001" +#define OPENSSL_VERSION_NUMBER 0x00906020L +#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.6b-dev [engine] XX xxx XXXX" #define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c index 567838f6c3..2d049e227b 100644 --- a/crypto/rand/md_rand.c +++ b/crypto/rand/md_rand.c @@ -141,10 +141,11 @@ static long md_count[2]={0,0}; static double entropy=0; static int initialized=0; -/* This should be set to 1 only when ssleay_rand_add() is called inside - an already locked state, so it doesn't try to lock and thereby cause - a hang. And it should always be reset back to 0 before unlocking. */ -static int add_do_not_lock=0; +static unsigned int crypto_lock_rand = 0; /* may be set only when a thread + * holds CRYPTO_LOCK_RAND + * (to prevent double locking) */ +static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */ + #ifdef PREDICT int rand_predictable=0; @@ -191,6 +192,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) long md_c[2]; unsigned char local_md[MD_DIGEST_LENGTH]; MD_CTX m; + int do_not_lock; /* * (Based on the rand(3) manpage) @@ -207,7 +209,10 @@ static void ssleay_rand_add(const void *buf, int num, double add) * hash function. */ - if (!add_do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); + /* check if we already have the lock */ + do_not_lock = crypto_lock_rand && (locking_thread == CRYPTO_thread_id()); + + if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); st_idx=state_index; /* use our own copies of the counters so that even @@ -239,7 +244,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) md_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0); - if (!add_do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); + if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); for (i=0; i 0) @@ -498,14 +508,37 @@ static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num) static int ssleay_rand_status(void) { int ret; + int do_not_lock; + /* check if we already have the lock + * (could happen if a RAND_poll() implementation calls RAND_status()) */ + do_not_lock = crypto_lock_rand && (locking_thread == CRYPTO_thread_id()); + + if (!do_not_lock) + { + CRYPTO_w_lock(CRYPTO_LOCK_RAND); + + /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ + crypto_lock_rand = 1; + locking_thread = CRYPTO_thread_id(); + } + if (!initialized) + { RAND_poll(); + initialized = 1; + } - CRYPTO_w_lock(CRYPTO_LOCK_RAND); - initialized = 1; ret = entropy >= ENTROPY_NEEDED; - CRYPTO_w_unlock(CRYPTO_LOCK_RAND); + if (!do_not_lock) + { + /* before unlocking, we must clear 'crypto_lock_rand' */ + crypto_lock_rand = 0; + locking_thread = 0; + + CRYPTO_w_unlock(CRYPTO_LOCK_RAND); + } + return ret; } diff --git a/doc/apps/rsautl.pod b/doc/apps/rsautl.pod index 7a334bc8d6..a7c1681d98 100644 --- a/doc/apps/rsautl.pod +++ b/doc/apps/rsautl.pod @@ -101,11 +101,11 @@ Sign some data using a private key: Recover the signed data - openssl rsautl -sign -in sig -inkey key.pem + openssl rsautl -verify -in sig -inkey key.pem Examine the raw signed data: - openssl rsautl -sign -in file -inkey key.pem -raw -hexdump + openssl rsautl -verify -in file -inkey key.pem -raw -hexdump 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ diff --git a/doc/apps/s_server.pod b/doc/apps/s_server.pod index 419383b55d..313116ab66 100644 --- a/doc/apps/s_server.pod +++ b/doc/apps/s_server.pod @@ -7,7 +7,7 @@ s_server - SSL/TLS server program =head1 SYNOPSIS -B B +B B [B<-accept port>] [B<-context id>] [B<-verify depth>] diff --git a/doc/crypto/bio.pod b/doc/crypto/bio.pod index 24f61dfb56..f9239226ff 100644 --- a/doc/crypto/bio.pod +++ b/doc/crypto/bio.pod @@ -40,7 +40,7 @@ BIO). =head1 SEE ALSO L, -L, +L, L, L, L, L, L, L, L, diff --git a/doc/ssl/SSL_CTX_load_verify_locations.pod b/doc/ssl/SSL_CTX_load_verify_locations.pod index 88f18bd5ff..0f63537e78 100644 --- a/doc/ssl/SSL_CTX_load_verify_locations.pod +++ b/doc/ssl/SSL_CTX_load_verify_locations.pod @@ -33,10 +33,6 @@ which can be used e.g. for descriptions of the certificates. The B is processed on execution of the SSL_CTX_load_verify_locations() function. -If on an TLS/SSL server no special setting is performed using *client_CA_list() -functions, the certificates contained in B are listed to the client -as available CAs during the TLS/SSL handshake. - If B is not NULL, it points to a directory containing CA certificates in PEM format. The files each contain one CA certificate. The files are looked up by the CA subject name hash value, which must hence be available. @@ -50,9 +46,6 @@ The certificates in B are only looked up when required, e.g. when building the certificate chain or when actually performing the verification of a peer certificate. -On a server, the certificates in B are not listed as available -CA certificates to a client during a TLS/SSL handshake. - When looking up CA certificates, the OpenSSL library will first search the certificates in B, then those in B. Certificate matching is done based on the subject name, the key identifier (if present), and the @@ -62,6 +55,13 @@ matching the parameters is found, the verification process will be performed; no other certificates for the same parameters will be searched in case of failure. +In server mode, when requesting a client certificate, the server must send +the list of CAs of which it will accept client certificates. This list +is not influenced by the contents of B or B and must +explicitely be set using the +L +family of functions. + When building its own certificate chain, an OpenSSL client/server will try to fill in missing certificates from B/B, if the certificate chain was not explicitly specified (see diff --git a/doc/ssl/SSL_CTX_set_client_CA_list.pod b/doc/ssl/SSL_CTX_set_client_CA_list.pod index 81e312761e..632b556d12 100644 --- a/doc/ssl/SSL_CTX_set_client_CA_list.pod +++ b/doc/ssl/SSL_CTX_set_client_CA_list.pod @@ -36,25 +36,23 @@ the chosen B, overriding the setting valid for B's SSL_CTX object. When a TLS/SSL server requests a client certificate (see B), it sends a list of CAs, for which -it will accept certificates, to the client. If no special list is provided, -the CAs available using the B option in -L -are sent. +it will accept certificates, to the client. -This list can be explicitly set using the SSL_CTX_set_client_CA_list() for +This list must explicitly be set using SSL_CTX_set_client_CA_list() for B and SSL_set_client_CA_list() for the specific B. The list specified overrides the previous setting. The CAs listed do not become trusted (B only contains the names, not the complete certificates); use L to additionally load them for verification. +If the list of acceptable CAs is compiled in a file, the +L +function can be used to help importing the necessary data. + SSL_CTX_add_client_CA() and SSL_add_client_CA() can be used to add additional items the list of client CAs. If no list was specified before using SSL_CTX_set_client_CA_list() or SSL_set_client_CA_list(), a new client -CA list for B or B (as appropriate) is opened. The CAs implicitly -specified using -L -are no longer used automatically. +CA list for B or B (as appropriate) is opened. These functions are only useful for TLS/SSL servers. @@ -80,11 +78,17 @@ to find out the reason. =back +=head1 EXAMPLES + +Scan all certificates in B and list them as acceptable CAs: + + SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile)); + =head1 SEE ALSO L, L, -L +L, L =cut diff --git a/doc/ssl/SSL_get_peer_certificate.pod b/doc/ssl/SSL_get_peer_certificate.pod index 1102c7fba9..18d1db5183 100644 --- a/doc/ssl/SSL_get_peer_certificate.pod +++ b/doc/ssl/SSL_get_peer_certificate.pod @@ -17,6 +17,12 @@ peer presented. If the peer did not present a certificate, NULL is returned. =head1 NOTES +Due to the protocol definition, a TLS/SSL server will always send a +certificate, if present. A client will only send a certificate when +explicitely requested to do so by the server (see +L). If an anonymous cipher +is used, no certificates are sent. + That a certificate is returned does not indicate information about the verification state, use L to check the verification state. @@ -43,6 +49,7 @@ The return value points to the certificate presented by the peer. =head1 SEE ALSO -L, L +L, L, +L =cut diff --git a/doc/ssl/SSL_shutdown.pod b/doc/ssl/SSL_shutdown.pod index 7988dd3c90..c4ae6704e7 100644 --- a/doc/ssl/SSL_shutdown.pod +++ b/doc/ssl/SSL_shutdown.pod @@ -66,7 +66,7 @@ Call SSL_get_error() with the return value B to find out the reason. L, L, L, L, -L, +L, L, L, L =cut diff --git a/test/Makefile.ssl b/test/Makefile.ssl index 2cfe3de410..1e975c5338 100644 --- a/test/Makefile.ssl +++ b/test/Makefile.ssl @@ -192,7 +192,7 @@ test_bn: @./$(BNTEST) >tmp.bntest @echo quit >>tmp.bntest @echo "running bc" - @) {if (/^test (.*)/) {print STDERR "\nverify $$1";} elsif (!/^0$$/) {die "\nFailed! bc: $$_";} else {print STDERR "."; $$i++;}} print STDERR "\n$$i tests passed\n"' + @) {if (/^test (.*)/) {print STDERR "\nverify $$1";} elsif (!/^0$$/) {die "\nFailed! bc: $$_";} else {print STDERR "."; $$i++;}} print STDERR "\n$$i tests passed\n"' @echo 'test a^b%c implementations' ./$(EXPTEST) diff --git a/test/bctest b/test/bctest index 17b75d4eca..fbe74ed90b 100755 --- a/test/bctest +++ b/test/bctest @@ -12,10 +12,22 @@ IFS=: -for dir in $PATH; do - bc="$dir/bc" +try_without_dir=true +# First we try "bc", then "$dir/bc" for each item in $PATH. +for dir in dummy:$PATH; do + if [ "$try_without_dir" = true ]; then + # first iteration + bc=bc + try_without_dir=false + else + # second and later iterations + bc="$dir/bc" + if [ ! -f "$bc" ]; then # '-x' is not available on Ultrix + bc='' + fi + fi - if [ -x "$bc" -a ! -d "$bc" ]; then + if [ ! "$bc" = '' ]; then failure=none -- 2.25.1