Skip to content

Commit 65300ca

Browse files
committed
Rename make_credential() to store_credential()
Since the credential is made on the client-side, "make" is a bad name as it implies that the credential is made on the server, but it isn't, it's merely "stored" on the server.
1 parent bc6a07e commit 65300ca

32 files changed

+68
-63
lines changed

1.0--1.1.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

1.1--1.2.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DROP FUNCTION webauthn.make_credential(
2+
credential_id text,
3+
credential_type webauthn.credential_type,
4+
attestation_object text,
5+
client_data_json text,
6+
credential_at timestamptz
7+
);

FUNCTIONS/generate_test.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SELECT jsonb_pretty(webauthn.init_credential(
2525
challenge_at := '%10$s'
2626
));
2727

28-
SELECT * FROM webauthn.make_credential(
28+
SELECT * FROM webauthn.store_credential(
2929
credential_id := '%11$s',
3030
credential_type := '%12$s',
3131
attestation_object := '%13$s',
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE OR REPLACE FUNCTION webauthn.make_credential(
1+
CREATE OR REPLACE FUNCTION webauthn.store_credential(
22
OUT user_id bytea,
33
credential_id text,
44
credential_type webauthn.credential_type,
@@ -11,15 +11,15 @@ LANGUAGE sql
1111
AS $$
1212
INSERT INTO webauthn.credentials (credential_id, credential_type, attestation_object, client_data_json, challenge, user_name, user_id, credential_at)
1313
SELECT
14-
webauthn.base64url_decode(make_credential.credential_id),
15-
make_credential.credential_type,
16-
webauthn.base64url_decode(make_credential.attestation_object),
17-
webauthn.base64url_decode(make_credential.client_data_json),
14+
webauthn.base64url_decode(store_credential.credential_id),
15+
store_credential.credential_type,
16+
webauthn.base64url_decode(store_credential.attestation_object),
17+
webauthn.base64url_decode(store_credential.client_data_json),
1818
credential_challenges.challenge,
1919
credential_challenges.user_name,
2020
credential_challenges.user_id,
21-
make_credential.credential_at
21+
store_credential.credential_at
2222
FROM webauthn.credential_challenges
23-
WHERE credential_challenges.challenge = webauthn.base64url_decode(webauthn.from_utf8(webauthn.base64url_decode(make_credential.client_data_json))::jsonb->>'challenge')
23+
WHERE credential_challenges.challenge = webauthn.base64url_decode(webauthn.from_utf8(webauthn.base64url_decode(store_credential.client_data_json))::jsonb->>'challenge')
2424
RETURNING credentials.user_id
2525
$$;

Makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
EXTENSION = webauthn
2-
DATA = webauthn--1.1.sql webauthn--1.0--1.1.sql
2+
DATA = webauthn--1.2.sql webauthn--1.1--1.2.sql
33
REGRESS = ok \
44
ok_user_handle \
55
error_assertions_check_user_verified_or_not_required \
@@ -13,13 +13,13 @@ REGRESS = ok \
1313
error_replay_attack \
1414
error_hijack_attack
1515

16-
EXTRA_CLEAN = webauthn--1.1.sql webauthn--1.0--1.1.sql
16+
EXTRA_CLEAN = webauthn--1.2.sql webauthn--1.1--1.2.sql
1717

1818
PG_CONFIG = pg_config
1919
PGXS := $(shell $(PG_CONFIG) --pgxs)
2020
include $(PGXS)
2121

22-
all: webauthn--1.1.sql webauthn--1.0--1.1.sql
22+
all: webauthn--1.2.sql webauthn--1.1--1.2.sql
2323

2424
SQL_SRC = \
2525
complain_header.sql \
@@ -45,19 +45,18 @@ SQL_SRC = \
4545
TABLES/assertions.sql \
4646
FUNCTIONS/get_credential_creation_options.sql \
4747
FUNCTIONS/init_credential.sql \
48-
FUNCTIONS/make_credential.sql \
48+
FUNCTIONS/store_credential.sql \
4949
FUNCTIONS/get_credentials.sql \
5050
FUNCTIONS/verify_assertion.sql \
5151
FUNCTIONS/generate_test.sql
5252

53-
webauthn--1.1.sql: $(SQL_SRC)
53+
webauthn--1.2.sql: $(SQL_SRC)
5454
cat $^ > $@
5555

5656
SQL_SRC = \
5757
complain_header.sql \
58-
FUNCTIONS/get_credential_creation_options.sql \
59-
FUNCTIONS/init_credential.sql \
60-
1.0--1.1.sql
58+
FUNCTIONS/store_credential.sql \
59+
1.1--1.2.sql
6160

62-
webauthn--1.0--1.1.sql: $(SQL_SRC)
61+
webauthn--1.1--1.2.sql: $(SQL_SRC)
6362
cat $^ > $@

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
1. [API](#api)
88
1. [Sign-up functions](#sign-up)
99
1. [webauthn.init_credential()]
10-
1. [webauthn.make_credential()]
10+
1. [webauthn.store_credential()]
1111
1. [Sign-in functions](#sign-in)
1212
1. [webauthn.get_credentials()]
1313
1. [webauthn.verify_assertion()]
1414

1515
[webauthn.init_credential()]: #init-credential
16-
[webauthn.make_credential()]: #make-credential
16+
[webauthn.store_credential()]: #make-credential
1717
[webauthn.get_credentials()]: #get-credentials
1818
[webauthn.verify_assertion()]: #verify-assertion
1919

@@ -85,7 +85,7 @@ The API consists of two sign-up functions and two sign-in functions.
8585

8686
<h3 id="sign-up">5.1. Sign-up functions</h3>
8787

88-
To sign-up, the browser first calls [webauthn.init_credential()] to get a list of supported crypto algorithms together with a random challenge to be used in the subsequent [webauthn.make_credential()] call to save the public key credential generated by the browser.
88+
To sign-up, the browser first calls [webauthn.init_credential()] to get a list of supported crypto algorithms together with a random challenge to be used in the subsequent [webauthn.store_credential()] call to save the public key credential generated by the browser.
8989

9090
<h3 id="init-credential"><code>webauthn.init_credential(...) → jsonb</code></h3>
9191

@@ -173,7 +173,7 @@ SELECT jsonb_pretty(webauthn.init_credential(
173173
}
174174
```
175175

176-
<h3 id="make-credential"><code>webauthn.make_credential(...) → user_id bytea</code></h3>
176+
<h3 id="make-credential"><code>webauthn.store_credential(...) → user_id bytea</code></h3>
177177

178178
Input Parameter | Type
179179
-------------------- | ------------------------
@@ -189,14 +189,14 @@ Input Parameter | Type
189189
[client_data_json]: https://www.w3.org/TR/webauthn-2/#dom-authenticatorresponse-clientdatajson
190190
[base64url]: https://tools.ietf.org/html/rfc4648#section-5
191191

192-
Source code: [FUNCTIONS/make_credential.sql](https://github.com/truthly/pg-webauthn/blob/master/FUNCTIONS/make_credential.sql#L1)
192+
Source code: [FUNCTIONS/store_credential.sql](https://github.com/truthly/pg-webauthn/blob/master/FUNCTIONS/store_credential.sql#L1)
193193

194194
Stores the public key for the credential generated by the browser to the [webauthn.credentials](https://github.com/truthly/pg-webauthn/blob/master/TABLES/credentials.sql#L1) table.
195195
The [challenge] can only be used once to prevent replay attacks.
196196
If successful, returns the corresponding [user_id] bytea value given as input to [webauthn.init_credential()], or `NULL` to indicate failure.
197197

198198
```sql
199-
SELECT * FROM webauthn.make_credential(
199+
SELECT * FROM webauthn.store_credential(
200200
credential_id := 'TMvc9cgQ4S3H498Qez2ilQdkDS02s0sR7wXyiaKrUphXQRNqiP1pfzoBPsEey8wjHDUXh_A-91zqP_H0bkeohA',
201201
credential_type := 'public-key',
202202
attestation_object := 'o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjESZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2NBAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEzL3PXIEOEtx-PfEHs9opUHZA0tNrNLEe8F8omiq1KYV0ETaoj9aX86AT7BHsvMIxw1F4fwPvdc6j_x9G5HqISlAQIDJiABIVggf6kt0GZu7nwT3be2JJsMj5-6Q2CFfE4V0vxjSitaH48iWCDbmYOzGUadNecZo7k-GsKShUzT_yrVCJhoGwoy_7y8ag',
@@ -224,7 +224,7 @@ Input Parameter | Type | Defa
224224

225225
Source code: [FUNCTIONS/get_credentials.sql](https://github.com/truthly/pg-webauthn/blob/master/FUNCTIONS/get_credentials.sql#L1)
226226

227-
Stores the random challenge to the [webauthn.assertion_challenges](https://github.com/truthly/pg-webauthn/blob/master/TABLES/assertion_challenges.sql#L1) table. If [user_name] is set, the returned *publicKey.allowCredentials* field will contain a list of all public keys matching [relying_party_id] and [user_name]. Such public keys have previously been created by the [webauthn.make_credential()] function,
227+
Stores the random challenge to the [webauthn.assertion_challenges](https://github.com/truthly/pg-webauthn/blob/master/TABLES/assertion_challenges.sql#L1) table. If [user_name] is set, the returned *publicKey.allowCredentials* field will contain a list of all public keys matching [relying_party_id] and [user_name]. Such public keys have previously been created by the [webauthn.store_credential()] function,
228228
stored in the [webauthn.credentials](https://github.com/truthly/pg-webauthn/blob/master/TABLES/credentials.sql#L1) table.
229229

230230
The [timeout] value, if specified, must lie [within a reasonable range](https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source) between 30 seconds to 10 minutes.

TABLES/credentials.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ALTER TABLE webauthn.credentials ADD UNIQUE (user_name, user_id, challenge);
4747
ALTER TABLE webauthn.credential_challenges ADD UNIQUE (user_name, user_id, challenge);
4848
ALTER TABLE webauthn.credentials ADD FOREIGN KEY (user_name, user_id, challenge) REFERENCES webauthn.credential_challenges (user_name, user_id, challenge);
4949

50-
COMMENT ON TABLE webauthn.credentials IS 'Used by webauthn.make_credential() to store credentials.';
50+
COMMENT ON TABLE webauthn.credentials IS 'Used by webauthn.store_credential() to store credentials.';
5151

5252
COMMENT ON COLUMN webauthn.credentials.credential_id IS 'https://www.w3.org/TR/webauthn-2/#credential-id';
5353
COMMENT ON COLUMN webauthn.credentials.challenge IS 'https://www.w3.org/TR/webauthn-2/#dom-collectedclientdata-challenge';
@@ -65,4 +65,4 @@ COMMENT ON COLUMN webauthn.credentials.client_data_json IS 'https://www.w3.org/T
6565
COMMENT ON COLUMN webauthn.credentials.origin IS 'https://www.w3.org/TR/webauthn-2/#dom-collectedclientdata-origin';
6666
COMMENT ON COLUMN webauthn.credentials.cross_origin IS 'https://www.w3.org/TR/webauthn-2/#dom-collectedclientdata-crossorigin';
6767
COMMENT ON COLUMN webauthn.credentials.user_id IS 'https://www.w3.org/TR/webauthn-2/#dom-publickeycredentialuserentity-id';
68-
COMMENT ON COLUMN webauthn.credentials.credential_at IS 'Timestamp of when the credential was created by webauthn.make_credential()';
68+
COMMENT ON COLUMN webauthn.credentials.credential_at IS 'Timestamp of when the credential was created by webauthn.store_credential()';

expected/error_assertions_check_reasonable_timeout.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SELECT jsonb_pretty(webauthn.init_credential(
4343
}
4444
(1 row)
4545

46-
SELECT * FROM webauthn.make_credential(
46+
SELECT * FROM webauthn.store_credential(
4747
credential_id := 'TMvc9cgQ4S3H498Qez2ilQdkDS02s0sR7wXyiaKrUphXQRNqiP1pfzoBPsEey8wjHDUXh_A-91zqP_H0bkeohA',
4848
credential_type := 'public-key',
4949
attestation_object := 'o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjESZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2NBAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEzL3PXIEOEtx-PfEHs9opUHZA0tNrNLEe8F8omiq1KYV0ETaoj9aX86AT7BHsvMIxw1F4fwPvdc6j_x9G5HqISlAQIDJiABIVggf6kt0GZu7nwT3be2JJsMj5-6Q2CFfE4V0vxjSitaH48iWCDbmYOzGUadNecZo7k-GsKShUzT_yrVCJhoGwoy_7y8ag',

expected/error_assertions_check_user_handle_equal_or_null.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SELECT jsonb_pretty(webauthn.init_credential(
4343
}
4444
(1 row)
4545

46-
SELECT * FROM webauthn.make_credential(
46+
SELECT * FROM webauthn.store_credential(
4747
credential_id := 'TMvc9cgQ4S3H498Qez2ilQdkDS02s0sR7wXyiaKrUphXQRNqiP1pfzoBPsEey8wjHDUXh_A-91zqP_H0bkeohA',
4848
credential_type := 'public-key',
4949
attestation_object := 'o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjESZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2NBAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEzL3PXIEOEtx-PfEHs9opUHZA0tNrNLEe8F8omiq1KYV0ETaoj9aX86AT7BHsvMIxw1F4fwPvdc6j_x9G5HqISlAQIDJiABIVggf6kt0GZu7nwT3be2JJsMj5-6Q2CFfE4V0vxjSitaH48iWCDbmYOzGUadNecZo7k-GsKShUzT_yrVCJhoGwoy_7y8ag',

expected/error_assertions_check_user_verified_or_not_required.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SELECT jsonb_pretty(webauthn.init_credential(
4343
}
4444
(1 row)
4545

46-
SELECT * FROM webauthn.make_credential(
46+
SELECT * FROM webauthn.store_credential(
4747
credential_id := 'TMvc9cgQ4S3H498Qez2ilQdkDS02s0sR7wXyiaKrUphXQRNqiP1pfzoBPsEey8wjHDUXh_A-91zqP_H0bkeohA',
4848
credential_type := 'public-key',
4949
attestation_object := 'o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjESZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2NBAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEzL3PXIEOEtx-PfEHs9opUHZA0tNrNLEe8F8omiq1KYV0ETaoj9aX86AT7BHsvMIxw1F4fwPvdc6j_x9G5HqISlAQIDJiABIVggf6kt0GZu7nwT3be2JJsMj5-6Q2CFfE4V0vxjSitaH48iWCDbmYOzGUadNecZo7k-GsKShUzT_yrVCJhoGwoy_7y8ag',

0 commit comments

Comments
 (0)