Skip to content

Commit 29931c1

Browse files
committed
Remove port auto-detect on macos, getting rid of CGO
With CGO out of the way the make-release-builds.sh script can build binaries for all OSs & architectures reproducibly in a container. Also create a Macos univeral binary. Commit checksums of all tkey-verification binaries (of the next version that is expected to be released), which the script checks after building. Signed-off-by: Daniel Lublin <[email protected]>
1 parent 3c52912 commit 29931c1

16 files changed

+227
-73
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/gotools/golangci-lint
22
/gotools/certstrap
3+
/gotools/lipo
34
/show-pubkey
45
/tkey-verification

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ clean:
3333
.PHONY: lint
3434
lint:
3535
$(MAKE) -C gotools golangci-lint
36-
./gotools/golangci-lint run
36+
GOOS=linux ./gotools/golangci-lint run
37+
GOOS=windows ./gotools/golangci-lint run
38+
GOOS=darwin ./gotools/golangci-lint run
3739

3840
.PHONY: certs
3941
certs:

README.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ produced by [Tillitis](https://tillitis.se/) (the vendor).
66

77
If you own a TKey and want make sure it's genuine you can follow
88
[these
9-
instructions](https://tillitis.se/app/tkey-device-verification/) (On
9+
instructions](https://tillitis.se/app/tkey-device-verification/) (on
1010
Tillitis' web). Or just download a release of the tool right away:
1111
https://github.com/tillitis/tkey-verification/releases
1212

13+
The published binaries can be reproduced by running
14+
`./make-release-builds.sh` with the wanted version (for example
15+
"0.0.2"). The [release-builds](release-builds) directory contains
16+
checksums of released versions (since we got reproducibility in
17+
place), which the script verifies after building. Running the script
18+
requires a rootless podman setup. On Ubuntu 22.10, running `apt
19+
install podman rootlesskit slirp4netns` should be enough.
20+
1321
## Terminology
1422

1523
- "device under verification": The device the vendor is provisioning
@@ -276,3 +284,25 @@ Example file content:
276284
"signature": "db4e7a72b720b33f6d4887df0f9dcdd6988ca8adb6b0042d8e8c92b5be3e4e39d908f166d093f3ab20880102d43a2b0c8e31178ab7cdb59977dcf7204116cc0c"
277285
}
278286
```
287+
288+
## Making releases of tkey-verification
289+
290+
Make the new release binaries for the expected version:
291+
292+
./make-release-builds 0.0.42
293+
294+
Generate and commit the new checksums:
295+
296+
./gen-release-checksums 0.0.42
297+
git add release-builds/*_0.0.42_*.sha512
298+
git commit -m "Release 0.0.42"
299+
300+
Then tag a new version and push it all:
301+
302+
git tag -a v0.0.42 -m v0.0.42
303+
git push origin main v0.0.42
304+
305+
Publish the new release at
306+
https://github.com/tillitis/tkey-verification/releases and upload the
307+
binaries and checksum files. For MacOS we'll provide only the
308+
universal binary.

build-appbin-in-container.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ cname="tkey-build"
5555

5656
podman run -it --name "$cname" \
5757
--mount type=bind,source="$(pwd)",target=/contrib \
58-
ghcr.io/tillitis/tkey-builder:1 \
58+
ghcr.io/tillitis/tkey-builder:2 \
5959
/bin/bash /contrib/containerbuild "$tag" "$appsrepotag"
6060

6161
podman cp "$cname":/tkey-verification/apps/verisigner/app.bin "$destd/$destf"

cmd/tkey-verification/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ Known firmwares:
8787
desc := fmt.Sprintf(`Usage: %s command [flags...]
8888
8989
Commands:
90-
serve-signer TODO write...
90+
serve-signer Run the server that offers an API for creating vendor signatures.
9191
92-
remote-sign TODO write...
92+
remote-sign Call the remote signing server to sign for a local TKey.
9393
9494
verify Verify that a TKey is genuine by extracting the TKey UDI and using it
9595
to fetch the verification data, including tag and signature from the

cmd/tkey-verification/verify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func verify(devPath string, verbose bool, showURLOnly bool, baseDir string, veri
128128
func verificationFromURL(verifyURL string) (Verification, error) {
129129
var verification Verification
130130

131-
le.Printf("Fetching %s ...\n", verifyURL)
131+
le.Printf("Fetching verification data from %s ...\n", verifyURL)
132132
client := http.Client{Timeout: 10 * time.Second}
133133
resp, err := client.Get(verifyURL) // #nosec G107
134134
if err != nil {
@@ -155,7 +155,7 @@ func verificationFromURL(verifyURL string) (Verification, error) {
155155
func verificationFromFile(fn string) (Verification, error) {
156156
var verification Verification
157157

158-
le.Printf("Reading %s ...\n", fn)
158+
le.Printf("Reading verification data from file %s ...\n", fn)
159159
verificationJSON, err := os.ReadFile(fn)
160160
if err != nil {
161161
return verification, fmt.Errorf("ReadFile failed: %w", err)

gen-release-checksums

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh -e
2+
3+
if ! hash 2>/dev/null sha512sum; then
4+
sha512sum() {
5+
shasum -a 512 "$@"
6+
}
7+
fi
8+
9+
version="$1"
10+
if [ -z "$version" ]; then
11+
printf "give me a version number\n"
12+
exit 1
13+
fi
14+
shift
15+
16+
cd release-builds
17+
18+
any=
19+
for file in *_"$version"_*; do
20+
[ -e "$file" ] || continue
21+
[ "${file##*.}" != "sha512" ] || continue
22+
hashf="$file.sha512"
23+
if [ -e "$hashf" ]; then
24+
printf "%s already exists, bailing out\n" "$hashf"
25+
exit 1
26+
fi
27+
sha512sum >"$hashf" "$file"
28+
printf "wrote %s\n" "$hashf"
29+
any=any
30+
done
31+
32+
if [ -z "$any" ]; then
33+
printf "no binaries in release-builds/ with that version?\n"
34+
fi

gotools/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ certstrap:
1515
go mod download github.com/square/certstrap
1616
go mod tidy
1717
go build github.com/square/certstrap
18+
19+
# .PHONY to let go-build handle deps and rebuilds
20+
.PHONY: lipo
21+
lipo:
22+
go mod download github.com/konoui/lipo
23+
go mod tidy
24+
go build github.com/konoui/lipo

gotools/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
github.com/golangci/golangci-lint v1.51.0
7+
github.com/konoui/lipo v0.4.1
78
github.com/square/certstrap v1.3.0
89
)
910

@@ -87,6 +88,7 @@ require (
8788
github.com/kisielk/errcheck v1.6.3 // indirect
8889
github.com/kisielk/gotool v1.0.0 // indirect
8990
github.com/kkHAIKE/contextcheck v1.1.3 // indirect
91+
github.com/konoui/go-qsort v0.0.1 // indirect
9092
github.com/kulti/thelper v0.6.3 // indirect
9193
github.com/kunwardeep/paralleltest v1.0.6 // indirect
9294
github.com/kyoh86/exportloopref v0.1.11 // indirect

gotools/go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
330330
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
331331
github.com/kkHAIKE/contextcheck v1.1.3 h1:l4pNvrb8JSwRd51ojtcOxOeHJzHek+MtOyXbaR0uvmw=
332332
github.com/kkHAIKE/contextcheck v1.1.3/go.mod h1:PG/cwd6c0705/LM0KTr1acO2gORUxkSVWyLJOFW5qoo=
333+
github.com/konoui/go-qsort v0.0.1 h1:7scLI7DAKynqS6enK0vnpwoiw7L38pBI49ofIahb9rc=
334+
github.com/konoui/go-qsort v0.0.1/go.mod h1:UOsvdDPBzyQDk9Tb21hETK6KYXGYQTnoZB5qeKA1ARs=
335+
github.com/konoui/lipo v0.4.1 h1:DbaBYvafcdXx2DMlmMtwVugO8GywlFgywR7qZGMxP1E=
336+
github.com/konoui/lipo v0.4.1/go.mod h1:PpyG5pH3dW3h7QSsAu69JZIBZ4V5e9fg/H67azfQ1f8=
333337
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
334338
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
335339
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=

gotools/gotools.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// Copyright (C) 2022 - Tillitis AB
1+
// Copyright (C) 2022, 2023 - Tillitis AB
22
// SPDX-License-Identifier: GPL-2.0-only
33

44
package gotools
55

66
import (
77
// Import tools we use
88
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
9+
_ "github.com/konoui/lipo"
910
_ "github.com/square/certstrap"
1011
)

internal/firmwares/firmwares.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func initFirmwares() error {
6868

6969
var err error
7070

71-
// TODO This is the default/qemu UDI0, with firmware from main at
71+
// This is the default/qemu UDI0, with firmware from main at
7272
// c126199a41149f6284aa9533e72395c978733b44
7373
err = addFirmware("00010203", 0x0010, 8, 3, 4192, "3769540390ee3d990ea3f9e4cc9a0d1af5bcaebb82218185a78c39c6bf01d9cdc305ba253a1fb9f3f9fcc63d97c8e5f34bbb1f7bec56a8f246f1d2239867b623")
7474
if err != nil {

internal/util/ports_darwin.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2023 - Tillitis AB
2+
// SPDX-License-Identifier: GPL-2.0-only
3+
4+
//go:build darwin
5+
6+
package util
7+
8+
import (
9+
"fmt"
10+
"os"
11+
)
12+
13+
func DetectSerialPort(verbose bool) (string, error) {
14+
fmt.Fprintf(os.Stderr, `Serial port detection is not available on MacOS.
15+
Please find the serial port device path using:
16+
ls -l /dev/cu.*
17+
Then run like:
18+
tkey-verification command --port /dev/cu.usbmodemN
19+
`)
20+
return "", fmt.Errorf("not available on MacOS")
21+
}

internal/util/ports.go renamed to internal/util/ports_linuxwindows.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Copyright (C) 2022 - Tillitis AB
1+
// Copyright (C) 2023 - Tillitis AB
22
// SPDX-License-Identifier: GPL-2.0-only
33

4+
//go:build linux || windows
5+
46
package util
57

68
import (
@@ -10,15 +12,18 @@ import (
1012
"go.bug.st/serial/enumerator"
1113
)
1214

15+
const (
16+
tillitisUSBVID = "1207"
17+
tillitisUSBPID = "8887"
18+
)
19+
1320
type constError string
1421

1522
func (err constError) Error() string {
1623
return string(err)
1724
}
1825

1926
const (
20-
tillitisUSBVID = "1207"
21-
tillitisUSBPID = "8887"
2227
// Custom errors
2328
ErrNoDevice = constError("no TKey connected")
2429
ErrManyDevices = constError("more than one TKey connected")
@@ -30,7 +35,7 @@ type SerialPort struct {
3035
}
3136

3237
func DetectSerialPort(verbose bool) (string, error) {
33-
ports, err := GetSerialPorts()
38+
ports, err := getSerialPorts()
3439
if err != nil {
3540
return "", err
3641
}
@@ -56,19 +61,19 @@ func DetectSerialPort(verbose bool) (string, error) {
5661
return ports[0].DevPath, nil
5762
}
5863

59-
func GetSerialPorts() ([]SerialPort, error) {
64+
func getSerialPorts() ([]SerialPort, error) {
6065
var ports []SerialPort
66+
6167
portDetails, err := enumerator.GetDetailedPortsList()
6268
if err != nil {
6369
return nil, fmt.Errorf("GetDetailedPortsList: %w", err)
6470
}
65-
if len(portDetails) == 0 {
66-
return ports, nil
67-
}
71+
6872
for _, port := range portDetails {
6973
if port.IsUSB && port.VID == tillitisUSBVID && port.PID == tillitisUSBPID {
7074
ports = append(ports, SerialPort{port.Name, port.SerialNumber})
7175
}
7276
}
77+
7378
return ports, nil
7479
}

make-release-binaries.sh

-56
This file was deleted.

0 commit comments

Comments
 (0)