spctl reports internal error for an ad-hoc signed macOS command-line tool

On an Apple Silicon Mac running macOS 27.0.1 (26A434), I am assessing the arm64 command-line tool age v1.3.2. The downloaded file retains its quarantine attribute.

The command spctl --assess --type execute --verbose=2 returned exit code 1 with: “internal error in Code Signing subsystem”. A later codesign --verify --strict --verbose=4 check returned exit code 0. The file hash and recorded attributes did not change around the strict verification.

The tool is ad-hoc/linker-signed, with no TeamIdentifier. I have not executed the tool or removed quarantine. The exact environment and independent raw output file for the first spctl assessment were not recorded; the error above is a transcription of the observed output.

What is the supported way to assess a standalone command-line tool in this situation? How can I distinguish a policy rejection from an assessment failure, and what further diagnostics would you recommend without running the tool or reducing system security?

Answered by DTS Engineer in 916800022

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

You wrote:

Our goal is encrypted backup and restore for an internal macOS app using the age command-line tool.

Just so we’re clear, you’re referring to this right?

What is the supported way to test and distribute this helper securely?

It very much depends on the nature of your product, but if you’re building a Mac app then standard practice is to embed the helper tool into your app and then sign and notarise it as part of your app’s distribution workflow.

For example, if you were building a sandboxed app to distribute on the Mac App Store you might use the process described in the second part (Embed an externally built tool) of Embedding a command-line tool in a sandboxed app.

The general process also works for non-sandboxed apps built with Xcode.

OTOH, if you’re not using Xcode to build your product then I recommend:

IMPORTANT When you build the tool, make sure you use the Apple linker. Go projects are notorious for using their own linker, which can result in all sorts of weird problems.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What are you trying to achieve here?

The spctl tool is meant to be used by users. It’s not meant to be used an an API for running assessments. So:

  • If you’re running spctl as its intended then the answer is “Look at the results and see if you think it succeeded or not.”
  • But if you’re trying to use it as an API then we need to talk more about what your actual goals are.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

You wrote:

Our goal is encrypted backup and restore for an internal macOS app using the age command-line tool.

Just so we’re clear, you’re referring to this right?

What is the supported way to test and distribute this helper securely?

It very much depends on the nature of your product, but if you’re building a Mac app then standard practice is to embed the helper tool into your app and then sign and notarise it as part of your app’s distribution workflow.

For example, if you were building a sandboxed app to distribute on the Mac App Store you might use the process described in the second part (Embed an externally built tool) of Embedding a command-line tool in a sandboxed app.

The general process also works for non-sandboxed apps built with Xcode.

OTOH, if you’re not using Xcode to build your product then I recommend:

IMPORTANT When you build the tool, make sure you use the Apple linker. Go projects are notorious for using their own linker, which can result in all sorts of weird problems.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you, Quinn. Yes, we mean FiloSottile’s age, specifically the upstream v1.3.2 darwin-arm64 release.

We plan to embed it as a helper and include it in our app’s Developer ID signing, notarization, and distribution process.

The existing binary passes strict code-signature verification, while the earlier spctl --assess --type execute returned “internal error in Code Signing subsystem.” We do not regard either result as identifying the cause.

We have not established the actual linker invocation used for this upstream artifact. What build evidence would you recommend obtaining to verify Apple linker use, and under what circumstances would you recommend rebuilding this helper rather than retaining the upstream binary for the distribution-signing workflow?

We have not executed the helper or changed quarantine or security settings.

Written by FangShenDev in 917016022

What build evidence would you recommend obtaining to verify Apple linker use

I don’t know enough about Go toolchains to offer a definitive answer to this. If you need that, I recommend that you ask this of the support channel for that tooling.

However, there are a few things you could check:

  • Make sure the resulting executable has a sensible build UUID, as discussed in TN3178 Checking for and resolving build UUID problems. And by sensible I mean that a) it’s not all zeros, or all ones, or some other obvious placeholder, and b) it varies from build to build.

  • That it imports the System framework dynamically [1]. For example, this is what I see with a standard C tool built using Xcode:

    % dyld_info -linked_dylibs Test857202
    Test857202 [arm64]:
        -linked_dylibs:
            attributes       load path
                             /usr/lib/libSystem.B.dylib
                             … and perhaps more …
    
  • That it includes a LC_BUILD_VERSION load command that includes the Apple linker in its tool list:

    % vtool -show-build Test857202
    Test857202:
    Load command 9
          cmd LC_BUILD_VERSION
      cmdsize 32
     platform MACOS
        minos 12.0
          sdk 27.2
       ntools 1
         tool LD
      version 27106.1
    

    Note that, if the tool was built with a really old deployment target (earlier than macOS 10.13) this command might not be present. Instead the tool will have LC_VERSION_MIN_MACOSX and that doesn’t have a spot to record info about the linker.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Historically the Go linker used to not import the System framework but instead make direct system calls. This is not supported on Apple platforms. I think the’ve fixed that, but this isn’t something I track in detail. My main experience with Go is helping developers recover from its… well… let’s just say… creative design choices (-: