Forum: PC-Programmierung openssl, Problem mit https-Website


von Linker (Gast)


Lesenswert?

Hallo,
ich wollte mit einem Linux-System und Standard-Webbrowser (luakit) die 
URL "https://fahrkarten.bahn.de/"; oeffnen und das ging nicht, es kam die 
Meldung:
  Problem occurred while loading the URL https://fahrkarten.bahn.de/
  Peer failed to perform TLS handshake

Dann probierte ich es mit Firefox, das funktionierte.


Rein aus Interesse versuchte, die URL mit einen PHP-Skript zu laden:
1
$fp = fsockopen("tls://fahrkarten.bahn.de",443, $errno, $errstr, 30);
2
if (!$fp) {
3
  echo "fsockopen:<br>"."$errstr ($errno)<br />\n";
4
  echo "url=$url\n";
5
  return "";
6
}

Dann kam der Fehler:
1
PHP Warning:  fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
2
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure in xxx.php on line 42
3
PHP Warning:  fsockopen(): Failed to enable crypto in xxx.php on line 42
4
PHP Warning:  fsockopen(): unable to connect to tls://fahrkarten.bahn.de:443 (Unknown error) in xxx.php on line 42

Mein System ist absolut auf neuestem Stand, d.h. Php 5.6.4 mit 
entsprechend neuer mcrypt und openssl.
Mein erster Gedanke war, dass es noch mit Poodel-Attack zusammenhaengt.
Die Internet-Suche war nicht sehr erfolgreich.
Die obige Fehlermeldung kennt man im Zusammenhang mit der 
Paypal-Website, aber nur bei Verwendung von "curl".
Anstatt "tls://" habe ich schon anderes probiert, z.B. "tslv1.2" ..., 
aber nichts funktionierte.

Andere https-Seiten funktionierten, z.b. https:/www.google.de, oder 
sogar https://www.bahn.de.

Hat jemand eine Ahnung, was hier falsch laueft?

von bluppdidupp (Gast)


Lesenswert?

