@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "log"
6
7
"log/syslog"
7
8
"net"
8
9
"os"
@@ -21,11 +22,13 @@ import (
21
22
"github.com/hanwen/go-fuse/fuse/pathfs"
22
23
23
24
"github.com/rfjakob/gocryptfs/internal/configfile"
25
+ "github.com/rfjakob/gocryptfs/internal/contentenc"
24
26
"github.com/rfjakob/gocryptfs/internal/cryptocore"
25
27
"github.com/rfjakob/gocryptfs/internal/ctlsock"
26
28
"github.com/rfjakob/gocryptfs/internal/exitcodes"
27
29
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
28
30
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
31
+ "github.com/rfjakob/gocryptfs/internal/nametransform"
29
32
"github.com/rfjakob/gocryptfs/internal/readpassword"
30
33
"github.com/rfjakob/gocryptfs/internal/tlog"
31
34
)
@@ -182,6 +185,13 @@ func setOpenFileLimit() {
182
185
}
183
186
}
184
187
188
+ // ctlsockFs satisfies both the pathfs.FileSystem and the ctlsock.Interface
189
+ // interfaces
190
+ type ctlsockFs interface {
191
+ pathfs.FileSystem
192
+ ctlsock.Interface
193
+ }
194
+
185
195
// initFuseFrontend - initialize gocryptfs/fusefrontend
186
196
// Calls os.Exit on errors
187
197
func initFuseFrontend (masterkey []byte , args * argContainer , confFile * configfile.ConfFile ) * fuse.Server {
@@ -203,11 +213,8 @@ func initFuseFrontend(masterkey []byte, args *argContainer, confFile *configfile
203
213
Cipherdir : args .cipherdir ,
204
214
PlaintextNames : args .plaintextnames ,
205
215
LongNames : args .longnames ,
206
- CryptoBackend : cryptoBackend ,
207
216
ConfigCustom : args ._configCustom ,
208
- Raw64 : args .raw64 ,
209
217
NoPrealloc : args .noprealloc ,
210
- HKDF : args .hkdf ,
211
218
SerializeReads : args .serialize_reads ,
212
219
ForceDecode : args .forcedecode ,
213
220
ForceOwner : args ._forceOwner ,
@@ -216,10 +223,10 @@ func initFuseFrontend(masterkey []byte, args *argContainer, confFile *configfile
216
223
if confFile != nil {
217
224
// Settings from the config file override command line args
218
225
frontendArgs .PlaintextNames = confFile .IsFeatureFlagSet (configfile .FlagPlaintextNames )
219
- frontendArgs . Raw64 = confFile .IsFeatureFlagSet (configfile .FlagRaw64 )
220
- frontendArgs . HKDF = confFile .IsFeatureFlagSet (configfile .FlagHKDF )
226
+ args . raw64 = confFile .IsFeatureFlagSet (configfile .FlagRaw64 )
227
+ args . hkdf = confFile .IsFeatureFlagSet (configfile .FlagHKDF )
221
228
if confFile .IsFeatureFlagSet (configfile .FlagAESSIV ) {
222
- frontendArgs . CryptoBackend = cryptocore .BackendAESSIV
229
+ cryptoBackend = cryptocore .BackendAESSIV
223
230
} else if args .reverse {
224
231
tlog .Fatal .Printf ("AES-SIV is required by reverse mode, but not enabled in the config file" )
225
232
os .Exit (exitcodes .Usage )
@@ -232,8 +239,6 @@ func initFuseFrontend(masterkey []byte, args *argContainer, confFile *configfile
232
239
}
233
240
jsonBytes , _ := json .MarshalIndent (frontendArgs , "" , "\t " )
234
241
tlog .Debug .Printf ("frontendArgs: %s" , string (jsonBytes ))
235
- var finalFs pathfs.FileSystem
236
- var ctlSockBackend ctlsock.Interface
237
242
// pathFsOpts are passed into go-fuse/pathfs
238
243
pathFsOpts := & pathfs.PathNodeFsOptions {ClientInodes : true }
239
244
if args .sharedstorage {
@@ -242,21 +247,23 @@ func initFuseFrontend(masterkey []byte, args *argContainer, confFile *configfile
242
247
// https://github.com/rfjakob/gocryptfs/issues/156
243
248
pathFsOpts .ClientInodes = false
244
249
}
250
+ // Init crypto backend
251
+ cCore := cryptocore .New (masterkey , cryptoBackend , contentenc .DefaultIVBits , args .hkdf , args .forcedecode )
252
+ cEnc := contentenc .New (cCore , contentenc .DefaultBS , args .forcedecode )
253
+ nameTransform := nametransform .New (cCore .EMECipher , frontendArgs .LongNames , args .raw64 )
254
+ // Spawn fusefrontend
255
+ var fs ctlsockFs
245
256
if args .reverse {
246
- // The dance with the intermediate variables is because we need to
247
- // cast the FS into pathfs.FileSystem *and* ctlsock.Interface. This
248
- // avoids using interface{}.
249
- fs := fusefrontend_reverse .NewFS (masterkey , frontendArgs )
250
- finalFs = fs
251
- ctlSockBackend = fs
257
+ if cryptoBackend != cryptocore .BackendAESSIV {
258
+ log .Panic ("reverse mode must use AES-SIV, everything else is insecure" )
259
+ }
260
+ fs = fusefrontend_reverse .NewFS (frontendArgs , cEnc , nameTransform )
252
261
// Reverse mode is read-only, so we don't need a working link().
253
262
// Disable hard link tracking to avoid strange breakage on duplicate
254
263
// inode numbers ( https://github.com/rfjakob/gocryptfs/issues/149 ).
255
264
pathFsOpts .ClientInodes = false
256
265
} else {
257
- fs := fusefrontend .NewFS (masterkey , frontendArgs )
258
- finalFs = fs
259
- ctlSockBackend = fs
266
+ fs = fusefrontend .NewFS (frontendArgs , cEnc , nameTransform )
260
267
}
261
268
// fusefrontend / fusefrontend_reverse have initialized their crypto with
262
269
// derived keys (HKDF), we can purge the master key from memory.
@@ -266,9 +273,9 @@ func initFuseFrontend(masterkey []byte, args *argContainer, confFile *configfile
266
273
// We have opened the socket early so that we cannot fail here after
267
274
// asking the user for the password
268
275
if args ._ctlsockFd != nil {
269
- go ctlsock .Serve (args ._ctlsockFd , ctlSockBackend )
276
+ go ctlsock .Serve (args ._ctlsockFd , fs )
270
277
}
271
- pathFs := pathfs .NewPathNodeFs (finalFs , pathFsOpts )
278
+ pathFs := pathfs .NewPathNodeFs (fs , pathFsOpts )
272
279
var fuseOpts * nodefs.Options
273
280
if args .sharedstorage {
274
281
// sharedstorage mode sets all cache timeouts to zero so changes to the
0 commit comments