diff --git a/.gitignore b/.gitignore index 23c48be7..7324bda1 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ Makefile # Auto generated headers /crypto/buildinf.h +/apps/progs.h /crypto/include/internal/*_conf.h /openssl/include/opensslconf.h /util/domd @@ -52,12 +53,7 @@ Makefile /test/v3ext # Certain files that get created by tests on the fly -/test/*.ss -/test/*.srl -/test/.rnd -/test/test*.pem -/test/newkey.pem -/test/*.log +/test/test-runs /test/buildtest_* # Fuzz stuff. diff --git a/.travis-apt-pin.preferences b/.travis-apt-pin.preferences new file mode 100644 index 00000000..1797bd04 --- /dev/null +++ b/.travis-apt-pin.preferences @@ -0,0 +1,15 @@ +Package: clang-3.9 +Pin: release o=Ubuntu +Pin-Priority: -1 + +Package: libclang-common-3.9-dev +Pin: release o=Ubuntu +Pin-Priority: -1 + +Package: libclang1-3.9 +Pin: release o=Ubuntu +Pin-Priority: -1 + +Package: libllvm3.9v4 +Pin: release o=Ubuntu +Pin-Priority: -1 diff --git a/.travis.yml b/.travis.yml index 47784809..b5fc4431 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,70 +28,29 @@ env: - CONFIG_OPTS="no-engine no-shared --strict-warnings" BUILDONLY="yes" - CONFIG_OPTS="no-stdio --strict-warnings" BUILDONLY="yes" - CONFIG_OPTS="no-ec" BUILDONLY="yes" + - CONFIG_OPTS="no-asm --strict-warnings" BUILDONLY="yes" CHECKDOCS="yes" matrix: include: - os: linux - addons: - apt: - packages: - - clang-3.9 - sources: - - llvm-toolchain-trusty-3.9 - - ubuntu-toolchain-r-test compiler: clang-3.9 env: CONFIG_OPTS="--strict-warnings no-deprecated" BUILDONLY="yes" - os: linux compiler: gcc env: CONFIG_OPTS="--debug --coverage no-asm enable-rc5 enable-md2 enable-ec_nistp_64_gcc_128 enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers" COVERALLS="yes" - os: linux - addons: - apt: - packages: - - clang-3.9 - sources: - - llvm-toolchain-trusty-3.9 - - ubuntu-toolchain-r-test compiler: clang-3.9 env: CONFIG_OPTS="enable-asan" - os: linux - addons: - apt: - packages: - - clang-3.9 - sources: - - llvm-toolchain-trusty-3.9 - - ubuntu-toolchain-r-test compiler: clang-3.9 env: CONFIG_OPTS="enable-msan" - os: linux - addons: - apt: - packages: - - clang-3.9 - sources: - - llvm-toolchain-trusty-3.9 - - ubuntu-toolchain-r-test compiler: clang-3.9 env: CONFIG_OPTS="no-asm enable-ubsan enable-rc5 enable-md2 enable-ssl3 enable-ssl3-method -fno-sanitize=alignment" - os: linux - addons: - apt: - packages: - - clang-3.9 - sources: - - llvm-toolchain-trusty-3.9 - - ubuntu-toolchain-r-test compiler: clang-3.9 env: CONFIG_OPTS="no-asm enable-asan enable-rc5 enable-md2" - os: linux - addons: - apt: - packages: - - clang-3.9 - sources: - - llvm-toolchain-trusty-3.9 - - ubuntu-toolchain-r-test compiler: clang-3.9 env: CONFIG_OPTS="no-stdio" - os: linux @@ -160,7 +119,14 @@ before_script: export CROSS_COMPILE=${CC%%gcc}; unset CC; $srcdir/Configure mingw64 $CONFIG_OPTS -Wno-pedantic-ms-format; else - if which ccache >/dev/null && [ "$CC" != clang-3.9 ]; then + if [ "$CC" == clang-3.9 ]; then + sudo cp .travis-apt-pin.preferences /etc/apt/preferences.d/no-ubuntu-clang; + curl -sSL "http://apt.llvm.org/llvm-snapshot.gpg.key" | sudo -E apt-key add -; + echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main" | sudo tee -a /etc/apt/sources.list > /dev/null; + sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test"; + sudo -E apt-get -yq update; + sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install clang-3.9; + elif which ccache >/dev/null; then CC="ccache $CC"; fi; $srcdir/config -v $CONFIG_OPTS; @@ -187,8 +153,24 @@ script: else top=.; fi - - $make update - - $make + - if $make update; then + echo -e '+\057 MAKE UPDATE OK'; + else + echo -e '+\057 MAKE UPDATE FAILED'; false; + fi; + git diff --exit-code + - if [ -n "$CHECKDOCS" ]; then + if $make doc-nits; then + echo -e '+\057\057 MAKE DOC-NITS OK'; + else + echo -e '+\057\057 MAKE DOC-NITS FAILED'; false; + fi; + fi + - if $make ; then + echo -e '+\057\057\057 MAKE OK'; + else + echo -e '+\057\057\057 MAKE FAILED'; false; + fi; - if [ -z "$BUILDONLY" ]; then if [ -n "$CROSS_COMPILE" ]; then sudo apt-get -yq install wine; @@ -196,11 +178,19 @@ script: fi; HARNESS_VERBOSE=yes make test; else - $make build_tests; + if $make build_tests; then + echo -e '+\057\057\075 MAKE BUILD_TESTS OK'; + else + echo -e '+\057\057\075 MAKE BUILD_TESTS FAILEd'; false; + fi; fi - if [ -n "$DESTDIR" ]; then mkdir "../$DESTDIR"; - $make install install_docs DESTDIR="../$DESTDIR"; + if $make install install_docs DESTDIR="../$DESTDIR"; then + echo -e '+\057\057\057\057\057 MAKE INSTALL_DOCS OK'; + else + echo -e '+\057\057\057\057\057 MAKE INSTALL_DOCS FAILED'; false; + fi; fi - cd $top diff --git a/CHANGES b/CHANGES index 49f9f788..0ea1ad55 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,124 @@ OpenSSL CHANGES _______________ + This is a high-level summary of the most important changes. + For a full list of changes, see the git commit log; for example, + https://github.com/openssl/openssl/commits/ and pick the appropriate + release branch. + + Changes between 1.1.0g and 1.1.0h [27 Mar 2018] + + *) Constructed ASN.1 types with a recursive definition could exceed the stack + + Constructed ASN.1 types with a recursive definition (such as can be found + in PKCS7) could eventually exceed the stack given malicious input with + excessive recursion. This could result in a Denial Of Service attack. There + are no such structures used within SSL/TLS that come from untrusted sources + so this is considered safe. + + This issue was reported to OpenSSL on 4th January 2018 by the OSS-fuzz + project. + (CVE-2018-0739) + [Matt Caswell] + + *) Incorrect CRYPTO_memcmp on HP-UX PA-RISC + + Because of an implementation bug the PA-RISC CRYPTO_memcmp function is + effectively reduced to only comparing the least significant bit of each + byte. This allows an attacker to forge messages that would be considered as + authenticated in an amount of tries lower than that guaranteed by the + security claims of the scheme. The module can only be compiled by the + HP-UX assembler, so that only HP-UX PA-RISC targets are affected. + + This issue was reported to OpenSSL on 2nd March 2018 by Peter Waltenberg + (IBM). + (CVE-2018-0733) + [Andy Polyakov] + + *) Add a build target 'build_all_generated', to build all generated files + and only that. This can be used to prepare everything that requires + things like perl for a system that lacks perl and then move everything + to that system and do the rest of the build there. + [Richard Levitte] + + *) Backport SSL_OP_NO_RENGOTIATION + + OpenSSL 1.0.2 and below had the ability to disable renegotiation using the + (undocumented) SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS flag. Due to the opacity + changes this is no longer possible in 1.1.0. Therefore the new + SSL_OP_NO_RENEGOTIATION option from 1.1.1-dev has been backported to + 1.1.0 to provide equivalent functionality. + + Note that if an application built against 1.1.0h headers (or above) is run + using an older version of 1.1.0 (prior to 1.1.0h) then the option will be + accepted but nothing will happen, i.e. renegotiation will not be prevented. + [Matt Caswell] + + *) Removed the OS390-Unix config target. It relied on a script that doesn't + exist. + [Rich Salz] + + *) rsaz_1024_mul_avx2 overflow bug on x86_64 + + There is an overflow bug in the AVX2 Montgomery multiplication procedure + used in exponentiation with 1024-bit moduli. No EC algorithms are affected. + Analysis suggests that attacks against RSA and DSA as a result of this + defect would be very difficult to perform and are not believed likely. + Attacks against DH1024 are considered just feasible, because most of the + work necessary to deduce information about a private key may be performed + offline. The amount of resources required for such an attack would be + significant. However, for an attack on TLS to be meaningful, the server + would have to share the DH1024 private key among multiple clients, which is + no longer an option since CVE-2016-0701. + + This only affects processors that support the AVX2 but not ADX extensions + like Intel Haswell (4th generation). + + This issue was reported to OpenSSL by David Benjamin (Google). The issue + was originally found via the OSS-Fuzz project. + (CVE-2017-3738) + [Andy Polyakov] + + Changes between 1.1.0f and 1.1.0g [2 Nov 2017] + + *) bn_sqrx8x_internal carry bug on x86_64 + + There is a carry propagating bug in the x86_64 Montgomery squaring + procedure. No EC algorithms are affected. Analysis suggests that attacks + against RSA and DSA as a result of this defect would be very difficult to + perform and are not believed likely. Attacks against DH are considered just + feasible (although very difficult) because most of the work necessary to + deduce information about a private key may be performed offline. The amount + of resources required for such an attack would be very significant and + likely only accessible to a limited number of attackers. An attacker would + additionally need online access to an unpatched system using the target + private key in a scenario with persistent DH parameters and a private + key that is shared between multiple clients. + + This only affects processors that support the BMI1, BMI2 and ADX extensions + like Intel Broadwell (5th generation) and later or AMD Ryzen. + + This issue was reported to OpenSSL by the OSS-Fuzz project. + (CVE-2017-3736) + [Andy Polyakov] + + *) Malformed X.509 IPAddressFamily could cause OOB read + + If an X.509 certificate has a malformed IPAddressFamily extension, + OpenSSL could do a one-byte buffer overread. The most likely result + would be an erroneous display of the certificate in text format. + + This issue was reported to OpenSSL by the OSS-Fuzz project. + (CVE-2017-3735) + [Rich Salz] + + *) Ignore the '-named_curve auto' value for compatibility of applications + with OpenSSL 1.0.2. + [Tomas Mraz ] + + *) Support for SSL_OP_NO_ENCRYPT_THEN_MAC in SSL_CONF_cmd. + [Emilia Käsper] + Changes between 1.1.0e and 1.1.0f [25 May 2017] *) Have 'config' recognise 64-bit mingw and choose 'mingw64' as the target @@ -2944,8 +3062,11 @@ to work with OPENSSL_NO_SSL_INTERN defined. [Steve Henson] - *) Add SRP support. - [Tom Wu and Ben Laurie] + *) A long standing patch to add support for SRP from EdelWeb (Peter + Sylvester and Christophe Renou) was integrated. + [Christophe Renou , Peter Sylvester + , Tom Wu , and + Ben Laurie] *) Add functions to copy EVP_PKEY_METHOD and retrieve flags and id. [Steve Henson] diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index 39b89e7e..b49f04b5 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -204,6 +204,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3 -fomit-frame-pointer"), threads("-pthread")), + ex_libs => add(threads("-pthread")), bn_ops => "BN_LLONG", shared_cflag => "-fPIC", shared_ldflag => "-shared -static-libgcc", @@ -223,6 +224,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3"), threads("-pthread")), + ex_libs => add(threads("-pthread")), bn_ops => "SIXTY_FOUR_BIT_LONG", perlasm_scheme => "elf", shared_cflag => "-fPIC", @@ -268,6 +270,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3"), threads("-pthread")), + ex_libs => add(threads("-pthread")), bn_ops => "BN_LLONG RC4_CHAR", shared_cflag => "-fPIC", shared_ldflag => "-shared", @@ -432,7 +435,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3"), threads("-pthread")), - ex_libs => add("-Wl,+s -ldld"), + ex_libs => add("-Wl,+s -ldld", threads("-pthread")), bn_ops => "BN_LLONG", thread_scheme => "pthreads", dso_scheme => "dl", @@ -551,7 +554,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3"), threads("-pthread")), - ex_libs => add("-ldl"), + ex_libs => add("-ldl", threads("-pthread")), bn_ops => "SIXTY_FOUR_BIT", thread_scheme => "pthreads", dso_scheme => "dlfcn", @@ -568,7 +571,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3"), threads("-pthread")), - ex_libs => add("-ldl"), + ex_libs => add("-ldl", threads("-pthread")), bn_ops => "SIXTY_FOUR_BIT_LONG", thread_scheme => "pthreads", dso_scheme => "dlfcn", @@ -583,7 +586,7 @@ sub vms_info { "MPE/iX-gcc" => { inherit_from => [ "BASE_unix" ], cc => "gcc", - cflags => "-D_ENDIAN -DBN_DIV2W -O3 -D_POSIX_SOURCE -D_SOCKET_SOURCE -I/SYSLOG/PUB", + cflags => "-DBN_DIV2W -O3 -D_POSIX_SOURCE -D_SOCKET_SOURCE -I/SYSLOG/PUB", sys_id => "MPE", ex_libs => add("-L/SYSLOG/PUB -lsyslog -lsocket -lcurses"), thread_scheme => "(unknown)", @@ -599,7 +602,7 @@ sub vms_info { cc => "gcc", cflags => combine("-std=c9x -D_XOPEN_SOURCE=500 -D_OSF_SOURCE -O3", threads("-pthread")), - ex_libs => "-lrt", # for mlock(2) + ex_libs => add("-lrt", threads("-pthread")), # for mlock(2) bn_ops => "SIXTY_FOUR_BIT_LONG", thread_scheme => "pthreads", dso_scheme => "dlfcn", @@ -611,7 +614,7 @@ sub vms_info { cc => "cc", cflags => combine("-std1 -D_XOPEN_SOURCE=500 -D_OSF_SOURCE -tune host -fast -readonly_strings", threads("-pthread")), - ex_libs => "-lrt", # for mlock(2) + ex_libs => add("-lrt", threads("-pthread")), # for mlock(2) bn_ops => "SIXTY_FOUR_BIT_LONG", thread_scheme => "pthreads", dso_scheme => "dlfcn", @@ -632,7 +635,7 @@ sub vms_info { debug => "-O0 -g", release => "-O3"), threads("-pthread")), - ex_libs => add("-ldl"), + ex_libs => add("-ldl", threads("-pthread")), bn_ops => "BN_LLONG RC4_CHAR", thread_scheme => "pthreads", dso_scheme => "dlfcn", @@ -896,7 +899,7 @@ sub vms_info { # # ANDROID_NDK=/some/where/android-ndk-10d # CROSS_SYSROOT=$ANDROID_NDK/platforms/android-14/arch-arm - # CROSS_COMPILE=arm-linux-adroideabi- + # CROSS_COMPILE=arm-linux-androideabi- # PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuild/linux-x86_64/bin # "android" => { @@ -1177,6 +1180,7 @@ sub vms_info { debug => "-O0 -g", release => "-O"), threads("-pthread")), + ex_libs => add(threads("-pthread")), sys_id => "AIX", bn_ops => "BN_LLONG RC4_CHAR", thread_scheme => "pthreads", @@ -1194,6 +1198,7 @@ sub vms_info { debug => "-O0 -g", release => "-O"), threads("-pthread")), + ex_libs => add(threads("-pthread")), sys_id => "AIX", bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", thread_scheme => "pthreads", @@ -1251,18 +1256,6 @@ sub vms_info { thread_scheme => "(unknown)", }, -# OS/390 Unix an EBCDIC-based Unix system on IBM mainframe -# You need to compile using the c89.sh wrapper in the tools directory, because the -# IBM compiler does not like the -L switch after any object modules. -# - "OS390-Unix" => { - inherit_from => [ "BASE_unix" ], - cc => "c89.sh", - cflags => "-O -DB_ENDIAN -DCHARSET_EBCDIC -DNO_SYS_PARAM_H -D_ALL_SOURCE", - bn_ops => "THIRTY_TWO_BIT RC4_CHAR", - thread_scheme => "(unknown)", - }, - #### Visual C targets # # Win64 targets, WIN64I denotes IA-64 and WIN64A - AMD64 @@ -1590,6 +1583,7 @@ sub vms_info { inherit_from => [ "darwin-common", asm("ppc32_asm") ], cflags => add("-arch ppc -std=gnu9x -DB_ENDIAN -Wa,-force_cpusubtype_ALL"), perlasm_scheme => "osx32", + shared_cflag => add("-fno-common"), shared_ldflag => "-arch ppc -dynamiclib", }, "darwin64-ppc-cc" => { @@ -1659,7 +1653,7 @@ sub vms_info { cc => "gcc", cflags => combine("-DL_ENDIAN -O3 -fomit-frame-pointer -Wall", threads("-pthread")), - ex_libs => add("-ldl"), + ex_libs => add("-ldl", threads("-pthread")), bn_ops => "BN_LLONG", thread_scheme => "pthreads", dso_scheme => "dlfcn", @@ -1735,9 +1729,7 @@ sub vms_info { "uClinux-dist" => { inherit_from => [ "BASE_unix" ], cc => "$ENV{'CC'}", - cflags => combine("\$(CFLAGS)", - threads("-D_REENTRANT")), - plib_lflags => "\$(LDFLAGS)", + cflags => combine(threads("-D_REENTRANT")), ex_libs => add("\$(LDLIBS)"), bn_ops => "BN_LLONG", thread_scheme => "pthreads", @@ -1751,9 +1743,7 @@ sub vms_info { "uClinux-dist64" => { inherit_from => [ "BASE_unix" ], cc => "$ENV{'CC'}", - cflags => combine("\$(CFLAGS)", - threads("-D_REENTRANT")), - plib_lflags => "\$(LDFLAGS)", + cflags => combine(threads("-D_REENTRANT")), ex_libs => add("\$(LDLIBS)"), bn_ops => "SIXTY_FOUR_BIT_LONG", thread_scheme => "pthreads", diff --git a/Configurations/README b/Configurations/README index 47971c27..6e136454 100644 --- a/Configurations/README +++ b/Configurations/README @@ -18,10 +18,14 @@ configuration in diverse ways: Configurations of OpenSSL target platforms ========================================== -Target configurations are a collection of facts that we know about +Configuration targets are a collection of facts that we know about different platforms and their capabilities. We organise them in a hash table, where each entry represent a specific target. +Note that configuration target names must be unique across all config +files. The Configure script does check that a config file doesn't +have config targets that shadow config targets from other files. + In each table entry, the following keys are significant: inherit_from => Other targets to inherit values from. @@ -86,6 +90,27 @@ In each table entry, the following keys are significant: files. On unix, this defaults to "" (NOTE: this is here for future use, it's not implemented yet) + shlib_variant => A "variant" identifier inserted between the base + shared library name and the extension. On "unixy" + platforms (BSD, Linux, Solaris, MacOS/X, ...) this + supports installation of custom OpenSSL libraries + that don't conflict with other builds of OpenSSL + installed on the system. The variant identifier + becomes part of the SONAME of the library and also + any symbol versions (symbol versions are not used or + needed with MacOS/X). For example, on a system + where a default build would normally create the SSL + shared library as 'libssl.so -> libssl.so.1.1' with + the value of the symlink as the SONAME, a target + definition that sets 'shlib_variant => "-abc"' will + create 'libssl.so -> libssl-abc.so.1.1', again with + an SONAME equal to the value of the symlink. The + symbol versions associated with the variant library + would then be 'OPENSSL_ABC_' rather than + the default 'OPENSSL_'. The string inserted + into symbol versions is obtained by mapping all + letters in the "variant" identifier to upper case + and all non-alphanumeric characters to '_'. thread_scheme => The type of threads is used on the configured platform. Currently known diff --git a/Configurations/common.tmpl b/Configurations/common.tmpl index 9d7fbf2e..13ffe948 100644 --- a/Configurations/common.tmpl +++ b/Configurations/common.tmpl @@ -52,8 +52,7 @@ generator_incs => $unified_info{includes}->{$script}, generator_deps => $unified_info{depends}->{$script}, deps => $unified_info{depends}->{$src}, - incs => [ @{$unified_info{includes}->{$bin}}, - @{$unified_info{includes}->{$obj}} ], + incs => $unified_info{includes}->{$obj}, %opts); foreach (@{$unified_info{depends}->{$src}}) { dogenerate($_, $obj, $bin, %opts); @@ -74,8 +73,7 @@ $OUT .= src2obj(obj => $obj_no_o, srcs => $unified_info{sources}->{$obj}, deps => $unified_info{depends}->{$obj}, - incs => [ @{$unified_info{includes}->{$bin}}, - @{$unified_info{includes}->{$obj}} ], + incs => $unified_info{includes}->{$obj}, %opts); foreach ((@{$unified_info{sources}->{$obj}}, @{$unified_info{depends}->{$obj}})) { diff --git a/Configurations/descrip.mms.tmpl b/Configurations/descrip.mms.tmpl index c4eb0a88..7e3356f1 100644 --- a/Configurations/descrip.mms.tmpl +++ b/Configurations/descrip.mms.tmpl @@ -89,7 +89,7 @@ sub dependmagic { my $target = shift; - return "$target : build_generated\n\t\pipe \$(MMS) depend && \$(MMS) _$target\n_$target"; + return "$target : build_generated\n\t\pipe \$(MMS) \$(MMSQUALIFIERS) depend && \$(MMS) \$(MMSQUALIFIERS) _$target\n_$target"; } #use Data::Dumper; #print STDERR "DEBUG: before:\n", Dumper($unified_info{before}); @@ -144,6 +144,9 @@ BIN_SCRIPTS=[.tools]c_rehash.pl MISC_SCRIPTS=[.apps]CA.pl, [.apps]tsget.pl {- output_on() if $disabled{apps}; "" -} +APPS_OPENSSL={- use File::Spec::Functions; + catfile("apps","openssl") -} + # DESTDIR is for package builders so that they can configure for, say, # SYS$COMMON:[OPENSSL] and yet have everything installed in STAGING:[USER]. # In that case, configure with --prefix=SYS$COMMON:[OPENSSL] and then run @@ -261,12 +264,18 @@ build_programs_nodep : $(PROGRAMS), $(SCRIPTS) # Kept around for backward compatibility build_apps build_tests : build_programs +# Convenience target to prebuild all generated files, not just the mandatory +# ones +build_all_generated : $(GENERATED_MANDATORY) $(GENERATED) + test : tests {- dependmagic('tests'); -} : build_programs_nodep, build_engines_nodep @ ! {- output_off() if $disabled{tests}; "" -} SET DEFAULT [.test]{- move("test") -} + CREATE/DIR [.test-runs] DEFINE SRCTOP {- sourcedir() -} DEFINE BLDTOP {- builddir() -} + DEFINE RESULT_D {- builddir(qw(test test-runs)) -} DEFINE OPENSSL_ENGINES {- builddir("engines") -} DEFINE OPENSSL_DEBUG_MEMORY "on" IF "$(VERBOSE)" .NES. "" THEN DEFINE VERBOSE "$(VERBOSE)" diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index 2cc37cd2..40cf2c3d 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -8,6 +8,7 @@ our $exeext = $target{exe_extension} || ""; our $libext = $target{lib_extension} || ".a"; our $shlibext = $target{shared_extension} || ".so"; + our $shlibvariant = $target{shlib_variant} || ""; our $shlibextsimple = $target{shared_extension_simple} || ".so"; our $shlibextimport = $target{shared_import_extension} || ""; our $dsoext = $target{dso_extension} || ".so"; @@ -40,7 +41,7 @@ sub shlib { return () if $disabled{shared}; my $lib = shift; - return $unified_info{sharednames}->{$lib} . $shlibext; + return $unified_info{sharednames}->{$lib}. $shlibvariant. $shlibext; } sub shlib_simple { return () if $disabled{shared}; @@ -97,8 +98,7 @@ DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; } {- output_on() if $disabled{makedepend}; "" -} GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -} GENERATED={- join(" ", - ( map { (my $x = $_) =~ s|\.S$|\.s|; $x } - grep { defined $unified_info{generate}->{$_} } + ( grep { defined $unified_info{generate}->{$_} } map { @{$unified_info{sources}->{$_}} } grep { /\.o$/ } keys %{$unified_info{sources}} ), ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -} @@ -113,6 +113,9 @@ BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash MISC_SCRIPTS=$(BLDDIR)/apps/CA.pl $(BLDDIR)/apps/tsget {- output_on() if $disabled{apps}; "" -} +APPS_OPENSSL={- use File::Spec::Functions; + catfile("apps","openssl") -} + # DESTDIR is for package builders so that they can configure for, say, # /usr/ and yet have everything installed to /tmp/somedir/usr/. # Normally it is left empty. @@ -204,9 +207,8 @@ TARFILE= ../$(NAME).tar # order to be excused from maintaining a separate set of architecture # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC # gcc, then the driver will automatically translate it to -xarch=v8plus -# and pass it down to assembler. -AS=$(CC) -c -ASFLAG=$(CFLAGS) +# and pass it down to assembler. In any case, we do not define AS or +# ASFLAGS for this reason. PERLASM_SCHEME= {- $target{perlasm_scheme} -} # For x86 assembler: Set PROCESSOR to 386 if you want to support @@ -237,15 +239,21 @@ build_programs_nodep: $(PROGRAMS) $(SCRIPTS) # Kept around for backward compatibility build_apps build_tests: build_programs +# Convenience target to prebuild all generated files, not just the mandatory +# ones +build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) + test: tests {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils @ : {- output_off() if $disabled{tests}; "" -} ( cd test; \ + mkdir -p test-runs; \ SRCTOP=../$(SRCDIR) \ BLDTOP=../$(BLDDIR) \ + RESULT_D=test-runs \ PERL="$(PERL)" \ EXE_EXT={- $exeext -} \ - OPENSSL_ENGINES=../$(BLDDIR)/engines \ + OPENSSL_ENGINES=`cd ../$(BLDDIR)/engines; pwd` \ OPENSSL_DEBUG_MEMORY=on \ $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) ) @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -} @@ -285,7 +293,7 @@ clean: libclean -$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"` $(RM) core $(RM) tags TAGS doc-nits - $(RM) test/.rnd + $(RM) -r test/test-runs $(RM) openssl.pc libcrypto.pc libssl.pc -$(RM) `find . -type l -a \! -path "./.git/*"` $(RM) $(TARFILE) @@ -592,19 +600,9 @@ doc-nits: lint: lint -DLINT $(INCLUDES) $(SRCS) -{- # because the program apps/openssl has object files as sources, and - # they then have the corresponding C files as source, we need to chain - # the lookups in %unified_info - my $apps_openssl = catfile("apps","openssl"); - our @openssl_source = map { @{$unified_info{sources}->{$_}} } - @{$unified_info{sources}->{$apps_openssl}}; - ""; -} generate_apps: ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \ < apps/openssl.cnf > apps/openssl-vms.cnf ) - ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b apps/progs.pl \ - {- join(" ", @openssl_source) -} \ - > apps/progs.h ) generate_crypto_bn: ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h ) @@ -656,9 +654,12 @@ tags TAGS: FORCE # Release targets (note: only available on Unix) ##################### +# If your tar command doesn't support --owner and --group, make sure to +# use one that does, for example GNU tar TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf - PREPARE_CMD=: tar: + set -e; \ TMPDIR=/var/tmp/openssl-copy.$$$$; \ DISTDIR=$(NAME); \ mkdir -p $$TMPDIR/$$DISTDIR; \ @@ -669,12 +670,12 @@ tar: mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \ cp $$F $$TMPDIR/$$DISTDIR/$$F; \ done); \ - (cd $$TMPDIR; \ + (cd $$TMPDIR/$$DISTDIR; \ $(PREPARE_CMD); \ - find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \ - find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \ - find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \ - $(TAR_COMMAND) $$DISTDIR) \ + find . -type d -print | xargs chmod 755; \ + find . -type f -print | xargs chmod a+r; \ + find . -type f -perm -0100 -print | xargs chmod a+x); \ + (cd $$TMPDIR; $(TAR_COMMAND) $$DISTDIR) \ | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \ rm -rf $$TMPDIR cd $(SRCDIR); ls -l $(TARFILE).gz @@ -722,7 +723,6 @@ libssl.pc: echo 'Version: '$(VERSION); \ echo 'Requires.private: libcrypto'; \ echo 'Libs: -L$${libdir} -lssl'; \ - echo 'Libs.private: $(EX_LIBS)'; \ echo 'Cflags: -I$${includedir}' ) > libssl.pc openssl.pc: @@ -799,20 +799,6 @@ EOF } if (defined($generator)) { - # If the target is named foo.S in build.info, we want to - # end up generating foo.s in two steps. - if ($args{src} =~ /\.S$/) { - (my $target = $args{src}) =~ s|\.S$|.s|; - return <<"EOF"; -$target: $args{generator}->[0] $deps - ( trap "rm -f \$@.*" INT 0; \\ - $generator \$@.S; \\ - \$(CC) $incs \$(CFLAGS) -E \$@.S | \\ - \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\ - mv -f \$@.i \$@ ) -EOF - } - # Otherwise.... return <<"EOF"; $args{src}: $args{generator}->[0] $deps $generator \$@ @@ -820,7 +806,7 @@ EOF } return <<"EOF"; $args{src}: $args{generator}->[0] $deps - \$(CC) $incs \$(CFLAGS) -E \$< | \\ + \$(CC) $incs \$(CFLAGS) -E $args{generator}->[0] | \\ \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@ EOF } @@ -832,12 +818,7 @@ EOF sub src2obj { my %args = @_; my $obj = $args{obj}; - my @srcs = map { if ($unified_info{generate}->{$_}) { - (my $x = $_) =~ s/\.S$/.s/; $x - } else { - $_ - } - } ( @{$args{srcs}} ); + my @srcs = @{$args{srcs}}; my $srcs = join(" ", @srcs); my $deps = join(" ", @srcs, @{$args{deps}}); my $incs = join("", map { " -I".$_ } @{$args{incs}}); @@ -850,11 +831,30 @@ EOF dso => '$(DSO_CFLAGS)', bin => '$(BIN_CFLAGS)' } -> {$args{intent}}; my $makedepprog = $config{makedepprog}; - my $recipe = <<"EOF"; -$obj$objext: $deps -EOF - if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) { + my $recipe; + # extension-specific rules + if (grep /\.s$/, @srcs) { $recipe .= <<"EOF"; +$obj$objext: $deps + \$(CC) \$(CFLAGS) $ecflags -c -o \$\@ $srcs +EOF + } elsif (grep /\.S$/, @srcs) { + # In case one wonders why not just $(CC) -c file.S. While it + # does work with contemporary compilers, there are some legacy + # ones that get it wrong. Hence the elaborate scheme... We + # don't care to maintain dependecy lists, because dependency + # is rather weak, at most one header file that lists constants + # which are assigned in ascending order. + $recipe .= <<"EOF"; +$obj$objext: $deps + ( trap "rm -f \$@.*" INT 0; \\ + \$(CPP) $incs \$(CFLAGS) $ecflags $srcs | \\ + \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.s && \\ + \$(CC) \$(CFLAGS) $ecflags -c -o \$\@ \$@.s ) +EOF + } elsif (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) { + $recipe .= <<"EOF"; +$obj$objext: $deps \$(CC) $incs \$(CFLAGS) $ecflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs \@touch $obj$depext.tmp \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\ @@ -865,6 +865,7 @@ EOF EOF } else { $recipe .= <<"EOF"; +$obj$objext: $deps \$(CC) $incs \$(CFLAGS) $ecflags -c -o \$\@ $srcs EOF if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) { @@ -900,6 +901,7 @@ EOF my $shlib_target = $target{shared_target}; my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : ""; my $target = shlib_simple($lib); + my $target_full = shlib($lib); return <<"EOF" # With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact # that two files get produced, {shlibname}.dll and {libname}.dll.a. @@ -914,27 +916,28 @@ $target: $lib$libext $deps $ordinalsfile PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\ INSTALLTOP='\$(INSTALLTOP)' LIBDIR='\$(LIBDIR)' \\ LIBDEPS='\$(PLIB_LDFLAGS) '"$linklibs"' \$(EX_LIBS)' \\ - LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\ - LIBCOMPATVERSIONS=';\$(SHLIB_VERSION_HISTORY)' \\ + LIBNAME=$libname SHLIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\ + STLIBNAME=$lib$libext \\ + SHLIBNAME=$target SHLIBNAME_FULL=$target_full \\ CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(LIB_CFLAGS)' \\ - LDFLAGS='\$(LDFLAGS)' \\ - SHARED_LDFLAGS='\$(LIB_LDFLAGS)' SHLIB_EXT=$shlibext \\ + LDFLAGS='\$(LDFLAGS)' SHARED_LDFLAGS='\$(LIB_LDFLAGS)' \\ RC='\$(RC)' SHARED_RCFLAGS='\$(RCFLAGS)' \\ link_shlib.$shlib_target EOF . (windowsdll() ? <<"EOF" : ""); rm -f apps/$shlib$shlibext rm -f test/$shlib$shlibext + rm -f fuzz/$shlib$shlibext cp -p $shlib$shlibext apps/ cp -p $shlib$shlibext test/ + cp -p $shlib$shlibext fuzz/ EOF } sub obj2dso { my %args = @_; - my $lib = $args{lib}; - my $libd = dirname($lib); - my $libn = basename($lib); - (my $libname = $libn) =~ s/^lib//; + my $dso = $args{lib}; + my $dsod = dirname($dso); + my $dson = basename($dso); my $shlibdeps = join("", map { my $d = dirname($_); my $f = basename($_); (my $l = $f) =~ s/^lib//; @@ -942,17 +945,16 @@ EOF my $deps = join(" ",compute_lib_depends(@{$args{deps}})); my $shlib_target = $target{shared_target}; my $objs = join(" ", map { $_.$objext } @{$args{objs}}); - my $target = dso($lib); + my $target = dso($dso); return <<"EOF"; $target: $objs $deps \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\ PLATFORM=\$(PLATFORM) \\ - PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$libd" \\ + PERL="\$(PERL)" SRCDIR='\$(SRCDIR)' DSTDIR="$dsod" \\ LIBDEPS='\$(PLIB_LDFLAGS) '"$shlibdeps"' \$(EX_LIBS)' \\ - LIBNAME=$libname LDFLAGS='\$(LDFLAGS)' \\ + SHLIBNAME_FULL=$target LDFLAGS='\$(LDFLAGS)' \\ CC='\$(CC)' CFLAGS='\$(CFLAGS) \$(DSO_CFLAGS)' \\ SHARED_LDFLAGS='\$(DSO_LDFLAGS)' \\ - SHLIB_EXT=$dsoext \\ LIBEXTRAS="$objs" \\ link_dso.$shlib_target EOF diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl index 77104cfa..e3e213f6 100644 --- a/Configurations/windows-makefile.tmpl +++ b/Configurations/windows-makefile.tmpl @@ -72,7 +72,7 @@ SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -} SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -} ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -} ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{engines}}) -} -PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{programs}}) -} +PROGRAMS={- our @PROGRAMS = map { $_.$exeext } @{$unified_info{programs}}; join(" ", @PROGRAMS) -} PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -} SCRIPTS={- join(" ", @{$unified_info{scripts}}) -} {- output_off() if $disabled{makedepend}; "" -} @@ -100,16 +100,20 @@ BIN_SCRIPTS=$(BLDDIR)\tools\c_rehash.pl MISC_SCRIPTS=$(BLDDIR)\apps\CA.pl $(BLDDIR)\apps\tsget.pl {- output_on() if $disabled{apps}; "" -} +APPS_OPENSSL={- use File::Spec::Functions; + catfile("apps","openssl") -} + # Do not edit these manually. Use Configure with --prefix or --openssldir # to change this! Short explanation in the top comment in Configure INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet # use File::Spec::Functions qw(:DEFAULT splitpath); - our $prefix = $config{prefix} || "$win_installroot\\OpenSSL"; + our $prefix = canonpath($config{prefix} + || "$win_installroot\\OpenSSL"); our ($prefix_dev, $prefix_dir, $prefix_file) = splitpath($prefix, 1); $prefix_dev -} -INSTALLTOP_dir={- $prefix_dir -} +INSTALLTOP_dir={- canonpath($prefix_dir) -} OPENSSLDIR_dev={- # # The logic here is that if no --openssldir was given, # OPENSSLDIR will get the value from $prefix plus "/ssl". @@ -123,13 +127,13 @@ OPENSSLDIR_dev={- # our $openssldir = $config{openssldir} ? (file_name_is_absolute($config{openssldir}) ? - $config{openssldir} + canonpath($config{openssldir}) : catdir($prefix, $config{openssldir})) - : "$win_commonroot\\SSL"; + : canonpath("$win_commonroot\\SSL"); our ($openssldir_dev, $openssldir_dir, $openssldir_file) = splitpath($openssldir, 1); $openssldir_dev -} -OPENSSLDIR_dir={- $openssldir_dir -} +OPENSSLDIR_dir={- canonpath($openssldir_dir) -} LIBDIR={- our $libdir = $config{libdir} || "lib"; $libdir -} ENGINESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath); @@ -137,7 +141,7 @@ ENGINESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath); our ($enginesdir_dev, $enginesdir_dir, $enginesdir_file) = splitpath($enginesdir, 1); $enginesdir_dev -} -ENGINESDIR_dir={- $enginesdir_dir -} +ENGINESDIR_dir={- canonpath($enginesdir_dir) -} !IF "$(DESTDIR)" != "" INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir) OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir) @@ -197,12 +201,19 @@ build_programs_nodep: $(PROGRAMS) $(SCRIPTS) # Kept around for backward compatibility build_apps build_tests: build_programs +# Convenience target to prebuild all generated files, not just the mandatory +# ones +build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) + test: tests {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep @rem {- output_off() if $disabled{tests}; "" -} + -mkdir $(BLDDIR)\test\test-runs set SRCTOP=$(SRCDIR) set BLDTOP=$(BLDDIR) + set RESULT_D=$(BLDDIR)\test\test-runs set PERL=$(PERL) + set OPENSSL_ENGINES=$(MAKEDIR)\engines set OPENSSL_DEBUG_MEMORY=on "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS) @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -} @@ -225,11 +236,14 @@ libclean: "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS) "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS) "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS) + "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """fuzz/$$1.*"""; } @ARGV" $(SHLIBS) -del /Q /F $(LIBS) -del /Q ossl_static.pdb clean: libclean - -del /Q /F $(PROGRAMS) $(ENGINES) $(SCRIPTS) + {- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) -} + -del /Q /F $(ENGINES) + -del /Q /F $(SCRIPTS) -del /Q /F $(GENERATED) -del /Q /S /F *.d -del /Q /S /F *.obj @@ -355,7 +369,8 @@ configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{b sub generatesrc { my %args = @_; (my $target = $args{src}) =~ s/\.[sS]$/.asm/; - my $generator = '"'.join('" "', @{$args{generator}}).'"'; + my ($gen0, @gens) = @{$args{generator}}; + my $generator = '"'.$gen0.'"'.join('', map { " $_" } @gens); my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}}); my $incs = join("", map { " /I \"$_\"" } @{$args{incs}}); my $deps = @{$args{deps}} ? @@ -445,9 +460,7 @@ s/^Note: including file: *//; END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" } << $obj$objext: $obj$depext - \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ @<< -$srcs -<< + \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ $srcs EOF return <<"EOF" if ($disabled{makedepend}); $obj$objext: $deps @@ -493,8 +506,10 @@ $objs $shlib.res$linklibs \$(EX_LIBS) \$(MT) \$(MTFLAGS) \$(MTINFLAG)$shlib$shlibext.manifest \$(MTOUTFLAG)$shlib$shlibext IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext + IF EXIST fuzz\\$shlib$shlibext DEL /Q /F fuzz\\$shlib$shlibext COPY $shlib$shlibext apps COPY $shlib$shlibext test + COPY $shlib$shlibext fuzz EOF } sub obj2dso { diff --git a/Configure b/Configure index 2520d7e1..c0033643 100644 --- a/Configure +++ b/Configure @@ -1,6 +1,6 @@ #! /usr/bin/env perl # -*- mode: perl; -*- -# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the OpenSSL license (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -11,10 +11,12 @@ use 5.10.0; use strict; +use FindBin; +use lib "$FindBin::Bin/util/perl"; use File::Basename; use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/; use File::Path qw/mkpath/; -use if $^O ne "VMS", 'File::Glob' => qw/glob/; +use OpenSSL::Glob; # see INSTALL for instructions. @@ -60,8 +62,7 @@ my $usage="Usage: Configure [no- ...] [enable- ...] [-Dxxx] [-lx # library and will be loaded in run-time by the OpenSSL library. # sctp include SCTP support # enable-weak-ssl-ciphers -# Enable weak ciphers that are disabled by default. This currently -# only includes RC4 based ciphers. +# Enable weak ciphers that are disabled by default. # 386 generate 80386 code in assembly modules # no-sse2 disables IA-32 SSE2 code in assembly modules, the above # mentioned '386' option implies this one @@ -116,6 +117,9 @@ my $gcc_devteam_warn = "-DDEBUG_UNUSED" # but 'long long' type. . " -DPEDANTIC -pedantic -Wno-long-long" . " -Wall" + . " -Wextra" + . " -Wno-unused-parameter" + . " -Wno-missing-field-initializers" . " -Wsign-compare" . " -Wmissing-prototypes" . " -Wshadow" @@ -136,15 +140,11 @@ my $gcc_devteam_warn = "-DDEBUG_UNUSED" # -Wextended-offsetof -- no, needed in CMS ASN1 code my $clang_devteam_warn = "" . " -Qunused-arguments" - . " -Wextra" - . " -Wno-unused-parameter" - . " -Wno-missing-field-initializers" . " -Wno-language-extension-token" . " -Wno-extended-offsetof" . " -Wconditional-uninitialized" . " -Wincompatible-pointer-types-discards-qualifiers" . " -Wmissing-variable-declarations" - . " -Wundef" ; # This adds backtrace information to the memory leak info. Is only used @@ -461,31 +461,10 @@ my @disable_cascades = ( sub { 0 == scalar grep { !$disabled{$_} } @dtls } => [ "dtls" ], - # SSL 3.0, (D)TLS 1.0 and TLS 1.1 require MD5 and SHA - "md5" => [ "ssl", "tls1", "tls1_1", "dtls1" ], - "sha" => [ "ssl", "tls1", "tls1_1", "dtls1" ], - - # Additionally, SSL 3.0 requires either RSA or DSA+DH - sub { $disabled{rsa} - && ($disabled{dsa} || $disabled{dh}); } - => [ "ssl" ], - - # (D)TLS 1.0 and TLS 1.1 also require either RSA or DSA+DH - # or ECDSA + ECDH. (D)TLS 1.2 has this requirement as well. - # (XXX: We don't support PSK-only builds). - sub { $disabled{rsa} - && ($disabled{dsa} || $disabled{dh}) - && ($disabled{ecdsa} || $disabled{ecdh}); } - => [ "tls1", "tls1_1", "tls1_2", - "dtls1", "dtls1_2" ], - "tls" => [ @tls ], sub { 0 == scalar grep { !$disabled{$_} } @tls } => [ "tls" ], - # SRP and HEARTBEATS require TLSEXT - "tlsext" => [ "srp", "heartbeats" ], - "crypto-mdebug" => [ "crypto-mdebug-backtrace" ], # Without DSO, we can't load dynamic engines, so don't build them dynamic @@ -499,7 +478,7 @@ my @disable_cascades = ( # no-autoalginit is only useful when building non-shared "autoalginit" => [ "shared", "apps" ], - "stdio" => [ "apps", "capieng" ], + "stdio" => [ "apps", "capieng", "egd" ], "apps" => [ "tests" ], "comp" => [ "zlib" ], sub { !$disabled{"unit-test"} } => [ "heartbeats" ], @@ -529,8 +508,6 @@ while ((my $first, my $second) = (shift @list, shift @list)) { # To remove something from %disabled, use "enable-foo". # For symmetry, "disable-foo" is a synonym for "no-foo". -my $no_sse2=0; - &usage if ($#ARGV < 0); my $user_cflags=""; @@ -880,7 +857,7 @@ foreach (sort (keys %disabled)) elsif (/^zlib-dynamic$/) { } elsif (/^sse2$/) - { $no_sse2 = 1; } + { } elsif (/^engine$/) { @{$config{dirs}} = grep !/^engines$/, @{$config{dirs}}; @@ -913,8 +890,6 @@ foreach (sort (keys %disabled)) { push @{$config{openssl_other_defines}}, "OPENSSL_NO_$WHAT"; print " OPENSSL_NO_$WHAT"; - - if (/^err$/) { push @user_defines, "OPENSSL_NO_ERR"; } } } @@ -1168,7 +1143,7 @@ unless ($disabled{asm}) { # bn-586 is the only one implementing bn_*_part_words push @{$config{defines}}, "OPENSSL_BN_ASM_PART_WORDS" if ($target{bn_asm_src} =~ /bn-586/); - push @{$config{defines}}, "OPENSSL_IA32_SSE2" if (!$no_sse2 && $target{bn_asm_src} =~ /86/); + push @{$config{defines}}, "OPENSSL_IA32_SSE2" if (!$disabled{sse2} && $target{bn_asm_src} =~ /86/); push @{$config{defines}}, "OPENSSL_BN_ASM_MONT" if ($target{bn_asm_src} =~ /-mont/); push @{$config{defines}}, "OPENSSL_BN_ASM_MONT5" if ($target{bn_asm_src} =~ /-mont5/); @@ -1200,7 +1175,7 @@ unless ($disabled{asm}) { push @{$config{defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//); # aes-xts.fake indicates presence of AES_xts_[en|de]crypt... push @{$config{defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//); - $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($no_sse2); + $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2}); push @{$config{defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/); push @{$config{defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/); } @@ -1225,29 +1200,29 @@ unless ($disabled{asm}) { } } -my $ecc = $target{cc}; -if ($^O ne "VMS" && !$disabled{makedepend}) { - # Is the compiler gcc or clang? $ecc is used below to see if - # error-checking can be turned on. - my $ccpcc = "$config{cross_compile_prefix}$target{cc}"; - open(PIPE, "$ccpcc --version 2>&1 |"); - my $lines = 2; - while ( ) { - # Find the version number and save the major. - m|(?:.*)\b(\d+)\.\d+\.\d+\b(?:.*)|; - my $compiler_major = $1; - # We know that GNU C version 3 and up as well as all clang - # versions support dependency generation - $config{makedepprog} = $ccpcc - if (/clang/ || (/gcc/ && $compiler_major >= 3)); - $ecc = "clang" if /clang/; - $ecc = "gcc" if /gcc/; - last if ($config{makedepprog} || !$lines--); +my %predefined; + +if ($^O ne "VMS") { + my $cc = "$config{cross_compile_prefix}$target{cc}"; + + # collect compiler pre-defines from gcc or gcc-alike... + open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |"); + while () { + m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last; + $predefined{$1} = $2 // ""; } close(PIPE); - $config{makedepprog} = which('makedepend') unless $config{makedepprog}; - $disabled{makedepend} = "unavailable" unless $config{makedepprog}; + if (!$disabled{makedepend}) { + # We know that GNU C version 3 and up as well as all clang + # versions support dependency generation + if ($predefined{__GNUC__} >= 3) { + $config{makedepprog} = $cc; + } else { + $config{makedepprog} = which('makedepend'); + $disabled{makedepend} = "unavailable" unless $config{makedepprog}; + } + } } @@ -1292,13 +1267,13 @@ if (defined($config{api})) { if ($strict_warnings) { my $wopt; - die "ERROR --strict-warnings requires gcc or clang" - unless $ecc eq 'gcc' || $ecc eq 'clang'; + die "ERROR --strict-warnings requires gcc or gcc-alike" + unless defined($predefined{__GNUC__}); foreach $wopt (split /\s+/, $gcc_devteam_warn) { $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/) } - if ($ecc eq "clang") + if (defined($predefined{__clang__})) { foreach $wopt (split /\s+/, $clang_devteam_warn) { @@ -1355,7 +1330,6 @@ my %unified_info = (); my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO}); if ($builder eq "unified") { - use lib catdir(dirname(__FILE__),"util"); use with_fallback qw(Text::Template); sub cleandir { @@ -1478,9 +1452,15 @@ if ($builder eq "unified") { my %sharednames = (); my %generate = (); + # We want to detect configdata.pm in the source tree, so we + # don't use it if the build tree is different. + my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir); + push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f); - my $template = Text::Template->new(TYPE => 'FILE', - SOURCE => catfile($sourced, $f)); + my $template = + Text::Template->new(TYPE => 'FILE', + SOURCE => catfile($sourced, $f), + PREPEND => qq{use lib "$FindBin::Bin/util/perl";}); die "Something went wrong with $sourced/$f: $!\n" unless $template; my @text = split /^/m, @@ -1781,7 +1761,7 @@ EOF # If it isn't in the source tree, we assume it's generated # in the build tree - if (! -f $s) { + if ($s eq $src_configdata || ! -f $s || $generate{$_}) { $s = cleanfile($buildd, $_, $blddir); } # We recognise C and asm files @@ -1807,7 +1787,7 @@ EOF # If it isn't in the source tree, we assume it's generated # in the build tree - if (! -f $s) { + if ($s eq $src_configdata || ! -f $s || $generate{$_}) { $s = cleanfile($buildd, $_, $blddir); } # We recognise C and asm files @@ -1842,7 +1822,7 @@ EOF # If the destination doesn't exist in source, it can only be # a generated file in the build tree. - if ($ddest ne "" && ! -f $ddest) { + if ($ddest ne "" && ($ddest eq $src_configdata || ! -f $ddest)) { $ddest = cleanfile($buildd, $_, $blddir); if ($unified_info{rename}->{$ddest}) { $ddest = $unified_info{rename}->{$ddest}; @@ -1856,7 +1836,8 @@ EOF # in the build tree rather than the source tree, and assume # and that there are lines to build it in a BEGINRAW..ENDRAW # section or in the Makefile template. - if (! -f $d + if ($d eq $src_configdata + || ! -f $d || (grep { $d eq $_ } map { cleanfile($srcdir, $_, $blddir) } grep { /\.h$/ } keys %{$unified_info{generate}})) { @@ -1867,13 +1848,6 @@ EOF $d = $unified_info{rename}->{$d}; } $unified_info{depends}->{$ddest}->{$d} = 1; - # If we depend on a header file or a perl module, let's make - # sure it can get included - if ($dest ne "" && $d =~ /\.(h|pm)$/) { - my $i = dirname($d); - push @{$unified_info{includes}->{$ddest}->{source}}, $i - unless grep { $_ eq $i } @{$unified_info{includes}->{$ddest}->{source}}; - } } } @@ -1883,7 +1857,7 @@ EOF # If the destination doesn't exist in source, it can only be # a generated file in the build tree. - if (! -f $ddest) { + if ($ddest eq $src_configdata || ! -f $ddest) { $ddest = cleanfile($buildd, $_, $blddir); if ($unified_info{rename}->{$ddest}) { $ddest = $unified_info{rename}->{$ddest}; @@ -1900,6 +1874,43 @@ EOF } } + # Massage the result + + # If we depend on a header file or a perl module, add an inclusion of + # its directory to allow smoothe inclusion + foreach my $dest (keys %{$unified_info{depends}}) { + next if $dest eq ""; + foreach my $d (keys %{$unified_info{depends}->{$dest}}) { + next unless $d =~ /\.(h|pm)$/; + my $i = dirname($d); + my $spot = + $d eq "configdata.pm" || defined($unified_info{generate}->{$d}) + ? 'build' : 'source'; + push @{$unified_info{includes}->{$dest}->{$spot}}, $i + unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}}; + } + } + + # Trickle down includes placed on libraries, engines and programs to + # their sources (i.e. object files) + foreach my $dest (keys %{$unified_info{engines}}, + keys %{$unified_info{libraries}}, + keys %{$unified_info{programs}}) { + foreach my $k (("source", "build")) { + next unless defined($unified_info{includes}->{$dest}->{$k}); + my @incs = reverse @{$unified_info{includes}->{$dest}->{$k}}; + foreach my $obj (grep /\.o$/, + (keys %{$unified_info{sources}->{$dest}}, + keys %{$unified_info{shared_sources}->{$dest}})) { + foreach my $inc (@incs) { + unshift @{$unified_info{includes}->{$obj}->{$k}}, $inc + unless grep { $_ eq $inc } @{$unified_info{includes}->{$obj}->{$k}}; + } + } + } + delete $unified_info{includes}->{$dest}; + } + ### Make unified_info a bit more efficient # One level structures foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) { @@ -1915,8 +1926,9 @@ EOF # Includes foreach my $dest (sort keys %{$unified_info{includes}}) { if (defined($unified_info{includes}->{$dest}->{build})) { - my @source_includes = - ( @{$unified_info{includes}->{$dest}->{source}} ); + my @source_includes = (); + @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} ) + if defined($unified_info{includes}->{$dest}->{source}); $unified_info{includes}->{$dest} = [ @{$unified_info{includes}->{$dest}->{build}} ]; foreach my $inc (@source_includes) { @@ -2134,14 +2146,6 @@ or position independent code, please let us know (but please first make sure you have tried with a current version of OpenSSL). EOF -print <<"EOF" if (-f catfile($srcdir, "configdata.pm") && $srcdir ne $blddir); - -WARNING: there are indications that another build was made in the source -directory. This build may have picked up artifacts from that build, the -safest course of action is to clean the source directory and redo this -configuration. -EOF - exit(0); ###################################################################### @@ -2291,6 +2295,17 @@ sub read_config { eval $content; warn $@ if $@; } + my %preexisting = (); + foreach (sort keys %targets) { + $preexisting{$_} = 1 if $table{$_}; + } + die <<"EOF", +The following config targets from $fname +shadow pre-existing config targets with the same name: +EOF + map { " $_\n" } sort keys %preexisting + if %preexisting; + # For each target, check that it's configured with a hash table. foreach (keys %targets) { diff --git a/INSTALL b/INSTALL index b03643ff..3e21cc29 100644 --- a/INSTALL +++ b/INSTALL @@ -408,8 +408,9 @@ has an impact when not built "shared". no-stdio - Don't use any C "stdio" features. Only libcrypto and libssl - can be built in this way. Using this option will suppress + Don't use anything from the C header file "stdio.h" that + makes use of the "FILE" type. Only libcrypto and libssl can + be built in this way. Using this option will suppress building the command line applications. Additionally since the OpenSSL tests also use the command line applications the tests will also be skipped. @@ -678,7 +679,8 @@ compiler optimization flags from the CFLAGS line in Makefile and run "make clean; make" or corresponding. - Please send bug reports to . + To report a bug please open an issue on GitHub, at + https://github.com/openssl/openssl/issues. 4. If everything tests ok, install OpenSSL with diff --git a/LICENSE b/LICENSE index 8fbabd8a..e953f590 100644 --- a/LICENSE +++ b/LICENSE @@ -10,7 +10,7 @@ --------------- /* ==================================================================== - * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * Copyright (c) 1998-2018 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/Makefile.shared b/Makefile.shared index 098e1ec6..4f9550aa 100644 --- a/Makefile.shared +++ b/Makefile.shared @@ -29,6 +29,37 @@ NM=nm #LIBNAME=foo LIBNAME= +# STLIBNAME contains the path of the static library to build the shared +# library from, for example: +#STLIBNAME=libfoo.a +STLIBNAME= + +# On most Unix platforms, SHLIBNAME contains the path of the short name of +# the shared library to build, for example +#SHLIBNAME=libfoo.so +# On Windows POSIX layers (cygwin and mingw), SHLIBNAME contains the import +# library name for the shared library to be built, for example: +#SHLIBNAME=libfoo.dll.a + +# SHLIBNAME_FULL contains the path of the full name of the shared library to +# build, for example: +#SHLIBNAME_FULL=libfoo.so.1.2 +# When building DSOs, SHLIBNAME_FULL contains path of the full DSO name, for +# example: +#SHLIBNAME_FULL=dir/dso.so +SHLIBNAME_FULL= + +# SHLIBVERSION contains the current version of the shared library (not to +# be confused with the project version) +#SHLIBVERSION=1.2 +SHLIBVERSION= + +# NOTE: to build shared libraries, LIBNAME, STLIBNAME, SHLIBNAME and +# SHLIBNAME_FULL MUST have values when using this makefile, and in some +# cases, SHLIBVERSION as well. To build DSOs, SHLIBNAME_FULL MUST have +# a value, the rest can be left alone. + + # APPNAME contains just the name of the application, without suffix ("" # on Unix, ".exe" on Windows, ...). This one MUST have a value when using # this makefile to build applications. @@ -36,9 +67,6 @@ LIBNAME= #APPNAME=foo APPNAME= -# DSTDIR is the directory where the built file should end up in. -DSTDIR=. - # SRCDIR is the top directory of the source tree. SRCDIR=. @@ -55,24 +83,6 @@ OBJECTS= # names of all object files that go into the target shared object. LIBEXTRAS= -# LIBVERSION contains the current version of the library. -# For example, to build libfoo.so.1.2, you need to do the following: -#LIBVERSION=1.2 -LIBVERSION= - -# LIBCOMPATVERSIONS contains the compatibility versions (a list) of -# the library. They MUST be in decreasing order. -# For example, if libfoo.so.1.2.1 is backward compatible with libfoo.so.1.2 -# and libfoo.so.1, you need to do the following: -#LIBCOMPATVERSIONS=1.2 1 -# Note that on systems that use sonames, the last number will appear as -# part of it. -# It's also possible, for systems that support it (Tru64, for example), -# to add extra compatibility info with more precision, by adding a second -# list of versions, separated from the first with a semicolon, like this: -#LIBCOMPATVERSIONS=1.2 1;1.2.0 1.1.2 1.1.1 1.1.0 1.0.0 -LIBCOMPATVERSIONS= - # LIBDEPS contains all the flags necessary to cover all necessary # dependencies to other libraries. LIBDEPS= @@ -86,20 +96,6 @@ SET_X=: top: echo "Trying to use this makefile interactively? Don't." -CALC_VERSIONS= \ - SHLIB_COMPAT=; SHLIB_SOVER=; \ - if [ -n "$(LIBVERSION)$(LIBCOMPATVERSIONS)" ]; then \ - prev=""; \ - for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \ - SHLIB_SOVER_NODOT=$$v; \ - SHLIB_SOVER=.$$v; \ - if [ -n "$$prev" ]; then \ - SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \ - fi; \ - prev=$$v; \ - done; \ - fi - LINK_APP= \ ( $(SET_X); \ LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \ @@ -120,43 +116,37 @@ LINK_SO= \ LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \ echo LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \ $${SHAREDCMD} $${SHAREDFLAGS} \ - -o $(DSTDIR)/$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \ + -o $(SHLIBNAME_FULL) \ $$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS; \ LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \ $${SHAREDCMD} $${SHAREDFLAGS} \ - -o $(DSTDIR)/$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \ + -o $(SHLIBNAME_FULL) \ $$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS \ ) && $(SYMLINK_SO) SYMLINK_SO= \ if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \ - prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \ - if [ -n "$$SHLIB_COMPAT" ]; then \ - for x in $$SHLIB_COMPAT; do \ - ( $(SET_X); rm -f $(DSTDIR)/$$SHLIB$$x$$SHLIB_SUFFIX; \ - ln -s $$prev $(DSTDIR)/$$SHLIB$$x$$SHLIB_SUFFIX ); \ - prev=$$SHLIB$$x$$SHLIB_SUFFIX; \ - done; \ - fi; \ - if [ -n "$$SHLIB_SOVER" ]; then \ - ( $(SET_X); rm -f $(DSTDIR)/$$SHLIB$$SHLIB_SUFFIX; \ - ln -s $$prev $(DSTDIR)/$$SHLIB$$SHLIB_SUFFIX ); \ + if [ -n "$(SHLIBNAME_FULL)" -a -n "$(SHLIBNAME)" -a \ + "$(SHLIBNAME_FULL)" != "$(SHLIBNAME)" ]; then \ + ( $(SET_X); \ + rm -f $(SHLIBNAME); \ + ln -s $(SHLIBNAME_FULL) $(SHLIBNAME) ); \ fi; \ fi -LINK_SO_SHLIB= SHOBJECTS="$(DSTDIR)/lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO) +LINK_SO_SHLIB= SHOBJECTS="$(STLIBNAME) $(LIBEXTRAS)"; $(LINK_SO) LINK_SO_DSO= INHIBIT_SYMLINKS=yes; SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO) LINK_SO_SHLIB_VIA_O= \ - SHOBJECTS=$(DSTDIR)/lib$(LIBNAME).o; \ + SHOBJECTS=$(STLIBNAME).o; \ ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \ - ( echo ld $(LDFLAGS) -r -o $$SHOBJECTS $$ALL lib$(LIBNAME).a $(LIBEXTRAS); \ - ld $(LDFLAGS) -r -o $$SHOBJECTS $$ALL $(DSTDIR)/lib$(LIBNAME).a $(LIBEXTRAS) ); \ + ( echo ld $(LDFLAGS) -r -o $$SHOBJECTS $$ALL $(STLIBNAME) $(LIBEXTRAS); \ + ld $(LDFLAGS) -r -o $$SHOBJECTS $$ALL $(STLIBNAME) $(LIBEXTRAS) ); \ $(LINK_SO) && ( echo rm -f $$SHOBJECTS; rm -f $$SHOBJECTS ) LINK_SO_SHLIB_UNPACKED= \ UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \ - (cd $$UNPACKDIR; ar x ../$(DSTDIR)/lib$(LIBNAME).a) && \ + (cd $$UNPACKDIR; ar x ../$(STLIBNAME)) && \ ([ -z "$(LIBEXTRAS)" ] || cp $(LIBEXTRAS) $$UNPACKDIR) && \ SHOBJECTS=$$UNPACKDIR/*.o; \ $(LINK_SO) && rm -rf $$UNPACKDIR @@ -164,15 +154,10 @@ LINK_SO_SHLIB_UNPACKED= \ DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null DO_GNU_SO_COMMON=\ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX" + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$(SHLIBNAME_FULL)" DO_GNU_DSO=\ - SHLIB=$(LIBNAME).so; \ - SHLIB_SOVER=; \ - SHLIB_SUFFIX=; \ $(DO_GNU_SO_COMMON) DO_GNU_SO=\ - $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).so; \ ALLSYMSFLAGS='-Wl,--whole-archive'; \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ $(DO_GNU_SO_COMMON) @@ -201,8 +186,6 @@ link_shlib.linux-shared: link_dso.bsd: @if $(DETECT_GNU_LD); then $(DO_GNU_DSO); else \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ LIBDEPS=" "; \ ALLSYMSFLAGS=; \ NOALLSYMSFLAGS=; \ @@ -210,9 +193,6 @@ link_dso.bsd: fi; $(LINK_SO_DSO) link_shlib.bsd: @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \ - $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ LIBDEPS=" "; \ ALLSYMSFLAGS="-Wl,-Bforcearchive"; \ NOALLSYMSFLAGS=; \ @@ -241,50 +221,33 @@ link_app.bsd: # Alternative to this heuristic approach is to develop specific # MacOS X dso module relying on whichever "native" dyld interface. link_dso.darwin: - @ SHLIB=$(LIBNAME); \ - SHLIB_SUFFIX=.dylib; \ - ALLSYMSFLAGS=''; \ + @ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ SHAREDFLAGS="$(CFLAGS) `echo $(SHARED_LDFLAGS) | sed s/dynamiclib/bundle/`"; \ $(LINK_SO_DSO) link_shlib.darwin: - @ $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME); \ - SHLIB_SUFFIX=.dylib; \ - ALLSYMSFLAGS='-all_load'; \ + @ ALLSYMSFLAGS='-all_load'; \ NOALLSYMSFLAGS=''; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \ - if [ -n "$(LIBVERSION)" ]; then \ - SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \ - fi; \ - if [ -n "$$SHLIB_SOVER_NODOT" ]; then \ - SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \ - fi; \ - SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$(SHLIB_EXT)"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -current_version $(SHLIBVERSION) -compatibility_version $(SHLIBVERSION) -install_name $(INSTALLTOP)/$(LIBDIR)/$(SHLIBNAME_FULL)"; \ $(LINK_SO_SHLIB) link_app.darwin: # is there run-path on darwin? $(LINK_APP) link_dso.cygwin: - @SHLIB=$(LIBNAME); \ - SHLIB_SUFFIX=.dll; \ - ALLSYMSFLAGS=''; \ + @ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ base=-Wl,--enable-auto-image-base; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic"; \ $(LINK_SO_DSO) link_shlib.cygwin: - @ $(CALC_VERSIONS); \ - INHIBIT_SYMLINKS=yes; \ - SHLIB=cyg$(LIBNAME); SHLIB_SOVER=-$(LIBVERSION); SHLIB_SUFFIX=.dll; \ - dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \ - echo "$(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name |" \ + @ INHIBIT_SYMLINKS=yes; \ + echo "$(PERL) $(SRCDIR)/util/mkrc.pl $(SHLIBNAME_FULL) |" \ "$(RC) $(SHARED_RCFLAGS) -o rc.o"; \ - $(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name | \ + $(PERL) $(SRCDIR)/util/mkrc.pl $(SHLIBNAME_FULL) | \ $(RC) $(SHARED_RCFLAGS) -o rc.o; \ ALLSYMSFLAGS='-Wl,--whole-archive'; \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,--enable-auto-image-base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a rc.o"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,--enable-auto-image-base -Wl,-Bsymbolic -Wl,--out-implib,$(SHLIBNAME) rc.o"; \ $(LINK_SO_SHLIB) || exit 1; \ rm rc.o link_app.cygwin: @@ -293,26 +256,18 @@ link_app.cygwin: # link_dso.mingw-shared and link_app.mingw-shared are mapped to the # corresponding cygwin targets, as they do the exact same thing. link_shlib.mingw: - @ $(CALC_VERSIONS); \ - INHIBIT_SYMLINKS=yes; \ - arch=; \ - if expr $(PLATFORM) : mingw64 > /dev/null; then arch=-x64; fi; \ - sover=`echo $(LIBVERSION) | sed -e 's/\./_/g'` ; \ - SHLIB=lib$(LIBNAME); \ - SHLIB_SOVER=-$$sover$$arch; \ - SHLIB_SUFFIX=.dll; \ - dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \ + @ INHIBIT_SYMLINKS=yes; \ base=; [ $(LIBNAME) = "crypto" -a -n "$(FIPSCANLIB)" ] && base=-Wl,--image-base,0x63000000; \ $(PERL) $(SRCDIR)/util/mkdef.pl 32 $(LIBNAME) \ - | sed -e 's|^\(LIBRARY *\)$(LIBNAME)32|\1'"$$dll_name"'|' \ + | sed -e 's|^\(LIBRARY *\)$(LIBNAME)32|\1$(SHLIBNAME_FULL)|' \ > $(LIBNAME).def; \ - echo "$(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name |" \ + echo "$(PERL) $(SRCDIR)/util/mkrc.pl $(SHLIBNAME_FULL) |" \ "$(RC) $(SHARED_RCFLAGS) -o rc.o"; \ - $(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name | \ + $(PERL) $(SRCDIR)/util/mkrc.pl $(SHLIBNAME_FULL) | \ $(RC) $(SHARED_RCFLAGS) -o rc.o; \ ALLSYMSFLAGS='-Wl,--whole-archive'; \ NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a $(LIBNAME).def rc.o"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,$(SHLIBNAME) $(LIBNAME).def rc.o"; \ $(LINK_SO_SHLIB) || exit 1; \ rm $(LIBNAME).def rc.o @@ -320,8 +275,6 @@ link_dso.alpha-osf1: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_DSO); \ else \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic"; \ @@ -331,21 +284,9 @@ link_shlib.alpha-osf1: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_SO); \ else \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ - SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \ - if [ -n "$$SHLIB_HIST" ]; then \ - SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \ - else \ - SHLIB_HIST="$(LIBVERSION)"; \ - fi; \ - SHLIB_SOVER=; \ ALLSYMSFLAGS='-all'; \ NOALLSYMSFLAGS='-none'; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic"; \ - if [ -n "$$SHLIB_HIST" ]; then \ - SHAREDFLAGS="$$SHAREDFLAGS -set_version $$SHLIB_HIST"; \ - fi; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic -set_version $(SHLIBVERSION)"; \ fi; \ $(LINK_SO_SHLIB) link_app.alpha-osf1: @@ -360,25 +301,19 @@ link_dso.solaris: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_DSO); \ else \ - $(CALC_VERSIONS); \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=""; \ NOALLSYMSFLAGS=""; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $(SHLIBNAME_FULL) -Wl,-Bsymbolic"; \ fi; \ $(LINK_SO_DSO) link_shlib.solaris: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_SO); \ else \ - $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=;\ $(PERL) $(SRCDIR)/util/mkdef.pl $(LIBNAME) linux >$(LIBNAME).map; \ ALLSYMSFLAGS="-Wl,-z,allextract,-M,$(LIBNAME).map"; \ NOALLSYMSFLAGS="-Wl,-z,defaultextract"; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $(SHLIBNAME_FULL) -Wl,-Bsymbolic"; \ fi; \ $(LINK_SO_SHLIB) link_app.solaris: @@ -394,24 +329,18 @@ link_dso.svr3: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_DSO); \ else \ - $(CALC_VERSIONS); \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ - SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SUFFIX"; \ + SHAREDFLAGS="$(CFLAGS) -G -h $(SHLIBNAME_FULL)"; \ fi; \ $(LINK_SO_DSO) link_shlib.svr3: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_SO); \ else \ - $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ - SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \ + SHAREDFLAGS="$(CFLAGS) -G -h $(SHLIBNAME_FULL)"; \ fi; \ $(LINK_SO_SHLIB_UNPACKED) link_app.svr3: @@ -425,25 +354,20 @@ link_dso.svr5: else \ SHARE_FLAG='-G'; \ ($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ - SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SUFFIX"; \ + SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $(SHLIBNAME_FULL)"; \ fi; \ $(LINK_SO_DSO) link_shlib.svr5: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_SO); \ else \ - $(CALC_VERSIONS); \ SHARE_FLAG='-G'; \ ($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ - SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \ + SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $(SHLIBNAME_FULL)"; \ fi; \ $(LINK_SO_SHLIB_UNPACKED) link_app.svr5: @@ -454,25 +378,20 @@ link_dso.irix: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_DSO); \ else \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=""; \ NOALLSYMSFLAGS=""; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SUFFIX,-B,symbolic"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$(SHLIBNAME_FULL),-B,symbolic"; \ fi; \ $(LINK_SO_DSO) link_shlib.irix: @ if $(DETECT_GNU_LD); then \ $(DO_GNU_SO); \ else \ - $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ MINUSWL=""; \ ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \ ALLSYMSFLAGS="$${MINUSWL}-all"; \ NOALLSYMSFLAGS="$${MINUSWL}-none"; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,-B,symbolic"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$(SHLIBNAME_FULL),-B,symbolic"; \ fi; \ $(LINK_SO_SHLIB) link_app.irix: @@ -489,29 +408,22 @@ link_app.irix: # link_dso.hpux: @if $(DETECT_GNU_LD); then $(DO_GNU_DSO); else \ - SHLIB=$(LIBNAME).sl; \ - expr "$(CFLAGS)" : '.*DSO_DLFCN' > /dev/null && SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SUFFIX,+cdp,../:,+cdp,./:"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$(SHLIBNAME_FULL),+cdp,../:,+cdp,./:"; \ fi; \ - rm -f $(DSTDIR)/$$SHLIB$$SHLIB_SUFFIX || :; \ - $(LINK_SO_DSO) && chmod a=rx $(DSTDIR)/$$SHLIB$$SHLIB_SUFFIX + rm -f $(SHLIBNAME_FULL) || :; \ + $(LINK_SO_DSO) && chmod a=rx $(SHLIBNAME_FULL) link_shlib.hpux: @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \ - $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).sl; \ - expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS='-Wl,-Fl'; \ NOALLSYMSFLAGS=''; \ expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \ - SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+cdp,../:,+cdp,./:"; \ + SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$(SHLIBNAME_FULL),+cdp,../:,+cdp,./:"; \ fi; \ - rm -f $(DSTDIR)/$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \ - $(LINK_SO_SHLIB) && chmod a=rx $(DSTDIR)/$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX + rm -f $(SHLIBNAME_FULL) || :; \ + $(LINK_SO_SHLIB) && chmod a=rx $(SHLIBNAME_FULL) link_app.hpux: @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \ LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,+s,+cdp,../:,+cdp,./:"; \ @@ -521,23 +433,18 @@ link_app.hpux: link_dso.aix: @OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || :; \ OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \ - SHLIB=$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS=''; \ NOALLSYMSFLAGS=''; \ SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \ - rm -f $(DSTDIR)/$$SHLIB$$SHLIB_SOVER 2>&1 > /dev/null ; \ + rm -f $(SHLIBNAME_FULL) 2>&1 > /dev/null ; \ $(LINK_SO_DSO); link_shlib.aix: - @ $(CALC_VERSIONS); \ - OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || : ; \ + @ OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || : ; \ OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \ - SHLIB=lib$(LIBNAME).so; \ - SHLIB_SUFFIX=; \ ALLSYMSFLAGS='-bnogc'; \ NOALLSYMSFLAGS=''; \ SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \ - rm -f $(DSTDIR)/$$SHLIB$$SHLIB_SOVER 2>&1 > /dev/null ; \ + rm -f $(SHLIBNAME_FULL) 2>&1 > /dev/null ; \ $(LINK_SO_SHLIB_VIA_O) link_app.aix: LDFLAGS="$(CFLAGS) -Wl,-bsvr4 $(LDFLAGS)"; \ @@ -547,19 +454,11 @@ link_app.aix: # Targets to build symbolic links when needed symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \ symlink.aix: - @ $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).so; \ - $(SYMLINK_SO) + @ $(SYMLINK_SO) symlink.darwin: - @ $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME); \ - SHLIB_SUFFIX=.dylib; \ - $(SYMLINK_SO) + @ $(SYMLINK_SO) symlink.hpux: - @ $(CALC_VERSIONS); \ - SHLIB=lib$(LIBNAME).sl; \ - expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \ - $(SYMLINK_SO) + @ $(SYMLINK_SO) # The following lines means those specific architectures do no symlinks symlink.cygwin symlink.alpha-osf1 symlink.tru64 symlink.tru64-rpath: diff --git a/NEWS b/NEWS index b4db8dfc..8744fe68 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,18 @@ This file gives a brief overview of the major changes between each OpenSSL release. For more details please read the CHANGES file. + Major changes between OpenSSL 1.1.0g and OpenSSL 1.1.0h [27 Mar 2018] + + o Constructed ASN.1 types with a recursive definition could exceed the + stack (CVE-2018-0739) + o Incorrect CRYPTO_memcmp on HP-UX PA-RISC (CVE-2018-0733) + o rsaz_1024_mul_avx2 overflow bug on x86_64 (CVE-2017-3738) + + Major changes between OpenSSL 1.1.0f and OpenSSL 1.1.0g [2 Nov 2017] + + o bn_sqrx8x_internal carry bug on x86_64 (CVE-2017-3736) + o Malformed X.509 IPAddressFamily could cause OOB read (CVE-2017-3735) + Major changes between OpenSSL 1.1.0e and OpenSSL 1.1.0f [25 May 2017] o config now recognises 64-bit mingw and chooses mingw64 instead of mingw diff --git a/README b/README index a7bfd730..3491280e 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ - OpenSSL 1.1.0f 25 May 2017 + OpenSSL 1.1.0h 27 Mar 2018 Copyright (c) 1998-2016 The OpenSSL Project Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson diff --git a/apps/CA.pl.in b/apps/CA.pl.in index 3187e473..7277eeca 100644 --- a/apps/CA.pl.in +++ b/apps/CA.pl.in @@ -145,7 +145,7 @@ if ($WHAT eq '-newcert' ) { print "CA certificate is in ${CATOP}/$CACERT\n" if $RET == 0; } } elsif ($WHAT eq '-pkcs12' ) { - my $cname = $ARGV[1]; + my $cname = $ARGV[0]; $cname = "My Certificate" unless defined $cname; $RET = run("$PKCS12 -in $NEWCERT -inkey $NEWKEY" . " -certfile ${CATOP}/$CACERT" @@ -178,12 +178,12 @@ if ($WHAT eq '-newcert' ) { $RET = run("$CA -gencrl -out ${CATOP}/crl/$CACRL"); print "Generated CRL is in ${CATOP}/crl/$CACRL\n" if $RET == 0; } elsif ($WHAT eq '-revoke' ) { - my $cname = $ARGV[1]; + my $cname = $ARGV[0]; if (!defined $cname) { print "Certificate filename is required; reason optional.\n"; exit 1; } - my $reason = $ARGV[2]; + my $reason = $ARGV[1]; $reason = " -crl_reason $reason" if defined $reason && crl_reason_ok($reason); $RET = run("$CA -revoke \"$cname\"" . $reason); diff --git a/apps/app_rand.c b/apps/app_rand.c index 0d44af90..ff0771cb 100644 --- a/apps/app_rand.c +++ b/apps/app_rand.c @@ -20,7 +20,7 @@ int app_RAND_load_file(const char *file, int dont_warn) char buffer[200]; if (file == NULL) - file = RAND_file_name(buffer, sizeof buffer); + file = RAND_file_name(buffer, sizeof(buffer)); #ifndef OPENSSL_NO_EGD else if (RAND_egd(file) > 0) { /* @@ -101,7 +101,7 @@ int app_RAND_write_file(const char *file) return 0; if (file == NULL) - file = RAND_file_name(buffer, sizeof buffer); + file = RAND_file_name(buffer, sizeof(buffer)); if (file == NULL || !RAND_write_file(file)) { BIO_printf(bio_err, "unable to write 'random state'\n"); return 0; diff --git a/apps/apps.c b/apps/apps.c index cbf4e90b..8703d0cc 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -18,9 +18,7 @@ #include #include #include -#ifndef NO_SYS_TYPES_H -# include -#endif +#include #ifndef OPENSSL_NO_POSIX_IO # include # include @@ -1390,9 +1388,9 @@ int save_serial(const char *serialfile, const char *suffix, const BIGNUM *serial OPENSSL_strlcpy(buf[0], serialfile, BSIZE); else { #ifndef OPENSSL_SYS_VMS - j = BIO_snprintf(buf[0], sizeof buf[0], "%s.%s", serialfile, suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", serialfile, suffix); #else - j = BIO_snprintf(buf[0], sizeof buf[0], "%s-%s", serialfile, suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", serialfile, suffix); #endif } out = BIO_new_file(buf[0], "w"); @@ -1433,11 +1431,11 @@ int rotate_serial(const char *serialfile, const char *new_suffix, goto err; } #ifndef OPENSSL_SYS_VMS - j = BIO_snprintf(buf[0], sizeof buf[0], "%s.%s", serialfile, new_suffix); - j = BIO_snprintf(buf[1], sizeof buf[1], "%s.%s", serialfile, old_suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", serialfile, new_suffix); + j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s.%s", serialfile, old_suffix); #else - j = BIO_snprintf(buf[0], sizeof buf[0], "%s-%s", serialfile, new_suffix); - j = BIO_snprintf(buf[1], sizeof buf[1], "%s-%s", serialfile, old_suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", serialfile, new_suffix); + j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s-%s", serialfile, old_suffix); #endif if (rename(serialfile, buf[1]) < 0 && errno != ENOENT #ifdef ENOTDIR @@ -1506,9 +1504,9 @@ CA_DB *load_index(const char *dbfile, DB_ATTR *db_attr) goto err; #ifndef OPENSSL_SYS_VMS - BIO_snprintf(buf, sizeof buf, "%s.attr", dbfile); + BIO_snprintf(buf, sizeof(buf), "%s.attr", dbfile); #else - BIO_snprintf(buf, sizeof buf, "%s-attr", dbfile); + BIO_snprintf(buf, sizeof(buf), "%s-attr", dbfile); #endif dbattr_conf = app_load_config(buf); @@ -1569,13 +1567,13 @@ int save_index(const char *dbfile, const char *suffix, CA_DB *db) goto err; } #ifndef OPENSSL_SYS_VMS - j = BIO_snprintf(buf[2], sizeof buf[2], "%s.attr", dbfile); - j = BIO_snprintf(buf[1], sizeof buf[1], "%s.attr.%s", dbfile, suffix); - j = BIO_snprintf(buf[0], sizeof buf[0], "%s.%s", dbfile, suffix); + j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s.attr", dbfile); + j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s.attr.%s", dbfile, suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", dbfile, suffix); #else - j = BIO_snprintf(buf[2], sizeof buf[2], "%s-attr", dbfile); - j = BIO_snprintf(buf[1], sizeof buf[1], "%s-attr-%s", dbfile, suffix); - j = BIO_snprintf(buf[0], sizeof buf[0], "%s-%s", dbfile, suffix); + j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s-attr", dbfile); + j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s-attr-%s", dbfile, suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", dbfile, suffix); #endif out = BIO_new_file(buf[0], "w"); if (out == NULL) { @@ -1618,17 +1616,17 @@ int rotate_index(const char *dbfile, const char *new_suffix, goto err; } #ifndef OPENSSL_SYS_VMS - j = BIO_snprintf(buf[4], sizeof buf[4], "%s.attr", dbfile); - j = BIO_snprintf(buf[3], sizeof buf[3], "%s.attr.%s", dbfile, old_suffix); - j = BIO_snprintf(buf[2], sizeof buf[2], "%s.attr.%s", dbfile, new_suffix); - j = BIO_snprintf(buf[1], sizeof buf[1], "%s.%s", dbfile, old_suffix); - j = BIO_snprintf(buf[0], sizeof buf[0], "%s.%s", dbfile, new_suffix); + j = BIO_snprintf(buf[4], sizeof(buf[4]), "%s.attr", dbfile); + j = BIO_snprintf(buf[3], sizeof(buf[3]), "%s.attr.%s", dbfile, old_suffix); + j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s.attr.%s", dbfile, new_suffix); + j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s.%s", dbfile, old_suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", dbfile, new_suffix); #else - j = BIO_snprintf(buf[4], sizeof buf[4], "%s-attr", dbfile); - j = BIO_snprintf(buf[3], sizeof buf[3], "%s-attr-%s", dbfile, old_suffix); - j = BIO_snprintf(buf[2], sizeof buf[2], "%s-attr-%s", dbfile, new_suffix); - j = BIO_snprintf(buf[1], sizeof buf[1], "%s-%s", dbfile, old_suffix); - j = BIO_snprintf(buf[0], sizeof buf[0], "%s-%s", dbfile, new_suffix); + j = BIO_snprintf(buf[4], sizeof(buf[4]), "%s-attr", dbfile); + j = BIO_snprintf(buf[3], sizeof(buf[3]), "%s-attr-%s", dbfile, old_suffix); + j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s-attr-%s", dbfile, new_suffix); + j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s-%s", dbfile, old_suffix); + j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", dbfile, new_suffix); #endif if (rename(dbfile, buf[1]) < 0 && errno != ENOENT #ifdef ENOTDIR @@ -2255,29 +2253,27 @@ int app_access(const char* name, int flag) #ifdef _WIN32 int app_isdir(const char *name) { - HANDLE hList; - WIN32_FIND_DATA FileData; + DWORD attr; # if defined(UNICODE) || defined(_UNICODE) size_t i, len_0 = strlen(name) + 1; + WCHAR tempname[MAX_PATH]; - if (len_0 > OSSL_NELEM(FileData.cFileName)) + if (len_0 > MAX_PATH) return -1; # if !defined(_WIN32_WCE) || _WIN32_WCE>=101 - if (!MultiByteToWideChar - (CP_ACP, 0, name, len_0, FileData.cFileName, len_0)) + if (!MultiByteToWideChar(CP_ACP, 0, name, len_0, tempname, MAX_PATH)) # endif for (i = 0; i < len_0; i++) - FileData.cFileName[i] = (WCHAR)name[i]; + tempname[i] = (WCHAR)name[i]; - hList = FindFirstFile(FileData.cFileName, &FileData); + attr = GetFileAttributes(tempname); # else - hList = FindFirstFile(name, &FileData); + attr = GetFileAttributes(name); # endif - if (hList == INVALID_HANDLE_VALUE) + if (attr == INVALID_FILE_ATTRIBUTES) return -1; - FindClose(hList); - return ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); + return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0); } #else # include @@ -2575,6 +2571,7 @@ void wait_for_async(SSL *s) fd_set asyncfds; OSSL_ASYNC_FD *fds; size_t numfds; + size_t i; if (!SSL_get_all_async_fds(s, NULL, &numfds)) return; @@ -2583,17 +2580,17 @@ void wait_for_async(SSL *s) fds = app_malloc(sizeof(OSSL_ASYNC_FD) * numfds, "allocate async fds"); if (!SSL_get_all_async_fds(s, fds, &numfds)) { OPENSSL_free(fds); + return; } FD_ZERO(&asyncfds); - while (numfds > 0) { - if (width <= (int)*fds) - width = (int)*fds + 1; - openssl_fdset((int)*fds, &asyncfds); - numfds--; - fds++; + for (i = 0; i < numfds; i++) { + if (width <= (int)fds[i]) + width = (int)fds[i] + 1; + openssl_fdset((int)fds[i], &asyncfds); } select(width, (void *)&asyncfds, NULL, NULL, NULL); + OPENSSL_free(fds); #endif } diff --git a/apps/apps.h b/apps/apps.h index 926a6d62..f91faf8c 100644 --- a/apps/apps.h +++ b/apps/apps.h @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -214,8 +214,8 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate, OPT_S_SERVERPREF, OPT_S_LEGACYRENEG, OPT_S_LEGACYCONN, \ OPT_S_ONRESUMP, OPT_S_NOLEGACYCONN, OPT_S_STRICT, OPT_S_SIGALGS, \ OPT_S_CLIENTSIGALGS, OPT_S_CURVES, OPT_S_NAMEDCURVE, OPT_S_CIPHER, \ - OPT_S_DHPARAM, OPT_S_DEBUGBROKE, OPT_S_COMP, \ - OPT_S__LAST + OPT_S_DEBUGBROKE, OPT_S_COMP, OPT_S_MINPROTO, OPT_S_MAXPROTO, \ + OPT_S_NO_RENEGOTIATION, OPT_S__LAST # define OPT_S_OPTIONS \ {"no_ssl3", OPT_S_NOSSL3, '-',"Just disable SSLv3" }, \ @@ -230,6 +230,8 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate, {"serverpref", OPT_S_SERVERPREF, '-', "Use server's cipher preferences"}, \ {"legacy_renegotiation", OPT_S_LEGACYRENEG, '-', \ "Enable use of legacy renegotiation (dangerous)"}, \ + {"no_renegotiation", OPT_S_NO_RENEGOTIATION, '-', \ + "Disable all renegotiation."}, \ {"legacy_server_connect", OPT_S_LEGACYCONN, '-', \ "Allow initial connection to servers that don't support RI"}, \ {"no_resumption_on_reneg", OPT_S_ONRESUMP, '-', \ @@ -248,8 +250,8 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate, {"named_curve", OPT_S_NAMEDCURVE, 's', \ "Elliptic curve used for ECDHE (server-side only)" }, \ {"cipher", OPT_S_CIPHER, 's', "Specify cipher list to be used"}, \ - {"dhparam", OPT_S_DHPARAM, '<', \ - "DH parameter file to use, in cert file if not specified"}, \ + {"min_protocol", OPT_S_MINPROTO, 's', "Specify the minimum protocol version to be used"}, \ + {"max_protocol", OPT_S_MAXPROTO, 's', "Specify the maximum protocol version to be used"}, \ {"debug_broken_protocol", OPT_S_DEBUGBROKE, '-', \ "Perform all sorts of protocol violations for testing purposes"} @@ -274,7 +276,9 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate, case OPT_S_CURVES: \ case OPT_S_NAMEDCURVE: \ case OPT_S_CIPHER: \ - case OPT_S_DHPARAM: \ + case OPT_S_MINPROTO: \ + case OPT_S_MAXPROTO: \ + case OPT_S_NO_RENEGOTIATION: \ case OPT_S_DEBUGBROKE #define IS_NO_PROT_FLAG(o) \ diff --git a/apps/build.info b/apps/build.info index ae648619..e2ddd2b5 100644 --- a/apps/build.info +++ b/apps/build.info @@ -1,21 +1,27 @@ {- our $tsget_name = $config{target} =~ /^(VC|vms)-/ ? "tsget.pl" : "tsget"; + our @apps_openssl_src = + ( qw(openssl.c + asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c dgst.c dhparam.c + dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c errstr.c gendsa.c + genpkey.c genrsa.c nseq.c ocsp.c passwd.c pkcs12.c pkcs7.c pkcs8.c + pkey.c pkeyparam.c pkeyutl.c prime.c rand.c req.c rsa.c rsautl.c + s_client.c s_server.c s_time.c sess_id.c smime.c speed.c spkac.c + srp.c ts.c verify.c version.c x509.c rehash.c + apps.c opt.c s_cb.c s_socket.c + app_rand.c), + split(/\s+/, $target{apps_aux_src}) ); "" -} IF[{- !$disabled{apps} -}] PROGRAMS=openssl - SOURCE[openssl]=\ - openssl.c \ - asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c dgst.c dhparam.c \ - dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c errstr.c gendsa.c \ - genpkey.c genrsa.c nseq.c ocsp.c passwd.c pkcs12.c pkcs7.c pkcs8.c \ - pkey.c pkeyparam.c pkeyutl.c prime.c rand.c req.c rsa.c rsautl.c \ - s_client.c s_server.c s_time.c sess_id.c smime.c speed.c spkac.c \ - srp.c ts.c verify.c version.c x509.c rehash.c \ - apps.c opt.c s_cb.c s_socket.c \ - app_rand.c \ - {- $target{apps_aux_src} -} + SOURCE[openssl]={- join(" ", @apps_openssl_src) -} INCLUDE[openssl]=.. ../include DEPEND[openssl]=../libssl + {- join("\n ", map { (my $x = $_) =~ s|\.c$|.o|; "DEPEND[$x]=progs.h" } + @apps_openssl_src) -} + GENERATE[progs.h]=progs.pl $(APPS_OPENSSL) + DEPEND[progs.h]=../configdata.pm + SCRIPTS=CA.pl {- $tsget_name -} SOURCE[CA.pl]=CA.pl.in SOURCE[{- $tsget_name -}]=tsget.in diff --git a/apps/ca.c b/apps/ca.c index 350a7484..d474a2b6 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -440,30 +440,23 @@ end_of_options: && (section = lookup_conf(conf, BASE_SECTION, ENV_DEFAULT_CA)) == NULL) goto end; - if (conf != NULL) { - p = NCONF_get_string(conf, NULL, "oid_file"); - if (p == NULL) - ERR_clear_error(); - if (p != NULL) { - BIO *oid_bio; + p = NCONF_get_string(conf, NULL, "oid_file"); + if (p == NULL) + ERR_clear_error(); + if (p != NULL) { + BIO *oid_bio = BIO_new_file(p, "r"); - oid_bio = BIO_new_file(p, "r"); - if (oid_bio == NULL) { - /*- - BIO_printf(bio_err,"problems opening %s for extra oid's\n",p); - ERR_print_errors(bio_err); - */ - ERR_clear_error(); - } else { - OBJ_create_objects(oid_bio); - BIO_free(oid_bio); - } - } - if (!add_oid_section(conf)) { - ERR_print_errors(bio_err); - goto end; + if (oid_bio == NULL) { + ERR_clear_error(); + } else { + OBJ_create_objects(oid_bio); + BIO_free(oid_bio); } } + if (!add_oid_section(conf)) { + ERR_print_errors(bio_err); + goto end; + } randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE"); if (randfile == NULL) @@ -1098,13 +1091,13 @@ end_of_options: goto end; tmptm = ASN1_TIME_new(); - if (tmptm == NULL) - goto end; - X509_gmtime_adj(tmptm, 0); - X509_CRL_set1_lastUpdate(crl, tmptm); - if (!X509_time_adj_ex(tmptm, crldays, crlhours * 60 * 60 + crlsec, - NULL)) { + if (tmptm == NULL + || X509_gmtime_adj(tmptm, 0) == NULL + || !X509_CRL_set1_lastUpdate(crl, tmptm) + || X509_time_adj_ex(tmptm, crldays, crlhours * 60 * 60 + crlsec, + NULL) == NULL) { BIO_puts(bio_err, "error setting CRL nextUpdate\n"); + ASN1_TIME_free(tmptm); goto end; } X509_CRL_set1_nextUpdate(crl, tmptm); @@ -1376,8 +1369,7 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, CONF *lconf, unsigned long certopt, unsigned long nameopt, int default_op, int ext_copy, int selfsign) { - X509_NAME *name = NULL, *CAname = NULL, *subject = NULL, *dn_subject = - NULL; + X509_NAME *name = NULL, *CAname = NULL, *subject = NULL; const ASN1_TIME *tm; ASN1_STRING *str, *str2; ASN1_OBJECT *obj; @@ -1559,7 +1551,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, if (push != NULL) { if (!X509_NAME_add_entry(subject, push, -1, 0)) { - X509_NAME_ENTRY_free(push); BIO_printf(bio_err, "Memory allocation failure\n"); goto end; } @@ -1577,104 +1568,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, goto end; } - if (verbose) - BIO_printf(bio_err, - "The subject name appears to be ok, checking data base for clashes\n"); - - /* Build the correct Subject if no e-mail is wanted in the subject */ - /* - * and add it later on because of the method extensions are added - * (altName) - */ - - if (email_dn) - dn_subject = subject; - else { - X509_NAME_ENTRY *tmpne; - /* - * Its best to dup the subject DN and then delete any email addresses - * because this retains its structure. - */ - if ((dn_subject = X509_NAME_dup(subject)) == NULL) { - BIO_printf(bio_err, "Memory allocation failure\n"); - goto end; - } - while ((i = X509_NAME_get_index_by_NID(dn_subject, - NID_pkcs9_emailAddress, - -1)) >= 0) { - tmpne = X509_NAME_get_entry(dn_subject, i); - X509_NAME_delete_entry(dn_subject, i); - X509_NAME_ENTRY_free(tmpne); - } - } - - if (BN_is_zero(serial)) - row[DB_serial] = OPENSSL_strdup("00"); - else - row[DB_serial] = BN_bn2hex(serial); - if (row[DB_serial] == NULL) { - BIO_printf(bio_err, "Memory allocation failure\n"); - goto end; - } - - if (db->attributes.unique_subject) { - OPENSSL_STRING *crow = row; - - rrow = TXT_DB_get_by_index(db->db, DB_name, crow); - if (rrow != NULL) { - BIO_printf(bio_err, - "ERROR:There is already a certificate for %s\n", - row[DB_name]); - } - } - if (rrow == NULL) { - rrow = TXT_DB_get_by_index(db->db, DB_serial, row); - if (rrow != NULL) { - BIO_printf(bio_err, - "ERROR:Serial number %s has already been issued,\n", - row[DB_serial]); - BIO_printf(bio_err, - " check the database/serial_file for corruption\n"); - } - } - - if (rrow != NULL) { - BIO_printf(bio_err, "The matching entry has the following details\n"); - if (rrow[DB_type][0] == 'E') - p = "Expired"; - else if (rrow[DB_type][0] == 'R') - p = "Revoked"; - else if (rrow[DB_type][0] == 'V') - p = "Valid"; - else - p = "\ninvalid type, Data base error\n"; - BIO_printf(bio_err, "Type :%s\n", p);; - if (rrow[DB_type][0] == 'R') { - p = rrow[DB_exp_date]; - if (p == NULL) - p = "undef"; - BIO_printf(bio_err, "Was revoked on:%s\n", p); - } - p = rrow[DB_exp_date]; - if (p == NULL) - p = "undef"; - BIO_printf(bio_err, "Expires on :%s\n", p); - p = rrow[DB_serial]; - if (p == NULL) - p = "undef"; - BIO_printf(bio_err, "Serial Number :%s\n", p); - p = rrow[DB_file]; - if (p == NULL) - p = "undef"; - BIO_printf(bio_err, "File name :%s\n", p); - p = rrow[DB_name]; - if (p == NULL) - p = "undef"; - BIO_printf(bio_err, "Subject Name :%s\n", p); - ok = -1; /* This is now a 'bad' error. */ - goto end; - } - /* We are now totally happy, lets make and sign the certificate */ if (verbose) BIO_printf(bio_err, @@ -1704,7 +1597,9 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, if (enddate != NULL) { int tdays; - ASN1_TIME_diff(&tdays, NULL, NULL, X509_get0_notAfter(ret)); + + if (!ASN1_TIME_diff(&tdays, NULL, NULL, X509_get0_notAfter(ret))) + goto end; days = tdays; } @@ -1719,7 +1614,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, /* Lets add the extensions, if there are any */ if (ext_sect) { X509V3_CTX ctx; - X509_set_version(ret, 2); /* Initialize the context structure */ if (selfsign) @@ -1774,10 +1668,132 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, goto end; } - /* Set the right value for the noemailDN option */ - if (email_dn == 0) { - if (!X509_set_subject_name(ret, dn_subject)) + { + const STACK_OF(X509_EXTENSION) *exts = X509_get0_extensions(ret); + + if (exts != NULL && sk_X509_EXTENSION_num(exts) > 0) + /* Make it an X509 v3 certificate. */ + if (!X509_set_version(ret, 2)) + goto end; + } + + if (verbose) + BIO_printf(bio_err, + "The subject name appears to be ok, checking data base for clashes\n"); + + /* Build the correct Subject if no e-mail is wanted in the subject. */ + if (!email_dn) { + X509_NAME_ENTRY *tmpne; + X509_NAME *dn_subject; + + /* + * Its best to dup the subject DN and then delete any email addresses + * because this retains its structure. + */ + if ((dn_subject = X509_NAME_dup(subject)) == NULL) { + BIO_printf(bio_err, "Memory allocation failure\n"); goto end; + } + while ((i = X509_NAME_get_index_by_NID(dn_subject, + NID_pkcs9_emailAddress, + -1)) >= 0) { + tmpne = X509_NAME_get_entry(dn_subject, i); + X509_NAME_delete_entry(dn_subject, i); + X509_NAME_ENTRY_free(tmpne); + } + + if (!X509_set_subject_name(ret, dn_subject)) { + X509_NAME_free(dn_subject); + goto end; + } + X509_NAME_free(dn_subject); + } + + row[DB_name] = X509_NAME_oneline(X509_get_subject_name(ret), NULL, 0); + if (row[DB_name] == NULL) { + BIO_printf(bio_err, "Memory allocation failure\n"); + goto end; + } + + if (BN_is_zero(serial)) + row[DB_serial] = OPENSSL_strdup("00"); + else + row[DB_serial] = BN_bn2hex(serial); + if (row[DB_serial] == NULL) { + BIO_printf(bio_err, "Memory allocation failure\n"); + goto end; + } + + if (row[DB_name][0] == '\0') { + /* + * An empty subject! We'll use the serial number instead. If + * unique_subject is in use then we don't want different entries with + * empty subjects matching each other. + */ + OPENSSL_free(row[DB_name]); + row[DB_name] = OPENSSL_strdup(row[DB_serial]); + if (row[DB_name] == NULL) { + BIO_printf(bio_err, "Memory allocation failure\n"); + goto end; + } + } + + if (db->attributes.unique_subject) { + OPENSSL_STRING *crow = row; + + rrow = TXT_DB_get_by_index(db->db, DB_name, crow); + if (rrow != NULL) { + BIO_printf(bio_err, + "ERROR:There is already a certificate for %s\n", + row[DB_name]); + } + } + if (rrow == NULL) { + rrow = TXT_DB_get_by_index(db->db, DB_serial, row); + if (rrow != NULL) { + BIO_printf(bio_err, + "ERROR:Serial number %s has already been issued,\n", + row[DB_serial]); + BIO_printf(bio_err, + " check the database/serial_file for corruption\n"); + } + } + + if (rrow != NULL) { + BIO_printf(bio_err, "The matching entry has the following details\n"); + if (rrow[DB_type][0] == DB_TYPE_EXP) + p = "Expired"; + else if (rrow[DB_type][0] == DB_TYPE_REV) + p = "Revoked"; + else if (rrow[DB_type][0] == DB_TYPE_VAL) + p = "Valid"; + else + p = "\ninvalid type, Data base error\n"; + BIO_printf(bio_err, "Type :%s\n", p);; + if (rrow[DB_type][0] == DB_TYPE_REV) { + p = rrow[DB_exp_date]; + if (p == NULL) + p = "undef"; + BIO_printf(bio_err, "Was revoked on:%s\n", p); + } + p = rrow[DB_exp_date]; + if (p == NULL) + p = "undef"; + BIO_printf(bio_err, "Expires on :%s\n", p); + p = rrow[DB_serial]; + if (p == NULL) + p = "undef"; + BIO_printf(bio_err, "Serial Number :%s\n", p); + p = rrow[DB_file]; + if (p == NULL) + p = "undef"; + BIO_printf(bio_err, "File name :%s\n", p); + p = rrow[DB_name]; + if (p == NULL) + p = "undef"; + BIO_printf(bio_err, "Subject Name :%s\n", p); + ok = -1; /* This is now a 'bad' error. */ + goto end; } if (!default_op) { @@ -1829,8 +1845,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, row[DB_exp_date][tm->length] = '\0'; row[DB_rev_date] = NULL; row[DB_file] = OPENSSL_strdup("unknown"); - row[DB_name] = X509_NAME_oneline(X509_get_subject_name(ret), NULL, 0); - if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) || (row[DB_file] == NULL) || (row[DB_name] == NULL)) { BIO_printf(bio_err, "Memory allocation failure\n"); @@ -1850,16 +1864,14 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, irow = NULL; ok = 1; end: - if (irow != NULL) { + if (ok != 1) { for (i = 0; i < DB_NUMBER; i++) OPENSSL_free(row[i]); - OPENSSL_free(irow); } + OPENSSL_free(irow); X509_NAME_free(CAname); X509_NAME_free(subject); - if (dn_subject != subject) - X509_NAME_free(dn_subject); if (ok <= 0) X509_free(ret); else @@ -2040,6 +2052,11 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value) else row[DB_serial] = BN_bn2hex(bn); BN_free(bn); + if (row[DB_name] != NULL && row[DB_name][0] == '\0') { + /* Entries with empty Subjects actually use the serial number instead */ + OPENSSL_free(row[DB_name]); + row[DB_name] = OPENSSL_strdup(row[DB_serial]); + } if ((row[DB_name] == NULL) || (row[DB_serial] == NULL)) { BIO_printf(bio_err, "Memory allocation failure\n"); goto end; @@ -2200,7 +2217,10 @@ static int do_updatedb(CA_DB *db) return -1; /* get actual time and make a string */ - a_tm = X509_gmtime_adj(a_tm, 0); + if (X509_gmtime_adj(a_tm, 0) == NULL) { + ASN1_UTCTIME_free(a_tm); + return -1; + } a_tm_s = app_malloc(a_tm->length + 1, "time string"); memcpy(a_tm_s, a_tm->data, a_tm->length); diff --git a/apps/ciphers.c b/apps/ciphers.c index c0f43ea2..e1b5b255 100644 --- a/apps/ciphers.c +++ b/apps/ciphers.c @@ -225,7 +225,7 @@ int ciphers_main(int argc, char **argv) BIO_printf(bio_out, "%s - ", nm); } #endif - BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof buf)); + BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof(buf))); } } diff --git a/apps/cms.c b/apps/cms.c index 579b2273..640f92eb 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2008-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -931,11 +931,15 @@ int cms_main(int argc, char **argv) keyfile = sk_OPENSSL_STRING_value(skkeys, i); signer = load_cert(signerfile, FORMAT_PEM, "signer certificate"); - if (!signer) + if (!signer) { + ret = 2; goto end; + } key = load_key(keyfile, keyform, 0, passin, e, "signing key file"); - if (!key) + if (!key) { + ret = 2; goto end; + } for (kparam = key_first; kparam; kparam = kparam->next) { if (kparam->idx == i) { tflags |= CMS_KEY_PARAM; diff --git a/apps/dhparam.c b/apps/dhparam.c index 0616333a..94322e37 100644 --- a/apps/dhparam.c +++ b/apps/dhparam.c @@ -326,9 +326,9 @@ int dhparam_main(int argc, char **argv) "\n" " if (dh == NULL)\n" " return NULL;\n"); - BIO_printf(out, " dhp_bn = BN_bin2bn(dhp_%d, sizeof (dhp_%d), NULL);\n", + BIO_printf(out, " dhp_bn = BN_bin2bn(dhp_%d, sizeof(dhp_%d), NULL);\n", bits, bits); - BIO_printf(out, " dhg_bn = BN_bin2bn(dhg_%d, sizeof (dhg_%d), NULL);\n", + BIO_printf(out, " dhg_bn = BN_bin2bn(dhg_%d, sizeof(dhg_%d), NULL);\n", bits, bits); BIO_printf(out, " if (dhp_bn == NULL || dhg_bn == NULL\n" " || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {\n" diff --git a/apps/dsa.c b/apps/dsa.c index 9c935491..8454b2e9 100644 --- a/apps/dsa.c +++ b/apps/dsa.c @@ -217,6 +217,9 @@ int dsa_main(int argc, char **argv) } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) { EVP_PKEY *pk; pk = EVP_PKEY_new(); + if (pk == NULL) + goto end; + EVP_PKEY_set1_DSA(pk, dsa); if (outformat == FORMAT_PVK) { if (pubin) { diff --git a/apps/dsaparam.c b/apps/dsaparam.c index 92588030..5c3c8f80 100644 --- a/apps/dsaparam.c +++ b/apps/dsaparam.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -234,11 +234,11 @@ int dsaparam_main(int argc, char **argv) "\n"); BIO_printf(bio_out, " if (dsa == NULL)\n" " return NULL;\n"); - BIO_printf(bio_out, " dsa->p = BN_bin2bn(dsap_%d, sizeof (dsap_%d), NULL);\n", + BIO_printf(bio_out, " dsa->p = BN_bin2bn(dsap_%d, sizeof(dsap_%d), NULL);\n", bits_p, bits_p); - BIO_printf(bio_out, " dsa->q = BN_bin2bn(dsaq_%d, sizeof (dsaq_%d), NULL);\n", + BIO_printf(bio_out, " dsa->q = BN_bin2bn(dsaq_%d, sizeof(dsaq_%d), NULL);\n", bits_p, bits_p); - BIO_printf(bio_out, " dsa->g = BN_bin2bn(dsag_%d, sizeof (dsag_%d), NULL);\n", + BIO_printf(bio_out, " dsa->g = BN_bin2bn(dsag_%d, sizeof(dsag_%d), NULL);\n", bits_p, bits_p); BIO_printf(bio_out, " if (!dsa->p || !dsa->q || !dsa->g) {\n" " DSA_free(dsa);\n" @@ -248,6 +248,9 @@ int dsaparam_main(int argc, char **argv) OPENSSL_free(data); } + if (outformat == FORMAT_ASN1 && genkey) + noout = 1; + if (!noout) { if (outformat == FORMAT_ASN1) i = i2d_DSAparams_bio(out, dsa); diff --git a/apps/ecparam.c b/apps/ecparam.c index 891a0cac..999f7487 100644 --- a/apps/ecparam.c +++ b/apps/ecparam.c @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -357,24 +357,24 @@ int ecparam_main(int argc, char **argv) " BIGNUM *tmp_3 = NULL;\n" "\n"); - BIO_printf(out, " if ((tmp_1 = BN_bin2bn(ec_p_%d, sizeof (ec_p_%d), NULL)) == NULL)\n" + BIO_printf(out, " if ((tmp_1 = BN_bin2bn(ec_p_%d, sizeof(ec_p_%d), NULL)) == NULL)\n" " goto err;\n", len, len); - BIO_printf(out, " if ((tmp_2 = BN_bin2bn(ec_a_%d, sizeof (ec_a_%d), NULL)) == NULL)\n" + BIO_printf(out, " if ((tmp_2 = BN_bin2bn(ec_a_%d, sizeof(ec_a_%d), NULL)) == NULL)\n" " goto err;\n", len, len); - BIO_printf(out, " if ((tmp_3 = BN_bin2bn(ec_b_%d, sizeof (ec_b_%d), NULL)) == NULL)\n" + BIO_printf(out, " if ((tmp_3 = BN_bin2bn(ec_b_%d, sizeof(ec_b_%d), NULL)) == NULL)\n" " goto err;\n", len, len); BIO_printf(out, " if ((group = EC_GROUP_new_curve_GFp(tmp_1, tmp_2, tmp_3, NULL)) == NULL)\n" " goto err;\n" "\n"); BIO_printf(out, " /* build generator */\n"); - BIO_printf(out, " if ((tmp_1 = BN_bin2bn(ec_gen_%d, sizeof (ec_gen_%d), tmp_1)) == NULL)\n" + BIO_printf(out, " if ((tmp_1 = BN_bin2bn(ec_gen_%d, sizeof(ec_gen_%d), tmp_1)) == NULL)\n" " goto err;\n", len, len); BIO_printf(out, " point = EC_POINT_bn2point(group, tmp_1, NULL, NULL);\n"); BIO_printf(out, " if (point == NULL)\n" " goto err;\n"); - BIO_printf(out, " if ((tmp_2 = BN_bin2bn(ec_order_%d, sizeof (ec_order_%d), tmp_2)) == NULL)\n" + BIO_printf(out, " if ((tmp_2 = BN_bin2bn(ec_order_%d, sizeof(ec_order_%d), tmp_2)) == NULL)\n" " goto err;\n", len, len); - BIO_printf(out, " if ((tmp_3 = BN_bin2bn(ec_cofactor_%d, sizeof (ec_cofactor_%d), tmp_3)) == NULL)\n" + BIO_printf(out, " if ((tmp_3 = BN_bin2bn(ec_cofactor_%d, sizeof(ec_cofactor_%d), tmp_3)) == NULL)\n" " goto err;\n", len, len); BIO_printf(out, " if (!EC_GROUP_set_generator(group, point, tmp_2, tmp_3))\n" " goto err;\n" @@ -393,6 +393,9 @@ int ecparam_main(int argc, char **argv) "}\n"); } + if (outformat == FORMAT_ASN1 && genkey) + noout = 1; + if (!noout) { if (outformat == FORMAT_ASN1) i = i2d_ECPKParameters_bio(out, group); @@ -428,6 +431,9 @@ int ecparam_main(int argc, char **argv) goto end; } + if (new_form) + EC_KEY_set_conv_form(eckey, form); + if (!EC_KEY_generate_key(eckey)) { BIO_printf(bio_err, "unable to generate key\n"); EC_KEY_free(eckey); diff --git a/apps/enc.c b/apps/enc.c index c9065633..df553811 100644 --- a/apps/enc.c +++ b/apps/enc.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -96,7 +96,7 @@ int enc_main(int argc, char **argv) char *hkey = NULL, *hiv = NULL, *hsalt = NULL, *p; char *infile = NULL, *outfile = NULL, *prog; char *str = NULL, *passarg = NULL, *pass = NULL, *strbuf = NULL; - char mbuf[sizeof magic - 1]; + char mbuf[sizeof(magic) - 1]; OPTION_CHOICE o; int bsize = BSIZE, verbose = 0, debug = 0, olb64 = 0, nosalt = 0; int enc = 1, printkey = 0, i, k; @@ -218,7 +218,7 @@ int enc_main(int argc, char **argv) in = bio_open_default(opt_arg(), 'r', FORMAT_TEXT); if (in == NULL) goto opthelp; - i = BIO_gets(in, buf, sizeof buf); + i = BIO_gets(in, buf, sizeof(buf)); BIO_free(in); in = NULL; if (i <= 0) { @@ -257,6 +257,10 @@ int enc_main(int argc, char **argv) break; } } + if (opt_num_rest() != 0) { + BIO_printf(bio_err, "Extra arguments given.\n"); + goto opthelp; + } if (cipher && EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) { BIO_printf(bio_err, "%s: AEAD ciphers not supported\n", prog); @@ -311,7 +315,7 @@ int enc_main(int argc, char **argv) for (;;) { char prompt[200]; - BIO_snprintf(prompt, sizeof prompt, "enter %s %s password:", + BIO_snprintf(prompt, sizeof(prompt), "enter %s %s password:", OBJ_nid2ln(EVP_CIPHER_nid(cipher)), (enc) ? "encryption" : "decryption"); strbuf[0] = '\0'; @@ -398,31 +402,31 @@ int enc_main(int argc, char **argv) else { if (enc) { if (hsalt) { - if (!set_hex(hsalt, salt, sizeof salt)) { + if (!set_hex(hsalt, salt, sizeof(salt))) { BIO_printf(bio_err, "invalid hex salt value\n"); goto end; } - } else if (RAND_bytes(salt, sizeof salt) <= 0) + } else if (RAND_bytes(salt, sizeof(salt)) <= 0) goto end; /* * If -P option then don't bother writing */ if ((printkey != 2) && (BIO_write(wbio, magic, - sizeof magic - 1) != sizeof magic - 1 + sizeof(magic) - 1) != sizeof(magic) - 1 || BIO_write(wbio, (char *)salt, - sizeof salt) != sizeof salt)) { + sizeof(salt)) != sizeof(salt))) { BIO_printf(bio_err, "error writing output file\n"); goto end; } - } else if (BIO_read(rbio, mbuf, sizeof mbuf) != sizeof mbuf + } else if (BIO_read(rbio, mbuf, sizeof(mbuf)) != sizeof(mbuf) || BIO_read(rbio, (unsigned char *)salt, - sizeof salt) != sizeof salt) { + sizeof(salt)) != sizeof(salt)) { BIO_printf(bio_err, "error reading input file\n"); goto end; - } else if (memcmp(mbuf, magic, sizeof magic - 1)) { + } else if (memcmp(mbuf, magic, sizeof(magic) - 1)) { BIO_printf(bio_err, "bad magic number\n"); goto end; } @@ -449,7 +453,7 @@ int enc_main(int argc, char **argv) int siz = EVP_CIPHER_iv_length(cipher); if (siz == 0) { BIO_printf(bio_err, "warning: iv not use by this cipher\n"); - } else if (!set_hex(hiv, iv, sizeof iv)) { + } else if (!set_hex(hiv, iv, sizeof(iv))) { BIO_printf(bio_err, "invalid hex iv value\n"); goto end; } diff --git a/apps/engine.c b/apps/engine.c index ffd31374..4eeb6424 100644 --- a/apps/engine.c +++ b/apps/engine.c @@ -311,6 +311,7 @@ int engine_main(int argc, char **argv) break; case OPT_TT: test_avail_noise++; + /* fall thru */ case OPT_T: test_avail++; break; diff --git a/apps/errstr.c b/apps/errstr.c index 5fda799d..79d83ee4 100644 --- a/apps/errstr.c +++ b/apps/errstr.c @@ -58,7 +58,7 @@ int errstr_main(int argc, char **argv) */ OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); - ERR_error_string_n(l, buf, sizeof buf); + ERR_error_string_n(l, buf, sizeof(buf)); BIO_printf(bio_out, "%s\n", buf); } } diff --git a/apps/genrsa.c b/apps/genrsa.c index 1ac66a97..19bc7535 100644 --- a/apps/genrsa.c +++ b/apps/genrsa.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -78,6 +78,7 @@ int genrsa_main(int argc, char **argv) switch (o) { case OPT_EOF: case OPT_ERR: +opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: @@ -110,11 +111,16 @@ int genrsa_main(int argc, char **argv) } argc = opt_num_rest(); argv = opt_rest(); + + if (argc == 1) { + if (!opt_int(argv[0], &num) || num <= 0) + goto end; + } else if (argc > 0) { + BIO_printf(bio_err, "Extra arguments given.\n"); + goto opthelp; + } + private = 1; - - if (argv[0] && (!opt_int(argv[0], &num) || num <= 0)) - goto end; - if (!app_passwd(NULL, passoutarg, NULL, &passout)) { BIO_printf(bio_err, "Error getting password\n"); goto end; diff --git a/apps/ocsp.c b/apps/ocsp.c index 41ea9703..4b533348 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -1074,7 +1074,7 @@ static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio) *pcbio = cbio; /* Read the request line. */ - len = BIO_gets(cbio, reqbuf, sizeof reqbuf); + len = BIO_gets(cbio, reqbuf, sizeof(reqbuf)); if (len <= 0) return 1; if (strncmp(reqbuf, "GET ", 4) == 0) { @@ -1116,7 +1116,7 @@ static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio) /* Read and skip past the headers. */ for (;;) { - len = BIO_gets(cbio, inbuf, sizeof inbuf); + len = BIO_gets(cbio, inbuf, sizeof(inbuf)); if (len <= 0) return 1; if ((inbuf[0] == '\r') || (inbuf[0] == '\n')) diff --git a/apps/openssl.c b/apps/openssl.c index e69e7d9b..2607694f 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -69,8 +69,8 @@ static int apps_startup() #endif /* Set non-default library initialisation settings */ - if (!OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN - | OPENSSL_INIT_LOAD_CONFIG, NULL)) + if (!OPENSSL_init_ssl(OPENSSL_INIT_ENGINE_ALL_BUILTIN + | OPENSSL_INIT_LOAD_CONFIG, NULL)) return 0; #ifndef OPENSSL_NO_UI @@ -154,8 +154,13 @@ int main(int argc, char *argv[]) #endif } - if (!apps_startup()) + if (!apps_startup()) { + BIO_printf(bio_err, + "FATAL: Startup failure (dev note: apps_startup() failed)\n"); + ERR_print_errors(bio_err); + ret = 1; goto end; + } prog = prog_init(); pname = opt_progname(argv[0]); @@ -183,7 +188,7 @@ int main(int argc, char *argv[]) for (;;) { ret = 0; /* Read a line, continue reading if line ends with \ */ - for (p = buf, n = sizeof buf, i = 0, first = 1; n > 0; first = 0) { + for (p = buf, n = sizeof(buf), i = 0, first = 1; n > 0; first = 0) { prompt = first ? "OpenSSL> " : "> "; p[0] = '\0'; #ifndef READLINE @@ -329,6 +334,7 @@ int list_main(int argc, char **argv) switch (o) { case OPT_EOF: /* Never hit, but suppresses warning */ case OPT_ERR: +opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); return 1; case OPT_HELP: @@ -358,12 +364,14 @@ int list_main(int argc, char **argv) } done = 1; } - - if (!done) { - BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); - return 1; + if (opt_num_rest() != 0) { + BIO_printf(bio_err, "Extra arguments given.\n"); + goto opthelp; } + if (!done) + goto opthelp; + return 0; } diff --git a/apps/opt.c b/apps/opt.c index f72ac64e..6e40f648 100644 --- a/apps/opt.c +++ b/apps/opt.c @@ -60,10 +60,10 @@ char *opt_progname(const char *argv0) n -= 4; /* Copy over the name, in lowercase. */ - if (n > sizeof prog - 1) - n = sizeof prog - 1; + if (n > sizeof(prog) - 1) + n = sizeof(prog) - 1; for (q = prog, i = 0; i < n; i++, p++) - *q++ = isupper(*p) ? tolower(*p) : *p; + *q++ = tolower((unsigned char)*p); *q = '\0'; return prog; } @@ -82,9 +82,9 @@ char *opt_progname(const char *argv0) } q = strrchr(p, '.'); - strncpy(prog, p, sizeof prog - 1); - prog[sizeof prog - 1] = '\0'; - if (q != NULL && q - p < sizeof prog) + strncpy(prog, p, sizeof(prog) - 1); + prog[sizeof(prog) - 1] = '\0'; + if (q != NULL && q - p < sizeof(prog)) prog[q - p] = '\0'; return prog; } @@ -101,8 +101,8 @@ char *opt_progname(const char *argv0) p++; break; } - strncpy(prog, p, sizeof prog - 1); - prog[sizeof prog - 1] = '\0'; + strncpy(prog, p, sizeof(prog) - 1); + prog[sizeof(prog) - 1] = '\0'; return prog; } #endif @@ -840,7 +840,7 @@ void opt_help(const OPTIONS *list) i += 1 + strlen(valtype2param(o)); if (i < MAX_OPT_HELP_WIDTH && i > width) width = i; - assert(i < (int)sizeof start); + assert(i < (int)sizeof(start)); } if (standard_prolog) @@ -857,7 +857,7 @@ void opt_help(const OPTIONS *list) /* Pad out prefix */ memset(start, ' ', sizeof(start) - 1); - start[sizeof start - 1] = '\0'; + start[sizeof(start) - 1] = '\0'; if (o->name == OPT_MORE_STR) { /* Continuation of previous line; pad and print. */ diff --git a/apps/passwd.c b/apps/passwd.c index 98fae52e..f2b0d9a2 100644 --- a/apps/passwd.c +++ b/apps/passwd.c @@ -79,9 +79,9 @@ int passwd_main(int argc, char **argv) char *salt_malloc = NULL, *passwd_malloc = NULL, *prog; OPTION_CHOICE o; int in_stdin = 0, pw_source_defined = 0; -#ifndef OPENSSL_NO_UI +# ifndef OPENSSL_NO_UI int in_noverify = 0; -#endif +# endif int passed_salt = 0, quiet = 0, table = 0, reverse = 0; int ret = 1, usecrypt = 0, use1 = 0, useapr1 = 0; size_t passwd_malloc_size = 0, pw_maxlen = 256; @@ -105,9 +105,9 @@ int passwd_main(int argc, char **argv) pw_source_defined = 1; break; case OPT_NOVERIFY: -#ifndef OPENSSL_NO_UI +# ifndef OPENSSL_NO_UI in_noverify = 1; -#endif +# endif break; case OPT_QUIET: quiet = 1; @@ -198,26 +198,31 @@ int passwd_main(int argc, char **argv) } if ((in == NULL) && (passwds == NULL)) { + /* + * we use the following method to make sure what + * in the 'else' section is always compiled, to + * avoid rot of not-frequently-used code. + */ if (1) { -#ifndef OPENSSL_NO_UI +# ifndef OPENSSL_NO_UI /* build a null-terminated list */ static char *passwds_static[2] = { NULL, NULL }; passwds = passwds_static; - if (in == NULL) + if (in == NULL) { if (EVP_read_pw_string (passwd_malloc, passwd_malloc_size, "Password: ", !(passed_salt || in_noverify)) != 0) goto end; + } passwds[0] = passwd_malloc; } else { -#endif +# endif BIO_printf(bio_err, "password required\n"); goto end; } } - if (in == NULL) { assert(passwds != NULL); assert(*passwds != NULL); @@ -228,11 +233,9 @@ int passwd_main(int argc, char **argv) quiet, table, reverse, pw_maxlen, usecrypt, use1, useapr1)) goto end; - } - while (*passwds != NULL); - } else + } while (*passwds != NULL); + } else { /* in != NULL */ - { int done; assert(passwd != NULL); @@ -240,13 +243,13 @@ int passwd_main(int argc, char **argv) int r = BIO_gets(in, passwd, pw_maxlen + 1); if (r > 0) { char *c = (strchr(passwd, '\n')); - if (c != NULL) + if (c != NULL) { *c = 0; /* truncate at newline */ - else { + } else { /* ignore rest of line */ char trash[BUFSIZ]; do - r = BIO_gets(in, trash, sizeof trash); + r = BIO_gets(in, trash, sizeof(trash)); while ((r > 0) && (!strchr(trash, '\n'))); } @@ -256,8 +259,7 @@ int passwd_main(int argc, char **argv) goto end; } done = (r <= 0); - } - while (!done); + } while (!done); } ret = 0; @@ -298,9 +300,9 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) if (magic_len > 4) /* assert it's "1" or "apr1" */ return NULL; - OPENSSL_strlcat(out_buf, magic, sizeof out_buf); - OPENSSL_strlcat(out_buf, "$", sizeof out_buf); - OPENSSL_strlcat(out_buf, salt, sizeof out_buf); + OPENSSL_strlcat(out_buf, magic, sizeof(out_buf)); + OPENSSL_strlcat(out_buf, "$", sizeof(out_buf)); + OPENSSL_strlcat(out_buf, salt, sizeof(out_buf)); if (strlen(out_buf) > 6 + 8) /* assert "$apr1$..salt.." */ return NULL; @@ -330,8 +332,8 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) || !EVP_DigestFinal_ex(md2, buf, NULL)) goto err; - for (i = passwd_len; i > sizeof buf; i -= sizeof buf) { - if (!EVP_DigestUpdate(md, buf, sizeof buf)) + for (i = passwd_len; i > sizeof(buf); i -= sizeof(buf)) { + if (!EVP_DigestUpdate(md, buf, sizeof(buf))) goto err; } if (!EVP_DigestUpdate(md, buf, i)) @@ -351,7 +353,7 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) goto err; if (!EVP_DigestUpdate(md2, (i & 1) ? (unsigned const char *)passwd : buf, - (i & 1) ? passwd_len : sizeof buf)) + (i & 1) ? passwd_len : sizeof(buf))) goto err; if (i % 3) { if (!EVP_DigestUpdate(md2, salt_out, salt_len)) @@ -363,7 +365,7 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) } if (!EVP_DigestUpdate(md2, (i & 1) ? buf : (unsigned const char *)passwd, - (i & 1) ? sizeof buf : passwd_len)) + (i & 1) ? sizeof(buf) : passwd_len)) goto err; if (!EVP_DigestFinal_ex(md2, buf, NULL)) goto err; @@ -375,7 +377,7 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) { /* transform buf into output string */ - unsigned char buf_perm[sizeof buf]; + unsigned char buf_perm[sizeof(buf)]; int dest, source; char *output; @@ -387,7 +389,7 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) buf_perm[15] = buf[11]; # ifndef PEDANTIC /* Unfortunately, this generates a "no * effect" warning */ - assert(16 == sizeof buf_perm); + assert(16 == sizeof(buf_perm)); # endif output = salt_out + salt_len; @@ -433,9 +435,8 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, if (!passed_salt) { # ifndef OPENSSL_NO_DES if (usecrypt) { - if (*salt_malloc_p == NULL) { + if (*salt_malloc_p == NULL) *salt_p = *salt_malloc_p = app_malloc(3, "salt buffer"); - } if (RAND_bytes((unsigned char *)*salt_p, 2) <= 0) goto end; (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f]; /* 6 bits */ @@ -452,9 +453,8 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p, if (use1 || useapr1) { int i; - if (*salt_malloc_p == NULL) { + if (*salt_malloc_p == NULL) *salt_p = *salt_malloc_p = app_malloc(9, "salt buffer"); - } if (RAND_bytes((unsigned char *)*salt_p, 8) <= 0) goto end; diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 6c07e810..85f649d8 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -323,7 +323,7 @@ int pkcs12_main(int argc, char **argv) if (1) { #ifndef OPENSSL_NO_UI if (EVP_read_pw_string - (macpass, sizeof macpass, "Enter MAC Password:", export_cert)) { + (macpass, sizeof(macpass), "Enter MAC Password:", export_cert)) { BIO_printf(bio_err, "Can't read Password\n"); goto end; } @@ -440,7 +440,7 @@ int pkcs12_main(int argc, char **argv) if (!noprompt) { if (1) { #ifndef OPENSSL_NO_UI - if (EVP_read_pw_string(pass, sizeof pass, "Enter Export Password:", + if (EVP_read_pw_string(pass, sizeof(pass), "Enter Export Password:", 1)) { BIO_printf(bio_err, "Can't read Password\n"); goto export_end; @@ -453,7 +453,7 @@ int pkcs12_main(int argc, char **argv) } if (!twopass) - OPENSSL_strlcpy(macpass, pass, sizeof macpass); + OPENSSL_strlcpy(macpass, pass, sizeof(macpass)); p12 = PKCS12_create(cpass, name, key, ucert, certs, key_pbe, cert_pbe, iter, -1, keytype); @@ -506,7 +506,7 @@ int pkcs12_main(int argc, char **argv) if (!noprompt) { if (1) { #ifndef OPENSSL_NO_UI - if (EVP_read_pw_string(pass, sizeof pass, "Enter Import Password:", + if (EVP_read_pw_string(pass, sizeof(pass), "Enter Import Password:", 0)) { BIO_printf(bio_err, "Can't read Password\n"); goto end; @@ -519,7 +519,7 @@ int pkcs12_main(int argc, char **argv) } if (!twopass) - OPENSSL_strlcpy(macpass, pass, sizeof macpass); + OPENSSL_strlcpy(macpass, pass, sizeof(macpass)); if ((options & INFO) && PKCS12_mac_present(p12)) { const ASN1_INTEGER *tmaciter; diff --git a/apps/pkcs8.c b/apps/pkcs8.c index 4b3fa10d..0874370d 100644 --- a/apps/pkcs8.c +++ b/apps/pkcs8.c @@ -238,7 +238,7 @@ int pkcs8_main(int argc, char **argv) #ifndef OPENSSL_NO_UI p8pass = pass; if (EVP_read_pw_string - (pass, sizeof pass, "Enter Encryption Password:", 1)) { + (pass, sizeof(pass), "Enter Encryption Password:", 1)) { X509_ALGOR_free(pbe); goto end; } @@ -300,7 +300,7 @@ int pkcs8_main(int argc, char **argv) else if (1) { #ifndef OPENSSL_NO_UI p8pass = pass; - if (EVP_read_pw_string(pass, sizeof pass, "Enter Password:", 0)) { + if (EVP_read_pw_string(pass, sizeof(pass), "Enter Password:", 0)) { BIO_printf(bio_err, "Can't read Password\n"); goto end; } diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c index 962a389d..bbb1274f 100644 --- a/apps/pkeyutl.c +++ b/apps/pkeyutl.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -81,8 +81,7 @@ int pkeyutl_main(int argc, char **argv) char hexdump = 0, asn1parse = 0, rev = 0, *prog; unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL; OPTION_CHOICE o; - int buf_inlen = 0, siglen = -1, keyform = FORMAT_PEM, peerform = - FORMAT_PEM; + int buf_inlen = 0, siglen = -1, keyform = FORMAT_PEM, peerform = FORMAT_PEM; int keysize = -1, pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY; int engine_impl = 0; int ret = 1, rv = -1; @@ -193,10 +192,18 @@ int pkeyutl_main(int argc, char **argv) goto opthelp; if (kdfalg != NULL) { - if (kdflen == 0) + if (kdflen == 0) { + BIO_printf(bio_err, + "%s: no KDF length given (-kdflen parameter).\n", prog); goto opthelp; - } else if ((inkey == NULL) - || (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE)) { + } + } else if (inkey == NULL) { + BIO_printf(bio_err, + "%s: no private key given (-inkey parameter).\n", prog); + goto opthelp; + } else if (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE) { + BIO_printf(bio_err, + "%s: no peer key given (-peerkey parameter).\n", prog); goto opthelp; } ctx = init_ctx(kdfalg, &keysize, inkey, keyform, key_type, @@ -219,7 +226,8 @@ int pkeyutl_main(int argc, char **argv) const char *opt = sk_OPENSSL_STRING_value(pkeyopts, i); if (pkey_ctrl_string(ctx, opt) <= 0) { - BIO_printf(bio_err, "%s: Can't set parameter:\n", prog); + BIO_printf(bio_err, "%s: Can't set parameter \"%s\":\n", + prog, opt); ERR_print_errors(bio_err); goto end; } @@ -307,7 +315,11 @@ int pkeyutl_main(int argc, char **argv) buf_in, (size_t)buf_inlen); } if (rv <= 0) { - BIO_puts(bio_err, "Public Key operation error\n"); + if (pkey_op != EVP_PKEY_OP_DERIVE) { + BIO_puts(bio_err, "Public Key operation error\n"); + } else { + BIO_puts(bio_err, "Key derivation failed\n"); + } ERR_print_errors(bio_err); goto end; } @@ -383,8 +395,15 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize, if (kdfalg) { int kdfnid = OBJ_sn2nid(kdfalg); - if (kdfnid == NID_undef) - goto end; + + if (kdfnid == NID_undef) { + kdfnid = OBJ_ln2nid(kdfalg); + if (kdfnid == NID_undef) { + BIO_printf(bio_err, "The given KDF \"%s\" is unknown.\n", + kdfalg); + goto end; + } + } ctx = EVP_PKEY_CTX_new_id(kdfnid, impl); } else { if (pkey == NULL) @@ -435,10 +454,10 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize, } static int setup_peer(EVP_PKEY_CTX *ctx, int peerform, const char *file, - ENGINE* e) + ENGINE *e) { EVP_PKEY *peer = NULL; - ENGINE* engine = NULL; + ENGINE *engine = NULL; int ret; if (peerform == FORMAT_ENGINE) diff --git a/apps/prime.c b/apps/prime.c index b0f5969a..c12463d8 100644 --- a/apps/prime.c +++ b/apps/prime.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -43,6 +43,7 @@ int prime_main(int argc, char **argv) switch (o) { case OPT_EOF: case OPT_ERR: +opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: @@ -69,9 +70,14 @@ int prime_main(int argc, char **argv) argc = opt_num_rest(); argv = opt_rest(); - if (argc == 0 && !generate) { + if (generate) { + if (argc != 0) { + BIO_printf(bio_err, "Extra arguments given.\n"); + goto opthelp; + } + } else if (argc == 0) { BIO_printf(bio_err, "%s: No prime specified\n", prog); - goto end; + goto opthelp; } if (generate) { diff --git a/apps/progs.h b/apps/progs.h deleted file mode 100644 index 5f6f07f8..00000000 --- a/apps/progs.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - * WARNING: do not edit! - * Generated by apps/progs.pl - * - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -typedef enum FUNC_TYPE { - FT_none, FT_general, FT_md, FT_cipher, FT_pkey, - FT_md_alg, FT_cipher_alg -} FUNC_TYPE; - -typedef struct function_st { - FUNC_TYPE type; - const char *name; - int (*func)(int argc, char *argv[]); - const OPTIONS *help; -} FUNCTION; - -DEFINE_LHASH_OF(FUNCTION); - -extern int asn1parse_main(int argc, char *argv[]); -extern int ca_main(int argc, char *argv[]); -extern int ciphers_main(int argc, char *argv[]); -extern int cms_main(int argc, char *argv[]); -extern int crl_main(int argc, char *argv[]); -extern int crl2pkcs7_main(int argc, char *argv[]); -extern int dgst_main(int argc, char *argv[]); -extern int dhparam_main(int argc, char *argv[]); -extern int dsa_main(int argc, char *argv[]); -extern int dsaparam_main(int argc, char *argv[]); -extern int ec_main(int argc, char *argv[]); -extern int ecparam_main(int argc, char *argv[]); -extern int enc_main(int argc, char *argv[]); -extern int engine_main(int argc, char *argv[]); -extern int errstr_main(int argc, char *argv[]); -extern int exit_main(int argc, char *argv[]); -extern int gendsa_main(int argc, char *argv[]); -extern int genpkey_main(int argc, char *argv[]); -extern int genrsa_main(int argc, char *argv[]); -extern int help_main(int argc, char *argv[]); -extern int list_main(int argc, char *argv[]); -extern int nseq_main(int argc, char *argv[]); -extern int ocsp_main(int argc, char *argv[]); -extern int passwd_main(int argc, char *argv[]); -extern int pkcs12_main(int argc, char *argv[]); -extern int pkcs7_main(int argc, char *argv[]); -extern int pkcs8_main(int argc, char *argv[]); -extern int pkey_main(int argc, char *argv[]); -extern int pkeyparam_main(int argc, char *argv[]); -extern int pkeyutl_main(int argc, char *argv[]); -extern int prime_main(int argc, char *argv[]); -extern int rand_main(int argc, char *argv[]); -extern int rehash_main(int argc, char *argv[]); -extern int req_main(int argc, char *argv[]); -extern int rsa_main(int argc, char *argv[]); -extern int rsautl_main(int argc, char *argv[]); -extern int s_client_main(int argc, char *argv[]); -extern int s_server_main(int argc, char *argv[]); -extern int s_time_main(int argc, char *argv[]); -extern int sess_id_main(int argc, char *argv[]); -extern int smime_main(int argc, char *argv[]); -extern int speed_main(int argc, char *argv[]); -extern int spkac_main(int argc, char *argv[]); -extern int srp_main(int argc, char *argv[]); -extern int ts_main(int argc, char *argv[]); -extern int verify_main(int argc, char *argv[]); -extern int version_main(int argc, char *argv[]); -extern int x509_main(int argc, char *argv[]); - -extern OPTIONS asn1parse_options[]; -extern OPTIONS ca_options[]; -extern OPTIONS ciphers_options[]; -extern OPTIONS cms_options[]; -extern OPTIONS crl_options[]; -extern OPTIONS crl2pkcs7_options[]; -extern OPTIONS dgst_options[]; -extern OPTIONS dhparam_options[]; -extern OPTIONS dsa_options[]; -extern OPTIONS dsaparam_options[]; -extern OPTIONS ec_options[]; -extern OPTIONS ecparam_options[]; -extern OPTIONS enc_options[]; -extern OPTIONS engine_options[]; -extern OPTIONS errstr_options[]; -extern OPTIONS exit_options[]; -extern OPTIONS gendsa_options[]; -extern OPTIONS genpkey_options[]; -extern OPTIONS genrsa_options[]; -extern OPTIONS help_options[]; -extern OPTIONS list_options[]; -extern OPTIONS nseq_options[]; -extern OPTIONS ocsp_options[]; -extern OPTIONS passwd_options[]; -extern OPTIONS pkcs12_options[]; -extern OPTIONS pkcs7_options[]; -extern OPTIONS pkcs8_options[]; -extern OPTIONS pkey_options[]; -extern OPTIONS pkeyparam_options[]; -extern OPTIONS pkeyutl_options[]; -extern OPTIONS prime_options[]; -extern OPTIONS rand_options[]; -extern OPTIONS rehash_options[]; -extern OPTIONS req_options[]; -extern OPTIONS rsa_options[]; -extern OPTIONS rsautl_options[]; -extern OPTIONS s_client_options[]; -extern OPTIONS s_server_options[]; -extern OPTIONS s_time_options[]; -extern OPTIONS sess_id_options[]; -extern OPTIONS smime_options[]; -extern OPTIONS speed_options[]; -extern OPTIONS spkac_options[]; -extern OPTIONS srp_options[]; -extern OPTIONS ts_options[]; -extern OPTIONS verify_options[]; -extern OPTIONS version_options[]; -extern OPTIONS x509_options[]; - -#ifdef INCLUDE_FUNCTION_TABLE -static FUNCTION functions[] = { - { FT_general, "asn1parse", asn1parse_main, asn1parse_options }, - { FT_general, "ca", ca_main, ca_options }, -#ifndef OPENSSL_NO_SOCK - { FT_general, "ciphers", ciphers_main, ciphers_options }, -#endif -#ifndef OPENSSL_NO_CMS - { FT_general, "cms", cms_main, cms_options }, -#endif - { FT_general, "crl", crl_main, crl_options }, - { FT_general, "crl2pkcs7", crl2pkcs7_main, crl2pkcs7_options }, - { FT_general, "dgst", dgst_main, dgst_options }, -#ifndef OPENSSL_NO_DH - { FT_general, "dhparam", dhparam_main, dhparam_options }, -#endif -#ifndef OPENSSL_NO_DSA - { FT_general, "dsa", dsa_main, dsa_options }, -#endif -#ifndef OPENSSL_NO_DSA - { FT_general, "dsaparam", dsaparam_main, dsaparam_options }, -#endif -#ifndef OPENSSL_NO_EC - { FT_general, "ec", ec_main, ec_options }, -#endif -#ifndef OPENSSL_NO_EC - { FT_general, "ecparam", ecparam_main, ecparam_options }, -#endif - { FT_general, "enc", enc_main, enc_options }, -#ifndef OPENSSL_NO_ENGINE - { FT_general, "engine", engine_main, engine_options }, -#endif - { FT_general, "errstr", errstr_main, errstr_options }, - { FT_general, "exit", exit_main, exit_options }, -#ifndef OPENSSL_NO_DSA - { FT_general, "gendsa", gendsa_main, gendsa_options }, -#endif - { FT_general, "genpkey", genpkey_main, genpkey_options }, -#ifndef OPENSSL_NO_RSA - { FT_general, "genrsa", genrsa_main, genrsa_options }, -#endif - { FT_general, "help", help_main, help_options }, - { FT_general, "list", list_main, list_options }, - { FT_general, "nseq", nseq_main, nseq_options }, -#ifndef OPENSSL_NO_OCSP - { FT_general, "ocsp", ocsp_main, ocsp_options }, -#endif - { FT_general, "passwd", passwd_main, passwd_options }, -#ifndef OPENSSL_NO_DES - { FT_general, "pkcs12", pkcs12_main, pkcs12_options }, -#endif - { FT_general, "pkcs7", pkcs7_main, pkcs7_options }, - { FT_general, "pkcs8", pkcs8_main, pkcs8_options }, - { FT_general, "pkey", pkey_main, pkey_options }, - { FT_general, "pkeyparam", pkeyparam_main, pkeyparam_options }, - { FT_general, "pkeyutl", pkeyutl_main, pkeyutl_options }, - { FT_general, "prime", prime_main, prime_options }, - { FT_general, "rand", rand_main, rand_options }, - { FT_general, "rehash", rehash_main, rehash_options }, - { FT_general, "req", req_main, req_options }, - { FT_general, "rsa", rsa_main, rsa_options }, -#ifndef OPENSSL_NO_RSA - { FT_general, "rsautl", rsautl_main, rsautl_options }, -#endif -#ifndef OPENSSL_NO_SOCK - { FT_general, "s_client", s_client_main, s_client_options }, -#endif -#ifndef OPENSSL_NO_SOCK - { FT_general, "s_server", s_server_main, s_server_options }, -#endif -#ifndef OPENSSL_NO_SOCK - { FT_general, "s_time", s_time_main, s_time_options }, -#endif - { FT_general, "sess_id", sess_id_main, sess_id_options }, - { FT_general, "smime", smime_main, smime_options }, - { FT_general, "speed", speed_main, speed_options }, - { FT_general, "spkac", spkac_main, spkac_options }, -#ifndef OPENSSL_NO_SRP - { FT_general, "srp", srp_main, srp_options }, -#endif -#ifndef OPENSSL_NO_TS - { FT_general, "ts", ts_main, ts_options }, -#endif - { FT_general, "verify", verify_main, verify_options }, - { FT_general, "version", version_main, version_options }, - { FT_general, "x509", x509_main, x509_options }, -#ifndef OPENSSL_NO_MD2 - { FT_md, "md2", dgst_main}, -#endif -#ifndef OPENSSL_NO_MD4 - { FT_md, "md4", dgst_main}, -#endif - { FT_md, "md5", dgst_main}, -#ifndef OPENSSL_NO_GOST - { FT_md, "gost", dgst_main}, -#endif - { FT_md, "sha1", dgst_main}, - { FT_md, "sha224", dgst_main}, - { FT_md, "sha256", dgst_main}, - { FT_md, "sha384", dgst_main}, - { FT_md, "sha512", dgst_main}, -#ifndef OPENSSL_NO_MDC2 - { FT_md, "mdc2", dgst_main}, -#endif -#ifndef OPENSSL_NO_RMD160 - { FT_md, "rmd160", dgst_main}, -#endif -#ifndef OPENSSL_NO_BLAKE2 - { FT_md, "blake2b512", dgst_main}, -#endif -#ifndef OPENSSL_NO_BLAKE2 - { FT_md, "blake2s256", dgst_main}, -#endif - { FT_cipher, "aes-128-cbc", enc_main, enc_options }, - { FT_cipher, "aes-128-ecb", enc_main, enc_options }, - { FT_cipher, "aes-192-cbc", enc_main, enc_options }, - { FT_cipher, "aes-192-ecb", enc_main, enc_options }, - { FT_cipher, "aes-256-cbc", enc_main, enc_options }, - { FT_cipher, "aes-256-ecb", enc_main, enc_options }, -#ifndef OPENSSL_NO_CAMELLIA - { FT_cipher, "camellia-128-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAMELLIA - { FT_cipher, "camellia-128-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAMELLIA - { FT_cipher, "camellia-192-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAMELLIA - { FT_cipher, "camellia-192-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAMELLIA - { FT_cipher, "camellia-256-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAMELLIA - { FT_cipher, "camellia-256-ecb", enc_main, enc_options }, -#endif - { FT_cipher, "base64", enc_main, enc_options }, -#ifdef ZLIB - { FT_cipher, "zlib", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des3", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "desx", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_IDEA - { FT_cipher, "idea", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_SEED - { FT_cipher, "seed", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC4 - { FT_cipher, "rc4", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC4 - { FT_cipher, "rc4-40", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_BF - { FT_cipher, "bf", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAST - { FT_cipher, "cast", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC5 - { FT_cipher, "rc5", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede3", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede3-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede3-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_DES - { FT_cipher, "des-ede3-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_IDEA - { FT_cipher, "idea-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_IDEA - { FT_cipher, "idea-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_IDEA - { FT_cipher, "idea-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_IDEA - { FT_cipher, "idea-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_SEED - { FT_cipher, "seed-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_SEED - { FT_cipher, "seed-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_SEED - { FT_cipher, "seed-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_SEED - { FT_cipher, "seed-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2-64-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC2 - { FT_cipher, "rc2-40-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_BF - { FT_cipher, "bf-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_BF - { FT_cipher, "bf-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_BF - { FT_cipher, "bf-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_BF - { FT_cipher, "bf-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAST - { FT_cipher, "cast5-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAST - { FT_cipher, "cast5-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAST - { FT_cipher, "cast5-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAST - { FT_cipher, "cast5-ofb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_CAST - { FT_cipher, "cast-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC5 - { FT_cipher, "rc5-cbc", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC5 - { FT_cipher, "rc5-ecb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC5 - { FT_cipher, "rc5-cfb", enc_main, enc_options }, -#endif -#ifndef OPENSSL_NO_RC5 - { FT_cipher, "rc5-ofb", enc_main, enc_options }, -#endif - { 0, NULL, NULL} -}; -#endif diff --git a/apps/progs.pl b/apps/progs.pl index 21baf173..0d3b4469 100644 --- a/apps/progs.pl +++ b/apps/progs.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the OpenSSL license (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -11,13 +11,22 @@ use strict; use warnings; -use configdata qw/@disablables/; +use lib '.'; +use configdata qw/@disablables %unified_info/; my %commands = (); my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/; -foreach my $filename (@ARGV) { - open F, $filename or die "Coudn't open $_: $!\n"; +my $apps_openssl = shift @ARGV; +# because the program apps/openssl has object files as sources, and +# they then have the corresponding C files as source, we need to chain +# the lookups in %unified_info +my @openssl_source = + map { @{$unified_info{sources}->{$_}} } + @{$unified_info{sources}->{$apps_openssl}}; + +foreach my $filename (@openssl_source) { + open F, $filename or die "Couldn't open $filename: $!\n"; foreach (grep /$cmdre/, ) { my @foo = /$cmdre/; $commands{$1} = 1; @@ -32,7 +41,7 @@ print <<'EOF'; * WARNING: do not edit! * Generated by apps/progs.pl * - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy diff --git a/apps/rand.c b/apps/rand.c index e7261802..b3ec70a7 100644 --- a/apps/rand.c +++ b/apps/rand.c @@ -1,5 +1,5 @@ /* - * Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -76,9 +76,13 @@ int rand_main(int argc, char **argv) } argc = opt_num_rest(); argv = opt_rest(); - - if (argc != 1 || !opt_int(argv[0], &num) || num < 0) + if (argc == 1) { + if (!opt_int(argv[0], &num) || num <= 0) + goto end; + } else if (argc > 0) { + BIO_printf(bio_err, "Extra arguments given.\n"); goto opthelp; + } app_RAND_load_file(NULL, (inrand != NULL)); if (inrand != NULL) @@ -102,7 +106,7 @@ int rand_main(int argc, char **argv) chunk = num; if (chunk > (int)sizeof(buf)) - chunk = sizeof buf; + chunk = sizeof(buf); r = RAND_bytes(buf, chunk); if (r <= 0) goto end; diff --git a/apps/rehash.c b/apps/rehash.c index 2b517be9..273ad749 100644 --- a/apps/rehash.c +++ b/apps/rehash.c @@ -305,7 +305,7 @@ static int massage_filename(char *name) if (q != NULL) { for (q++; *q != '\0'; q++) { - if (!isdigit(*q)) + if (!isdigit((unsigned char)*q)) return 1; } } diff --git a/apps/req.c b/apps/req.c index a749925b..2a215695 100644 --- a/apps/req.c +++ b/apps/req.c @@ -973,7 +973,7 @@ static int prompt_info(X509_REQ *req, /* If OBJ not recognised ignore it */ if ((nid = OBJ_txt2nid(type)) == NID_undef) goto start; - if (BIO_snprintf(buf, sizeof buf, "%s_default", v->name) + if (BIO_snprintf(buf, sizeof(buf), "%s_default", v->name) >= (int)sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long\n", v->name); return 0; @@ -984,19 +984,19 @@ static int prompt_info(X509_REQ *req, def = ""; } - BIO_snprintf(buf, sizeof buf, "%s_value", v->name); + BIO_snprintf(buf, sizeof(buf), "%s_value", v->name); if ((value = NCONF_get_string(req_conf, dn_sect, buf)) == NULL) { ERR_clear_error(); value = NULL; } - BIO_snprintf(buf, sizeof buf, "%s_min", v->name); + BIO_snprintf(buf, sizeof(buf), "%s_min", v->name); if (!NCONF_get_number(req_conf, dn_sect, buf, &n_min)) { ERR_clear_error(); n_min = -1; } - BIO_snprintf(buf, sizeof buf, "%s_max", v->name); + BIO_snprintf(buf, sizeof(buf), "%s_max", v->name); if (!NCONF_get_number(req_conf, dn_sect, buf, &n_max)) { ERR_clear_error(); n_max = -1; @@ -1032,7 +1032,7 @@ static int prompt_info(X509_REQ *req, if ((nid = OBJ_txt2nid(type)) == NID_undef) goto start2; - if (BIO_snprintf(buf, sizeof buf, "%s_default", type) + if (BIO_snprintf(buf, sizeof(buf), "%s_default", type) >= (int)sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long\n", v->name); return 0; @@ -1044,20 +1044,20 @@ static int prompt_info(X509_REQ *req, def = ""; } - BIO_snprintf(buf, sizeof buf, "%s_value", type); + BIO_snprintf(buf, sizeof(buf), "%s_value", type); if ((value = NCONF_get_string(req_conf, attr_sect, buf)) == NULL) { ERR_clear_error(); value = NULL; } - BIO_snprintf(buf, sizeof buf, "%s_min", type); + BIO_snprintf(buf, sizeof(buf), "%s_min", type); if (!NCONF_get_number(req_conf, attr_sect, buf, &n_min)) { ERR_clear_error(); n_min = -1; } - BIO_snprintf(buf, sizeof buf, "%s_max", type); + BIO_snprintf(buf, sizeof(buf), "%s_max", type); if (!NCONF_get_number(req_conf, attr_sect, buf, &n_max)) { ERR_clear_error(); n_max = -1; @@ -1155,13 +1155,13 @@ static int add_DN_object(X509_NAME *n, char *text, const char *def, BIO_printf(bio_err, "%s [%s]:", text, def); (void)BIO_flush(bio_err); if (value != NULL) { - OPENSSL_strlcpy(buf, value, sizeof buf); - OPENSSL_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, value, sizeof(buf)); + OPENSSL_strlcat(buf, "\n", sizeof(buf)); BIO_printf(bio_err, "%s\n", value); } else { buf[0] = '\0'; if (!batch) { - if (!fgets(buf, sizeof buf, stdin)) + if (!fgets(buf, sizeof(buf), stdin)) return 0; } else { buf[0] = '\n'; @@ -1174,8 +1174,8 @@ static int add_DN_object(X509_NAME *n, char *text, const char *def, else if (buf[0] == '\n') { if ((def == NULL) || (def[0] == '\0')) return (1); - OPENSSL_strlcpy(buf, def, sizeof buf); - OPENSSL_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, def, sizeof(buf)); + OPENSSL_strlcat(buf, "\n", sizeof(buf)); } else if ((buf[0] == '.') && (buf[1] == '\n')) return (1); @@ -1214,13 +1214,13 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def, BIO_printf(bio_err, "%s [%s]:", text, def); (void)BIO_flush(bio_err); if (value != NULL) { - OPENSSL_strlcpy(buf, value, sizeof buf); - OPENSSL_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, value, sizeof(buf)); + OPENSSL_strlcat(buf, "\n", sizeof(buf)); BIO_printf(bio_err, "%s\n", value); } else { buf[0] = '\0'; if (!batch) { - if (!fgets(buf, sizeof buf, stdin)) + if (!fgets(buf, sizeof(buf), stdin)) return 0; } else { buf[0] = '\n'; @@ -1233,8 +1233,8 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def, else if (buf[0] == '\n') { if ((def == NULL) || (def[0] == '\0')) return (1); - OPENSSL_strlcpy(buf, def, sizeof buf); - OPENSSL_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, def, sizeof(buf)); + OPENSSL_strlcat(buf, "\n", sizeof(buf)); } else if ((buf[0] == '.') && (buf[1] == '\n')) return (1); diff --git a/apps/rsa.c b/apps/rsa.c index 35ab7271..8b15fcba 100644 --- a/apps/rsa.c +++ b/apps/rsa.c @@ -215,7 +215,7 @@ int rsa_main(int argc, char **argv) } if (check) { - int r = RSA_check_key(rsa); + int r = RSA_check_key_ex(rsa, NULL); if (r == 1) BIO_printf(out, "RSA key ok\n"); @@ -224,7 +224,7 @@ int rsa_main(int argc, char **argv) while ((err = ERR_peek_error()) != 0 && ERR_GET_LIB(err) == ERR_LIB_RSA && - ERR_GET_FUNC(err) == RSA_F_RSA_CHECK_KEY && + ERR_GET_FUNC(err) == RSA_F_RSA_CHECK_KEY_EX && ERR_GET_REASON(err) != ERR_R_MALLOC_FAILURE) { BIO_printf(out, "RSA key error: %s\n", ERR_reason_error_string(err)); diff --git a/apps/s_client.c b/apps/s_client.c index ce1a408d..fb89f0cd 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -1370,11 +1370,13 @@ int s_client_main(int argc, char **argv) } } +#ifdef AF_UNIX if (socket_family == AF_UNIX && socket_type != SOCK_STREAM) { BIO_printf(bio_err, "Can't use unix sockets and datagrams together\n"); goto end; } +#endif if (split_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) { BIO_printf(bio_err, "Bad split send fragment size\n"); @@ -1484,6 +1486,9 @@ int s_client_main(int argc, char **argv) if (sdebug) ssl_ctx_security_debug(ctx, sdebug); + if (!config_ctx(cctx, ssl_args, ctx)) + goto end; + if (ssl_config) { if (SSL_CTX_config(ctx, ssl_config) == 0) { BIO_printf(bio_err, "Error using configuration \"%s\"\n", @@ -1493,9 +1498,11 @@ int s_client_main(int argc, char **argv) } } - if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0) + if (min_version != 0 + && SSL_CTX_set_min_proto_version(ctx, min_version) == 0) goto end; - if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0) + if (max_version != 0 + && SSL_CTX_set_max_proto_version(ctx, max_version) == 0) goto end; if (vpmtouched && !SSL_CTX_set1_param(ctx, vpm)) { @@ -1518,9 +1525,6 @@ int s_client_main(int argc, char **argv) SSL_CTX_set_default_read_buffer_len(ctx, read_buf_len); } - if (!config_ctx(cctx, ssl_args, ctx)) - goto end; - if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile, crls, crl_download)) { BIO_printf(bio_err, "Error loading store locations\n"); @@ -2459,7 +2463,7 @@ int s_client_main(int argc, char **argv) if (in_init) print_stuff(bio_c_out, con, full_log); do_ssl_shutdown(con); -#if defined(OPENSSL_SYS_WINDOWS) + /* * Give the socket time to send its last data before we close it. * No amount of setting SO_LINGER etc on the socket seems to persuade @@ -2467,8 +2471,23 @@ int s_client_main(int argc, char **argv) * for a short time seems to do it (units in ms) * TODO: Find a better way to do this */ +#if defined(OPENSSL_SYS_WINDOWS) Sleep(50); +#elif defined(OPENSSL_SYS_CYGWIN) + usleep(50000); #endif + + /* + * If we ended with an alert being sent, but still with data in the + * network buffer to be read, then calling BIO_closesocket() will + * result in a TCP-RST being sent. On some platforms (notably + * Windows) then this will result in the peer immediately abandoning + * the connection including any buffered alert data before it has + * had a chance to be read. Shutting down the sending side first, + * and then closing the socket sends TCP-FIN first followed by + * TCP-RST. This seems to allow the peer to read the alert data. + */ + shutdown(SSL_get_fd(con), 1); /* SHUT_WR */ BIO_closesocket(SSL_get_fd(con)); end: if (con != NULL) { @@ -2534,10 +2553,10 @@ static void print_stuff(BIO *bio, SSL *s, int full) BIO_printf(bio, "---\nCertificate chain\n"); for (i = 0; i < sk_X509_num(sk); i++) { X509_NAME_oneline(X509_get_subject_name(sk_X509_value(sk, i)), - buf, sizeof buf); + buf, sizeof(buf)); BIO_printf(bio, "%2d s:%s\n", i, buf); X509_NAME_oneline(X509_get_issuer_name(sk_X509_value(sk, i)), - buf, sizeof buf); + buf, sizeof(buf)); BIO_printf(bio, " i:%s\n", buf); if (c_showcerts) PEM_write_bio_X509(bio, sk_X509_value(sk, i)); @@ -2552,9 +2571,9 @@ static void print_stuff(BIO *bio, SSL *s, int full) /* Redundant if we showed the whole chain */ if (!(c_showcerts && got_a_chain)) PEM_write_bio_X509(bio, peer); - X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf); + X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof(buf)); BIO_printf(bio, "subject=%s\n", buf); - X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf); + X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof(buf)); BIO_printf(bio, "issuer=%s\n", buf); } else BIO_printf(bio, "no peer certificate available\n"); diff --git a/apps/s_server.c b/apps/s_server.c index 7e18aaf0..31c90fdd 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -704,13 +704,14 @@ OPTIONS s_server_options[] = { "PEM serverinfo file for certificate"}, {"certform", OPT_CERTFORM, 'F', "Certificate format (PEM or DER) PEM default"}, - {"key", OPT_KEY, '<', + {"key", OPT_KEY, 's', "Private Key if not in -cert; default is " TEST_CERT}, {"keyform", OPT_KEYFORM, 'f', "Key format (PEM, DER or ENGINE) PEM default"}, {"pass", OPT_PASS, 's', "Private key file pass phrase source"}, {"dcert", OPT_DCERT, '<', "Second certificate file to use (usually for DSA)"}, + {"dhparam", OPT_DHPARAM, '<', "DH parameters file to use"}, {"dcertform", OPT_DCERTFORM, 'F', "Second certificate format (PEM or DER) PEM default"}, {"dkey", OPT_DKEY, '<', @@ -1614,6 +1615,10 @@ int s_server_main(int argc, char *argv[]) } if (sdebug) ssl_ctx_security_debug(ctx, sdebug); + + if (!config_ctx(cctx, ssl_args, ctx)) + goto end; + if (ssl_config) { if (SSL_CTX_config(ctx, ssl_config) == 0) { BIO_printf(bio_err, "Error using configuration \"%s\"\n", @@ -1622,9 +1627,11 @@ int s_server_main(int argc, char *argv[]) goto end; } } - if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0) + if (min_version != 0 + && SSL_CTX_set_min_proto_version(ctx, min_version) == 0) goto end; - if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0) + if (max_version != 0 + && SSL_CTX_set_max_proto_version(ctx, max_version) == 0) goto end; if (session_id_prefix) { @@ -1686,8 +1693,6 @@ int s_server_main(int argc, char *argv[]) } ssl_ctx_add_crls(ctx, crls, 0); - if (!config_ctx(cctx, ssl_args, ctx)) - goto end; if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile, crls, crl_download)) { @@ -1852,7 +1857,7 @@ int s_server_main(int argc, char *argv[]) SSL_CTX_set_verify(ctx, s_server_verify, verify_callback); if (!SSL_CTX_set_session_id_context(ctx, (void *)&s_server_session_id_context, - sizeof s_server_session_id_context)) { + sizeof(s_server_session_id_context))) { BIO_printf(bio_err, "error setting session id context\n"); ERR_print_errors(bio_err); goto end; @@ -1866,7 +1871,7 @@ int s_server_main(int argc, char *argv[]) SSL_CTX_set_verify(ctx2, s_server_verify, verify_callback); if (!SSL_CTX_set_session_id_context(ctx2, (void *)&s_server_session_id_context, - sizeof s_server_session_id_context)) { + sizeof(s_server_session_id_context))) { BIO_printf(bio_err, "error setting session id context\n"); ERR_print_errors(bio_err); goto end; @@ -2534,15 +2539,15 @@ static int init_ssl_connection(SSL *con) if (peer != NULL) { BIO_printf(bio_s_out, "Client certificate\n"); PEM_write_bio_X509(bio_s_out, peer); - X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf); + X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof(buf)); BIO_printf(bio_s_out, "subject=%s\n", buf); - X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf); + X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof(buf)); BIO_printf(bio_s_out, "issuer=%s\n", buf); X509_free(peer); peer = NULL; } - if (SSL_get_shared_ciphers(con, buf, sizeof buf) != NULL) + if (SSL_get_shared_ciphers(con, buf, sizeof(buf)) != NULL) BIO_printf(bio_s_out, "Shared ciphers:%s\n", buf); str = SSL_CIPHER_get_name(SSL_get_current_cipher(con)); ssl_print_sigalgs(bio_s_out, con); @@ -2574,6 +2579,9 @@ static int init_ssl_connection(SSL *con) BIO_printf(bio_s_out, "Reused session-id\n"); BIO_printf(bio_s_out, "Secure Renegotiation IS%s supported\n", SSL_get_secure_renegotiation_support(con) ? "" : " NOT"); + if ((SSL_get_options(con) & SSL_OP_NO_RENEGOTIATION)) + BIO_printf(bio_s_out, "Renegotiation is DISABLED\n"); + if (keymatexportlabel != NULL) { BIO_printf(bio_s_out, "Keying material exporter:\n"); BIO_printf(bio_s_out, " Label: '%s'\n", keymatexportlabel); @@ -2853,9 +2861,10 @@ static int www_body(int s, int stype, unsigned char *context) PEM_write_bio_X509(io, peer); X509_free(peer); peer = NULL; - } else + } else { BIO_puts(io, "no client certificate available\n"); - BIO_puts(io, "\r\n\r\n"); + } + BIO_puts(io, "\r\n\r\n"); break; } else if ((www == 2 || www == 3) && (strncmp("GET /", buf, 5) == 0)) { diff --git a/apps/s_socket.c b/apps/s_socket.c index 0cbe8851..458aa862 100644 --- a/apps/s_socket.c +++ b/apps/s_socket.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -136,6 +136,10 @@ int do_server(int *accept_sock, const char *host, const char *port, int sock; int i; BIO_ADDRINFO *res = NULL; + const BIO_ADDRINFO *next; + int sock_family, sock_type, sock_protocol; + const BIO_ADDR *sock_address; + int sock_options = BIO_SOCK_REUSEADDR; int ret = 0; if (!BIO_sock_init()) @@ -151,10 +155,29 @@ int do_server(int *accept_sock, const char *host, const char *port, OPENSSL_assert((family == AF_UNSPEC || family == BIO_ADDRINFO_family(res)) && (type == 0 || type == BIO_ADDRINFO_socktype(res))); - asock = BIO_socket(BIO_ADDRINFO_family(res), BIO_ADDRINFO_socktype(res), - BIO_ADDRINFO_protocol(res), 0); + sock_family = BIO_ADDRINFO_family(res); + sock_type = BIO_ADDRINFO_socktype(res); + sock_protocol = BIO_ADDRINFO_protocol(res); + sock_address = BIO_ADDRINFO_address(res); + next = BIO_ADDRINFO_next(res); + if (sock_family == AF_INET6) + sock_options |= BIO_SOCK_V6_ONLY; + if (next != NULL + && BIO_ADDRINFO_socktype(next) == sock_type + && BIO_ADDRINFO_protocol(next) == sock_protocol) { + if (sock_family == AF_INET + && BIO_ADDRINFO_family(next) == AF_INET6) { + sock_family = AF_INET6; + sock_address = BIO_ADDRINFO_address(next); + } else if (sock_family == AF_INET6 + && BIO_ADDRINFO_family(next) == AF_INET) { + sock_options &= ~BIO_SOCK_V6_ONLY; + } + } + + asock = BIO_socket(sock_family, sock_type, sock_protocol, 0); if (asock == INVALID_SOCKET - || !BIO_listen(asock, BIO_ADDRINFO_address(res), BIO_SOCK_REUSEADDR)) { + || !BIO_listen(asock, sock_address, sock_options)) { BIO_ADDRINFO_free(res); ERR_print_errors(bio_err); if (asock != INVALID_SOCKET) @@ -171,13 +194,38 @@ int do_server(int *accept_sock, const char *host, const char *port, if (type == SOCK_STREAM) { do { sock = BIO_accept_ex(asock, NULL, 0); - } while (sock < 0 && BIO_sock_should_retry(ret)); + } while (sock < 0 && BIO_sock_should_retry(sock)); if (sock < 0) { ERR_print_errors(bio_err); BIO_closesocket(asock); break; } i = (*cb)(sock, type, context); + + /* + * Give the socket time to send its last data before we close it. + * No amount of setting SO_LINGER etc on the socket seems to + * persuade Windows to send the data before closing the socket... + * but sleeping for a short time seems to do it (units in ms) + * TODO: Find a better way to do this + */ +#if defined(OPENSSL_SYS_WINDOWS) + Sleep(50); +#elif defined(OPENSSL_SYS_CYGWIN) + usleep(50000); +#endif + + /* + * If we ended with an alert being sent, but still with data in the + * network buffer to be read, then calling BIO_closesocket() will + * result in a TCP-RST being sent. On some platforms (notably + * Windows) then this will result in the peer immediately abandoning + * the connection including any buffered alert data before it has + * had a chance to be read. Shutting down the sending side first, + * and then closing the socket sends TCP-FIN first followed by + * TCP-RST. This seems to allow the peer to read the alert data. + */ + shutdown(sock, 1); /* SHUT_WR */ BIO_closesocket(sock); } else { i = (*cb)(asock, type, context); diff --git a/apps/s_time.c b/apps/s_time.c index 263502c7..dc0ec4af 100644 --- a/apps/s_time.c +++ b/apps/s_time.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,8 +7,6 @@ * https://www.openssl.org/source/license.html */ -#define NO_SHUTDOWN - #include #include #include @@ -28,22 +26,8 @@ # include OPENSSL_UNISTD #endif -#undef ioctl -#define ioctl ioctlsocket - #define SSL_CONNECT_NAME "localhost:4433" -/* no default cert. */ -/* - * #define TEST_CERT "client.pem" - */ - -#undef min -#undef max -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#define max(a,b) (((a) > (b)) ? (a) : (b)) - -#undef SECONDS #define SECONDS 30 #define SECONDSSTR "30" @@ -185,21 +169,20 @@ int s_time_main(int argc, char **argv) if (cipher == NULL) cipher = getenv("SSL_CIPHER"); - if (cipher == NULL) { + if (cipher == NULL) BIO_printf(bio_err, "No CIPHER specified\n"); - goto end; - } if ((ctx = SSL_CTX_new(meth)) == NULL) goto end; + SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); SSL_CTX_set_quiet_shutdown(ctx, 1); if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0) goto end; if (st_bugs) SSL_CTX_set_options(ctx, SSL_OP_ALL); - if (!SSL_CTX_set_cipher_list(ctx, cipher)) + if (cipher != NULL && !SSL_CTX_set_cipher_list(ctx, cipher)) goto end; if (!set_cert_stuff(ctx, certfile, keyfile)) goto end; @@ -225,18 +208,14 @@ int s_time_main(int argc, char **argv) goto end; if (www_path != NULL) { - buf_len = BIO_snprintf(buf, sizeof buf, + buf_len = BIO_snprintf(buf, sizeof(buf), fmt_http_get_cmd, www_path); if (SSL_write(scon, buf, buf_len) <= 0) goto end; while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) bytes_read += i; } -#ifdef NO_SHUTDOWN SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); -#else - SSL_shutdown(scon); -#endif BIO_closesocket(SSL_get_fd(scon)); nConn += 1; @@ -283,18 +262,14 @@ int s_time_main(int argc, char **argv) } if (www_path != NULL) { - buf_len = BIO_snprintf(buf, sizeof buf, + buf_len = BIO_snprintf(buf, sizeof(buf), fmt_http_get_cmd, www_path); if (SSL_write(scon, buf, buf_len) <= 0) goto end; - while (SSL_read(scon, buf, sizeof(buf)) > 0) + while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) continue; } -#ifdef NO_SHUTDOWN SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); -#else - SSL_shutdown(scon); -#endif BIO_closesocket(SSL_get_fd(scon)); nConn = 0; @@ -314,18 +289,14 @@ int s_time_main(int argc, char **argv) goto end; if (www_path) { - BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n", + BIO_snprintf(buf, sizeof(buf), "GET %s HTTP/1.0\r\n\r\n", www_path); if (SSL_write(scon, buf, strlen(buf)) <= 0) goto end; while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) bytes_read += i; } -#ifdef NO_SHUTDOWN SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); -#else - SSL_shutdown(scon); -#endif BIO_closesocket(SSL_get_fd(scon)); nConn += 1; @@ -367,13 +338,13 @@ static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx) { BIO *conn; SSL *serverCon; - int width, i; - fd_set readfds; + int i; if ((conn = BIO_new(BIO_s_connect())) == NULL) - return (NULL); + return NULL; BIO_set_conn_hostname(conn, host); + BIO_set_conn_mode(conn, BIO_SOCK_NODELAY); if (scon == NULL) serverCon = SSL_new(ctx); @@ -385,26 +356,7 @@ static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx) SSL_set_bio(serverCon, conn, conn); /* ok, lets connect */ - for (;;) { - i = SSL_connect(serverCon); - if (BIO_sock_should_retry(i)) { - BIO_printf(bio_err, "DELAY\n"); - - i = SSL_get_fd(serverCon); - width = i + 1; - FD_ZERO(&readfds); - openssl_fdset(i, &readfds); - /* - * Note: under VMS with SOCKETSHR the 2nd parameter is currently - * of type (int *) whereas under other systems it is (void *) if - * you don't have a cast it will choke the compiler: if you do - * have a cast then you can either go for (int *) or (void *). - */ - select(width, (void *)&readfds, NULL, NULL, NULL); - continue; - } - break; - } + i = SSL_connect(serverCon); if (i <= 0) { BIO_printf(bio_err, "ERROR\n"); if (verify_args.error != X509_V_OK) @@ -417,6 +369,17 @@ static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx) return NULL; } +#if defined(SOL_SOCKET) && defined(SO_LINGER) + { + struct linger no_linger; + + no_linger.l_onoff = 1; + no_linger.l_linger = 0; + (void) setsockopt(SSL_get_fd(serverCon), SOL_SOCKET, SO_LINGER, + (char*)&no_linger, sizeof(no_linger)); + } +#endif + return serverCon; } #endif /* OPENSSL_NO_SOCK */ diff --git a/apps/speed.c b/apps/speed.c index ad2daab1..b0a7b6ec 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -293,7 +293,8 @@ static SIGRETTYPE sig_done(int sig) # if !defined(SIGALRM) # define SIGALRM # endif -static unsigned int lapse, schlock; +static unsigned int lapse; +static volatile unsigned int schlock; static void alarm_win32(unsigned int secs) { lapse = secs * 1000; @@ -1240,6 +1241,7 @@ int speed_main(int argc, char **argv) || !defined(OPENSSL_NO_EC) long rsa_count = 1; #endif + size_t loop; /* What follows are the buffers and key material. */ #ifndef OPENSSL_NO_RC5 @@ -1378,6 +1380,7 @@ int speed_main(int argc, char **argv) usertime = 0; break; case OPT_EVP: + evp_md = NULL; evp_cipher = EVP_get_cipherbyname(opt_arg()); if (evp_cipher == NULL) evp_md = EVP_get_digestbyname(opt_arg()); @@ -1465,12 +1468,8 @@ int speed_main(int argc, char **argv) continue; } #ifndef OPENSSL_NO_RSA -# ifndef RSA_NULL - if (strcmp(*argv, "openssl") == 0) { - RSA_set_default_method(RSA_PKCS1_OpenSSL()); + if (strcmp(*argv, "openssl") == 0) continue; - } -# endif if (strcmp(*argv, "rsa") == 0) { rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] = rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] = @@ -1508,8 +1507,8 @@ int speed_main(int argc, char **argv) #endif #ifndef OPENSSL_NO_EC if (strcmp(*argv, "ecdsa") == 0) { - for (i = 0; i < EC_NUM; i++) - ecdsa_doit[i] = 1; + for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++) + ecdsa_doit[ecdsa_choices[loop].retval] = 1; continue; } if (found(*argv, ecdsa_choices, &i)) { @@ -1517,8 +1516,8 @@ int speed_main(int argc, char **argv) continue; } if (strcmp(*argv, "ecdh") == 0) { - for (i = 0; i < EC_NUM; i++) - ecdh_doit[i] = 1; + for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++) + ecdh_doit[ecdh_choices[loop].retval] = 1; continue; } if (found(*argv, ecdh_choices, &i)) { @@ -1585,10 +1584,10 @@ int speed_main(int argc, char **argv) dsa_doit[i] = 1; #endif #ifndef OPENSSL_NO_EC - for (i = 0; i < EC_NUM; i++) - ecdsa_doit[i] = 1; - for (i = 0; i < EC_NUM; i++) - ecdh_doit[i] = 1; + for (loop = 0; loop < OSSL_NELEM(ecdsa_choices); loop++) + ecdsa_doit[ecdsa_choices[loop].retval] = 1; + for (loop = 0; loop < OSSL_NELEM(ecdh_choices); loop++) + ecdh_doit[ecdh_choices[loop].retval] = 1; #endif } for (i = 0; i < ALGOR_NUM; i++) @@ -2403,7 +2402,7 @@ int speed_main(int argc, char **argv) #ifndef OPENSSL_NO_DSA if (RAND_status() != 1) { - RAND_seed(rnd_seed, sizeof rnd_seed); + RAND_seed(rnd_seed, sizeof(rnd_seed)); } for (testnum = 0; testnum < DSA_NUM; testnum++) { int st = 0; @@ -2471,7 +2470,7 @@ int speed_main(int argc, char **argv) #ifndef OPENSSL_NO_EC if (RAND_status() != 1) { - RAND_seed(rnd_seed, sizeof rnd_seed); + RAND_seed(rnd_seed, sizeof(rnd_seed)); } for (testnum = 0; testnum < EC_NUM; testnum++) { int st = 1; @@ -2555,7 +2554,7 @@ int speed_main(int argc, char **argv) } if (RAND_status() != 1) { - RAND_seed(rnd_seed, sizeof rnd_seed); + RAND_seed(rnd_seed, sizeof(rnd_seed)); } for (testnum = 0; testnum < EC_NUM; testnum++) { int ecdh_checks = 1; @@ -2878,7 +2877,7 @@ static char *sstrsep(char **string, const char *delim) if (**string == 0) return NULL; - memset(isdelim, 0, sizeof isdelim); + memset(isdelim, 0, sizeof(isdelim)); isdelim[0] = 1; while (*delim) { @@ -2939,7 +2938,7 @@ static int do_multi(int multi) char *p; f = fdopen(fds[n], "r"); - while (fgets(buf, sizeof buf, f)) { + while (fgets(buf, sizeof(buf), f)) { p = strchr(buf, '\n'); if (p) *p = '\0'; diff --git a/apps/spkac.c b/apps/spkac.c index 90a5beab..34490679 100644 --- a/apps/spkac.c +++ b/apps/spkac.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -116,19 +116,22 @@ int spkac_main(int argc, char **argv) goto end; } - if (keyfile) { + if (keyfile != NULL) { pkey = load_key(strcmp(keyfile, "-") ? keyfile : NULL, FORMAT_PEM, 1, passin, e, "private key"); - if (!pkey) { + if (pkey == NULL) goto end; - } spki = NETSCAPE_SPKI_new(); - if (challenge) + if (spki == NULL) + goto end; + if (challenge != NULL) ASN1_STRING_set(spki->spkac->challenge, challenge, (int)strlen(challenge)); NETSCAPE_SPKI_set_pubkey(spki, pkey); NETSCAPE_SPKI_sign(spki, pkey, EVP_md5()); spkstr = NETSCAPE_SPKI_b64_encode(spki); + if (spkstr == NULL) + goto end; out = bio_open_default(outfile, 'w', FORMAT_TEXT); if (out == NULL) { @@ -154,7 +157,7 @@ int spkac_main(int argc, char **argv) spki = NETSCAPE_SPKI_b64_decode(spkstr, -1); - if (!spki) { + if (spki == NULL) { BIO_printf(bio_err, "Error loading SPKAC\n"); ERR_print_errors(bio_err); goto end; @@ -169,9 +172,9 @@ int spkac_main(int argc, char **argv) pkey = NETSCAPE_SPKI_get_pubkey(spki); if (verify) { i = NETSCAPE_SPKI_verify(spki, pkey); - if (i > 0) + if (i > 0) { BIO_printf(bio_err, "Signature OK\n"); - else { + } else { BIO_printf(bio_err, "Signature Failure\n"); ERR_print_errors(bio_err); goto end; diff --git a/apps/srp.c b/apps/srp.c index ec35c551..0ead68e8 100644 --- a/apps/srp.c +++ b/apps/srp.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -293,11 +293,12 @@ int srp_main(int argc, char **argv) "Exactly one of the options -add, -delete, -modify -list must be specified.\n"); goto opthelp; } - if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) - && argc < 1) { - BIO_printf(bio_err, - "Need at least one user for options -add, -delete, -modify. \n"); - goto opthelp; + if (mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) { + if (argc == 0) { + BIO_printf(bio_err, "Need at least one user.\n"); + goto opthelp; + } + user = *argv++; } if ((passinarg || passoutarg) && argc != 1) { BIO_printf(bio_err, @@ -391,10 +392,7 @@ int srp_main(int argc, char **argv) if (verbose > 1) BIO_printf(bio_err, "Starting user processing\n"); - if (argc > 0) - user = *(argv++); - - while (mode == OPT_LIST || user) { + while (mode == OPT_LIST || user != NULL) { int userindex = -1; if (user != NULL && verbose > 1) @@ -557,9 +555,8 @@ int srp_main(int argc, char **argv) doupdatedb = 1; } } - if (--argc > 0) { - user = *(argv++); - } else { + user = *argv++; + if (user == NULL) { /* no more processing in any mode if no users left */ break; } diff --git a/apps/tsget.in b/apps/tsget.in index 89d1bc7e..c6193e57 100644 --- a/apps/tsget.in +++ b/apps/tsget.in @@ -198,4 +198,3 @@ REQUEST: foreach (@ARGV) { STDERR->printflush(", $output written.\n") if $options{v}; } $curl->cleanup(); -WWW::Curl::Easy::global_cleanup(); diff --git a/apps/verify.c b/apps/verify.c index 3c456639..0925ee62 100644 --- a/apps/verify.c +++ b/apps/verify.c @@ -282,6 +282,7 @@ static int cb(int ok, X509_STORE_CTX *ctx) switch (cert_error) { case X509_V_ERR_NO_EXPLICIT_POLICY: policies_print(ctx); + /* fall thru */ case X509_V_ERR_CERT_HAS_EXPIRED: /* diff --git a/apps/version.c b/apps/version.c index e3c8299f..2f8be364 100644 --- a/apps/version.c +++ b/apps/version.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -61,6 +61,7 @@ int version_main(int argc, char **argv) switch (o) { case OPT_EOF: case OPT_ERR: +opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: @@ -89,10 +90,14 @@ int version_main(int argc, char **argv) dirty = version = 1; break; case OPT_A: - cflags = version = date = platform = dir = engdir = 1; + options = cflags = version = date = platform = dir = engdir = 1; break; } } + if (opt_num_rest() != 0) { + BIO_printf(bio_err, "Extra parameters given.\n"); + goto opthelp; + } if (!dirty) version = 1; diff --git a/apps/vms_term_sock.c b/apps/vms_term_sock.c index a7d87ff3..bc0c173e 100644 --- a/apps/vms_term_sock.c +++ b/apps/vms_term_sock.c @@ -143,7 +143,7 @@ int main (int argc, char *argv[], char *envp[]) ** Process the terminal input */ LogMessage ("Waiting on terminal I/O ...\n"); - len = recv (TermSock, TermBuff, sizeof (TermBuff), 0) ; + len = recv (TermSock, TermBuff, sizeof(TermBuff), 0) ; TermBuff[len] = '\0'; LogMessage ("Received terminal I/O [%s]", TermBuff); @@ -209,7 +209,7 @@ int TerminalSocket (int FunctionCode, int *ReturnSocket) TerminalDeviceAst, 0, TerminalDeviceBuff, - sizeof (TerminalDeviceBuff) - 2, + sizeof(TerminalDeviceBuff) - 2, 0, 0, 0, 0); if (! (status & 1)) { LogMessage ("TerminalSocket: SYS$QIO () - %08X", status); @@ -317,7 +317,7 @@ static int CreateSocketPair (int SocketFamily, /* ** Initialize the socket information */ - slen = sizeof (sin); + slen = sizeof(sin); memset ((char *) &sin, 0, slen); sin.sin_family = SocketFamily; sin.sin_addr.s_addr = inet_addr (LocalHostAddr); @@ -434,12 +434,12 @@ static int CreateSocketPair (int SocketFamily, /* ** Now issue the connect */ - memset ((char *) &sin, 0, sizeof (sin)) ; + memset ((char *) &sin, 0, sizeof(sin)) ; sin.sin_family = SocketFamily; sin.sin_addr.s_addr = inet_addr (LocalHostAddr) ; sin.sin_port = LocalHostPort ; - status = connect (SockDesc2, (struct sockaddr *) &sin, sizeof (sin)); + status = connect (SockDesc2, (struct sockaddr *) &sin, sizeof(sin)); if (status < 0 ) { LogMessage ("CreateSocketPair: connect () - %d", errno); sys$cantim (&sptb, 0); @@ -528,7 +528,7 @@ static int TerminalDeviceAst (int astparm) TerminalDeviceAst, 0, TerminalDeviceBuff, - sizeof (TerminalDeviceBuff) - 1, + sizeof(TerminalDeviceBuff) - 1, 0, 0, 0, 0); /* diff --git a/apps/x509.c b/apps/x509.c index 577c35dd..7a66ea66 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -123,7 +123,7 @@ OPTIONS x509_options[] = { {"checkemail", OPT_CHECKEMAIL, 's', "Check certificate matches email"}, {"checkip", OPT_CHECKIP, 's', "Check certificate matches ipaddr"}, {"CAform", OPT_CAFORM, 'F', "CA format - default PEM"}, - {"CAkeyform", OPT_CAKEYFORM, 'F', "CA key format - default PEM"}, + {"CAkeyform", OPT_CAKEYFORM, 'f', "CA key format - default PEM"}, {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"}, {"force_pubkey", OPT_FORCE_PUBKEY, '<', "Force the Key to put inside certificate"}, {"next_serial", OPT_NEXT_SERIAL, '-', "Increment current certificate serial number"}, @@ -450,10 +450,6 @@ int x509_main(int argc, char **argv) if (!nmflag_set) nmflag = XN_FLAG_ONELINE; - out = bio_open_default(outfile, 'w', outformat); - if (out == NULL) - goto end; - if (need_rand) app_RAND_load_file(NULL, 0); @@ -579,10 +575,12 @@ int x509_main(int argc, char **argv) goto end; } - if (!noout || text || next_serial) { - OBJ_create("2.99999.3", "SET.ex3", "SET x509v3 extension 3"); + out = bio_open_default(outfile, 'w', outformat); + if (out == NULL) + goto end; - } + if (!noout || text || next_serial) + OBJ_create("2.99999.3", "SET.ex3", "SET x509v3 extension 3"); if (alias) X509_alias_set1(x, (unsigned char *)alias, -1); @@ -726,11 +724,11 @@ int x509_main(int argc, char **argv) char *m; int len; - X509_NAME_oneline(X509_get_subject_name(x), buf, sizeof buf); + X509_NAME_oneline(X509_get_subject_name(x), buf, sizeof(buf)); BIO_printf(out, "/*\n" " * Subject: %s\n", buf); - X509_NAME_oneline(X509_get_issuer_name(x), buf, sizeof buf); + X509_NAME_oneline(X509_get_issuer_name(x), buf, sizeof(buf)); BIO_printf(out, " * Issuer: %s\n" " */\n", buf); diff --git a/config.com b/config.com index 5b549955..46ccaa20 100644 --- a/config.com +++ b/config.com @@ -1,5 +1,5 @@ $ ! OpenSSL config: determine the architecture and run Configure -$ ! Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +$ ! Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. $ ! $ ! Licensed under the OpenSSL license (the "License"). You may not use $ ! this file except in compliance with the License. You can obtain a @@ -73,7 +73,7 @@ $ collected_args = collected_args + " --debug" $ P = "" $ ENDIF $ IF P .NES. "" THEN - - collected_args = collected_args + " " + P1 + collected_args = collected_args + " """ + P1 + """" $ P1 = P2 $ P2 = P3 $ P3 = P4 @@ -87,7 +87,7 @@ $ ENDLOOP1: $ $ target = "vms-''arch'''pointer_size'" $ IF verbose THEN - - WRITE SYS$OUTPUT "PERL ''here'Configure ""''target'""''collected_args'" + WRITE SYS$OUTPUT "PERL ''here'Configure ""''target'""",collected_args $ IF .not. dryrun THEN - - PERL 'here'Configure "''target'" 'debug' 'collected_args' + PERL 'here'Configure "''target'"'collected_args' $ EXIT $STATUS diff --git a/crypto/aes/asm/aes-armv4.pl b/crypto/aes/asm/aes-armv4.pl index 16d79aae..99815899 100644 --- a/crypto/aes/asm/aes-armv4.pl +++ b/crypto/aes/asm/aes-armv4.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the OpenSSL license (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -200,10 +200,10 @@ AES_encrypt: #ifndef __thumb2__ sub r3,pc,#8 @ AES_encrypt #else - adr r3,AES_encrypt + adr r3,. #endif stmdb sp!,{r1,r4-r12,lr} -#ifdef __APPLE__ +#if defined(__thumb2__) || defined(__APPLE__) adr $tbl,AES_Te #else sub $tbl,r3,#AES_encrypt-AES_Te @ Te @@ -450,7 +450,7 @@ _armv4_AES_set_encrypt_key: #ifndef __thumb2__ sub r3,pc,#8 @ AES_set_encrypt_key #else - adr r3,AES_set_encrypt_key + adr r3,. #endif teq r0,#0 #ifdef __thumb2__ @@ -481,7 +481,7 @@ _armv4_AES_set_encrypt_key: mov lr,r1 @ bits mov $key,r2 @ key -#ifdef __APPLE__ +#if defined(__thumb2__) || defined(__APPLE__) adr $tbl,AES_Te+1024 @ Te4 #else sub $tbl,r3,#_armv4_AES_set_encrypt_key-AES_Te-1024 @ Te4 @@ -976,10 +976,10 @@ AES_decrypt: #ifndef __thumb2__ sub r3,pc,#8 @ AES_decrypt #else - adr r3,AES_decrypt + adr r3,. #endif stmdb sp!,{r1,r4-r12,lr} -#ifdef __APPLE__ +#if defined(__thumb2__) || defined(__APPLE__) adr $tbl,AES_Td #else sub $tbl,r3,#AES_decrypt-AES_Td @ Td diff --git a/crypto/aes/asm/aes-s390x.pl b/crypto/aes/asm/aes-s390x.pl index a93d6019..fd8a7371 100644 --- a/crypto/aes/asm/aes-s390x.pl +++ b/crypto/aes/asm/aes-s390x.pl @@ -813,7 +813,7 @@ _s390x_AES_set_encrypt_key: .Lproceed: ___ $code.=<<___ if (!$softonly); - # convert bits to km code, [128,192,256]->[18,19,20] + # convert bits to km(c) code, [128,192,256]->[18,19,20] lhi %r5,-128 lhi %r0,18 ar %r5,$bits @@ -821,13 +821,10 @@ $code.=<<___ if (!$softonly); ar %r5,%r0 larl %r1,OPENSSL_s390xcap_P - lg %r0,0(%r1) - tmhl %r0,0x4000 # check for message-security assist - jz .Lekey_internal - llihh %r0,0x8000 srlg %r0,%r0,0(%r5) - ng %r0,48(%r1) # check kmc capability vector + ng %r0,32(%r1) # check availability of both km... + ng %r0,48(%r1) # ...and kmc support for given key length jz .Lekey_internal lmg %r0,%r1,0($inp) # just copy 128 bits... @@ -842,7 +839,7 @@ $code.=<<___ if (!$softonly); stg %r1,24($key) 1: st $bits,236($key) # save bits [for debugging purposes] lgr $t0,%r5 - st %r5,240($key) # save km code + st %r5,240($key) # save km(c) code lghi %r2,0 br %r14 ___ @@ -1439,12 +1436,7 @@ $code.=<<___ if (!$softonly); .Lctr32_hw_switch: ___ -$code.=<<___ if (0); ######### kmctr code was measured to be ~12% slower - larl $s0,OPENSSL_s390xcap_P - lg $s0,8($s0) - tmhh $s0,0x0004 # check for message_security-assist-4 - jz .Lctr32_km_loop - +$code.=<<___ if (!$softonly && 0);# kmctr code was measured to be ~12% slower llgfr $s0,%r0 lgr $s1,%r1 larl %r1,OPENSSL_s390xcap_P @@ -1488,7 +1480,7 @@ $code.=<<___ if (0); ######### kmctr code was measured to be ~12% slower br $ra .align 16 ___ -$code.=<<___; +$code.=<<___ if (!$softonly); .Lctr32_km_loop: la $s2,16($sp) lgr $s3,$fp @@ -2227,7 +2219,6 @@ ___ } $code.=<<___; .string "AES for s390x, CRYPTOGAMS by " -.comm OPENSSL_s390xcap_P,80,8 ___ $code =~ s/\`([^\`]*)\`/eval $1/gem; diff --git a/crypto/aes/asm/aesni-sha1-x86_64.pl b/crypto/aes/asm/aesni-sha1-x86_64.pl index adff3a35..33a7f0cf 100644 --- a/crypto/aes/asm/aesni-sha1-x86_64.pl +++ b/crypto/aes/asm/aesni-sha1-x86_64.pl @@ -34,6 +34,8 @@ # Haswell 4.43[+3.6(4.2)] 8.00(8.58) 4.55(5.21) +75%(+65%) # Skylake 2.63[+3.5(4.1)] 6.17(6.69) 4.23(4.44) +46%(+51%) # Bulldozer 5.77[+6.0] 11.72 6.37 +84% +# Ryzen(**) 2.71[+1.93] 4.64 2.74 +69% +# Goldmont(**) 3.82[+1.70] 5.52 4.20 +31% # # AES-192-CBC # Westmere 4.51 9.81 6.80 +44% @@ -47,13 +49,16 @@ # Sandy Bridge 7.05 12.06(13.15) 7.12(7.72) +69%(+70%) # Ivy Bridge 7.05 11.65 7.12 +64% # Haswell 6.19 9.76(10.34) 6.21(6.25) +57%(+65%) -# Skylake 3.62 7.16(7.68) 4.56(4.76) +57%(+61$) +# Skylake 3.62 7.16(7.68) 4.56(4.76) +57%(+61%) # Bulldozer 8.00 13.95 8.25 +69% +# Ryzen(**) 3.71 5.64 3.72 +52% +# Goldmont(**) 5.35 7.05 5.76 +22% # # (*) There are two code paths: SSSE3 and AVX. See sha1-568.pl for # background information. Above numbers in parentheses are SSSE3 # results collected on AVX-capable CPU, i.e. apply on OSes that # don't support AVX. +# (**) SHAEXT results. # # Needless to mention that it makes no sense to implement "stitched" # *decrypt* subroutine. Because *both* AESNI-CBC decrypt and SHA1 diff --git a/crypto/aes/asm/aesni-sha256-x86_64.pl b/crypto/aes/asm/aesni-sha256-x86_64.pl index 3b03328f..0e49f26f 100644 --- a/crypto/aes/asm/aesni-sha256-x86_64.pl +++ b/crypto/aes/asm/aesni-sha256-x86_64.pl @@ -28,18 +28,21 @@ # for standalone AESNI-CBC encrypt, standalone SHA256, and stitched # subroutine: # -# AES-128/-192/-256+SHA256 this(**)gain -# Sandy Bridge 5.05/6.05/7.05+11.6 13.0 +28%/36%/43% -# Ivy Bridge 5.05/6.05/7.05+10.3 11.6 +32%/41%/50% -# Haswell 4.43/5.29/6.19+7.80 8.79 +39%/49%/59% -# Skylake 2.62/3.14/3.62+7.70 8.10 +27%/34%/40% -# Bulldozer 5.77/6.89/8.00+13.7 13.7 +42%/50%/58% +# AES-128/-192/-256+SHA256 this(**) gain +# Sandy Bridge 5.05/6.05/7.05+11.6 13.0 +28%/36%/43% +# Ivy Bridge 5.05/6.05/7.05+10.3 11.6 +32%/41%/50% +# Haswell 4.43/5.29/6.19+7.80 8.79 +39%/49%/59% +# Skylake 2.62/3.14/3.62+7.70 8.10 +27%/34%/40% +# Bulldozer 5.77/6.89/8.00+13.7 13.7 +42%/50%/58% +# Ryzen(***) 2.71/-/3.71+2.05 2.74/-/3.73 +74%/-/54% +# Goldmont(***) 3.82/-/5.35+4.16 4.73/-/5.94 +69%/-/60% # # (*) there are XOP, AVX1 and AVX2 code paths, meaning that # Westmere is omitted from loop, this is because gain was not # estimated high enough to justify the effort; # (**) these are EVP-free results, results obtained with 'speed # -evp aes-256-cbc-hmac-sha256' will vary by percent or two; +# (***) these are SHAEXT results; $flavour = shift; $output = shift; diff --git a/crypto/aes/asm/bsaes-armv7.pl b/crypto/aes/asm/bsaes-armv7.pl index 9f288660..7af38afc 100644 --- a/crypto/aes/asm/bsaes-armv7.pl +++ b/crypto/aes/asm/bsaes-armv7.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2012-2018 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the OpenSSL license (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -744,9 +744,9 @@ $code.=<<___; .type _bsaes_decrypt8,%function .align 4 _bsaes_decrypt8: - adr $const,_bsaes_decrypt8 + adr $const,. vldmia $key!, {@XMM[9]} @ round 0 key -#ifdef __APPLE__ +#if defined(__thumb2__) || defined(__APPLE__) adr $const,.LM0ISR #else add $const,$const,#.LM0ISR-_bsaes_decrypt8 @@ -843,9 +843,9 @@ _bsaes_const: .type _bsaes_encrypt8,%function .align 4 _bsaes_encrypt8: - adr $const,_bsaes_encrypt8 + adr $const,. vldmia $key!, {@XMM[9]} @ round 0 key -#ifdef __APPLE__ +#if defined(__thumb2__) || defined(__APPLE__) adr $const,.LM0SR #else sub $const,$const,#_bsaes_encrypt8-.LM0SR @@ -951,9 +951,9 @@ $code.=<<___; .type _bsaes_key_convert,%function .align 4 _bsaes_key_convert: - adr $const,_bsaes_key_convert + adr $const,. vld1.8 {@XMM[7]}, [$inp]! @ load round 0 key -#ifdef __APPLE__ +#if defined(__thumb2__) || defined(__APPLE__) adr $const,.LM0 #else sub $const,$const,#_bsaes_key_convert-.LM0 diff --git a/crypto/armcap.c b/crypto/armcap.c index 29534845..432a06c0 100644 --- a/crypto/armcap.c +++ b/crypto/armcap.c @@ -1,5 +1,5 @@ /* - * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2011-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -69,7 +69,7 @@ static unsigned long (*getauxval) (unsigned long) = NULL; # endif /* - * ARM puts the the feature bits for Crypto Extensions in AT_HWCAP2, whereas + * ARM puts the feature bits for Crypto Extensions in AT_HWCAP2, whereas * AArch64 used AT_HWCAP. */ # if defined(__arm__) || defined (__arm) diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c index 33be907f..b2e0fb68 100644 --- a/crypto/asn1/a_bitstr.c +++ b/crypto/asn1/a_bitstr.c @@ -7,6 +7,7 @@ * https://www.openssl.org/source/license.html */ +#include #include #include "internal/cryptlib.h" #include @@ -88,6 +89,11 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, goto err; } + if (len > INT_MAX) { + i = ASN1_R_STRING_TOO_LONG; + goto err; + } + if ((a == NULL) || ((*a) == NULL)) { if ((ret = ASN1_BIT_STRING_new()) == NULL) return (NULL); diff --git a/crypto/asn1/a_digest.c b/crypto/asn1/a_digest.c index 46bff0d8..c84ecc9b 100644 --- a/crypto/asn1/a_digest.c +++ b/crypto/asn1/a_digest.c @@ -9,13 +9,10 @@ #include #include +#include #include "internal/cryptlib.h" -#ifndef NO_SYS_TYPES_H -# include -#endif - #include #include #include diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c index 1514ede4..3b3f713c 100644 --- a/crypto/asn1/a_i2d_fp.c +++ b/crypto/asn1/a_i2d_fp.c @@ -38,6 +38,9 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) int i, j = 0, n, ret = 1; n = i2d(x, NULL); + if (n <= 0) + return 0; + b = OPENSSL_malloc(n); if (b == NULL) { ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE); diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c index 5578e923..7a035afb 100644 --- a/crypto/asn1/a_mbstr.c +++ b/crypto/asn1/a_mbstr.c @@ -100,14 +100,14 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, if ((minsize > 0) && (nchar < minsize)) { ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT); - BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize); + BIO_snprintf(strbuf, sizeof(strbuf), "%ld", minsize); ERR_add_error_data(2, "minsize=", strbuf); return -1; } if ((maxsize > 0) && (nchar > maxsize)) { ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG); - BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize); + BIO_snprintf(strbuf, sizeof(strbuf), "%ld", maxsize); ERR_add_error_data(2, "maxsize=", strbuf); return -1; } diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c index 79f0ecd2..1ec7a7e1 100644 --- a/crypto/asn1/a_object.c +++ b/crypto/asn1/a_object.c @@ -42,7 +42,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) { int i, first, len = 0, c, use_bn; char ftmp[24], *tmp = ftmp; - int tmpsize = sizeof ftmp; + int tmpsize = sizeof(ftmp); const char *p; unsigned long l; BIGNUM *bl = NULL; @@ -177,7 +177,7 @@ int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a) if ((a == NULL) || (a->data == NULL)) return (BIO_write(bp, "NULL", 4)); - i = i2t_ASN1_OBJECT(buf, sizeof buf, a); + i = i2t_ASN1_OBJECT(buf, sizeof(buf), a); if (i > (int)(sizeof(buf) - 1)) { p = OPENSSL_malloc(i + 1); if (p == NULL) diff --git a/crypto/asn1/a_sign.c b/crypto/asn1/a_sign.c index 7e21a5ec..3b261eba 100644 --- a/crypto/asn1/a_sign.c +++ b/crypto/asn1/a_sign.c @@ -9,13 +9,10 @@ #include #include +#include #include "internal/cryptlib.h" -#ifndef NO_SYS_TYPES_H -# include -#endif - #include #include #include diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index 1bc06799..b91266b3 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -63,7 +63,7 @@ typedef int char_io (void *arg, const void *buf, int len); * even 4 byte forms. */ -static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, +static int do_esc_char(unsigned long c, unsigned short flags, char *do_quotes, char_io *io_ch, void *arg) { unsigned short chflgs; @@ -73,13 +73,13 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, if (c > 0xffffffffL) return -1; if (c > 0xffff) { - BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); + BIO_snprintf(tmphex, sizeof(tmphex), "\\W%08lX", c); if (!io_ch(arg, tmphex, 10)) return -1; return 10; } if (c > 0xff) { - BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); + BIO_snprintf(tmphex, sizeof(tmphex), "\\U%04lX", c); if (!io_ch(arg, tmphex, 6)) return -1; return 6; @@ -116,7 +116,7 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, * If we get this far and do any escaping at all must escape the escape * character itself: backslash. */ - if (chtmp == '\\' && flags & ESC_FLAGS) { + if (chtmp == '\\' && (flags & ESC_FLAGS)) { if (!io_ch(arg, "\\\\", 2)) return -1; return 2; @@ -143,6 +143,7 @@ static int do_buf(unsigned char *buf, int buflen, unsigned short orflags; unsigned char *p, *q; unsigned long c; + p = buf; q = buf + buflen; outlen = 0; @@ -182,7 +183,7 @@ static int do_buf(unsigned char *buf, int buflen, if (type & BUF_TYPE_CONVUTF8) { unsigned char utfbuf[6]; int utflen; - utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); + utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c); for (i = 0; i < utflen; i++) { /* * We don't need to worry about setting orflags correctly @@ -190,17 +191,15 @@ static int do_buf(unsigned char *buf, int buflen, * otherwise each character will be > 0x7f and so the * character will never be escaped on first and last. */ - len = - do_esc_char(utfbuf[i], (unsigned short)(flags | orflags), - quotes, io_ch, arg); + len = do_esc_char(utfbuf[i], flags | orflags, quotes, + io_ch, arg); if (len < 0) return -1; outlen += len; } } else { - len = - do_esc_char(c, (unsigned short)(flags | orflags), quotes, - io_ch, arg); + len = do_esc_char(c, flags | orflags, quotes, + io_ch, arg); if (len < 0) return -1; outlen += len; @@ -479,7 +478,7 @@ static int do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, if (fn_opt != XN_FLAG_FN_NONE) { int objlen, fld_len; if ((fn_opt == XN_FLAG_FN_OID) || (fn_nid == NID_undef)) { - OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); + OBJ_obj2txt(objtmp, sizeof(objtmp), fn, 1); fld_len = 0; /* XXX: what should this be? */ objbuf = objtmp; } else { diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index aadc26ce..ecf178e2 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -214,6 +214,7 @@ static ASN1_STRING_TABLE *stable_get(int nid) rv->mask = tmp->mask; rv->flags = tmp->flags | STABLE_FLAGS_MALLOC; } else { + rv->nid = nid; rv->minsize = -1; rv->maxsize = -1; rv->flags = STABLE_FLAGS_MALLOC; diff --git a/crypto/asn1/a_verify.c b/crypto/asn1/a_verify.c index 00ab136f..fb3607cb 100644 --- a/crypto/asn1/a_verify.c +++ b/crypto/asn1/a_verify.c @@ -9,13 +9,10 @@ #include #include +#include #include "internal/cryptlib.h" -#ifndef NO_SYS_TYPES_H -# include -#endif - #include #include #include diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index cfde49ab..b8ba0678 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -143,7 +143,8 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len) { int i; - const EVP_PKEY_ASN1_METHOD *ameth; + const EVP_PKEY_ASN1_METHOD *ameth = NULL; + if (len == -1) len = strlen(str); if (pe) { @@ -163,12 +164,12 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, #endif *pe = NULL; } - for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { + for (i = EVP_PKEY_asn1_get_count(); i-- > 0; ) { ameth = EVP_PKEY_asn1_get0(i); if (ameth->pkey_flags & ASN1_PKEY_ALIAS) continue; - if (((int)strlen(ameth->pem_str) == len) - && (strncasecmp(ameth->pem_str, str, len) == 0)) + if ((int)strlen(ameth->pem_str) == len + && strncasecmp(ameth->pem_str, str, len) == 0) return ameth; } return NULL; @@ -176,11 +177,21 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) { + EVP_PKEY_ASN1_METHOD tmp = { 0, }; + if (app_methods == NULL) { app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); if (app_methods == NULL) return 0; } + + tmp.pkey_id = ameth->pkey_id; + if (sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp) >= 0) { + EVPerr(EVP_F_EVP_PKEY_ASN1_ADD0, + EVP_R_PKEY_APPLICATION_ASN1_METHOD_ALREADY_REGISTERED); + return 0; + } + if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) return 0; sk_EVP_PKEY_ASN1_METHOD_sort(app_methods); diff --git a/crypto/asn1/asn1_err.c b/crypto/asn1/asn1_err.c index dd0e99e6..8602c408 100644 --- a/crypto/asn1/asn1_err.c +++ b/crypto/asn1/asn1_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -203,6 +203,7 @@ static ERR_STRING_DATA ASN1_str_reasons[] = { {ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL), "mstring not universal"}, {ERR_REASON(ASN1_R_MSTRING_WRONG_TAG), "mstring wrong tag"}, {ERR_REASON(ASN1_R_NESTED_ASN1_STRING), "nested asn1 string"}, + {ERR_REASON(ASN1_R_NESTED_TOO_DEEP), "nested too deep"}, {ERR_REASON(ASN1_R_NON_HEX_CHARACTERS), "non hex characters"}, {ERR_REASON(ASN1_R_NOT_ASCII_FORMAT), "not ascii format"}, {ERR_REASON(ASN1_R_NOT_ENOUGH_DATA), "not enough data"}, diff --git a/crypto/asn1/asn1_locl.h b/crypto/asn1/asn1_locl.h index 9470c7d0..9a47b1ef 100644 --- a/crypto/asn1/asn1_locl.h +++ b/crypto/asn1/asn1_locl.h @@ -65,6 +65,7 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it); +void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed); void asn1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed); void asn1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); diff --git a/crypto/asn1/asn1_par.c b/crypto/asn1/asn1_par.c index af045cb1..fabc8d6f 100644 --- a/crypto/asn1/asn1_par.c +++ b/crypto/asn1/asn1_par.c @@ -38,13 +38,13 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, p = str; if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) - BIO_snprintf(str, sizeof str, "priv [ %d ] ", tag); + BIO_snprintf(str, sizeof(str), "priv [ %d ] ", tag); else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) - BIO_snprintf(str, sizeof str, "cont [ %d ]", tag); + BIO_snprintf(str, sizeof(str), "cont [ %d ]", tag); else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) - BIO_snprintf(str, sizeof str, "appl [ %d ]", tag); + BIO_snprintf(str, sizeof(str), "appl [ %d ]", tag); else if (tag > 30) - BIO_snprintf(str, sizeof str, "", tag); + BIO_snprintf(str, sizeof(str), "", tag); else p = ASN1_tag2str(tag); diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index d7ec801b..84475e94 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2008-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -425,6 +425,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) || hdr->value == NULL) { sk_MIME_HEADER_pop_free(headers, mime_hdr_free); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); + sk_BIO_pop_free(parts, BIO_vfree); return NULL; } diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c index 7576c65d..2a8a41f5 100644 --- a/crypto/asn1/bio_asn1.c +++ b/crypto/asn1/bio_asn1.c @@ -65,7 +65,7 @@ static int asn1_bio_gets(BIO *h, char *str, int size); static long asn1_bio_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int asn1_bio_new(BIO *h); static int asn1_bio_free(BIO *data); -static long asn1_bio_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long asn1_bio_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size); static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, @@ -301,7 +301,7 @@ static int asn1_bio_gets(BIO *b, char *str, int size) return BIO_gets(next, str, size); } -static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long asn1_bio_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { BIO *next = BIO_next(b); if (next == NULL) diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index c9b63751..af8641e3 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,9 +17,18 @@ #include "internal/numbers.h" #include "asn1_locl.h" +/* + * Constructed types with a recursive definition (such as can be found in PKCS7) + * could eventually exceed the stack given malicious input with excessive + * recursion. Therefore we limit the stack depth. This is the maximum number of + * recursive invocations of asn1_item_embed_d2i(). + */ +#define ASN1_MAX_CONSTRUCTED_NEST 30 + static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, - int tag, int aclass, char opt, ASN1_TLC *ctx); + int tag, int aclass, char opt, ASN1_TLC *ctx, + int depth); static int asn1_check_eoc(const unsigned char **in, long len); static int asn1_find_end(const unsigned char **in, long len, char inf); @@ -37,11 +46,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, - ASN1_TLC *ctx); + ASN1_TLC *ctx, int depth); static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, - ASN1_TLC *ctx); + ASN1_TLC *ctx, int depth); static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, @@ -111,7 +120,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, int tag, int aclass, char opt, ASN1_TLC *ctx) { int rv; - rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx); + rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx, 0); if (rv <= 0) ASN1_item_ex_free(pval, it); return rv; @@ -124,7 +133,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, - int tag, int aclass, char opt, ASN1_TLC *ctx) + int tag, int aclass, char opt, ASN1_TLC *ctx, + int depth) { const ASN1_TEMPLATE *tt, *errtt = NULL; const ASN1_EXTERN_FUNCS *ef; @@ -145,6 +155,11 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, else asn1_cb = 0; + if (++depth > ASN1_MAX_CONSTRUCTED_NEST) { + ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_NESTED_TOO_DEEP); + goto err; + } + switch (it->itype) { case ASN1_ITYPE_PRIMITIVE: if (it->templates) { @@ -160,7 +175,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, goto err; } return asn1_template_ex_d2i(pval, in, len, - it->templates, opt, ctx); + it->templates, opt, ctx, depth); } return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx); @@ -221,7 +236,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, /* * We mark field as OPTIONAL so its absence can be recognised. */ - ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx); + ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx, depth); /* If field not present, try the next one */ if (ret == -1) continue; @@ -344,7 +359,8 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, * attempt to read in field, allowing each to be OPTIONAL */ - ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx); + ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx, + depth); if (!ret) { errtt = seqtt; goto err; @@ -420,7 +436,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, - ASN1_TLC *ctx) + ASN1_TLC *ctx, int depth) { int flags, aclass; int ret; @@ -455,7 +471,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, return 0; } /* We've found the field so it can't be OPTIONAL now */ - ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); + ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx, depth); if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; @@ -479,7 +495,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, } } } else - return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx); + return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx, depth); *in = p; return 1; @@ -491,7 +507,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, - ASN1_TLC *ctx) + ASN1_TLC *ctx, int depth) { int flags, aclass; int ret; @@ -573,7 +589,8 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, } skfield = NULL; if (!asn1_item_embed_d2i(&skfield, &p, len, - ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) { + ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx, + depth)) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); /* |skfield| may be partially allocated despite failure. */ @@ -595,7 +612,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, /* IMPLICIT tagging */ ret = asn1_item_embed_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, - ctx); + ctx, depth); if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -604,7 +621,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, } else { /* Nothing special */ ret = asn1_item_embed_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), - -1, 0, opt, ctx); + -1, 0, opt, ctx, depth); if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; diff --git a/crypto/asn1/tasn_fre.c b/crypto/asn1/tasn_fre.c index ae914617..bbce489f 100644 --- a/crypto/asn1/tasn_fre.c +++ b/crypto/asn1/tasn_fre.c @@ -13,9 +13,6 @@ #include #include "asn1_locl.h" -static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, - int embed); - /* Free up an ASN1 structure */ void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) @@ -28,8 +25,7 @@ void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) asn1_item_embed_free(pval, it, 0); } -static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, - int embed) +void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) { const ASN1_TEMPLATE *tt = NULL, *seqtt; const ASN1_EXTERN_FUNCS *ef; diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c index f695e38d..11c80402 100644 --- a/crypto/asn1/tasn_new.c +++ b/crypto/asn1/tasn_new.c @@ -124,8 +124,13 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) goto memerr; } /* 0 : init. lock */ - if (asn1_do_lock(pval, 0, it) < 0) - goto memerr2; + if (asn1_do_lock(pval, 0, it) < 0) { + if (!embed) { + OPENSSL_free(*pval); + *pval = NULL; + } + goto memerr; + } asn1_enc_init(pval, it); for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { pseqval = asn1_get_field_ptr(pval, tt); @@ -142,7 +147,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) return 1; memerr2: - ASN1_item_ex_free(pval, it); + asn1_item_embed_free(pval, it, embed); memerr: ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ERR_R_MALLOC_FAILURE); #ifndef OPENSSL_NO_CRYPTO_MDEBUG @@ -151,7 +156,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) return 0; auxerr2: - ASN1_item_ex_free(pval, it); + asn1_item_embed_free(pval, it, embed); auxerr: ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ASN1_R_AUX_ERROR); #ifndef OPENSSL_NO_CRYPTO_MDEBUG diff --git a/crypto/asn1/tasn_prn.c b/crypto/asn1/tasn_prn.c index f53e9056..53a9ee8e 100644 --- a/crypto/asn1/tasn_prn.c +++ b/crypto/asn1/tasn_prn.c @@ -409,7 +409,7 @@ static int asn1_print_oid(BIO *out, const ASN1_OBJECT *oid) ln = OBJ_nid2ln(OBJ_obj2nid(oid)); if (!ln) ln = ""; - OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1); + OBJ_obj2txt(objbuf, sizeof(objbuf), oid, 1); if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0) return 0; return 1; diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h index 3c61f7f7..76937a9e 100644 --- a/crypto/async/arch/async_posix.h +++ b/crypto/async/arch/async_posix.h @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,7 +11,7 @@ #define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H #include -#if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) \ +#if defined(OPENSSL_SYS_UNIX) \ && defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) \ && !defined(__ANDROID__) && !defined(__OpenBSD__) diff --git a/crypto/async/async.c b/crypto/async/async.c index 8c699af7..9a4e6b26 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -36,7 +36,7 @@ static async_ctx *async_ctx_new(void) { async_ctx *nctx = NULL; - nctx = OPENSSL_malloc(sizeof (async_ctx)); + nctx = OPENSSL_malloc(sizeof(async_ctx)); if (nctx == NULL) { ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE); goto err; @@ -81,7 +81,7 @@ static ASYNC_JOB *async_job_new(void) { ASYNC_JOB *job = NULL; - job = OPENSSL_zalloc(sizeof (ASYNC_JOB)); + job = OPENSSL_zalloc(sizeof(ASYNC_JOB)); if (job == NULL) { ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE); return NULL; @@ -330,7 +330,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size) return 0; } - pool = OPENSSL_zalloc(sizeof *pool); + pool = OPENSSL_zalloc(sizeof(*pool)); if (pool == NULL) { ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE); return 0; diff --git a/crypto/async/async_wait.c b/crypto/async/async_wait.c index e115985d..0a0bf873 100644 --- a/crypto/async/async_wait.c +++ b/crypto/async/async_wait.c @@ -47,7 +47,7 @@ int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key, { struct fd_lookup_st *fdlookup; - fdlookup = OPENSSL_zalloc(sizeof *fdlookup); + fdlookup = OPENSSL_zalloc(sizeof(*fdlookup)); if (fdlookup == NULL) return 0; diff --git a/crypto/bf/bf_locl.h b/crypto/bf/bf_locl.h index 7e5f92c2..b1a415e5 100644 --- a/crypto/bf/bf_locl.h +++ b/crypto/bf/bf_locl.h @@ -17,12 +17,19 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 1: l1|=((unsigned long)(*(--(c))))<<24; \ } \ } @@ -32,12 +39,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ } \ } diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c index 289404c1..aea843a7 100644 --- a/crypto/bio/b_addr.c +++ b/crypto/bio/b_addr.c @@ -76,7 +76,7 @@ int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa) } #endif #ifdef AF_UNIX - if (ap->sa.sa_family == AF_UNIX) { + if (sa->sa_family == AF_UNIX) { ap->s_un = *(const struct sockaddr_un *)sa; return 1; } @@ -668,7 +668,7 @@ int BIO_lookup(const char *host, const char *service, int gai_ret = 0; struct addrinfo hints; - memset(&hints, 0, sizeof hints); + memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = socktype; diff --git a/crypto/bio/b_dump.c b/crypto/bio/b_dump.c index a27954fa..424195e1 100644 --- a/crypto/bio/b_dump.c +++ b/crypto/bio/b_dump.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,7 +14,6 @@ #include #include "bio_lcl.h" -#define TRUNCATE #define DUMP_WIDTH 16 #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4)) @@ -29,17 +28,10 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), { int ret = 0; char buf[288 + 1], tmp[20], str[128 + 1]; - int i, j, rows, trc; + int i, j, rows; unsigned char ch; int dump_width; - trc = 0; - -#ifdef TRUNCATE - for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) - trc++; -#endif - if (indent < 0) indent = 0; if (indent) { @@ -54,50 +46,43 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), if ((rows * dump_width) < len) rows++; for (i = 0; i < rows; i++) { - OPENSSL_strlcpy(buf, str, sizeof buf); - BIO_snprintf(tmp, sizeof tmp, "%04x - ", i * dump_width); - OPENSSL_strlcat(buf, tmp, sizeof buf); + OPENSSL_strlcpy(buf, str, sizeof(buf)); + BIO_snprintf(tmp, sizeof(tmp), "%04x - ", i * dump_width); + OPENSSL_strlcat(buf, tmp, sizeof(buf)); for (j = 0; j < dump_width; j++) { if (((i * dump_width) + j) >= len) { - OPENSSL_strlcat(buf, " ", sizeof buf); + OPENSSL_strlcat(buf, " ", sizeof(buf)); } else { ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; - BIO_snprintf(tmp, sizeof tmp, "%02x%c", ch, + BIO_snprintf(tmp, sizeof(tmp), "%02x%c", ch, j == 7 ? '-' : ' '); - OPENSSL_strlcat(buf, tmp, sizeof buf); + OPENSSL_strlcat(buf, tmp, sizeof(buf)); } } - OPENSSL_strlcat(buf, " ", sizeof buf); + OPENSSL_strlcat(buf, " ", sizeof(buf)); for (j = 0; j < dump_width; j++) { if (((i * dump_width) + j) >= len) break; ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; #ifndef CHARSET_EBCDIC - BIO_snprintf(tmp, sizeof tmp, "%c", + BIO_snprintf(tmp, sizeof(tmp), "%c", ((ch >= ' ') && (ch <= '~')) ? ch : '.'); #else - BIO_snprintf(tmp, sizeof tmp, "%c", + BIO_snprintf(tmp, sizeof(tmp), "%c", ((ch >= os_toascii[' ']) && (ch <= os_toascii['~'])) ? os_toebcdic[ch] : '.'); #endif - OPENSSL_strlcat(buf, tmp, sizeof buf); + OPENSSL_strlcat(buf, tmp, sizeof(buf)); } - OPENSSL_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcat(buf, "\n", sizeof(buf)); /* * if this is the last call then update the ddt_dump thing so that we * will move the selection point in the debug window */ ret += cb((void *)buf, strlen(buf), u); } -#ifdef TRUNCATE - if (trc > 0) { - BIO_snprintf(buf, sizeof buf, "%s%04x - \n", str, - len + trc); - ret += cb((void *)buf, strlen(buf), u); - } -#endif - return (ret); + return ret; } #ifndef OPENSSL_NO_STDIO diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c index 7bbc551c..cdfe05f9 100644 --- a/crypto/bio/b_print.c +++ b/crypto/bio/b_print.c @@ -258,6 +258,7 @@ _dopr(char **sbuffer, break; case 'E': flags |= DP_F_UP; + /* fall thru */ case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); @@ -269,6 +270,7 @@ _dopr(char **sbuffer, break; case 'G': flags |= DP_F_UP; + /* fall thru */ case 'g': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); @@ -663,7 +665,7 @@ fmtfp(char **sbuffer, iconvert[iplace++] = "0123456789"[intpart % 10]; intpart = (intpart / 10); } while (intpart && (iplace < (int)sizeof(iconvert))); - if (iplace == sizeof iconvert) + if (iplace == sizeof(iconvert)) iplace--; iconvert[iplace] = 0; @@ -681,7 +683,7 @@ fmtfp(char **sbuffer, fracpart = (fracpart / 10); } - if (fplace == sizeof fconvert) + if (fplace == sizeof(fconvert)) fplace--; fconvert[fplace] = 0; diff --git a/crypto/bio/b_sock2.c b/crypto/bio/b_sock2.c index 7f4d89e5..d8b49d02 100644 --- a/crypto/bio/b_sock2.c +++ b/crypto/bio/b_sock2.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -172,8 +172,10 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options) return 0; # ifndef OPENSSL_SYS_WINDOWS - /* SO_REUSEADDR has different behavior on Windows than on - * other operating systems, don't set it there. */ + /* + * SO_REUSEADDR has different behavior on Windows than on + * other operating systems, don't set it there. + */ if (options & BIO_SOCK_REUSEADDR) { if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) { SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error()); @@ -200,7 +202,12 @@ int BIO_listen(int sock, const BIO_ADDR *addr, int options) } # ifdef IPV6_V6ONLY - if ((options & BIO_SOCK_V6_ONLY) && BIO_ADDR_family(addr) == AF_INET6) { + if (BIO_ADDR_family(addr) == AF_INET6) { + /* + * Note: Windows default of IPV6_V6ONLY is ON, and Linux is OFF. + * Therefore we always have to use setsockopt here. + */ + on = options & BIO_SOCK_V6_ONLY ? 1 : 0; if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) != 0) { SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error()); BIOerr(BIO_F_BIO_LISTEN, BIO_R_LISTEN_V6_ONLY); diff --git a/crypto/bio/bf_buff.c b/crypto/bio/bf_buff.c index b2a387b5..85099561 100644 --- a/crypto/bio/bf_buff.c +++ b/crypto/bio/bf_buff.c @@ -19,7 +19,7 @@ static int buffer_gets(BIO *h, char *str, int size); static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int buffer_new(BIO *h); static int buffer_free(BIO *data); -static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long buffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); #define DEFAULT_BUFFER_SIZE 4096 static const BIO_METHOD methods_buffer = { @@ -388,7 +388,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) return (0); } -static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; diff --git a/crypto/bio/bf_lbuf.c b/crypto/bio/bf_lbuf.c index b3c2b5ee..a80f899a 100644 --- a/crypto/bio/bf_lbuf.c +++ b/crypto/bio/bf_lbuf.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,7 +20,7 @@ static int linebuffer_gets(BIO *h, char *str, int size); static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int linebuffer_new(BIO *h); static int linebuffer_free(BIO *data); -static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long linebuffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); /* A 10k maximum should be enough for most purposes */ #define DEFAULT_LINEBUFFER_SIZE 1024*10 @@ -116,9 +116,10 @@ static int linebuffer_write(BIO *b, const char *in, int inl) do { const char *p; + char c; - for (p = in; p < in + inl && *p != '\n'; p++) ; - if (*p == '\n') { + for (p = in, c = '\0'; p < in + inl && (c = *p) != '\n'; p++) ; + if (c == '\n') { p++; foundnl = 1; } else @@ -292,7 +293,7 @@ static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) return (0); } -static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long linebuffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; diff --git a/crypto/bio/bf_nbio.c b/crypto/bio/bf_nbio.c index 364d9fb5..3328506d 100644 --- a/crypto/bio/bf_nbio.c +++ b/crypto/bio/bf_nbio.c @@ -24,7 +24,7 @@ static int nbiof_gets(BIO *h, char *str, int size); static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int nbiof_new(BIO *h); static int nbiof_free(BIO *data); -static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long nbiof_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); typedef struct nbio_test_st { /* only set if we sent a 'should retry' error */ int lrn; @@ -165,7 +165,7 @@ static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) return (ret); } -static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long nbiof_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; diff --git a/crypto/bio/bf_null.c b/crypto/bio/bf_null.c index 0736b3f2..6b86aa55 100644 --- a/crypto/bio/bf_null.c +++ b/crypto/bio/bf_null.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -21,9 +21,7 @@ static int nullf_read(BIO *h, char *buf, int size); static int nullf_puts(BIO *h, const char *str); static int nullf_gets(BIO *h, char *str, int size); static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2); -static int nullf_new(BIO *h); -static int nullf_free(BIO *data); -static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long nullf_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); static const BIO_METHOD methods_nullf = { BIO_TYPE_NULL_FILTER, "NULL filter", @@ -32,8 +30,8 @@ static const BIO_METHOD methods_nullf = { nullf_puts, nullf_gets, nullf_ctrl, - nullf_new, - nullf_free, + NULL, + NULL, nullf_callback_ctrl, }; @@ -42,26 +40,6 @@ const BIO_METHOD *BIO_f_null(void) return (&methods_nullf); } -static int nullf_new(BIO *bi) -{ - bi->init = 1; - bi->ptr = NULL; - bi->flags = 0; - return (1); -} - -static int nullf_free(BIO *a) -{ - if (a == NULL) - return (0); - /*- - a->ptr=NULL; - a->init=0; - a->flags=0; - */ - return (1); -} - static int nullf_read(BIO *b, char *out, int outl) { int ret = 0; @@ -111,7 +89,7 @@ static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr) return (ret); } -static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long nullf_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; diff --git a/crypto/bio/bio_cb.c b/crypto/bio/bio_cb.c index 69ea3d06..412387b6 100644 --- a/crypto/bio/bio_cb.c +++ b/crypto/bio/bio_cb.c @@ -27,7 +27,7 @@ long BIO_debug_callback(BIO *bio, int cmd, const char *argp, if (BIO_CB_RETURN & cmd) r = ret; - len = BIO_snprintf(buf, sizeof buf, "BIO[%p]: ", (void *)bio); + len = BIO_snprintf(buf, sizeof(buf), "BIO[%p]: ", (void *)bio); /* Ignore errors and continue printing the other information. */ if (len < 0) diff --git a/crypto/bio/bio_err.c b/crypto/bio/bio_err.c index 98c90d6e..c914dcff 100644 --- a/crypto/bio/bio_err.c +++ b/crypto/bio/bio_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -34,6 +34,7 @@ static ERR_STRING_DATA BIO_str_functs[] = { {ERR_FUNC(BIO_F_BIO_LISTEN), "BIO_listen"}, {ERR_FUNC(BIO_F_BIO_LOOKUP), "BIO_lookup"}, {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "bio_make_pair"}, + {ERR_FUNC(BIO_F_BIO_METH_NEW), "BIO_meth_new"}, {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"}, {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"}, diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 62392c3a..7b98dc93 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -42,6 +42,8 @@ BIO *BIO_new(const BIO_METHOD *method) CRYPTO_THREAD_lock_free(bio->lock); goto err; } + if (method->create == NULL) + bio->init = 1; return bio; @@ -350,9 +352,7 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) return (ret); } -long BIO_callback_ctrl(BIO *b, int cmd, - void (*fp) (struct bio_st *, int, const char *, int, - long, long)) +long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret; long (*cb) (BIO *, int, const char *, int, long, long); diff --git a/crypto/bio/bio_meth.c b/crypto/bio/bio_meth.c index c5f9f7e8..1e785d34 100644 --- a/crypto/bio/bio_meth.c +++ b/crypto/bio/bio_meth.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -37,16 +37,21 @@ BIO_METHOD *BIO_meth_new(int type, const char *name) { BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD)); - if (biom != NULL) { - biom->type = type; - biom->name = name; + if (biom == NULL + || (biom->name = OPENSSL_strdup(name)) == NULL) { + OPENSSL_free(biom); + BIOerr(BIO_F_BIO_METH_NEW, ERR_R_MALLOC_FAILURE); + return NULL; } return biom; } void BIO_meth_free(BIO_METHOD *biom) { - OPENSSL_free(biom); + if (biom != NULL) { + OPENSSL_free(biom->name); + OPENSSL_free(biom); + } } int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int) @@ -131,14 +136,14 @@ int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *)) return 1; } -long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) (BIO *, int, bio_info_cb *) +long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) (BIO *, int, BIO_info_cb *) { return biom->callback_ctrl; } int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, long (*callback_ctrl) (BIO *, int, - bio_info_cb *)) + BIO_info_cb *)) { biom->callback_ctrl = callback_ctrl; return 1; diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c index 6fb971a5..21d21c16 100644 --- a/crypto/bio/bss_acpt.c +++ b/crypto/bio/bss_acpt.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -57,11 +57,11 @@ static const BIO_METHOD methods_acceptp = { acpt_write, acpt_read, acpt_puts, - NULL, /* connect_gets, */ + NULL, /* connect_gets, */ acpt_ctrl, acpt_new, acpt_free, - NULL, + NULL, /* connect_callback_ctrl */ }; const BIO_METHOD *BIO_s_accept(void) @@ -271,6 +271,11 @@ static int acpt_state(BIO *b, BIO_ACCEPT *c) BIO_clear_retry_flags(b); b->retry_reason = 0; + OPENSSL_free(c->cache_peer_name); + c->cache_peer_name = NULL; + OPENSSL_free(c->cache_peer_serv); + c->cache_peer_serv = NULL; + s = BIO_accept_ex(c->accept_sock, &c->cache_peer_addr, c->accepted_mode); diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index dfd0988d..e343bcdd 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -32,7 +32,7 @@ typedef struct bio_connect_st { * The callback should return 'ret'. state is for compatibility with the * ssl info_callback */ - int (*info_callback) (const BIO *bio, int state, int ret); + BIO_info_cb *info_callback; } BIO_CONNECT; static int conn_write(BIO *h, const char *buf, int num); @@ -41,7 +41,7 @@ static int conn_puts(BIO *h, const char *str); static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int conn_new(BIO *h); static int conn_free(BIO *data); -static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *); +static long conn_callback_ctrl(BIO *h, int cmd, BIO_info_cb *); static int conn_state(BIO *b, BIO_CONNECT *c); static void conn_close_socket(BIO *data); @@ -61,7 +61,7 @@ static const BIO_METHOD methods_connectp = { conn_write, conn_read, conn_puts, - NULL, /* connect_gets, */ + NULL, /* conn_gets, */ conn_ctrl, conn_new, conn_free, @@ -71,7 +71,7 @@ static const BIO_METHOD methods_connectp = { static int conn_state(BIO *b, BIO_CONNECT *c) { int ret = -1, i; - int (*cb) (const BIO *, int, int) = NULL; + BIO_info_cb *cb = NULL; if (c->info_callback != NULL) cb = c->info_callback; @@ -469,8 +469,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) * FIXME: the cast of the function seems unlikely to be a good * idea */ - (void)BIO_set_info_callback(dbio, - (bio_info_cb *)data->info_callback); + (void)BIO_set_info_callback(dbio, data->info_callback); } break; case BIO_CTRL_SET_CALLBACK: @@ -486,9 +485,9 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) break; case BIO_CTRL_GET_CALLBACK: { - int (**fptr) (const BIO *bio, int state, int xret); + BIO_info_cb **fptr; - fptr = (int (**)(const BIO *bio, int state, int xret))ptr; + fptr = (BIO_info_cb **)ptr; *fptr = data->info_callback; } break; @@ -499,7 +498,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) return (ret); } -static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long conn_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; BIO_CONNECT *data; @@ -509,8 +508,7 @@ static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) switch (cmd) { case BIO_CTRL_SET_CALLBACK: { - data->info_callback = - (int (*)(const struct bio_st *, int, int))fp; + data->info_callback = fp; } break; default: diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c index 81730abe..c772d956 100644 --- a/crypto/bio/bss_dgram.c +++ b/crypto/bio/bss_dgram.c @@ -76,11 +76,11 @@ static const BIO_METHOD methods_dgramp = { dgram_write, dgram_read, dgram_puts, - NULL, /* dgram_gets, */ + NULL, /* dgram_gets, */ dgram_ctrl, dgram_new, dgram_free, - NULL, + NULL, /* dgram_callback_ctrl */ }; # ifndef OPENSSL_NO_SCTP @@ -90,11 +90,11 @@ static const BIO_METHOD methods_dgramp_sctp = { dgram_sctp_write, dgram_sctp_read, dgram_sctp_puts, - NULL, /* dgram_gets, */ + NULL, /* dgram_gets, */ dgram_sctp_ctrl, dgram_sctp_new, dgram_sctp_free, - NULL, + NULL, /* dgram_callback_ctrl */ }; # endif @@ -782,6 +782,15 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD: ret = dgram_get_mtu_overhead(data); break; + + /* + * BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE is used here for compatibility + * reasons. When BIO_CTRL_DGRAM_SET_PEEK_MODE was first defined its value + * was incorrectly clashing with BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE. The + * value has been updated to a non-clashing value. However to preserve + * binary compatiblity we now respond to both the old value and the new one + */ + case BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE: case BIO_CTRL_DGRAM_SET_PEEK_MODE: data->peekmode = (unsigned int)num; break; @@ -1442,6 +1451,7 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) * we need to deactivate an old key */ data->ccs_sent = 1; + /* fall-through */ case BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD: /* Returns 0 on success, -1 otherwise. */ diff --git a/crypto/bio/bss_fd.c b/crypto/bio/bss_fd.c index 1e56cb62..2bd3517d 100644 --- a/crypto/bio/bss_fd.c +++ b/crypto/bio/bss_fd.c @@ -58,7 +58,8 @@ static int fd_free(BIO *data); int BIO_fd_should_retry(int s); static const BIO_METHOD methods_fdp = { - BIO_TYPE_FD, "file descriptor", + BIO_TYPE_FD, + "file descriptor", fd_write, fd_read, fd_puts, @@ -66,7 +67,7 @@ static const BIO_METHOD methods_fdp = { fd_ctrl, fd_new, fd_free, - NULL, + NULL, /* fd_callback_ctrl */ }; const BIO_METHOD *BIO_s_fd(void) @@ -144,6 +145,7 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) switch (cmd) { case BIO_CTRL_RESET: num = 0; + /* fall thru */ case BIO_C_FILE_SEEK: ret = (long)UP_lseek(b->num, num, 0); break; diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c index e3d8c0e4..2edf2448 100644 --- a/crypto/bio/bss_file.c +++ b/crypto/bio/bss_file.c @@ -58,7 +58,7 @@ static const BIO_METHOD methods_filep = { file_ctrl, file_new, file_free, - NULL, + NULL, /* file_callback_ctrl */ }; BIO *BIO_new_file(const char *filename, const char *mode) @@ -267,15 +267,15 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) b->shutdown = (int)num & BIO_CLOSE; if (num & BIO_FP_APPEND) { if (num & BIO_FP_READ) - OPENSSL_strlcpy(p, "a+", sizeof p); + OPENSSL_strlcpy(p, "a+", sizeof(p)); else - OPENSSL_strlcpy(p, "a", sizeof p); + OPENSSL_strlcpy(p, "a", sizeof(p)); } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) - OPENSSL_strlcpy(p, "r+", sizeof p); + OPENSSL_strlcpy(p, "r+", sizeof(p)); else if (num & BIO_FP_WRITE) - OPENSSL_strlcpy(p, "w", sizeof p); + OPENSSL_strlcpy(p, "w", sizeof(p)); else if (num & BIO_FP_READ) - OPENSSL_strlcpy(p, "r", sizeof p); + OPENSSL_strlcpy(p, "r", sizeof(p)); else { BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); ret = 0; @@ -406,7 +406,7 @@ static const BIO_METHOD methods_filep = { file_ctrl, file_new, file_free, - NULL, + NULL, /* file_callback_ctrl */ }; const BIO_METHOD *BIO_s_file(void) diff --git a/crypto/bio/bss_log.c b/crypto/bio/bss_log.c index 6cbde4d2..5221acc2 100644 --- a/crypto/bio/bss_log.c +++ b/crypto/bio/bss_log.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -85,15 +85,16 @@ static void xsyslog(BIO *bp, int priority, const char *string); static void xcloselog(BIO *bp); static const BIO_METHOD methods_slg = { - BIO_TYPE_MEM, "syslog", + BIO_TYPE_MEM, + "syslog", slg_write, - NULL, + NULL, /* slg_read, */ slg_puts, - NULL, + NULL, /* slg_gets, */ slg_ctrl, slg_new, slg_free, - NULL, + NULL, /* slg_callback_ctrl */ }; const BIO_METHOD *BIO_s_log(void) diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c index 6dc075dc..ff9a3ebb 100644 --- a/crypto/bio/bss_mem.c +++ b/crypto/bio/bss_mem.c @@ -33,7 +33,7 @@ static const BIO_METHOD mem_method = { mem_ctrl, mem_new, mem_free, - NULL, + NULL, /* mem_callback_ctrl */ }; static const BIO_METHOD secmem_method = { @@ -46,7 +46,7 @@ static const BIO_METHOD secmem_method = { mem_ctrl, secmem_new, mem_free, - NULL, + NULL, /* mem_callback_ctrl */ }; /* BIO memory stores buffer and read pointer */ diff --git a/crypto/bio/bss_null.c b/crypto/bio/bss_null.c index e5c4adc8..56f95f9f 100644 --- a/crypto/bio/bss_null.c +++ b/crypto/bio/bss_null.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,8 +17,6 @@ static int null_read(BIO *h, char *buf, int size); static int null_puts(BIO *h, const char *str); static int null_gets(BIO *h, char *str, int size); static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); -static int null_new(BIO *h); -static int null_free(BIO *data); static const BIO_METHOD null_method = { BIO_TYPE_NULL, "NULL", @@ -27,9 +25,9 @@ static const BIO_METHOD null_method = { null_puts, null_gets, null_ctrl, - null_new, - null_free, NULL, + NULL, + NULL, /* null_callback_ctrl */ }; const BIO_METHOD *BIO_s_null(void) @@ -37,21 +35,6 @@ const BIO_METHOD *BIO_s_null(void) return (&null_method); } -static int null_new(BIO *bi) -{ - bi->init = 1; - bi->num = 0; - bi->ptr = (NULL); - return (1); -} - -static int null_free(BIO *a) -{ - if (a == NULL) - return (0); - return (1); -} - static int null_read(BIO *b, char *out, int outl) { return (0); diff --git a/crypto/bio/bss_sock.c b/crypto/bio/bss_sock.c index 570e8985..992266dc 100644 --- a/crypto/bio/bss_sock.c +++ b/crypto/bio/bss_sock.c @@ -41,11 +41,11 @@ static const BIO_METHOD methods_sockp = { sock_write, sock_read, sock_puts, - NULL, /* sock_gets, */ + NULL, /* sock_gets, */ sock_ctrl, sock_new, sock_free, - NULL, + NULL, /* sock_callback_ctrl */ }; const BIO_METHOD *BIO_s_socket(void) diff --git a/crypto/bn/asm/rsaz-avx2.pl b/crypto/bn/asm/rsaz-avx2.pl index 0c1b236e..46d746b7 100644 --- a/crypto/bn/asm/rsaz-avx2.pl +++ b/crypto/bn/asm/rsaz-avx2.pl @@ -246,7 +246,7 @@ $code.=<<___; vmovdqu 32*8-128($ap), $ACC8 lea 192(%rsp), $tp0 # 64+128=192 - vpbroadcastq .Land_mask(%rip), $AND_MASK + vmovdqu .Land_mask(%rip), $AND_MASK jmp .LOOP_GRANDE_SQR_1024 .align 32 @@ -1077,10 +1077,10 @@ $code.=<<___; vpmuludq 32*6-128($np),$Yi,$TEMP1 vpaddq $TEMP1,$ACC6,$ACC6 vpmuludq 32*7-128($np),$Yi,$TEMP2 - vpblendd \$3, $ZERO, $ACC9, $ACC9 # correct $ACC3 + vpblendd \$3, $ZERO, $ACC9, $TEMP1 # correct $ACC3 vpaddq $TEMP2,$ACC7,$ACC7 vpmuludq 32*8-128($np),$Yi,$TEMP0 - vpaddq $ACC9, $ACC3, $ACC3 # correct $ACC3 + vpaddq $TEMP1, $ACC3, $ACC3 # correct $ACC3 vpaddq $TEMP0,$ACC8,$ACC8 mov %rbx, %rax @@ -1093,7 +1093,9 @@ $code.=<<___; vmovdqu -8+32*2-128($ap),$TEMP2 mov $r1, %rax + vpblendd \$0xfc, $ZERO, $ACC9, $ACC9 # correct $ACC3 imull $n0, %eax + vpaddq $ACC9,$ACC4,$ACC4 # correct $ACC3 and \$0x1fffffff, %eax imulq 16-128($ap),%rbx @@ -1329,15 +1331,12 @@ ___ # But as we underutilize resources, it's possible to correct in # each iteration with marginal performance loss. But then, as # we do it in each iteration, we can correct less digits, and -# avoid performance penalties completely. Also note that we -# correct only three digits out of four. This works because -# most significant digit is subjected to less additions. +# avoid performance penalties completely. $TEMP0 = $ACC9; $TEMP3 = $Bi; $TEMP4 = $Yi; $code.=<<___; - vpermq \$0, $AND_MASK, $AND_MASK vpaddq (%rsp), $TEMP1, $ACC0 vpsrlq \$29, $ACC0, $TEMP1 @@ -1770,7 +1769,7 @@ $code.=<<___; .align 64 .Land_mask: - .quad 0x1fffffff,0x1fffffff,0x1fffffff,-1 + .quad 0x1fffffff,0x1fffffff,0x1fffffff,0x1fffffff .Lscatter_permd: .long 0,2,4,6,7,7,7,7 .Lgather_permd: diff --git a/crypto/bn/asm/x86.pl b/crypto/bn/asm/x86.pl deleted file mode 100644 index d57571db..00000000 --- a/crypto/bn/asm/x86.pl +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env perl -# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. -# -# Licensed under the OpenSSL license (the "License"). You may not use -# this file except in compliance with the License. You can obtain a copy -# in the file LICENSE in the source distribution or at -# https://www.openssl.org/source/license.html - -push(@INC,"perlasm","../../perlasm"); -require "x86asm.pl"; - -require("x86/mul_add.pl"); -require("x86/mul.pl"); -require("x86/sqr.pl"); -require("x86/div.pl"); -require("x86/add.pl"); -require("x86/sub.pl"); -require("x86/comba.pl"); - -$output = pop; -open STDOUT,">$output"; - -&asm_init($ARGV[0],$0); - -&bn_mul_add_words("bn_mul_add_words"); -&bn_mul_words("bn_mul_words"); -&bn_sqr_words("bn_sqr_words"); -&bn_div_words("bn_div_words"); -&bn_add_words("bn_add_words"); -&bn_sub_words("bn_sub_words"); -&bn_mul_comba("bn_mul_comba8",8); -&bn_mul_comba("bn_mul_comba4",4); -&bn_sqr_comba("bn_sqr_comba8",8); -&bn_sqr_comba("bn_sqr_comba4",4); - -&asm_finish(); - -close STDOUT; diff --git a/crypto/bn/asm/x86_64-gcc.c b/crypto/bn/asm/x86_64-gcc.c index 4f19abe4..0ff3805a 100644 --- a/crypto/bn/asm/x86_64-gcc.c +++ b/crypto/bn/asm/x86_64-gcc.c @@ -225,9 +225,10 @@ BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, " adcq (%5,%2,8),%0 \n" " movq %0,(%3,%2,8) \n" " lea 1(%2),%2 \n" - " loop 1b \n" - " sbbq %0,%0 \n":"=&r" (ret), "+c"(n), - "+r"(i) + " dec %1 \n" + " jnz 1b \n" + " sbbq %0,%0 \n" + :"=&r" (ret), "+c"(n), "+r"(i) :"r"(rp), "r"(ap), "r"(bp) :"cc", "memory"); @@ -251,9 +252,10 @@ BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, " sbbq (%5,%2,8),%0 \n" " movq %0,(%3,%2,8) \n" " lea 1(%2),%2 \n" - " loop 1b \n" - " sbbq %0,%0 \n":"=&r" (ret), "+c"(n), - "+r"(i) + " dec %1 \n" + " jnz 1b \n" + " sbbq %0,%0 \n" + :"=&r" (ret), "+c"(n), "+r"(i) :"r"(rp), "r"(ap), "r"(bp) :"cc", "memory"); diff --git a/crypto/bn/asm/x86_64-mont5.pl b/crypto/bn/asm/x86_64-mont5.pl index 6807ab5c..5779059e 100644 --- a/crypto/bn/asm/x86_64-mont5.pl +++ b/crypto/bn/asm/x86_64-mont5.pl @@ -3099,11 +3099,19 @@ $code.=<<___; .align 32 .Lsqrx8x_break: - sub 16+8(%rsp),%r8 # consume last carry + xor $zero,$zero + sub 16+8(%rsp),%rbx # mov 16(%rsp),%cf + adcx $zero,%r8 mov 24+8(%rsp),$carry # initial $tptr, borrow $carry + adcx $zero,%r9 mov 0*8($aptr),%rdx # a[8], modulo-scheduled - xor %ebp,%ebp # xor $zero,$zero + adc \$0,%r10 mov %r8,0*8($tptr) + adc \$0,%r11 + adc \$0,%r12 + adc \$0,%r13 + adc \$0,%r14 + adc \$0,%r15 cmp $carry,$tptr # cf=0, of=0 je .Lsqrx8x_outer_loop diff --git a/crypto/bn/bn_add.c b/crypto/bn/bn_add.c index 6479650a..7cdefa77 100644 --- a/crypto/bn/bn_add.c +++ b/crypto/bn/bn_add.c @@ -141,9 +141,13 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) borrow &= (t1 == 0); } + while (max && *--rp == 0) + max--; + r->top = max; r->neg = 0; - bn_correct_top(r); + bn_pollute(r); + return 1; } diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c index feeb7649..0d2d1eca 100644 --- a/crypto/bn/bn_exp.c +++ b/crypto/bn/bn_exp.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -43,7 +43,8 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) int i, bits, ret = 0; BIGNUM *v, *rr; - if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { + if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(a, BN_FLG_CONSTTIME) != 0) { /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ BNerr(BN_F_BN_EXP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; @@ -143,7 +144,9 @@ int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, if (BN_is_odd(m)) { # ifdef MONT_EXP_WORD if (a->top == 1 && !a->neg - && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) { + && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0) + && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0) + && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) { BN_ULONG A = a->d[0]; ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL); } else @@ -175,7 +178,9 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BIGNUM *val[TABLE_SIZE]; BN_RECP_CTX recp; - if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { + if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(a, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) { /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; @@ -309,7 +314,9 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, BIGNUM *val[TABLE_SIZE]; BN_MONT_CTX *mont = NULL; - if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { + if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(a, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) { return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont); } @@ -626,7 +633,11 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, top = m->top; - bits = BN_num_bits(p); + /* + * Use all bits stored in |p|, rather than |BN_num_bits|, so we do not leak + * whether the top bits are zero. + */ + bits = p->top * BN_BITS2; if (bits == 0) { /* x**0 mod 1 is still zero. */ if (BN_is_one(m)) { @@ -1121,7 +1132,8 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, #define BN_TO_MONTGOMERY_WORD(r, w, mont) \ (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx)) - if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { + if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) { /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; @@ -1252,7 +1264,9 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, /* Table of variables obtained from 'ctx' */ BIGNUM *val[TABLE_SIZE]; - if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { + if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(a, BN_FLG_CONSTTIME) != 0 + || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) { /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ BNerr(BN_F_BN_MOD_EXP_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 17d34c31..70584940 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -88,74 +88,47 @@ const BIGNUM *BN_value_one(void) int BN_num_bits_word(BN_ULONG l) { - static const unsigned char bits[256] = { - 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - }; + BN_ULONG x, mask; + int bits = (l != 0); -#if defined(SIXTY_FOUR_BIT_LONG) - if (l & 0xffffffff00000000L) { - if (l & 0xffff000000000000L) { - if (l & 0xff00000000000000L) { - return (bits[(int)(l >> 56)] + 56); - } else - return (bits[(int)(l >> 48)] + 48); - } else { - if (l & 0x0000ff0000000000L) { - return (bits[(int)(l >> 40)] + 40); - } else - return (bits[(int)(l >> 32)] + 32); - } - } else -#else -# ifdef SIXTY_FOUR_BIT - if (l & 0xffffffff00000000LL) { - if (l & 0xffff000000000000LL) { - if (l & 0xff00000000000000LL) { - return (bits[(int)(l >> 56)] + 56); - } else - return (bits[(int)(l >> 48)] + 48); - } else { - if (l & 0x0000ff0000000000LL) { - return (bits[(int)(l >> 40)] + 40); - } else - return (bits[(int)(l >> 32)] + 32); - } - } else -# endif +#if BN_BITS2 > 32 + x = l >> 32; + mask = (0 - x) & BN_MASK2; + mask = (0 - (mask >> (BN_BITS2 - 1))); + bits += 32 & mask; + l ^= (x ^ l) & mask; #endif - { -#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) - if (l & 0xffff0000L) { - if (l & 0xff000000L) - return (bits[(int)(l >> 24L)] + 24); - else - return (bits[(int)(l >> 16L)] + 16); - } else -#endif - { -#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) - if (l & 0xff00L) - return (bits[(int)(l >> 8)] + 8); - else -#endif - return (bits[(int)(l)]); - } - } + + x = l >> 16; + mask = (0 - x) & BN_MASK2; + mask = (0 - (mask >> (BN_BITS2 - 1))); + bits += 16 & mask; + l ^= (x ^ l) & mask; + + x = l >> 8; + mask = (0 - x) & BN_MASK2; + mask = (0 - (mask >> (BN_BITS2 - 1))); + bits += 8 & mask; + l ^= (x ^ l) & mask; + + x = l >> 4; + mask = (0 - x) & BN_MASK2; + mask = (0 - (mask >> (BN_BITS2 - 1))); + bits += 4 & mask; + l ^= (x ^ l) & mask; + + x = l >> 2; + mask = (0 - x) & BN_MASK2; + mask = (0 - (mask >> (BN_BITS2 - 1))); + bits += 2 & mask; + l ^= (x ^ l) & mask; + + x = l >> 1; + mask = (0 - x) & BN_MASK2; + mask = (0 - (mask >> (BN_BITS2 - 1))); + bits += 1 & mask; + + return bits; } int BN_num_bits(const BIGNUM *a) @@ -295,10 +268,13 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) switch (b->top & 3) { case 3: A[2] = B[2]; + /* fall thru */ case 2: A[1] = B[1]; + /* fall thru */ case 1: A[0] = B[0]; + /* fall thru */ case 0: /* Without the "case 0" some old optimizers got this wrong. */ ; @@ -390,10 +366,13 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) switch (b->top & 3) { case 3: A[2] = B[2]; + /* fall thru */ case 2: A[1] = B[1]; + /* fall thru */ case 1: A[0] = B[0]; + /* fall thru */ case 0:; } #else @@ -888,7 +867,7 @@ int BN_security_bits(int L, int N) int secbits, bits; if (L >= 15360) secbits = 256; - else if (L >= 7690) + else if (L >= 7680) secbits = 192; else if (L >= 3072) secbits = 128; diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c index 6d37279a..faef5815 100644 --- a/crypto/bn/bn_mont.c +++ b/crypto/bn/bn_mont.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -101,6 +101,11 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) r->top = max; n0 = mont->n0[0]; + /* + * Add multiples of |n| to |r| until R = 2^(nl * BN_BITS2) divides it. On + * input, we had |r| < |n| * R, so now |r| < 2 * |n| * R. Note that |r| + * includes |carry| which is stored separately. + */ for (carry = 0, i = 0; i < nl; i++, rp++) { v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2); v = (v + carry + rp[nl]) & BN_MASK2; @@ -115,46 +120,24 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) ret->neg = r->neg; rp = ret->d; + + /* + * Shift |nl| words to divide by R. We have |ap| < 2 * |n|. Note that |ap| + * includes |carry| which is stored separately. + */ ap = &(r->d[nl]); -# define BRANCH_FREE 1 -# if BRANCH_FREE - { - BN_ULONG *nrp; - size_t m; - - v = bn_sub_words(rp, ap, np, nl) - carry; - /* - * if subtraction result is real, then trick unconditional memcpy - * below to perform in-place "refresh" instead of actual copy. - */ - m = (0 - (size_t)v); - nrp = - (BN_ULONG *)(((PTR_SIZE_INT) rp & ~m) | ((PTR_SIZE_INT) ap & m)); - - for (i = 0, nl -= 4; i < nl; i += 4) { - BN_ULONG t1, t2, t3, t4; - - t1 = nrp[i + 0]; - t2 = nrp[i + 1]; - t3 = nrp[i + 2]; - ap[i + 0] = 0; - t4 = nrp[i + 3]; - ap[i + 1] = 0; - rp[i + 0] = t1; - ap[i + 2] = 0; - rp[i + 1] = t2; - ap[i + 3] = 0; - rp[i + 2] = t3; - rp[i + 3] = t4; - } - for (nl += 4; i < nl; i++) - rp[i] = nrp[i], ap[i] = 0; + /* + * |v| is one if |ap| - |np| underflowed or zero if it did not. Note |v| + * cannot be -1. That would imply the subtraction did not fit in |nl| words, + * and we know at most one subtraction is needed. + */ + v = bn_sub_words(rp, ap, np, nl) - carry; + v = 0 - v; + for (i = 0; i < nl; i++) { + rp[i] = (v & ap[i]) | (~v & rp[i]); + ap[i] = 0; } -# else - if (bn_sub_words(rp, ap, np, nl) - carry) - memcpy(rp, ap, nl * sizeof(BN_ULONG)); -# endif bn_correct_top(r); bn_correct_top(ret); bn_check_top(ret); @@ -258,6 +241,8 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) R = &(mont->RR); /* grab RR as a temp */ if (!BN_copy(&(mont->N), mod)) goto err; /* Set N */ + if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0) + BN_set_flags(&(mont->N), BN_FLG_CONSTTIME); mont->N.neg = 0; #ifdef MONT_WORD @@ -270,6 +255,9 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) tmod.dmax = 2; tmod.neg = 0; + if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0) + BN_set_flags(&tmod, BN_FLG_CONSTTIME); + mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2; # if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32) diff --git a/crypto/bn/bn_mul.c b/crypto/bn/bn_mul.c index 4a0a9505..a1abc5b0 100644 --- a/crypto/bn/bn_mul.c +++ b/crypto/bn/bn_mul.c @@ -115,10 +115,12 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, r[1] = a[1]; if (--dl <= 0) break; + /* fall thru */ case 2: r[2] = a[2]; if (--dl <= 0) break; + /* fall thru */ case 3: r[3] = a[3]; if (--dl <= 0) @@ -206,10 +208,12 @@ BN_ULONG bn_add_part_words(BN_ULONG *r, r[1] = b[1]; if (++dl >= 0) break; + /* fall thru */ case 2: r[2] = b[2]; if (++dl >= 0) break; + /* fall thru */ case 3: r[3] = b[3]; if (++dl >= 0) @@ -276,10 +280,12 @@ BN_ULONG bn_add_part_words(BN_ULONG *r, r[1] = a[1]; if (--dl <= 0) break; + /* fall thru */ case 2: r[2] = a[2]; if (--dl <= 0) break; + /* fall thru */ case 3: r[3] = a[3]; if (--dl <= 0) @@ -918,46 +924,6 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) rr->top = top; goto end; } -# if 0 - if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) { - BIGNUM *tmp_bn = (BIGNUM *)b; - if (bn_wexpand(tmp_bn, al) == NULL) - goto err; - tmp_bn->d[bl] = 0; - bl++; - i--; - } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) { - BIGNUM *tmp_bn = (BIGNUM *)a; - if (bn_wexpand(tmp_bn, bl) == NULL) - goto err; - tmp_bn->d[al] = 0; - al++; - i++; - } - if (i == 0) { - /* symmetric and > 4 */ - /* 16 or larger */ - j = BN_num_bits_word((BN_ULONG)al); - j = 1 << (j - 1); - k = j + j; - t = BN_CTX_get(ctx); - if (al == j) { /* exact multiple */ - if (bn_wexpand(t, k * 2) == NULL) - goto err; - if (bn_wexpand(rr, k * 2) == NULL) - goto err; - bn_mul_recursive(rr->d, a->d, b->d, al, t->d); - } else { - if (bn_wexpand(t, k * 4) == NULL) - goto err; - if (bn_wexpand(rr, k * 4) == NULL) - goto err; - bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d); - } - rr->top = top; - goto end; - } -# endif } #endif /* BN_RECURSION */ if (bn_wexpand(rr, top) == NULL) diff --git a/crypto/bn/bn_print.c b/crypto/bn/bn_print.c index 82167606..5ffe2fc9 100644 --- a/crypto/bn/bn_print.c +++ b/crypto/bn/bn_print.c @@ -332,10 +332,10 @@ char *BN_options(void) if (!init) { init++; #ifdef BN_LLONG - BIO_snprintf(data, sizeof data, "bn(%d,%d)", + BIO_snprintf(data, sizeof(data), "bn(%d,%d)", (int)sizeof(BN_ULLONG) * 8, (int)sizeof(BN_ULONG) * 8); #else - BIO_snprintf(data, sizeof data, "bn(%d,%d)", + BIO_snprintf(data, sizeof(data), "bn(%d,%d)", (int)sizeof(BN_ULONG) * 8, (int)sizeof(BN_ULONG) * 8); #endif } diff --git a/crypto/bn/bn_x931p.c b/crypto/bn/bn_x931p.c index 40734cb2..8bfbcac6 100644 --- a/crypto/bn/bn_x931p.c +++ b/crypto/bn/bn_x931p.c @@ -178,6 +178,8 @@ int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) BN_CTX_start(ctx); t = BN_CTX_get(ctx); + if (t == NULL) + goto err; for (i = 0; i < 1000; i++) { if (!BN_rand(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY)) @@ -216,10 +218,12 @@ int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, int ret = 0; BN_CTX_start(ctx); - if (!Xp1) + if (Xp1 == NULL) Xp1 = BN_CTX_get(ctx); - if (!Xp2) + if (Xp2 == NULL) Xp2 = BN_CTX_get(ctx); + if (Xp1 == NULL || Xp2 == NULL) + goto error; if (!BN_rand(Xp1, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)) goto error; diff --git a/crypto/buffer/buffer.c b/crypto/buffer/buffer.c index 6b0bd4a4..f3f8a1b5 100644 --- a/crypto/buffer/buffer.c +++ b/crypto/buffer/buffer.c @@ -47,7 +47,7 @@ void BUF_MEM_free(BUF_MEM *a) if (a->data != NULL) { if (a->flags & BUF_MEM_FLAG_SECURE) - OPENSSL_secure_free(a->data); + OPENSSL_secure_clear_free(a->data, a->max); else OPENSSL_clear_free(a->data, a->max); } @@ -62,9 +62,11 @@ static char *sec_alloc_realloc(BUF_MEM *str, size_t len) ret = OPENSSL_secure_malloc(len); if (str->data != NULL) { - if (ret != NULL) + if (ret != NULL) { memcpy(ret, str->data, str->length); - OPENSSL_secure_free(str->data); + OPENSSL_secure_clear_free(str->data, str->length); + str->data = NULL; + } } return (ret); } diff --git a/crypto/cast/c_enc.c b/crypto/cast/c_enc.c index 9a858125..700b6d16 100644 --- a/crypto/cast/c_enc.c +++ b/crypto/cast/c_enc.c @@ -12,8 +12,8 @@ void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key) { - register CAST_LONG l, r, t; - const register CAST_LONG *k; + CAST_LONG l, r, t; + const CAST_LONG *k; k = &(key->data[0]); l = data[0]; @@ -44,8 +44,8 @@ void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key) void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key) { - register CAST_LONG l, r, t; - const register CAST_LONG *k; + CAST_LONG l, r, t; + const CAST_LONG *k; k = &(key->data[0]); l = data[0]; diff --git a/crypto/cast/cast_lcl.h b/crypto/cast/cast_lcl.h index 504232a1..e8cf322d 100644 --- a/crypto/cast/cast_lcl.h +++ b/crypto/cast/cast_lcl.h @@ -64,12 +64,19 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 1: l1|=((unsigned long)(*(--(c))))<<24; \ } \ } @@ -79,12 +86,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ } \ } diff --git a/crypto/cms/cms_asn1.c b/crypto/cms/cms_asn1.c index 81e9a530..0a594f41 100644 --- a/crypto/cms/cms_asn1.c +++ b/crypto/cms/cms_asn1.c @@ -292,6 +292,7 @@ static int cms_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, case ASN1_OP_STREAM_PRE: if (CMS_stream(&sarg->boundary, cms) <= 0) return 0; + /* fall thru */ case ASN1_OP_DETACHED_PRE: sarg->ndef_bio = CMS_dataInit(cms, sarg->out); if (!sarg->ndef_bio) diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c index 76c1f53b..4108fe70 100644 --- a/crypto/cms/cms_sd.c +++ b/crypto/cms/cms_sd.c @@ -713,8 +713,10 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si) md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm); if (md == NULL) return -1; - if (si->mctx == NULL) - si->mctx = EVP_MD_CTX_new(); + if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) { + CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY, ERR_R_MALLOC_FAILURE); + return -1; + } mctx = si->mctx; if (EVP_DigestVerifyInit(mctx, &si->pctx, md, NULL, si->pkey) <= 0) goto err; diff --git a/crypto/cms/cms_smime.c b/crypto/cms/cms_smime.c index dbf7dd3a..7e7b6e5d 100644 --- a/crypto/cms/cms_smime.c +++ b/crypto/cms/cms_smime.c @@ -583,19 +583,17 @@ static int cms_kari_set1_pkey(CMS_ContentInfo *cms, CMS_RecipientInfo *ri, STACK_OF(CMS_RecipientEncryptedKey) *reks; CMS_RecipientEncryptedKey *rek; reks = CMS_RecipientInfo_kari_get0_reks(ri); - if (!cert) - return 0; for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks); i++) { int rv; rek = sk_CMS_RecipientEncryptedKey_value(reks, i); - if (CMS_RecipientEncryptedKey_cert_cmp(rek, cert)) + if (cert != NULL && CMS_RecipientEncryptedKey_cert_cmp(rek, cert)) continue; CMS_RecipientInfo_kari_set0_pkey(ri, pk); rv = CMS_RecipientInfo_kari_decrypt(cms, ri, rek); CMS_RecipientInfo_kari_set0_pkey(ri, NULL); if (rv > 0) return 1; - return -1; + return cert == NULL ? 0 : -1; } return 0; } @@ -659,8 +657,8 @@ int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert) return 1; } } - /* If no cert and not debugging always return success */ - if (match_ri && !cert && !debug) { + /* If no cert, key transport and not debugging always return success */ + if (cert == NULL && ri_type == CMS_RECIPINFO_TRANS && match_ri && !debug) { ERR_clear_error(); return 1; } diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c index 2f38c2e9..821dc099 100644 --- a/crypto/comp/c_zlib.c +++ b/crypto/comp/c_zlib.c @@ -292,15 +292,15 @@ static int bio_zlib_free(BIO *bi); static int bio_zlib_read(BIO *b, char *out, int outl); static int bio_zlib_write(BIO *b, const char *in, int inl); static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr); -static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp); +static long bio_zlib_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp); static const BIO_METHOD bio_meth_zlib = { BIO_TYPE_COMP, "zlib", bio_zlib_write, bio_zlib_read, - NULL, - NULL, + NULL, /* bio_zlib_puts, */ + NULL, /* bio_zlib_gets, */ bio_zlib_ctrl, bio_zlib_new, bio_zlib_free, @@ -604,7 +604,7 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr) return ret; } -static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long bio_zlib_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { BIO *next = BIO_next(b); if (next == NULL) diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index a7b11d15..b443903f 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -353,7 +353,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) OPENSSL_free(section); if (line != NULL) *line = eline; - BIO_snprintf(btmp, sizeof btmp, "%ld", eline); + BIO_snprintf(btmp, sizeof(btmp), "%ld", eline); ERR_add_error_data(2, "line ", btmp); if (h != conf->data) { CONF_free(conf->data); diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c index 31f838e0..543a8ea4 100644 --- a/crypto/conf/conf_mod.c +++ b/crypto/conf/conf_mod.c @@ -171,7 +171,7 @@ static int module_run(const CONF *cnf, const char *name, const char *value, if (!(flags & CONF_MFLAGS_SILENT)) { char rcode[DECIMAL_SIZE(ret) + 1]; CONFerr(CONF_F_MODULE_RUN, CONF_R_MODULE_INITIALIZATION_ERROR); - BIO_snprintf(rcode, sizeof rcode, "%-8d", ret); + BIO_snprintf(rcode, sizeof(rcode), "%-8d", ret); ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode); } diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index 01b8ce5e..d93bcd35 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -1,5 +1,5 @@ /* - * Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -46,12 +46,24 @@ void OPENSSL_cpuid_setup(void) if (!sscanf(env + off, "%lli", (long long *)&vec)) vec = strtoul(env + off, NULL, 0); # endif - if (off) - vec = OPENSSL_ia32_cpuid(OPENSSL_ia32cap_P) & ~vec; - else if (env[0] == ':') + if (off) { + IA32CAP mask = vec; + vec = OPENSSL_ia32_cpuid(OPENSSL_ia32cap_P) & ~mask; + if (mask & (1<<24)) { + /* + * User disables FXSR bit, mask even other capabilities + * that operate exclusively on XMM, so we don't have to + * double-check all the time. We mask PCLMULQDQ, AMD XOP, + * AES-NI and AVX. Formally speaking we don't have to + * do it in x86_64 case, but we can safely assume that + * x86_64 users won't actually flip this flag. + */ + vec &= ~((IA32CAP)(1<<1|1<<11|1<<25|1<<28) << 32); + } + } else if (env[0] == ':') { vec = OPENSSL_ia32_cpuid(OPENSSL_ia32cap_P); + } - OPENSSL_ia32cap_P[2] = 0; if ((env = strchr(env, ':'))) { unsigned int vecx; env++; @@ -61,9 +73,12 @@ void OPENSSL_cpuid_setup(void) OPENSSL_ia32cap_P[2] &= ~vecx; else OPENSSL_ia32cap_P[2] = vecx; + } else { + OPENSSL_ia32cap_P[2] = 0; } - } else + } else { vec = OPENSSL_ia32_cpuid(OPENSSL_ia32cap_P); + } /* * |(1<<10) sets a reserved bit to signal that variable @@ -84,7 +99,7 @@ void OPENSSL_cpuid_setup(void) } #endif -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) # include # include # ifdef __WATCOMC__ @@ -293,7 +308,7 @@ void OPENSSL_die(const char *message, const char *file, int line) { OPENSSL_showfatal("%s:%d: OpenSSL internal error: %s\n", file, line, message); -#if !defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) abort(); #else /* diff --git a/crypto/ct/ct_log.c b/crypto/ct/ct_log.c index 6db4c3eb..d442322e 100644 --- a/crypto/ct/ct_log.c +++ b/crypto/ct/ct_log.c @@ -198,6 +198,8 @@ int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file) char *enabled_logs; CTLOG_STORE_LOAD_CTX* load_ctx = ctlog_store_load_ctx_new(); + if (load_ctx == NULL) + return 0; load_ctx->log_store = store; load_ctx->conf = NCONF_new(NULL); if (load_ctx->conf == NULL) diff --git a/crypto/des/des_locl.h b/crypto/des/des_locl.h index 53881d41..1fe47688 100644 --- a/crypto/des/des_locl.h +++ b/crypto/des/des_locl.h @@ -41,13 +41,20 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \ + /* fall thru */ \ case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \ + /* fall thru */ \ case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \ - case 5: l2|=((DES_LONG)(*(--(c)))); \ + /* fall thru */ \ + case 5: l2|=((DES_LONG)(*(--(c)))); \ + /* fall thru */ \ case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \ + /* fall thru */ \ case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \ + /* fall thru */ \ case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \ - case 1: l1|=((DES_LONG)(*(--(c)))); \ + /* fall thru */ \ + case 1: l1|=((DES_LONG)(*(--(c)))); \ } \ } @@ -77,12 +84,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ } \ } diff --git a/crypto/des/ecb_enc.c b/crypto/des/ecb_enc.c index bd130c6e..32df4600 100644 --- a/crypto/des/ecb_enc.c +++ b/crypto/des/ecb_enc.c @@ -24,7 +24,7 @@ const char *DES_options(void) size = "int"; else size = "long"; - BIO_snprintf(buf, sizeof buf, "des(%s)", size); + BIO_snprintf(buf, sizeof(buf), "des(%s)", size); init = 0; } return (buf); diff --git a/crypto/des/fcrypt.c b/crypto/des/fcrypt.c index 5215ad3e..baede4fc 100644 --- a/crypto/des/fcrypt.c +++ b/crypto/des/fcrypt.c @@ -77,7 +77,7 @@ char *DES_crypt(const char *buf, const char *salt) /* Convert password to ASCII. */ OPENSSL_strlcpy(e_buf, buf, sizeof(e_buf)); - ebcdic2ascii(e_buf, e_buf, sizeof e_buf); + ebcdic2ascii(e_buf, e_buf, sizeof(e_buf)); /* Encrypt it (from/to ASCII); if it worked, convert back. */ ret = DES_fcrypt(e_buf, e_salt, buff); diff --git a/crypto/des/set_key.c b/crypto/des/set_key.c index 795d9549..dc88b8d0 100644 --- a/crypto/des/set_key.c +++ b/crypto/des/set_key.c @@ -319,7 +319,7 @@ void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule) register int i; #ifdef OPENBSD_DEV_CRYPTO - memcpy(schedule->key, key, sizeof schedule->key); + memcpy(schedule->key, key, sizeof(schedule->key)); schedule->session = NULL; #endif k = &schedule->ks->deslong[0]; diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 204e5a7a..fce9ff47 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -56,11 +56,23 @@ static DH_METHOD dh_ossl = { NULL }; +static const DH_METHOD *default_DH_method = &dh_ossl; + const DH_METHOD *DH_OpenSSL(void) { return &dh_ossl; } +void DH_set_default_method(const DH_METHOD *meth) +{ + default_DH_method = meth; +} + +const DH_METHOD *DH_get_default_method(void) +{ + return default_DH_method; +} + static int generate_key(DH *dh) { int ok = 0; diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c index adf17715..716f4a4b 100644 --- a/crypto/dh/dh_lib.c +++ b/crypto/dh/dh_lib.c @@ -13,20 +13,6 @@ #include "dh_locl.h" #include -static const DH_METHOD *default_DH_method = NULL; - -void DH_set_default_method(const DH_METHOD *meth) -{ - default_DH_method = meth; -} - -const DH_METHOD *DH_get_default_method(void) -{ - if (!default_DH_method) - default_DH_method = DH_OpenSSL(); - return default_DH_method; -} - int DH_set_method(DH *dh, const DH_METHOD *meth) { /* @@ -244,13 +230,6 @@ void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) { - /* If the field pub_key in dh is NULL, the corresponding input - * parameters MUST be non-NULL. The priv_key field may - * be left NULL. - */ - if (dh->pub_key == NULL && pub_key == NULL) - return 0; - if (pub_key != NULL) { BN_free(dh->pub_key); dh->pub_key = pub_key; diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index 7c0428d3..d4e4066c 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -82,6 +82,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) int penclen; ASN1_STRING *str = NULL; ASN1_INTEGER *pubint = NULL; + ASN1_OBJECT *aobj; dsa = pkey->pkey.dsa; if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { @@ -114,8 +115,11 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) goto err; } - if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), - ptype, str, penc, penclen)) + aobj = OBJ_nid2obj(EVP_PKEY_DSA); + if (aobj == NULL) + goto err; + + if (X509_PUBKEY_set0_param(pk, aobj, ptype, str, penc, penclen)) return 1; err: @@ -175,6 +179,7 @@ static int dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) goto dsaerr; } + BN_set_flags(dsa->priv_key, BN_FLG_CONSTTIME); if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR); goto dsaerr; diff --git a/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index 3efeab84..e58ad8d7 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -376,6 +376,8 @@ int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N, } else { p = BN_CTX_get(ctx); q = BN_CTX_get(ctx); + if (q == NULL) + goto err; } if (!BN_lshift(test, BN_value_one(), L - 1)) diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index 42324c70..9598846e 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -17,20 +17,6 @@ #include #include -static const DSA_METHOD *default_DSA_method = NULL; - -void DSA_set_default_method(const DSA_METHOD *meth) -{ - default_DSA_method = meth; -} - -const DSA_METHOD *DSA_get_default_method(void) -{ - if (!default_DSA_method) - default_DSA_method = DSA_OpenSSL(); - return default_DSA_method; -} - DSA *DSA_new(void) { return DSA_new_method(NULL); diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index f9f6a136..7f48cf2e 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -41,6 +41,18 @@ static DSA_METHOD openssl_dsa_meth = { NULL }; +static const DSA_METHOD *default_DSA_method = &openssl_dsa_meth; + +void DSA_set_default_method(const DSA_METHOD *meth) +{ + default_DSA_method = meth; +} + +const DSA_METHOD *DSA_get_default_method(void) +{ + return default_DSA_method; +} + const DSA_METHOD *DSA_OpenSSL(void) { return &openssl_dsa_meth; @@ -136,7 +148,9 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, { BN_CTX *ctx = NULL; BIGNUM *k, *kinv = NULL, *r = *rp; + BIGNUM *l, *m; int ret = 0; + int q_bits; if (!dsa->p || !dsa->q || !dsa->g) { DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS); @@ -144,7 +158,9 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, } k = BN_new(); - if (k == NULL) + l = BN_new(); + m = BN_new(); + if (k == NULL || l == NULL || m == NULL) goto err; if (ctx_in == NULL) { @@ -153,6 +169,13 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, } else ctx = ctx_in; + /* Preallocate space */ + q_bits = BN_num_bits(dsa->q); + if (!BN_set_bit(k, q_bits) + || !BN_set_bit(l, q_bits) + || !BN_set_bit(m, q_bits)) + goto err; + /* Get random k */ do { if (dgst != NULL) { @@ -179,17 +202,19 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, /* * We do not want timing information to leak the length of k, so we - * compute g^k using an equivalent exponent of fixed length. (This - * is a kludge that we need because the BN_mod_exp_mont() does not - * let us specify the desired timing behaviour.) + * compute G^k using an equivalent scalar of fixed bit-length. + * + * We unconditionally perform both of these additions to prevent a + * small timing information leakage. We then choose the sum that is + * one bit longer than the modulus. + * + * TODO: revisit the BN_copy aiming for a memory access agnostic + * conditional copy. */ - - if (!BN_add(k, k, dsa->q)) + if (!BN_add(l, k, dsa->q) + || !BN_add(m, l, dsa->q) + || !BN_copy(k, BN_num_bits(l) > q_bits ? l : m)) goto err; - if (BN_num_bits(k) <= BN_num_bits(dsa->q)) { - if (!BN_add(k, k, dsa->q)) - goto err; - } if ((dsa)->meth->bn_mod_exp != NULL) { if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx, @@ -217,6 +242,8 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, if (ctx != ctx_in) BN_CTX_free(ctx); BN_clear_free(k); + BN_clear_free(l); + BN_clear_free(m); return ret; } diff --git a/crypto/ec/asm/ecp_nistz256-x86_64.pl b/crypto/ec/asm/ecp_nistz256-x86_64.pl index 16b6639b..714e852a 100644 --- a/crypto/ec/asm/ecp_nistz256-x86_64.pl +++ b/crypto/ec/asm/ecp_nistz256-x86_64.pl @@ -1185,19 +1185,18 @@ __ecp_nistz256_sqr_montx: adox $t1, $acc5 .byte 0x67,0x67 mulx %rdx, $t0, $t4 - mov $acc0, %rdx + mov .Lpoly+8*3(%rip), %rdx adox $t0, $acc6 shlx $a_ptr, $acc0, $t0 adox $t4, $acc7 shrx $a_ptr, $acc0, $t4 - mov .Lpoly+8*3(%rip), $t1 + mov %rdx,$t1 # reduction step 1 add $t0, $acc1 adc $t4, $acc2 - mulx $t1, $t0, $acc0 - mov $acc1, %rdx + mulx $acc0, $t0, $acc0 adc $t0, $acc3 shlx $a_ptr, $acc1, $t0 adc \$0, $acc0 @@ -1207,8 +1206,7 @@ __ecp_nistz256_sqr_montx: add $t0, $acc2 adc $t4, $acc3 - mulx $t1, $t0, $acc1 - mov $acc2, %rdx + mulx $acc1, $t0, $acc1 adc $t0, $acc0 shlx $a_ptr, $acc2, $t0 adc \$0, $acc1 @@ -1218,8 +1216,7 @@ __ecp_nistz256_sqr_montx: add $t0, $acc3 adc $t4, $acc0 - mulx $t1, $t0, $acc2 - mov $acc3, %rdx + mulx $acc2, $t0, $acc2 adc $t0, $acc1 shlx $a_ptr, $acc3, $t0 adc \$0, $acc2 @@ -1229,12 +1226,12 @@ __ecp_nistz256_sqr_montx: add $t0, $acc0 adc $t4, $acc1 - mulx $t1, $t0, $acc3 + mulx $acc3, $t0, $acc3 adc $t0, $acc2 adc \$0, $acc3 - xor $t3, $t3 # cf=0 - adc $acc0, $acc4 # accumulate upper half + xor $t3, $t3 + add $acc0, $acc4 # accumulate upper half mov .Lpoly+8*1(%rip), $a_ptr adc $acc1, $acc5 mov $acc4, $acc0 @@ -1243,8 +1240,7 @@ __ecp_nistz256_sqr_montx: mov $acc5, $acc1 adc \$0, $t3 - xor %eax, %eax # cf=0 - sbb \$-1, $acc4 # .Lpoly[0] + sub \$-1, $acc4 # .Lpoly[0] mov $acc6, $acc2 sbb $a_ptr, $acc5 # .Lpoly[1] sbb \$0, $acc6 # .Lpoly[2] diff --git a/crypto/ec/curve25519.c b/crypto/ec/curve25519.c index e535823c..c8aa9aa6 100644 --- a/crypto/ec/curve25519.c +++ b/crypto/ec/curve25519.c @@ -3226,6 +3226,8 @@ static void ge_scalarmult_base(ge_p3 *h, const uint8_t *a) { ge_madd(&r, h, &t); ge_p1p1_to_p3(h, &r); } + + OPENSSL_cleanse(e, sizeof(e)); } /* Replace (f,g) with (g,f) if b == 1; @@ -3356,6 +3358,8 @@ static void x25519_scalar_mult_generic(uint8_t out[32], fe_invert(z2, z2); fe_mul(x2, x2, z2); fe_tobytes(out, x2); + + OPENSSL_cleanse(e, sizeof(e)); } static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32], @@ -3391,4 +3395,6 @@ void X25519_public_from_private(uint8_t out_public_value[32], fe_invert(zminusy_inv, zminusy); fe_mul(zplusy, zplusy, zminusy_inv); fe_tobytes(out_public_value, zplusy); + + OPENSSL_cleanse(e, sizeof(e)); } diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c index fa5bd031..b66adf2b 100644 --- a/crypto/ec/ec_ameth.c +++ b/crypto/ec/ec_ameth.c @@ -298,17 +298,21 @@ static int ec_missing_parameters(const EVP_PKEY *pkey) static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) { EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec)); + if (group == NULL) return 0; if (to->pkey.ec == NULL) { to->pkey.ec = EC_KEY_new(); if (to->pkey.ec == NULL) - return 0; + goto err; } if (EC_KEY_set_group(to->pkey.ec, group) == 0) - return 0; + goto err; EC_GROUP_free(group); return 1; + err: + EC_GROUP_free(group); + return 0; } static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c index eb469ba3..5e5d1ae1 100644 --- a/crypto/ec/ec_kmeth.c +++ b/crypto/ec/ec_kmeth.c @@ -236,7 +236,7 @@ void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, meth->verify_sig = verify_sig; } -void EC_KEY_METHOD_get_init(EC_KEY_METHOD *meth, +void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, int (**pinit)(EC_KEY *key), void (**pfinish)(EC_KEY *key), int (**pcopy)(EC_KEY *dest, const EC_KEY *src), @@ -261,14 +261,14 @@ void EC_KEY_METHOD_get_init(EC_KEY_METHOD *meth, *pset_public = meth->set_public; } -void EC_KEY_METHOD_get_keygen(EC_KEY_METHOD *meth, +void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, int (**pkeygen)(EC_KEY *key)) { if (pkeygen != NULL) *pkeygen = meth->keygen; } -void EC_KEY_METHOD_get_compute_key(EC_KEY_METHOD *meth, +void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, int (**pck)(unsigned char **pout, size_t *poutlen, const EC_POINT *pub_key, @@ -278,7 +278,7 @@ void EC_KEY_METHOD_get_compute_key(EC_KEY_METHOD *meth, *pck = meth->compute_key; } -void EC_KEY_METHOD_get_sign(EC_KEY_METHOD *meth, +void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, int (**psign)(int type, const unsigned char *dgst, int dlen, unsigned char *sig, unsigned int *siglen, @@ -300,7 +300,7 @@ void EC_KEY_METHOD_get_sign(EC_KEY_METHOD *meth, *psign_sig = meth->sign_sig; } -void EC_KEY_METHOD_get_verify(EC_KEY_METHOD *meth, +void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, int (**pverify)(int type, const unsigned char *dgst, int dgst_len, const unsigned char *sigbuf, diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c index 03604623..b39777fb 100644 --- a/crypto/ec/ec_mult.c +++ b/crypto/ec/ec_mult.c @@ -222,11 +222,11 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, totalnum = num + numblocks; - wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]); - wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]); - wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]); /* includes space - * for pivot */ - val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]); + wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0])); + wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0])); + /* include space for pivot */ + wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0])); + val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0])); /* Ensure wNAF is initialised in case we end up going to err */ if (wNAF != NULL) @@ -372,7 +372,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, * 'val_sub[i]' is a pointer to the subarray for the i-th point, or to a * subarray of 'pre_comp->points' if we already have precomputation. */ - val = OPENSSL_malloc((num_val + 1) * sizeof val[0]); + val = OPENSSL_malloc((num_val + 1) * sizeof(val[0])); if (val == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; diff --git a/crypto/ec/ecdh_ossl.c b/crypto/ec/ecdh_ossl.c index caf65de8..a8651459 100644 --- a/crypto/ec/ecdh_ossl.c +++ b/crypto/ec/ecdh_ossl.c @@ -66,6 +66,10 @@ int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen, BN_CTX_start(ctx); x = BN_CTX_get(ctx); y = BN_CTX_get(ctx); + if (y == NULL) { + ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); + goto err; + } priv_key = EC_KEY_get0_private_key(ecdh); if (priv_key == NULL) { diff --git a/crypto/ec/ecdsa_ossl.c b/crypto/ec/ecdsa_ossl.c index d67c4852..72e2f0f2 100644 --- a/crypto/ec/ecdsa_ossl.c +++ b/crypto/ec/ecdsa_ossl.c @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2002-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -41,6 +41,7 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, EC_POINT *tmp_point = NULL; const EC_GROUP *group; int ret = 0; + int order_bits; if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) { ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER); @@ -77,6 +78,13 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, goto err; } + /* Preallocate space */ + order_bits = BN_num_bits(order); + if (!BN_set_bit(k, order_bits) + || !BN_set_bit(r, order_bits) + || !BN_set_bit(X, order_bits)) + goto err; + do { /* get random k */ do @@ -100,13 +108,19 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, /* * We do not want timing information to leak the length of k, so we * compute G*k using an equivalent scalar of fixed bit-length. + * + * We unconditionally perform both of these additions to prevent a + * small timing information leakage. We then choose the sum that is + * one bit longer than the order. This guarantees the code + * path used in the constant time implementations elsewhere. + * + * TODO: revisit the BN_copy aiming for a memory access agnostic + * conditional copy. */ - - if (!BN_add(k, k, order)) + if (!BN_add(r, k, order) + || !BN_add(X, r, order) + || !BN_copy(k, BN_num_bits(r) > order_bits ? r : X)) goto err; - if (BN_num_bits(k) <= BN_num_bits(order)) - if (!BN_add(k, k, order)) - goto err; /* compute r the x-coordinate of generator * k */ if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) { diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c index 0c11abc0..0cd994fc 100644 --- a/crypto/ec/ecp_nistp224.c +++ b/crypto/ec/ecp_nistp224.c @@ -50,7 +50,6 @@ typedef __uint128_t uint128_t; /* nonstandard; implemented by gcc on 64-bit typedef uint8_t u8; typedef uint64_t u64; -typedef int64_t s64; /******************************************************************************/ /*- @@ -337,7 +336,7 @@ static int BN_to_felem(felem out, const BIGNUM *bn) /* BN_bn2bin eats leading zeroes */ memset(b_out, 0, sizeof(b_out)); num_bytes = BN_num_bytes(bn); - if (num_bytes > sizeof b_out) { + if (num_bytes > sizeof(b_out)) { ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); return 0; } @@ -356,8 +355,8 @@ static BIGNUM *felem_to_BN(BIGNUM *out, const felem in) { felem_bytearray b_in, b_out; felem_to_bin28(b_in, in); - flip_endian(b_out, b_in, sizeof b_out); - return BN_bin2bn(b_out, sizeof b_out, out); + flip_endian(b_out, b_in, sizeof(b_out)); + return BN_bin2bn(b_out, sizeof(b_out), out); } /******************************************************************************/ @@ -700,7 +699,7 @@ static limb felem_is_zero(const felem in) return (zero | two224m96p1 | two225m97p2); } -static limb felem_is_zero_int(const felem in) +static int felem_is_zero_int(const void *in) { return (int)(felem_is_zero(in) & ((limb) 1)); } @@ -1365,7 +1364,6 @@ static void make_points_affine(size_t num, felem points[ /* num */ ][3], sizeof(felem), tmp_felems, (void (*)(void *))felem_one, - (int (*)(const void *)) felem_is_zero_int, (void (*)(void *, const void *)) felem_assign, diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c index 8cd72228..ffd2a7d9 100644 --- a/crypto/ec/ecp_nistp256.c +++ b/crypto/ec/ecp_nistp256.c @@ -53,7 +53,6 @@ typedef __int128_t int128_t; typedef uint8_t u8; typedef uint32_t u32; typedef uint64_t u64; -typedef int64_t s64; /* * The underlying field. P256 operates over GF(2^256-2^224+2^192+2^96-1). We @@ -165,7 +164,7 @@ static int BN_to_felem(felem out, const BIGNUM *bn) /* BN_bn2bin eats leading zeroes */ memset(b_out, 0, sizeof(b_out)); num_bytes = BN_num_bytes(bn); - if (num_bytes > sizeof b_out) { + if (num_bytes > sizeof(b_out)) { ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); return 0; } @@ -184,8 +183,8 @@ static BIGNUM *smallfelem_to_BN(BIGNUM *out, const smallfelem in) { felem_bytearray b_in, b_out; smallfelem_to_bin32(b_in, in); - flip_endian(b_out, b_in, sizeof b_out); - return BN_bin2bn(b_out, sizeof b_out, out); + flip_endian(b_out, b_in, sizeof(b_out)); + return BN_bin2bn(b_out, sizeof(b_out), out); } /*- @@ -394,7 +393,7 @@ static void felem_shrink(smallfelem out, const felem in) { felem tmp; u64 a, b, mask; - s64 high, low; + u64 high, low; static const u64 kPrime3Test = 0x7fffffff00000001ul; /* 2^63 - 2^32 + 1 */ /* Carry 2->3 */ @@ -435,29 +434,31 @@ static void felem_shrink(smallfelem out, const felem in) * In order to make space in tmp[3] for the carry from 2 -> 3, we * conditionally subtract kPrime if tmp[3] is large enough. */ - high = tmp[3] >> 64; + high = (u64)(tmp[3] >> 64); /* As tmp[3] < 2^65, high is either 1 or 0 */ - high <<= 63; - high >>= 63; + high = 0 - high; /*- * high is: * all ones if the high word of tmp[3] is 1 - * all zeros if the high word of tmp[3] if 0 */ - low = tmp[3]; - mask = low >> 63; + * all zeros if the high word of tmp[3] if 0 + */ + low = (u64)tmp[3]; + mask = 0 - (low >> 63); /*- * mask is: * all ones if the MSB of low is 1 - * all zeros if the MSB of low if 0 */ + * all zeros if the MSB of low if 0 + */ low &= bottom63bits; low -= kPrime3Test; /* if low was greater than kPrime3Test then the MSB is zero */ low = ~low; - low >>= 63; + low = 0 - (low >> 63); /*- * low is: * all ones if low was > kPrime3Test - * all zeros if low was <= kPrime3Test */ + * all zeros if low was <= kPrime3Test + */ mask = (mask & low) | high; tmp[0] -= mask & kPrime[0]; tmp[1] -= mask & kPrime[1]; @@ -891,7 +892,7 @@ static void felem_contract(smallfelem out, const felem in) equal &= equal << 4; equal &= equal << 2; equal &= equal << 1; - equal = ((s64) equal) >> 63; + equal = 0 - (equal >> 63); all_equal_so_far &= equal; } @@ -958,7 +959,7 @@ static limb smallfelem_is_zero(const smallfelem small) is_zero &= is_zero << 4; is_zero &= is_zero << 2; is_zero &= is_zero << 1; - is_zero = ((s64) is_zero) >> 63; + is_zero = 0 - (is_zero >> 63); is_p = (small[0] ^ kPrime[0]) | (small[1] ^ kPrime[1]) | @@ -970,7 +971,7 @@ static limb smallfelem_is_zero(const smallfelem small) is_p &= is_p << 4; is_p &= is_p << 2; is_p &= is_p << 1; - is_p = ((s64) is_p) >> 63; + is_p = 0 - (is_p >> 63); is_zero |= is_p; @@ -979,7 +980,7 @@ static limb smallfelem_is_zero(const smallfelem small) return result; } -static int smallfelem_is_zero_int(const smallfelem small) +static int smallfelem_is_zero_int(const void *small) { return (int)(smallfelem_is_zero(small) & ((limb) 1)); } @@ -1983,7 +1984,6 @@ static void make_points_affine(size_t num, smallfelem points[][3], sizeof(smallfelem), tmp_smallfelems, (void (*)(void *))smallfelem_one, - (int (*)(const void *)) smallfelem_is_zero_int, (void (*)(void *, const void *)) smallfelem_assign, diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c index 4701d5d5..133f089f 100644 --- a/crypto/ec/ecp_nistp521.c +++ b/crypto/ec/ecp_nistp521.c @@ -50,7 +50,6 @@ typedef __uint128_t uint128_t; /* nonstandard; implemented by gcc on 64-bit typedef uint8_t u8; typedef uint64_t u64; -typedef int64_t s64; /* * The underlying field. P521 operates over GF(2^521-1). We can serialise an @@ -188,7 +187,7 @@ static int BN_to_felem(felem out, const BIGNUM *bn) /* BN_bn2bin eats leading zeroes */ memset(b_out, 0, sizeof(b_out)); num_bytes = BN_num_bytes(bn); - if (num_bytes > sizeof b_out) { + if (num_bytes > sizeof(b_out)) { ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); return 0; } @@ -207,8 +206,8 @@ static BIGNUM *felem_to_BN(BIGNUM *out, const felem in) { felem_bytearray b_in, b_out; felem_to_bin66(b_in, in); - flip_endian(b_out, b_in, sizeof b_out); - return BN_bin2bn(b_out, sizeof b_out, out); + flip_endian(b_out, b_in, sizeof(b_out)); + return BN_bin2bn(b_out, sizeof(b_out), out); } /*- @@ -867,7 +866,7 @@ static limb felem_is_zero(const felem in) * We know that ftmp[i] < 2^63, therefore the only way that the top bit * can be set is if is_zero was 0 before the decrement. */ - is_zero = ((s64) is_zero) >> 63; + is_zero = 0 - (is_zero >> 63); is_p = ftmp[0] ^ kPrime[0]; is_p |= ftmp[1] ^ kPrime[1]; @@ -880,13 +879,13 @@ static limb felem_is_zero(const felem in) is_p |= ftmp[8] ^ kPrime[8]; is_p--; - is_p = ((s64) is_p) >> 63; + is_p = 0 - (is_p >> 63); is_zero |= is_p; return is_zero; } -static int felem_is_zero_int(const felem in) +static int felem_is_zero_int(const void *in) { return (int)(felem_is_zero(in) & ((limb) 1)); } @@ -951,7 +950,7 @@ static void felem_contract(felem out, const felem in) is_p &= is_p << 4; is_p &= is_p << 2; is_p &= is_p << 1; - is_p = ((s64) is_p) >> 63; + is_p = 0 - (is_p >> 63); is_p = ~is_p; /* is_p is 0 iff |out| == 2^521-1 and all ones otherwise */ @@ -977,7 +976,7 @@ static void felem_contract(felem out, const felem in) is_greater |= is_greater << 4; is_greater |= is_greater << 2; is_greater |= is_greater << 1; - is_greater = ((s64) is_greater) >> 63; + is_greater = 0 - (is_greater >> 63); out[0] -= kPrime[0] & is_greater; out[1] -= kPrime[1] & is_greater; @@ -1805,7 +1804,6 @@ static void make_points_affine(size_t num, felem points[][3], sizeof(felem), tmp_felems, (void (*)(void *))felem_one, - (int (*)(const void *)) felem_is_zero_int, (void (*)(void *, const void *)) felem_assign, diff --git a/crypto/ec/ecp_nistz256.c b/crypto/ec/ecp_nistz256.c index dca3a2dd..24618983 100644 --- a/crypto/ec/ecp_nistz256.c +++ b/crypto/ec/ecp_nistz256.c @@ -757,12 +757,12 @@ __owur static int ecp_nistz256_windowed_mul(const EC_GROUP *group, } /* Coordinates of G, for which we have precomputed tables */ -const static BN_ULONG def_xG[P256_LIMBS] = { +static const BN_ULONG def_xG[P256_LIMBS] = { TOBN(0x79e730d4, 0x18a9143c), TOBN(0x75ba95fc, 0x5fedb601), TOBN(0x79fb732b, 0x77622510), TOBN(0x18905f76, 0xa53755c6) }; -const static BN_ULONG def_yG[P256_LIMBS] = { +static const BN_ULONG def_yG[P256_LIMBS] = { TOBN(0xddf25357, 0xce95560a), TOBN(0x8b4ab8e4, 0xba19e45c), TOBN(0xd2e88688, 0xdd21f325), TOBN(0x8571ff18, 0x25885d85) }; diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c index 76e0caf9..abd37950 100644 --- a/crypto/ec/ecp_smpl.c +++ b/crypto/ec/ecp_smpl.c @@ -1221,7 +1221,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, if (tmp == NULL || tmp_Z == NULL) goto err; - prod_Z = OPENSSL_malloc(num * sizeof prod_Z[0]); + prod_Z = OPENSSL_malloc(num * sizeof(prod_Z[0])); if (prod_Z == NULL) goto err; for (i = 0; i < num; i++) { diff --git a/crypto/ec/ecx_meth.c b/crypto/ec/ecx_meth.c index 06e39113..018a9419 100644 --- a/crypto/ec/ecx_meth.c +++ b/crypto/ec/ecx_meth.c @@ -212,7 +212,7 @@ static void ecx_free(EVP_PKEY *pkey) X25519_KEY *xkey = pkey->pkey.ptr; if (xkey) - OPENSSL_secure_free(xkey->privkey); + OPENSSL_secure_clear_free(xkey->privkey, X25519_KEYLEN); OPENSSL_free(xkey); } diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c index d63c918c..55727350 100644 --- a/crypto/engine/eng_cryptodev.c +++ b/crypto/engine/eng_cryptodev.c @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -44,10 +44,13 @@ #if (defined(__unix__) || defined(unix)) && !defined(USG) && \ (defined(OpenBSD) || defined(__FreeBSD__)) # include -# if (OpenBSD >= 200112) || ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || __FreeBSD_version >= 500041) +# if (defined(OpenBSD) && (OpenBSD >= 200112)) || \ + (defined(__FreeBSD_version) && \ + ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || \ + __FreeBSD_version >= 500041)) # define HAVE_CRYPTODEV # endif -# if (OpenBSD >= 200110) +# if defined(OpenBSD) && (OpenBSD >= 200110) # define HAVE_SYSLOG_R # endif #endif diff --git a/crypto/engine/eng_fat.c b/crypto/engine/eng_fat.c index 631aa396..5cb81874 100644 --- a/crypto/engine/eng_fat.c +++ b/crypto/engine/eng_fat.c @@ -113,6 +113,7 @@ int ENGINE_register_complete(ENGINE *e) #endif ENGINE_register_RAND(e); ENGINE_register_pkey_meths(e); + ENGINE_register_pkey_asn1_meths(e); return 1; } diff --git a/crypto/engine/eng_table.c b/crypto/engine/eng_table.c index 219253a3..ac4b02fc 100644 --- a/crypto/engine/eng_table.c +++ b/crypto/engine/eng_table.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -109,6 +109,11 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, } fnd->funct = NULL; (void)lh_ENGINE_PILE_insert(&(*table)->piles, fnd); + if (lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate) != fnd) { + sk_ENGINE_free(fnd->sk); + OPENSSL_free(fnd); + goto end; + } } /* A registration shouldn't add duplicate entries */ (void)sk_ENGINE_delete_ptr(fnd->sk, e); diff --git a/crypto/err/err.c b/crypto/err/err.c index f866f2fd..c4399285 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -122,6 +122,7 @@ static ERR_STRING_DATA ERR_str_reasons[] = { #endif static CRYPTO_ONCE err_init = CRYPTO_ONCE_STATIC_INIT; +static int set_err_thread_local; static CRYPTO_THREAD_LOCAL err_thread_local; static CRYPTO_ONCE err_string_init = CRYPTO_ONCE_STATIC_INIT; @@ -260,7 +261,8 @@ DEFINE_RUN_ONCE_STATIC(do_err_strings_init) void err_cleanup(void) { - CRYPTO_THREAD_cleanup_local(&err_thread_local); + if (set_err_thread_local != 0) + CRYPTO_THREAD_cleanup_local(&err_thread_local); CRYPTO_THREAD_lock_free(err_string_lock); err_string_lock = NULL; } @@ -359,6 +361,8 @@ void ERR_put_error(int lib, int func, int reason, const char *file, int line) } #endif es = ERR_get_state(); + if (es == NULL) + return; es->top = (es->top + 1) % ERR_NUM_ERRORS; if (es->top == es->bottom) @@ -376,6 +380,8 @@ void ERR_clear_error(void) ERR_STATE *es; es = ERR_get_state(); + if (es == NULL) + return; for (i = 0; i < ERR_NUM_ERRORS; i++) { err_clear(es, i); @@ -440,6 +446,8 @@ static unsigned long get_error_values(int inc, int top, const char **file, unsigned long ret; es = ERR_get_state(); + if (es == NULL) + return 0; if (inc && top) { if (file) @@ -617,7 +625,7 @@ const char *ERR_reason_error_string(unsigned long e) void err_delete_thread_state(void) { - ERR_STATE *state = ERR_get_state(); + ERR_STATE *state = CRYPTO_THREAD_get_local(&err_thread_local); if (state == NULL) return; @@ -639,6 +647,7 @@ void ERR_remove_state(unsigned long pid) DEFINE_RUN_ONCE_STATIC(err_do_init) { + set_err_thread_local = 1; return CRYPTO_THREAD_init_local(&err_thread_local, NULL); } @@ -649,6 +658,14 @@ ERR_STATE *ERR_get_state(void) if (!RUN_ONCE(&err_init, err_do_init)) return NULL; + /* + * If base OPENSSL_init_crypto() hasn't been called yet, be sure to call + * it now to avoid state to be doubly allocated and thereby leak memory. + * Needed on any platform that doesn't define OPENSSL_USE_NODELETE. + */ + if (!OPENSSL_init_crypto(0, NULL)) + return NULL; + state = CRYPTO_THREAD_get_local(&err_thread_local); if (state == NULL) { @@ -656,14 +673,14 @@ ERR_STATE *ERR_get_state(void) if (state == NULL) return NULL; - if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) { + if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE) + || !CRYPTO_THREAD_set_local(&err_thread_local, state)) { ERR_STATE_free(state); return NULL; } /* Ignore failures from these */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); - ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE); } return state; @@ -689,10 +706,10 @@ void ERR_set_error_data(char *data, int flags) int i; es = ERR_get_state(); + if (es == NULL) + return; i = es->top; - if (i == 0) - i = ERR_NUM_ERRORS - 1; err_clear_data(es, i); es->err_data[i] = data; @@ -744,6 +761,8 @@ int ERR_set_mark(void) ERR_STATE *es; es = ERR_get_state(); + if (es == NULL) + return 0; if (es->bottom == es->top) return 0; @@ -756,6 +775,8 @@ int ERR_pop_to_mark(void) ERR_STATE *es; es = ERR_get_state(); + if (es == NULL) + return 0; while (es->bottom != es->top && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) { diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c index c7dc1d15..6ae12515 100644 --- a/crypto/err/err_prn.c +++ b/crypto/err/err_prn.c @@ -35,7 +35,7 @@ void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), tid.tid = CRYPTO_THREAD_get_current_id(); while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { - ERR_error_string_n(l, buf, sizeof buf); + ERR_error_string_n(l, buf, sizeof(buf)); BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf, file, line, (flags & ERR_TXT_STRING) ? data : ""); if (cb(buf2, strlen(buf2), u) <= 0) diff --git a/crypto/evp/bio_b64.c b/crypto/evp/bio_b64.c index 32a884a7..a86e8db0 100644 --- a/crypto/evp/bio_b64.c +++ b/crypto/evp/bio_b64.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,7 +23,7 @@ static int b64_puts(BIO *h, const char *str); static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int b64_new(BIO *h); static int b64_free(BIO *data); -static long b64_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long b64_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); #define B64_BLOCK_SIZE 1024 #define B64_BLOCK_SIZE2 768 #define B64_NONE 0 @@ -47,7 +47,8 @@ typedef struct b64_struct { } BIO_B64_CTX; static const BIO_METHOD methods_b64 = { - BIO_TYPE_BASE64, "base64 encoding", + BIO_TYPE_BASE64, + "base64 encoding", b64_write, b64_read, b64_puts, @@ -287,6 +288,14 @@ static int b64_read(BIO *b, char *out, int outl) (unsigned char *)ctx->tmp, i); ctx->tmp_len = 0; } + /* + * If eof or an error was signalled, then the condition + * 'ctx->cont <= 0' will prevent b64_read() from reading + * more data on subsequent calls. This assignment was + * deleted accidentally in commit 5562cfaca4f3. + */ + ctx->cont = i; + ctx->buf_off = 0; if (i < 0) { ret_code = 0; @@ -521,7 +530,7 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr) return ret; } -static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long b64_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; BIO *next = BIO_next(b); diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c index 5a3beef9..e62d1dfd 100644 --- a/crypto/evp/bio_enc.c +++ b/crypto/evp/bio_enc.c @@ -25,7 +25,7 @@ static int enc_read(BIO *h, char *buf, int size); static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int enc_new(BIO *h); static int enc_free(BIO *data); -static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps); +static long enc_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fps); #define ENC_BLOCK_SIZE (1024*4) #define ENC_MIN_CHUNK (256) #define BUF_OFFSET (ENC_MIN_CHUNK + EVP_MAX_BLOCK_LENGTH) @@ -46,7 +46,8 @@ typedef struct enc_struct { } BIO_ENC_CTX; static const BIO_METHOD methods_enc = { - BIO_TYPE_CIPHER, "cipher", + BIO_TYPE_CIPHER, + "cipher", enc_write, enc_read, NULL, /* enc_puts, */ @@ -386,7 +387,7 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) return (ret); } -static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long enc_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; BIO *next = BIO_next(b); diff --git a/crypto/evp/bio_md.c b/crypto/evp/bio_md.c index cd968ec2..2f0f2831 100644 --- a/crypto/evp/bio_md.c +++ b/crypto/evp/bio_md.c @@ -29,10 +29,11 @@ static int md_gets(BIO *h, char *str, int size); static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int md_new(BIO *h); static int md_free(BIO *data); -static long md_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long md_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); static const BIO_METHOD methods_md = { - BIO_TYPE_MD, "message digest", + BIO_TYPE_MD, + "message digest", md_write, md_read, NULL, /* md_puts, */ @@ -196,7 +197,7 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr) return (ret); } -static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long md_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; BIO *next; diff --git a/crypto/evp/bio_ok.c b/crypto/evp/bio_ok.c index 7974b963..b156e62e 100644 --- a/crypto/evp/bio_ok.c +++ b/crypto/evp/bio_ok.c @@ -83,7 +83,7 @@ static int ok_read(BIO *h, char *buf, int size); static long ok_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int ok_new(BIO *h); static int ok_free(BIO *data); -static long ok_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); +static long ok_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); static __owur int sig_out(BIO *b); static __owur int sig_in(BIO *b); @@ -108,7 +108,8 @@ typedef struct ok_struct { } BIO_OK_CTX; static const BIO_METHOD methods_ok = { - BIO_TYPE_CIPHER, "reliable", + BIO_TYPE_CIPHER, + "reliable", ok_write, ok_read, NULL, /* ok_puts, */ @@ -398,7 +399,7 @@ static long ok_ctrl(BIO *b, int cmd, long num, void *ptr) return ret; } -static long ok_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) +static long ok_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) { long ret = 1; BIO *next; diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index 17822f20..3f36d707 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -1229,6 +1229,8 @@ static int aes_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, EVP_CIPHER_CTX_encrypting(ctx), dat->block); EVP_CIPHER_CTX_set_num(ctx, num); len -= MAXBITCHUNK; + out += MAXBITCHUNK; + in += MAXBITCHUNK; } if (len) { int num = EVP_CIPHER_CTX_num(ctx); @@ -1978,6 +1980,7 @@ static int aes_ccm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) case EVP_CTRL_AEAD_SET_IVLEN: arg = 15 - arg; + /* fall thru */ case EVP_CTRL_CCM_SET_L: if (arg < 2 || arg > 8) return 0; diff --git a/crypto/evp/e_aes_cbc_hmac_sha1.c b/crypto/evp/e_aes_cbc_hmac_sha1.c index 8e71e591..f30f722e 100644 --- a/crypto/evp/e_aes_cbc_hmac_sha1.c +++ b/crypto/evp/e_aes_cbc_hmac_sha1.c @@ -528,12 +528,17 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8); maxpad &= 255; - ret &= constant_time_ge(maxpad, pad); + mask = constant_time_ge(maxpad, pad); + ret &= mask; + /* + * If pad is invalid then we will fail the above test but we must + * continue anyway because we are in constant time code. However, + * we'll use the maxpad value instead of the supplied pad to make + * sure we perform well defined pointer arithmetic. + */ + pad = constant_time_select(mask, pad, maxpad); inp_len = len - (SHA_DIGEST_LENGTH + pad + 1); - mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1))); - inp_len &= mask; - ret &= (int)mask; key->aux.tls_aad[plen - 2] = inp_len >> 8; key->aux.tls_aad[plen - 1] = inp_len; diff --git a/crypto/evp/e_aes_cbc_hmac_sha256.c b/crypto/evp/e_aes_cbc_hmac_sha256.c index f0be05ca..13973f11 100644 --- a/crypto/evp/e_aes_cbc_hmac_sha256.c +++ b/crypto/evp/e_aes_cbc_hmac_sha256.c @@ -453,10 +453,12 @@ static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx, * to identify it and avoid stitch invocation. So that after we * establish that current CPU supports AVX, we even see if it's * either even XOP-capable Bulldozer-based or GenuineIntel one. + * But SHAEXT-capable go ahead... */ - if (OPENSSL_ia32cap_P[1] & (1 << (60 - 32)) && /* AVX? */ - ((OPENSSL_ia32cap_P[1] & (1 << (43 - 32))) /* XOP? */ - | (OPENSSL_ia32cap_P[0] & (1<<30))) && /* "Intel CPU"? */ + if (((OPENSSL_ia32cap_P[2] & (1 << 29)) || /* SHAEXT? */ + ((OPENSSL_ia32cap_P[1] & (1 << (60 - 32))) && /* AVX? */ + ((OPENSSL_ia32cap_P[1] & (1 << (43 - 32))) /* XOP? */ + | (OPENSSL_ia32cap_P[0] & (1 << 30))))) && /* "Intel CPU"? */ plen > (sha_off + iv) && (blocks = (plen - (sha_off + iv)) / SHA256_CBLOCK)) { SHA256_Update(&key->md, in + iv, sha_off); @@ -538,12 +540,17 @@ static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx, maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8); maxpad &= 255; - ret &= constant_time_ge(maxpad, pad); + mask = constant_time_ge(maxpad, pad); + ret &= mask; + /* + * If pad is invalid then we will fail the above test but we must + * continue anyway because we are in constant time code. However, + * we'll use the maxpad value instead of the supplied pad to make + * sure we perform well defined pointer arithmetic. + */ + pad = constant_time_select(mask, pad, maxpad); inp_len = len - (SHA256_DIGEST_LENGTH + pad + 1); - mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1))); - inp_len &= mask; - ret &= (int)mask; key->aux.tls_aad[plen - 2] = inp_len >> 8; key->aux.tls_aad[plen - 1] = inp_len; diff --git a/crypto/evp/e_camellia.c b/crypto/evp/e_camellia.c index b50fa0b9..2df4a6e3 100644 --- a/crypto/evp/e_camellia.c +++ b/crypto/evp/e_camellia.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -325,8 +325,10 @@ static int camellia_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, int num = EVP_CIPHER_CTX_num(ctx); CRYPTO_cfb128_1_encrypt(in, out, MAXBITCHUNK * 8, &dat->ks, EVP_CIPHER_CTX_iv_noconst(ctx), &num, EVP_CIPHER_CTX_encrypting(ctx), dat->block); - len -= MAXBITCHUNK; EVP_CIPHER_CTX_set_num(ctx, num); + len -= MAXBITCHUNK; + out += MAXBITCHUNK; + in += MAXBITCHUNK; } if (len) { int num = EVP_CIPHER_CTX_num(ctx); diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index f829e8dc..e5807edd 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -50,7 +50,8 @@ void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int enc) { - EVP_CIPHER_CTX_reset(ctx); + if (cipher != NULL) + EVP_CIPHER_CTX_reset(ctx); return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); } @@ -391,7 +392,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) } b = ctx->cipher->block_size; - OPENSSL_assert(b <= sizeof ctx->buf); + OPENSSL_assert(b <= sizeof(ctx->buf)); if (b == 1) { *outl = 0; return 1; @@ -452,7 +453,7 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, if (ctx->flags & EVP_CIPH_NO_PADDING) return EVP_EncryptUpdate(ctx, out, outl, in, inl); - OPENSSL_assert(b <= sizeof ctx->final); + OPENSSL_assert(b <= sizeof(ctx->final)); if (ctx->final_used) { /* see comment about PTRDIFF_T comparison above */ @@ -524,7 +525,7 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_WRONG_FINAL_BLOCK_LENGTH); return (0); } - OPENSSL_assert(b <= sizeof ctx->final); + OPENSSL_assert(b <= sizeof(ctx->final)); /* * The following assumes that the ciphertext has been authenticated. diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index e32a1c01..c4b163f0 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -49,6 +49,7 @@ static ERR_STRING_DATA EVP_str_functs[] = { {ERR_FUNC(EVP_F_EVP_PBE_SCRYPT), "EVP_PBE_scrypt"}, {ERR_FUNC(EVP_F_EVP_PKCS82PKEY), "EVP_PKCS82PKEY"}, {ERR_FUNC(EVP_F_EVP_PKEY2PKCS8), "EVP_PKEY2PKCS8"}, + {ERR_FUNC(EVP_F_EVP_PKEY_ASN1_ADD0), "EVP_PKEY_asn1_add0"}, {ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS), "EVP_PKEY_copy_parameters"}, {ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL), "EVP_PKEY_CTX_ctrl"}, {ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL_STR), "EVP_PKEY_CTX_ctrl_str"}, @@ -72,6 +73,7 @@ static ERR_STRING_DATA EVP_str_functs[] = { {ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"}, {ERR_FUNC(EVP_F_EVP_PKEY_PARAMGEN), "EVP_PKEY_paramgen"}, {ERR_FUNC(EVP_F_EVP_PKEY_PARAMGEN_INIT), "EVP_PKEY_paramgen_init"}, + {ERR_FUNC(EVP_F_EVP_PKEY_SET1_ENGINE), "EVP_PKEY_set1_engine"}, {ERR_FUNC(EVP_F_EVP_PKEY_SIGN), "EVP_PKEY_sign"}, {ERR_FUNC(EVP_F_EVP_PKEY_SIGN_INIT), "EVP_PKEY_sign_init"}, {ERR_FUNC(EVP_F_EVP_PKEY_VERIFY), "EVP_PKEY_verify"}, @@ -141,6 +143,10 @@ static ERR_STRING_DATA EVP_str_reasons[] = { {ERR_REASON(EVP_R_OPERATON_NOT_INITIALIZED), "operaton not initialized"}, {ERR_REASON(EVP_R_PARTIALLY_OVERLAPPING), "partially overlapping buffers"}, + {ERR_REASON(EVP_R_PKEY_APPLICATION_ASN1_METHOD_ALREADY_REGISTERED), + "pkey application asn1 method already registered"}, + {ERR_REASON(EVP_R_PKEY_ASN1_METHOD_ALREADY_REGISTERED), + "pkey asn1 method already registered"}, {ERR_REASON(EVP_R_PRIVATE_KEY_DECODE_ERROR), "private key decode error"}, {ERR_REASON(EVP_R_PRIVATE_KEY_ENCODE_ERROR), "private key encode error"}, {ERR_REASON(EVP_R_PUBLIC_KEY_NOT_RSA), "public key not rsa"}, diff --git a/crypto/evp/evp_key.c b/crypto/evp/evp_key.c index 8a4297cf..52011307 100644 --- a/crypto/evp/evp_key.c +++ b/crypto/evp/evp_key.c @@ -49,7 +49,7 @@ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) int EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, int verify) { - int ret; + int ret = -1; char buff[BUFSIZ]; UI *ui; @@ -57,16 +57,18 @@ int EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, prompt = prompt_string; ui = UI_new(); if (ui == NULL) - return -1; - UI_add_input_string(ui, prompt, 0, buf, min, - (len >= BUFSIZ) ? BUFSIZ - 1 : len); - if (verify) - UI_add_verify_string(ui, prompt, 0, - buff, min, (len >= BUFSIZ) ? BUFSIZ - 1 : len, - buf); + return ret; + if (UI_add_input_string(ui, prompt, 0, buf, min, + (len >= BUFSIZ) ? BUFSIZ - 1 : len) < 0 + || (verify + && UI_add_verify_string(ui, prompt, 0, buff, min, + (len >= BUFSIZ) ? BUFSIZ - 1 : len, + buf) < 0)) + goto end; ret = UI_process(ui); - UI_free(ui); OPENSSL_cleanse(buff, BUFSIZ); + end: + UI_free(ui); return ret; } #endif /* OPENSSL_NO_UI */ diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c index ce7aa2cf..eb7344c2 100644 --- a/crypto/evp/evp_pbe.c +++ b/crypto/evp/evp_pbe.c @@ -90,9 +90,9 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, char obj_tmp[80]; EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_UNKNOWN_PBE_ALGORITHM); if (!pbe_obj) - OPENSSL_strlcpy(obj_tmp, "NULL", sizeof obj_tmp); + OPENSSL_strlcpy(obj_tmp, "NULL", sizeof(obj_tmp)); else - i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj); + i2t_ASN1_OBJECT(obj_tmp, sizeof(obj_tmp), pbe_obj); ERR_add_error_data(2, "TYPE=", obj_tmp); return 0; } diff --git a/crypto/evp/m_sha1.c b/crypto/evp/m_sha1.c index 8f30077a..e68f32a0 100644 --- a/crypto/evp/m_sha1.c +++ b/crypto/evp/m_sha1.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -115,16 +115,21 @@ static int init224(EVP_MD_CTX *ctx) return SHA224_Init(EVP_MD_CTX_md_data(ctx)); } +static int update224(EVP_MD_CTX *ctx, const void *data, size_t count) +{ + return SHA224_Update(EVP_MD_CTX_md_data(ctx), data, count); +} + +static int final224(EVP_MD_CTX *ctx, unsigned char *md) +{ + return SHA224_Final(md, EVP_MD_CTX_md_data(ctx)); +} + static int init256(EVP_MD_CTX *ctx) { return SHA256_Init(EVP_MD_CTX_md_data(ctx)); } -/* - * Even though there're separate SHA224_[Update|Final], we call - * SHA256 functions even in SHA224 context. This is what happens - * there anyway, so we can spare few CPU cycles:-) - */ static int update256(EVP_MD_CTX *ctx, const void *data, size_t count) { return SHA256_Update(EVP_MD_CTX_md_data(ctx), data, count); @@ -141,8 +146,8 @@ static const EVP_MD sha224_md = { SHA224_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, init224, - update256, - final256, + update224, + final224, NULL, NULL, SHA256_CBLOCK, @@ -178,6 +183,16 @@ static int init384(EVP_MD_CTX *ctx) return SHA384_Init(EVP_MD_CTX_md_data(ctx)); } +static int update384(EVP_MD_CTX *ctx, const void *data, size_t count) +{ + return SHA384_Update(EVP_MD_CTX_md_data(ctx), data, count); +} + +static int final384(EVP_MD_CTX *ctx, unsigned char *md) +{ + return SHA384_Final(md, EVP_MD_CTX_md_data(ctx)); +} + static int init512(EVP_MD_CTX *ctx) { return SHA512_Init(EVP_MD_CTX_md_data(ctx)); @@ -200,8 +215,8 @@ static const EVP_MD sha384_md = { SHA384_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, init384, - update512, - final512, + update384, + final384, NULL, NULL, SHA512_CBLOCK, diff --git a/crypto/evp/m_sigver.c b/crypto/evp/m_sigver.c index 3b74f722..582e563d 100644 --- a/crypto/evp/m_sigver.c +++ b/crypto/evp/m_sigver.c @@ -109,8 +109,12 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, r = EVP_DigestFinal_ex(ctx, md, &mdlen); } else { EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new(); - if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx)) + if (tmp_ctx == NULL) return 0; + if (!EVP_MD_CTX_copy_ex(tmp_ctx, ctx)) { + EVP_MD_CTX_free(tmp_ctx); + return 0; + } if (sctx) r = tmp_ctx->pctx->pmeth->signctx(tmp_ctx->pctx, sigret, siglen, tmp_ctx); @@ -154,8 +158,12 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, r = EVP_DigestFinal_ex(ctx, md, &mdlen); } else { EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new(); - if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx)) + if (tmp_ctx == NULL) return -1; + if (!EVP_MD_CTX_copy_ex(tmp_ctx, ctx)) { + EVP_MD_CTX_free(tmp_ctx); + return -1; + } if (vctx) { r = tmp_ctx->pctx->pmeth->verifyctx(tmp_ctx->pctx, sig, siglen, tmp_ctx); diff --git a/crypto/evp/p5_crpt2.c b/crypto/evp/p5_crpt2.c index 365e240c..6d5f289b 100644 --- a/crypto/evp/p5_crpt2.c +++ b/crypto/evp/p5_crpt2.c @@ -215,7 +215,7 @@ int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, goto err; } keylen = EVP_CIPHER_CTX_key_length(ctx); - OPENSSL_assert(keylen <= sizeof key); + OPENSSL_assert(keylen <= sizeof(key)); /* Decode parameter */ diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 98286205..d7372aa1 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -187,9 +187,11 @@ static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len) if ((type == pkey->save_type) && pkey->ameth) return 1; #ifndef OPENSSL_NO_ENGINE - /* If we have an ENGINE release it */ + /* If we have ENGINEs release them */ ENGINE_finish(pkey->engine); pkey->engine = NULL; + ENGINE_finish(pkey->pmeth_engine); + pkey->pmeth_engine = NULL; #endif } if (str) @@ -223,7 +225,25 @@ int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len) { return pkey_set_type(pkey, EVP_PKEY_NONE, str, len); } - +#ifndef OPENSSL_NO_ENGINE +int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e) +{ + if (e != NULL) { + if (!ENGINE_init(e)) { + EVPerr(EVP_F_EVP_PKEY_SET1_ENGINE, ERR_R_ENGINE_LIB); + return 0; + } + if (ENGINE_get_pkey_meth(e, pkey->type) == NULL) { + ENGINE_finish(e); + EVPerr(EVP_F_EVP_PKEY_SET1_ENGINE, EVP_R_UNSUPPORTED_ALGORITHM); + return 0; + } + } + ENGINE_finish(pkey->pmeth_engine); + pkey->pmeth_engine = e; + return 1; +} +#endif int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) { if (pkey == NULL || !EVP_PKEY_set_type(pkey, type)) @@ -413,6 +433,8 @@ static void EVP_PKEY_free_it(EVP_PKEY *x) #ifndef OPENSSL_NO_ENGINE ENGINE_finish(x->engine); x->engine = NULL; + ENGINE_finish(x->pmeth_engine); + x->pmeth_engine = NULL; #endif } diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index b7f06be5..5e650a9d 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -89,16 +89,17 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) id = pkey->ameth->pkey_id; } #ifndef OPENSSL_NO_ENGINE - if (pkey && pkey->engine) - e = pkey->engine; + if (e == NULL && pkey != NULL) + e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine; /* Try to find an ENGINE which implements this method */ if (e) { if (!ENGINE_init(e)) { EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB); return NULL; } - } else + } else { e = ENGINE_get_pkey_meth_engine(id); + } /* * If an ENGINE handled this method look it up. Otherwise use internal @@ -112,6 +113,9 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) pmeth = EVP_PKEY_meth_find(id); if (pmeth == NULL) { +#ifndef OPENSSL_NO_ENGINE + ENGINE_finish(e); +#endif EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM); return NULL; } diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 4a3201a9..22c4d3d9 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -287,7 +287,14 @@ int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, CRYPTOerr(CRYPTO_F_CRYPTO_DUP_EX_DATA, ERR_R_MALLOC_FAILURE); return 0; } - if (!CRYPTO_set_ex_data(to, mx - 1, NULL)) + /* + * Make sure the ex_data stack is at least |mx| elements long to avoid + * issues in the for loop that follows; so go get the |mx|'th element + * (if it does not exist CRYPTO_get_ex_data() returns NULL), and assign + * to itself. This is normally a no-op; but ensures the stack is the + * proper size + */ + if (!CRYPTO_set_ex_data(to, mx - 1, CRYPTO_get_ex_data(to, mx - 1))) goto err; for (i = 0; i < mx; i++) { diff --git a/crypto/ia64cpuid.S b/crypto/ia64cpuid.S index ffd6d6ca..92c55124 100644 --- a/crypto/ia64cpuid.S +++ b/crypto/ia64cpuid.S @@ -1,4 +1,4 @@ -// Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. +// Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved. // // Licensed under the OpenSSL license (the "License"). You may not use // this file except in compliance with the License. You can obtain a copy @@ -75,7 +75,7 @@ OPENSSL_wipe_cpu: { .mii; add r9=96*8-8,r9 mov ar.ec=1 };; -// One can sweep double as fast, but then we can't quarantee +// One can sweep double as fast, but then we can't guarantee // that backing storage is wiped... .L_wipe_top: { .mfi; st8 [r9]=r0,-8 diff --git a/crypto/idea/idea_lcl.h b/crypto/idea/idea_lcl.h index f227d0db..825d0006 100644 --- a/crypto/idea/idea_lcl.h +++ b/crypto/idea/idea_lcl.h @@ -38,12 +38,19 @@ else \ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 1: l1|=((unsigned long)(*(--(c))))<<24; \ } \ } @@ -53,12 +60,19 @@ else \ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ } \ } diff --git a/crypto/include/internal/bn_dh.h b/crypto/include/internal/bn_dh.h index b4bca40c..f49f0398 100644 --- a/crypto/include/internal/bn_dh.h +++ b/crypto/include/internal/bn_dh.h @@ -8,9 +8,9 @@ */ #define declare_dh_bn(x) \ - const extern BIGNUM _bignum_dh##x##_p; \ - const extern BIGNUM _bignum_dh##x##_g; \ - const extern BIGNUM _bignum_dh##x##_q; + extern const BIGNUM _bignum_dh##x##_p; \ + extern const BIGNUM _bignum_dh##x##_g; \ + extern const BIGNUM _bignum_dh##x##_q; declare_dh_bn(1024_160) declare_dh_bn(2048_224) diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index c9ef5827..f34699bf 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -199,7 +199,7 @@ static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, cprefix##_cfb##cbits##_encrypt(in, out, (long) \ ((cbits == 1) \ && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) \ - ? inl*8 : inl), \ + ? chunk*8 : chunk), \ &EVP_C_DATA(kstruct, ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx),\ &num, EVP_CIPHER_CTX_encrypting(ctx));\ EVP_CIPHER_CTX_set_num(ctx, num);\ @@ -356,6 +356,7 @@ struct evp_pkey_st { int references; const EVP_PKEY_ASN1_METHOD *ameth; ENGINE *engine; + ENGINE *pmeth_engine; /* If not NULL public key ENGINE to use */ union { void *ptr; # ifndef OPENSSL_NO_RSA diff --git a/crypto/init.c b/crypto/init.c index 647cfb6c..173eac37 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -42,8 +42,11 @@ static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc) CRYPTO_THREAD_get_local(&threadstopkey); if (local == NULL && alloc) { - local = OPENSSL_zalloc(sizeof *local); - CRYPTO_THREAD_set_local(&threadstopkey, local); + local = OPENSSL_zalloc(sizeof(*local)); + if (local != NULL && !CRYPTO_THREAD_set_local(&threadstopkey, local)) { + OPENSSL_free(local); + return NULL; + } } if (!alloc) { CRYPTO_THREAD_set_local(&threadstopkey, NULL); @@ -356,7 +359,12 @@ void OPENSSL_thread_stop(void) int ossl_init_thread_start(uint64_t opts) { - struct thread_local_inits_st *locals = ossl_init_get_thread_local(1); + struct thread_local_inits_st *locals; + + if (!OPENSSL_init_crypto(0, NULL)) + return 0; + + locals = ossl_init_get_thread_local(1); if (locals == NULL) return 0; @@ -642,7 +650,7 @@ int OPENSSL_atexit(void (*handler)(void)) * Deliberately leak a reference to the handler. This will force the * library/code containing the handler to remain loaded until we run the * atexit handler. If -znodelete has been used then this is - * unneccessary. + * unnecessary. */ { DSO *dso = NULL; diff --git a/crypto/lhash/lh_stats.c b/crypto/lhash/lh_stats.c index 73378324..5586afa0 100644 --- a/crypto/lhash/lh_stats.c +++ b/crypto/lhash/lh_stats.c @@ -61,6 +61,9 @@ void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp) void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out) { + OPENSSL_LHASH *lh_mut = (OPENSSL_LHASH *) lh; + int ret; + BIO_printf(out, "num_items = %lu\n", lh->num_items); BIO_printf(out, "num_nodes = %u\n", lh->num_nodes); BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes); @@ -69,15 +72,24 @@ void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out) BIO_printf(out, "num_contracts = %lu\n", lh->num_contracts); BIO_printf(out, "num_contract_reallocs = %lu\n", lh->num_contract_reallocs); - BIO_printf(out, "num_hash_calls = %lu\n", lh->num_hash_calls); - BIO_printf(out, "num_comp_calls = %lu\n", lh->num_comp_calls); + CRYPTO_atomic_add(&lh_mut->num_hash_calls, 0, &ret, + lh->retrieve_stats_lock); + BIO_printf(out, "num_hash_calls = %d\n", ret); + CRYPTO_atomic_add(&lh_mut->num_comp_calls, 0, &ret, + lh->retrieve_stats_lock); + BIO_printf(out, "num_comp_calls = %d\n", ret); BIO_printf(out, "num_insert = %lu\n", lh->num_insert); BIO_printf(out, "num_replace = %lu\n", lh->num_replace); BIO_printf(out, "num_delete = %lu\n", lh->num_delete); BIO_printf(out, "num_no_delete = %lu\n", lh->num_no_delete); - BIO_printf(out, "num_retrieve = %lu\n", lh->num_retrieve); - BIO_printf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss); - BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps); + CRYPTO_atomic_add(&lh_mut->num_retrieve, 0, &ret, lh->retrieve_stats_lock); + BIO_printf(out, "num_retrieve = %d\n", ret); + CRYPTO_atomic_add(&lh_mut->num_retrieve_miss, 0, &ret, + lh->retrieve_stats_lock); + BIO_printf(out, "num_retrieve_miss = %d\n", ret); + CRYPTO_atomic_add(&lh_mut->num_hash_comps, 0, &ret, + lh->retrieve_stats_lock); + BIO_printf(out, "num_hash_comps = %d\n", ret); } void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out) diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c index adde832c..f4854117 100644 --- a/crypto/lhash/lhash.c +++ b/crypto/lhash/lhash.c @@ -14,6 +14,23 @@ #include #include "lhash_lcl.h" +/* + * A hashing implementation that appears to be based on the linear hashing + * algorithm: + * https://en.wikipedia.org/wiki/Linear_hashing + * + * Litwin, Witold (1980), "Linear hashing: A new tool for file and table + * addressing", Proc. 6th Conference on Very Large Databases: 212-223 + * http://hackthology.com/pdfs/Litwin-1980-Linear_Hashing.pdf + * + * From the wikipedia article "Linear hashing is used in the BDB Berkeley + * database system, which in turn is used by many software systems such as + * OpenLDAP, using a C implementation derived from the CACM article and first + * published on the Usenet in 1988 by Esmond Pitt." + * + * The CACM paper is available here: + * https://pdfs.semanticscholar.org/ff4d/1c5deca6269cc316bfd952172284dbf610ee.pdf + */ #undef MIN_NODES #define MIN_NODES 16 @@ -29,9 +46,11 @@ OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c) OPENSSL_LHASH *ret; if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) - goto err0; + return NULL; if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL) - goto err1; + goto err; + if ((ret->retrieve_stats_lock = CRYPTO_THREAD_lock_new()) == NULL) + goto err; ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c); ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h); ret->num_nodes = MIN_NODES / 2; @@ -41,10 +60,10 @@ OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c) ret->down_load = DOWN_LOAD; return (ret); - err1: +err: + OPENSSL_free(ret->b); OPENSSL_free(ret); - err0: - return (NULL); + return NULL; } void OPENSSL_LH_free(OPENSSL_LHASH *lh) @@ -63,6 +82,7 @@ void OPENSSL_LH_free(OPENSSL_LHASH *lh) n = nn; } } + CRYPTO_THREAD_lock_free(lh->retrieve_stats_lock); OPENSSL_free(lh->b); OPENSSL_free(lh); } @@ -133,18 +153,19 @@ void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data) unsigned long hash; OPENSSL_LH_NODE **rn; void *ret; + int scratch; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { - lh->num_retrieve_miss++; - return (NULL); + CRYPTO_atomic_add(&lh->num_retrieve_miss, 1, &scratch, lh->retrieve_stats_lock); + return NULL; } else { ret = (*rn)->data; - lh->num_retrieve++; + CRYPTO_atomic_add(&lh->num_retrieve, 1, &scratch, lh->retrieve_stats_lock); } - return (ret); + return ret; } static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg, @@ -187,16 +208,34 @@ void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void static int expand(OPENSSL_LHASH *lh) { OPENSSL_LH_NODE **n, **n1, **n2, *np; - unsigned int p, i, j; - unsigned long hash, nni; + unsigned int p, pmax, nni, j; + unsigned long hash; + + nni = lh->num_alloc_nodes; + p = lh->p; + pmax = lh->pmax; + if (p + 1 >= pmax) { + j = nni * 2; + n = OPENSSL_realloc(lh->b, sizeof(OPENSSL_LH_NODE *) * j); + if (n == NULL) { + lh->error++; + return 0; + } + lh->b = n; + memset(n + nni, 0, sizeof(*n) * (j - nni)); + lh->pmax = nni; + lh->num_alloc_nodes = j; + lh->num_expand_reallocs++; + lh->p = 0; + } else { + lh->p++; + } lh->num_nodes++; lh->num_expands++; - p = (int)lh->p++; n1 = &(lh->b[p]); - n2 = &(lh->b[p + (int)lh->pmax]); + n2 = &(lh->b[p + pmax]); *n2 = NULL; - nni = lh->num_alloc_nodes; for (np = *n1; np != NULL;) { hash = np->hash; @@ -209,23 +248,6 @@ static int expand(OPENSSL_LHASH *lh) np = *n1; } - if ((lh->p) >= lh->pmax) { - j = (int)lh->num_alloc_nodes * 2; - n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j)); - if (n == NULL) { - lh->error++; - lh->num_nodes--; - lh->p = 0; - return 0; - } - for (i = (int)lh->num_alloc_nodes; i < j; i++) /* 26/02/92 eay */ - n[i] = NULL; /* 02/03/92 eay */ - lh->pmax = lh->num_alloc_nodes; - lh->num_alloc_nodes = j; - lh->num_expand_reallocs++; - lh->p = 0; - lh->b = n; - } return 1; } @@ -270,9 +292,10 @@ static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, OPENSSL_LH_NODE **ret, *n1; unsigned long hash, nn; OPENSSL_LH_COMPFUNC cf; + int scratch; hash = (*(lh->hash)) (data); - lh->num_hash_calls++; + CRYPTO_atomic_add(&lh->num_hash_calls, 1, &scratch, lh->retrieve_stats_lock); *rhash = hash; nn = hash % lh->pmax; @@ -282,12 +305,12 @@ static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, cf = lh->comp; ret = &(lh->b[(int)nn]); for (n1 = *ret; n1 != NULL; n1 = n1->next) { - lh->num_hash_comps++; + CRYPTO_atomic_add(&lh->num_hash_comps, 1, &scratch, lh->retrieve_stats_lock); if (n1->hash != hash) { ret = &(n1->next); continue; } - lh->num_comp_calls++; + CRYPTO_atomic_add(&lh->num_comp_calls, 1, &scratch, lh->retrieve_stats_lock); if (cf(n1->data, data) == 0) break; ret = &(n1->next); diff --git a/crypto/lhash/lhash_lcl.h b/crypto/lhash/lhash_lcl.h index eb4a1a3f..01d463fb 100644 --- a/crypto/lhash/lhash_lcl.h +++ b/crypto/lhash/lhash_lcl.h @@ -6,7 +6,7 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ - +#include struct lhash_node_st { void *data; @@ -18,6 +18,13 @@ struct lhash_st { OPENSSL_LH_NODE **b; OPENSSL_LH_COMPFUNC comp; OPENSSL_LH_HASHFUNC hash; + /* + * some stats are updated on lookup, which callers aren't expecting to have + * to take an exclusive lock around. This lock protects them on platforms + * without atomics, and their types are int rather than unsigned long below + * so they can be adjusted with CRYPTO_atomic_add. + */ + CRYPTO_RWLOCK *retrieve_stats_lock; unsigned int num_nodes; unsigned int num_alloc_nodes; unsigned int p; @@ -29,14 +36,14 @@ struct lhash_st { unsigned long num_expand_reallocs; unsigned long num_contracts; unsigned long num_contract_reallocs; - unsigned long num_hash_calls; - unsigned long num_comp_calls; + int num_hash_calls; + int num_comp_calls; unsigned long num_insert; unsigned long num_replace; unsigned long num_delete; unsigned long num_no_delete; - unsigned long num_retrieve; - unsigned long num_retrieve_miss; - unsigned long num_hash_comps; + int num_retrieve; + int num_retrieve_miss; + int num_hash_comps; int error; }; diff --git a/crypto/mem.c b/crypto/mem.c index bc35132f..72b04c82 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -78,7 +78,14 @@ void *CRYPTO_malloc(size_t num, const char *file, int line) if (num == 0) return NULL; - allow_customize = 0; + if (allow_customize) { + /* + * Disallow customization after the first allocation. We only set this + * if necessary to avoid a store to the same cache line on every + * allocation. + */ + allow_customize = 0; + } #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_malloc(NULL, num, 0, file, line); @@ -117,7 +124,6 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) return NULL; } - allow_customize = 0; #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { void *ret; diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index dc3f8ff5..c884078e 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -466,7 +466,7 @@ static void print_leak(const MEM *m, MEM_LEAK *l) } tid; CRYPTO_THREAD_ID ti; -#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf)) +#define BUF_REMAIN (sizeof(buf) - (size_t)(bufp - buf)) lcl = localtime(&m->time); BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ", @@ -505,7 +505,7 @@ static void print_leak(const MEM *m, MEM_LEAK *l) memset(buf, '>', ami_cnt); tid.ltid = 0; tid.tid = amip->threadid; - BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt, + BIO_snprintf(buf + ami_cnt, sizeof(buf) - ami_cnt, " thread=%lu, file=%s, line=%d, info=\"", tid.ltid, amip->file, amip->line); @@ -515,10 +515,10 @@ static void print_leak(const MEM *m, MEM_LEAK *l) memcpy(buf + buf_len, amip->info, 128 - buf_len - 3); buf_len = 128 - 3; } else { - OPENSSL_strlcpy(buf + buf_len, amip->info, sizeof buf - buf_len); + OPENSSL_strlcpy(buf + buf_len, amip->info, sizeof(buf) - buf_len); buf_len = strlen(buf); } - BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n"); + BIO_snprintf(buf + buf_len, sizeof(buf) - buf_len, "\"\n"); BIO_puts(l->bio, buf); diff --git a/crypto/mem_sec.c b/crypto/mem_sec.c index 664b4ad1..25cdb47d 100644 --- a/crypto/mem_sec.c +++ b/crypto/mem_sec.c @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -24,7 +24,11 @@ #include -#if defined(OPENSSL_SYS_LINUX) || defined(OPENSSL_SYS_UNIX) +/* e_os.h includes unistd.h, which defines _POSIX_VERSION */ +#if !defined(OPENSSL_NO_SECURE_MEMORY) && defined(OPENSSL_SYS_UNIX) \ + && ( (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \ + || defined(__sun) || defined(__hpux) || defined(__sgi) \ + || defined(__osf__) ) # define IMPLEMENTED # include # include @@ -40,6 +44,9 @@ #ifndef PAGE_SIZE # define PAGE_SIZE 4096 #endif +#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) +# define MAP_ANON MAP_ANONYMOUS +#endif #ifdef IMPLEMENTED static size_t secure_mem_used; @@ -156,6 +163,33 @@ void CRYPTO_secure_free(void *ptr, const char *file, int line) #endif /* IMPLEMENTED */ } +void CRYPTO_secure_clear_free(void *ptr, size_t num, + const char *file, int line) +{ +#ifdef IMPLEMENTED + size_t actual_size; + + if (ptr == NULL) + return; + if (!CRYPTO_secure_allocated(ptr)) { + OPENSSL_cleanse(ptr, num); + CRYPTO_free(ptr, file, line); + return; + } + CRYPTO_THREAD_write_lock(sec_malloc_lock); + actual_size = sh_actual_size(ptr); + CLEAR(ptr, actual_size); + secure_mem_used -= actual_size; + sh_free(ptr); + CRYPTO_THREAD_unlock(sec_malloc_lock); +#else + if (ptr == NULL) + return; + OPENSSL_cleanse(ptr, num); + CRYPTO_free(ptr, file, line); +#endif /* IMPLEMENTED */ +} + int CRYPTO_secure_allocated(const void *ptr) { #ifdef IMPLEMENTED @@ -346,7 +380,7 @@ static int sh_init(size_t size, int minsize) size_t pgsize; size_t aligned; - memset(&sh, 0, sizeof sh); + memset(&sh, 0, sizeof(sh)); /* make sure size and minsize are powers of 2 */ OPENSSL_assert(size > 0); @@ -373,7 +407,7 @@ static int sh_init(size_t size, int minsize) for (i = sh.bittable_size; i; i >>= 1) sh.freelist_size++; - sh.freelist = OPENSSL_zalloc(sh.freelist_size * sizeof (char *)); + sh.freelist = OPENSSL_zalloc(sh.freelist_size * sizeof(char *)); OPENSSL_assert(sh.freelist != NULL); if (sh.freelist == NULL) goto err; @@ -459,7 +493,7 @@ static void sh_done() OPENSSL_free(sh.bitmalloc); if (sh.map_result != NULL && sh.map_size) munmap(sh.map_result, sh.map_size); - memset(&sh, 0, sizeof sh); + memset(&sh, 0, sizeof(sh)); } static int sh_allocated(const char *ptr) diff --git a/crypto/modes/asm/ghash-s390x.pl b/crypto/modes/asm/ghash-s390x.pl index 65ffaf98..6e628d88 100644 --- a/crypto/modes/asm/ghash-s390x.pl +++ b/crypto/modes/asm/ghash-s390x.pl @@ -88,9 +88,6 @@ gcm_gmult_4bit: ___ $code.=<<___ if(!$softonly && 0); # hardware is slow for single block... larl %r1,OPENSSL_s390xcap_P - lg %r0,0(%r1) - tmhl %r0,0x4000 # check for message-security-assist - jz .Lsoft_gmult lghi %r0,0 lg %r1,24(%r1) # load second word of kimd capabilities vector tmhh %r1,0x4000 # check for function 65 @@ -126,14 +123,8 @@ gcm_ghash_4bit: ___ $code.=<<___ if(!$softonly); larl %r1,OPENSSL_s390xcap_P - lg %r0,0(%r1) - tmhl %r0,0x4000 # check for message-security-assist - jz .Lsoft_ghash - lghi %r0,0 - la %r1,16($sp) - .long 0xb93e0004 # kimd %r0,%r4 - lg %r1,24($sp) - tmhh %r1,0x4000 # check for function 65 + lg %r0,24(%r1) # load second word of kimd capabilities vector + tmhh %r0,0x4000 # check for function 65 jz .Lsoft_ghash lghi %r0,65 # function 65 la %r1,0($Xi) # H lies right after Xi in gcm128_context diff --git a/crypto/modes/gcm128.c b/crypto/modes/gcm128.c index df9f6547..a2b05c4d 100644 --- a/crypto/modes/gcm128.c +++ b/crypto/modes/gcm128.c @@ -747,8 +747,7 @@ void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block) # endif # if defined(GHASH_ASM_X86_OR_64) # if !defined(GHASH_ASM_X86) || defined(OPENSSL_IA32_SSE2) - if (OPENSSL_ia32cap_P[0] & (1 << 24) && /* check FXSR bit */ - OPENSSL_ia32cap_P[1] & (1 << 1)) { /* check PCLMULQDQ bit */ + if (OPENSSL_ia32cap_P[1] & (1 << 1)) { /* check PCLMULQDQ bit */ if (((OPENSSL_ia32cap_P[1] >> 22) & 0x41) == 0x41) { /* AVX+MOVBE */ gcm_init_avx(ctx->Htable, ctx->H.u); ctx->gmult = gcm_gmult_avx; diff --git a/crypto/modes/ocb128.c b/crypto/modes/ocb128.c index f6f8da7a..db794d08 100644 --- a/crypto/modes/ocb128.c +++ b/crypto/modes/ocb128.c @@ -274,8 +274,7 @@ int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad, { u64 i, all_num_blocks; size_t num_blocks, last_len; - OCB_BLOCK tmp1; - OCB_BLOCK tmp2; + OCB_BLOCK tmp; /* Calculate the number of blocks of AAD provided now, and so far */ num_blocks = len / 16; @@ -284,7 +283,6 @@ int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad, /* Loop through all full blocks of AAD */ for (i = ctx->blocks_hashed + 1; i <= all_num_blocks; i++) { OCB_BLOCK *lookup; - OCB_BLOCK *aad_block; /* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ lookup = ocb_lookup_l(ctx, ocb_ntz(i)); @@ -292,11 +290,13 @@ int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad, return 0; ocb_block16_xor(&ctx->offset_aad, lookup, &ctx->offset_aad); + memcpy(tmp.c, aad, 16); + aad += 16; + /* Sum_i = Sum_{i-1} xor ENCIPHER(K, A_i xor Offset_i) */ - aad_block = (OCB_BLOCK *)(aad + ((i - ctx->blocks_hashed - 1) * 16)); - ocb_block16_xor_misaligned(&ctx->offset_aad, aad_block, &tmp1); - ctx->encrypt(tmp1.c, tmp2.c, ctx->keyenc); - ocb_block16_xor(&ctx->sum, &tmp2, &ctx->sum); + ocb_block16_xor(&ctx->offset_aad, &tmp, &tmp); + ctx->encrypt(tmp.c, tmp.c, ctx->keyenc); + ocb_block16_xor(&tmp, &ctx->sum, &ctx->sum); } /* @@ -310,14 +310,14 @@ int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad, ocb_block16_xor(&ctx->offset_aad, &ctx->l_star, &ctx->offset_aad); /* CipherInput = (A_* || 1 || zeros(127-bitlen(A_*))) xor Offset_* */ - memset(&tmp1, 0, 16); - memcpy(&tmp1, aad + (num_blocks * 16), last_len); - ((unsigned char *)&tmp1)[last_len] = 0x80; - ocb_block16_xor(&ctx->offset_aad, &tmp1, &tmp2); + memset(tmp.c, 0, 16); + memcpy(tmp.c, aad, last_len); + tmp.c[last_len] = 0x80; + ocb_block16_xor(&ctx->offset_aad, &tmp, &tmp); /* Sum = Sum_m xor ENCIPHER(K, CipherInput) */ - ctx->encrypt(tmp2.c, tmp1.c, ctx->keyenc); - ocb_block16_xor(&ctx->sum, &tmp1, &ctx->sum); + ctx->encrypt(tmp.c, tmp.c, ctx->keyenc); + ocb_block16_xor(&tmp, &ctx->sum, &ctx->sum); } ctx->blocks_hashed = all_num_blocks; @@ -335,9 +335,6 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, { u64 i, all_num_blocks; size_t num_blocks, last_len; - OCB_BLOCK tmp1; - OCB_BLOCK tmp2; - OCB_BLOCK pad; /* * Calculate the number of blocks of data to be encrypted provided now, and @@ -366,8 +363,7 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, /* Loop through all full blocks to be encrypted */ for (i = ctx->blocks_processed + 1; i <= all_num_blocks; i++) { OCB_BLOCK *lookup; - OCB_BLOCK *inblock; - OCB_BLOCK *outblock; + OCB_BLOCK tmp; /* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ lookup = ocb_lookup_l(ctx, ocb_ntz(i)); @@ -375,16 +371,19 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, return 0; ocb_block16_xor(&ctx->offset, lookup, &ctx->offset); - /* C_i = Offset_i xor ENCIPHER(K, P_i xor Offset_i) */ - inblock = - (OCB_BLOCK *)(in + ((i - ctx->blocks_processed - 1) * 16)); - ocb_block16_xor_misaligned(&ctx->offset, inblock, &tmp1); + memcpy(tmp.c, in, 16); + in += 16; + /* Checksum_i = Checksum_{i-1} xor P_i */ - ocb_block16_xor_misaligned(&ctx->checksum, inblock, &ctx->checksum); - ctx->encrypt(tmp1.c, tmp2.c, ctx->keyenc); - outblock = - (OCB_BLOCK *)(out + ((i - ctx->blocks_processed - 1) * 16)); - ocb_block16_xor_misaligned(&ctx->offset, &tmp2, outblock); + ocb_block16_xor(&tmp, &ctx->checksum, &ctx->checksum); + + /* C_i = Offset_i xor ENCIPHER(K, P_i xor Offset_i) */ + ocb_block16_xor(&ctx->offset, &tmp, &tmp); + ctx->encrypt(tmp.c, tmp.c, ctx->keyenc); + ocb_block16_xor(&ctx->offset, &tmp, &tmp); + + memcpy(out, tmp.c, 16); + out += 16; } } @@ -395,6 +394,8 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, last_len = len % 16; if (last_len > 0) { + OCB_BLOCK pad; + /* Offset_* = Offset_m xor L_* */ ocb_block16_xor(&ctx->offset, &ctx->l_star, &ctx->offset); @@ -402,14 +403,13 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, ctx->encrypt(ctx->offset.c, pad.c, ctx->keyenc); /* C_* = P_* xor Pad[1..bitlen(P_*)] */ - ocb_block_xor(in + (len / 16) * 16, (unsigned char *)&pad, last_len, - out + (num_blocks * 16)); + ocb_block_xor(in, pad.c, last_len, out); /* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */ - memset(&tmp1, 0, 16); - memcpy(&tmp1, in + (len / 16) * 16, last_len); - ((unsigned char *)(&tmp1))[last_len] = 0x80; - ocb_block16_xor(&ctx->checksum, &tmp1, &ctx->checksum); + memset(pad.c, 0, 16); /* borrow pad */ + memcpy(pad.c, in, last_len); + pad.c[last_len] = 0x80; + ocb_block16_xor(&pad, &ctx->checksum, &ctx->checksum); } ctx->blocks_processed = all_num_blocks; @@ -427,9 +427,6 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, { u64 i, all_num_blocks; size_t num_blocks, last_len; - OCB_BLOCK tmp1; - OCB_BLOCK tmp2; - OCB_BLOCK pad; /* * Calculate the number of blocks of data to be decrypted provided now, and @@ -455,10 +452,10 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, (size_t)ctx->blocks_processed + 1, ctx->offset.c, (const unsigned char (*)[16])ctx->l, ctx->checksum.c); } else { + OCB_BLOCK tmp; + /* Loop through all full blocks to be decrypted */ for (i = ctx->blocks_processed + 1; i <= all_num_blocks; i++) { - OCB_BLOCK *inblock; - OCB_BLOCK *outblock; /* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ OCB_BLOCK *lookup = ocb_lookup_l(ctx, ocb_ntz(i)); @@ -466,17 +463,19 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, return 0; ocb_block16_xor(&ctx->offset, lookup, &ctx->offset); + memcpy(tmp.c, in, 16); + in += 16; + /* P_i = Offset_i xor DECIPHER(K, C_i xor Offset_i) */ - inblock = - (OCB_BLOCK *)(in + ((i - ctx->blocks_processed - 1) * 16)); - ocb_block16_xor_misaligned(&ctx->offset, inblock, &tmp1); - ctx->decrypt(tmp1.c, tmp2.c, ctx->keydec); - outblock = - (OCB_BLOCK *)(out + ((i - ctx->blocks_processed - 1) * 16)); - ocb_block16_xor_misaligned(&ctx->offset, &tmp2, outblock); + ocb_block16_xor(&ctx->offset, &tmp, &tmp); + ctx->decrypt(tmp.c, tmp.c, ctx->keydec); + ocb_block16_xor(&ctx->offset, &tmp, &tmp); /* Checksum_i = Checksum_{i-1} xor P_i */ - ocb_block16_xor_misaligned(&ctx->checksum, outblock, &ctx->checksum); + ocb_block16_xor(&tmp, &ctx->checksum, &ctx->checksum); + + memcpy(out, tmp.c, 16); + out += 16; } } @@ -487,6 +486,8 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, last_len = len % 16; if (last_len > 0) { + OCB_BLOCK pad; + /* Offset_* = Offset_m xor L_* */ ocb_block16_xor(&ctx->offset, &ctx->l_star, &ctx->offset); @@ -494,14 +495,13 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, ctx->encrypt(ctx->offset.c, pad.c, ctx->keyenc); /* P_* = C_* xor Pad[1..bitlen(C_*)] */ - ocb_block_xor(in + (len / 16) * 16, (unsigned char *)&pad, last_len, - out + (num_blocks * 16)); + ocb_block_xor(in, pad.c, last_len, out); /* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */ - memset(&tmp1, 0, 16); - memcpy(&tmp1, out + (len / 16) * 16, last_len); - ((unsigned char *)(&tmp1))[last_len] = 0x80; - ocb_block16_xor(&ctx->checksum, &tmp1, &ctx->checksum); + memset(pad.c, 0, 16); /* borrow pad */ + memcpy(pad.c, out, last_len); + pad.c[last_len] = 0x80; + ocb_block16_xor(&pad, &ctx->checksum, &ctx->checksum); } ctx->blocks_processed = all_num_blocks; @@ -515,15 +515,15 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag, size_t len) { - OCB_BLOCK tmp1, tmp2; + OCB_BLOCK tmp; /* * Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */ - ocb_block16_xor(&ctx->checksum, &ctx->offset, &tmp1); - ocb_block16_xor(&tmp1, &ctx->l_dollar, &tmp2); - ctx->encrypt(tmp2.c, tmp1.c, ctx->keyenc); - ocb_block16_xor(&tmp1, &ctx->sum, &ctx->tag); + ocb_block16_xor(&ctx->checksum, &ctx->offset, &tmp); + ocb_block16_xor(&ctx->l_dollar, &tmp, &tmp); + ctx->encrypt(tmp.c, tmp.c, ctx->keyenc); + ocb_block16_xor(&tmp, &ctx->sum, &ctx->tag); if (len > 16 || len < 1) { return -1; @@ -549,7 +549,7 @@ int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len) CRYPTO_ocb128_finish(ctx, NULL, 0); /* Copy the tag into the supplied buffer */ - memcpy(tag, &ctx->tag, len); + memcpy(tag, ctx->tag.c, len); return 1; } diff --git a/crypto/o_str.c b/crypto/o_str.c index d8516c27..528655aa 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -193,7 +193,7 @@ unsigned char *OPENSSL_hexstr2buf(const char *str, long *len) */ char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len) { - const static char hexdig[] = "0123456789ABCDEF"; + static const char hexdig[] = "0123456789ABCDEF"; char *tmp, *q; const unsigned char *p; int i; diff --git a/crypto/o_time.c b/crypto/o_time.c index 36902325..b2fb38a5 100644 --- a/crypto/o_time.c +++ b/crypto/o_time.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,7 +20,7 @@ struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result) /* * On VMS, gmtime_r() takes a 32-bit pointer as second argument. * Since we can't know that |result| is in a space that can easily - * translate to a 32-bit pointer, we must store temporarly on stack + * translate to a 32-bit pointer, we must store temporarily on stack * and copy the result. The stack is always reachable with 32-bit * pointers. */ diff --git a/crypto/objects/o_names.c b/crypto/objects/o_names.c index ed98df8c..15fe653d 100644 --- a/crypto/objects/o_names.c +++ b/crypto/objects/o_names.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "obj_lcl.h" /* @@ -44,6 +45,7 @@ static int obj_strcmp(const char *a, const char *b) */ static LHASH_OF(OBJ_NAME) *names_lh = NULL; static int names_type_num = OBJ_NAME_TYPE_NUM; +static CRYPTO_RWLOCK *lock = NULL; struct name_funcs_st { unsigned long (*hash_func) (const char *name); @@ -62,23 +64,33 @@ static STACK_OF(NAME_FUNCS) *name_funcs_stack; static unsigned long obj_name_hash(const OBJ_NAME *a); static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b); -int OBJ_NAME_init(void) +static CRYPTO_ONCE init = CRYPTO_ONCE_STATIC_INIT; +DEFINE_RUN_ONCE_STATIC(o_names_init) { - if (names_lh != NULL) - return (1); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); names_lh = lh_OBJ_NAME_new(obj_name_hash, obj_name_cmp); + lock = CRYPTO_THREAD_lock_new(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); - return (names_lh != NULL); + return names_lh != NULL && lock != NULL; +} + +int OBJ_NAME_init(void) +{ + return RUN_ONCE(&init, o_names_init); } int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), int (*cmp_func) (const char *, const char *), void (*free_func) (const char *, int, const char *)) { - int ret, i, push; + int ret = 0, i, push; NAME_FUNCS *name_funcs; + if (!OBJ_NAME_init()) + return 0; + + CRYPTO_THREAD_write_lock(lock); + if (name_funcs_stack == NULL) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); name_funcs_stack = sk_NAME_FUNCS_new_null(); @@ -86,7 +98,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), } if (name_funcs_stack == NULL) { /* ERROR */ - return (0); + goto out; } ret = names_type_num; names_type_num++; @@ -96,7 +108,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); if (name_funcs == NULL) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); - return (0); + ret = 0; + goto out; } name_funcs->hash_func = OPENSSL_LH_strhash; name_funcs->cmp_func = obj_strcmp; @@ -108,7 +121,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), if (!push) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); OPENSSL_free(name_funcs); - return 0; + ret = 0; + goto out; } } name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret); @@ -118,7 +132,10 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), name_funcs->cmp_func = cmp_func; if (free_func != NULL) name_funcs->free_func = free_func; - return (ret); + +out: + CRYPTO_THREAD_unlock(lock); + return ret; } static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b) @@ -134,7 +151,7 @@ static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b) } else ret = strcmp(a->name, b->name); } - return (ret); + return ret; } static unsigned long obj_name_hash(const OBJ_NAME *a) @@ -150,18 +167,20 @@ static unsigned long obj_name_hash(const OBJ_NAME *a) ret = OPENSSL_LH_strhash(a->name); } ret ^= a->type; - return (ret); + return ret; } const char *OBJ_NAME_get(const char *name, int type) { OBJ_NAME on, *ret; int num = 0, alias; + const char *value = NULL; if (name == NULL) - return (NULL); - if ((names_lh == NULL) && !OBJ_NAME_init()) - return (NULL); + return NULL; + if (!OBJ_NAME_init()) + return NULL; + CRYPTO_THREAD_read_lock(lock); alias = type & OBJ_NAME_ALIAS; type &= ~OBJ_NAME_ALIAS; @@ -172,24 +191,30 @@ const char *OBJ_NAME_get(const char *name, int type) for (;;) { ret = lh_OBJ_NAME_retrieve(names_lh, &on); if (ret == NULL) - return (NULL); + break; if ((ret->alias) && !alias) { if (++num > 10) - return (NULL); + break; on.name = ret->data; } else { - return (ret->data); + value = ret->data; + break; } } + + CRYPTO_THREAD_unlock(lock); + return value; } int OBJ_NAME_add(const char *name, int type, const char *data) { OBJ_NAME *onp, *ret; - int alias; + int alias, ok = 0; - if ((names_lh == NULL) && !OBJ_NAME_init()) - return (0); + if (!OBJ_NAME_init()) + return 0; + + CRYPTO_THREAD_write_lock(lock); alias = type & OBJ_NAME_ALIAS; type &= ~OBJ_NAME_ALIAS; @@ -197,7 +222,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data) onp = OPENSSL_malloc(sizeof(*onp)); if (onp == NULL) { /* ERROR */ - return 0; + goto unlock; } onp->name = name; @@ -223,18 +248,26 @@ int OBJ_NAME_add(const char *name, int type, const char *data) if (lh_OBJ_NAME_error(names_lh)) { /* ERROR */ OPENSSL_free(onp); - return 0; + goto unlock; } } - return 1; + + ok = 1; + +unlock: + CRYPTO_THREAD_unlock(lock); + return ok; } int OBJ_NAME_remove(const char *name, int type) { OBJ_NAME on, *ret; + int ok = 0; - if (names_lh == NULL) - return (0); + if (!OBJ_NAME_init()) + return 0; + + CRYPTO_THREAD_write_lock(lock); type &= ~OBJ_NAME_ALIAS; on.name = name; @@ -253,9 +286,11 @@ int OBJ_NAME_remove(const char *name, int type) ret->data); } OPENSSL_free(ret); - return (1); - } else - return (0); + ok = 1; + } + + CRYPTO_THREAD_unlock(lock); + return ok; } typedef struct { @@ -363,8 +398,10 @@ void OBJ_NAME_cleanup(int type) if (type < 0) { lh_OBJ_NAME_free(names_lh); sk_NAME_FUNCS_pop_free(name_funcs_stack, name_funcs_free); + CRYPTO_THREAD_lock_free(lock); names_lh = NULL; name_funcs_stack = NULL; + lock = NULL; } else lh_OBJ_NAME_set_down_load(names_lh, down_load); } diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index 9f374177..21a1f05b 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -213,8 +213,8 @@ int OBJ_add_object(const ASN1_OBJECT *obj) err: for (i = ADDED_DATA; i <= ADDED_NID; i++) OPENSSL_free(ao[i]); - OPENSSL_free(o); - return (NID_undef); + ASN1_OBJECT_free(o); + return NID_undef; } ASN1_OBJECT *OBJ_nid2obj(int n) @@ -500,7 +500,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) n += i; OPENSSL_free(bndec); } else { - BIO_snprintf(tbuf, sizeof tbuf, ".%lu", l); + BIO_snprintf(tbuf, sizeof(tbuf), ".%lu", l); i = strlen(tbuf); if (buf && (buf_len > 0)) { OPENSSL_strlcpy(buf, tbuf, buf_len); @@ -632,6 +632,10 @@ const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num, return (p); } +/* + * Parse a BIO sink to create some extra oid's objects. + * Line format: + */ int OBJ_create_objects(BIO *in) { char buf[512]; @@ -653,9 +657,9 @@ int OBJ_create_objects(BIO *in) *(s++) = '\0'; while (isspace((unsigned char)*s)) s++; - if (*s == '\0') + if (*s == '\0') { s = NULL; - else { + } else { l = s; while ((*l != '\0') && !isspace((unsigned char)*l)) l++; @@ -663,15 +667,18 @@ int OBJ_create_objects(BIO *in) *(l++) = '\0'; while (isspace((unsigned char)*l)) l++; - if (*l == '\0') + if (*l == '\0') { l = NULL; - } else + } + } else { l = NULL; + } } - } else + } else { s = NULL; - if ((o == NULL) || (*o == '\0')) - return (num); + } + if (*o == '\0') + return num; if (!OBJ_create(o, s, l)) return (num); num++; @@ -685,7 +692,8 @@ int OBJ_create(const char *oid, const char *sn, const char *ln) int ok = 0; /* Check to see if short or long name already present */ - if (OBJ_sn2nid(sn) != NID_undef || OBJ_ln2nid(ln) != NID_undef) { + if ((sn != NULL && OBJ_sn2nid(sn) != NID_undef) + || (ln != NULL && OBJ_ln2nid(ln) != NID_undef)) { OBJerr(OBJ_F_OBJ_CREATE, OBJ_R_OID_EXISTS); return 0; } diff --git a/crypto/ocsp/ocsp_ht.c b/crypto/ocsp/ocsp_ht.c index 680edfa5..d8796ca6 100644 --- a/crypto/ocsp/ocsp_ht.c +++ b/crypto/ocsp/ocsp_ht.c @@ -298,10 +298,12 @@ int OCSP_REQ_CTX_nbio(OCSP_REQ_CTX *rctx) } rctx->state = OHS_ASN1_WRITE_INIT; + /* fall thru */ case OHS_ASN1_WRITE_INIT: rctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL); rctx->state = OHS_ASN1_WRITE; + /* fall thru */ case OHS_ASN1_WRITE: n = BIO_get_mem_data(rctx->mem, &p); @@ -323,6 +325,7 @@ int OCSP_REQ_CTX_nbio(OCSP_REQ_CTX *rctx) (void)BIO_reset(rctx->mem); + /* fall thru */ case OHS_ASN1_FLUSH: i = BIO_flush(rctx->io); diff --git a/crypto/ocsp/ocsp_lcl.h b/crypto/ocsp/ocsp_lcl.h index f93a268e..d1cf1583 100644 --- a/crypto/ocsp/ocsp_lcl.h +++ b/crypto/ocsp/ocsp_lcl.h @@ -214,3 +214,19 @@ struct ocsp_service_locator_st { X509_NAME *issuer; STACK_OF(ACCESS_DESCRIPTION) *locator; }; + +# define OCSP_REQUEST_sign(o,pkey,md) \ + ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\ + &(o)->optionalSignature->signatureAlgorithm,NULL,\ + (o)->optionalSignature->signature,&(o)->tbsRequest,pkey,md) + +# define OCSP_BASICRESP_sign(o,pkey,md,d) \ + ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),&(o)->signatureAlgorithm,\ + NULL,(o)->signature,&(o)->tbsResponseData,pkey,md) + +# define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\ + &(a)->optionalSignature->signatureAlgorithm,\ + (a)->optionalSignature->signature,&(a)->tbsRequest,r) + +# define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\ + &(a)->signatureAlgorithm,(a)->signature,&(a)->tbsResponseData,r) diff --git a/crypto/ocsp/ocsp_vfy.c b/crypto/ocsp/ocsp_vfy.c index e2cfa6dd..9a8d3438 100644 --- a/crypto/ocsp/ocsp_vfy.c +++ b/crypto/ocsp/ocsp_vfy.c @@ -73,6 +73,8 @@ int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, goto f_err; } } + } else if (certs != NULL) { + untrusted = certs; } else { untrusted = bs->certs; } @@ -136,6 +138,15 @@ int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, goto end; } +int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer, + STACK_OF(X509) *extra_certs) +{ + int ret; + + ret = ocsp_find_signer(signer, bs, extra_certs, 0); + return (ret > 0) ? 1 : 0; +} + static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs, unsigned long flags) { diff --git a/crypto/pariscid.pl b/crypto/pariscid.pl index f82e27ac..3d4a5f8a 100644 --- a/crypto/pariscid.pl +++ b/crypto/pariscid.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2009-2018 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the OpenSSL license (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -160,7 +160,7 @@ L\$oop_cmp or %r29,$rv,$rv sub %r0,$rv,%r29 - extru %r29,31,1,$rv + extru %r29,0,1,$rv L\$no_data bv ($rp) .EXIT diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c index dd493c85..78d4476a 100644 --- a/crypto/pem/pem_info.c +++ b/crypto/pem/pem_info.c @@ -294,7 +294,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, /* create the right magic header stuff */ OPENSSL_assert(strlen(objstr) + 23 + 2 * EVP_CIPHER_iv_length(enc) + 13 <= - sizeof buf); + sizeof(buf)); buf[0] = '\0'; PEM_proc_type(buf, PEM_TYPE_ENCRYPTED); PEM_dek_info(buf, objstr, EVP_CIPHER_iv_length(enc), diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c index 3f53fd89..e9202f44 100644 --- a/crypto/pem/pem_lib.c +++ b/crypto/pem/pem_lib.c @@ -357,7 +357,7 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, OPENSSL_cleanse(buf, PEM_BUFSIZE); OPENSSL_assert(strlen(objstr) + 23 + 2 * EVP_CIPHER_iv_length(enc) + 13 - <= sizeof buf); + <= sizeof(buf)); buf[0] = '\0'; PEM_proc_type(buf, PEM_TYPE_ENCRYPTED); diff --git a/crypto/pem/pem_pk8.c b/crypto/pem/pem_pk8.c index 993c595a..5caad9fa 100644 --- a/crypto/pem/pem_pk8.c +++ b/crypto/pem/pem_pk8.c @@ -131,6 +131,7 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, } p8inf = PKCS8_decrypt(p8, psbuf, klen); X509_SIG_free(p8); + OPENSSL_cleanse(psbuf, klen); if (!p8inf) return NULL; ret = EVP_PKCS82PKEY(p8inf); diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index 63086227..671b374f 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -66,6 +66,7 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, } p8inf = PKCS8_decrypt(p8, psbuf, klen); X509_SIG_free(p8); + OPENSSL_cleanse(psbuf, klen); if (!p8inf) goto p8err; ret = EVP_PKCS82PKEY(p8inf); diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c index 248704ec..d0a42395 100644 --- a/crypto/pem/pvkfmt.c +++ b/crypto/pem/pvkfmt.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2005-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -120,6 +120,7 @@ static int do_blob_header(const unsigned char **in, unsigned int length, case MS_DSS1MAGIC: *pisdss = 1; + /* fall thru */ case MS_RSA1MAGIC: if (*pispub == 0) { PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB); @@ -129,6 +130,7 @@ static int do_blob_header(const unsigned char **in, unsigned int length, case MS_DSS2MAGIC: *pisdss = 1; + /* fall thru */ case MS_RSA2MAGIC: if (*pispub == 1) { PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB); @@ -283,14 +285,17 @@ static EVP_PKEY *b2i_dss(const unsigned char **in, goto memerr; BN_CTX_free(ctx); + ctx = NULL; } if (!DSA_set0_pqg(dsa, pbn, qbn, gbn)) goto memerr; pbn = qbn = gbn = NULL; if (!DSA_set0_key(dsa, pub_key, priv_key)) goto memerr; + pub_key = priv_key = NULL; - EVP_PKEY_set1_DSA(ret, dsa); + if (!EVP_PKEY_set1_DSA(ret, dsa)) + goto memerr; DSA_free(dsa); *in = p; return ret; @@ -343,12 +348,19 @@ static EVP_PKEY *b2i_rsa(const unsigned char **in, goto memerr; if (!read_lebn(&pin, nbyte, &d)) goto memerr; - RSA_set0_factors(rsa, p, q); - RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp); + if (!RSA_set0_factors(rsa, p, q)) + goto memerr; + p = q = NULL; + if (!RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp)) + goto memerr; + dmp1 = dmq1 = iqmp = NULL; } - RSA_set0_key(rsa, n, e, d); + if (!RSA_set0_key(rsa, n, e, d)) + goto memerr; + n = e = d = NULL; - EVP_PKEY_set1_RSA(ret, rsa); + if (!EVP_PKEY_set1_RSA(ret, rsa)) + goto memerr; RSA_free(rsa); *in = pin; return ret; diff --git a/crypto/pkcs12/p12_kiss.c b/crypto/pkcs12/p12_kiss.c index 62f5d1ec..7ab98385 100644 --- a/crypto/pkcs12/p12_kiss.c +++ b/crypto/pkcs12/p12_kiss.c @@ -34,6 +34,12 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, { STACK_OF(X509) *ocerts = NULL; X509 *x = NULL; + + if (pkey) + *pkey = NULL; + if (cert) + *cert = NULL; + /* Check for NULL PKCS12 structure */ if (!p12) { @@ -42,11 +48,6 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, return 0; } - if (pkey) - *pkey = NULL; - if (cert) - *cert = NULL; - /* Check the mac */ /* @@ -75,7 +76,7 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, if (!ocerts) { PKCS12err(PKCS12_F_PKCS12_PARSE, ERR_R_MALLOC_FAILURE); - return 0; + goto err; } if (!parse_pk12(p12, pass, -1, pkey, ocerts)) { @@ -111,10 +112,14 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, err: - if (pkey) + if (pkey) { EVP_PKEY_free(*pkey); - if (cert) + *pkey = NULL; + } + if (cert) { X509_free(*cert); + *cert = NULL; + } X509_free(x); sk_X509_pop_free(ocerts, X509_free); return 0; diff --git a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c index 899a12e1..a9e22026 100644 --- a/crypto/pkcs12/p12_mutl.c +++ b/crypto/pkcs12/p12_mutl.c @@ -124,8 +124,8 @@ static int pkcs12_gen_mac(PKCS12 *p12, const char *pass, int passlen, PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_KEY_GEN_ERROR); return 0; } - hmac = HMAC_CTX_new(); - if (!HMAC_Init_ex(hmac, key, md_size, md_type, NULL) + if ((hmac = HMAC_CTX_new()) == NULL + || !HMAC_Init_ex(hmac, key, md_size, md_type, NULL) || !HMAC_Update(hmac, p12->authsafes->d.data->data, p12->authsafes->d.data->length) || !HMAC_Final(hmac, mac, maclen)) { diff --git a/crypto/pkcs7/pk7_asn1.c b/crypto/pkcs7/pk7_asn1.c index 315e1b81..cd9fb4f5 100644 --- a/crypto/pkcs7/pk7_asn1.c +++ b/crypto/pkcs7/pk7_asn1.c @@ -40,6 +40,7 @@ static int pk7_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, case ASN1_OP_STREAM_PRE: if (PKCS7_stream(&sarg->boundary, *pp7) <= 0) return 0; + /* fall thru */ case ASN1_OP_DETACHED_PRE: sarg->ndef_bio = PKCS7_dataInit(*pp7, sarg->out); if (!sarg->ndef_bio) diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c index bc6bd30f..e6e80f08 100644 --- a/crypto/pkcs7/pk7_doit.c +++ b/crypto/pkcs7/pk7_doit.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -316,16 +316,18 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio) } if (bio == NULL) { - if (PKCS7_is_detached(p7)) + if (PKCS7_is_detached(p7)) { bio = BIO_new(BIO_s_null()); - else if (os && os->length > 0) + } else if (os && os->length > 0) { bio = BIO_new_mem_buf(os->data, os->length); - if (bio == NULL) { + } else { bio = BIO_new(BIO_s_mem()); if (bio == NULL) goto err; BIO_set_mem_eof_return(bio, 0); } + if (bio == NULL) + goto err; } if (out) BIO_push(out, bio); diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c index 85ce4e6f..7d5fcb7f 100644 --- a/crypto/rand/md_rand.c +++ b/crypto/rand/md_rand.c @@ -169,7 +169,7 @@ static int rand_add(const void *buf, int num, double add) md_c[0] = md_count[0]; md_c[1] = md_count[1]; - memcpy(local_md, md, sizeof md); + memcpy(local_md, md, sizeof(md)); /* state_index <= state_num <= STATE_SIZE */ state_index += num; @@ -416,7 +416,7 @@ static int rand_bytes(unsigned char *buf, int num, int pseudo) st_num = state_num; md_c[0] = md_count[0]; md_c[1] = md_count[1]; - memcpy(local_md, md, sizeof md); + memcpy(local_md, md, sizeof(md)); state_index += num_ceil; if (state_index > state_num) @@ -442,15 +442,15 @@ static int rand_bytes(unsigned char *buf, int num, int pseudo) goto err; #ifndef GETPID_IS_MEANINGLESS if (curr_pid) { /* just in the first iteration to save time */ - if (!MD_Update(m, (unsigned char *)&curr_pid, sizeof curr_pid)) + if (!MD_Update(m, (unsigned char *)&curr_pid, sizeof(curr_pid))) goto err; curr_pid = 0; } #endif if (curr_time) { /* just in the first iteration to save time */ - if (!MD_Update(m, (unsigned char *)&curr_time, sizeof curr_time)) + if (!MD_Update(m, (unsigned char *)&curr_time, sizeof(curr_time))) goto err; - if (!MD_Update(m, (unsigned char *)&tv, sizeof tv)) + if (!MD_Update(m, (unsigned char *)&tv, sizeof(tv))) goto err; curr_time = 0; if (!rand_hw_seed(m)) @@ -492,6 +492,7 @@ static int rand_bytes(unsigned char *buf, int num, int pseudo) */ ASYNC_block_pause(); if (!MD_Update(m, md, MD_DIGEST_LENGTH) || !MD_Final(m, md)) { + ASYNC_unblock_pause(); CRYPTO_THREAD_unlock(rand_lock); goto err; } diff --git a/crypto/rand/rand_egd.c b/crypto/rand/rand_egd.c index dd58b214..50963b8e 100644 --- a/crypto/rand/rand_egd.c +++ b/crypto/rand/rand_egd.c @@ -102,7 +102,7 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) addr.sun_family = AF_UNIX; if (strlen(path) >= sizeof(addr.sun_path)) return (-1); - OPENSSL_strlcpy(addr.sun_path, path, sizeof addr.sun_path); + OPENSSL_strlcpy(addr.sun_path, path, sizeof(addr.sun_path)); len = offsetof(struct sockaddr_un, sun_path) + strlen(path); fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c index ecba2dc9..7a5a9484 100644 --- a/crypto/rand/rand_unix.c +++ b/crypto/rand/rand_unix.c @@ -80,15 +80,15 @@ int RAND_poll(void) */ curr_gid = getgid(); - RAND_add(&curr_gid, sizeof curr_gid, 1); + RAND_add(&curr_gid, sizeof(curr_gid), 1); curr_gid = 0; curr_pid = getpid(); - RAND_add(&curr_pid, sizeof curr_pid, 1); + RAND_add(&curr_pid, sizeof(curr_pid), 1); curr_pid = 0; curr_uid = getuid(); - RAND_add(&curr_uid, sizeof curr_uid, 1); + RAND_add(&curr_uid, sizeof(curr_uid), 1); curr_uid = 0; for (i = 0; i < (ENTROPY_NEEDED * 4); i++) { @@ -116,7 +116,7 @@ int RAND_poll(void) /* take 8 bits */ v = (unsigned char)(ts.tv_nsec % 256); - RAND_add(&v, sizeof v, 1); + RAND_add(&v, sizeof(v), 1); v = 0; } return 1; @@ -289,7 +289,7 @@ int RAND_poll(void) # if defined(DEVRANDOM) || (!defined(OPENSSL_NO_EGD) && defined(DEVRANDOM_EGD)) if (n > 0) { - RAND_add(tmpbuf, sizeof tmpbuf, (double)n); + RAND_add(tmpbuf, sizeof(tmpbuf), (double)n); OPENSSL_cleanse(tmpbuf, n); } # endif diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index 15fa9dce..dbd03ff2 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -21,9 +21,7 @@ #ifdef OPENSSL_SYS_VMS # include #endif -#ifndef NO_SYS_TYPES_H -# include -#endif +#include #ifndef OPENSSL_NO_POSIX_IO # include # include diff --git a/crypto/rc2/rc2_locl.h b/crypto/rc2/rc2_locl.h index a9a57d61..e4dad947 100644 --- a/crypto/rc2/rc2_locl.h +++ b/crypto/rc2/rc2_locl.h @@ -20,13 +20,20 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ - case 5: l2|=((unsigned long)(*(--(c)))); \ + /* fall thru */ \ + case 5: l2|=((unsigned long)(*(--(c)))); \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ - case 1: l1|=((unsigned long)(*(--(c)))); \ + /* fall thru */ \ + case 1: l1|=((unsigned long)(*(--(c)))); \ } \ } @@ -42,12 +49,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ } \ } @@ -58,12 +72,19 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 1: l1|=((unsigned long)(*(--(c))))<<24; \ } \ } @@ -73,12 +94,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ } \ } diff --git a/crypto/rc4/asm/rc4-c64xplus.pl b/crypto/rc4/asm/rc4-c64xplus.pl index daed75c7..184922c1 100644 --- a/crypto/rc4/asm/rc4-c64xplus.pl +++ b/crypto/rc4/asm/rc4-c64xplus.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the OpenSSL license (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -186,5 +186,7 @@ rc4_options: .align 4 ___ +$output=pop; +open STDOUT,">$output"; print $code; close STDOUT; diff --git a/crypto/rc4/build.info b/crypto/rc4/build.info index 6c488890..8659526d 100644 --- a/crypto/rc4/build.info +++ b/crypto/rc4/build.info @@ -20,7 +20,7 @@ ENDRAW[makefile(windows)] BEGINRAW[Makefile] {- $builddir -}/rc4-ia64.s: {- $sourcedir -}/asm/rc4-ia64.pl @(trap "rm $@.*" INT 0; \ - $(PERL) $< $(CFLAGS) $(LIB_CFLAGS) $@.S; \ + $(PERL) {- $sourcedir -}/asm/rc4-ia64.pl $(CFLAGS) $(LIB_CFLAGS) $@.S; \ case `awk '/^#define RC4_INT/{print$$NF}' $(BLDDIR)/include/openssl/opensslconf.h` in \ int) set -x; $(CC) $(CFLAGS) $(LIB_CFLAGS) -DSZ=4 -E $@.S > $@.i && mv -f $@.i $@;; \ char) set -x; $(CC) $(CFLAGS) $(LIB_CFLAGS) -DSZ=1 -E $@.S > $@.i && mv -f $@.i $@;; \ diff --git a/crypto/rc5/rc5_locl.h b/crypto/rc5/rc5_locl.h index 33a709b4..41130fe3 100644 --- a/crypto/rc5/rc5_locl.h +++ b/crypto/rc5/rc5_locl.h @@ -22,13 +22,20 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ - case 5: l2|=((unsigned long)(*(--(c)))); \ + /* fall thru */ \ + case 5: l2|=((unsigned long)(*(--(c)))); \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ - case 1: l1|=((unsigned long)(*(--(c)))); \ + /* fall thru */ \ + case 1: l1|=((unsigned long)(*(--(c)))); \ } \ } @@ -44,12 +51,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ } \ } @@ -60,12 +74,19 @@ l1=l2=0; \ switch (n) { \ case 8: l2 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + /* fall thru */ \ case 4: l1 =((unsigned long)(*(--(c)))) ; \ + /* fall thru */ \ case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + /* fall thru */ \ case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + /* fall thru */ \ case 1: l1|=((unsigned long)(*(--(c))))<<24; \ } \ } @@ -75,12 +96,19 @@ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + /* fall thru */ \ case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + /* fall thru */ \ case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + /* fall thru */ \ case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + /* fall thru */ \ case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + /* fall thru */ \ case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + /* fall thru */ \ case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + /* fall thru */ \ case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ } \ } diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index 5694140a..4a12276a 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -773,7 +773,8 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri) EVP_PKEY_CTX *pkctx = CMS_RecipientInfo_get0_pkey_ctx(ri); int pad_mode = RSA_PKCS1_PADDING, rv = 0, labellen; unsigned char *label; - CMS_RecipientInfo_ktri_get0_algs(ri, NULL, NULL, &alg); + if (CMS_RecipientInfo_ktri_get0_algs(ri, NULL, NULL, &alg) <= 0) + return 0; if (pkctx) { if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0) return 0; diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index 4ced9655..9af43e05 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -42,6 +42,7 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BIGNUM *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *tmp; int bitsp, bitsq, ok = -1, n = 0; BN_CTX *ctx = NULL; + unsigned long error = 0; /* * When generating ridiculously small keys, we can get stuck @@ -88,16 +89,26 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, if (BN_copy(rsa->e, e_value) == NULL) goto err; + BN_set_flags(r2, BN_FLG_CONSTTIME); /* generate p and q */ for (;;) { if (!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb)) goto err; if (!BN_sub(r2, rsa->p, BN_value_one())) goto err; - if (!BN_gcd(r1, r2, rsa->e, ctx)) - goto err; - if (BN_is_one(r1)) + ERR_set_mark(); + if (BN_mod_inverse(r1, r2, rsa->e, ctx) != NULL) { + /* GCD == 1 since inverse exists */ break; + } + error = ERR_peek_last_error(); + if (ERR_GET_LIB(error) == ERR_LIB_BN + && ERR_GET_REASON(error) == BN_R_NO_INVERSE) { + /* GCD != 1 */ + ERR_pop_to_mark(); + } else { + goto err; + } if (!BN_GENCB_call(cb, 2, n++)) goto err; } @@ -110,10 +121,19 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, } while (BN_cmp(rsa->p, rsa->q) == 0); if (!BN_sub(r2, rsa->q, BN_value_one())) goto err; - if (!BN_gcd(r1, r2, rsa->e, ctx)) - goto err; - if (BN_is_one(r1)) + ERR_set_mark(); + if (BN_mod_inverse(r1, r2, rsa->e, ctx) != NULL) { + /* GCD == 1 since inverse exists */ break; + } + error = ERR_peek_last_error(); + if (ERR_GET_LIB(error) == ERR_LIB_BN + && ERR_GET_REASON(error) == BN_R_NO_INVERSE) { + /* GCD != 1 */ + ERR_pop_to_mark(); + } else { + goto err; + } if (!BN_GENCB_call(cb, 2, n++)) goto err; } diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index 48e9100a..e1377a06 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -15,31 +15,9 @@ #include #include "rsa_locl.h" -static const RSA_METHOD *default_RSA_meth = NULL; - RSA *RSA_new(void) { - RSA *r = RSA_new_method(NULL); - - return r; -} - -void RSA_set_default_method(const RSA_METHOD *meth) -{ - default_RSA_meth = meth; -} - -const RSA_METHOD *RSA_get_default_method(void) -{ - if (default_RSA_meth == NULL) { -#ifdef RSA_NULL - default_RSA_meth = RSA_null_method(); -#else - default_RSA_meth = RSA_PKCS1_OpenSSL(); -#endif - } - - return default_RSA_meth; + return RSA_new_method(NULL); } const RSA_METHOD *RSA_get_method(const RSA *rsa) diff --git a/crypto/rsa/rsa_oaep.c b/crypto/rsa/rsa_oaep.c index 868104f1..4878d495 100644 --- a/crypto/rsa/rsa_oaep.c +++ b/crypto/rsa/rsa_oaep.c @@ -122,7 +122,7 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, int plen, const EVP_MD *md, const EVP_MD *mgf1md) { - int i, dblen, mlen = -1, one_index = 0, msg_index; + int i, dblen = 0, mlen = -1, one_index = 0, msg_index; unsigned int good, found_one_byte; const unsigned char *maskedseed, *maskeddb; /* @@ -239,8 +239,8 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1, RSA_R_OAEP_DECODING_ERROR); cleanup: - OPENSSL_free(db); - OPENSSL_free(em); + OPENSSL_clear_free(db, dblen); + OPENSSL_clear_free(em, num); return mlen; } diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c index 78260664..62a88959 100644 --- a/crypto/rsa/rsa_ossl.c +++ b/crypto/rsa/rsa_ossl.c @@ -11,8 +11,6 @@ #include "internal/bn_int.h" #include "rsa_locl.h" -#ifndef RSA_NULL - static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding); static int rsa_ossl_private_encrypt(int flen, const unsigned char *from, @@ -26,7 +24,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa, static int rsa_ossl_init(RSA *rsa); static int rsa_ossl_finish(RSA *rsa); static RSA_METHOD rsa_pkcs1_ossl_meth = { - "OpenSSL PKCS#1 RSA (from Eric Young)", + "OpenSSL PKCS#1 RSA", rsa_ossl_public_encrypt, rsa_ossl_public_decrypt, /* signature verification */ rsa_ossl_private_encrypt, /* signing */ @@ -43,6 +41,18 @@ static RSA_METHOD rsa_pkcs1_ossl_meth = { NULL /* rsa_keygen */ }; +static const RSA_METHOD *default_RSA_meth = &rsa_pkcs1_ossl_meth; + +void RSA_set_default_method(const RSA_METHOD *meth) +{ + default_RSA_meth = meth; +} + +const RSA_METHOD *RSA_get_default_method(void) +{ + return default_RSA_meth; +} + const RSA_METHOD *RSA_PKCS1_OpenSSL(void) { return &rsa_pkcs1_ossl_meth; @@ -593,6 +603,8 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) r1 = BN_CTX_get(ctx); m1 = BN_CTX_get(ctx); vrfy = BN_CTX_get(ctx); + if (vrfy == NULL) + goto err; { BIGNUM *p = BN_new(), *q = BN_new(); @@ -786,5 +798,3 @@ static int rsa_ossl_finish(RSA *rsa) BN_MONT_CTX_free(rsa->_method_mod_q); return (1); } - -#endif diff --git a/crypto/rsa/rsa_pk1.c b/crypto/rsa/rsa_pk1.c index efb16a02..aeeb32c2 100644 --- a/crypto/rsa/rsa_pk1.c +++ b/crypto/rsa/rsa_pk1.c @@ -226,8 +226,6 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, * We can't continue in constant-time because we need to copy the result * and we cannot fake its length. This unavoidably leaks timing * information at the API boundary. - * TODO(emilia): this could be addressed at the call site, - * see BoringSSL commit 0aa0767340baf925bda4804882aab0cb974b2d26. */ if (!good) { mlen = -1; @@ -237,7 +235,7 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, memcpy(to, em + msg_index, mlen); err: - OPENSSL_free(em); + OPENSSL_clear_free(em, num); if (mlen == -1) RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, RSA_R_PKCS_DECODING_ERROR); diff --git a/crypto/rsa/rsa_pss.c b/crypto/rsa/rsa_pss.c index 2aebbe96..f8143387 100644 --- a/crypto/rsa/rsa_pss.c +++ b/crypto/rsa/rsa_pss.c @@ -111,7 +111,7 @@ int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, goto err; } if (!EVP_DigestInit_ex(ctx, Hash, NULL) - || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) + || !EVP_DigestUpdate(ctx, zeroes, sizeof(zeroes)) || !EVP_DigestUpdate(ctx, mHash, hLen)) goto err; if (maskedDBLen - i) { @@ -207,7 +207,7 @@ int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, if (ctx == NULL) goto err; if (!EVP_DigestInit_ex(ctx, Hash, NULL) - || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) + || !EVP_DigestUpdate(ctx, zeroes, sizeof(zeroes)) || !EVP_DigestUpdate(ctx, mHash, hLen)) goto err; if (sLen && !EVP_DigestUpdate(ctx, salt, sLen)) diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c index 9dd993fb..877ee221 100644 --- a/crypto/rsa/rsa_x931g.c +++ b/crypto/rsa/rsa_x931g.c @@ -153,6 +153,8 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_CTX_start(ctx); Xp = BN_CTX_get(ctx); Xq = BN_CTX_get(ctx); + if (Xq == NULL) + goto error; if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx)) goto error; diff --git a/crypto/s390xcap.c b/crypto/s390xcap.c index 675f2ecb..272c5517 100644 --- a/crypto/s390xcap.c +++ b/crypto/s390xcap.c @@ -13,7 +13,7 @@ #include #include -extern unsigned long OPENSSL_s390xcap_P[]; +unsigned long long OPENSSL_s390xcap_P[10]; static sigjmp_buf ill_jmp; static void ill_handler(int sig) diff --git a/crypto/s390xcpuid.S b/crypto/s390xcpuid.S index 8859e9e6..fc141d92 100644 --- a/crypto/s390xcpuid.S +++ b/crypto/s390xcpuid.S @@ -176,5 +176,3 @@ OPENSSL_instrument_bus2: .section .init brasl %r14,OPENSSL_cpuid_setup - -.comm OPENSSL_s390xcap_P,80,8 diff --git a/crypto/sha/asm/sha1-s390x.pl b/crypto/sha/asm/sha1-s390x.pl index b19606c5..79df1ffd 100644 --- a/crypto/sha/asm/sha1-s390x.pl +++ b/crypto/sha/asm/sha1-s390x.pl @@ -172,9 +172,6 @@ sha1_block_data_order: ___ $code.=<<___ if ($kimdfunc); larl %r1,OPENSSL_s390xcap_P - lg %r0,0(%r1) - tmhl %r0,0x4000 # check for message-security assist - jz .Lsoftware lg %r0,16(%r1) # check kimd capabilities tmhh %r0,`0x8000>>$kimdfunc` jz .Lsoftware @@ -242,7 +239,6 @@ $code.=<<___; br %r14 .size sha1_block_data_order,.-sha1_block_data_order .string "SHA1 block transform for s390x, CRYPTOGAMS by " -.comm OPENSSL_s390xcap_P,80,8 ___ $code =~ s/\`([^\`]*)\`/eval $1/gem; diff --git a/crypto/sha/asm/sha512-s390x.pl b/crypto/sha/asm/sha512-s390x.pl index 582d393c..427d6f82 100644 --- a/crypto/sha/asm/sha512-s390x.pl +++ b/crypto/sha/asm/sha512-s390x.pl @@ -244,9 +244,6 @@ $Func: ___ $code.=<<___ if ($kimdfunc); larl %r1,OPENSSL_s390xcap_P - lg %r0,0(%r1) - tmhl %r0,0x4000 # check for message-security assist - jz .Lsoftware lg %r0,16(%r1) # check kimd capabilities tmhh %r0,`0x8000>>$kimdfunc` jz .Lsoftware @@ -315,7 +312,6 @@ $code.=<<___; br %r14 .size $Func,.-$Func .string "SHA${label} block transform for s390x, CRYPTOGAMS by " -.comm OPENSSL_s390xcap_P,80,8 ___ $code =~ s/\`([^\`]*)\`/eval $1/gem; diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index c06baa05..464dac42 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -15,8 +15,6 @@ #include #include "ui_locl.h" -static const UI_METHOD *default_UI_meth = NULL; - UI *UI_new(void) { return (UI_new_method(NULL)); @@ -481,6 +479,8 @@ int UI_process(UI *ui) } } } + + state = NULL; err: if (ui->meth->ui_close_session != NULL && ui->meth->ui_close_session(ui) <= 0) { @@ -531,19 +531,6 @@ void *UI_get_ex_data(UI *r, int idx) return (CRYPTO_get_ex_data(&r->ex_data, idx)); } -void UI_set_default_method(const UI_METHOD *meth) -{ - default_UI_meth = meth; -} - -const UI_METHOD *UI_get_default_method(void) -{ - if (default_UI_meth == NULL) { - default_UI_meth = UI_OpenSSL(); - } - return default_UI_meth; -} - const UI_METHOD *UI_get_method(UI *ui) { return ui->meth; diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c index ed0bfa0b..8fa8deca 100644 --- a/crypto/ui/ui_openssl.c +++ b/crypto/ui/ui_openssl.c @@ -202,6 +202,18 @@ static UI_METHOD ui_openssl = { NULL }; +static const UI_METHOD *default_UI_meth = &ui_openssl; + +void UI_set_default_method(const UI_METHOD *meth) +{ + default_UI_meth = meth; +} + +const UI_METHOD *UI_get_default_method(void) +{ + return default_UI_meth; +} + /* The method with all the built-in thingies */ UI_METHOD *UI_OpenSSL(void) { diff --git a/crypto/whrlpool/wp_dgst.c b/crypto/whrlpool/wp_dgst.c index ed064244..6d925517 100644 --- a/crypto/whrlpool/wp_dgst.c +++ b/crypto/whrlpool/wp_dgst.c @@ -174,7 +174,7 @@ void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *_inp, size_t bits) goto reconsider; } else #endif - if (bits >= 8) { + if (bits > 8) { b = ((inp[0] << inpgap) | (inp[1] >> (8 - inpgap))); b &= 0xff; if (bitrem) @@ -191,7 +191,7 @@ void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *_inp, size_t bits) } if (bitrem) c->data[byteoff] = b << (8 - bitrem); - } else { /* remaining less than 8 bits */ + } else { /* remaining less than or equal to 8 bits */ b = (inp[0] << inpgap) & 0xff; if (bitrem) diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c index f3a1f054..21672a7e 100644 --- a/crypto/x509/by_dir.c +++ b/crypto/x509/by_dir.c @@ -10,12 +10,10 @@ #include #include #include +#include #include "internal/cryptlib.h" -#ifndef NO_SYS_TYPES_H -# include -#endif #ifndef OPENSSL_NO_POSIX_IO # include #endif diff --git a/crypto/x509/by_file.c b/crypto/x509/by_file.c index 4376bed8..0bcc6af3 100644 --- a/crypto/x509/by_file.c +++ b/crypto/x509/by_file.c @@ -42,12 +42,12 @@ static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, char **ret) { int ok = 0; - char *file; + const char *file; switch (cmd) { case X509_L_FILE_LOAD: if (argl == X509_FILETYPE_DEFAULT) { - file = (char *)getenv(X509_get_default_cert_file_env()); + file = getenv(X509_get_default_cert_file_env()); if (file) ok = (X509_load_cert_crl_file(ctx, file, X509_FILETYPE_PEM) != 0); @@ -90,7 +90,7 @@ int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) if (type == X509_FILETYPE_PEM) { for (;;) { - x = PEM_read_bio_X509_AUX(in, NULL, NULL, NULL); + x = PEM_read_bio_X509_AUX(in, NULL, NULL, ""); if (x == NULL) { if ((ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE) && (count > 0)) { @@ -147,7 +147,7 @@ int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) if (type == X509_FILETYPE_PEM) { for (;;) { - x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); + x = PEM_read_bio_X509_CRL(in, NULL, NULL, ""); if (x == NULL) { if ((ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE) && (count > 0)) { @@ -199,7 +199,7 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_SYS_LIB); return 0; } - inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); + inf = PEM_X509_INFO_read_bio(in, NULL, NULL, ""); BIO_free(in); if (!inf) { X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB); diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index eb65d887..c7ced67f 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -340,7 +340,7 @@ int X509_aux_print(BIO *out, X509 *x, int indent) BIO_puts(out, ", "); else first = 0; - OBJ_obj2txt(oidstr, sizeof oidstr, + OBJ_obj2txt(oidstr, sizeof(oidstr), sk_ASN1_OBJECT_value(trust, i), 0); BIO_puts(out, oidstr); } @@ -355,7 +355,7 @@ int X509_aux_print(BIO *out, X509 *x, int indent) BIO_puts(out, ", "); else first = 0; - OBJ_obj2txt(oidstr, sizeof oidstr, + OBJ_obj2txt(oidstr, sizeof(oidstr), sk_ASN1_OBJECT_value(reject, i), 0); BIO_puts(out, oidstr); } diff --git a/crypto/x509/x509_v3.c b/crypto/x509/x509_v3.c index 213e762f..19016bb1 100644 --- a/crypto/x509/x509_v3.c +++ b/crypto/x509/x509_v3.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -128,7 +128,8 @@ STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509err(X509_F_X509V3_ADD_EXT, ERR_R_MALLOC_FAILURE); err2: X509_EXTENSION_free(new_ex); - sk_X509_EXTENSION_free(sk); + if (x != NULL && *x == NULL) + sk_X509_EXTENSION_free(sk); return (NULL); } diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index ebc44240..3018c69a 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -216,7 +216,6 @@ static int verify_chain(X509_STORE_CTX *ctx) if ((ok = build_chain(ctx)) == 0 || (ok = check_chain_extensions(ctx)) == 0 || (ok = check_auth_level(ctx)) == 0 || - (ok = check_name_constraints(ctx)) == 0 || (ok = check_id(ctx)) == 0 || 1) X509_get_pubkey_parameters(NULL, ctx->chain); if (ok == 0 || (ok = ctx->check_revocation(ctx)) == 0) @@ -234,6 +233,9 @@ static int verify_chain(X509_STORE_CTX *ctx) if (!ok) return ok; + if ((ok = check_name_constraints(ctx)) == 0) + return ok; + #ifndef OPENSSL_NO_RFC3779 /* RFC 3779 path validation, now that CRL check has been done */ if ((ok = X509v3_asid_validate_path(ctx)) == 0) diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c index 97d735f8..0af5df5c 100644 --- a/crypto/x509/x_name.c +++ b/crypto/x509/x_name.c @@ -472,19 +472,11 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * _intname, int X509_NAME_set(X509_NAME **xn, X509_NAME *name) { - X509_NAME *in; - - if (!xn || !name) - return (0); - - if (*xn != name) { - in = X509_NAME_dup(name); - if (in != NULL) { - X509_NAME_free(*xn); - *xn = in; - } - } - return (*xn != NULL); + if ((name = X509_NAME_dup(name)) == NULL) + return 0; + X509_NAME_free(*xn); + *xn = name; + return 1; } int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase) diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c index 9f9246be..b3d1983f 100644 --- a/crypto/x509v3/pcy_tree.c +++ b/crypto/x509v3/pcy_tree.c @@ -638,6 +638,7 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, { int init_ret; int ret; + int calc_ret; X509_POLICY_TREE *tree = NULL; STACK_OF(X509_POLICY_NODE) *nodes, *auth_nodes = NULL; @@ -675,11 +676,14 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, } /* Tree is not empty: continue */ - if ((ret = tree_calculate_authority_set(tree, &auth_nodes)) == 0 || - !tree_calculate_user_set(tree, policy_oids, auth_nodes)) + + if ((calc_ret = tree_calculate_authority_set(tree, &auth_nodes)) == 0) goto error; - if (ret == TREE_CALC_OK_DOFREE) + ret = tree_calculate_user_set(tree, policy_oids, auth_nodes); + if (calc_ret == TREE_CALC_OK_DOFREE) sk_X509_POLICY_NODE_free(auth_nodes); + if (!ret) + goto error; *ptree = tree; diff --git a/crypto/x509v3/v3_addr.c b/crypto/x509v3/v3_addr.c index ef1d775a..c5183a17 100644 --- a/crypto/x509v3/v3_addr.c +++ b/crypto/x509v3/v3_addr.c @@ -84,10 +84,12 @@ static int length_from_afi(const unsigned afi) */ unsigned int X509v3_addr_get_afi(const IPAddressFamily *f) { - return ((f != NULL && - f->addressFamily != NULL && f->addressFamily->data != NULL) - ? ((f->addressFamily->data[0] << 8) | (f->addressFamily->data[1])) - : 0); + if (f == NULL + || f->addressFamily == NULL + || f->addressFamily->data == NULL + || f->addressFamily->length < 2) + return 0; + return (f->addressFamily->data[0] << 8) | f->addressFamily->data[1]; } /* diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c index 93f8c25c..a35d3376 100644 --- a/crypto/x509v3/v3_alt.c +++ b/crypto/x509v3/v3_alt.c @@ -108,12 +108,12 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, case GEN_IPADD: p = gen->d.ip->data; if (gen->d.ip->length == 4) - BIO_snprintf(oline, sizeof oline, + BIO_snprintf(oline, sizeof(oline), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); else if (gen->d.ip->length == 16) { oline[0] = 0; for (i = 0; i < 8; i++) { - BIO_snprintf(htmp, sizeof htmp, "%X", p[0] << 8 | p[1]); + BIO_snprintf(htmp, sizeof(htmp), "%X", p[0] << 8 | p[1]); p += 2; strcat(oline, htmp); if (i != 7) diff --git a/crypto/x509v3/v3_conf.c b/crypto/x509v3/v3_conf.c index f625ff54..3cc5b14d 100644 --- a/crypto/x509v3/v3_conf.c +++ b/crypto/x509v3/v3_conf.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -313,8 +313,12 @@ int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section, return 0; if (ctx->flags == X509V3_CTX_REPLACE) delete_ext(*sk, ext); - if (sk) - X509v3_add_ext(sk, ext, -1); + if (sk != NULL) { + if (X509v3_add_ext(sk, ext, -1) == NULL) { + X509_EXTENSION_free(ext); + return 0; + } + } X509_EXTENSION_free(ext); } return 1; diff --git a/crypto/x509v3/v3_genn.c b/crypto/x509v3/v3_genn.c index 8d119974..85fc3fc2 100644 --- a/crypto/x509v3/v3_genn.c +++ b/crypto/x509v3/v3_genn.c @@ -181,6 +181,7 @@ int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, oth = OTHERNAME_new(); if (oth == NULL) return 0; + ASN1_TYPE_free(oth->value); oth->type_id = oid; oth->value = value; GENERAL_NAME_set0_value(gen, GEN_OTHERNAME, oth); diff --git a/crypto/x509v3/v3_info.c b/crypto/x509v3/v3_info.c index c29c7e2a..a0bca5fb 100644 --- a/crypto/x509v3/v3_info.c +++ b/crypto/x509v3/v3_info.c @@ -77,7 +77,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS( goto err; tret = tmp; vtmp = sk_CONF_VALUE_value(tret, i); - i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method); + i2t_ASN1_OBJECT(objtmp, sizeof(objtmp), desc->method); nlen = strlen(objtmp) + strlen(vtmp->name) + 5; ntmp = OPENSSL_malloc(nlen); if (ntmp == NULL) diff --git a/crypto/x509v3/v3_lib.c b/crypto/x509v3/v3_lib.c index a3ca720f..d7143086 100644 --- a/crypto/x509v3/v3_lib.c +++ b/crypto/x509v3/v3_lib.c @@ -120,6 +120,7 @@ const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid) X509V3_EXT_METHOD tmp; const X509V3_EXT_METHOD *t = &tmp, *const *ret; int idx; + if (nid < 0) return NULL; tmp.ext_nid = nid; @@ -231,6 +232,7 @@ void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, { int lastpos, i; X509_EXTENSION *ex, *found_ex = NULL; + if (!x) { if (idx) *idx = -1; @@ -284,9 +286,9 @@ void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int crit, unsigned long flags) { - int extidx = -1; - int errcode; - X509_EXTENSION *ext, *extmp; + int errcode, extidx = -1; + X509_EXTENSION *ext = NULL, *extmp; + STACK_OF(X509_EXTENSION) *ret = NULL; unsigned long ext_op = flags & X509V3_ADD_OP_MASK; /* @@ -345,14 +347,23 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, return 1; } + ret = *x; if (*x == NULL - && (*x = sk_X509_EXTENSION_new_null()) == NULL) - return -1; - if (!sk_X509_EXTENSION_push(*x, ext)) - return -1; + && (ret = sk_X509_EXTENSION_new_null()) == NULL) + goto m_fail; + if (!sk_X509_EXTENSION_push(ret, ext)) + goto m_fail; + *x = ret; return 1; + m_fail: + /* X509V3err(X509V3_F_X509V3_ADD1_I2D, ERR_R_MALLOC_FAILURE); */ + if (ret != *x) + sk_X509_EXTENSION_free(ret); + X509_EXTENSION_free(ext); + return -1; + err: if (!(flags & X509V3_ADD_SILENT)) X509V3err(X509V3_F_X509V3_ADD1_I2D, errcode); diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c index 9b3bb128..2eec405a 100644 --- a/crypto/x509v3/v3_ncons.c +++ b/crypto/x509v3/v3_ncons.c @@ -9,6 +9,7 @@ #include #include "internal/cryptlib.h" +#include "internal/numbers.h" #include "internal/asn1_int.h" #include #include @@ -62,6 +63,46 @@ ASN1_SEQUENCE(NAME_CONSTRAINTS) = { IMPLEMENT_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE) IMPLEMENT_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS) +/* + * We cannot use strncasecmp here because that applies locale specific rules. + * For example in Turkish 'I' is not the uppercase character for 'i'. We need to + * do a simple ASCII case comparison ignoring the locale (that is why we use + * numeric constants below). + */ +static int ia5ncasecmp(const char *s1, const char *s2, size_t n) +{ + for (; n > 0; n--, s1++, s2++) { + if (*s1 != *s2) { + unsigned char c1 = (unsigned char)*s1, c2 = (unsigned char)*s2; + + /* Convert to lower case */ + if (c1 >= 0x41 /* A */ && c1 <= 0x5A /* Z */) + c1 += 0x20; + if (c2 >= 0x41 /* A */ && c2 <= 0x5A /* Z */) + c2 += 0x20; + + if (c1 == c2) + continue; + + if (c1 < c2) + return -1; + + /* c1 > c2 */ + return 1; + } else if (*s1 == 0) { + /* If we get here we know that *s2 == 0 too */ + return 0; + } + } + + return 0; +} + +static int ia5casecmp(const char *s1, const char *s2) +{ + return ia5ncasecmp(s1, s2, SIZE_MAX); +} + static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) { @@ -165,6 +206,22 @@ static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip) return 1; } +#define NAME_CHECK_MAX (1 << 20) + +static int add_lengths(int *out, int a, int b) +{ + /* sk_FOO_num(NULL) returns -1 but is effectively 0 when iterating. */ + if (a < 0) + a = 0; + if (b < 0) + b = 0; + + if (a > INT_MAX - b) + return 0; + *out = a + b; + return 1; +} + /*- * Check a certificate conforms to a specified set of constraints. * Return values: @@ -179,11 +236,23 @@ static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip) int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc) { - int r, i; + int r, i, name_count, constraint_count; X509_NAME *nm; nm = X509_get_subject_name(x); + /* + * Guard against certificates with an excessive number of names or + * constraints causing a computationally expensive name constraints check. + */ + if (!add_lengths(&name_count, X509_NAME_entry_count(nm), + sk_GENERAL_NAME_num(x->altname)) + || !add_lengths(&constraint_count, + sk_GENERAL_SUBTREE_num(nc->permittedSubtrees), + sk_GENERAL_SUBTREE_num(nc->excludedSubtrees)) + || (name_count > 0 && constraint_count > NAME_CHECK_MAX / name_count)) + return X509_V_ERR_UNSPECIFIED; + if (X509_NAME_entry_count(nm) > 0) { GENERAL_NAME gntmp; gntmp.type = GEN_DIRNAME; @@ -387,7 +456,7 @@ static int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base) return X509_V_ERR_PERMITTED_VIOLATION; } - if (strcasecmp(baseptr, dnsptr)) + if (ia5casecmp(baseptr, dnsptr)) return X509_V_ERR_PERMITTED_VIOLATION; return X509_V_OK; @@ -407,7 +476,7 @@ static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base) if (!baseat && (*baseptr == '.')) { if (eml->length > base->length) { emlptr += eml->length - base->length; - if (strcasecmp(baseptr, emlptr) == 0) + if (ia5casecmp(baseptr, emlptr) == 0) return X509_V_OK; } return X509_V_ERR_PERMITTED_VIOLATION; @@ -428,7 +497,7 @@ static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base) } emlptr = emlat + 1; /* Just have hostname left to match: case insensitive */ - if (strcasecmp(baseptr, emlptr)) + if (ia5casecmp(baseptr, emlptr)) return X509_V_ERR_PERMITTED_VIOLATION; return X509_V_OK; @@ -467,14 +536,14 @@ static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base) if (*baseptr == '.') { if (hostlen > base->length) { p = hostptr + hostlen - base->length; - if (strncasecmp(p, baseptr, base->length) == 0) + if (ia5ncasecmp(p, baseptr, base->length) == 0) return X509_V_OK; } return X509_V_ERR_PERMITTED_VIOLATION; } if ((base->length != (int)hostlen) - || strncasecmp(hostptr, baseptr, hostlen)) + || ia5ncasecmp(hostptr, baseptr, hostlen)) return X509_V_ERR_PERMITTED_VIOLATION; return X509_V_OK; diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index fa5c425f..6d2f354d 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -847,6 +847,13 @@ const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x) return x->skid; } +const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x) +{ + /* Call for side-effect of computing hash and caching extensions */ + X509_check_purpose(x, -1, -1); + return (x->akid != NULL ? x->akid->keyid : NULL); +} + long X509_get_pathlen(X509 *x) { /* Called for side effect of caching extensions */ diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index 7dc9a453..418ef06a 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -13,6 +13,7 @@ #include #include "internal/cryptlib.h" #include +#include #include #include "internal/x509_int.h" #include @@ -37,6 +38,7 @@ int X509V3_add_value(const char *name, const char *value, { CONF_VALUE *vtmp = NULL; char *tname = NULL, *tvalue = NULL; + int sk_allocated = (*extlist == NULL); if (name && (tname = OPENSSL_strdup(name)) == NULL) goto err; @@ -44,7 +46,7 @@ int X509V3_add_value(const char *name, const char *value, goto err; if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL) goto err; - if (*extlist == NULL && (*extlist = sk_CONF_VALUE_new_null()) == NULL) + if (sk_allocated && (*extlist = sk_CONF_VALUE_new_null()) == NULL) goto err; vtmp->section = NULL; vtmp->name = tname; @@ -54,6 +56,10 @@ int X509V3_add_value(const char *name, const char *value, return 1; err: X509V3err(X509V3_F_X509V3_ADD_VALUE, ERR_R_MALLOC_FAILURE); + if (sk_allocated) { + sk_CONF_VALUE_free(*extlist); + *extlist = NULL; + } OPENSSL_free(vtmp); OPENSSL_free(tname); OPENSSL_free(tvalue); @@ -94,6 +100,43 @@ int X509V3_add_value_bool_nf(const char *name, int asn1_bool, return 1; } +static char *bignum_to_string(const BIGNUM *bn) +{ + char *tmp, *ret; + size_t len; + + /* + * Display large numbers in hex and small numbers in decimal. Converting to + * decimal takes quadratic time and is no more useful than hex for large + * numbers. + */ + if (BN_num_bits(bn) < 128) + return BN_bn2dec(bn); + + tmp = BN_bn2hex(bn); + if (tmp == NULL) + return NULL; + + len = strlen(tmp) + 3; + ret = OPENSSL_malloc(len); + if (ret == NULL) { + X509V3err(X509V3_F_BIGNUM_TO_STRING, ERR_R_MALLOC_FAILURE); + OPENSSL_free(tmp); + return NULL; + } + + /* Prepend "0x", but place it after the "-" if negative. */ + if (tmp[0] == '-') { + OPENSSL_strlcpy(ret, "-0x", len); + OPENSSL_strlcat(ret, tmp + 1, len); + } else { + OPENSSL_strlcpy(ret, "0x", len); + OPENSSL_strlcat(ret, tmp, len); + } + OPENSSL_free(tmp); + return ret; +} + char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, const ASN1_ENUMERATED *a) { BIGNUM *bntmp = NULL; @@ -102,7 +145,7 @@ char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, const ASN1_ENUMERATED *a) if (!a) return NULL; if ((bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) == NULL - || (strtmp = BN_bn2dec(bntmp)) == NULL) + || (strtmp = bignum_to_string(bntmp)) == NULL) X509V3err(X509V3_F_I2S_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); BN_free(bntmp); return strtmp; @@ -116,7 +159,7 @@ char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, const ASN1_INTEGER *a) if (!a) return NULL; if ((bntmp = ASN1_INTEGER_to_BN(a, NULL)) == NULL - || (strtmp = BN_bn2dec(bntmp)) == NULL) + || (strtmp = bignum_to_string(bntmp)) == NULL) X509V3err(X509V3_F_I2S_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); BN_free(bntmp); return strtmp; diff --git a/crypto/x509v3/v3err.c b/crypto/x509v3/v3err.c index 5d79c8c6..d5987913 100644 --- a/crypto/x509v3/v3err.c +++ b/crypto/x509v3/v3err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -26,6 +26,7 @@ static ERR_STRING_DATA X509V3_str_functs[] = { "ASIdentifierChoice_canonize"}, {ERR_FUNC(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL), "ASIdentifierChoice_is_canonical"}, + {ERR_FUNC(X509V3_F_BIGNUM_TO_STRING), "bignum_to_string"}, {ERR_FUNC(X509V3_F_COPY_EMAIL), "copy_email"}, {ERR_FUNC(X509V3_F_COPY_ISSUER), "copy_issuer"}, {ERR_FUNC(X509V3_F_DO_DIRNAME), "do_dirname"}, diff --git a/crypto/x86_64cpuid.pl b/crypto/x86_64cpuid.pl index afc50af0..1a6f728d 100644 --- a/crypto/x86_64cpuid.pl +++ b/crypto/x86_64cpuid.pl @@ -143,8 +143,19 @@ OPENSSL_ia32_cpuid: or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs and \$15,%ah cmp \$15,%ah # examine Family ID - jne .Lnotintel + jne .LnotP4 or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR +.LnotP4: + cmp \$6,%ah + jne .Lnotintel + and \$0x0fff0ff0,%eax + cmp \$0x00050670,%eax # Knights Landing + je .Lknights + cmp \$0x00080650,%eax # Knights Mill (according to sde) + jne .Lnotintel +.Lknights: + and \$0xfbffffff,%ecx # clear XSAVE flag to mimic Silvermont + .Lnotintel: bt \$28,%edx # test hyper-threading bit jnc .Lgeneric @@ -169,6 +180,10 @@ OPENSSL_ia32_cpuid: mov \$7,%eax xor %ecx,%ecx cpuid + bt \$26,%r9d # check XSAVE bit, cleared on Knights + jc .Lnotknights + and \$0xfff7ffff,%ebx # clear ADCX/ADOX flag +.Lnotknights: mov %ebx,8(%rdi) # save extended feature flags .Lno_extended_info: @@ -182,7 +197,7 @@ OPENSSL_ia32_cpuid: .Lclear_avx: mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11) and %eax,%r9d # clear AVX, FMA and AMD XOP bits - andl \$0xffffffdf,8(%rdi) # cleax AVX2, ~(1<<5) + andl \$0xffffffdf,8(%rdi) # clear AVX2, ~(1<<5) .Ldone: shl \$32,%r9 mov %r10d,%eax diff --git a/demos/bio/cmod.cnf b/demos/bio/cmod.cnf index 4c45dfb7..39ac54ed 100644 --- a/demos/bio/cmod.cnf +++ b/demos/bio/cmod.cnf @@ -5,7 +5,7 @@ testapp = test_sect [test_sect] -# list of confuration modules +# list of configuration modules # SSL configuration module ssl_conf = ssl_sect diff --git a/doc/HOWTO/keys.txt b/doc/HOWTO/keys.txt index ba0314fa..1662c170 100644 --- a/doc/HOWTO/keys.txt +++ b/doc/HOWTO/keys.txt @@ -27,12 +27,6 @@ With this variant, you will be prompted for a protecting password. If you don't want your key to be protected by a password, remove the flag '-des3' from the command line above. - NOTE: if you intend to use the key together with a server - certificate, it may be a good thing to avoid protecting it - with a password, since that would mean someone would have to - type in the password every time the server needs to access - the key. - The number 2048 is the size of the key, in bits. Today, 2048 or higher is recommended for RSA keys, as fewer amount of bits is consider insecure or to be insecure pretty soon. @@ -62,11 +56,50 @@ With this variant, you will be prompted for a protecting password. If you don't want your key to be protected by a password, remove the flag '-des3' from the command line above. - NOTE: if you intend to use the key together with a server - certificate, it may be a good thing to avoid protecting it - with a password, since that would mean someone would have to - type in the password every time the server needs to access - the key. --- -Richard Levitte +4. To generate an EC key + +An EC key can be used both for key agreement (ECDH) and signing (ECDSA). + +Generating a key for ECC is similar to generating a DSA key. These are +two-step processes. First, you have to get the EC parameters from which +the key will be generated: + + openssl ecparam -name prime256v1 -out prime256v1.pem + +The prime256v1, or NIST P-256, which stands for 'X9.62/SECG curve over +a 256-bit prime field', is the name of an elliptic curve which generates the +parameters. You can use the following command to list all supported curves: + + openssl ecparam -list_curves + +When that is done, you can generate a key using the created parameters (several +keys can be produced from the same parameters): + + openssl genpkey -des3 -paramfile prime256v1.pem -out private.key + +With this variant, you will be prompted for a password to protect your key. +If you don't want your key to be protected by a password, remove the flag +'-des3' from the command line above. + +You can also directly generate the key in one step: + + openssl ecparam -genkey -name prime256v1 -out private.key + +or + + openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 + + +5. NOTE + +If you intend to use the key together with a server certificate, +it may be reasonable to avoid protecting it with a password, since +otherwise someone would have to type in the password every time the +server needs to access the key. + +For X25519, it's treated as a distinct algorithm but not as one of +the curves listed with 'ecparam -list_curves' option. You can use +the following command to generate an X25519 key: + + openssl genpkey -algorithm X25519 -out xkey.pem diff --git a/doc/apps/asn1parse.pod b/doc/apps/asn1parse.pod index 10a5aba5..3c607e8a 100644 --- a/doc/apps/asn1parse.pod +++ b/doc/apps/asn1parse.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-asn1parse, asn1parse - ASN.1 parsing tool =head1 SYNOPSIS diff --git a/doc/apps/ca.pod b/doc/apps/ca.pod index c09db826..9918a136 100644 --- a/doc/apps/ca.pod +++ b/doc/apps/ca.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-ca, ca - sample minimal CA application =head1 SYNOPSIS @@ -442,6 +443,10 @@ versions of OpenSSL. However, to make CA certificate roll-over easier, it's recommended to use the value B, especially if combined with the B<-selfsign> command line option. +Note that it is valid in some circumstances for certificates to be created +without any subject. In the case where there are multiple certificates without +subjects this does not count as a duplicate. + =item B a text file containing the next serial number to use in hex. Mandatory. @@ -709,7 +714,7 @@ L, L =head1 COPYRIGHT -Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/apps/ciphers.pod b/doc/apps/ciphers.pod index 03cac2f1..def3bdc3 100644 --- a/doc/apps/ciphers.pod +++ b/doc/apps/ciphers.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-ciphers, ciphers - SSL cipher display and cipher list tool =head1 SYNOPSIS diff --git a/doc/apps/cms.pod b/doc/apps/cms.pod index b97120a0..96acd315 100644 --- a/doc/apps/cms.pod +++ b/doc/apps/cms.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-cms, cms - CMS utility =head1 SYNOPSIS @@ -185,7 +186,7 @@ output an error. =item B<-EncryptedData_encrypt> Encrypt content using supplied symmetric key and algorithm using a CMS -B type and output the content. +B type and output the content. =item B<-sign_receipt> diff --git a/doc/apps/crl.pod b/doc/apps/crl.pod index 2fad2101..fded3972 100644 --- a/doc/apps/crl.pod +++ b/doc/apps/crl.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-crl, crl - CRL utility =head1 SYNOPSIS diff --git a/doc/apps/crl2pkcs7.pod b/doc/apps/crl2pkcs7.pod index 8c679ea8..933750ad 100644 --- a/doc/apps/crl2pkcs7.pod +++ b/doc/apps/crl2pkcs7.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-crl2pkcs7, crl2pkcs7 - Create a PKCS#7 structure from a CRL and certificates =head1 SYNOPSIS diff --git a/doc/apps/dgst.pod b/doc/apps/dgst.pod index 677f2b21..59919c32 100644 --- a/doc/apps/dgst.pod +++ b/doc/apps/dgst.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-dgst, dgst, sha, sha1, mdc2, ripemd160, sha224, sha256, sha384, sha512, md4, md5, blake2b, blake2s - message digests =head1 SYNOPSIS diff --git a/doc/apps/dhparam.pod b/doc/apps/dhparam.pod index addd88a5..52fc0df3 100644 --- a/doc/apps/dhparam.pod +++ b/doc/apps/dhparam.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-dhparam, dhparam - DH parameter manipulation and generation =head1 SYNOPSIS diff --git a/doc/apps/dsa.pod b/doc/apps/dsa.pod index 0e4f508f..37358044 100644 --- a/doc/apps/dsa.pod +++ b/doc/apps/dsa.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-dsa, dsa - DSA key processing =head1 SYNOPSIS diff --git a/doc/apps/dsaparam.pod b/doc/apps/dsaparam.pod index 08ad47fa..0dfda660 100644 --- a/doc/apps/dsaparam.pod +++ b/doc/apps/dsaparam.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-dsaparam, dsaparam - DSA parameter manipulation and generation =head1 SYNOPSIS diff --git a/doc/apps/ec.pod b/doc/apps/ec.pod index a5f920e8..c06005d8 100644 --- a/doc/apps/ec.pod +++ b/doc/apps/ec.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-ec, ec - EC key processing =head1 SYNOPSIS diff --git a/doc/apps/ecparam.pod b/doc/apps/ecparam.pod index 51678964..69a26319 100644 --- a/doc/apps/ecparam.pod +++ b/doc/apps/ecparam.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-ecparam, ecparam - EC parameter manipulation and generation =head1 SYNOPSIS @@ -90,8 +91,8 @@ currently implemented EC parameters names and exit. =item B<-conv_form> This specifies how the points on the elliptic curve are converted -into octet strings. Possible values are: B (the default -value), B and B. For more information regarding +into octet strings. Possible values are: B, B (the +default value) and B. For more information regarding the point conversion forms please read the X9.62 standard. B Due to patent issues the B option is disabled by default for binary curves and can be enabled by defining @@ -175,7 +176,7 @@ L, L =head1 COPYRIGHT -Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2003-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/apps/enc.pod b/doc/apps/enc.pod index b3bf82ad..6338d6c8 100644 --- a/doc/apps/enc.pod +++ b/doc/apps/enc.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-enc, enc - symmetric cipher routines =head1 SYNOPSIS diff --git a/doc/apps/engine.pod b/doc/apps/engine.pod index 674ab565..155cc629 100644 --- a/doc/apps/engine.pod +++ b/doc/apps/engine.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-engine, engine - load and query engines =head1 SYNOPSIS @@ -92,9 +93,19 @@ To list the capabilities of the I engine: [RSA] (dynamic) Dynamic engine loading support +=head1 ENVIRONMENT + +=over 4 + +=item B + +The path to the engines directory. + +=back + =head1 COPYRIGHT -Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/apps/errstr.pod b/doc/apps/errstr.pod index 8dfe49a5..3c89b8f5 100644 --- a/doc/apps/errstr.pod +++ b/doc/apps/errstr.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-errstr, errstr - lookup error codes =head1 SYNOPSIS diff --git a/doc/apps/gendsa.pod b/doc/apps/gendsa.pod index 4fd17147..36c810a9 100644 --- a/doc/apps/gendsa.pod +++ b/doc/apps/gendsa.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-gendsa, gendsa - generate a DSA private key from a set of parameters =head1 SYNOPSIS diff --git a/doc/apps/genpkey.pod b/doc/apps/genpkey.pod index e77fc7ef..d4869520 100644 --- a/doc/apps/genpkey.pod +++ b/doc/apps/genpkey.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-genpkey, genpkey - generate a private key =head1 SYNOPSIS diff --git a/doc/apps/genrsa.pod b/doc/apps/genrsa.pod index f4ed9593..8be06834 100644 --- a/doc/apps/genrsa.pod +++ b/doc/apps/genrsa.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-genrsa, genrsa - generate an RSA private key =head1 SYNOPSIS diff --git a/doc/apps/list.pod b/doc/apps/list.pod index e6e1f176..10887626 100644 --- a/doc/apps/list.pod +++ b/doc/apps/list.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-list, list - list algorithms and features =head1 SYNOPSIS diff --git a/doc/apps/nseq.pod b/doc/apps/nseq.pod index a90f8a00..6b25e221 100644 --- a/doc/apps/nseq.pod +++ b/doc/apps/nseq.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-nseq, nseq - create or examine a Netscape certificate sequence =head1 SYNOPSIS diff --git a/doc/apps/ocsp.pod b/doc/apps/ocsp.pod index ec82088f..5e273cfe 100644 --- a/doc/apps/ocsp.pod +++ b/doc/apps/ocsp.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-ocsp, ocsp - Online Certificate Status Protocol utility =head1 SYNOPSIS diff --git a/doc/apps/openssl.pod b/doc/apps/openssl.pod index 7fc53c9b..6e822a61 100644 --- a/doc/apps/openssl.pod +++ b/doc/apps/openssl.pod @@ -182,6 +182,10 @@ PKCS#12 Data Management. PKCS#7 Data Management. +=item L|pkcs8(1)> + +PKCS#8 format private key conversion tool. + =item L|pkey(1)> Public and private key management. @@ -198,6 +202,10 @@ Public key algorithm cryptographic operation utility. Generate pseudo-random bytes. +=item L|rehash(1)> + +Create symbolic links to certificate and CRL files named by the hash values. + =item L|req(1)> PKCS#10 X.509 Certificate Signing Request (CSR) Management. @@ -418,17 +426,20 @@ Read the password from standard input. =head1 SEE ALSO -L, L, L, +L, L, L, L, L, L, L, L, L, L, L, -L, L, L, L, -L, L, L, +L, L, +L, L, L, L, L, +L, L, L, L, L, L, L, -L, L, L, +L, L, L, +L, L, L, L, L, L, -L, L, -L, L, +L, L, L, +L, L, L, +L, L, L, L, L, L, L diff --git a/doc/apps/passwd.pod b/doc/apps/passwd.pod index 87dd8d86..46632014 100644 --- a/doc/apps/passwd.pod +++ b/doc/apps/passwd.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-passwd, passwd - compute password hashes =head1 SYNOPSIS diff --git a/doc/apps/pkcs12.pod b/doc/apps/pkcs12.pod index 2df47769..44ee3d4e 100644 --- a/doc/apps/pkcs12.pod +++ b/doc/apps/pkcs12.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-pkcs12, pkcs12 - PKCS#12 file utility =head1 SYNOPSIS diff --git a/doc/apps/pkcs7.pod b/doc/apps/pkcs7.pod index d238946b..340b72da 100644 --- a/doc/apps/pkcs7.pod +++ b/doc/apps/pkcs7.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-pkcs7, pkcs7 - PKCS#7 utility =head1 SYNOPSIS diff --git a/doc/apps/pkcs8.pod b/doc/apps/pkcs8.pod index dee64a00..402e7b2b 100644 --- a/doc/apps/pkcs8.pod +++ b/doc/apps/pkcs8.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-pkcs8, pkcs8 - PKCS#8 format private key conversion tool =head1 SYNOPSIS diff --git a/doc/apps/pkey.pod b/doc/apps/pkey.pod index 2119c70c..ef2e4633 100644 --- a/doc/apps/pkey.pod +++ b/doc/apps/pkey.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-pkey, pkey - public or private key processing tool =head1 SYNOPSIS diff --git a/doc/apps/pkeyparam.pod b/doc/apps/pkeyparam.pod index 755915ff..309e2495 100644 --- a/doc/apps/pkeyparam.pod +++ b/doc/apps/pkeyparam.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-pkeyparam, pkeyparam - public key algorithm parameter processing tool =head1 SYNOPSIS diff --git a/doc/apps/pkeyutl.pod b/doc/apps/pkeyutl.pod index ceb9de34..e72486de 100644 --- a/doc/apps/pkeyutl.pod +++ b/doc/apps/pkeyutl.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-pkeyutl, pkeyutl - public key algorithm utility =head1 SYNOPSIS diff --git a/doc/apps/rand.pod b/doc/apps/rand.pod index 0faf6872..4cdb3705 100644 --- a/doc/apps/rand.pod +++ b/doc/apps/rand.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-rand, rand - generate pseudo-random bytes =head1 SYNOPSIS diff --git a/doc/apps/rehash.pod b/doc/apps/rehash.pod index 1dca9b53..79268d47 100644 --- a/doc/apps/rehash.pod +++ b/doc/apps/rehash.pod @@ -5,6 +5,7 @@ Original text by James Westby, contributed under the OpenSSL license. =head1 NAME +openssl-c_rehash, openssl-rehash, c_rehash, rehash - Create symbolic links to files named by the hash values =head1 SYNOPSIS diff --git a/doc/apps/req.pod b/doc/apps/req.pod index 8cfe2bc5..c5b5260c 100644 --- a/doc/apps/req.pod +++ b/doc/apps/req.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-req, req - PKCS#10 certificate request and certificate generating utility =head1 SYNOPSIS diff --git a/doc/apps/rsa.pod b/doc/apps/rsa.pod index 8e9943fe..dcbf5142 100644 --- a/doc/apps/rsa.pod +++ b/doc/apps/rsa.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-rsa, rsa - RSA key processing tool =head1 SYNOPSIS diff --git a/doc/apps/rsautl.pod b/doc/apps/rsautl.pod index 038f00be..c07d60ae 100644 --- a/doc/apps/rsautl.pod +++ b/doc/apps/rsautl.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-rsautl, rsautl - RSA utility =head1 SYNOPSIS @@ -115,7 +116,7 @@ Recover the signed data Examine the raw signed data: - openssl rsautl -verify -in file -inkey key.pem -raw -hexdump + openssl rsautl -verify -in sig -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_client.pod b/doc/apps/s_client.pod index 43989d0c..01a6c5f7 100644 --- a/doc/apps/s_client.pod +++ b/doc/apps/s_client.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-s_client, s_client - SSL/TLS client program =head1 SYNOPSIS @@ -346,12 +347,14 @@ Can be used to override the implicit B<-ign_eof> after B<-quiet>. =item B<-psk_identity identity> Use the PSK identity B when using a PSK cipher suite. +The default value is "Client_identity" (without the quotes). =item B<-psk key> Use the PSK key B when using a PSK cipher suite. The key is given as a hexadecimal number without leading 0x, for example -psk 1a2b3c4d. +This option must be provided in order to use a PSK cipher. =item B<-ssl3>, B<-tls1>, B<-tls1_1>, B<-tls1_2>, B<-no_ssl3>, B<-no_tls1>, B<-no_tls1_1>, B<-no_tls1_2> diff --git a/doc/apps/s_server.pod b/doc/apps/s_server.pod index ad718679..e8ec91b4 100644 --- a/doc/apps/s_server.pod +++ b/doc/apps/s_server.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-s_server, s_server - SSL/TLS server program =head1 SYNOPSIS @@ -323,6 +324,7 @@ Use the PSK identity hint B when using a PSK cipher suite. Use the PSK key B when using a PSK cipher suite. The key is given as a hexadecimal number without leading 0x, for example -psk 1a2b3c4d. +This option must be provided in order to use a PSK cipher. =item B<-ssl2>, B<-ssl3>, B<-tls1>, B<-tls1_1>, B<-tls1_2>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1>, B<-no_tls1_1>, B<-no_tls1_2> @@ -574,10 +576,6 @@ a web browser the command: can be used for example. -Most web browsers (in particular Netscape and MSIE) only support RSA cipher -suites, so they cannot connect to servers which don't use a certificate -carrying an RSA key or a version of OpenSSL with RSA disabled. - Although specifying an empty list of CAs when requesting a client certificate is strictly speaking a protocol violation, some SSL clients interpret this to mean any CA is acceptable. This is useful for debugging purposes. diff --git a/doc/apps/s_time.pod b/doc/apps/s_time.pod index acadd300..d44dd935 100644 --- a/doc/apps/s_time.pod +++ b/doc/apps/s_time.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-s_time, s_time - SSL/TLS performance timing program =head1 SYNOPSIS diff --git a/doc/apps/sess_id.pod b/doc/apps/sess_id.pod index 19ac9a75..7766c71e 100644 --- a/doc/apps/sess_id.pod +++ b/doc/apps/sess_id.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-sess_id, sess_id - SSL/TLS session handling utility =head1 SYNOPSIS diff --git a/doc/apps/smime.pod b/doc/apps/smime.pod index d3e02146..753e2757 100644 --- a/doc/apps/smime.pod +++ b/doc/apps/smime.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-smime, smime - S/MIME utility =head1 SYNOPSIS diff --git a/doc/apps/speed.pod b/doc/apps/speed.pod index ad81bfbc..4379319d 100644 --- a/doc/apps/speed.pod +++ b/doc/apps/speed.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-speed, speed - test library performance =head1 SYNOPSIS diff --git a/doc/apps/spkac.pod b/doc/apps/spkac.pod index 8955bc44..e337e4e7 100644 --- a/doc/apps/spkac.pod +++ b/doc/apps/spkac.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-spkac, spkac - SPKAC printing and generating utility =head1 SYNOPSIS diff --git a/doc/apps/ts.pod b/doc/apps/ts.pod index cf30947d..0c949bfb 100644 --- a/doc/apps/ts.pod +++ b/doc/apps/ts.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-ts, ts - Time Stamping Authority tool (client/server) =head1 SYNOPSIS diff --git a/doc/apps/tsget.pod b/doc/apps/tsget.pod index cf7817a0..f566f3a4 100644 --- a/doc/apps/tsget.pod +++ b/doc/apps/tsget.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-tsget, tsget - Time Stamping HTTP/HTTPS client =head1 SYNOPSIS diff --git a/doc/apps/verify.pod b/doc/apps/verify.pod index 8ba5ff67..38fa346f 100644 --- a/doc/apps/verify.pod +++ b/doc/apps/verify.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-verify, verify - Utility to verify certificates =head1 SYNOPSIS diff --git a/doc/apps/version.pod b/doc/apps/version.pod index a97ed204..305a1b74 100644 --- a/doc/apps/version.pod +++ b/doc/apps/version.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-version, version - print OpenSSL version information =head1 SYNOPSIS diff --git a/doc/apps/x509.pod b/doc/apps/x509.pod index cddfc8ce..f2dcef2e 100644 --- a/doc/apps/x509.pod +++ b/doc/apps/x509.pod @@ -2,6 +2,7 @@ =head1 NAME +openssl-x509, x509 - Certificate display and signing utility =head1 SYNOPSIS @@ -230,8 +231,11 @@ non-zero if yes it will expire or zero if not. =item B<-fingerprint> -prints out the digest of the DER encoded version of the whole certificate -(see digest options). +Calculates and outputs the digest of the DER encoded version of the entire +certificate (see digest options). +This is commonly called a "fingerprint". Because of the nature of message +digests, the fingerprint of a certificate is unique to that certificate and +two certificates with the same fingerprint can be considered to be the same. =item B<-C> @@ -686,10 +690,6 @@ supporting UTF8: openssl x509 -in cert.pem -noout -subject -nameopt oneline,-esc_msb -Display the certificate MD5 fingerprint: - - openssl x509 -in cert.pem -noout -fingerprint - Display the certificate SHA1 fingerprint: openssl x509 -sha1 -in cert.pem -noout -fingerprint @@ -743,13 +743,6 @@ T61Strings use the ISO8859-1 character set. This is wrong but Netscape and MSIE do this as do many certificates. So although this is incorrect it is more likely to display the majority of certificates correctly. -The B<-fingerprint> option takes the digest of the DER encoded certificate. -This is commonly called a "fingerprint". Because of the nature of message -digests the fingerprint of a certificate is unique to that certificate and -two certificates with the same fingerprint can be considered to be the same. - -The Netscape fingerprint uses MD5 whereas MSIE uses SHA1. - The B<-email> option searches the subject name and the subject alternative name extension. Only unique email addresses will be printed out: it will not print the same address more than once. @@ -895,7 +888,7 @@ the old form must have their links rebuilt using B or similar. =head1 COPYRIGHT -Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/apps/x509v3_config.pod b/doc/apps/x509v3_config.pod index 17d9f1c3..c0742c84 100644 --- a/doc/apps/x509v3_config.pod +++ b/doc/apps/x509v3_config.pod @@ -352,7 +352,7 @@ Example: noticeNumbers=1,2,3,4 The B option changes the type of the I field. In RFC2459 -it can only be of type DisplayText. In RFC3280 IA5Strring is also permissible. +it can only be of type DisplayText. In RFC3280 IA5String is also permissible. Some software (for example some versions of MSIE) may require ia5org. =head2 Policy Constraints diff --git a/doc/crypto/ASN1_STRING_length.pod b/doc/crypto/ASN1_STRING_length.pod index 26cb1761..20a372dc 100644 --- a/doc/crypto/ASN1_STRING_length.pod +++ b/doc/crypto/ASN1_STRING_length.pod @@ -71,8 +71,8 @@ utility functions should be used instead. In general it cannot be assumed that the data returned by ASN1_STRING_data() is null terminated or does not contain embedded nulls. The actual format of the data will depend on the actual string type itself: for example -for and IA5String the data will be ASCII, for a BMPString two bytes per -character in big endian format, UTF8String will be in UTF8 format. +for an IA5String the data will be ASCII, for a BMPString two bytes per +character in big endian format, and for an UTF8String it will be in UTF8 format. Similar care should be take to ensure the data is in the correct format when calling ASN1_STRING_set(). @@ -83,7 +83,7 @@ L =head1 COPYRIGHT -Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/BIO_ctrl.pod b/doc/crypto/BIO_ctrl.pod index a098946d..60cd1088 100644 --- a/doc/crypto/BIO_ctrl.pod +++ b/doc/crypto/BIO_ctrl.pod @@ -5,17 +5,17 @@ BIO_ctrl, BIO_callback_ctrl, BIO_ptr_ctrl, BIO_int_ctrl, BIO_reset, BIO_seek, BIO_tell, BIO_flush, BIO_eof, BIO_set_close, BIO_get_close, BIO_pending, BIO_wpending, BIO_ctrl_pending, BIO_ctrl_wpending, -BIO_get_info_callback, BIO_set_info_callback, bio_info_cb +BIO_get_info_callback, BIO_set_info_callback, BIO_info_cb - BIO control operations =head1 SYNOPSIS #include - typedef void (*bio_info_cb)(BIO *b, int oper, const char *ptr, int arg1, long arg2, long arg3); + typedef int BIO_info_cb(BIO *b, int state, int res); long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); - long BIO_callback_ctrl(BIO *b, int cmd, bio_info_cb cb); + long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *cb); char *BIO_ptr_ctrl(BIO *bp, int cmd, long larg); long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); @@ -31,8 +31,8 @@ BIO_get_info_callback, BIO_set_info_callback, bio_info_cb size_t BIO_ctrl_pending(BIO *b); size_t BIO_ctrl_wpending(BIO *b); - int BIO_get_info_callback(BIO *b, bio_info_cb **cbp); - int BIO_set_info_callback(BIO *b, bio_info_cb *cb); + int BIO_get_info_callback(BIO *b, BIO_info_cb **cbp); + int BIO_set_info_callback(BIO *b, BIO_info_cb *cb); =head1 DESCRIPTION diff --git a/doc/crypto/BIO_get_data.pod b/doc/crypto/BIO_get_data.pod index 14f21fa7..c3137c4c 100644 --- a/doc/crypto/BIO_get_data.pod +++ b/doc/crypto/BIO_get_data.pod @@ -51,7 +51,7 @@ L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/BIO_get_ex_new_index.pod b/doc/crypto/BIO_get_ex_new_index.pod index 3e24f10b..9cf20c27 100644 --- a/doc/crypto/BIO_get_ex_new_index.pod +++ b/doc/crypto/BIO_get_ex_new_index.pod @@ -11,7 +11,7 @@ X509_STORE_CTX_get_ex_new_index, X509_STORE_CTX_set_ex_data, X509_STORE_CTX_get_ DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data, DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data, ECDH_get_ex_new_index, ECDH_set_ex_data, ECDH_get_ex_data, -ECDSA_get_ex_new_index, ECDSA_set_ex_data, ECDSA_get_ex_data, +EC_KEY_get_ex_new_index, EC_KEY_set_ex_data, EC_KEY_get_ex_data, RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - application-specific data diff --git a/doc/crypto/BIO_meth_new.pod b/doc/crypto/BIO_meth_new.pod index bf331610..f682c37d 100644 --- a/doc/crypto/BIO_meth_new.pod +++ b/doc/crypto/BIO_meth_new.pod @@ -8,7 +8,7 @@ BIO_meth_get_read, BIO_meth_set_read, BIO_meth_get_puts, BIO_meth_set_puts, BIO_meth_get_gets, BIO_meth_set_gets, BIO_meth_get_ctrl, BIO_meth_set_ctrl, BIO_meth_get_create, BIO_meth_set_create, BIO_meth_get_destroy, BIO_meth_set_destroy, BIO_meth_get_callback_ctrl, -BIO_meth_set_callback_ctrl - Routines to build up BIO methods +BIO_meth_set_callback_ctrl - Routines to build up BIO methods =head1 SYNOPSIS @@ -37,10 +37,10 @@ BIO_meth_set_callback_ctrl - Routines to build up BIO methods int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *); int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *)); long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) - (BIO *, int, bio_info_cb *); + (BIO *, int, BIO_info_cb *); int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, long (*callback_ctrl) (BIO *, int, - bio_info_cb *)); + BIO_info_cb *)); =head1 DESCRIPTION @@ -117,7 +117,7 @@ L, L, L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/BIO_push.pod b/doc/crypto/BIO_push.pod index 762027ff..ce56db98 100644 --- a/doc/crypto/BIO_push.pod +++ b/doc/crypto/BIO_push.pod @@ -75,7 +75,7 @@ L =head1 HISTORY -The BIO_set_next() function was added in OpenSSL version 1.1.0. +The BIO_set_next() function was added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/BIO_s_mem.pod b/doc/crypto/BIO_s_mem.pod index b272c410..eb67cbe9 100644 --- a/doc/crypto/BIO_s_mem.pod +++ b/doc/crypto/BIO_s_mem.pod @@ -56,14 +56,14 @@ zero then it will return B when it is empty and it will set the read retry flag (that is BIO_read_retry(b) is true). To avoid ambiguity with a normal positive return value B should be set to a negative value, typically -1. -BIO_get_mem_data() sets B to a pointer to the start of the memory BIOs data +BIO_get_mem_data() sets *B to a pointer to the start of the memory BIOs data and returns the total amount of data available. It is implemented as a macro. BIO_set_mem_buf() sets the internal BUF_MEM structure to B and sets the close flag to B, that is B should be either BIO_CLOSE or BIO_NOCLOSE. It is a macro. -BIO_get_mem_ptr() places the underlying BUF_MEM structure in B. It is +BIO_get_mem_ptr() places the underlying BUF_MEM structure in *B. It is a macro. BIO_new_mem_buf() creates a memory BIO using B bytes of data at B, @@ -114,7 +114,7 @@ Extract the BUF_MEM structure from a memory BIO and then free up the BIO: =head1 COPYRIGHT -Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/BIO_set_callback.pod b/doc/crypto/BIO_set_callback.pod index 3d158594..27aa4f45 100644 --- a/doc/crypto/BIO_set_callback.pod +++ b/doc/crypto/BIO_set_callback.pod @@ -20,8 +20,8 @@ BIO_callback_fn_ex, BIO_callback_fn void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback); BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b); - void BIO_set_callback(BIO *b, BIO_callack_fn cb); - BIO_callack_fn BIO_get_callback(BIO *b); + void BIO_set_callback(BIO *b, BIO_callback_fn cb); + BIO_callback_fn BIO_get_callback(BIO *b); void BIO_set_callback_arg(BIO *b, char *arg); char *BIO_get_callback_arg(const BIO *b); @@ -37,7 +37,7 @@ operation. BIO_set_callback() and BIO_get_callback() set and retrieve the old format BIO callback. New code should not use these functions, but they are retained for -backwards compatbility. Any callback set via BIO_set_callback_ex() will get +backwards compatibility. Any callback set via BIO_set_callback_ex() will get called in preference to any set by BIO_set_callback(). BIO_set_callback_arg() and BIO_get_callback_arg() are macros which can be diff --git a/doc/crypto/BIO_should_retry.pod b/doc/crypto/BIO_should_retry.pod index d6ddf48e..d01d5bbc 100644 --- a/doc/crypto/BIO_should_retry.pod +++ b/doc/crypto/BIO_should_retry.pod @@ -118,7 +118,7 @@ L =head1 HISTORY The BIO_get_retry_reason() and BIO_set_retry_reason() functions were added in -OpenSSL version 1.1.0. +OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/BN_bn2bin.pod b/doc/crypto/BN_bn2bin.pod index 9e16c0d2..ac469484 100644 --- a/doc/crypto/BN_bn2bin.pod +++ b/doc/crypto/BN_bn2bin.pod @@ -87,8 +87,8 @@ BN_bn2binpad() returns the number of bytes written or -1 if the supplied buffer is too small. BN_bn2hex() and BN_bn2dec() return a null-terminated string, or NULL -on error. BN_hex2bn() and BN_dec2bn() return the the length of valid -representation in hexadecimal or decimal digits, and 0 on error, in which +on error. BN_hex2bn() and BN_dec2bn() return the number of characters +used in parsing, or 0 on error, in which case no new B will be created. BN_print_fp() and BN_print() return 1 on success, 0 on write errors. diff --git a/doc/crypto/BN_new.pod b/doc/crypto/BN_new.pod index 36bd00da..08aae5e9 100644 --- a/doc/crypto/BN_new.pod +++ b/doc/crypto/BN_new.pod @@ -36,7 +36,8 @@ If B is NULL, nothing is done. =head1 RETURN VALUES BN_new() and BN_secure_new() -return a pointer to the B. If the allocation fails, +return a pointer to the B initialised to the value 0. +If the allocation fails, they return B and set an error code that can be obtained by L. diff --git a/doc/crypto/BN_zero.pod b/doc/crypto/BN_zero.pod index 91d48aad..2ca8850f 100644 --- a/doc/crypto/BN_zero.pod +++ b/doc/crypto/BN_zero.pod @@ -14,8 +14,8 @@ operations const BIGNUM *BN_value_one(void); - int BN_set_word(BIGNUM *a, unsigned long w); - unsigned long BN_get_word(BIGNUM *a); + int BN_set_word(BIGNUM *a, BN_ULONG w); + BN_ULONG BN_get_word(BIGNUM *a); Deprecated: @@ -25,19 +25,21 @@ Deprecated: =head1 DESCRIPTION +B is a macro that will be an unsigned integral type optimied +for the most efficient implementation on the local platform. + BN_zero(), BN_one() and BN_set_word() set B to the values 0, 1 and B respectively. BN_zero() and BN_one() are macros. BN_value_one() returns a B constant of value 1. This constant is useful for use in comparisons and assignment. -BN_get_word() returns B, if it can be represented as an unsigned -long. +BN_get_word() returns B, if it can be represented as a B. =head1 RETURN VALUES -BN_get_word() returns the value B, and 0xffffffffL if B cannot -be represented as an unsigned long. +BN_get_word() returns the value B, or all-bits-set if B cannot +be represented as a B. BN_one(), BN_set_word() and the deprecated version of BN_zero() return 1 on success, 0 otherwise. @@ -46,10 +48,11 @@ The preferred version of BN_zero() never fails and returns no value. =head1 BUGS -Someone might change the constant. +If a B is equal to the value of all-bits-set, it will collide +with the error condition returned by BN_get_word() which uses that +as an error value. -If a B is equal to 0xffffffffL it can be represented as an -unsigned long but this value is also returned on error. +B should probably be a typedef. =head1 SEE ALSO @@ -57,7 +60,7 @@ L =head1 COPYRIGHT -Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/BUF_MEM_new.pod b/doc/crypto/BUF_MEM_new.pod index 29466088..1d89159c 100644 --- a/doc/crypto/BUF_MEM_new.pod +++ b/doc/crypto/BUF_MEM_new.pod @@ -2,7 +2,7 @@ =head1 NAME -BUF_MEM_new, BUF_MEM_new_ex, BUF_MEM_free, BUF_MEM_grow +BUF_MEM_new, BUF_MEM_new_ex, BUF_MEM_free, BUF_MEM_grow, BUF_MEM_grow_clean, BUF_reverse - simple character array structure diff --git a/doc/crypto/CRYPTO_get_ex_new_index.pod b/doc/crypto/CRYPTO_get_ex_new_index.pod index 0853ce58..a5bf6209 100644 --- a/doc/crypto/CRYPTO_get_ex_new_index.pod +++ b/doc/crypto/CRYPTO_get_ex_new_index.pod @@ -17,8 +17,8 @@ CRYPTO_get_ex_data, CRYPTO_free_ex_data, CRYPTO_new_ex_data CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); - typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, - int idx, long argl, void *argp); + typedef void CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp); typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, @@ -128,7 +128,8 @@ initially registered via CRYPTO_get_ex_new_index() and can be used if the same callback handles different types of exdata. dup_func() is called when a structure is being copied. This is only done -for B and B objects. The B and B parameters +for B, B, B objects and B chains via +BIO_dup_chain(). The B and B parameters are pointers to the destination and source B structures, respectively. The B parameter needs to be cast to a B as the API has currently the wrong signature; that will be changed in a diff --git a/doc/crypto/DEFINE_STACK_OF.pod b/doc/crypto/DEFINE_STACK_OF.pod index fbd43f97..f655f84e 100644 --- a/doc/crypto/DEFINE_STACK_OF.pod +++ b/doc/crypto/DEFINE_STACK_OF.pod @@ -94,12 +94,12 @@ B. sk_TYPE_value() returns element B in B, where B starts at zero. If B is out of range then B is returned. -sk_TYPE_new() allocates a new empty stack using comparison function B. -If B is B then no comparison function is used. +sk_TYPE_new() allocates a new empty stack using comparison function B. +If B is B then no comparison function is used. sk_TYPE_new_null() allocates a new empty stack with no comparison function. -sk_TYPE_set_cmp_func() sets the comparison function of B to B. +sk_TYPE_set_cmp_func() sets the comparison function of B to B. The previous comparison function is returned or B if there was no previous comparison function. diff --git a/doc/crypto/DH_get0_pqg.pod b/doc/crypto/DH_get0_pqg.pod index 79647bf8..38098135 100644 --- a/doc/crypto/DH_get0_pqg.pod +++ b/doc/crypto/DH_get0_pqg.pod @@ -48,13 +48,11 @@ been set yet, although if the private key has been set then the public key must be. The values point to the internal representation of the public key and private key values. This memory should not be freed directly. -The public and private key values can be set using DH_set0_key(). The public -key must be non-NULL the first time this function is called on a given DH -object. The private key may be NULL. On subsequent calls, either may be NULL, -which means the corresponding DH field is left untouched. As for DH_set0_pqg() -this function transfers the memory management of the key values to the DH -object, and therefore they should not be freed directly after this function has -been called. +The public and private key values can be set using DH_set0_key(). Either +parameter may be NULL, which means the corresponding DH field is left +untouched. As with DH_set0_pqg() this function transfers the memory management +of the key values to the DH object, and therefore they should not be freed +directly after this function has been called. DH_set_flags() sets the flags in the B parameter on the DH object. Multiple flags can be passed in one go (bitwise ORed together). Any flags that @@ -98,7 +96,7 @@ L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/DH_meth_new.pod b/doc/crypto/DH_meth_new.pod index bcf55921..d768da8c 100644 --- a/doc/crypto/DH_meth_new.pod +++ b/doc/crypto/DH_meth_new.pod @@ -142,7 +142,7 @@ L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/DH_set_method.pod b/doc/crypto/DH_set_method.pod index cd75a9b5..21006086 100644 --- a/doc/crypto/DH_set_method.pod +++ b/doc/crypto/DH_set_method.pod @@ -31,8 +31,11 @@ Initially, the default DH_METHOD is the OpenSSL internal implementation, as returned by DH_OpenSSL(). DH_set_default_method() makes B the default method for all DH -structures created later. B: This is true only whilst no ENGINE has been set +structures created later. +B: This is true only whilst no ENGINE has been set as a default for DH, so this function is no longer recommended. +This function is not thread-safe and should not be called at the same time +as other OpenSSL functions. DH_get_default_method() returns a pointer to the current default DH_METHOD. However, the meaningfulness of this result is dependent on whether the ENGINE diff --git a/doc/crypto/DSA_get0_pqg.pod b/doc/crypto/DSA_get0_pqg.pod index e87e42a4..6c1c09a5 100644 --- a/doc/crypto/DSA_get0_pqg.pod +++ b/doc/crypto/DSA_get0_pqg.pod @@ -88,7 +88,7 @@ L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/DSA_meth_new.pod b/doc/crypto/DSA_meth_new.pod index 68f744ab..948ab29b 100644 --- a/doc/crypto/DSA_meth_new.pod +++ b/doc/crypto/DSA_meth_new.pod @@ -10,7 +10,7 @@ DSA_meth_get_verify, DSA_meth_set_verify, DSA_meth_get_mod_exp, DSA_meth_set_mod_exp, DSA_meth_get_bn_mod_exp, DSA_meth_set_bn_mod_exp, DSA_meth_get_init, DSA_meth_set_init, DSA_meth_get_finish, DSA_meth_set_finish, DSA_meth_get_paramgen, DSA_meth_set_paramgen, DSA_meth_get_keygen, -DSA_meth_set_keygen - Routines to build up DSA methods +DSA_meth_set_keygen - Routines to build up DSA methods =head1 SYNOPSIS @@ -179,7 +179,7 @@ L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/DSA_set_method.pod b/doc/crypto/DSA_set_method.pod index a64725f7..d870f56f 100644 --- a/doc/crypto/DSA_set_method.pod +++ b/doc/crypto/DSA_set_method.pod @@ -31,8 +31,11 @@ Initially, the default DSA_METHOD is the OpenSSL internal implementation, as returned by DSA_OpenSSL(). DSA_set_default_method() makes B the default method for all DSA -structures created later. B: This is true only whilst no ENGINE has +structures created later. +B: This is true only whilst no ENGINE has been set as a default for DSA, so this function is no longer recommended. +This function is not thread-safe and should not be called at the same time +as other OpenSSL functions. DSA_get_default_method() returns a pointer to the current default DSA_METHOD. However, the meaningfulness of this result is dependent on diff --git a/doc/crypto/EC_POINT_new.pod b/doc/crypto/EC_POINT_new.pod index 3358a08d..5ac41b32 100644 --- a/doc/crypto/EC_POINT_new.pod +++ b/doc/crypto/EC_POINT_new.pod @@ -164,7 +164,7 @@ EC_POINT_set_compressed_coordinates_GF2m() and EC_POINT_oct2point(). EC_POINT_method_of returns the EC_METHOD associated with the supplied EC_POINT. -EC_POINT_point2oct() and EC_point2buf() return the length of the required +EC_POINT_point2oct() and EC_POINT_point2buf() return the length of the required buffer or 0 on error. EC_POINT_point2bn() returns the pointer to the BIGNUM supplied, or NULL on @@ -186,7 +186,7 @@ L, L =head1 COPYRIGHT -Copyright 2013-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2013-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/ENGINE_add.pod b/doc/crypto/ENGINE_add.pod index 37384f69..d5a7d724 100644 --- a/doc/crypto/ENGINE_add.pod +++ b/doc/crypto/ENGINE_add.pod @@ -589,6 +589,16 @@ might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" - and ENGINE could therefore decide whether or not to support this "foo"-specific extension). +=head1 ENVIRONMENT + +=over 4 + +=item B + +The path to the engines directory. + +=back + =head1 SEE ALSO L, L, L, L, L @@ -601,7 +611,7 @@ OPENSSL_init_crypto(). =head1 COPYRIGHT -Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/EVP_CIPHER_meth_new.pod b/doc/crypto/EVP_CIPHER_meth_new.pod index ef47f0fd..08e8290b 100644 --- a/doc/crypto/EVP_CIPHER_meth_new.pod +++ b/doc/crypto/EVP_CIPHER_meth_new.pod @@ -10,7 +10,7 @@ EVP_CIPHER_meth_set_set_asn1_params, EVP_CIPHER_meth_set_get_asn1_params, EVP_CIPHER_meth_set_ctrl, EVP_CIPHER_meth_get_init, EVP_CIPHER_meth_get_do_cipher, EVP_CIPHER_meth_get_cleanup, EVP_CIPHER_meth_get_set_asn1_params, EVP_CIPHER_meth_get_get_asn1_params, -EVP_CIPHER_meth_get_ctrl - Routines to build up EVP_CIPHER methods +EVP_CIPHER_meth_get_ctrl - Routines to build up EVP_CIPHER methods =head1 SYNOPSIS @@ -204,17 +204,32 @@ EVP_CIPHER_CTX_get_cipher_data(). This cleanup function is called by EVP_CIPHER_CTX_reset() and EVP_CIPHER_CTX_free(). +EVP_CIPHER_meth_set_set_asn1_params() sets the function for B +to set the AlgorithmIdentifier "parameter" based on the passed cipher. +This function is called by EVP_CIPHER_param_to_asn1(). +EVP_CIPHER_meth_set_get_asn1_params() sets the function for B +that sets the cipher parameters based on an ASN.1 AlgorithmIdentifier +"parameter". +Both these functions are needed when there is a need for custom data +(more or other than the cipher IV). +They are called by EVP_CIPHER_param_to_asn1() and +EVP_CIPHER_asn1_to_param() respectively if defined. + EVP_CIPHER_meth_set_ctrl() sets the control function for B. +EVP_CIPHER_meth_get_init(), EVP_CIPHER_meth_get_do_cipher(), +EVP_CIPHER_meth_get_cleanup(), EVP_CIPHER_meth_get_set_asn1_params(), +EVP_CIPHER_meth_get_get_asn1_params() and EVP_CIPHER_meth_get_ctrl() +are all used to retrieve the method data given with the +EVP_CIPHER_meth_set_*() functions above. + =head1 RETURN VALUES -EVP_CIPHER_meth_get_input_blocksize(), EVP_CIPHER_meth_get_result_size(), -EVP_CIPHER_meth_get_app_datasize(), EVP_CIPHER_meth_get_flags(), -EVP_CIPHER_meth_get_init(), EVP_CIPHER_meth_get_update(), -EVP_CIPHER_meth_get_final(), EVP_CIPHER_meth_get_copy(), -EVP_CIPHER_meth_get_cleanup() and EVP_CIPHER_meth_get_ctrl() are all used -to retrieve the method data given with the EVP_CIPHER_meth_set_*() -functions above. +EVP_CIPHER_meth_new() and EVP_CIPHER_meth_dup() return a pointer to a +newly created B, or NULL on failure. +All EVP_CIPHER_meth_set_*() functions return 1. +All EVP_CIPHER_meth_get_*() functions return pointers to their +respective B function. =head1 SEE ALSO @@ -223,12 +238,12 @@ L =head1 HISTORY The B structure was openly available in OpenSSL before version -1.1. -The functions described here were added in OpenSSL version 1.1. +1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/EVP_EncryptInit.pod b/doc/crypto/EVP_EncryptInit.pod index b0832eb9..d1af772f 100644 --- a/doc/crypto/EVP_EncryptInit.pod +++ b/doc/crypto/EVP_EncryptInit.pod @@ -31,7 +31,7 @@ EVP_aes_256_cbc, EVP_aes_256_ecb, EVP_aes_256_cfb, EVP_aes_256_ofb, EVP_aes_128_gcm, EVP_aes_192_gcm, EVP_aes_256_gcm, EVP_aes_128_ccm, EVP_aes_192_ccm, EVP_aes_256_ccm, EVP_aes_128_cbc_hmac_sha1, EVP_aes_256_cbc_hmac_sha1, -EVP_aes_128_cbc_hmac_sha256, EVP_aes_256_cbc_hmac_sha256 +EVP_aes_128_cbc_hmac_sha256, EVP_aes_256_cbc_hmac_sha256, EVP_chacha20, EVP_chacha20_poly1305 - EVP cipher routines =head1 SYNOPSIS @@ -45,38 +45,38 @@ EVP_chacha20, EVP_chacha20_poly1305 - EVP cipher routines void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx); int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - ENGINE *impl, unsigned char *key, unsigned char *iv); + ENGINE *impl, const unsigned char *key, const unsigned char *iv); int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, - int *outl, unsigned char *in, int inl); + int *outl, const unsigned char *in, int inl); int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - ENGINE *impl, unsigned char *key, unsigned char *iv); + ENGINE *impl, const unsigned char *key, const unsigned char *iv); int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, - int *outl, unsigned char *in, int inl); + int *outl, const unsigned char *in, int inl); int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - ENGINE *impl, unsigned char *key, unsigned char *iv, int enc); + ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc); int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, - int *outl, unsigned char *in, int inl); + int *outl, const unsigned char *in, int inl); int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - unsigned char *key, unsigned char *iv); + const unsigned char *key, const unsigned char *iv); int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - unsigned char *key, unsigned char *iv); + const unsigned char *key, const unsigned char *iv); int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, - unsigned char *key, unsigned char *iv, int enc); + const unsigned char *key, const unsigned char *iv, int enc); int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); @@ -448,9 +448,8 @@ either be 16 or the value previously set via EVP_CTRL_OCB_SET_TAGLEN. EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag); Sets the expected tag to B bytes from B. This call is only legal -when decrypting data and must be made B any data is processed (e.g. -before any EVP_DecryptUpdate() call). For OCB mode the taglen must -either be 16 or the value previously set via EVP_CTRL_AEAD_SET_TAG. +when decrypting data. For OCB mode the taglen must either be 16 or the value +previously set via EVP_CTRL_AEAD_SET_TAG. In OCB mode calling this with B set to NULL sets the tag length. The tag length can only be set before specifying an IV. If not called a default tag @@ -652,7 +651,7 @@ EVP_CIPHER_CTX_reset(). =head1 COPYRIGHT -Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/EVP_MD_meth_new.pod b/doc/crypto/EVP_MD_meth_new.pod index c15a31e7..4dac6722 100644 --- a/doc/crypto/EVP_MD_meth_new.pod +++ b/doc/crypto/EVP_MD_meth_new.pod @@ -11,7 +11,7 @@ EVP_MD_meth_set_ctrl, EVP_MD_meth_get_input_blocksize, EVP_MD_meth_get_result_size, EVP_MD_meth_get_app_datasize, EVP_MD_meth_get_flags, EVP_MD_meth_get_init, EVP_MD_meth_get_update, EVP_MD_meth_get_final, EVP_MD_meth_get_copy, EVP_MD_meth_get_cleanup, -EVP_MD_meth_get_ctrl, EVP_MD_CTX_md_data +EVP_MD_meth_get_ctrl - Routines to build up EVP_MD methods =head1 SYNOPSIS @@ -34,7 +34,6 @@ EVP_MD_meth_get_ctrl, EVP_MD_CTX_md_data unsigned char *md)); int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)); - void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx); int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx)); int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)); @@ -140,7 +139,6 @@ EVP_MD_CTX_free(). EVP_MD_meth_set_ctrl() sets the control function for B. - EVP_MD_meth_get_input_blocksize(), EVP_MD_meth_get_result_size(), EVP_MD_meth_get_app_datasize(), EVP_MD_meth_get_flags(), EVP_MD_meth_get_init(), EVP_MD_meth_get_update(), @@ -149,6 +147,17 @@ EVP_MD_meth_get_cleanup() and EVP_MD_meth_get_ctrl() are all used to retrieve the method data given with the EVP_MD_meth_set_*() functions above. +=head1 RETURN VALUES + +EVP_MD_meth_new() and EVP_MD_meth_dup() return a pointer to a newly +created B, or NULL on failure. +All EVP_MD_meth_set_*() functions return 1. +EVP_MD_get_input_blocksize(), EVP_MD_meth_get_result_size(), +EVP_MD_meth_get_app_datasize() and EVP_MD_meth_get_flags() return the +indicated sizes or flags. +All other EVP_CIPHER_meth_get_*() functions return pointers to their +respective B function. + =head1 SEE ALSO L, L, L @@ -156,11 +165,11 @@ L, L, L =head1 HISTORY The B structure was openly available in OpenSSL before version -1.1. The functions described here were added in OpenSSL version 1.1. +1.1.0. The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/EVP_PKEY_ASN1_METHOD.pod b/doc/crypto/EVP_PKEY_ASN1_METHOD.pod new file mode 100644 index 00000000..0eece53c --- /dev/null +++ b/doc/crypto/EVP_PKEY_ASN1_METHOD.pod @@ -0,0 +1,358 @@ +=pod + +=head1 NAME + +EVP_PKEY_ASN1_METHOD, +EVP_PKEY_asn1_new, +EVP_PKEY_asn1_copy, +EVP_PKEY_asn1_free, +EVP_PKEY_asn1_add0, +EVP_PKEY_asn1_add_alias, +EVP_PKEY_asn1_set_public, +EVP_PKEY_asn1_set_private, +EVP_PKEY_asn1_set_param, +EVP_PKEY_asn1_set_free, +EVP_PKEY_asn1_set_ctrl, +EVP_PKEY_asn1_set_item, +EVP_PKEY_asn1_set_security_bits, +EVP_PKEY_get0_asn1 +- manipulating and registering EVP_PKEY_ASN1_METHOD structure + +=head1 SYNOPSIS + + #include + + typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD; + + EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, + const char *pem_str, + const char *info); + void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, + const EVP_PKEY_ASN1_METHOD *src); + void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth); + int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth); + int EVP_PKEY_asn1_add_alias(int to, int from); + + void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, + int (*pub_decode) (EVP_PKEY *pk, + X509_PUBKEY *pub), + int (*pub_encode) (X509_PUBKEY *pub, + const EVP_PKEY *pk), + int (*pub_cmp) (const EVP_PKEY *a, + const EVP_PKEY *b), + int (*pub_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx), + int (*pkey_size) (const EVP_PKEY *pk), + int (*pkey_bits) (const EVP_PKEY *pk)); + void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, + int (*priv_decode) (EVP_PKEY *pk, + const PKCS8_PRIV_KEY_INFO + *p8inf), + int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, + const EVP_PKEY *pk), + int (*priv_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, + ASN1_PCTX *pctx)); + void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, + int (*param_decode) (EVP_PKEY *pkey, + const unsigned char **pder, + int derlen), + int (*param_encode) (const EVP_PKEY *pkey, + unsigned char **pder), + int (*param_missing) (const EVP_PKEY *pk), + int (*param_copy) (EVP_PKEY *to, + const EVP_PKEY *from), + int (*param_cmp) (const EVP_PKEY *a, + const EVP_PKEY *b), + int (*param_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, + ASN1_PCTX *pctx)); + + void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, + void (*pkey_free) (EVP_PKEY *pkey)); + void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_ctrl) (EVP_PKEY *pkey, int op, + long arg1, void *arg2)); + void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth, + int (*item_verify) (EVP_MD_CTX *ctx, + const ASN1_ITEM *it, + void *asn, + X509_ALGOR *a, + ASN1_BIT_STRING *sig, + EVP_PKEY *pkey), + int (*item_sign) (EVP_MD_CTX *ctx, + const ASN1_ITEM *it, + void *asn, + X509_ALGOR *alg1, + X509_ALGOR *alg2, + ASN1_BIT_STRING *sig)); + + void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_security_bits) (const EVP_PKEY + *pk)); + + const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey); + +=head1 DESCRIPTION + +B is a structure which holds a set of ASN.1 +conversion, printing and information methods for a specific public key +algorithm. + +There are two places where the B objects are +stored: one is a built-in array representing the standard methods for +different algorithms, and the other one is a stack of user-defined +application-specific methods, which can be manipulated by using +L. + +=head2 Methods + +The methods are the underlying implementations of a particular public +key algorithm present by the B object. + + int (*pub_decode) (EVP_PKEY *pk, X509_PUBKEY *pub); + int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk); + int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b); + int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent, + ASN1_PCTX *pctx); + +The pub_decode() and pub_encode() methods are called to decode / +encode B ASN.1 parameters to / from B. +They MUST return 0 on error, 1 on success. +They're called by L and L. + +The pub_cmp() method is called when two public keys are to be +compared. +It MUST return 1 when the keys are equal, 0 otherwise. +It's called by L. + +The pub_print() method is called to print a public key in humanly +readable text to B, indented B spaces. +It MUST return 0 on error, 1 on success. +It's called by L. + + int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf); + int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk); + int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent, + ASN1_PCTX *pctx); + +The priv_decode() and priv_encode() methods are called to decode / +encode B form private key to / from B. +They MUST return 0 on error, 1 on success. +They're called by L and L. + +The priv_print() method is called to print a private key in humanly +readable text to B, indented B spaces. +It MUST return 0 on error, 1 on success. +It's called by L. + + int (*pkey_size) (const EVP_PKEY *pk); + int (*pkey_bits) (const EVP_PKEY *pk); + int (*pkey_security_bits) (const EVP_PKEY *pk); + +The pkey_size() method returns the key size in bytes. +It's called by L. + +The pkey_bits() method returns the key size in bits. +It's called by L. + + int (*param_decode) (EVP_PKEY *pkey, + const unsigned char **pder, int derlen); + int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder); + int (*param_missing) (const EVP_PKEY *pk); + int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from); + int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b); + int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent, + ASN1_PCTX *pctx); + +The param_decode() and param_encode() methods are called to decode / +encode DER formatted parameters to / from B. +They MUST return 0 on error, 1 on success. +They're called by L and the B +L. + +The param_missing() method returns 0 if a key parameter is missing, +otherwise 1. +It's called by L. + +The param_copy() method copies key parameters from B to B. +It MUST return 0 on error, 1 on success. +It's called by L. + +The param_cmp() method compares the parameters of keys B and B. +It MUST return 1 when the keys are equal, 0 when not equal, or a +negative number on error. +It's called by L. + +The param_print() method prints the private key parameters in humanly +readable text to B, indented B spaces. +It MUST return 0 on error, 1 on success. +It's called by L. + + int (*sig_print) (BIO *out, + const X509_ALGOR *sigalg, const ASN1_STRING *sig, + int indent, ASN1_PCTX *pctx); + +The sig_print() method prints a signature in humanly readable text to +B, indented B spaces. +B contains the exact signature algorithm. +If the signature in B doesn't correspond to what this method +expects, X509_signature_dump() must be used as a last resort. +It MUST return 0 on error, 1 on success. +It's called by L. + + void (*pkey_free) (EVP_PKEY *pkey); + +The pkey_free() method helps freeing the internals of B. +It's called by L, L, +L, and L. + + int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2); + +The pkey_ctrl() method adds extra algorithm specific control. +It's called by L, +L, +L, L, +L, ... + + int (*old_priv_decode) (EVP_PKEY *pkey, + const unsigned char **pder, int derlen); + int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder); + +The old_priv_decode() and old_priv_encode() methods decode / encode +they private key B from / to a DER formatted array. +These are exclusively used to help decoding / encoding older (pre +PKCS#8) PEM formatted encrypted private keys. +old_priv_decode() MUST return 0 on error, 1 on success. +old_priv_encode() MUST the return same kind of values as +i2d_PrivateKey(). +They're called by L and L. + + int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn, + X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey); + int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn, + X509_ALGOR *alg1, X509_ALGOR *alg2, + ASN1_BIT_STRING *sig); + +The item_sign() and item_verify() methods make it possible to have +algorithm specific signatures and verification of them. + +item_sign() MUST return one of: + +=over 4 + +=item <=0 + +error + +=item Z<>1 + +item_sign() did everything, OpenSSL internals just needs to pass the +signature length back. + +=item Z<>2 + +item_sign() did nothing, OpenSSL internal standard routines are +expected to continue with the default signature production. + +=item Z<>3 + +item_sign() set the algorithm identifier B and B, +OpenSSL internals should just sign using those algorithms. + +=back + +item_verify() MUST return one of: + +=over 4 + +=item <=0 + +error + +=item Z<>1 + +item_sign() did everything, OpenSSL internals just needs to pass the +signature length back. + +=item Z<>2 + +item_sign() did nothing, OpenSSL internal standard routines are +expected to continue with the default signature production. + +=back + +item_verify() and item_sign() are called by L and +L, and by extension, L, +L, L, L, ... + +=head2 Functions + +EVP_PKEY_asn1_new() creates and returns a new B +object, and associates the given B, B, B and +B. +B is a NID, B is the PEM type string, B is a +descriptive string. +The following B are supported: + + ASN1_PKEY_SIGPARAM_NULL + +If B is set, then the signature algorithm +parameters are given the type B by default, otherwise +they will be given the type B (i.e. the parameter is +omitted). +See L for more information. + +EVP_PKEY_asn1_copy() copies an B object from +B to B. +This function is not thread safe, it's recommended to only use this +when initializing the application. + +EVP_PKEY_asn1_free() frees an existing B pointed +by B. + +EVP_PKEY_asn1_add0() adds B to the user defined stack of +methods unless another B with the same NID is +already there. +This function is not thread safe, it's recommended to only use this +when initializing the application. + +EVP_PKEY_asn1_add_alias() creates an alias with the NID B for the +B with NID B unless another +B with the same NID is already added. +This function is not thread safe, it's recommended to only use this +when initializing the application. + +EVP_PKEY_asn1_set_public(), EVP_PKEY_asn1_set_private(), +EVP_PKEY_asn1_set_param(), EVP_PKEY_asn1_set_free(), +EVP_PKEY_asn1_set_ctrl(), EVP_PKEY_asn1_set_item(), and +EVP_PKEY_asn1_set_security_bits() set the diverse methods of the given +B object. + +EVP_PKEY_get0_asn1() finds the B associated +with the key B. + +=head1 RETURN VALUES + +EVP_PKEY_asn1_new() returns NULL on error, or a pointer to an +B object otherwise. + +EVP_PKEY_asn1_add0() and EVP_PKEY_asn1_add_alias() return 0 on error, +or 1 on success. + +EVP_PKEY_get0_asn1() returns NULL on error, or a pointer to a constant +B object otherwise. + +=head1 COPYRIGHT + +Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the OpenSSL license (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/crypto/EVP_PKEY_asn1_get_count.pod b/doc/crypto/EVP_PKEY_asn1_get_count.pod new file mode 100644 index 00000000..9ad2daed --- /dev/null +++ b/doc/crypto/EVP_PKEY_asn1_get_count.pod @@ -0,0 +1,80 @@ +=pod + +=head1 NAME + +EVP_PKEY_asn1_find, +EVP_PKEY_asn1_find_str, +EVP_PKEY_asn1_get_count, +EVP_PKEY_asn1_get0, +EVP_PKEY_asn1_get0_info +- enumerate public key ASN.1 methods + +=head1 SYNOPSIS + + #include + + int EVP_PKEY_asn1_get_count(void); + const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx); + const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type); + const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, + const char *str, int len); + int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, + int *ppkey_flags, const char **pinfo, + const char **ppem_str, + const EVP_PKEY_ASN1_METHOD *ameth); + +=head1 DESCRIPTION + +EVP_PKEY_asn1_count() returns a count of the number of public key +ASN.1 methods available: it includes standard methods and any methods +added by the application. + +EVP_PKEY_asn1_get0() returns the public key ASN.1 method B. +The value of B must be between zero and EVP_PKEY_asn1_get_count() +- 1. + +EVP_PKEY_asn1_find() looks up the B with NID +B. +If B isn't B, then it will look up an engine implementing a +B for the NID B and return that instead, +and also set B<*pe> to point at the engine that implements it. + +EVP_PKEY_asn1_find_str() looks up the B with PEM +type string B. +Just like EVP_PKEY_asn1_find(), if B isn't B, then it will +look up an engine implementing a B for the NID +B and return that instead, and also set B<*pe> to point at the +engine that implements it. + +EVP_PKEY_asn1_get0_info() returns the public key ID, base public key +ID (both NIDs), any flags, the method description and PEM type string +associated with the public key ASN.1 method B<*ameth>. + +EVP_PKEY_asn1_count(), EVP_PKEY_asn1_get0(), EVP_PKEY_asn1_find() and +EVP_PKEY_asn1_find_str() are not thread safe, but as long as all +B objects are added before the application gets +threaded, using them is safe. See L. + +=head1 RETURN VALUES + +EVP_PKEY_asn1_count() returns the number of available public key methods. + +EVP_PKEY_asn1_get0() return a public key method or B if B is +out of range. + +EVP_PKEY_asn1_get0_info() returns 0 on failure, 1 on success. + +=head1 SEE ALSO + +L, L + +=head1 COPYRIGHT + +Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the OpenSSL license (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/crypto/EVP_PKEY_keygen.pod b/doc/crypto/EVP_PKEY_keygen.pod index ed4a3e1d..b1e708fc 100644 --- a/doc/crypto/EVP_PKEY_keygen.pod +++ b/doc/crypto/EVP_PKEY_keygen.pod @@ -18,7 +18,7 @@ EVP_PKEY_gen_cb int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); - typedef int (*EVP_PKEY_gen_cb)(EVP_PKEY_CTX *ctx); + typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx); void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx); diff --git a/doc/crypto/EVP_PKEY_set1_RSA.pod b/doc/crypto/EVP_PKEY_set1_RSA.pod index e1b7110f..884cf91c 100644 --- a/doc/crypto/EVP_PKEY_set1_RSA.pod +++ b/doc/crypto/EVP_PKEY_set1_RSA.pod @@ -5,10 +5,9 @@ EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY, EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY, EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY, -EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY, -EVP_PKEY_get0_hmac, -EVP_PKEY_type, EVP_PKEY_id, EVP_PKEY_base_id -- EVP_PKEY assignment functions +EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, +EVP_PKEY_assign_EC_KEY, EVP_PKEY_get0_hmac, EVP_PKEY_type, EVP_PKEY_id, +EVP_PKEY_base_id, EVP_PKEY_set1_engine - EVP_PKEY assignment functions =head1 SYNOPSIS @@ -39,6 +38,8 @@ EVP_PKEY_type, EVP_PKEY_id, EVP_PKEY_base_id int EVP_PKEY_base_id(const EVP_PKEY *pkey); int EVP_PKEY_type(int type); + int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *engine); + =head1 DESCRIPTION EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and @@ -72,6 +73,11 @@ often seen in practice. EVP_PKEY_type() returns the underlying type of the NID B. For example EVP_PKEY_type(EVP_PKEY_RSA2) will return B. +EVP_PKEY_set1_engine() sets the ENGINE handling B to B. It +must be called after the key algorithm and components are set up. +If B does not include an B for B an +error occurs. + =head1 NOTES In accordance with the OpenSSL naming convention the key obtained @@ -89,6 +95,9 @@ Previous versions of this document suggested using EVP_PKEY_type(pkey->type) to determine the type of a key. Since B is now opaque this is no longer possible: the equivalent is EVP_PKEY_base_id(pkey). +EVP_PKEY_set1_engine() is typically used by an ENGINE returning an HSM +key as part of its routine to load a private key. + =head1 RETURN VALUES EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and @@ -104,6 +113,8 @@ and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure. EVP_PKEY_base_id(), EVP_PKEY_id() and EVP_PKEY_type() return a key type or B (equivalently B) on error. +EVP_PKEY_set1_engine() returns 1 for success and 0 for failure. + =head1 SEE ALSO L diff --git a/doc/crypto/EVP_SignInit.pod b/doc/crypto/EVP_SignInit.pod index c40da1ea..21eb868b 100644 --- a/doc/crypto/EVP_SignInit.pod +++ b/doc/crypto/EVP_SignInit.pod @@ -59,11 +59,6 @@ The B interface to digital signatures should almost always be used in preference to the low level interfaces. This is because the code then becomes transparent to the algorithm used and much more flexible. -Due to the link between message digests and public key algorithms the correct -digest algorithm must be used with the correct public key type. A list of -algorithms and associated public key algorithms appears in -L. - When signing with DSA private keys the random number generator must be seeded or the operation will fail. The random number generator does not need to be seeded for RSA signatures. @@ -100,7 +95,7 @@ L, L =head1 COPYRIGHT -Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/EVP_VerifyInit.pod b/doc/crypto/EVP_VerifyInit.pod index ffb6f140..92146098 100644 --- a/doc/crypto/EVP_VerifyInit.pod +++ b/doc/crypto/EVP_VerifyInit.pod @@ -51,11 +51,6 @@ The B interface to digital signatures should almost always be used in preference to the low level interfaces. This is because the code then becomes transparent to the algorithm used and much more flexible. -Due to the link between message digests and public key algorithms the correct -digest algorithm must be used with the correct public key type. A list of -algorithms and associated public key algorithms appears in -L. - The call to EVP_VerifyFinal() internally finalizes a copy of the digest context. This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can be called later to digest and verify additional data. @@ -89,7 +84,7 @@ L, L =head1 COPYRIGHT -Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/OCSP_resp_find_status.pod b/doc/crypto/OCSP_resp_find_status.pod index 36f66a85..5123f0ad 100644 --- a/doc/crypto/OCSP_resp_find_status.pod +++ b/doc/crypto/OCSP_resp_find_status.pod @@ -3,6 +3,7 @@ =head1 NAME OCSP_resp_get0_certs, +OCSP_resp_get0_signer, OCSP_resp_get0_id, OCSP_resp_get0_produced_at, OCSP_resp_find_status, OCSP_resp_count, OCSP_resp_get0, OCSP_resp_find, @@ -32,6 +33,9 @@ OCSP_single_get0_status, OCSP_check_validity const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs); + int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer, + STACK_OF(X509) *extra_certs); + int OCSP_resp_get0_id(const OCSP_BASICRESP *bs, const ASN1_OCTET_STRING **pid, const X509_NAME **pname); @@ -72,7 +76,13 @@ single response B. OCSP_resp_get0_certs() returns any certificates included in B. -OCSP_resp_get0_id() gets the responder id of . If the responder ID is +OCSP_resp_get0_signer() attempts to retrieve the certificate that directly +signed B. The OCSP protocol does not require that this certificate +is included in the B field of the response, so additional certificates +can be supplied in B if the certificates that may have +signed the response are known via some out-of-band mechanism. + +OCSP_resp_get0_id() gets the responder id of B. If the responder ID is a name then <*pname> is set to the name and B<*pid> is set to NULL. If the responder ID is by key ID then B<*pid> is set to the key ID and B<*pname> is set to NULL. @@ -99,6 +109,9 @@ B was not found. OCSP_single_get0_status() returns the status of B or -1 if an error occurred. +OCSP_resp_get0_signer() returns 1 if the signing certificate was located, +or 0 on error. + =head1 NOTES Applications will typically call OCSP_resp_find_status() using the certificate diff --git a/doc/crypto/OCSP_response_status.pod b/doc/crypto/OCSP_response_status.pod index 81946a63..180ab8d3 100644 --- a/doc/crypto/OCSP_response_status.pod +++ b/doc/crypto/OCSP_response_status.pod @@ -86,7 +86,7 @@ L =head1 HISTORY The OCSP_RESPID_set_by_name(), OCSP_RESPID_set_by_key() and OCSP_RESPID_match() -functions were added in OpenSSL version 1.1.0a. +functions were added in OpenSSL 1.1.0a. =head1 COPYRIGHT diff --git a/doc/crypto/OPENSSL_VERSION_NUMBER.pod b/doc/crypto/OPENSSL_VERSION_NUMBER.pod index 9cc1ed1d..f50faec7 100644 --- a/doc/crypto/OPENSSL_VERSION_NUMBER.pod +++ b/doc/crypto/OPENSSL_VERSION_NUMBER.pod @@ -47,6 +47,11 @@ number was therefore 0x0090581f. OpenSSL_version_num() returns the version number. +The macro OPENSSL_VERSION_AT_LEAST(major,minor) can be used at compile +time test if the current version is at least as new as the version provided. +The arguments major, minor and fix correspond to the version information +as given above. + OpenSSL_version() returns different strings depending on B: =over 4 @@ -96,7 +101,7 @@ L =head1 COPYRIGHT -Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/OPENSSL_secure_malloc.pod b/doc/crypto/OPENSSL_secure_malloc.pod index 3f49abf6..3f27d76d 100644 --- a/doc/crypto/OPENSSL_secure_malloc.pod +++ b/doc/crypto/OPENSSL_secure_malloc.pod @@ -5,8 +5,9 @@ CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_initialized, CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, CRYPTO_secure_malloc, OPENSSL_secure_zalloc, CRYPTO_secure_zalloc, OPENSSL_secure_free, -CRYPTO_secure_free, OPENSSL_secure_actual_size, OPENSSL_secure_allocated, -CRYPTO_secure_used - secure heap storage +OPENSSL_secure_clear_free, CRYPTO_secure_free, CRYPTO_secure_clear_free, +OPENSSL_secure_actual_size, OPENSSL_secure_allocated, CRYPTO_secure_used +- secure heap storage =head1 SYNOPSIS @@ -27,6 +28,9 @@ CRYPTO_secure_used - secure heap storage void OPENSSL_secure_free(void* ptr); void CRYPTO_secure_free(void *ptr, const char *, int); + void OPENSSL_secure_clear_free(void* ptr, size_t num); + void CRYPTO_secure_clear_free(void *ptr, size_t num, const char *, int); + size_t OPENSSL_secure_actual_size(const void *ptr); int OPENSSL_secure_allocated(const void *ptr); @@ -104,13 +108,17 @@ CRYPTO_secure_allocated() returns 1 if the pointer is in the secure heap, or 0 i CRYPTO_secure_malloc_done() returns 1 if the secure memory area is released, or 0 if not. -OPENSSL_secure_free() returns no values. +OPENSSL_secure_free() and OPENSSL_secure_clear_free() return no values. =head1 SEE ALSO L, L +=head1 HISTORY + +OPENSSL_secure_clear_free() was added in OpenSSL 1.1.0g. + =head1 COPYRIGHT Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/crypto/PEM_read_bio_PrivateKey.pod b/doc/crypto/PEM_read_bio_PrivateKey.pod index fbfe975b..6b3006ef 100644 --- a/doc/crypto/PEM_read_bio_PrivateKey.pod +++ b/doc/crypto/PEM_read_bio_PrivateKey.pod @@ -30,7 +30,7 @@ PEM_write_bio_PKCS7, PEM_write_PKCS7 - PEM routines #include - typedef int (*pem_password_cb)(char *buf, int size, int rwflag, void *u); + typedef int pem_password_cb(char *buf, int size, int rwflag, void *u); EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); diff --git a/doc/crypto/PKCS7_sign.pod b/doc/crypto/PKCS7_sign.pod index b5a52da9..f319f664 100644 --- a/doc/crypto/PKCS7_sign.pod +++ b/doc/crypto/PKCS7_sign.pod @@ -46,7 +46,7 @@ required by the S/MIME specifications) if B is set no translation occurs. This option should be used if the supplied data is in binary format otherwise the translation will corrupt it. -The signedData structure includes several PKCS#7 autenticatedAttributes +The signedData structure includes several PKCS#7 authenticatedAttributes including the signing time, the PKCS#7 content type and the supported list of ciphers in an SMIMECapabilities attribute. If B is set then no authenticatedAttributes will be used. If B is set then just diff --git a/doc/crypto/PKCS7_sign_add_signer.pod b/doc/crypto/PKCS7_sign_add_signer.pod index c2a06e7a..88fef771 100644 --- a/doc/crypto/PKCS7_sign_add_signer.pod +++ b/doc/crypto/PKCS7_sign_add_signer.pod @@ -55,7 +55,7 @@ B parameter though. This can reduce the size of the signature if the signers certificate can be obtained by other means: for example a previously signed message. -The signedData structure includes several PKCS#7 autenticatedAttributes +The signedData structure includes several PKCS#7 authenticatedAttributes including the signing time, the PKCS#7 content type and the supported list of ciphers in an SMIMECapabilities attribute. If B is set then no authenticatedAttributes will be used. If B is set then just diff --git a/doc/crypto/RAND_load_file.pod b/doc/crypto/RAND_load_file.pod index 39084b2c..1053a925 100644 --- a/doc/crypto/RAND_load_file.pod +++ b/doc/crypto/RAND_load_file.pod @@ -55,7 +55,7 @@ RAND_load_file() in a later session. =head1 RETURN VALUES -RAND_load_file() returns the number of bytes read. +RAND_load_file() returns the number of bytes read or -1 on error. RAND_write_file() returns the number of bytes written, and -1 if the bytes written were generated without appropriate seed. diff --git a/doc/crypto/RSA_get0_key.pod b/doc/crypto/RSA_get0_key.pod index 52f83e1b..579a2df0 100644 --- a/doc/crypto/RSA_get0_key.pod +++ b/doc/crypto/RSA_get0_key.pod @@ -58,6 +58,10 @@ set with RSA_get0_factors() and RSA_set0_factors(), and the B, B and B parameters can be obtained and set with RSA_get0_crt_params() and RSA_set0_crt_params(). +For RSA_get0_key(), RSA_get0_factors(), and RSA_get0_crt_params(), +NULL value BIGNUM ** output parameters are permitted. The functions +ignore NULL parameters but return values for other, non-NULL, parameters. + RSA_set_flags() sets the flags in the B parameter on the RSA object. Multiple flags can be passed in one go (bitwise ORed together). Any flags that are already set are left set. RSA_test_flags() tests to @@ -94,7 +98,7 @@ L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/RSA_meth_new.pod b/doc/crypto/RSA_meth_new.pod index e46b3984..9970aa6b 100644 --- a/doc/crypto/RSA_meth_new.pod +++ b/doc/crypto/RSA_meth_new.pod @@ -221,7 +221,7 @@ L, L, L =head1 HISTORY -The functions described here were added in OpenSSL version 1.1.0. +The functions described here were added in OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/RSA_padding_add_PKCS1_type_1.pod b/doc/crypto/RSA_padding_add_PKCS1_type_1.pod index 30899440..5b53eb9e 100644 --- a/doc/crypto/RSA_padding_add_PKCS1_type_1.pod +++ b/doc/crypto/RSA_padding_add_PKCS1_type_1.pod @@ -104,6 +104,13 @@ The RSA_padding_check_xxx() functions return the length of the recovered data, -1 on error. Error codes can be obtained by calling L. +=head1 WARNING + +The RSA_padding_check_PKCS1_type_2() padding check leaks timing +information which can potentially be used to mount a Bleichenbacher +padding oracle attack. This is an inherent weakness in the PKCS #1 +v1.5 padding design. Prefer PKCS1_OAEP padding. + =head1 SEE ALSO L, diff --git a/doc/crypto/RSA_public_encrypt.pod b/doc/crypto/RSA_public_encrypt.pod index 05eda944..b1dd50d7 100644 --- a/doc/crypto/RSA_public_encrypt.pod +++ b/doc/crypto/RSA_public_encrypt.pod @@ -67,6 +67,13 @@ recovered plaintext. On error, -1 is returned; the error codes can be obtained by L. +=head1 WARNING + +Decryption failures in the RSA_PKCS1_PADDING mode leak information +which can potentially be used to mount a Bleichenbacher padding oracle +attack. This is an inherent weakness in the PKCS #1 v1.5 padding +design. Prefer RSA_PKCS1_OAEP_PADDING. + =head1 CONFORMING TO SSL, PKCS #1 v2.0 diff --git a/doc/crypto/RSA_set_method.pod b/doc/crypto/RSA_set_method.pod index 7e7d27cf..668ad7a1 100644 --- a/doc/crypto/RSA_set_method.pod +++ b/doc/crypto/RSA_set_method.pod @@ -3,7 +3,7 @@ =head1 NAME RSA_set_default_method, RSA_get_default_method, RSA_set_method, -RSA_get_method, RSA_PKCS1_OpenSSL, RSA_null_method, RSA_flags, +RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags, RSA_new_method - select RSA method =head1 SYNOPSIS @@ -20,8 +20,6 @@ RSA_new_method - select RSA method RSA_METHOD *RSA_PKCS1_OpenSSL(void); - RSA_METHOD *RSA_null_method(void); - int RSA_flags(const RSA *rsa); RSA *RSA_new_method(ENGINE *engine); @@ -38,8 +36,11 @@ Initially, the default RSA_METHOD is the OpenSSL internal implementation, as returned by RSA_PKCS1_OpenSSL(). RSA_set_default_method() makes B the default method for all RSA -structures created later. B: This is true only whilst no ENGINE has +structures created later. +B: This is true only whilst no ENGINE has been set as a default for RSA, so this function is no longer recommended. +This function is not thread-safe and should not be called at the same time +as other OpenSSL functions. RSA_get_default_method() returns a pointer to the current default RSA_METHOD. However, the meaningfulness of this result is dependent on @@ -168,6 +169,11 @@ not currently exist). L +=head1 HISTORY + +The RSA_null_method(), which was a partial attempt to avoid patent issues, +was replaced to always return NULL in OpenSSL 1.1.0f. + =head1 COPYRIGHT Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/crypto/SCT_new.pod b/doc/crypto/SCT_new.pod index 23595e10..fb395a51 100644 --- a/doc/crypto/SCT_new.pod +++ b/doc/crypto/SCT_new.pod @@ -11,7 +11,7 @@ SCT_get_signature_nid, SCT_set_signature_nid, SCT_get0_signature, SCT_set0_signature, SCT_set1_signature, SCT_get0_extensions, SCT_set0_extensions, SCT_set1_extensions, SCT_get_source, SCT_set_source - - A Certificate Transparency Signed Certificate Timestamp +- A Certificate Transparency Signed Certificate Timestamp =head1 SYNOPSIS diff --git a/doc/crypto/SSL_CTX_set_tlsext_use_srtp.pod b/doc/crypto/SSL_CTX_set_tlsext_use_srtp.pod new file mode 100644 index 00000000..2746d501 --- /dev/null +++ b/doc/crypto/SSL_CTX_set_tlsext_use_srtp.pod @@ -0,0 +1,111 @@ +=pod + +=head1 NAME + +SSL_CTX_set_tlsext_use_srtp, +SSL_set_tlsext_use_srtp, +SSL_get_srtp_profiles, +SSL_get_selected_srtp_profile +- Configure and query SRTP support + +=head1 SYNOPSIS + + #include + + int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles); + int SSL_set_tlsext_use_srtp(SSL *ssl, const char *profiles); + + STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *ssl); + SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s); + +=head1 DESCRIPTION + +SRTP is the Secure Real-Time Transport Protocol. OpenSSL implements support for +the "use_srtp" DTLS extension defined in RFC5764. This provides a mechanism for +establishing SRTP keying material, algorithms and parameters using DTLS. This +capability may be used as part of an implementation that conforms to RFC5763. +OpenSSL does not implement SRTP itself or RFC5763. Note that OpenSSL does not +support the use of SRTP Master Key Identifiers (MKIs). Also note that this +extension is only supported in DTLS. Any SRTP configuration will be ignored if a +TLS connection is attempted. + +An OpenSSL client wishing to send the "use_srtp" extension should call +SSL_CTX_set_tlsext_use_srtp() to set its use for all SSL objects subsequently +created from an SSL_CTX. Alternatively a client may call +SSL_set_tlsext_use_srtp() to set its use for an individual SSL object. The +B parameters should point to a NUL-terminated, colon delimited list of +SRTP protection profile names. + +The currently supported protection profile names are: + +=over 4 + +=item SRTP_AES128_CM_SHA1_80 + +This corresponds to SRTP_AES128_CM_HMAC_SHA1_80 defined in RFC5764. + +=item SRTP_AES128_CM_SHA1_32 + +This corresponds to SRTP_AES128_CM_HMAC_SHA1_32 defined in RFC5764. + +=item SRTP_AEAD_AES_128_GCM + +This corresponds to the profile of the same name defined in RFC7714. + +=item SRTP_AEAD_AES_256_GCM + +This corresponds to the profile of the same name defined in RFC7714. + +=back + +Supplying an unrecognised protection profile name will result in an error. + +An OpenSSL server wishing to support the "use_srtp" extension should also call +SSL_CTX_set_tlsext_use_srtp() or SSL_set_tlsext_use_srtp() to indicate the +protection profiles that it is willing to negotiate. + +The currently configured list of protection profiles for either a client or a +server can be obtained by calling SSL_get_srtp_profiles(). This returns a stack +of SRTP_PROTECTION_PROFILE objects. The memory pointed to in the return value of +this function should not be freed by the caller. + +After a handshake has been completed the negotiated SRTP protection profile (if +any) can be obtained (on the client or the server) by calling +SSL_get_selected_srtp_profile(). This function will return NULL if no SRTP +protection profile was negotiated. The memory returned from this function should +not be freed by the caller. + +If an SRTP protection profile has been sucessfully negotiated then the SRTP +keying material (on both the client and server) should be obtained via a call to +L. This call should provide a label value of +"EXTRACTOR-dtls_srtp" and a NULL context value (use_context is 0). The total +length of keying material obtained should be equal to two times the sum of the +master key length and the salt length as defined for the protection profile in +use. This provides the client write master key, the server write master key, the +client write master salt and the server write master salt in that order. + +=head1 RETURN VALUES + +SSL_CTX_set_tlsext_use_srtp() and SSL_set_tlsext_use_srtp() return 0 on success +or 1 on error. + +SSL_get_srtp_profiles() returns a stack of SRTP_PROTECTION_PROFILE objects on +success or NULL on error or if no protection profiles have been configured. + +SSL_get_selected_srtp_profile() returns a pointer to an SRTP_PROTECTION_PROFILE +object if one has been negotiated or NULL otherwise. + +=head1 SEE ALSO + +L + +=head1 COPYRIGHT + +Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the OpenSSL license (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/crypto/UI_STRING.pod b/doc/crypto/UI_STRING.pod index 12d5a40b..340d9b2a 100644 --- a/doc/crypto/UI_STRING.pod +++ b/doc/crypto/UI_STRING.pod @@ -99,9 +99,9 @@ UI_get0_output_string() returns the UI string output string. UI_get0_action_string() returns the UI string action description string for B type UI strings, NULL for any other type. -UI_get0_result_string() returns the UI string action description -string for B and B type UI strings, NULL for -any other type. +UI_get0_result_string() returns the UI string result buffer for +B and B type UI strings, NULL for any other +type. UI_get0_test_string() returns the UI string action description string for B type UI strings, NULL for any other type. diff --git a/doc/crypto/X509_STORE_get0_param.pod b/doc/crypto/X509_STORE_get0_param.pod index 2144f2b0..0aed725a 100644 --- a/doc/crypto/X509_STORE_get0_param.pod +++ b/doc/crypto/X509_STORE_get0_param.pod @@ -43,7 +43,7 @@ L =head1 HISTORY B and B were added in -OpenSSL version 1.1.0. +OpenSSL 1.1.0. =head1 COPYRIGHT diff --git a/doc/crypto/X509_STORE_set_verify_cb_func.pod b/doc/crypto/X509_STORE_set_verify_cb_func.pod index 68d6a650..12a46467 100644 --- a/doc/crypto/X509_STORE_set_verify_cb_func.pod +++ b/doc/crypto/X509_STORE_set_verify_cb_func.pod @@ -30,7 +30,7 @@ X509_STORE_get_verify_cb, X509_STORE_set_verify_cb_func, X509_STORE_set_verify_cb, X509_STORE_CTX_cert_crl_fn, X509_STORE_CTX_check_crl_fn, X509_STORE_CTX_check_issued_fn, X509_STORE_CTX_check_policy_fn, -X509_STORE_CTX_check_revocation_fn, X509_STORE_CTX_cleanup_fn +X509_STORE_CTX_check_revocation_fn, X509_STORE_CTX_cleanup_fn, X509_STORE_CTX_get_crl_fn, X509_STORE_CTX_get_issuer_fn, X509_STORE_CTX_lookup_certs_fn, X509_STORE_CTX_lookup_crls_fn - set verification callback diff --git a/doc/crypto/X509_VERIFY_PARAM_set_flags.pod b/doc/crypto/X509_VERIFY_PARAM_set_flags.pod index d081d98b..5263facf 100644 --- a/doc/crypto/X509_VERIFY_PARAM_set_flags.pod +++ b/doc/crypto/X509_VERIFY_PARAM_set_flags.pod @@ -248,10 +248,14 @@ check the signature anyway. A side effect of not checking the root CA signature is that disabled or unsupported message digests on the root CA are not treated as fatal errors. -If B is set, when constructing the certificate chain, -L will search the trust store for issuer certificates before -searching the provided untrusted certificates. -As of OpenSSL 1.1.0 this option is on by default and cannot be disabled. +When B is set, construction of the certificate chain +in L will search the trust store for issuer certificates +before searching the provided untrusted certificates. +Local issuer certificates are often more likely to satisfy local security +requirements and lead to a locally trusted root. +This is especially important when some certificates in the trust store have +explicit trust settings (see "TRUST SETTINGS" in L). +As of OpenSSL 1.1.0 this option is on by default. The B flag suppresses checking for alternative chains. @@ -263,6 +267,19 @@ found that is trusted. As of OpenSSL 1.1.0, with B always set, this option has no effect. +The B flag causes intermediate certificates in the +trust store to be treated as trust-anchors, in the same way as the self-signed +root CA certificates. +This makes it possible to trust certificates issued by an intermediate CA +without having to trust its ancestor root CA. +With OpenSSL 1.1.0 and later and set, chain +construction stops as soon as the first certificate from the trust store is +added to the chain, whether that certificate is a self-signed "root" +certificate or a not self-signed intermediate certificate. +Thus, when an intermediate certificate is found in the trust store, the +verified chain passed to callbacks may be shorter than it otherwise would +be without the B flag. + The B flag suppresses checking the validity period of certificates and CRLs against the current time. If X509_VERIFY_PARAM_set_time() is used to specify a verification time, the check is not suppressed. @@ -321,7 +338,8 @@ connections associated with an B structure B: L, L, L, -L +L, +L =head1 HISTORY @@ -331,7 +349,7 @@ OpenSSL 1.1.0, and has no effect. =head1 COPYRIGHT -Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2009-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/X509_digest.pod b/doc/crypto/X509_digest.pod index 6f78a5cb..3c76c8fd 100644 --- a/doc/crypto/X509_digest.pod +++ b/doc/crypto/X509_digest.pod @@ -5,7 +5,7 @@ X509_digest, X509_CRL_digest, X509_pubkey_digest, X509_NAME_digest, -X509_REQ_digest +X509_REQ_digest, PKCS7_ISSUER_AND_SERIAL_digest - get digest of various objects diff --git a/doc/crypto/X509_get_notBefore.pod b/doc/crypto/X509_get0_notBefore.pod similarity index 99% rename from doc/crypto/X509_get_notBefore.pod rename to doc/crypto/X509_get0_notBefore.pod index 82502f65..0427d412 100644 --- a/doc/crypto/X509_get_notBefore.pod +++ b/doc/crypto/X509_get0_notBefore.pod @@ -36,7 +36,7 @@ the call. X509_getm_notBefore() and X509_getm_notAfter() are similar to X509_get0_notBefore() and X509_get0_notAfter() except they return non-constant mutable references to the associated date field of -the certficate. +the certificate. X509_set1_notBefore() and X509_set1_notAfter() set the B and B fields of B to B. Ownership of the passed diff --git a/doc/crypto/X509_get_extension_flags.pod b/doc/crypto/X509_get_extension_flags.pod index c78e4573..c07ef972 100644 --- a/doc/crypto/X509_get_extension_flags.pod +++ b/doc/crypto/X509_get_extension_flags.pod @@ -3,6 +3,7 @@ =head1 NAME X509_get0_subject_key_id, +X509_get0_authority_key_id, X509_get_pathlen, X509_get_extension_flags, X509_get_key_usage, @@ -20,6 +21,7 @@ X509_get_proxy_pathlen - retrieve certificate extension data uint32_t X509_get_key_usage(X509 *x); uint32_t X509_get_extended_key_usage(X509 *x); const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x); + const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x); void X509_set_proxy_flag(X509 *x); void X509_set_proxy_pathlen(int l); long X509_get_proxy_pathlen(X509 *x); @@ -109,6 +111,10 @@ X509_get0_subject_key_id() returns an internal pointer to the subject key identifier of B as an B or B if the extension is not present or cannot be parsed. +X509_get0_authority_key_id() returns an internal pointer to the authority key +identifier of B as an B or B if the extension +is not present or cannot be parsed. + X509_set_proxy_flag() marks the certificate with the B flag. This is for the users who need to mark non-RFC3820 proxy certificates as such, as OpenSSL only detects RFC3820 compliant ones. @@ -165,7 +171,7 @@ X509_get_proxy_pathlen() were added in OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/ct.pod b/doc/crypto/ct.pod index 355204d2..60718b3f 100644 --- a/doc/crypto/ct.pod +++ b/doc/crypto/ct.pod @@ -1,5 +1,7 @@ =pod +=for comment openssl_manual_section:7 + =head1 NAME ct - Certificate Transparency diff --git a/doc/crypto/d2i_PrivateKey.pod b/doc/crypto/d2i_PrivateKey.pod index 30caeebc..f5b4667a 100644 --- a/doc/crypto/d2i_PrivateKey.pod +++ b/doc/crypto/d2i_PrivateKey.pod @@ -2,7 +2,8 @@ =head1 NAME -d2i_PrivateKey, d2i_AutoPrivateKey, i2d_PrivateKey, +d2i_PrivateKey, d2i_PublicKey, d2i_AutoPrivateKey, +i2d_PrivateKey, i2d_PublicKey, d2i_PrivateKey_bio, d2i_PrivateKey_fp - decode and encode functions for reading and saving EVP_PKEY structures @@ -12,9 +13,12 @@ d2i_PrivateKey_bio, d2i_PrivateKey_fp EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length); + EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, + long length); EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length); int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); + int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) @@ -25,12 +29,14 @@ d2i_PrivateKey() decodes a private key using algorithm B. It attempts to use any key specific format or PKCS#8 unencrypted PrivateKeyInfo format. The B parameter should be a public key algorithm constant such as B. An error occurs if the decoded key does not match B. +d2i_PublicKey() does the same for public keys. d2i_AutoPrivateKey() is similar to d2i_PrivateKey() except it attempts to automatically detect the private key format. i2d_PrivateKey() encodes B. It uses a key specific format or, if none is defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format. +i2d_PublicKey() does the same for public keys. These functions are similar to the d2i_X509() functions; see L. diff --git a/doc/crypto/d2i_X509.pod b/doc/crypto/d2i_X509.pod index f78d0206..1fbe5cad 100644 --- a/doc/crypto/d2i_X509.pod +++ b/doc/crypto/d2i_X509.pod @@ -46,6 +46,7 @@ d2i_DSAPrivateKey, d2i_DSAPrivateKey_bio, d2i_DSAPrivateKey_fp, d2i_DSAPublicKey, +d2i_DSA_PUBKEY, d2i_DSA_PUBKEY_bio, d2i_DSA_PUBKEY_fp, d2i_DSA_SIG, @@ -121,7 +122,6 @@ d2i_POLICYINFO, d2i_POLICYQUALINFO, d2i_PROXY_CERT_INFO_EXTENSION, d2i_PROXY_POLICY, -d2i_PublicKey, d2i_RSAPrivateKey, d2i_RSAPrivateKey_bio, d2i_RSAPrivateKey_fp, @@ -217,6 +217,7 @@ i2d_DSAPrivateKey, i2d_DSAPrivateKey_bio, i2d_DSAPrivateKey_fp, i2d_DSAPublicKey, +i2d_DSA_PUBKEY, i2d_DSA_PUBKEY_bio, i2d_DSA_PUBKEY_fp, i2d_DSA_SIG, @@ -353,11 +354,11 @@ i2d_X509_VAL, =for comment generic - TYPE *d2i_TYPE(TYPE **a, unsigned char **pp, long length); + TYPE *d2i_TYPE(TYPE **a, unsigned char **ppin, long length); TYPE *d2i_TYPE_bio(BIO *bp, TYPE **a); TYPE *d2i_TYPE_fp(FILE *fp, TYPE **a); - int i2d_TYPE(TYPE *a, unsigned char **pp); + int i2d_TYPE(TYPE *a, unsigned char **ppout); int i2d_TYPE_fp(FILE *fp, TYPE *a); int i2d_TYPE_bio(BIO *bp, TYPE *a); @@ -365,14 +366,16 @@ i2d_X509_VAL, In the description here, I is used a placeholder for any of the OpenSSL datatypes, such as I. +The function parameters I and I are generally +either both named I in the headers, or I and I. These functions convert OpenSSL objects to and from their ASN.1/DER encoding. Unlike the C structures which can have pointers to sub-objects within, the DER is a serialized encoding, suitable for sending over the network, writing to a file, and so on. -d2i_TYPE() attempts to decode B bytes at B<*in>. If successful a -pointer to the B structure is returned and B<*in> is incremented to +d2i_TYPE() attempts to decode B bytes at B<*ppin>. If successful a +pointer to the B structure is returned and B<*ppin> is incremented to the byte following the parsed data. If B is not B then a pointer to the returned structure is also written to B<*a>. If an error occurred then B is returned. @@ -390,13 +393,13 @@ d2i_TYPE_fp() is similar to d2i_TYPE() except it attempts to parse data from FILE pointer B. i2d_TYPE() encodes the structure pointed to by B into DER format. -If B is not B, it writes the DER encoded data to the buffer -at B<*out>, and increments it to point after the data just written. +If B is not B, it writes the DER encoded data to the buffer +at B<*ppout>, and increments it to point after the data just written. If the return value is negative an error occurred, otherwise it returns the length of the encoded data. -If B<*out> is B memory will be allocated for a buffer and the encoded -data written to it. In this case B<*out> is not incremented and it points +If B<*ppout> is B memory will be allocated for a buffer and the encoded +data written to it. In this case B<*ppout> is not incremented and it points to the start of the data just written. i2d_TYPE_bio() is similar to i2d_TYPE() except it writes @@ -427,7 +430,7 @@ Therefore any FILE pointers or BIOs should be opened in binary mode. Functions such as strlen() will B return the correct length of the encoded structure. -The ways that B<*in> and B<*out> are incremented after the operation +The ways that B<*ppin> and B<*ppout> are incremented after the operation can trap the unwary. See the B section for some common errors. The reason for this-auto increment behaviour is to reflect a typical @@ -465,7 +468,7 @@ Represents a PKCS#1 RSA public key structure. =item B -Represents an B structure as used in IETF RFC 6960 and +Represents an B structure as used in IETF RFC 6960 and elsewhere. =item B @@ -588,7 +591,7 @@ occurs. =head1 COPYRIGHT -Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/crypto/des_modes.pod b/doc/crypto/des_modes.pod index 7c179698..d5a3f8d6 100644 --- a/doc/crypto/des_modes.pod +++ b/doc/crypto/des_modes.pod @@ -1,4 +1,5 @@ =pod + =for comment openssl_manual_section:7 =head1 NAME diff --git a/doc/crypto/hmac.pod b/doc/crypto/hmac.pod index 87f7e330..219c9ba2 100644 --- a/doc/crypto/hmac.pod +++ b/doc/crypto/hmac.pod @@ -57,7 +57,8 @@ B bytes long. It places the result in B (which must have space for the output of the hash function, which is no more than B bytes). If B is NULL, the digest is placed in a static array. The size of -the output is placed in B, unless it is B. +the output is placed in B, unless it is B. Note: passing a NULL +value for B to use the static array is not thread safe. B can be EVP_sha1(), EVP_ripemd160() etc. diff --git a/doc/crypto/x509.pod b/doc/crypto/x509.pod index 06584e3a..483b0376 100644 --- a/doc/crypto/x509.pod +++ b/doc/crypto/x509.pod @@ -1,5 +1,7 @@ =pod +=for comment openssl_manual_section:7 + =head1 NAME x509 - X.509 certificate handling diff --git a/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod b/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod deleted file mode 100644 index 3b0a5095..00000000 --- a/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod +++ /dev/null @@ -1,62 +0,0 @@ -=pod - -=head1 NAME - -SSL_CTX_set_tlsext_servername_callback, SSL_CTX_set_tlsext_servername_arg, -SSL_get_servername_type, SSL_get_servername - handle server name indication -(SNI) - -=head1 SYNOPSIS - - #include - - long SSL_CTX_set_tlsext_servername_callback(SSL_CTX *ctx, - int (*cb)(SSL *, int *, void *)); - long SSL_CTX_set_tlsext_servername_arg(SSL_CTX *ctx, void *arg); - - const char *SSL_get_servername(const SSL *s, const int type); - int SSL_get_servername_type(const SSL *s); - -=head1 DESCRIPTION - -SSL_CTX_set_tlsext_servername_callback() sets the application callback B -used by a server to perform any actions or configuration required based on -the servername extension received in the incoming connection. When B -is NULL, SNI is not used. The B value is a pointer which is passed to -the application callback. - -SSL_CTX_set_tlsext_servername_arg() sets a context-specific argument to be -passed into the callback for this B. - -SSL_get_servername() returns a servername extension value of the specified -type if provided in the Client Hello or NULL. - -SSL_get_servername_type() returns the servername type or -1 if no servername -is present. Currently the only supported type (defined in RFC3546) is -B. - -=head1 NOTES - -The ALPN and SNI callbacks are both executed during Client Hello processing. -The servername callback is executed first, followed by the ALPN callback. - -=head1 RETURN VALUES - -SSL_CTX_set_tlsext_servername_callback() and -SSL_CTX_set_tlsext_servername_arg() both always return 1 indicating success. - -=head1 SEE ALSO - -L, L, -L - -=head1 COPYRIGHT - -Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. - -Licensed under the OpenSSL license (the "License"). You may not use -this file except in compliance with the License. You can obtain a copy -in the file LICENSE in the source distribution or at -L. - -=cut diff --git a/doc/openssl-c-indent.el b/doc/openssl-c-indent.el index c28814a6..cca11830 100644 --- a/doc/openssl-c-indent.el +++ b/doc/openssl-c-indent.el @@ -2,7 +2,7 @@ ;;; ;;; This definition is for the "CC mode" package, which is the default ;;; mode for editing C source files in Emacs 20, not for the older -;;; c-mode.el (which was the default in less recent releaes of Emacs 19). +;;; c-mode.el (which was the default in less recent release of Emacs 19). ;;; ;;; Recommended use is to add this line in your .emacs: ;;; diff --git a/doc/ssl/SSL_CONF_cmd.pod b/doc/ssl/SSL_CONF_cmd.pod index d8c0e9b9..a28e2183 100644 --- a/doc/ssl/SSL_CONF_cmd.pod +++ b/doc/ssl/SSL_CONF_cmd.pod @@ -110,6 +110,11 @@ Attempts to use the file B as the set of temporary DH parameters for the appropriate context. This option is only supported if certificate operations are permitted. +=item B<-no_renegotiation> + +Disables all attempts at renegotiation in TLSv1.2 and earlier, same as setting +B. + =item B<-min_protocol>, B<-max_protocol> Sets the minimum and maximum supported protocol. @@ -227,6 +232,11 @@ Attempts to use the file B as the set of temporary DH parameters for the appropriate context. This option is only supported if certificate operations are permitted. +=item B + +Disables all attempts at renegotiation in TLSv1.2 and earlier, same as setting +B. + =item B This sets the supported signature algorithms for TLS v1.2. For clients this @@ -424,7 +434,7 @@ SSLv3 is B disabled and attempt to override this by the user are ignored. By checking the return code of SSL_CTX_cmd() it is possible to query if a -given B is recognised, this is useful is SSL_CTX_cmd() values are +given B is recognised, this is useful if SSL_CTX_cmd() values are mixed with additional application specific operations. For example an application might call SSL_CTX_cmd() and if it returns @@ -543,7 +553,7 @@ B and B where added in OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2012-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/ssl/SSL_CTX_config.pod b/doc/ssl/SSL_CTX_config.pod index 802c4c35..ec744ad0 100644 --- a/doc/ssl/SSL_CTX_config.pod +++ b/doc/ssl/SSL_CTX_config.pod @@ -40,7 +40,7 @@ If the file "config.cnf" contains the following: testapp = test_sect [test_sect] - # list of confuration modules + # list of configuration modules ssl_conf = ssl_sect diff --git a/doc/ssl/SSL_CTX_dane_enable.pod b/doc/ssl/SSL_CTX_dane_enable.pod index fb535ec5..cdb6d1bd 100644 --- a/doc/ssl/SSL_CTX_dane_enable.pod +++ b/doc/ssl/SSL_CTX_dane_enable.pod @@ -3,10 +3,10 @@ =head1 NAME SSL_CTX_dane_enable, SSL_CTX_dane_mtype_set, SSL_dane_enable, -SSL_dane_tlsa_add, SSL_get0_dane_authority, SSL_get0_dane_tlsa +SSL_dane_tlsa_add, SSL_get0_dane_authority, SSL_get0_dane_tlsa, SSL_CTX_dane_set_flags, SSL_CTX_dane_clear_flags, -SSL_dane_set_flags, SSL_dane_clear_flags - -enable DANE TLS authentication of the remote TLS server in the local +SSL_dane_set_flags, SSL_dane_clear_flags +- enable DANE TLS authentication of the remote TLS server in the local TLS client =head1 SYNOPSIS @@ -76,6 +76,8 @@ TLSA records that apply to the remote TLS peer. The arguments specify the fields of the TLSA record. The B field is provided in binary (wire RDATA) form, not the hexadecimal ASCII presentation form, with an explicit length passed via B. +The library takes a copy of the B buffer contents and the caller may +free the original B buffer when convenient. A return value of 0 indicates that "unusable" TLSA records (with invalid or unsupported parameters) were provided. A negative return value indicates an internal error in processing the record. @@ -372,7 +374,7 @@ These functions were first added to OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/ssl/SSL_CTX_set_min_proto_version.pod b/doc/ssl/SSL_CTX_set_min_proto_version.pod index 3e9fe80b..ff080e48 100644 --- a/doc/ssl/SSL_CTX_set_min_proto_version.pod +++ b/doc/ssl/SSL_CTX_set_min_proto_version.pod @@ -3,7 +3,9 @@ =head1 NAME SSL_CTX_set_min_proto_version, SSL_CTX_set_max_proto_version, -SSL_set_min_proto_version, SSL_set_max_proto_version - Set minimum +SSL_CTX_get_min_proto_version, SSL_CTX_get_max_proto_version, +SSL_set_min_proto_version, SSL_set_max_proto_version, +SSL_get_min_proto_version, SSL_get_max_proto_version - Get and set minimum and maximum supported protocol version =head1 SYNOPSIS @@ -12,12 +14,17 @@ and maximum supported protocol version int SSL_CTX_set_min_proto_version(SSL_CTX *ctx, int version); int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version); + int SSL_CTX_get_min_proto_version(SSL_CTX *ctx); + int SSL_CTX_get_max_proto_version(SSL_CTX *ctx); + int SSL_set_min_proto_version(SSL *ssl, int version); int SSL_set_max_proto_version(SSL *ssl, int version); + int SSL_get_min_proto_version(SSL *ssl); + int SSL_get_max_proto_version(SSL *ssl); =head1 DESCRIPTION -The functions set the minimum and maximum supported protocol versions +The functions get or set the minimum and maximum supported protocol versions for the B or B. This works in combination with the options set via L that also make it possible to disable @@ -28,13 +35,18 @@ Setting the minimum or maximum version to 0, will enable protocol versions down to the lowest version, or up to the highest version supported by the library, respectively. +Getters return 0 in case B or B have been configured to +automatically use the lowest or highest version supported by the library. + Currently supported versions are B, B, B, B for TLS and B, B for DTLS. =head1 RETURN VALUES -These functions return 1 on success and 0 on failure. +These setter functions return 1 on success and 0 on failure. The getter +functions return the configured version or 0 for auto-configuration of +lowest or highest protocol, respectively. =head1 NOTES @@ -42,7 +54,8 @@ All these functions are implemented using macros. =head1 HISTORY -The functions were added in OpenSSL 1.1.0 +The setter functions were added in OpenSSL 1.1.0. The getter functions +were added in OpenSSL 1.1.1. =head1 SEE ALSO diff --git a/doc/ssl/SSL_CTX_set_options.pod b/doc/ssl/SSL_CTX_set_options.pod index 635b470e..241aeb3c 100644 --- a/doc/ssl/SSL_CTX_set_options.pod +++ b/doc/ssl/SSL_CTX_set_options.pod @@ -189,6 +189,19 @@ Allow legacy insecure renegotiation between OpenSSL and unpatched servers B: this option is currently set by default. See the B section for more details. +=item SSL_OP_NO_ENCRYPT_THEN_MAC + +Normally clients and servers will transparently attempt to negotiate the +RFC7366 Encrypt-then-MAC option on TLS and DTLS connection. + +If this option is set, Encrypt-then-MAC is disabled. Clients will not +propose, and servers will not accept the extension. + +=item SSL_OP_NO_RENEGOTIATION + +Disable all renegotiation in TLSv1.2 and earlier. Do not send HelloRequest +messages, and ignore renegotiation requests via ClientHello. + =back =head1 SECURE RENEGOTIATION @@ -280,9 +293,11 @@ L The attempt to always try to use secure renegotiation was added in Openssl 0.9.8m. +B was added in OpenSSL 1.1.0h. + =head1 COPYRIGHT -Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/ssl/SSL_export_keying_material.pod b/doc/ssl/SSL_export_keying_material.pod new file mode 100644 index 00000000..ccb99ec9 --- /dev/null +++ b/doc/ssl/SSL_export_keying_material.pod @@ -0,0 +1,61 @@ +=pod + +=head1 NAME + +SSL_export_keying_material - obtain keying material for application use + +=head1 SYNOPSIS + + #include + + int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen, + const char *label, size_t llen, + const unsigned char *context, + size_t contextlen, int use_context); + +=head1 DESCRIPTION + +During the creation of a TLS or DTLS connection shared keying material is +established between the two endpoints. The function SSL_export_keying_material() +enables an application to use some of this keying material for its own purposes +in accordance with RFC5705. + +An application may need to securely establish the context within which this +keying material will be used. For example this may include identifiers for the +application session, application algorithms or parameters, or the lifetime of +the context. The context value is left to the application but must be the same +on both sides of the communication. + +For a given SSL connection B, B bytes of data will be written to +B. The application specific context should be supplied in the location +pointed to by B and should be B bytes long. Provision of +a context is optional. If the context should be omitted entirely then +B should be set to 0. Otherwise it should be any other value. If +B is 0 then the values of B and B are ignored. +Note that a zero length context is treated differently to no context at all, and +will result in different keying material being returned. + +An application specific label should be provided in the location pointed to by +B