Separate out key directory

This commit is contained in:
cheddar 2025-02-17 19:55:53 -05:00
parent b7671b9a97
commit 3dfe5b8558
No known key found for this signature in database
6 changed files with 85 additions and 60 deletions

20
main.go
View file

@ -13,6 +13,7 @@ import (
"crispbyte.dev/sig-auth/client"
"crispbyte.dev/sig-auth/server"
"crispbyte.dev/sig-auth/sqlite_directory"
"github.com/opencontainers/go-digest"
"golang.org/x/crypto/ssh"
)
@ -92,13 +93,15 @@ func runClient(keyFile *string, simulateCaddy bool) {
}
func runServer(keyFile *string, simulateCaddy bool) {
key, err := loadPublicKey(*keyFile)
key, alg, err := loadPublicKey(*keyFile)
if err != nil {
log.Fatal(err)
}
server.Start(key, simulateCaddy)
keyDir := sqlite_directory.CreateDirectory(alg, key)
server.Start(simulateCaddy, keyDir)
}
func loadPrivateKey(keyFile string) (crypto.PrivateKey, error) {
@ -111,14 +114,21 @@ func loadPrivateKey(keyFile string) (crypto.PrivateKey, error) {
return ssh.ParseRawPrivateKey(keyBytes)
}
func loadPublicKey(keyFile string) (crypto.PublicKey, error) {
func loadPublicKey(keyFile string) (crypto.PublicKey, string, error) {
keyBytes, err := os.ReadFile(keyFile)
if err != nil {
return nil, err
return nil, "", err
}
pk, _, _, _, err := ssh.ParseAuthorizedKey(keyBytes)
return pk.(ssh.CryptoPublicKey).CryptoPublicKey(), err
var alg string
switch pk.Type() {
case "ssh-ed25519":
alg = "ed25519"
}
return pk.(ssh.CryptoPublicKey).CryptoPublicKey(), alg, err
}