"SSL23_GET_SERVER_HELLO:sslv3"
SSLv3 dürfte dank Poodle 
(http://www.heise.de/security/meldung/So-wehren-Sie-Poodle-Angriffe-ab-2424327.html) 
wohl kaum noch irgendwo aktiv sein.
Ich würde vermuten, das openssl da nicht korrekt konfiguriert ist und 
womöglich die benötigte TLS-Version nicht unterstützt.

von bluppdidupp (Gast)


Lesenswert?


von Linker (Gast)


Lesenswert?

bluppdidupp schrieb:
> Das hier könnte ggf. helfen:
> 
http://stackoverflow.com/questions/16547163/how-to-force-a-certain-tls-version-in-a-php-stream-context-for-the-ssl-transp

Ja, diese Seite hatte ich schon, aber half nichts.
Dieser Code ...
1
$ctx=stream_context_create(['ssl'=>['protocol_version' => 'tls1']]);
2
file_get_contents('https://fahrkarten.bahn.de', false, $ctx);
3
exit(0);
...erzeugt auch wieder
1
PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
2
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure in xxx.php on line 243
3
PHP Warning:  file_get_contents(): Failed to enable crypto in xxx.php on line 243



Interessanterweise kann ich viele https-Seiten mit PHP oeffnen, z.B. 
Banken.
Es ist wirklich nur die fahrkarten.bahn.de die sich verweigert.

von Linker (Gast)


Lesenswert?

Sorry, zu schnell abgeschickt.
Das aber funktioniert:
1
$ctx=stream_context_create(['ssl'=>['protocol_version' => 'tlsv1.2',
2
  'ciphers' => 'DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA:KRB5-DES-CBC3-MD5:KRB5-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:EDH-DSS-DES-CBC3-SHA:DES-CBC3-SHA:DES-CBC3-MD5:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:AES128-SHA:RC2-CBC-MD5:KRB5-RC4-MD5:KRB5-RC4-SHA:RC4-SHA:RC4-MD5:RC4-MD5:KRB5-DES-CBC-MD5:KRB5-DES-CBC-SHA:EDH-RSA-DES-CBC-SHA:EDH-DSS-DES-CBC-SHA:DES-CBC-SHA:DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5:EXP-KRB5-DES-CBC-MD5:EXP-KRB5-RC2-CBC-SHA:EXP-KRB5-DES-CBC-SHA:EXP-EDH-RSA-DES-CBC-SHA:EXP-EDH-DSS-DES-CBC-SHA:EXP-DES-CBC-SHA:EXP-RC2-CBC-MD5:EXP-RC2-CBC-MD5:EXP-KRB5-RC4-MD5:EXP-KRB5-RC4-SHA:EXP-RC4-MD5:EXP-RC4-MD5',
3
]]);
4
file_get_contents('https://fahrkarten.bahn.de', false, $ctx);

Leider unterstuetzt fsockopen keine context.

von bluppdidupp (Gast)


Lesenswert?

Das ist ja interessant - TLS 1.2 unterstützt der Server gar nicht:
https://www.ssllabs.com/ssltest/analyze.html?d=fahrkarten.bahn.de&hideResults=on

von Jim M. (turboj)


Lesenswert?

Der Server fahrkarten.bahn.de:443 unterstützt (Stand 6.1.2015) nur RC4 
als Verschlüsselung, das gilt aber als gebrochen und unsicher. Daher 
verweigert neuere Software die Verbindung, IMHO völlig zurecht.

von Linker und Compilierer (Gast)


Lesenswert?

das Problem - PHP ist ja gelöst:
1
  $ctx=stream_context_create(
2
  array('ssl'=>array('protocol_version' => 'tlsv1.2',
3
  'ciphers' => 'DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA:KRB5-DES-CBC3-MD5:KRB5-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:EDH-DSS-DES-CBC3-SHA:DES-CBC3-SHA:DES-CBC3-MD5:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:AES128-SHA:RC2-CBC-MD5:KRB5-RC4-MD5:KRB5-RC4-SHA:RC4-SHA:RC4-MD5:RC4-MD5:KRB5-DES-CBC-MD5:KRB5-DES-CBC-SHA:EDH-RSA-DES-CBC-SHA:EDH-DSS-DES-CBC-SHA:DES-CBC-SHA:DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5:EXP-KRB5-DES-CBC-MD5:EXP-KRB5-RC2-CBC-SHA:EXP-KRB5-DES-CBC-SHA:EXP-EDH-RSA-DES-CBC-SHA:EXP-EDH-DSS-DES-CBC-SHA:EXP-DES-CBC-SHA:EXP-RC2-CBC-MD5:EXP-RC2-CBC-MD5:EXP-KRB5-RC4-MD5:EXP-KRB5-RC4-SHA:EXP-RC4-MD5:EXP-RC4-MD5',
4
)));
5
  $fp = stream_socket_client(($port==443?"ssl://":"tcp://").
6
       $url.($port==443?":443":":80"),
7
   $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx);

Allerdings habe ich jetzt mit Java das gleiche Problem.
Genau mit der gleichen URL (https://fahrkarten.bahn.de) passiert mit 
Java (neueste Oracle-JDK) diese Exception.
Weiß jemand, wie man das löst?
1
Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: protocol_version
2
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
3
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
4
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
5
  at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
6
  at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1888)
7
  at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1883)
8
  at java.security.AccessController.doPrivileged(Native Method)
9
  at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1882)
10
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1455)
11
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
12
  at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
13
Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
14
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
15
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
16
  at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1991)
17
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1104)
18
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
19
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
20
  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
21
  at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
22
  at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
23
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1511)
24
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
25
  at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2952)
26
  at sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderFields(HttpsURLConnectionImpl.java:283)

von Linker und Compilierer (Gast)


Lesenswert?

Google hat mir folgendes gesagt:
1
-Dhttps.protocols="TLSv1" 
2
or using
3
System.setProperty("https.protocols", "TLSv1");

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.