- Notifications
You must be signed in to change notification settings - Fork5
chore: enforce minimum coder server version of v2.20.0#90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
cd6d354 chore: enforce minimum coder server version of v2.20.0
ethanndickson6e99358 lint
ethanndickson48c893c new function
ethanndickson4c892a6 also check at login
ethanndicksond23b1a2 fix tests
ethanndickson590e97c add extra test
ethanndicksonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletionsCoder Desktop/Coder Desktop/Views/LoginForm.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletionsCoder Desktop/Coder DesktopTests/LoginFormTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsCoder Desktop/VPN/Manager.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -31,9 +31,9 @@ actor Manager { | ||
| // The tunnel might be asked to start before the network interfaces have woken up from sleep | ||
| sessionConfig.waitsForConnectivity = true | ||
| // URLSession's waiting for connectivity sometimes hangs even when | ||
| // the network is up so this is deliberately short (30s) to avoid a | ||
| // poor UX where it appears stuck. | ||
| sessionConfig.timeoutIntervalForResource =30 | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| try await download(src: dylibPath, dest: dest, urlSession: URLSession(configuration: sessionConfig)) | ||
| } catch { | ||
| throw .download(error) | ||
24 changes: 23 additions & 1 deletionCoder Desktop/VPNLib/Download.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,7 @@ public enum ValidationError: Error { | ||
| case invalidTeamIdentifier(identifier: String?) | ||
| case missingInfoPList | ||
| case invalidVersion(version: String?) | ||
| case belowMinimumCoderVersion | ||
| public var description: String { | ||
| switch self { | ||
| @@ -29,13 +30,21 @@ public enum ValidationError: Error { | ||
| "Invalid team identifier: \(identifier ?? "unknown")." | ||
| case .missingInfoPList: | ||
| "Info.plist is not embedded within the dylib." | ||
| case .belowMinimumCoderVersion: | ||
| """ | ||
| The Coder deployment must be version \(SignatureValidator.minimumCoderVersion) | ||
| or higher to use Coder Desktop. | ||
| """ | ||
| } | ||
| } | ||
| public var localizedDescription: String { description } | ||
| } | ||
| public class SignatureValidator { | ||
| // Whilst older dylibs exist, this app assumes v2.20 or later. | ||
| public static let minimumCoderVersion = "2.20.0" | ||
| private static let expectedName = "CoderVPN" | ||
| private static let expectedIdentifier = "com.coder.Coder-Desktop.VPN.dylib" | ||
| private static let expectedTeamIdentifier = "4399GN35BJ" | ||
| @@ -87,6 +96,10 @@ public class SignatureValidator { | ||
| throw .missingInfoPList | ||
| } | ||
| try validateInfo(infoPlist: infoPlist, expectedVersion: expectedVersion) | ||
| } | ||
| private static func validateInfo(infoPlist: [String: AnyObject], expectedVersion: String) throws(ValidationError) { | ||
| guard let plistIdent = infoPlist[infoIdentifierKey] as? String, plistIdent == expectedIdentifier else { | ||
| throw .invalidIdentifier(identifier: infoPlist[infoIdentifierKey] as? String) | ||
| } | ||
| @@ -95,11 +108,20 @@ public class SignatureValidator { | ||
| throw .invalidIdentifier(identifier: infoPlist[infoNameKey] as? String) | ||
| } | ||
| // Downloaded dylib must match the version of the server | ||
| guard let dylibVersion = infoPlist[infoShortVersionKey] as? String, | ||
| expectedVersion == dylibVersion | ||
| else { | ||
| throw .invalidVersion(version: infoPlist[infoShortVersionKey] as? String) | ||
| } | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // Downloaded dylib must be at least the minimum Coder server version | ||
| guard let dylibVersion = infoPlist[infoShortVersionKey] as? String, | ||
| // x.compare(y) is .orderedDescending if x > y | ||
| minimumCoderVersion.compare(dylibVersion, options: .numeric) != .orderedDescending | ||
| else { | ||
| throw .belowMinimumCoderVersion | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.