-
-
Notifications
You must be signed in to change notification settings - Fork 0
[feature] API's key signatures #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c22621e
add migration
gocanto 79b7e9c
add model
gocanto b4bac35
fix migration
gocanto 2909c17
fix collision
gocanto e2ed2b1
format
gocanto 666da19
work on endpoint
gocanto 8b6a5e4
work on validation
gocanto 25f6a21
fix req payload
gocanto 442d9e8
start working on signature generation
gocanto 2a4eddc
generation
gocanto bdc1db1
work on candence
gocanto c894c04
isert signatures
gocanto f61067b
avoid creating multiple signatures
gocanto 3623b35
fix query
gocanto 2486797
add tries
gocanto 27a9f73
format
gocanto 0afc249
wip
gocanto 40571ad
use a DB trasaction instead
gocanto 216affb
extract guard
gocanto 5a14552
format
gocanto a9dc4e8
response
gocanto cab7e47
add signature validation
gocanto 618671d
add max & current tries
gocanto 8408254
add time constraint
gocanto a28715a
format
gocanto 621cf10
caddy headers
gocanto 8c16cc4
tweaks
gocanto c452421
format
gocanto d5fcf8c
clean up
gocanto 58f3066
performance
gocanto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
database/infra/migrations/000003_api_keys_signatures.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| CREATE TABLE api_key_signatures ( | ||
| id BIGSERIAL PRIMARY KEY, | ||
| uuid UUID UNIQUE NOT NULL, | ||
| api_key_id BIGINT NOT NULL, | ||
| signature BYTEA NOT NULL, | ||
| max_tries SMALLINT NOT NULL DEFAULT 1 CHECK (max_tries > 0), | ||
| current_tries SMALLINT NOT NULL DEFAULT 1 CHECK (current_tries > 0), | ||
| expires_at TIMESTAMP DEFAULT NULL, | ||
| expired_at TIMESTAMP DEFAULT NULL, | ||
| origin TEXT, | ||
| created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
| deleted_at TIMESTAMP DEFAULT NULL, | ||
|
|
||
| CONSTRAINT uq_api_key_signatures_signature UNIQUE (signature), | ||
| CONSTRAINT api_key_signatures_fk_api_key_id FOREIGN KEY (api_key_id) REFERENCES api_keys(id) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE INDEX idx_api_key_signatures_api_key_id ON api_key_signatures(api_key_id); | ||
| CREATE INDEX idx_api_key_signatures_signature_created_at ON api_key_signatures(signature, created_at); | ||
| CREATE INDEX idx_api_key_signatures_origin ON api_key_signatures(origin); | ||
| CREATE INDEX idx_api_key_signatures_expires_at ON api_key_signatures(expires_at); | ||
| CREATE INDEX idx_api_key_signatures_expired_at ON api_key_signatures(expired_at); | ||
| CREATE INDEX idx_api_key_signatures_created_at ON api_key_signatures(created_at); | ||
| CREATE INDEX idx_api_key_signatures_deleted_at ON api_key_signatures(deleted_at); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package repoentity | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/oullin/database" | ||
| ) | ||
|
|
||
| type APIKeyCreateSignatureFor struct { | ||
| Key *database.APIKey | ||
| ExpiresAt time.Time | ||
| Seed []byte | ||
| Origin string | ||
| } | ||
|
|
||
| type FindSignatureFrom struct { | ||
| Key *database.APIKey | ||
| Signature []byte | ||
| Origin string | ||
| ServerTime time.Time | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package payload | ||
|
|
||
| type SignatureRequest struct { | ||
| Nonce string `json:"nonce" validate:"required,lowercase,hexadecimal,len=32"` | ||
| PublicKey string `json:"public_key" validate:"required,lowercase,min=64,max=67"` | ||
| Username string `json:"username" validate:"required,lowercase,min=5"` | ||
| Timestamp int64 `json:"timestamp" validate:"required,number,gte=1000000000,min=10"` | ||
| Origin string `json:"origin"` | ||
| } | ||
|
|
||
| type SignatureResponse struct { | ||
| Signature string `json:"signature"` | ||
| MaxTries int `json:"max_tries"` | ||
| Cadence SignatureCadenceResponse `json:"cadence"` | ||
| } | ||
|
|
||
| type SignatureCadenceResponse struct { | ||
| ReceivedAt string `json:"received_at"` | ||
| CreatedAt string `json:"created_at"` | ||
| ExpiresAt string `json:"expires_at"` | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.