Redesign authentication protocol

This commit is contained in:
2019-02-22 17:35:49 +01:00
parent 4a69555578
commit 19732daaf5
33 changed files with 791 additions and 413 deletions

View File

@ -1,15 +1,17 @@
package chi
import (
"crypto/rsa"
peering "forge.cadoles.com/wpetit/go-http-peering"
"forge.cadoles.com/wpetit/go-http-peering/server"
"github.com/go-chi/chi"
)
func Mount(r chi.Router, store peering.Store, funcs ...server.OptionFunc) {
r.Post(peering.AdvertisePath, server.AdvertiseHandler(store, funcs...))
func Mount(r chi.Router, store peering.Store, key *rsa.PublicKey, funcs ...server.OptionFunc) {
r.Post(peering.AdvertisePath, server.AdvertiseHandler(store, key, funcs...))
r.Group(func(r chi.Router) {
r.Use(server.Authenticate(store, funcs...))
r.Use(server.Authenticate(store, key, funcs...))
r.Post(peering.UpdatePath, server.UpdateHandler(store, funcs...))
r.Post(peering.PingPath, server.PingHandler(store, funcs...))
})

View File

@ -4,6 +4,7 @@ import (
"testing"
peering "forge.cadoles.com/wpetit/go-http-peering"
peeringCrypto "forge.cadoles.com/wpetit/go-http-peering/crypto"
"forge.cadoles.com/wpetit/go-http-peering/memory"
"github.com/go-chi/chi"
)
@ -13,7 +14,12 @@ func TestMount(t *testing.T) {
r := chi.NewRouter()
store := memory.NewStore()
Mount(r, store)
pk, err := peeringCrypto.CreateRSAKey(1024)
if err != nil {
t.Fatal(err)
}
Mount(r, store, &pk.PublicKey)
routes := r.Routes()