- Notifications
You must be signed in to change notification settings - Fork5
fix: add code signing requirements to xpc connections#206
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
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,6 @@ | ||
import CryptoKit | ||
import Foundation | ||
public func download( | ||
src: URL, | ||
dest: URL, | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,128 @@ | ||||||
import Foundation | ||||||
publicenumValidationError:Error{ | ||||||
case fileNotFound | ||||||
case unableToCreateStaticCode | ||||||
case invalidSignature | ||||||
case unableToRetrieveInfo | ||||||
case invalidIdentifier(identifier:String?) | ||||||
case invalidTeamIdentifier(identifier:String?) | ||||||
case missingInfoPList | ||||||
case invalidVersion(version:String?) | ||||||
case belowMinimumCoderVersion | ||||||
publicvardescription:String{ | ||||||
switchself{ | ||||||
case.fileNotFound: | ||||||
"The file does not exist." | ||||||
case.unableToCreateStaticCode: | ||||||
"Unable to create a static code object." | ||||||
case.invalidSignature: | ||||||
"The file's signature is invalid." | ||||||
case.unableToRetrieveInfo: | ||||||
"Unable to retrieve signing information." | ||||||
caselet.invalidIdentifier(identifier): | ||||||
"Invalid identifier:\(identifier??"unknown")." | ||||||
caselet.invalidVersion(version): | ||||||
"Invalid runtime version:\(version??"unknown")." | ||||||
caselet.invalidTeamIdentifier(identifier): | ||||||
"Invalid team identifier:\(identifier??"unknown")." | ||||||
case.missingInfoPList: | ||||||
"Info.plist is not embedded within the dylib." | ||||||
case.belowMinimumCoderVersion: | ||||||
""" | ||||||
The Coder deployment must be version\(Validator.minimumCoderVersion) | ||||||
or higher to use Coder Desktop. | ||||||
""" | ||||||
} | ||||||
} | ||||||
publicvarlocalizedDescription:String{ description} | ||||||
} | ||||||
publicclassValidator{ | ||||||
// Whilst older dylibs exist, this app assumes v2.20 or later. | ||||||
publicstaticletminimumCoderVersion="2.20.0" | ||||||
privatestaticletexpectedName="CoderVPN" | ||||||
privatestaticletexpectedIdentifier="com.coder.Coder-Desktop.VPN.dylib" | ||||||
privatestaticletexpectedTeamIdentifier="4399GN35BJ" | ||||||
privatestaticletinfoIdentifierKey="CFBundleIdentifier" | ||||||
privatestaticletinfoNameKey="CFBundleName" | ||||||
privatestaticletinfoShortVersionKey="CFBundleShortVersionString" | ||||||
privatestaticletsignInfoFlags:SecCSFlags=.init(rawValue: kSecCSSigningInformation) | ||||||
// `expectedVersion` must be of the form `[0-9]+.[0-9]+.[0-9]+` | ||||||
publicstaticfunc validate(path:URL, expectedVersion:String)throws(ValidationError){ | ||||||
guardFileManager.default.fileExists(atPath: path.path)else{ | ||||||
throw.fileNotFound | ||||||
} | ||||||
varstaticCode:SecStaticCode? | ||||||
letstatus=SecStaticCodeCreateWithPath(pathasCFURL,SecCSFlags(),&staticCode) | ||||||
guard status== errSecSuccess,let code= staticCodeelse{ | ||||||
throw.unableToCreateStaticCode | ||||||
} | ||||||
letvalidateStatus=SecStaticCodeCheckValidity(code,SecCSFlags(),nil) | ||||||
guard validateStatus== errSecSuccesselse{ | ||||||
throw.invalidSignature | ||||||
} | ||||||
varinformation:CFDictionary? | ||||||
letinfoStatus=SecCodeCopySigningInformation(code, signInfoFlags,&information) | ||||||
guard infoStatus== errSecSuccess,let info= informationas?[String:Any]else{ | ||||||
throw.unableToRetrieveInfo | ||||||
} | ||||||
guardlet identifier=info[kSecCodeInfoIdentifierasString]as?String, | ||||||
identifier== expectedIdentifier | ||||||
else{ | ||||||
throw.invalidIdentifier(identifier:info[kSecCodeInfoIdentifierasString]as?String) | ||||||
} | ||||||
guardlet teamIdentifier=info[kSecCodeInfoTeamIdentifierasString]as?String, | ||||||
teamIdentifier== expectedTeamIdentifier | ||||||
else{ | ||||||
throw.invalidTeamIdentifier( | ||||||
identifier:info[kSecCodeInfoTeamIdentifierasString]as?String | ||||||
) | ||||||
} | ||||||
guardlet infoPlist=info[kSecCodeInfoPListasString]as?[String:AnyObject]else{ | ||||||
throw.missingInfoPList | ||||||
} | ||||||
tryvalidateInfo(infoPlist: infoPlist, expectedVersion: expectedVersion) | ||||||
} | ||||||
publicstaticletxpcPeerRequirement="anchor apple generic"+ // Apple-issued certificate chain | ||||||
" and certificate leaf[subject.OU] =\""+ expectedTeamIdentifier+"\"" // Signed by the Coder team | ||||||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||
privatestaticfunc validateInfo(infoPlist:[String:AnyObject], expectedVersion:String)throws(ValidationError){ | ||||||
guardlet plistIdent=infoPlist[infoIdentifierKey]as?String, plistIdent== expectedIdentifierelse{ | ||||||
throw.invalidIdentifier(identifier:infoPlist[infoIdentifierKey]as?String) | ||||||
} | ||||||
guardlet plistName=infoPlist[infoNameKey]as?String, plistName== expectedNameelse{ | ||||||
throw.invalidIdentifier(identifier:infoPlist[infoNameKey]as?String) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The error type should be a name-specific validation error, not Suggested change
Copilot uses AI. Check for mistakes. | ||||||
} | ||||||
// Downloaded dylib must match the version of the server | ||||||
guardlet dylibVersion=infoPlist[infoShortVersionKey]as?String, | ||||||
expectedVersion== dylibVersion | ||||||
else{ | ||||||
throw.invalidVersion(version:infoPlist[infoShortVersionKey]as?String) | ||||||
} | ||||||
// Downloaded dylib must be at least the minimum Coder server version | ||||||
guardlet dylibVersion=infoPlist[infoShortVersionKey]as?String, | ||||||
// x.compare(y) is .orderedDescending if x > y | ||||||
minimumCoderVersion.compare(dylibVersion, options:.numeric)!=.orderedDescending | ||||||
else{ | ||||||
throw.belowMinimumCoderVersion | ||||||
} | ||||||
} | ||||||
} |
Uh oh!
There was an error while loading.Please reload this page.