@@ -10,6 +10,7 @@ public enum ValidationError: Error {
10
10
case invalidTeamIdentifier( identifier: String ? )
11
11
case missingInfoPList
12
12
case invalidVersion( version: String ? )
13
+ case belowMinimumCoderVersion
13
14
14
15
public var description : String {
15
16
switch self {
@@ -29,13 +30,18 @@ public enum ValidationError: Error {
29
30
" Invalid team identifier: \( identifier ?? " unknown " ) . "
30
31
case . missingInfoPList:
31
32
" Info.plist is not embedded within the dylib. "
33
+ case . belowMinimumCoderVersion:
34
+ " The Coder deployment must be version \( SignatureValidator . minimumCoderVersion) or higher to use Coder Desktop. "
32
35
}
33
36
}
34
37
35
38
public var localizedDescription : String { description }
36
39
}
37
40
38
41
public class SignatureValidator {
42
+ // Whilst older dylibs exist, this app assumes v2.20 or later.
43
+ static let minimumCoderVersion = " 2.20.0 "
44
+
39
45
private static let expectedName = " CoderVPN "
40
46
private static let expectedIdentifier = " com.coder.Coder-Desktop.VPN.dylib "
41
47
private static let expectedTeamIdentifier = " 4399GN35BJ "
@@ -95,11 +101,20 @@ public class SignatureValidator {
95
101
throw . invalidIdentifier( identifier: infoPlist [ infoNameKey] as? String )
96
102
}
97
103
104
+ // Downloaded dylib must match the version of the server
98
105
guard let dylibVersion = infoPlist [ infoShortVersionKey] as? String ,
99
- expectedVersion. compare ( dylibVersion , options : . numeric ) != . orderedDescending
106
+ expectedVersion == dylibVersion
100
107
else {
101
108
throw . invalidVersion( version: infoPlist [ infoShortVersionKey] as? String )
102
109
}
110
+
111
+ // Downloaded dylib must be at least the minimum Coder server version
112
+ guard let dylibVersion = infoPlist [ infoShortVersionKey] as? String ,
113
+ // x.compare(y) is .orderedDescending if x > y
114
+ minimumCoderVersion. compare ( dylibVersion, options: . numeric) != . orderedDescending
115
+ else {
116
+ throw . belowMinimumCoderVersion
117
+ }
103
118
}
104
119
}
105
120
0 commit comments