Skip to content

initial yubikey piv support #409

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

Closed
wants to merge 25 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions backend/backend.go
Original file line number Diff line number Diff line change
@@ -3,9 +3,11 @@ package backend
import (
"crypto"
"crypto/x509"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"github.com/foxboron/sbctl/logging"
"io"
"os"
"path/filepath"
@@ -81,8 +83,6 @@ func (k *KeyHierarchy) GetKeyBackend(e efivar.Efivar) KeyBackend {
return k.KEK
case efivar.Db:
return k.Db
// case efivar.Dbx:
// return k.Dbx
default:
panic("invalid key hierarchy")
}
@@ -200,6 +200,8 @@ func createKey(state *config.State, backend string, hier hierarchy.Hierarchy, de
return NewFileKey(hier, desc)
case "tpm":
return NewTPMKey(state.TPM, desc)
case "yubikey":
return NewYubikeyKey(state.YubikeySigKeys, hier, desc)
default:
return NewFileKey(hier, desc)
}
@@ -255,6 +257,8 @@ func readKey(state *config.State, keydir string, kc *config.KeyConfig, hier hier
return FileKeyFromBytes(keyb, pemb)
case TPMBackend:
return TPMKeyFromBytes(state.TPM, keyb, pemb)
case YubikeyBackend:
return YubikeyFromBytes(state.YubikeySigKeys, keyb, pemb)
default:
return nil, fmt.Errorf("unknown key")
}
@@ -295,15 +299,25 @@ func GetKeyHierarchy(vfs afero.Fs, state *config.State) (*KeyHierarchy, error) {
}

func GetBackendType(b []byte) (BackendType, error) {
block, _ := pem.Decode(b)
// TODO: Add TSS2 keys
switch block.Type {
case "PRIVATE KEY":
return FileBackend, nil
case "TSS2 PRIVATE KEY":
return TPMBackend, nil
default:
return "", fmt.Errorf("unknown file type: %s", block.Type)
if json.Valid(b) {
var yubiData YubikeyData
err := json.Unmarshal(b, &yubiData)
if err != nil {
logging.Errorf("Error unmarshalling Yubikey: %v\n", err)
return "", err
}
return YubikeyBackend, nil
} else {
block, _ := pem.Decode(b)
// TODO: Add TSS2 keys
switch block.Type {
case "PRIVATE KEY":
return FileBackend, nil
case "TSS2 PRIVATE KEY":
return TPMBackend, nil
default:
return "", fmt.Errorf("unknown file type: %s", block.Type)
}
}
}

@@ -322,6 +336,8 @@ func InitBackendFromKeys(state *config.State, priv, pem []byte, hier hierarchy.H
return FileKeyFromBytes(priv, pem)
case "tpm":
return TPMKeyFromBytes(state.TPM, priv, pem)
case "yubikey":
return YubikeyFromBytes(state.YubikeySigKeys, priv, pem)
default:
return nil, fmt.Errorf("unknown key backend: %s", t)
}
Loading