Regarding Programs can’t authenticate themselves.
I don't try to authenticate my own executable, I am trying to verify a helper binary/dylib inside my product that can be updated separately from the main binary.
Before running/dlopening it, I would like to ensure:
Test 1) The signature chain of the executable/dylib leads to the apple root.
Test 2) The leaf certificate team-id is my team-id.
Per my understanding this will ensure that this executable/binary was signed by me.
If anyone else has a valid certificate(it can pass Test 1) but it will fail the Test 2 as its team ID will be different.
If someone crafts a rogue certificate in order to pass Test 2 then this rogue certificate is not signed by apple and therefore will fail Test 1.
Please advise if you see any problem with this approach.
Now to my main question:
When I try to extract the team id from the executable/dylib using SecCodeCopySigningInformation, I see some posts claim that if that executable is not signed by apple root chain team-id will come up as empty.
I therefore ask:
Approach 1: Is it enough to extract the team-id and compare to mine ?
Does extracting a team-id(using SecCodeCopySigningInformation) automatically verifies that the anchor is apple ?
OR
Approach 2: Should I extract the team-id and compare it to mine AND in addition, manually verify the that anchor/root is apple ?
I currently did "Approach 2" but it seems when I am trying to verify the anchor it sometimes takes several minutes for some reason and I see:
trustd: [com.apple.securityd:SecError] Malformed anchor records, not an array
Printed in the logs.
I therefore wonder if its required at all.
Topic:
Code Signing
SubTopic:
Certificates, Identifiers & Profiles
Tags: