Skip to content

Commit 5c6152b

Browse files
committed
Updated to latest safefile lib - fixed up caller sites.
1 parent e305314 commit 5c6152b

File tree

6 files changed

+48
-27
lines changed

6 files changed

+48
-27
lines changed

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ go 1.21.1
55
require (
66
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a
77
github.com/opencoff/go-mmap v0.1.2
8-
github.com/opencoff/go-utils v0.9.0
8+
github.com/opencoff/go-utils v0.9.3
99
github.com/opencoff/pflag v1.0.6-sh1
10-
golang.org/x/crypto v0.17.0
11-
google.golang.org/protobuf v1.32.0
10+
golang.org/x/crypto v0.21.0
11+
google.golang.org/protobuf v1.33.0
1212
gopkg.in/yaml.v2 v2.4.0
1313
)
1414

1515
require (
16-
golang.org/x/sys v0.16.0 // indirect
17-
golang.org/x/term v0.15.0 // indirect
16+
golang.org/x/sys v0.18.0 // indirect
17+
golang.org/x/term v0.18.0 // indirect
1818
)
1919

2020
//replace github.com/opencoff/go-mmap => ../go-mmap
21+
//replace github.com/opencoff/go-utils => ../go-utils

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
44
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
55
github.com/opencoff/go-mmap v0.1.2 h1:2yrYleq0x9cBruDRTafs7GZt4tCYmsUlvyN77HnY9hA=
66
github.com/opencoff/go-mmap v0.1.2/go.mod h1:+UjRnKQ3l5dLqSNAczz7zKI8LJ7mBhJhaSqU4S91tFs=
7-
github.com/opencoff/go-utils v0.9.0 h1:qJcRsjLHADmej3/BkH6cLX3pxapLwHf9uSN0E7vvZf4=
8-
github.com/opencoff/go-utils v0.9.0/go.mod h1:IHjYSeM+bOKhCD2rBEba4/0C7Apko+KZKKyFgDF43Sc=
7+
github.com/opencoff/go-utils v0.9.3 h1:Gdx1uB6QZ9/8FNU4h+94xGJ+onu8bQLRE4gyKRrrDD8=
8+
github.com/opencoff/go-utils v0.9.3/go.mod h1:nNx572v21m3AkY9JomSXUG8iruY56Fm2zceNKNJDJaU=
99
github.com/opencoff/pflag v1.0.6-sh1 h1:6RO8GgnpH928yu6earGDD01FnFT//bDJ1hCovcVVqY4=
1010
github.com/opencoff/pflag v1.0.6-sh1/go.mod h1:2bXtpAD/5h/2LarkbsRwiUxqnvB1nZBzn9Xjad1P41A=
11-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
12-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
13-
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
14-
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15-
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
16-
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
11+
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
12+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
13+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
14+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15+
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
16+
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
1717
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
1818
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
19-
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
20-
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
19+
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
20+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
2121
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2222
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2323
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

