feat: read pubkey from file

This commit is contained in:
2021-07-18 23:15:56 +08:00
parent 6e8cd28aa2
commit 671dd62492

10
main.go
View File

@@ -18,7 +18,6 @@ import (
gossh "golang.org/x/crypto/ssh"
)
const SK_ECDSA_PUBKEY = "sk-ecdsa-sha2-nistp256@openssh.com AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTYAAABBBIEy/KQzi+q7uqufEtqHXusQbpT9GVM2j1jNhU83VI8T8VOy4nWX9STNU+qpcwp6l1wqhYZSmMRkXF+3CwCAssAAAAAEc3NoOg== fido-u2f"
const WELCOME = ", . . . \n" +
"| . | | | \n" +
"| ) ) ,-. | ,-. ,-. ;-.-. ,-. |- ,-. \n" +
@@ -33,7 +32,7 @@ const WELCOME = ", . . .
" \n"
func main() {
sshPublicKey, sshPublicKeyErr := parseSshPubkey(SK_ECDSA_PUBKEY)
sshPublicKey, sshPublicKeyErr := parseSshPubkey()
if sshPublicKeyErr != nil {
log.Fatal("Parse sk ecdsa public key failed: ", sshPublicKeyErr)
return
@@ -92,7 +91,12 @@ func setWinsize(f *os.File, w, h int) {
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0})))
}
func parseSshPubkey(pubkey string) (gossh.PublicKey, error) {
func parseSshPubkey() (gossh.PublicKey, error) {
pubkeyBytes, pubkeyErr := ioutil.ReadFile("allowed_key")
if pubkeyErr != nil {
return nil, pubkeyErr
}
pubkey := strings.TrimSpace(string(pubkeyBytes))
if strings.Contains(pubkey, " ") {
pubkey = strings.Split(pubkey, " ")[1]
}