# How to Check a Downloaded Mac App Before You Open It

> Verify a Mac download in Terminal: compare the SHA-256 with shasum, ask Gatekeeper with spctl, read the signer with codesign and check notarization.

Canonical URL: https://levelrail.com/blog/verify-downloaded-mac-app-before-opening/

Four Terminal checks tell you whether a Mac download is the file the publisher released, who signed it and whether Apple notarized it. None of them runs the app.

The examples use the [Levelrail for Mac](https://levelrail.com/download/) 0.1.0 disk image. Swap in your own file names.

## The checks at a glance

| Check | Command | Answers |
| --- | --- | --- |
| Checksum | `shasum -a 256` | Is this the published file? |
| Gatekeeper | `spctl --assess` | Would macOS accept this app? |
| Signature | `codesign` | Who signed it, and was it changed since? |
| Ticket | `stapler validate` | Is the notarization ticket attached? |

## Step 1: compare the checksum

Get the SHA-256 from the publisher's own page, then run:

```bash
cd ~/Downloads
echo "7ae3f9e6ddcc8b7a8689e636bfe28087a708765a4ae2889a42f8c2c724b30342  Levelrail_0.1.0_arm64.dmg" | shasum -a 256 -c
```

Keep the two spaces between the hash and the file name. A match prints:

```text
Levelrail_0.1.0_arm64.dmg: OK
```

If a release ships a `.sha256` file, as [this one does](https://github.com/glincker/levelrail/releases/tag/desktop/v0.1.0), save it next to the download and run `shasum -a 256 -c Levelrail_0.1.0_arm64.dmg.sha256`.

A mismatch means stop. Delete the file and download it again from the official page.

## Step 2: mount the image and ask Gatekeeper

Mounting a disk image does not start the app inside it. Double click the file, or mount it read-only:

```bash
hdiutil attach -readonly -nobrowse ~/Downloads/Levelrail_0.1.0_arm64.dmg
spctl --assess --type execute -vv /Volumes/Levelrail/Levelrail.app
```

The output for this release:

```text
/Volumes/Levelrail/Levelrail.app: accepted
source=Notarized Developer ID
origin=Developer ID Application: Gagan Deep Singh (CR6FQFMMSW)
```

Read all three lines. `accepted` is the verdict, `source` says it is notarized, and `origin` names the signer. Check that the signer is who you expect.

Run this check on the app. For Levelrail 0.1.0 the signature and notarization are on the app, and the `.dmg` is its container, so assessing the image itself reports no usable signature. The checksum in step 1 is what covers the image.

## Step 3: verify the signature

```bash
codesign --verify --deep --strict --verbose=2 /Volumes/Levelrail/Levelrail.app
codesign -dv --verbose=2 /Volumes/Levelrail/Levelrail.app
```

The output of the first command should include these two lines:

```text
/Volumes/Levelrail/Levelrail.app: valid on disk
/Volumes/Levelrail/Levelrail.app: satisfies its Designated Requirement
```

The second prints details. These are the ones to read:

```text
Identifier=com.levelrail.desktop
Authority=Developer ID Application: Gagan Deep Singh (CR6FQFMMSW)
Authority=Developer ID Certification Authority
Authority=Apple Root CA
TeamIdentifier=CR6FQFMMSW
```

The chain should end at `Apple Root CA`. Note the team identifier: a later version of the same app should normally carry the same one.

You can also ask `codesign` to require notarization:

```bash
codesign --test-requirement="=notarized" --verify --verbose /Volumes/Levelrail/Levelrail.app
```

Success includes the line `explicit requirement satisfied`.

## Step 4: check the stapled ticket

```bash
xcrun stapler validate /Volumes/Levelrail/Levelrail.app
```

For this release it ends with `The validate action worked!`.

A stapled ticket lets Gatekeeper confirm notarization without a network connection. Software can be notarized without one, in which case [Apple says Gatekeeper finds the ticket online](https://developer.apple.com/documentation/security/customizing-the-notarization-workflow). So read a missing ticket together with the `spctl` result.

When you are done, eject the image:

```bash
hdiutil detach /Volumes/Levelrail
```

## If a check fails

Treat a failure as information. If `spctl` says `rejected` for an app, or the signer is not the one you expect, do not open it.

Apple documents an **Open Anyway** button under System Settings, Privacy & Security, for apps you are certain come from a trustworthy source. Read [Apple's guidance](https://support.apple.com/en-us/102445) first, and be wary of any download page that tells you to strip security attributes in Terminal.

## What to do next

Copy the app to Applications once the checks pass. The [Levelrail download page](https://levelrail.com/download/#verify) shows the checksum and the requirements. For server binaries and container images, see [verifying a Levelrail release with checksums and cosign](https://levelrail.com/blog/verify-levelrail-release-checksums-cosign/), or the [install page](https://levelrail.com/install/).

## Frequently asked questions

### Does a matching SHA-256 mean the app is safe?

No. It means your file is the same as the one the publisher hashed. Use it together with the signature and notarization checks.

### What does notarized mean?

Apple says that for a notarized app, it checked the software for malicious content and none was detected. It is not a review of what the app does.

### Do I need Xcode for these checks?

shasum, spctl, codesign and hdiutil come with macOS. The stapler tool is part of Apple's developer tools.
