openssl
openssl 1.1.1-pre1 in mobaxterm
OpenSSL testet an einer neuen Version herum. Aber auch OpenSSL 1.1.1-pre1 lässt sich nicht ohne weiters in MobaXTerm bauen.
Bekanntes Problem, gleiche Lösung:
$ make clean && ./config && make
crypto/async/arch/async_posix.o:async_posix.c:(.text+0xe): undefined reference to `getcontext' crypto/async/arch/async_posix.o:async_posix.c:(.text+0x56): undefined reference to `getcontext' crypto/async/arch/async_posix.o:async_posix.c:(.text+0xd4): undefined reference to `makecontext' crypto/async/async.o:async.c:(.text+0x34): undefined reference to `setcontext' collect2: error: ld returned 1 exit status Makefile:728: recipe for target 'libcrypto.dll.a' failed make[1]: *** [libcrypto.dll.a] Error 1 make[1]: Leaving directory '/home/mobaxterm/_work/openssl-1.1.1-pre1' Makefile:143: recipe for target 'all' failed make: *** [all] Error 2 Command exited with non-zero status 2
$ make clean && ./config no_async && make
$ apps/openssl.exe version OpenSSL 1.1.1-pre1 (alpha) 13 Feb 2018
OpenSSL in MobaXterm
Neue OpenSSL Version kompilieren in MobaXterm bricht einfach ab mit Fehlermeldung
./config && make ... ... ... gcc -I. -Iinclude -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC-DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR=""/usr/local/ssl"" -DENGINESDIR=""/usr/local/lib/engines-1.1"" -D TERMIOS -DL_ENDIAN -Wall -O3 -fomit-frame-pointer -D_WINDLL -MMD -MF ssl/tls_srp.d.tmp -MT ssl/tls_srp.o -c -o ssl/tls_srp.o ssl/tls_srp.c ar r libssl.a ssl/bio_ssl.o ssl/d1_lib.o ssl/d1_msg.o ssl/d1_srtp.o ssl/methods.o ssl/pqueue.o ssl/record/dtls1_bitmap.o ssl/record/rec_layer_d1.o ssl/record/rec_layer_s3.o ssl/record/ssl3_buffer.o ssl/record/ssl3_record.o ssl/s3_cbc.o ssl/s3_enc.o ssl/s3_lib.o ssl/s3_msg.o ssl/ssl_asn1.o ssl/ssl_cert.o ssl/ssl_ciph.o ssl/ssl_conf.o ssl/ssl_err.o ssl/ssl_init.o ssl/ssl_lib.o ssl/ssl_mcnf.o ssl/ssl_rsa.o ssl/ssl_sess.o ssl/ssl_stat.o ssl/ssl_txt.o ssl/ssl_utst.o ssl/statem/statem.o ssl/statem/statem_clnt.o ssl/statem/statem_dtls.o ssl/statem/statem_lib.o ssl/statem/statem_srvr.o ssl/t1_enc.o ssl/t1_ext.o ssl/t1_lib.o ssl/t1_reneg.o ssl/t1_trce.o ssl/tls_srp.o ar: creating libssl.a ranlib libssl.a || echo Never mind. /bin/make -f ./Makefile.shared -e \ PLATFORM=Cygwin-x86 \ PERL="/usr/bin/perl" SRCDIR='.' DSTDIR="." \ INSTALLTOP='/usr/local' LIBDIR='lib' \ LIBDEPS=' '""' ' \ LIBNAME=crypto SHLIBVERSION=1.1 \ STLIBNAME=libcrypto.a \ SHLIBNAME=libcrypto.dll.a SHLIBNAME_FULL=cygcrypto-1.1.dll \ CC='gcc' CFLAGS='-DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR=""/usr/local/ssl"" -DENGINESDIR=""/usr/local/lib/engines-1.1"" -DTERMIOS -DL_ENDIAN -Wall -O3 -fomit-frame-pointer -D_WINDLL' \ LDFLAGS='' SHARED_LDFLAGS='-shared ' \ RC='windres' SHARED_RCFLAGS='' \ link_shlib.cygwin-shared make[2]: Entering directory '/drives/c/temp/openssl-1.1.0g' /usr/bin/perl ./util/mkrc.pl cygcrypto-1.1.dll | windres -o rc.o LD_LIBRARY_PATH=:/bin gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="/usr/local/ssl" -DENGINESDIR="/usr/local/lib/engines-1.1" -DTERMIOS -DL_ENDIAN -Wall -O3 -fomit-frame-pointer -D_WINDLL -shared -shared -Wl,--enable-auto-image-base -Wl,-Bsymbolic -Wl,--out-implib,libcrypto.dll.a rc.o -o cygcrypto-1.1.dll -Wl,--whole-archive libcrypto.a -Wl,--no-whole-archive libcrypto.a(async_posix.o):async_posix.c:(.text+0xe): undefined reference to `getcontext' libcrypto.a(async_posix.o):async_posix.c:(.text+0x56): undefined reference to `getcontext' libcrypto.a(async_posix.o):async_posix.c:(.text+0xd4): undefined reference to `makecontext' libcrypto.a(async.o):async.c:(.text+0x34): undefined reference to `setcontext' collect2: error: ld returned 1 exit status Makefile.shared:243: recipe for target 'link_shlib.cygwin' failed make[2]: *** [link_shlib.cygwin] Error 1 make[2]: Leaving directory '/drives/c/temp/openssl-1.1.0g' Makefile:639: recipe for target 'libcrypto.dll.a' failed make[1]: *** [libcrypto.dll.a] Error 2 make[1]: Leaving directory '/drives/c/temp/openssl-1.1.0g' Makefile:130: recipe for target 'all' failed make: *** [all] Error 2
Lösung:
./config no-async && make
Der Build läuft durch und baut eine funktionierende exe
$ apps/openssl.exe version OpenSSL 1.1.0g 2 Nov 2017
Verify X509 Certificate
Es ist nicht ausreichend nur den Private Key zu überprüfen!
OpenSSL bietet auch eine einfache Möglichkeit einen CSR zu prüfen:
openssl req -in example.csr -verify verify OK
Beim Public Key wird es komplizierter. Einzig eine Prüfung mit der Signatur der übergeordneten CA hilft. Hier eine erste Version eines Prüfscriptes.
#!/bin/bash if [[ $# -ne 1 ]]; then echo "Wrong number of arguments." exit 1 fi FILE=$1 # Allows to configure different openssl version OPENSSL=$(which openssl) TEMPDIR="/tmp USERAGENT="CustomUserAgent" # A proxy server would also get configured here WGETOPTS="--user-agent=${USERAGENT} --timeout=5 --tries=1 -e" SIGNER=$($OPENSSL x509 -in ${FILE} -text -noout | grep "CA Issuers - URI:http" | cut -d":" -f2- | tr -d '\r') if [[ -z $SIGNER ]]; then echo "No issuer certificate found for download." exit 1 fi SIGNERFILE=$(awk -F'/' '{print $NF}' <<<$SIGNER) /usr/bin/wget $WGETOPTS $SIGNER -O $TEMPDIR/$SIGNERFILE >/dev/null 2>&1 # Try to convert to PEM $OPENSSL x509 -inform der -in $TEMPDIR/$SIGNERFILE -out $TEMPDIR/$SIGNERFILE.cer 2>/dev/null if [[ -s $TEMPDIR/$SIGNERFILE.cer ]]; then # use converted file, if conversation was successfull SIGNERFILE="$SIGNERFILE.cer" fi echo -n "Certificate verification: " $OPENSSL verify -CAfile $TEMPDIR/$SIGNERFILE -partial_chain $FILE 2>&1 | grep -e "certificate signature failure" -e "OK" | cut -d":" -f2 # Cleanup if [[ ! -z $SIGNERFILE ]]; then /bin/rm $TEMPDIR/$SIGNERFILE* fi
Checking SSL Private Keys
Die ursprüngliche Frage war, wie kann ich feststellen, ob ein Zertifikat zum ursprünglichen Private Key passt. Googelt man die Frage, findet man auf SSLShopper einen Vorschlag, der aber nicht ausreicht sobald jemand Keys manipuliert!
Also muss noch eine zusätzliche Prüfung ins Script:
openssl rsa -in [privatekey] -check
Stellt sich raus, das funktioniert nicht mehr mit OpenSSL 1.1.0, weil eine Funktion einen neuen Namen erhalten hat. Aber die Leute bei OpenSSL sind da schnell und haben das nach meinen freundlichen Hinweis im Masterbranch eingepflegt.
OpenSSL 1.1.0 gibt’s ja jetzt schon etwas länger. Das bedeutet wohl, dass niemand seine Keys prüft. Zumindest nicht mit der aktuellen OpenSSL Version.
OpenSSL STR_COPY variable has no value
Openssl kann Shellvariablen im der Konfigurationsdatei verarbeiten. Kommt dabei eine Fehlermeldung wie
openssl.exe version 6870300:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:618:line 19
liegt das daran, dass die Shellvariable nicht definiert ist.
Eine leere Variable dagegen ist aber OK.
Ich dachte schon einen Bug gefunden zu haben. Der Report dafür wurde aber nicht anerkannt, weil das Verhalten so gewünscht und dokumentiert ist.
Wie kommt man zum Fehler? Mit einer Config wie:
[req] promt=no distinguished_name=dn default_md=sha256 default_bits=2048 req_extensions=alt_names [dn] C=AT ST=NOe L=xxx O="org" OU="ou" E="test@example.com" [alt_names] subjectAltName=${ENV::SAN}
Wie repariert man es?
Indem man einen Default Wert in der Config setzt:
SAN="" [req] promt=no distinguished_name=dn default_md=sha256 default_bits=2048 req_extensions=alt_names [dn] C=AT ST=NOe L=xxx O="org" OU="ou" E="test@example.com" [alt_names] subjectAltName=${ENV::SAN}
Dokumentation, wenn auch leicht verwirrend findet man unter https://www.openssl.org/docs/man1.0.2/apps/config.html bzw. https://www.openssl.org/docs/manmaster/apps/config.html für die letzte Version.
Suchen auf der Seite nach Begrif „ENV“.
OpenSSL 1.1.0 mit SSL3
Wie kompiliert man OpenSSL 1.1.0 mit SSL3?
Per Default wird SSL3 direkt abgeschaltet:
~/openssl-1.1.0>./config Operating system: x86_64-whatever-linux2 Configuring for linux-x86_64 Configuring OpenSSL version 1.1.0 (0x0x1010000fL) no-asan [default] OPENSSL_NO_ASAN (skip dir) no-crypto-mdebug [default] OPENSSL_NO_CRYPTO_MDEBUG (skip dir) no-crypto-mdebug-backtrace [default] OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE (skip dir) no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128 (skip dir) no-egd [default] OPENSSL_NO_EGD (skip dir) no-fuzz-afl [default] OPENSSL_NO_FUZZ_AFL (skip dir) no-fuzz-libfuzzer [default] OPENSSL_NO_FUZZ_LIBFUZZER (skip dir) no-heartbeats [default] OPENSSL_NO_HEARTBEATS (skip dir) no-md2 [default] OPENSSL_NO_MD2 (skip dir) no-msan [default] OPENSSL_NO_MSAN (skip dir) no-rc5 [default] OPENSSL_NO_RC5 (skip dir) no-sctp [default] OPENSSL_NO_SCTP (skip dir) no-ssl-trace [default] OPENSSL_NO_SSL_TRACE (skip dir) no-ssl3 [default] OPENSSL_NO_SSL3 (skip dir) no-ssl3-method [default] OPENSSL_NO_SSL3_METHOD (skip dir) no-ubsan [default] OPENSSL_NO_UBSAN (skip dir) no-unit-test [default] OPENSSL_NO_UNIT_TEST (skip dir) no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS (skip dir) no-zlib [default] no-zlib-dynamic [default] Configuring for linux-x86_64 ...
Aber man kann es im Configure aktivieren:
~/openssl-1.1.0>./config enable-ssl3 enable-ssl3-method Operating system: x86_64-whatever-linux2 Configuring for linux-x86_64 Configuring OpenSSL version 1.1.0 (0x0x1010000fL) no-asan [default] OPENSSL_NO_ASAN (skip dir) no-crypto-mdebug [default] OPENSSL_NO_CRYPTO_MDEBUG (skip dir) no-crypto-mdebug-backtrace [default] OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE (skip dir) no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128 (skip dir) no-egd [default] OPENSSL_NO_EGD (skip dir) no-fuzz-afl [default] OPENSSL_NO_FUZZ_AFL (skip dir) no-fuzz-libfuzzer [default] OPENSSL_NO_FUZZ_LIBFUZZER (skip dir) no-heartbeats [default] OPENSSL_NO_HEARTBEATS (skip dir) no-md2 [default] OPENSSL_NO_MD2 (skip dir) no-msan [default] OPENSSL_NO_MSAN (skip dir) no-rc5 [default] OPENSSL_NO_RC5 (skip dir) no-sctp [default] OPENSSL_NO_SCTP (skip dir) no-ssl-trace [default] OPENSSL_NO_SSL_TRACE (skip dir) no-ubsan [default] OPENSSL_NO_UBSAN (skip dir) no-unit-test [default] OPENSSL_NO_UNIT_TEST (skip dir) no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS (skip dir) no-zlib [default] no-zlib-dynamic [default] Configuring for linux-x86_64 ...
Die Option -ssl3 wird jetzt wieder erkannt, funktioniert aber nicht:
echo "" | apps/openssl s_client -servername ${SERVERNAME} -connect $SERVERNAME:443 -ssl3 CONNECTED(00000003) 140198926489344:error:141640BF:SSL routines:tls_construct_client_hello:no protocols available:ssl/statem/statem_clnt.c:709: --- no peer certificate available --- No client certificate CA names sent --- SSL handshake has read 0 bytes and written 0 bytes Verification: OK --- New, (NONE), Cipher is (NONE) Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE No ALPN negotiated ---
Gleicher Befehl mit -tls1 bzw auch wenn keine Protokollversion explizit angegeben wird:
echo "" | apps/openssl s_client -servername ${SERVERNAME} -connect $SERVERNAME:443 -tls1 CONNECTED(00000003) ... Server did acknowledge servername extension. --- Certificate chain ... --- Server certificate -----BEGIN CERTIFICATE----- MIIHfjCC... ... dTc= -----END CERTIFICATE-----
Irgendjemand eine Idee dazu?
OpenSSL 1.1 ohne SSLv3
Bisher konnte man zum Beispiel auf SSLv3 testen mit OpenSSL:
openssl version OpenSSL 1.0.2h 3 May 2016 echo "" | openssl s_client -servername ${SERVERNAME} -connect $SERVERNAME:60003 -ssl3 CONNECTED(00000003) 2675996:error:1409E0E5:SSL routines:ssl3_write_bytes:ssl handshake failure:s3_pkt.c:656: ...
OpenSSL 1.1.0 kommt per default aber ohne support für SSL3. Das heißt auch, man kann Server von Haus aus nicht mehr auf SSL3 testen.
openssl version OpenSSL 1.1.0 25 Aug 2016 echo "" | openssl s_client -servername ${SERVERNAME} -connect $SERVERNAME:60003 -ssl3 s_client: Option unknown option -ssl3 s_client: Use -help for summary.
Muss man also Server darauf testen, sollte man noch eine ältere OpenSSL Version vorhalten.
Openssl CRL Verify
Openssl 1.0.2h hat einen kleinen Bug beim verifizieren von CRLs die etwas größer als ein MB sind. Überschreitet eine CRL diese Größe, funktioniert openssl nicht mehr. Bei Symantec war es diese Woche so weit. Es ist also doch nicht so toll, wenn man immer die letzte Version installiert hat.
Mittlerweile gibt es aber auch schon einen Patch dafür… nur halt noch keine offizielle Version.
Testing OCSP
To test OCSP you need three things: The issuer certificate, the certificate you’d like to check and the path to the OCSP. All this information seems to be slightly redundant, as the certificate itself already contains the information about the OCSP URL and most of the time also the path to the issuer certificate. It would be very nice if openssl would read all this information from the certificate itself, nevertheless you need this three things to do some basic checks.
Get the required information from the AIA and download the issuer certificate:
[1]Authority Info Access Access Method=On-line Certificate Status Protocol (1.3.6.1.5.5.7.48.1) Alternative Name: URL=http://ocsp.startssl.com/sub/class1/server/ca [2]Authority Info Access Access Method=Certification Authority Issuer (1.3.6.1.5.5.7.48.2) Alternative Name: URL=http://aia.startssl.com/certs/sub.class1.server.ca.crt
Write the request into a file
openssl ocsp -issuer startssl.cer -cert www.höllrigl.at.cer -no_nonce -url http://ocsp.startssl.com/sub/class1/server/ca -reqout ocsp.req
Convert the request to base64
openssl enc -in ocsp.req -out ocsp.req.b64 -a
The file should look something like this
MEswSTBHMEUwQzAJBgUrDgMCGgUABAR571c85Prvkggz7EWCVSbdzaAjFQQUFbqc WolwWaxKVTlvLQA1YeCBz7MCChnePRMAAAAArhA=
Then you URL encode that file – you might use some free online decoder like http://meyerweb.com/eric/tools/dencoder/ – but here you have to remove the line breaks in advance. Or you do it directly at the shell
tr -d '\n' < ocsp.req.b64 | php -R 'echo urlencode($argn);'
Your output should look something like
MEswSTBHMEUwQzAJBgUrDgMCGgUABAR571c85Prvkggz7EWCVSbdzaAjFQQUFbqcWolwWaxKVTlvLQA1YeCBz7MCChnePRMAAAAArhA%3D
Now you can build your request to submit in a webbrowser or using curl at the shell.
curl http://ocsp.startssl.com/sub/class1/server/ca/MEswSTBHMEUwQzAJBgUrDgMCGgUABAR571c85Prvkggz7EWCVSbdzaAjFQQUFbqcWolwWaxKVTlvLQA1YeCBz7MCChnePRMAAAAArhA%3D --proxy http://path.to.proxy:8080 > ocsp.resp
With the output file you are able to verify the output with something like
openssl ocsp -respin ocsp.resp -text OCSP Response Data: OCSP Response Status: successful (0x0) ...
Why all this effort, when openssl might do this on it’s own?
Just because openssl won’t work too well in an envrionment where a proxy is required.
The –proxy option seems only to work starting with version openssl 1.1
Alternatively you could also try telnet to connect via a proxy
telnet path.to.proxy 8080 CONNECT ocsp.startssl.com:80 HTTP/1.0 GET /sub/class1/server/ca/MEswSTBHMEUwQzAJBgUrDgMCGgUABAR571c85Prvkggz7EWCVSbdzaAjFQQUFbqcWolwWaxKVTlvLQA1YeCBz7MCChnePRMAAAAArhA%3D
But using curl and writing into a file might be more useful.
Compile OpenSSL
Most distributions contain only an old version of openssl. If you need a newer version for your scripts, ther often is no other way than compiling it from source. Here I’ll show you, how to do it. And don’t be afraid, it’s super easy! The latest version is a 1.1 development version.
There are only a few prerequisits: You need the packets make and gcc. First you download the source from github and unpack it:
wget https://github.com/openssl/openssl/archive/master.zip unzip master.zip cd openssl-master
You simply do the steps for compiling software on unix/linux:
./config make make install
You need to do at least the 3rd step as root, so it can install the files for you. By default, everything gets installed into /usr/local/ssl – so it won’t destroy your system OpenSSL.
# /usr/local/ssl/bin/openssl version OpenSSL 1.1.0-pre2-dev xx XXX xxxx
Have a lot of fun!