aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/http/public_key_pinning/index.html
blob: b467731092647dfdd7566cd4fb7ca728409e0914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
title: HTTP Public Key Pinning (HPKP)
slug: Web/HTTP/Public_Key_Pinning
tags:
  - Anleitung
  - HPKP
  - HTTP
  - Sicherheit
  - Webentwicklung
translation_of: Web/HTTP/Public_Key_Pinning
original_slug: Web/Security/Public_Key_Pinning
---
<div>{{HTTPSidebar}}</div>

<p class="summary"><span class="seoSummary">Die <strong>Public Key Pinning Erweiterung für HTTP</strong> (</span>{{Glossary("HPKP")}}<span class="seoSummary">) ist ein Sicherheitsfeature, das einem Webclient mitteilt, einen spezifischen kryptographischen Schlüssel mit einem bestimmten Webserver in Verbindung zu bringen um </span>{{Glossary("MITM")}}<span class="seoSummary"> mit gefälschten Zertifikaten zu vermeiden.</span></p>

<p>Um die Echtheit des öffentlichen Schlüssels eines Servers in {{Glossary("TLS")}}-Sessions sicherzustellen, wird dieser in ein X.509-Zertifikat gepackt, welches meistens von einer Zertifizierungsstelle ({{GLossary("CA")}}) signiert wird. Webclients wie Browser vertrauen vielen Zertifizierungsstellen, die Zertifikate für beliebige Domainnamen erstellen können. Wenn ein Angreifer dazu in der Lage ist, eine einzelne Zertifizierungsstelle zu infiltrieren, kann er MITM-Angriffe auf verschiedene TLS-Verbindungen starten. HPKP kann diese Gefahr für das {{Glossary("HTTPS")}}-Protokoll dadurch umgehen, dass dem Client mitgeteilt wird, welcher öffentliche Schlüssel zu einem bestimmten Webserver gehört.</p>

<p>HPKP is ein <em>Trust on First Use</em> ({{Glossary("TOFU")}}) ("Bei der ersten Benutzung vertrauen") Verfahren. Beim ersten Webseitenbesuch übermittelt der Server einen HTTP-Header um dem Client zu zeigen, welche öffentliche Schlüssel zu ihm gehören. Der Client speichert diese Information für eine angegebene Zeit. Wenn der Client die Webseite erneut besucht, erwartet er, dass mindestens ein Zertifikat der Zertifikatkette einen öffentlichen Schlüssel enthält, dessen Fingerprint dem Client bereits per HPKP bekannt ist. Wenn der Server einen unbekannten öffentlichen Schlüssel liefert, sollte der Client einen Fehler anzeigen.</p>

<p class="note">Firefox (und Chrome)<strong> deaktivieren die Pin Validierung</strong> für Pinned Hosts mit Zertifikatketten, die bei einem <strong>benutzerdefinierten trust anchor</strong> terminieren (anstatt bei einem eingebauten trust anchor). Dies bedeutet, dass alle Pinning-Nichteinhaltungen für Nutzer ignoriert werden, welche ein Root-Zertifikat importiert haben.</p>

<h2 id="HPKP_aktivieren">HPKP aktivieren</h2>

<p>Dieses Feature kann einfach aktiviert werden indem ein {{HTTPHeader("Public-Key-Pins")}} HTTP-Header beim Aufruf der Seite über HTTPS zurückgegeben wird:</p>

<pre>Public-Key-Pins: pin-sha256="base64=="; max-age=<em>expireTime</em> [; includeSubdomains][; report-uri="<em>reportURI"</em>]
</pre>

<dl>
 <dt><code>pin-sha256</code></dt>
 <dd>Der Parameter beinhaltet einen Base64 codierten <em>Subject Public Key Information</em> ({{Glossary("SPKI")}}) Fingerprint. Es ist auch möglich mehrere Pins zu verschiedenen öffentlichen Schlüsseln zu definieren. Einige Browser werden hier zukünftig neben SHA-256 evtl. weitere Hash-Algorithmen erlauben. Weiter unten ist beschrieben, wie diese Informationen entweder aus dem Zertifikat oder der Schlüsseldatei extrahiert werden können.</dd>
 <dt><code>max-age</code></dt>
 <dd>Die Zeit (in Sekunden) in Sekunden, die ein Browser sich merken soll, dass auf diese Seite nur bei Benutzung eines der öffentlichen Schlüssel zugegriffen werden darf.</dd>
 <dt><code>includeSubdomains</code> {{ optional_inline() }}</dt>
 <dd>Wenn dieser optionale Parameter angegeben wird, wird die Regel auch auf alle Subdomains der Site angewandt.</dd>
 <dt><code>report-uri</code> {{ optional_inline() }}</dt>
 <dd>Wenn dieser optionale Parameter angegeben wird, werden Pinvalidierungsfehlschläge an die angegebene URL gemeldet.</dd>
