I want to evaluate whether processes installed and running on a macOS system are legitimate.
I understand (thanks Eskimo) that checking their identifier is not a good way to identify processes, as any developer can use any identifier. I also understand that I should use DesignatedRequirements.
I have the following code at the moment:
// Get code signing information.
var infoOpt: CFDictionary? = nil
err = SecCodeCopySigningInformation(staticCode, SecCSFlags(rawValue:kSecCSRequirementInformation), &infoOpt)
guard err == errSecSuccess, let info = infoOpt as? [String:Any] else {
return nil
}
let processId = info[kSecCodeInfoIdentifier as String] as? String // nil iif code is not signed
let designatedRequirement = info[kSecCodeInfoDesignatedRequirement as String] as! SecRequirement
var designatedRequirementCFStr : CFString?
SecRequirementCopyString(designatedRequirement, [], &designatedRequirementCFStr)
let designatedRequirementStr = designatedRequirementCFStr as String?
But how can I use the designated requirement to ensure that the app is legitimate ?
More specifically :
- If I want the anchor (root certificate) to be Apple's, how can I programatically check it ? There must be something better than parsing the string above.
- I am not very familair with the certificate process. What is the anchor "apple generic" ?
- What is a reasonable rule to accept the process as legitimate? Is it all about the anchor and I can disregard the certificate leaf?
Thanks!