sign/iomisc.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ import (
2626
// Does MORE than ioutil.WriteFile() - in that it doesn't trash the
2727
// existing file with an incomplete write.
2828
func writeFile(fn string, b []byte, ovwrite bool, mode uint32) error {
29-
sf, err := utils.NewSafeFile(fn, ovwrite, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(mode))
29+
var opts uint32
30+
if ovwrite {
31+
opts |= utils.OPT_OVERWRITE
32+
}
33+
sf, err := utils.NewSafeFile(fn, opts, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(mode))
3034
if err != nil {
3135
return err
3236
}
33-
sf.Write(b)
37+
defer sf.Abort()
38+
if _, err = sf.Write(b); err != nil {
39+
return err
40+
}
41+
3442
return sf.Close()
3543
}
3644

src/crypt.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ func encrypt(args []string) {
140140
mode = ist.Mode()
141141
}
142142

143-
sf, err := utils.NewSafeFile(outfile, force, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode)
143+
var opts uint32
144+
if force {
145+
opts |= utils.OPT_OVERWRITE
146+
}
147+
sf, err := utils.NewSafeFile(outfile, opts, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode)
144148
if err != nil {
145149
Die("%s", err)
146150
}
@@ -302,7 +306,11 @@ func decrypt(args []string) {
302306
mode = ist.Mode()
303307
}
304308

305-
sf, err := utils.NewSafeFile(outfile, force, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode)
309+
var opts uint32
310+
if force {
311+
opts |= utils.OPT_OVERWRITE
312+
}
313+
sf, err := utils.NewSafeFile(outfile, opts, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode)
306314
if err != nil {
307315
Die("%s", err)
308316
}

src/sign.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ Options:
6868
var fd io.WriteCloser = os.Stdout
6969

7070
if outf != "-" {
71-
sf, err := utils.NewSafeFile(outf, force, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
71+
var opts uint32
72+
if force {
73+
opts |= utils.OPT_OVERWRITE
74+
}
75+
sf, err := utils.NewSafeFile(outf, opts, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
7276
if err != nil {
7377
Die("can't create sig file: %s", err)
7478
}

tests.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ $keygen -q -C 'ssk2@foo' -t ed25519 -f $ssk2 -N ""
8080
# extract the pk string
8181
spk1_str=$(cat $spk1 | awk '{ print $2 }')
8282

83-
$bin s --no-password $ssk1 -o $sig $0 || die "can't sign with $ssk1"
84-
$bin v -q $spk1 $sig $0 || die "can't verify with $spk2"
85-
$bin v -q $spk1_str $sig $0 || die "can't verify with $spk2_str"
83+
$bin s --no-password $ssk1 -o $sig $0 || die "can't sign with $ssk1"
84+
$bin v -q $spk1 $sig $0 || die "can't verify with $spk2"
85+
$bin v -q $spk1_str $sig $0 || die "can't verify with $spk2_str"
8686

8787
$bin e --no-password -o $encout $spk2 $0 || die "can't encrypt to $spk2 with $ssk1"
8888
$bin d --no-password -o $decout $ssk2 $encout || die "can't decrypt with $ssk2"
@@ -101,9 +101,9 @@ pk_str=$(cat $pk | grep 'pk:' | sed -e 's/^pk: //g')
101101
pk2_str=$(cat $pk2 | grep 'pk:' | sed -e 's/^pk: //g')
102102

103103
# sign and verify
104-
$bin s -E FOO $sk $0 -o $sig || die "can't sign $0"
105-
$bin v -q $pk $sig $0 || die "can't verify signature of $0"
106-
$bin v -q $pk_str $sig $0 || die "can't verify signature of $0"
104+
$bin s -E FOO $sk $0 -o $sig || die "can't sign $0"
105+
$bin v -q $pk $sig $0 || die "can't verify signature of $0"
106+
$bin v -q $pk_str $sig $0 || die "can't verify signature of $0"
107107
$bin v -q $pk2 $sig $0 2>/dev/null && die "bad verification with wrong $pk2"
108108
$bin v -q $pk2_str $sig $0 2>/dev/null && die "bad verification with wrong $pk2"
109109

@@ -115,7 +115,7 @@ cmp -s $decout $0 || die "decrypted file mismatch with $0"
115115
# now with sender verification
116116
$bin e -E FOO --overwrite -o $encout -s $sk $pk2 $0 || die "can't sender-encrypt to $pk2"
117117
$bin d -E FOO --overwrite -o $decout -v $pk $sk2 $encout || die "can't decrypt with $sk2"
118-
cmp -s $decout $0 || die "decrypted file mismatch with $0"
118+
cmp -s $decout $0 || die "decrypted file mismatch with $0"
119119

120120
# Only delete if everything worked
121121
echo "$Z: All tests pass!"

0 commit comments

Comments
 (0)