Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Aug 28, 2024
1 parent 35012c7 commit 2a55ceb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 40 deletions.
31 changes: 0 additions & 31 deletions p2p/http/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,37 +132,6 @@ func TestMutualAuth(t *testing.T) {
}
}

func FuzzServeHTTP(f *testing.F) {
zeroBytes := make([]byte, 64)
serverKey, _, err := crypto.GenerateEd25519Key(bytes.NewReader(zeroBytes))
require.NoError(f, err)
auth := ServerPeerIDAuth{
PrivKey: serverKey,
ValidHostnameFn: func(s string) bool {
return s == "example.com"
},
TokenTTL: time.Hour,
InsecureNoTLS: true,
}
// Just check that we don't panic
f.Fuzz(func(t *testing.T, data []byte) {
if len(data) == 0 {
return
}
hostLen := int(data[0])
data = data[1:]
if hostLen > len(data) {
return
}
host := string(data[:hostLen])
data = data[hostLen:]
req := httptest.NewRequest("GET", "http://example.com", nil)
req.Host = host
req.Header.Set("Authorization", string(data))
auth.ServeHTTP(httptest.NewRecorder(), req)
})
}

// // Test Vectors
// var zeroBytes = make([]byte, 64)
// var zeroKey, _, _ = crypto.GenerateEd25519Key(bytes.NewReader(zeroBytes))
Expand Down
6 changes: 0 additions & 6 deletions p2p/http/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ type tokenInfo struct {
peerID peer.ID
}

// AddAuthTokenToRequest adds the libp2p-Bearer token to the request. Returns the peer ID of the server.
func (a *ClientPeerIDAuth) AddAuthTokenToRequest(req *http.Request) (peer.ID, error) {
panic("todo")
}

// AuthenticatedDo is like http.Client.Do, but it does the libp2p peer ID auth handshake if needed.
func (a *ClientPeerIDAuth) AuthenticatedDo(client *http.Client, req *http.Request) (peer.ID, *http.Response, error) {
clonedReq := req.Clone(req.Context())
Expand Down Expand Up @@ -92,5 +87,4 @@ func (a *ClientPeerIDAuth) AuthenticatedDo(client *http.Client, req *http.Reques
a.tokenMapMu.Unlock()

return serverPeerID, resp, nil

}
3 changes: 0 additions & 3 deletions p2p/http/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"errors"
"hash"
"net/http"
"sync"
Expand All @@ -28,8 +27,6 @@ type ServerPeerIDAuth struct {
initHmac sync.Once
}

var errMissingAuthHeader = errors.New("missing header")

// ServeHTTP implements the http.Handler interface for PeerIDAuth. It will
// attempt to authenticate the request using using the libp2p peer ID auth
// scheme. If a Next handler is set, it will be called on authenticated
Expand Down

0 comments on commit 2a55ceb

Please sign in to comment.