summaryrefslogtreecommitdiff
path: root/internal/configfile/feature_flags.go
blob: 2d609f241d599ba20cf5a9992201726b499772c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package configfile

type flagIota int

const (
	// FlagPlaintextNames indicates that filenames are unencrypted.
	FlagPlaintextNames flagIota = iota
	// FlagDirIV indicates that a per-directory IV file is used.
	FlagDirIV
	// FlagEMENames indicates EME (ECB-Mix-ECB) filename encryption.
	// This flag is mandatory since gocryptfs v1.0.
	FlagEMENames
	// FlagGCMIV128 indicates 128-bit GCM IVs.
	// This flag is mandatory since gocryptfs v1.0.
	FlagGCMIV128
	// FlagLongNames allows file names longer than 176 bytes.
	FlagLongNames
	// FlagAESSIV selects an AES-SIV based crypto backend.
	FlagAESSIV
	// FlagRaw64 enables raw (unpadded) base64 encoding for file names
	FlagRaw64
	// FlagHKDF enables HKDF-derived keys for use with GCM, EME and SIV
	// instead of directly using the master key (GCM and EME) or the SHA-512
	// hashed master key (SIV).
	// Note that this flag does not change the password hashing algorithm
	// which always is scrypt.
	FlagHKDF
)

// knownFlags stores the known feature flags and their string representation
var knownFlags = map[flagIota]string{
	FlagPlaintextNames: "PlaintextNames",
	FlagDirIV:          "DirIV",
	FlagEMENames:       "EMENames",
	FlagGCMIV128:       "GCMIV128",
	FlagLongNames:      "LongNames",
	FlagAESSIV:         "AESSIV",
	FlagRaw64:          "Raw64",
	FlagHKDF:           "HKDF",
}

// Filesystems that do not have these feature flags set are deprecated.
var requiredFlagsNormal = []flagIota{
	FlagDirIV,
	FlagEMENames,
	FlagGCMIV128,
}

// Filesystems without filename encryption obviously don't have or need the
// filename related feature flags.
var requiredFlagsPlaintextNames = []flagIota{
	FlagGCMIV128,
}

// isFeatureFlagKnown verifies that we understand a feature flag.
func (cf *ConfFile) isFeatureFlagKnown(flag string) bool {
	for _, knownFlag := range knownFlags {
		if knownFlag == flag {
			return true
		}
	}
	return false
}

// IsFeatureFlagSet returns true if the feature flag "flagWant" is enabled.
func (cf *ConfFile) IsFeatureFlagSet(flagWant flagIota) bool {
	flagString := knownFlags[flagWant]
	for _, flag := range cf.FeatureFlags {
		if flag == flagString {
			return true
		}
	}
	return false
}