Skip to content

Commit ec15741

Browse files
committed
Support SCRAM-SHA-256 authentication.
1 parent 933661c commit ec15741

40 files changed

+3069
-284
lines changed

Docs/API/Classes.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ <h4>Declaration</h4>
216216
<p>The result of successfully executing a <code><a href="Classes/Statement.html">Statement</a></code>.</p>
217217
<div class="aside aside-note">
218218
<p class="aside-title">Note</p>
219-
Do not confuse this <code>Cursor</code> class with the SQL cursors created by the <a href="https://www.postgresql.org/docs/11/sql-declare.html">SQL DECLARE
219+
Do not confuse this <code>Cursor</code> class with the SQL cursors created by the <a href="https://www.postgresql.org/docs/12/sql-declare.html">SQL DECLARE
220220
command</a>. The <code>Cursor</code> class exposes
221221
the result of executing a <em>single</em> SQL command. A SQL cursor, on other other hand, exposes
222222
a query&rsquo;s result by <em>repeated</em> execution of the SQL <code>FETCH</code> command.
@@ -232,7 +232,7 @@ <h4>Declaration</h4>
232232
Postgres server.</p>
233233
<div class="aside aside-see-also">
234234
<p class="aside-title">See also</p>
235-
<a href="https://www.postgresql.org/docs/11/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Postgres: Message Flow - Extended
235+
<a href="https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Postgres: Message Flow - Extended
236236
Query</a>
237237

238238
</div>

Docs/API/Classes/Cursor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h1>Cursor</h1>
5555
<p>The result of successfully executing a <code><a href="../Classes/Statement.html">Statement</a></code>.</p>
5656
<div class="aside aside-note">
5757
<p class="aside-title">Note</p>
58-
Do not confuse this <code>Cursor</code> class with the SQL cursors created by the <a href="https://www.postgresql.org/docs/11/sql-declare.html">SQL DECLARE
58+
Do not confuse this <code>Cursor</code> class with the SQL cursors created by the <a href="https://www.postgresql.org/docs/12/sql-declare.html">SQL DECLARE
5959
command</a>. The <code>Cursor</code> class exposes
6060
the result of executing a <em>single</em> SQL command. A SQL cursor, on other other hand, exposes
6161
a query&rsquo;s result by <em>repeated</em> execution of the SQL <code>FETCH</code> command.
@@ -71,7 +71,7 @@ <h1>Cursor</h1>
7171
Postgres server.</p>
7272
<div class="aside aside-see-also">
7373
<p class="aside-title">See also</p>
74-
<a href="https://www.postgresql.org/docs/11/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Postgres: Message Flow - Extended
74+
<a href="https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Postgres: Message Flow - Extended
7575
Query</a>
7676

7777
</div>

Docs/API/Enums.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ <h1>Enumerations</h1>
6767
<div class="abstract">
6868
<p>A credential for authenticating to the Postgres server.</p>
6969

70-
<p>PostgresClientKit supports <code>trust</code>, <code>password</code>, and <code>md5</code> authentication. The configuration of
71-
the Postgres server determines which authentication types are allowed.</p>
70+
<p>PostgresClientKit supports <code>trust</code>, <code>password</code>, <code>md5</code>, and <code>scram-sha-256</code> authentication.
71+
The configuration of the Postgres server determines which authentication types are allowed.</p>
7272
<div class="aside aside-see-also">
7373
<p class="aside-title">See also</p>
74-
<a href="https://www.postgresql.org/docs/11/client-authentication.html">Postgres:
74+
<a href="https://www.postgresql.org/docs/12/client-authentication.html">Postgres:
7575
Client Authentication</a>.
7676

7777
</div>

Docs/API/Enums/Credential.html

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ <h1>Credential</h1>
5454
</div>
5555
<p>A credential for authenticating to the Postgres server.</p>
5656

57-
<p>PostgresClientKit supports <code>trust</code>, <code>password</code>, and <code>md5</code> authentication. The configuration of
58-
the Postgres server determines which authentication types are allowed.</p>
57+
<p>PostgresClientKit supports <code>trust</code>, <code>password</code>, <code>md5</code>, and <code>scram-sha-256</code> authentication.
58+
The configuration of the Postgres server determines which authentication types are allowed.</p>
5959
<div class="aside aside-see-also">
6060
<p class="aside-title">See also</p>
61-
<a href="https://www.postgresql.org/docs/11/client-authentication.html">Postgres:
61+
<a href="https://www.postgresql.org/docs/12/client-authentication.html">Postgres:
6262
Client Authentication</a>.
6363

