how … do you determine if an app's signature is, uh, legitimate?
That depends on what you mean by “legitimate” (-:
Before we start I want you to read through the Code Signing Requirement Language section of the Code Signing Guide. I’m going to assume you understand that.
Also, the following is going to reference a whole bunch of oids that are specified by the various documents on the Apple PKI page.
There are four broad categories of code on the Mac:
You can check for each of these using a code signing requirement. For example, consider the designated requirement on a Developer ID app:
% codesign -d -r - "Pacifist.app"
…
designated => anchor apple generic and
identifier "com.charlessoft.pacifist" and
(certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or
certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and
certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and
certificate leaf[subject.OU] = HRLUCP7QP4
)
Note I’ve reflowed this to make it easier to read.
There’s three parts to this:
If you want to check for a Developer ID app but don’t care about the code signing identifier or the Team ID, build a requirement like this:
% cat DeveloperID-only.req
anchor apple generic and
(certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and
certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */
)
Now test it on various types of code:
% # Pacifist is Developer ID.
%
% codesign -v -R DeveloperID-only.req -v "Pacifist.app"
…
Pacifist.app: explicit requirement satisfied
%
% # Tap Forms is Mac App Store, so not Developer ID.
%
% codesign -v -R DeveloperID-only.req -v "Tap Forms 5.app"
…
test-requirement: code failed to satisfy specified code requirement(s)
%
% # TextEdit is built in, so not Developer ID.
%
% codesign -v -R DeveloperID-only.req -v "/System/Applications/TextEdit.app"
…
test-requirement: code failed to satisfy specified code requirement(s)
%
% # Safari Technology Preview is not-built-in Apple, so still not Developer ID.
%
% codesign -v -R DeveloperID-only.req -v "Safari Technology Preview.app"
…
test-requirement: code failed to satisfy specified code requirement(s)
Oh, one last thing: While I’m running these tests with the codesign tool, you can just as easily run them using SecCode APIs.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"