Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit929c831

Browse files
committed
chore: ensure downloaded slim binary version matches server
1 parente9e15db commit929c831

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

‎Coder-Desktop/Coder-DesktopHelper/Manager.swift‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ actor Manager {
7474
}
7575
pushProgress(stage:.validating)
7676
do{
77-
tryValidator.validate(path: dest)
77+
tryValidator.validateSignature(binaryPath: dest)
78+
tryawaitValidator.validateVersion(binaryPath: dest, serverVersion: buildInfo.version)
7879
}catch{
7980
throw.validation(error)
8081
}

‎Coder-Desktop/VPNLib/Validate.swift‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import Subprocess
23

34
publicenumValidationError:Error{
45
case fileNotFound
@@ -7,7 +8,8 @@ public enum ValidationError: Error {
78
case unableToRetrieveSignature
89
case invalidIdentifier(identifier:String?)
910
case invalidTeamIdentifier(identifier:String?)
10-
case invalidVersion(version:String?)
11+
case unableToReadVersion(anyError)
12+
case binaryVersionMismatch(binaryVersion:String, serverVersion:String)
1113

1214
publicvardescription:String{
1315
switchself{
@@ -21,10 +23,12 @@ public enum ValidationError: Error {
2123
"Unable to retrieve signing information."
2224
caselet.invalidIdentifier(identifier):
2325
"Invalid identifier:\(identifier??"unknown")."
24-
caselet.invalidVersion(version):
25-
"Invalid runtimeversion:\(version??"unknown")."
26+
caselet.binaryVersionMismatch(binaryVersion, serverVersion):
27+
"Binaryversion does not match server. Binary:\(binaryVersion), Server:\(serverVersion)."
2628
caselet.invalidTeamIdentifier(identifier):
2729
"Invalid team identifier:\(identifier??"unknown")."
30+
case.unableToReadVersion:
31+
"Unable to execute the binary to read version"
2832
}
2933
}
3034

@@ -41,13 +45,13 @@ public class Validator {
4145

4246
privatestaticletsignInfoFlags:SecCSFlags=.init(rawValue: kSecCSSigningInformation)
4347

44-
publicstaticfuncvalidate(path:URL)throws(ValidationError){
45-
guardFileManager.default.fileExists(atPath:path.path)else{
48+
publicstaticfuncvalidateSignature(binaryPath:URL)throws(ValidationError){
49+
guardFileManager.default.fileExists(atPath:binaryPath.path)else{
4650
throw.fileNotFound
4751
}
4852

4953
varstaticCode:SecStaticCode?
50-
letstatus=SecStaticCodeCreateWithPath(pathasCFURL,SecCSFlags(),&staticCode)
54+
letstatus=SecStaticCodeCreateWithPath(binaryPathasCFURL,SecCSFlags(),&staticCode)
5155
guard status== errSecSuccess,let code= staticCodeelse{
5256
throw.unableToCreateStaticCode
5357
}
@@ -78,6 +82,29 @@ public class Validator {
7882
}
7983
}
8084

85+
publicstaticfunc validateVersion(binaryPath:URL, serverVersion:String)asyncthrows(ValidationError){
86+
guardFileManager.default.fileExists(atPath: binaryPath.path)else{
87+
throw.fileNotFound
88+
}
89+
90+
letversion:String
91+
do{
92+
letversionOutput=tryawaitSubprocess.data(for:[binaryPath.path,"version","--output=json"])
93+
letparsed:VersionOutput=tryJSONDecoder().decode(VersionOutput.self, from: versionOutput)
94+
version= parsed.version
95+
}catch{
96+
throw.unableToReadVersion(error)
97+
}
98+
99+
guard version== serverVersionelse{
100+
throw.binaryVersionMismatch(binaryVersion: version, serverVersion: serverVersion)
101+
}
102+
}
103+
104+
structVersionOutput:Codable{
105+
letversion:String
106+
}
107+
81108
publicstaticletxpcPeerRequirement="anchor apple generic"+ // Apple-issued certificate chain
82109
" and certificate leaf[subject.OU] =\""+ expectedTeamIdentifier+"\"" // Signed by the Coder team
83110
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp