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