6464
</div>
@@ -150,6 +150,34 @@ <h4>Declaration</h4>
150150
</section>
151151
</div>
152152
</li>
153+
<li class="item">
154+
<div>
155+
<code>
156+
<a name="/s:17PostgresClientKit10CredentialO11scramSHA256yACSS_tcACmF"></a>
157+
<a name="//apple_ref/swift/Element/scramSHA256(password:)" class="dashAnchor"></a>
158+
<a class="token" href="#/s:17PostgresClientKit10CredentialO11scramSHA256yACSS_tcACmF">scramSHA256(password:)</a>
159+
</code>
160+
</div>
161+
<div class="height-container">
162+
<div class="pointer-container"></div>
163+
<section class="section">
164+
<div class="pointer"></div>
165+
<div class="abstract">
166+
<p>Authenticates using SCRAM-SHA-256 (RFC 7677). This is the most secure authentication
167+
method.</p>
168+
169+
</div>
170+
<div class="declaration">
171+
<h4>Declaration</h4>
172+
<div class="language">
173+
<p class="aside-title">Swift</p>
174+
<pre class="highlight swift"><code><span class="k">case</span> <span class="nf">scramSHA256</span><span class="p">(</span><span class="nv">password</span><span class="p">:</span> <span class="kt">String</span><span class="p">)</span></code></pre>
175+
176+
</div>
177+
</div>
178+
</section>
179+
</div>
180+
</li>
153181
</ul>
154182
</div>
155183
</section>

Docs/API/Enums/PostgresError.html

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,60 @@ <h4>Declaration</h4>
193193
</section>
194194
</div>
195195
</li>
196+
<li class="item">
197+
<div>
198+
<code>
199+
<a name="/s:17PostgresClientKit0A5ErrorO21invalidUsernameStringyA2CmF"></a>
200+
<a name="//apple_ref/swift/Element/invalidUsernameString" class="dashAnchor"></a>
201+
<a class="token" href="#/s:17PostgresClientKit0A5ErrorO21invalidUsernameStringyA2CmF">invalidUsernameString</a>
202+
</code>
203+
</div>
204+
<div class="height-container">
205+
<div class="pointer-container"></div>
206+
<section class="section">
207+
<div class="pointer"></div>
208+
<div class="abstract">
209+
<p>The specified username does not meet the SCRAM-SHA-256 requirements for a username.</p>
210+
211+
</div>
212+
<div class="declaration">
213+
<h4>Declaration</h4>
214+
<div class="language">
215+
<p class="aside-title">Swift</p>
216+
<pre class="highlight swift"><code><span class="k">case</span> <span class="n">invalidUsernameString</span></code></pre>
217+
218+
</div>
219+
</div>
220+
</section>
221+
</div>
222+
</li>
223+
<li class="item">
224+
<div>
225+
<code>
226+
<a name="/s:17PostgresClientKit0A5ErrorO21invalidPasswordStringyA2CmF"></a>
227+
<a name="//apple_ref/swift/Element/invalidPasswordString" class="dashAnchor"></a>
228+
<a class="token" href="#/s:17PostgresClientKit0A5ErrorO21invalidPasswordStringyA2CmF">invalidPasswordString</a>
229+
</code>
230+
</div>
231+
<div class="height-container">
232+
<div class="pointer-container"></div>
233+
<section class="section">
234+
<div class="pointer"></div>
235+
<div class="abstract">
236+
<p>The specified password does not meet the SCRAM-SHA-256 requirements for a password.</p>
237+
238+
</div>
239+
<div class="declaration">
240+
<h4>Declaration</h4>
241+
<div class="language">
242+
<p class="aside-title">Swift</p>
243+
<pre class="highlight swift"><code><span class="k">case</span> <span class="n">invalidPasswordString</span></code></pre>
244+
245+
</div>
246+
</div>
247+
</section>
248+
</div>
249+
</li>
196250
<li class="item">
197251
<div>
198252
<code>
@@ -220,6 +274,33 @@ <h4>Declaration</h4>
220274
</section>
221275
</div>
222276
</li>
277+
<li class="item">
278+
<div>
279+
<code>
280+
<a name="/s:17PostgresClientKit0A5ErrorO29scramSHA256CredentialRequiredyA2CmF"></a>
281+
<a name="//apple_ref/swift/Element/scramSHA256CredentialRequired" class="dashAnchor"></a>
282+
<a class="token" href="#/s:17PostgresClientKit0A5ErrorO29scramSHA256CredentialRequiredyA2CmF">scramSHA256CredentialRequired</a>
283+
</code>
284+
</div>
285+
<div class="height-container">
286+
<div class="pointer-container"></div>
287+
<section class="section">
288+
<div class="pointer"></div>
289+
<div class="abstract">
290+
<p>The Postgres server requires a <code>Credential.scramSHA256</code> for authentication.</p>
291+
292+
</div>
293+
<div class="declaration">
294+
<h4>Declaration</h4>
295+
<div class="language">
296+
<p class="aside-title">Swift</p>
297+
<pre class="highlight swift"><code><span class="k">case</span> <span class="n">scramSHA256CredentialRequired</span></code></pre>
298+
299+
</div>
300+
</div>
301+
</section>
302+
</div>
303+
</li>
223304
<li class="item">
224305
<div>
225306
<code>

