-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add prototype Meridian header #10
Changes from 8 commits
29ffa89
f6fee03
bed38e6
0c69813
f791a89
035578a
27390ce
68ded2c
334077a
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ package frisbii | |
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
|
@@ -15,6 +17,7 @@ import ( | |
"github.com/ipfs/go-unixfsnode" | ||
"github.com/ipld/go-ipld-prime/datamodel" | ||
"github.com/ipld/go-ipld-prime/linking" | ||
"github.com/libp2p/go-libp2p/core/crypto" | ||
) | ||
|
||
var _ http.Handler = (*HttpIpfs)(nil) | ||
|
@@ -23,6 +26,12 @@ type ErrorLogger interface { | |
LogError(status int, err error) | ||
} | ||
|
||
type RequestSignature struct { | ||
RequestId string `json:"requestId"` | ||
Cid string `json:"cid"` | ||
Protocol string `json:"protocol"` | ||
} | ||
|
||
// HttpIpfs is an http.Handler that serves IPLD data via HTTP according to the | ||
// Trustless Gateway specification. | ||
type HttpIpfs struct { | ||
|
@@ -31,6 +40,7 @@ type HttpIpfs struct { | |
lsys linking.LinkSystem | ||
maxResponseDuration time.Duration | ||
maxResponseBytes int64 | ||
privKey crypto.PrivKey | ||
} | ||
|
||
func NewHttpIpfs( | ||
|
@@ -39,6 +49,7 @@ func NewHttpIpfs( | |
lsys linking.LinkSystem, | ||
maxResponseDuration time.Duration, | ||
maxResponseBytes int64, | ||
privKey crypto.PrivKey, | ||
) *HttpIpfs { | ||
|
||
return &HttpIpfs{ | ||
|
@@ -47,6 +58,7 @@ func NewHttpIpfs( | |
lsys: lsys, | ||
maxResponseDuration: maxResponseDuration, | ||
maxResponseBytes: maxResponseBytes, | ||
privKey: privKey, | ||
} | ||
} | ||
|
||
|
@@ -119,6 +131,30 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) { | |
|
||
selNode := unixfsnode.UnixFSPathSelectorBuilder(path.String(), dagScope.TerminalSelectorSpec(), false) | ||
|
||
sig := RequestSignature{ | ||
RequestId: req.Header.Get("X-Request-Id"), | ||
Cid: rootCid.String(), | ||
Protocol: "https", | ||
} | ||
b, err := json.Marshal(sig) | ||
if err != nil { | ||
logError(http.StatusInternalServerError, err) | ||
return | ||
} | ||
sigSigned, err := hi.privKey.Sign(b) | ||
if err != nil { | ||
logError(http.StatusInternalServerError, err) | ||
return | ||
} | ||
res.Header().Set( | ||
"X-Attestation", | ||
fmt.Sprintf( | ||
"\"%s.%s\"", | ||
base64.StdEncoding.EncodeToString(b), | ||
base64.StdEncoding.EncodeToString(sigSigned), | ||
), | ||
) | ||
|
||
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. We need to send the attestation in response trailer headers, after the retrieved content was transmitted. I implemented this change in @juliangruber PTAL, could you also deploy my change to fly.io please?
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong. 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. It turns now Fetch API does not allow clients to read HTTP trailers :( Quoting from denoland/deno#10214 (comment)
Let's not deploy my change yet. |
||
bytesWrittenCh := make(chan struct{}) | ||
writer := newIpfsResponseWriter(res, hi.maxResponseBytes, func() { | ||
// called once we start writing blocks into the CAR (on the first Put()) | ||
|
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.
probably need to gate this on whether this header is included; maybe if there's no request id then you don't get an attestation?