curl

bash timeout

Written by  on Februar 14, 2016

Was tun, wenn man in einem Script nicht ewig auf einen externen Timeout warten möchte?
Wir rufen timeout auf. Das sieht z.B. so in einer Busy Box aus:
$ timeout -t 5 sleep 10
Terminated
$ echo $?
143

Hingegen auf einem Ubuntu 14.04 so:
$ timeout 2 sleep 5
$ echo $?
124

Auch wenn das nicht ganz einheitlich ist, doch ein tolles tool um z.B. curl nach ein paar Sekunden abzubrechen, wenn ein Download nicht funktioniert.

Testing OCSP

Written by  on Dezember 23, 2015

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.

wget and the http protocol version

Written by  on Dezember 4, 2015

Found some scripts using wget, which suddenly stopped working after a server upgrade. Strange thing, using curl still worked. Using a proxy server also worked.
So what was the problem?
The new server version didn’t support HTTP version 1.0 and discarded the requests with HTTP status 403, forbidden. But why in all the possible worlds would wget send an HTTP 1.0 header? Oh, it’s just because its a freaking old wget version 1.12 used by Red Hat which simply won’t support HTTP 1.1!
Check out the version information at Wikidpedia.

Wget 1.13, released August 2011, supports HTTP/1.1

Any newer version than this old version from September 2009 wouldn’t have caused troubles.
If I understand this question at Stackoverflow correctly HTTP 1.1 was introduced in 1996 … but the wget version from 2009 won’t support that.

HTTP Header

Written by  on Mai 3, 2012

Beim Testen von Webservern oder PHP-Scripts die die HTTP-Header auswerten sollen, hab ich bisher noch keine zufriedenstellende Lösung gefunden.
– Ein erster Ansatz war es Telnet zu verwenden, was sich als äusserst Mühsam herausstellt.
– Bald darauf landet man bei der Firefox Extension "Tamper Data" mit der sich die Header-Daten Manipulieren lassen. Da aber für jeden Request wieder angefragt wird, ob überhaupt Daten geändert werden sollen, und bei jedem Request wieder vergessen wird
– Noch eine Möglichkeit sind Curl-Aufrufe. Diese bieten sich für Scripte und automatische Verarbeitung an – sind aber ansonsten genau so mühsam.
– Eine geniale Lösung ohne Plugins stellt Opera mit Opera Dragonfly zur Verfügung:

Starten von Dragonfly

Auswählen von Netzwerk -> "Anfrage Starten"

Voll automatisch lassen sich Requests wiederholen. Alle Header lassen sich überschreiben. Und der Browser merkt sich, was als letztes Aufgerufen wurde. Eigentlich alles was man sich wünscht, nachdem man bisher mit den anderen Lösungen gelebt hat.