Docs/API/Protocols/ConnectionDelegate.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h1>ConnectionDelegate</h1>
7777
<p>Called upon receiving a notice message from the Postgres server.</p>
7878
<div class="aside aside-see-also">
7979
<p class="aside-title">See also</p>
80-
<p><a href="https://www.postgresql.org/docs/11/protocol-flow.html#PROTOCOL-ASYNC">Postgres: Message Flow - Asynchronous
80+
<p><a href="https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-ASYNC">Postgres: Message Flow - Asynchronous
8181
Opererations</a></p>
8282

8383
</div>
@@ -150,7 +150,7 @@ <h4>Parameters</h4>
150150
<p>Called upon a change in the value of certain Postgres server parameters.</p>
151151
<div class="aside aside-see-also">
152152
<p class="aside-title">See also</p>
153-
<p><a href="https://www.postgresql.org/docs/11/protocol-flow.html#PROTOCOL-ASYNC">Postgres: Message Flow - Asynchronous
153+
<p><a href="https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-ASYNC">Postgres: Message Flow - Asynchronous
154154
Opererations</a></p>
155155

156156
</div>
@@ -223,7 +223,7 @@ <h4>Parameters</h4>
223223
<p>Called upon receiving a notification message from the Postgres server.</p>
224224
<div class="aside aside-see-also">
225225
<p class="aside-title">See also</p>
226-
<p><a href="https://www.postgresql.org/docs/11/sql-notify.html">Postgres: NOTIFY command</a></p>
226+
<p><a href="https://www.postgresql.org/docs/12/sql-notify.html">Postgres: NOTIFY command</a></p>
227227

228228
</div>
229229

Docs/API/Structs/ColumnMetadata.html

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ <h4>Declaration</h4>
100100
<div class="abstract">
101101
<p>If the column can be identified as a column of a specific table, the object ID of that
102102
table; otherwise zero.</p>
103+
<div class="aside aside-see-also">
104+
<p class="aside-title">See also</p>
105+
<a href="https://www.postgresql.org/docs/12/catalog-pg-attribute.html">pg_attribute.attrelid</a>
103106

104-
<p>-SeeAlso: <a href="https://www.postgresql.org/docs/12/catalog-pg-attribute.html">pg_attribute.attrelid</a></p>
107+
</div>
105108

106109
</div>
107110
<div class="declaration">
@@ -130,8 +133,11 @@ <h4>Declaration</h4>
130133
<div class="abstract">
131134
<p>If the column can be identified as a column of a specific table, the attribute number of
132135
the column in that table; otherwise zero.</p>
136+
<div class="aside aside-see-also">
137+
<p class="aside-title">See also</p>
138+
<a href="https://www.postgresql.org/docs/12/catalog-pg-attribute.html">pg_attribute.attnum</a>
133139

134-
<p>-SeeAlso: <a href="https://www.postgresql.org/docs/12/catalog-pg-attribute.html">pg_attribute.attnum</a></p>
140+
</div>
135141

136142
</div>
137143
<div class="declaration">
@@ -159,8 +165,11 @@ <h4>Declaration</h4>
159165
<div class="pointer"></div>
160166
<div class="abstract">
161167
<p>The object ID of the column&rsquo;s data type.</p>
168+
<div class="aside aside-see-also">
169+
<p class="aside-title">See also</p>
170+
<a href="https://www.postgresql.org/docs/12/catalog-pg-type.html">pg_type.oid</a>
162171

