MacOS – How to compile Apple’s Security framework

macosopen sourceunixxcode

I am trying to compile my own copy of Apple's Security.framework, specifically version 55471.14.18, which was included in OS X 10.9.5 and whose source code can be downloaded from https://opensource.apple.com/tarballs/Security/Security-55471.14.18.tar.gz.

I'm using a copy of Mac OS X 10.9.5 in a VM. Xcode 6.2 has been installed, and xcode-select --install has separately been run to acquire system headers.


The readme file included in the source download says:

To build this project in a Darwin environment (as opposed to building
in-house at Apple), use the Darwin buildstyle. If you're building with
Xcode, select "Darwin" from the "Active Build Style" popup. If you're
building from the command line, specify the build style like so:

% xcodebuild -buildstyle Darwin install

But when I run the given command, I'm told:

xcodebuild: error: option '-buildstyle' is no longer supported

Since my copy of Xcode was current at the time this code was released, I'm not sure what to make of this error. I decided to ignore it and press on with just a standard xcodebuild command.


The first problem I ran into was easy to fix, but makes me worried I'm missing something larger. The compiler complains:

/Users/Jonathan/Desktop/Security-55471.14.18/libsecurity_utilities/lib/macho++.cpp:39:18: error: 
unused variable 'MAX_ARCH_COUNT' [-Werror,-Wunused-const-variable]
static const int MAX_ARCH_COUNT = 100;

Since the variable is reportedly unused anyway, I just opened the file and commented out the line static const int MAX_ARCH_COUNT = 100;.


Unfortunately, this is where I ran into a brick wall. Xcodebuild seems to want all sorts of headers that are not on my system or included in the project. For instance:

/Users/Jonathan/Desktop/Security-55471.14.18/libsecurity_utilities/lib/mach++.cpp:33:10: fatal error: 
      'bootstrap_priv.h' file not found
#include <bootstrap_priv.h>

These headers are also open source, and I know where to find them! Bootstrap_priv.h, for example, is part of launchd; the OS X 10.9.5 version can be downloaded from https://opensource.apple.com/tarballs/launchd/launchd-842.92.1.tar.gz

However, I do not understand where I'm supposed to put these headers in order for the compiler to find them! Things I've tried:

  • Copying the launchd project to /usr/include/
  • Copying the launchd project to the root of the security project
  • Copying just Bootstrap_priv.h to /usr/include/
  • Copying just bootstrap_priv.h to the root of the security project
  • Copying just bootstrap_priv.h to the project directory/libsecurity_utilities/lib/

That last attempt actually did let me get past the error (and to see the next missing header, IOPMLibPrivate.h), but I'm quite sure it's not what I'm supposed to do! As I keep adding headers to random places within the project, other source files get stuck finding headers I've already copied elsewhere. Some of the headers themselves get stuck this way, expecting a different relative path for dependencies than what the main project seems to need.


I am feeling extremely out of my depth here! Where are these header files actually supposed to go, and what is the meaning of that -buildstyle option I'm supposed to include but which can't be run? None of this appears to be documented anywhere!

Best Answer

This ended up being a lot more complicated than I think rightly fits this site's Q&A format. Even so, I didn't want to leave this question hanging, since I did get the framework to build, kindda.

This repository should build fully in 10.9.5 running the latest compatible version of xCode, and using the 10.9 SDK. https://github.com/Wowfunhappy/Wowfunhappy-Mavericks-Security-Framework

I used the "User Framework Search Paths" to add libraries, but because it's an absolute rather than a relative path, you may need to update it on your machine. This should be trivial even if it is a bit tedious—all of the actual frameworks are included in the Git repository. These Frameworks come from a combination of opensource.apple.com (preferred wherever available for obvious reasons), samdmarshall's reverse-engineered private SDK, and the Darling project.

The built Framework does not appear to actually function—replacing it on my hard drive makes the computer (a VM, thankfully) unable to boot. I initially expected this to be a code signing issue, but it doesn't look like that's the problem. But, still, it built!

tl;dr I wasn't making some stupid oversight, Apple's opensource releases are basically impossible to actually build without additional reverse engineering. Luckily, that reverse engineering work has largely been done by various projects, but seemingly not to the point where you can build something that actually works.