Skip to content

Commit 61ef6b0

Browse files
committed
-devrandom: make flag a no-op
Commit f3c777d added the `-devrandom` option: commit f3c777d Author: @slackner Date: Sun Nov 19 13:30:04 2017 +0100 main: Add '-devrandom' commandline option Allows to use /dev/random for generating the master key instead of the default Go implementation. When the kernel random generator has been properly initialized both are considered equally secure, however: * Versions of Go prior to 1.9 just fall back to /dev/urandom if the getrandom() syscall would be blocking (Go Bug #19274) * Kernel versions prior to 3.17 do not support getrandom(), and there is no check if the random generator has been properly initialized before reading from /dev/urandom This is especially useful for embedded hardware with low-entroy. Please note that generation of the master key might block indefinitely if the kernel cannot harvest enough entropy. We now require Go v1.13 and Kernel versions should have also moved on. Make the flag a no-op. #596
1 parent b3d26b7 commit 61ef6b0

File tree

5 files changed

+14
-47
lines changed

5 files changed

+14
-47
lines changed

Documentation/MANPAGE.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ leaks information about identical file names across directories
114114
The resulting `gocryptfs.conf` has "DirIV" missing from "FeatureFlags".
115115

116116
#### -devrandom
117-
Use `/dev/random` for generating the master key instead of the default Go
118-
implementation. This is especially useful on embedded systems with Go versions
119-
prior to 1.9, which fall back to weak random data when the getrandom syscall
120-
is blocking. Using this option can block indefinitely when the kernel cannot
121-
harvest enough entropy.
117+
Obsolete and ignored on gocryptfs v2.2 and later.
118+
119+
See https://github.com/rfjakob/gocryptfs/commit/f3c777d5eaa682d878c638192311e52f9c204294
120+
and https://github.com/rfjakob/gocryptfs/issues/596 for background info.
122121

123122
#### -hkdf
124123
Use HKDF to derive separate keys for content and name encryption from

cli_args.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type argContainer struct {
3030
plaintextnames, quiet, nosyslog, wpanic,
3131
longnames, allow_other, reverse, aessiv, nonempty, raw64,
3232
noprealloc, speed, hkdf, serialize_reads, forcedecode, hh, info,
33-
sharedstorage, devrandom, fsck, one_file_system, deterministic_names,
33+
sharedstorage, fsck, one_file_system, deterministic_names,
3434
xchacha bool
3535
// Mount options with opposites
3636
dev, nodev, suid, nosuid, exec, noexec, rw, ro, kernel_cache, acl bool
@@ -177,7 +177,6 @@ func parseCliOpts(osArgs []string) (args argContainer) {
177177
flagSet.BoolVar(&args.hh, "hh", false, "Show this long help text")
178178
flagSet.BoolVar(&args.info, "info", false, "Display information about CIPHERDIR")
179179
flagSet.BoolVar(&args.sharedstorage, "sharedstorage", false, "Make concurrent access to a shared CIPHERDIR safer")
180-
flagSet.BoolVar(&args.devrandom, "devrandom", false, "Use /dev/random for generating master key")
181180
flagSet.BoolVar(&args.fsck, "fsck", false, "Run a filesystem check on CIPHERDIR")
182181
flagSet.BoolVar(&args.one_file_system, "one-file-system", false, "Don't cross filesystem boundaries")
183182
flagSet.BoolVar(&args.deterministic_names, "deterministic-names", false, "Disable diriv file name randomisation")
@@ -228,11 +227,16 @@ func parseCliOpts(osArgs []string) (args argContainer) {
228227
flagSet.DurationVar(&args.idle, "idle", 0, "Auto-unmount after specified idle duration (ignored in reverse mode). "+
229228
"Durations are specified like \"500s\" or \"2h45m\". 0 means stay mounted indefinitely.")
230229

231-
var nofail bool
232-
flagSet.BoolVar(&nofail, "nofail", false, "Ignored for /etc/fstab compatibility")
233-
234230
var dummyString string
235231
flagSet.StringVar(&dummyString, "o", "", "For compatibility with mount(1), options can be also passed as a comma-separated list to -o on the end.")
232+
233+
// Ignored flags
234+
{
235+
var tmp bool
236+
flagSet.BoolVar(&tmp, "nofail", false, "Ignored for /etc/fstab compatibility")
237+
flagSet.BoolVar(&tmp, "devrandom", false, "Deprecated (ignored for compatibility)")
238+
}
239+
236240
// Actual parsing
237241
err = flagSet.Parse(osArgsPreprocessed[1:])
238242
if err == flag.ErrHelp {

init_dir.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ func initDir(args *argContainer) {
9393
LogN: args.scryptn,
9494
Creator: creator,
9595
AESSIV: args.aessiv,
96-
Devrandom: args.devrandom,
9796
Fido2CredentialID: fido2CredentialID,
9897
Fido2HmacSalt: fido2HmacSalt,
9998
DeterministicNames: args.deterministic_names,

internal/configfile/config_file.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ package configfile
55
import (
66
"encoding/json"
77
"fmt"
8-
"io"
98
"io/ioutil"
10-
"log"
119
"syscall"
1210

1311
"os"
@@ -61,21 +59,6 @@ type ConfFile struct {
6159
filename string
6260
}
6361

64-
// randBytesDevRandom gets "n" random bytes from /dev/random or panics
65-
func randBytesDevRandom(n int) []byte {
66-
f, err := os.Open("/dev/random")
67-
if err != nil {
68-
log.Panic("Failed to open /dev/random: " + err.Error())
69-
}
70-
defer f.Close()
71-
b := make([]byte, n)
72-
_, err = io.ReadFull(f, b)
73-
if err != nil {
74-
log.Panic("Failed to read random bytes: " + err.Error())
75-
}
76-
return b
77-
}
78-
7962
// CreateArgs exists because the argument list to Create became too long.
8063
type CreateArgs struct {
8164
Filename string
@@ -84,7 +67,6 @@ type CreateArgs struct {
8467
LogN int
8568
Creator string
8669
AESSIV bool
87-
Devrandom bool
8870
Fido2CredentialID []byte
8971
Fido2HmacSalt []byte
9072
DeterministicNames bool
@@ -136,12 +118,7 @@ func Create(args *CreateArgs) error {
136118
}
137119
{
138120
// Generate new random master key
139-
var key []byte
140-
if args.Devrandom {
141-
key = randBytesDevRandom(cryptocore.KeyLen)
142-
} else {
143-
key = cryptocore.RandBytes(cryptocore.KeyLen)
144-
}
121+
key := cryptocore.RandBytes(cryptocore.KeyLen)
145122
tlog.PrintMasterkeyReminder(key)
146123
// Encrypt it using the password
147124
// This sets ScryptObject and EncryptedKey

internal/configfile/config_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,6 @@ func TestCreateConfDefault(t *testing.T) {
8686
}
8787
}
8888

89-
func TestCreateConfDevRandom(t *testing.T) {
90-
err := Create(&CreateArgs{
91-
Filename: "config_test/tmp.conf",
92-
Password: testPw,
93-
LogN: 10,
94-
Creator: "test",
95-
Devrandom: true})
96-
if err != nil {
97-
t.Fatal(err)
98-
}
99-
}
100-
10189
func TestCreateConfPlaintextnames(t *testing.T) {
10290
err := Create(&CreateArgs{
10391
Filename: "config_test/tmp.conf",

0 commit comments

Comments
 (0)