-
Notifications
You must be signed in to change notification settings - Fork 91
RFC 9540 directory and receiver #549
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| //! IO-related types and functions. Specifically, fetching OHTTP keys from a payjoin directory. | ||
|
|
||
| use http::header::ACCEPT; | ||
| use reqwest::{Client, Proxy}; | ||
|
|
||
| use crate::into_url::IntoUrl; | ||
|
|
@@ -17,10 +18,10 @@ pub async fn fetch_ohttp_keys( | |
| ohttp_relay: impl IntoUrl, | ||
| payjoin_directory: impl IntoUrl, | ||
| ) -> Result<OhttpKeys, Error> { | ||
| let ohttp_keys_url = payjoin_directory.into_url()?.join("/ohttp-keys")?; | ||
| let ohttp_keys_url = payjoin_directory.into_url()?.join("/.well-known/ohttp-gateway")?; | ||
| let proxy = Proxy::all(ohttp_relay.into_url()?.as_str())?; | ||
| let client = Client::builder().proxy(proxy).build()?; | ||
| let res = client.get(ohttp_keys_url).send().await?; | ||
| let res = client.get(ohttp_keys_url).header(ACCEPT, "application/ohttp-keys").send().await?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mention in the commit messages that this isn't checked anywhere in the directory. Is there a plan to require that? Seems to not make a huge difference.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it seems needlessly pedantic to me, but i thought it was worth mentioning in case anyone disagrees |
||
| let body = res.bytes().await?.to_vec(); | ||
| OhttpKeys::decode(&body).map_err(|e| Error(InternalError::InvalidOhttpKeys(e.to_string()))) | ||
| } | ||
|
|
@@ -41,14 +42,14 @@ pub async fn fetch_ohttp_keys_with_cert( | |
| payjoin_directory: impl IntoUrl, | ||
| cert_der: Vec<u8>, | ||
| ) -> Result<OhttpKeys, Error> { | ||
| let ohttp_keys_url = payjoin_directory.into_url()?.join("/ohttp-keys")?; | ||
| let ohttp_keys_url = payjoin_directory.into_url()?.join("/.well-known/ohttp-gateway")?; | ||
| let proxy = Proxy::all(ohttp_relay.into_url()?.as_str())?; | ||
| let client = Client::builder() | ||
| .use_rustls_tls() | ||
| .add_root_certificate(reqwest::tls::Certificate::from_der(&cert_der)?) | ||
| .proxy(proxy) | ||
| .build()?; | ||
| let res = client.get(ohttp_keys_url).send().await?; | ||
| let res = client.get(ohttp_keys_url).header(ACCEPT, "application/ohttp-keys").send().await?; | ||
| let body = res.bytes().await?.to_vec(); | ||
| OhttpKeys::decode(&body).map_err(|e| Error(InternalError::InvalidOhttpKeys(e.to_string()))) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may make more sense to have our
extract_reqfns themselvesurl.join("/.well-known/ohttp-gateway").expect("invalid URL")since the path is the same for all functions assuming RFC 9540 compliance. That way the end user only needs to pass the directory origin and not the complete gateway url.I suppose this would make it impossible to use our crate with non-RFC 9540-compliant directories, but I think that's our intended behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not actually relevant, as it is the relay which appends that path
Only the key bootstrapping GET request explicitly specifies the RFC 9540 path, which for now is optional since the old
/ohttp-keysroute is still supported, that functionality accepts the payjoin directory base URI as before.The reason this method is provided is for the integration tests which bypass the relay.