-
Notifications
You must be signed in to change notification settings - Fork 291
HTTP: Peer ID Authentication #564
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 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e3460e2
Add http peer id auth
MarcoPolo 4af03c4
Include message to sign example. Add bearer token info
MarcoPolo 43a1c72
A single auth scheme
MarcoPolo abd08f2
Allow for using an server-encrypted value as challenge-client
MarcoPolo 7bfd2ae
PR comments
MarcoPolo 6c733c4
Wordsmithing
MarcoPolo 1f1d05c
Add overview, add parameter table
MarcoPolo 45006f1
Comment out parts I want to reword
MarcoPolo f56e82d
Reword
MarcoPolo ccec980
Rename origin to hostname
MarcoPolo f97e596
Fix table
MarcoPolo a1091a4
Address PR comments
MarcoPolo d5ec85a
Wordsmithing
MarcoPolo 1d35258
Drop peer-id parameter. Only public keys
MarcoPolo 24ef2bb
Formatting
MarcoPolo c000bb3
Sort parameters to sign
MarcoPolo e1df507
Fill in examples
MarcoPolo 189492a
Nits
MarcoPolo 05012d7
Add diagram in overview
MarcoPolo 8753236
Add Client Initiated handshake
MarcoPolo ad8cd05
Add maximum header size suggestion
MarcoPolo b51a4cc
Clarify that server may ignore client initiated handshake and start s…
MarcoPolo e074015
Add client initiated example
MarcoPolo 323c5fb
Nits and wordsmithing
MarcoPolo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Peer ID Authentication over HTTP | ||
|
|
||
| | Lifecycle Stage | Maturity | Status | Latest Revision | | ||
| | --------------- | ------------- | ------ | --------------- | | ||
| | 1A | Working Draft | Active | r0, 2023-01-23 | | ||
|
|
||
| Authors: [@MarcoPolo] | ||
|
|
||
| Interest Group: Same as [HTTP](README.md) | ||
|
|
||
| ## Introduction | ||
|
|
||
| This spec defines one way of authenticating Peer IDs over HTTP using a | ||
| challenge-response scheme. | ||
|
|
||
| ## Mutual Client and Server Peer ID Authentication | ||
|
|
||
| 1. The server initiates the authentication by responding to a request that must | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| be authenticated with the response header `WWW-Authenticate: Libp2p-Challenge | ||
| challenge="<base64-encoded-challenge>, Libp2p-Challenge-Server-Only"`. The | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| challenge MUST be randomly generated from server for sole purpose of | ||
| authenticating the client. The server SHOULD store the challenge temporarily | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| until the authentication is done. The challenge SHOULD be at least 32 bytes. | ||
| 1. The client sends a request and sets the `Authorization` | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [header](https://www.rfc-editor.org/rfc/rfc9110.html#section-11.6.2) header | ||
| to the following: | ||
| ``` | ||
| Libp2p-Challenge peer-id="<encoded-peer-id-bytes>",client-challenge="<base64-encoded-client-challenge>",sig="<base64-signature-bytes>" | ||
| ``` | ||
| * The peer-id is encoded per the [peer-ids spec](../peer-ids/peer-ids.md). | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * The signature is over the concatenated result of: | ||
| ``` | ||
| <varint-length> + "origin=" + server-name + | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <varint-length> + "client-challenge=" + base64-encoded-client-chosen-client-challenge + | ||
| <varint-length> + "challenge=" + base64-encoded-challenge | ||
| ``` | ||
| * The client chosen client-challenge MUST be randomly generated. | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * The client chosen client-challenge SHOULD be at least 32 bytes. | ||
| * The client MUST use the same server-name as what is used for the TLS | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| session. | ||
| 1. The server MUST verify the signature using the server name used in the TLS | ||
| session. The server MUST return 401 Unauthorized if the server fails to | ||
| validate the signature. | ||
| 1. If the signature is valid, the server has authenticated the client's peer id | ||
| and MAY fulfill the request according to application logic. If the request is | ||
| fulfilled, the server sets the `Authentication-Info` response header to the | ||
| following: | ||
| ``` | ||
| Libp2p-Challenge peer-id="<encoded-peer-id-bytes>",sig="<base64-signature-bytes>" | ||
| ``` | ||
| * The signature is over the concatenated result of: | ||
| ``` | ||
| <varint-length> + "origin=" + server-name + | ||
| <varint-length> + "client-challenge=" + base64-encoded-client-chosen-client-challenge + | ||
| <varint-length> + "client=" + <encoded-client-peer-id-bytes> | ||
| ``` | ||
| 1. The client can then authenticate the server with the the signature from | ||
| `Authentication-info`. | ||
|
|
||
| ## Server Authentication | ||
|
|
||
| Clients may wish to only authenticate the server's peer ID, but not themselves. | ||
| For example, a short lived client may want to get a block from a specific peer. | ||
|
|
||
| The protocol to do so is as follows: | ||
|
|
||
| 1. The client should set the request header `Authorization` to | ||
| `Libp2p-Challenge-Server-Only <base64-encoded-client-chosen-client-challenge>`. | ||
| 1. The server should response to the request and set `Authentication-Info` | ||
| response header to the following: | ||
| ``` | ||
| Libp2p-Challenge-Server-Only peer-id="<encoded-peer-id-bytes>",sig="<base64-signature-bytes>" | ||
| ``` | ||
| * The signature is over the concatenated result of: | ||
| ``` | ||
| <varint-length> + "origin=" + server-name + | ||
| <varint-length> + "client-challenge=" + base64-encoded-client-chosen-client-challenge | ||
| ``` | ||
| 1. The client can now authenticate the server. | ||
|
|
||
| ## Authentication Endpoint | ||
|
|
||
| Because the client needs to make a request to authenticate the server, and the | ||
| client may not want to make the real request before authenticating the server, | ||
| the server MAY provide an authentication endpoint. This authentication endpoint | ||
| is like any other application protocol, and it shows up in `.well-known/libp2p`, | ||
| but it only does the authentication flow. It doesn’t send any other data besides | ||
| what is defined in the above authentication flows. The protocol id for the | ||
| authentication endpoint is `/http-peer-id-auth/1.0.0`. | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Considerations for Implementations | ||
|
|
||
| * Implementations SHOULD limit the maximum length of any variable length field. | ||
MarcoPolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Note on web PKI | ||
|
|
||
| Protection against man-in-the-middle (mitm) type attacks is through web PKI. If | ||
| the client is in an environment where web PKI can not be fully trusted (e.g. an | ||
| enterprise network with a custom enterprise root CA installed on the client), | ||
| then this authentication scheme can not protect the client from a mitm attack. | ||
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.