163-
<p>-SeeAlso: <a href="https://www.postgresql.org/docs/12/catalog-pg-type.html">pg_type.oid</a></p>
172+
</div>
164173

165174
</div>
166175
<div class="declaration">
@@ -188,8 +197,11 @@ <h4>Declaration</h4>
188197
<div class="pointer"></div>
189198
<div class="abstract">
190199
<p>The data type size.</p>
200+
<div class="aside aside-see-also">
201+
<p class="aside-title">See also</p>
202+
<a href="https://www.postgresql.org/docs/12/catalog-pg-type.html">pg_type.typlen</a>
191203

192-
<p>-SeeAlso: <a href="https://www.postgresql.org/docs/12/catalog-pg-type.html">pg_type.typlen</a></p>
204+
</div>
193205

194206
</div>
195207
<div class="declaration">
@@ -217,8 +229,11 @@ <h4>Declaration</h4>
217229
<div class="pointer"></div>
218230
<div class="abstract">
219231
<p>The data type modifier.</p>
232+
<div class="aside aside-see-also">
233+
<p class="aside-title">See also</p>
234+
<a href="https://www.postgresql.org/docs/12/catalog-pg-attribute.html">pg_attribute.atttypmod</a>
220235

221-
<p>-SeeAlso: <a href="https://www.postgresql.org/docs/12/catalog-pg-attribute.html">pg_attribute.atttypmod</a></p>
236+
</div>
222237

223238
</div>
224239
<div class="declaration">

Docs/API/Structs/Notice.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ <h4>Declaration</h4>
131131
<p>The SQLSTATE code for the error. Not localizable.</p>
132132
<div class="aside aside-see-also">
133133
<p class="aside-title">See also</p>
134-
<a href="https://www.postgresql.org/docs/11/static/errcodes-appendix.html">Postgres:
134+
<a href="https://www.postgresql.org/docs/12/static/errcodes-appendix.html">Postgres:
135135
Error Codes</a>
136136

137137
</div>

Docs/setting_up_a_postgres_database_for_testing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ After [installing Postgres](https://www.postgresql.org/download/), follow the st
99
In `postgresql.conf`, ensure:
1010

1111
ssl = on
12+
password_encryption = scram-sha-256
1213

13-
If running Postgres on a different host than PostgresClientKit, confirm `postgressql.conf` also sets [`listen_addresses`](https://www.postgresql.org/docs/11/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS) to the desired network interface.
14+
If running Postgres on a different host than PostgresClientKit, confirm `postgressql.conf` also sets [`listen_addresses`](https://www.postgresql.org/docs/12/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS) to the desired network interface.
1415

1516
## Configure authentication
1617

@@ -24,13 +25,16 @@ host postgresclientkittest charlie_postgresclientkittest 0.0.0.0/0
2425
host postgresclientkittest charlie_postgresclientkittest ::0/0 password
2526
host postgresclientkittest mary_postgresclientkittest 0.0.0.0/0 md5
2627
host postgresclientkittest mary_postgresclientkittest ::0/0 md5
28+
host postgresclientkittest sally_postgresclientkittest 0.0.0.0/0 scram-sha-256
29+
host postgresclientkittest sally_postgresclientkittest ::0/0 scram-sha-256
2730
```
2831

2932
This configures how Postgres authenticates three test users.
3033

3134
- User `terry_postgresclientkittest` authenticates by `trust` (no password)
3235
- User `charlie_postgresclientkittest` authenticates by `password` (a cleartext password)
3336
- User `mary_postgresclientkittest` authenticates by `md5` (an MD5 hash of the username, password, and random salt)
37+
- User `sally_postgresclientkittest` authenticates by `scram-sha-256` (the most secure authentication mechanism supported)
3438

3539
(The users will be created below.)
3640

Docs/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ssl = on
4646

4747
## Authentication issues
4848

49-
Review the [`pg_hba.conf`](https://www.postgresql.org/docs/11/auth-pg-hba-conf.html) file for your Postgres server. PostgresClientKit supports the `trust`, `password`, and `md5` options for `auth-method`.
49+
Review the [`pg_hba.conf`](https://www.postgresql.org/docs/11/auth-pg-hba-conf.html) file for your Postgres server. PostgresClientKit supports the `trust`, `password`, `md5`, and `scram-sha-256` options for `auth-method`.
5050

5151

5252
## Cursor is unexpectedly closed

0 commit comments

Comments
 (0)