configfile: add LongNameMax support

Feature flag + numeric paramater

https://github.com/rfjakob/gocryptfs/issues/499
This commit is contained in:
Jakob Unterwurzacher 2021-10-21 09:58:37 +02:00
parent dc32710045
commit d583bdb79e
3 changed files with 37 additions and 0 deletions

View File

@ -55,6 +55,8 @@ type ConfFile struct {
FeatureFlags []string FeatureFlags []string
// FIDO2 parameters // FIDO2 parameters
FIDO2 *FIDO2Params `json:",omitempty"` FIDO2 *FIDO2Params `json:",omitempty"`
// LongNameMax corresponds to the -longnamemax flag
LongNameMax uint8 `json:",omitempty"`
// Filename is the name of the config file. Not exported to JSON. // Filename is the name of the config file. Not exported to JSON.
filename string filename string
} }
@ -71,6 +73,7 @@ type CreateArgs struct {
Fido2HmacSalt []byte Fido2HmacSalt []byte
DeterministicNames bool DeterministicNames bool
XChaCha20Poly1305 bool XChaCha20Poly1305 bool
LongNameMax uint8
} }
// Create - create a new config with a random key encrypted with // Create - create a new config with a random key encrypted with
@ -97,6 +100,12 @@ func Create(args *CreateArgs) error {
if !args.DeterministicNames { if !args.DeterministicNames {
cf.setFeatureFlag(FlagDirIV) cf.setFeatureFlag(FlagDirIV)
} }
// 0 means to *use* the default (which means we don't have to save it), and
// 255 *is* the default, which means we don't have to save it either.
if args.LongNameMax != 0 && args.LongNameMax != 255 {
cf.LongNameMax = args.LongNameMax
cf.setFeatureFlag(FlagLongNameMax)
}
cf.setFeatureFlag(FlagEMENames) cf.setFeatureFlag(FlagEMENames)
cf.setFeatureFlag(FlagLongNames) cf.setFeatureFlag(FlagLongNames)
cf.setFeatureFlag(FlagRaw64) cf.setFeatureFlag(FlagRaw64)

View File

@ -131,6 +131,30 @@ func TestCreateConfFileAESSIV(t *testing.T) {
} }
} }
func TestCreateConfLongNameMax(t *testing.T) {
args := &CreateArgs{
Filename: "config_test/tmp.conf",
Password: testPw,
LogN: 10,
Creator: "test",
LongNameMax: 100,
}
err := Create(args)
if err != nil {
t.Fatal(err)
}
_, c, err := LoadAndDecrypt("config_test/tmp.conf", testPw)
if err != nil {
t.Fatal(err)
}
if !c.IsFeatureFlagSet(FlagLongNameMax) {
t.Error("FlagLongNameMax should be set but is not")
}
if c.LongNameMax != args.LongNameMax {
t.Errorf("wrong LongNameMax value: want=%d have=%d", args.LongNameMax, c.LongNameMax)
}
}
func TestIsFeatureFlagKnown(t *testing.T) { func TestIsFeatureFlagKnown(t *testing.T) {
// Test a few hardcoded values // Test a few hardcoded values
testKnownFlags := []string{"DirIV", "PlaintextNames", "EMENames", "GCMIV128", "LongNames", "AESSIV"} testKnownFlags := []string{"DirIV", "PlaintextNames", "EMENames", "GCMIV128", "LongNames", "AESSIV"}

View File

@ -16,6 +16,9 @@ const (
FlagGCMIV128 FlagGCMIV128
// FlagLongNames allows file names longer than 176 bytes. // FlagLongNames allows file names longer than 176 bytes.
FlagLongNames FlagLongNames
// FlagLongNameMax sets a custom name length limit, names longer than that
// will be hashed.
FlagLongNameMax
// FlagAESSIV selects an AES-SIV based crypto backend. // FlagAESSIV selects an AES-SIV based crypto backend.
FlagAESSIV FlagAESSIV
// FlagRaw64 enables raw (unpadded) base64 encoding for file names // FlagRaw64 enables raw (unpadded) base64 encoding for file names
@ -40,6 +43,7 @@ var knownFlags = map[flagIota]string{
FlagEMENames: "EMENames", FlagEMENames: "EMENames",
FlagGCMIV128: "GCMIV128", FlagGCMIV128: "GCMIV128",
FlagLongNames: "LongNames", FlagLongNames: "LongNames",
FlagLongNameMax: "LongNameMax",
FlagAESSIV: "AESSIV", FlagAESSIV: "AESSIV",
FlagRaw64: "Raw64", FlagRaw64: "Raw64",
FlagHKDF: "HKDF", FlagHKDF: "HKDF",