</dl>

<div class="note">
<p><strong>Anmerkung:</strong> Die aktuelle Spezifikation verlangt die Aufnahme eines zweiten Pins für einen Backup-Schlüssel, der noch nicht in der Produktion verwendet wird. Dies ermöglicht es, den öffentlichen Schlüssel des Servers zu ändern, ohne die Zugänglichkeit für Clients zu beeinträchtigen, die die Pins bereits bemerkt haben. Dies ist z.B. dann wichtig, wenn der alte Schlüssel beschädigt wird.</p>
</div>

<h3 id="Base64-enkodierte_Public_Key_Informationen_extrahieren">Base64-enkodierte Public Key Informationen extrahieren</h3>

<div class="note">
<p><strong>Note:</strong> Während das folgende Beispiel zeigt, wie man einen Pin auf ein Serverzertifikat setzt, wird empfohlen, den Pin auf das Zwischenzertifikat der CA zu setzen, die das Serverzertifikat ausgestellt hat, um Verlängerungen und Rotationen von Zertifikaten zu erleichtern.</p>
</div>

<p>First you need to extract the public key information from your certificate or key file and encode them using Base64.</p>

<p>The following commands will help you extract the Base64 encoded information from a key file, a certificate signing request, or a certificate.</p>

<pre><code>openssl rsa -in my-key-file.key -outform der -pubout | openssl dgst -sha256 -binary | </code>openssl enc -base64</pre>

<pre><code>openssl req -in my-signing-request.csr -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64</code></pre>

<pre><code>openssl x509 -in my-certificate.crt -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64</code></pre>

<p>The following command will extract the Base64 encoded information for a website.</p>

<pre><code>openssl s_client -connect www.example.com:443 | openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64</code></pre>

<h3 id="Beispiel_für_ein_HPKP-Header">Beispiel für ein HPKP-Header</h3>

<pre>Public-Key-Pins: pin-sha256="cUPcTAZWKaASuYWhhneDttWpY3oBAkE3h2+soZS7sWs="; pin-sha256="M8HztCzM3elUxkcjR2S5P4hhyBNf6lHkmjAHKhpGPWE="; max-age=5184000; includeSubdomains; report-uri="<em>https://www.example.net/hpkp-report"</em></pre>

<p>In this example, <strong>pin-sha256="cUPcTAZWKaASuYWhhneDttWpY3oBAkE3h2+soZS7sWs="</strong> pins the server's public key used in production. The second pin declaration <strong>pin-sha256="M8HztCzM3elUxkcjR2S5P4hhyBNf6lHkmjAHKhpGPWE="</strong> also pins the backup key. <strong>max-age=5184000</strong> tells the client to store this information for two month, which is a reasonable time limit according to the IETF RFC. This key pinning is also valid for all subdomains, which is told by the <strong>includeSubdomains</strong> declaration. Finally, <strong>report-uri="https://www.example.net/hpkp-report"</strong> explains where to report pin validation failures.</p>

<h3 id="Setting_up_your_webserver_to_include_the_HPKP_header">Setting up your webserver to include the HPKP header</h3>

<p>The concrete steps necessary to deliver the HPKP header depend on the web server you use.</p>

<div class="note">
<p><strong>Note:</strong> These examples use a max-age of two months and include all subdomains. It is advised to verify that this setup will work for your server.</p>
</div>

<div class="warning">
<p id="HPKP_hat_das_Potential_Nutzer_für_eine_lange_Zeit_auszusperren_wenn_es_inkorrekt_genutzt_wird!_Die_Benutzung_von_Backup-Zertifikaten_undoder_das_Pinnen_der_Zertifizierungsstelle_wird_dringend_empfohlen.">HPKP hat das Potential Nutzer für eine lange Zeit auszusperren, wenn es inkorrekt genutzt wird! Die Benutzung von Backup-Zertifikaten und/oder das Pinnen der Zertifizierungsstelle wird dringend empfohlen.</p>
</div>

