Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
quite committed May 2, 2024
1 parent 65735e8 commit 64ac0fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ age-plugin-tkey: check-deviceapp-hashes
# go build -trimpath -buildvcs=false -ldflags="-X=main.version=$version"
# and CGO_ENABLED=0?

.PHONY: release-build
release-build:
@echo YOU ARE RESPONSIBLE FOR BEING ON A CLEAN TAG
CGO_ENABLED=0 go build -trimpath -buildvcs=false ./cmd/age-plugin-tkey

.PHONY: install
install:
cp -af age-plugin-tkey /usr/local/bin/
Expand Down
14 changes: 13 additions & 1 deletion cmd/age-plugin-tkey/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package main

import (
"crypto/rand"
"errors"
"fmt"
"os"
"time"

"github.com/quite/age-plugin-tkey/internal/identity"
"github.com/quite/age-plugin-tkey/internal/tkey"
"github.com/quite/tkeyx25519"
"github.com/tillitis/tkeyclient"
"golang.org/x/term"
)

Expand All @@ -22,7 +25,16 @@ func generate(out *os.File, requireTouch bool) bool {

udi, id, err := identity.NewIdentity(userSecret[:], requireTouch)
if err != nil {
le.Printf("NewIdentity failed: %s\n", err)
switch {
case errors.Is(err, tkeyclient.ErrNoDevice):
le.Printf("generate failed: %s\n", tkeyclient.ErrNoDevice)
case errors.Is(err, tkeyclient.ErrManyDevices):
le.Printf("generate failed: %s\n", tkeyclient.ErrManyDevices)
case errors.Is(err, tkey.ErrWrongDeviceApp):
le.Printf("generate failed: %s\n", tkeyclient.ErrManyDevices)
default:
le.Printf("NewIdentity failed: %s\n", err)
}
return false
}

Expand Down
18 changes: 12 additions & 6 deletions cmd/age-plugin-tkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ func run() int {
le.Printf("OpenFile failed: %s\n", err)
return 1
}
defer func() {
if err := f.Close(); err != nil {
le.Printf("Close failed: %s\n", err)
}
}()
out = f
}
if !generate(out, noTouchFlag == false) {
success := generate(out, noTouchFlag == false)
if outputFlag != "" {
if err := out.Close(); err != nil {
le.Printf("Close failed: %s\n", err)
}
}
if !success {
if outputFlag != "" {
if err := os.Remove(outputFlag); err != nil {
le.Printf("Remove failed: %s\n", err)
}
}
return 1
}
return 0
Expand Down

0 comments on commit 64ac0fe

Please sign in to comment.