pax_global_header00006660000000000000000000000064147146401720014520gustar00rootroot0000000000000052 comment=a7e0fa528e8950267f611f26d8a29300ce3c9e5d tkeyutil-0.0.9/000077500000000000000000000000001471464017200134005ustar00rootroot00000000000000tkeyutil-0.0.9/.editorconfig000066400000000000000000000000411471464017200160500ustar00rootroot00000000000000[*.{go,md}] max_line_length = 70 tkeyutil-0.0.9/.github/000077500000000000000000000000001471464017200147405ustar00rootroot00000000000000tkeyutil-0.0.9/.github/workflows/000077500000000000000000000000001471464017200167755ustar00rootroot00000000000000tkeyutil-0.0.9/.github/workflows/ci.yaml000066400000000000000000000015331471464017200202560ustar00rootroot00000000000000 name: ci on: push: branches: - 'main' pull_request: {} # allow manual runs: workflow_dispatch: {} jobs: ci: runs-on: ubuntu-latest container: image: ghcr.io/tillitis/tkey-builder:4 steps: - name: checkout uses: actions/checkout@v4 with: # fetch-depth: 0 persist-credentials: false - name: fix # https://github.com/actions/runner-images/issues/6775 run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" - name: make run: make -j - name: check for SPDX tags run: ./tools/spdx-ensure reuse-compliance-check: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: REUSE Compliance Check uses: fsfe/reuse-action@v4 with: args: lint tkeyutil-0.0.9/.github/workflows/golangci-lint.yml000066400000000000000000000037001471464017200222470ustar00rootroot00000000000000name: golangci-lint on: push: branches: - main pull_request: permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. # pull-requests: read jobs: golangci: name: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: '1.23' cache: false - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. version: v1.61.0 # Optional: working directory, useful for monorepos # working-directory: somedir # Optional: golangci-lint command line arguments. # # Note: By default, the `.golangci.yml` file should be at the root of the repository. # The location of the configuration file can be changed by using `--config=` # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true # Optional: if set to true, then all caching functionality will be completely disabled, # takes precedence over all other caching options. # skip-cache: true # Optional: if set to true, then the action won't cache or restore ~/go/pkg. # skip-pkg-cache: true # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. # skip-build-cache: true # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. # install-mode: "goinstall" tkeyutil-0.0.9/.gitignore000066400000000000000000000000241471464017200153640ustar00rootroot00000000000000*.a *.o *.bin *.elf tkeyutil-0.0.9/.golangci.yml000066400000000000000000000010711471464017200157630ustar00rootroot00000000000000linters: presets: # found in: golangci-lint help linters - bugs - comment - complexity - error - format - import - metalinter - module - performance - sql # - style # turned off, can be too much - test - unused disable: - cyclop - funlen - gocognit - nestif - exhaustruct # TODO? annoying for now - err113 # TODO enable later - godot - depguard - perfsprint issues: max-issues-per-linter: 0 max-same-issues: 0 linters-settings: govet: enable: - shadow tkeyutil-0.0.9/LICENSE000066400000000000000000000024241471464017200144070ustar00rootroot00000000000000BSD 2-Clause License Copyright 2022 Tillitis AB Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tkeyutil-0.0.9/LICENSES/000077500000000000000000000000001471464017200146055ustar00rootroot00000000000000tkeyutil-0.0.9/LICENSES/BSD-2-Clause.txt000066400000000000000000000023761471464017200173370ustar00rootroot00000000000000Copyright 2022 Tillitis AB Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tkeyutil-0.0.9/Makefile000066400000000000000000000001371471464017200150410ustar00rootroot00000000000000all: go build .PHONY: spdx spdx: ./tools/spdx-ensure .PHONY: lint lint: golangci-lint run tkeyutil-0.0.9/README.md000066400000000000000000000032361471464017200146630ustar00rootroot00000000000000[![ci](https://github.com/tillitis/tkeyutil/actions/workflows/ci.yaml/badge.svg?branch=main&event=push)](https://github.com/tillitis/tkeyutil/actions/workflows/ci.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/tillitis/tkeyutil.svg)](https://pkg.go.dev/github.com/tillitis/tkeyutil) # Tillitis TKey Utility package A Go package with utility functions for a client application communicating with a [Tillitis](https://tillitis.se/) TKey. See the [Go doc](https://pkg.go.dev/github.com/tillitis/tkeyutil) for `tkeyutil` for details on how to call the functions. See [tkey-ssh-agent](https://github.com/tillitis/tkey-ssh-agent/) for an example client application. Release notes in [RELEASE.md](RELEASE.md). ## Licenses and SPDX tags Unless otherwise noted, the project sources are copyright Tillitis AB, licensed under the terms and conditions of the "BSD-2-Clause" license. See [LICENSE](LICENSE) for the full license text. Until Oct 7, 2024, the license was GPL-2.0 Only. External source code we have imported are isolated in their own directories. They may be released under other licenses. This is noted with a similar `LICENSE` file in every directory containing imported sources. The project uses single-line references to Unique License Identifiers as defined by the Linux Foundation's [SPDX project](https://spdx.org/) on its own source files, but not necessarily imported files. The line in each individual source file identifies the license applicable to that file. The current set of valid, predefined SPDX identifiers can be found on the SPDX License List at: https://spdx.org/licenses/ We attempt to follow the [REUSE specification](https://reuse.software/). tkeyutil-0.0.9/RELEASE.md000066400000000000000000000005711471464017200150050ustar00rootroot00000000000000## v0.0.9 Fix a bug where the `--uss` flag would generate an invalid handle error on Windows machines, due to an incorrect file descriptor. ## v0.0.8 This release only changes the license to BSD-2 Clause. This repository is now REUSE compliant, see https://reuse.software/. ## v0.0.7 Just ripped from https://github.com/tillitis/tillitis-key1-apps No semantic changes. tkeyutil-0.0.9/REUSE.toml000066400000000000000000000010371471464017200151610ustar00rootroot00000000000000# SPDX-FileCopyrightText: 2024 Tillitis AB # SPDX-License-Identifier: BSD-2-Clause version = 1 [[annotations]] path = ".github/workflows/*" SPDX-FileCopyrightText = "2022 Tillitis AB " SPDX-License-Identifier = "BSD-2-Clause" [[annotations]] path = [ ".editorconfig", ".gitignore", ".golangci.yml", "LICENSE", "Makefile", "RELEASE.md", "README.md", "go.mod", "go.sum" ] SPDX-FileCopyrightText = "2022 Tillitis AB " SPDX-License-Identifier = "BSD-2-Clause" tkeyutil-0.0.9/go.mod000066400000000000000000000006731471464017200145140ustar00rootroot00000000000000module github.com/tillitis/tkeyutil go 1.19 require ( github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 golang.org/x/sys v0.26.0 golang.org/x/term v0.25.0 ) require ( github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect ) tkeyutil-0.0.9/go.sum000066400000000000000000000037051471464017200145400ustar00rootroot00000000000000github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f h1:oRm7Hy2dQWfHgOuOWRaYZf+kZcWJst7fxAlq+yjdLss= github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4= github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI= github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4= github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE= github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk= github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= tkeyutil-0.0.9/notify_unix.go000066400000000000000000000006021471464017200163000ustar00rootroot00000000000000// SPDX-FileCopyrightText: 2023 Tillitis AB // SPDX-License-Identifier: BSD-2-Clause //go:build unix package tkeyutil import ( "fmt" "os" "github.com/gen2brain/beeep" ) func Notify(progname, msg string) { // Using progname as title if err := beeep.Notify(progname, msg, ""); err != nil { fmt.Fprintf(os.Stderr, "Notify message %q failed: %s\n", msg, err) } } tkeyutil-0.0.9/notify_windows.go000066400000000000000000000017421471464017200170150ustar00rootroot00000000000000// SPDX-FileCopyrightText: 2023 Tillitis AB // SPDX-License-Identifier: BSD-2-Clause //go:build windows package tkeyutil import ( "fmt" "os" "github.com/gen2brain/beeep" "github.com/go-toast/toast" "golang.org/x/sys/windows" ) var isWindows10 bool func init() { maj, _, _ := windows.RtlGetNtVersionNumbers() isWindows10 = (maj >= 10) } func Notify(progname, msg string) { // Doing this because beeep doesn't let us set appID if isWindows10 { // Skipping msg title in win10+ toast. AppID (progname) will // be displayed at the top of the toast frame. notification := toast.Notification{ AppID: progname, Title: "", Message: msg, Icon: "", } if err := notification.Push(); err != nil { fmt.Fprintf(os.Stderr, "toastNotify message %q failed: %s\n", msg, err) } return } // Using progname as title if err := beeep.Notify(progname, msg, ""); err != nil { fmt.Fprintf(os.Stderr, "Notify message %q failed: %s\n", msg, err) } } tkeyutil-0.0.9/tools/000077500000000000000000000000001471464017200145405ustar00rootroot00000000000000tkeyutil-0.0.9/tools/spdx-ensure000077500000000000000000000034271471464017200167510ustar00rootroot00000000000000#!/bin/bash # SPDX-FileCopyrightText: 2022 Tillitis AB # SPDX-License-Identifier: BSD-2-Clause set -eu # Check for the SPDX tag in all files in the repo. Exit with a non-zero code if # some is missing. The missingok arrays below contain files and directories # with files where the the tag is not required. cd "${0%/*}" cd .. tag="SPDX-License-Identifier:" missingok_dirs=( .github/workflows/ ) missingok_files=( .editorconfig .gitignore .golangci.yml LICENSE LICENSES/BSD-2-Clause.txt Makefile RELEASE.md README.md go.mod go.sum ) is_missingok() { item="$1" # ok for empty files [[ -f "$item" ]] && [[ ! -s "$item" ]] && return 0 for fileok in "${missingok_files[@]}"; do [[ "$item" = "$fileok" ]] && return 0 done for dirok in "${missingok_dirs[@]}"; do [[ "$item" =~ ^$dirok ]] && return 0 done return 1 } printf "* Checking for SPDX tags in %s\n" "$PWD" mapfile -t repofiles < <(git ls-files || true) if [[ -z "${repofiles[*]}" ]]; then printf "* No files in the repo?!\n" exit 1 fi failed=0 printed=0 for fileok in "${missingok_files[@]}"; do [[ -f "$fileok" ]] && continue if (( !printed )); then printf "* Some files in missingok_files are themselves missing:\n" printed=1 failed=1 fi printf "%s\n" "$fileok" done printed=0 for dirok in "${missingok_dirs[@]}"; do [[ -d "$dirok" ]] && continue if (( !printed )); then printf "* Some dirs in missingok_dirs are themselves missing:\n" printed=1 failed=1 fi printf "%s\n" "$dirok" done printed=0 for file in "${repofiles[@]}"; do is_missingok "$file" && continue if ! grep -q "$tag" "$file"; then if (( !printed )); then printf "* Files missing the SPDX tag:\n" printed=1 failed=1 fi printf "%s\n" "$file" fi done exit "$failed" tkeyutil-0.0.9/uss.go000066400000000000000000000021011471464017200145330ustar00rootroot00000000000000// SPDX-FileCopyrightText: 2022 Tillitis AB // SPDX-License-Identifier: BSD-2-Clause package tkeyutil import ( "bytes" "fmt" "io" "os" "golang.org/x/term" ) func InputUSS() ([]byte, error) { fmt.Printf("Enter phrase for the USS: ") secret, err := term.ReadPassword(int(os.Stdin.Fd())) if err != nil { return nil, fmt.Errorf("ReadPassword: %w", err) } fmt.Printf("\nRepeat the phrase: ") ussAgain, err := term.ReadPassword(int(os.Stdin.Fd())) if err != nil { return nil, fmt.Errorf("ReadPassword: %w", err) } fmt.Printf("\n") if bytes.Compare(secret, ussAgain) != 0 { return nil, fmt.Errorf("phrases did not match") } if len(secret) == 0 { return nil, fmt.Errorf("no phrase entered") } return secret, nil } func ReadUSS(fileUSS string) ([]byte, error) { var secret []byte var err error if fileUSS == "-" { if secret, err = io.ReadAll(os.Stdin); err != nil { return nil, fmt.Errorf("ReadAll: %w", err) } } else if secret, err = os.ReadFile(fileUSS); err != nil { return nil, fmt.Errorf("ReadFile: %w", err) } return secret, nil }