<h4 id="Apache">Apache</h4>

<p>HPKP kann im Apache Webserver beispielsweise mit der folgenden Konfiguration aktiviert werden. Die Parameter müssen dann nur noch auf das Zielsystem angepasst werden. Das Apache Modul <code>mod_headers</code> wird benötigt.</p>

<pre>Header always set Public-Key-Pins "pin-sha256=\"base64+primary==\"; pin-sha256=\"base64+backup==\"; max-age=5184000; includeSubDomains"
</pre>

<h4 id="Nginx">Nginx</h4>

<p>Adding the following line and inserting the appropriate <code>pin-sha256="..."</code> values will enable HPKP on your nginx. This requires the <code>ngx_http_headers_module.</code></p>

<pre>add_header Public-Key-Pins 'pin-sha256="base64+primary=="; pin-sha256="base64+backup=="; max-age=5184000; includeSubDomains';</pre>

<h4 id="Lighttpd">Lighttpd</h4>

<p>The following line with your relevant key information (pin-sha256="..." fields) will enable HPKP on lighttpd.</p>

<pre>setenv.add-response-header  = ( "Public-Key-Pins" =&gt; "pin-sha256=\"base64+primary==\"; pin-sha256=\"base64+backup==\"; max-age=5184000; includeSubDomains")</pre>

<p><strong>Note:</strong> This requires the <code>mod_setenv</code> server.module loaded which can be included by the following if not already loaded.</p>

<pre><code>server.modules += ( "mod_setenv" )</code></pre>

<h4 id="IIS">IIS</h4>

<p>Add the following line to the Web.config file to send the <code>Public-Key-Pins</code> header:</p>

<pre class="brush: xml line-numbers  language-xml"><code class="language-xml">&lt;system.webServer&gt;
  ...

  <span class="tag token"><span class="tag token"><span class="punctuation token">&lt;</span>httpProtocol</span><span class="punctuation token">&gt;</span></span>
    <span class="tag token"><span class="tag token"><span class="punctuation token">&lt;</span>customHeaders</span><span class="punctuation token">&gt;</span></span>
      <span class="tag token"><span class="tag token"><span class="punctuation token">&lt;</span>add</span> <span class="attr-name token">name</span><span class="attr-value token"><span class="punctuation token">=</span><span class="punctuation token">"</span>Public-Key-Pins<span class="punctuation token">"</span></span> <span class="attr-name token">value</span><span class="attr-value token"><span class="punctuation token">=</span><span class="punctuation token">"</span>pin-sha256<span class="punctuation token">=</span>&amp;quot;base64+primary<span class="punctuation token">=</span><span class="punctuation token">=</span>&amp;quot;; pin-sha256<span class="punctuation token">=</span>&amp;quot;base64+backup<span class="punctuation token">=</span><span class="punctuation token">=</span>&amp;quot;; max-age<span class="punctuation token">=</span>5184000; includeSubDomains<span class="punctuation token">"</span></span> <span class="punctuation token">/&gt;</span></span>
    <span class="tag token"><span class="tag token"><span class="punctuation token">&lt;/</span>customHeaders</span><span class="punctuation token">&gt;</span></span>
  <span class="tag token"><span class="tag token"><span class="punctuation token">&lt;/</span>httpProtocol</span><span class="punctuation token">&gt;</span></span>

  ...
&lt;/system.webServer&gt;</code></pre>

<h2 id="Browserkompatibilität">Browserkompatibilität</h2>

<p>{{Compat("http.headers.Public-Key-Pins")}}</p>

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Spezifikation</th>
   <th scope="col">Titel</th>
  </tr>
  <tr>
   <td>{{RFC("7469", "Public-Key-Pins", "2.1")}}</td>
   <td>Public Key Pinning Erweiterung für HTTP</td>
  </tr>
 </tbody>
</table>

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li>{{HTTPHeader("Public-Key-Pins")}}</li>
 <li>{{HTTPHeader("Public-Key-Pins-Report-Only")}}</li>
</ul>