Separate out key directory
This commit is contained in:
parent
b7671b9a97
commit
3dfe5b8558
6 changed files with 85 additions and 60 deletions
|
@ -1,40 +0,0 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/ed25519"
|
||||
"fmt"
|
||||
|
||||
"github.com/common-fate/httpsig/alg_ed25519"
|
||||
"github.com/common-fate/httpsig/verifier"
|
||||
)
|
||||
|
||||
type KeyEntry struct {
|
||||
alg string
|
||||
publicKey crypto.PublicKey
|
||||
userId string
|
||||
}
|
||||
|
||||
type InMemoryDirectory struct {
|
||||
records map[string]KeyEntry
|
||||
}
|
||||
|
||||
func (dir *InMemoryDirectory) GetKey(ctx context.Context, keyId string, _ string) (verifier.Algorithm, error) {
|
||||
entry := dir.records[keyId]
|
||||
|
||||
var alg verifier.Algorithm
|
||||
var err error
|
||||
|
||||
switch entry.alg {
|
||||
case "ed25519":
|
||||
alg = alg_ed25519.Ed25519{
|
||||
PublicKey: entry.publicKey.(ed25519.PublicKey),
|
||||
Attrs: entry.userId,
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("unknown algoritm: %s", entry.alg)
|
||||
}
|
||||
|
||||
return alg, err
|
||||
}
|
|
@ -2,32 +2,20 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/common-fate/httpsig"
|
||||
"github.com/common-fate/httpsig/inmemory"
|
||||
"github.com/common-fate/httpsig/verifier"
|
||||
)
|
||||
|
||||
func Start(publicKey crypto.PublicKey, isCaddyAuth bool) error {
|
||||
keyDir := InMemoryDirectory{
|
||||
records: map[string]KeyEntry{},
|
||||
}
|
||||
|
||||
keyId := "test-id"
|
||||
|
||||
keyDir.records[keyId] = KeyEntry{
|
||||
alg: "ed25519",
|
||||
publicKey: publicKey,
|
||||
userId: "test_user",
|
||||
}
|
||||
|
||||
func Start(isCaddyAuth bool, keyDir verifier.KeyDirectory) error {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
verifier := httpsig.Middleware(httpsig.MiddlewareOpts{
|
||||
NonceStorage: inmemory.NewNonceStorage(),
|
||||
KeyDirectory: &keyDir,
|
||||
KeyDirectory: keyDir,
|
||||
Tag: "auth",
|
||||
Scheme: "http",
|
||||
Authority: "localhost:8080",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue