I'm using kauth
kernel framework in order to get events on files that are being opened in the system.
after filtering out the executable macho files, I'd like to check the signature validation for each such file that it's vnode is represented in vp = (vnode_t) arg1
Looking in xnu source code, I've found out mac_vnode_check_signature
in mac_framework.h
However it's not part of kernel public api... perhaps there are any alternatives ?
in user-space I've found good API for this called MOLCodesignChecker which is activated in the following way
MOLCodesignChecker *molChecker = [[MOLCodesignChecker alloc] initWithBinaryPath:filePath error:&error];
NSArray *certificates = molChecker.certificates;
MOLCertificate *cert = [certificates objectAtIndex:i];
// print organization name e.g: "Apple Inc."
printf("signing name = %s", cert.orgName);
UPDATE :
Following pmdj advice below, I've found a way to extract the signature of a running process using csproc_get_blob
and csproc_get_teamid
to extract the specific field which may represent the vendor (there are also synonyms for vnode instead of process).
However, After calling this method on /usr/sbin/spindump
I got NULL pointer (instead of valid string) and it matches the output from user-space command code sign
:
codesign -dvvv /usr/sbin/spindump
Executable=/usr/sbin/spindump
Identifier=com.apple.spindump
Format=Mach-O thin (x86_64)
CodeDirectory v=20100 size=3267 flags=0x0(none) hashes=95+5 location=embedded
Platform identifier=4
Hash type=sha256 size=32
CandidateCDHash sha256=d5bfa6a2a2ad8ffa377c6ef7f7b94c81821821fb
Hash choices=sha256
CDHash=d5bfa6a2a2ad8ffa377c6ef7f7b94c81821821fb
Signature size=4485
Authority=Software Signing
Authority=Apple Code Signing Certification Authority
Authority=Apple Root CA
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=1 size=68
As you can see, the TeamIdentifier is not set
. I'd like to somehow extract the Authority out of cs_blob
in order to get the vendor name (Apple
in this case)