Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a2105a2ae6 | |||
c1d535ef95 | |||
1083c0f733 | |||
914e4d6910 | |||
e70774f6aa |
1
.github/FUNDING.yml
vendored
@ -1 +0,0 @@
|
|||||||
github: maxgoedjen
|
|
BIN
.github/readme/app.png
vendored
Before Width: | Height: | Size: 338 KiB After Width: | Height: | Size: 348 KiB |
BIN
.github/readme/apple_watch_auth_mac.png
vendored
Before Width: | Height: | Size: 192 KiB |
BIN
.github/readme/apple_watch_auth_watch.png
vendored
Before Width: | Height: | Size: 26 KiB |
BIN
.github/readme/apple_watch_system_prefs.png
vendored
Before Width: | Height: | Size: 631 KiB |
BIN
.github/readme/notification.png
vendored
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.5 MiB |
BIN
.github/readme/touchid.png
vendored
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 135 KiB |
17
.github/workflows/release.yml
vendored
@ -6,7 +6,7 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: macos-11.0
|
runs-on: macOS-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
@ -17,15 +17,13 @@ jobs:
|
|||||||
HOST_PROFILE_DATA: ${{ secrets.HOST_PROFILE_DATA }}
|
HOST_PROFILE_DATA: ${{ secrets.HOST_PROFILE_DATA }}
|
||||||
AGENT_PROFILE_DATA: ${{ secrets.AGENT_PROFILE_DATA }}
|
AGENT_PROFILE_DATA: ${{ secrets.AGENT_PROFILE_DATA }}
|
||||||
run: ./.github/scripts/signing.sh
|
run: ./.github/scripts/signing.sh
|
||||||
- name: Set Environment
|
|
||||||
run: sudo xcrun xcode-select -s /Applications/Xcode_12.2.app
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: xcrun xcodebuild test -project Secretive.xcodeproj -scheme Secretive
|
run: xcrun xcodebuild test -project Secretive.xcodeproj -scheme Secretive
|
||||||
build:
|
build:
|
||||||
runs-on: macos-11.0
|
runs-on: macOS-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v1
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
@ -34,7 +32,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref }}
|
tag_name: ${{ github.ref }}
|
||||||
release_name: ${{ github.ref }}
|
release_name: ${{ github.ref }}
|
||||||
body: "## Build\nhttps://github.com/maxgoedjen/secretive/actions/runs/${{ github.run_id }}"
|
body: "Build: https://github.com/maxgoedjen/secretive/actions/runs/${{ github.run_id }}"
|
||||||
draft: true
|
draft: true
|
||||||
prerelease: false
|
prerelease: false
|
||||||
- name: Setup Signing
|
- name: Setup Signing
|
||||||
@ -44,17 +42,12 @@ jobs:
|
|||||||
HOST_PROFILE_DATA: ${{ secrets.HOST_PROFILE_DATA }}
|
HOST_PROFILE_DATA: ${{ secrets.HOST_PROFILE_DATA }}
|
||||||
AGENT_PROFILE_DATA: ${{ secrets.AGENT_PROFILE_DATA }}
|
AGENT_PROFILE_DATA: ${{ secrets.AGENT_PROFILE_DATA }}
|
||||||
run: ./.github/scripts/signing.sh
|
run: ./.github/scripts/signing.sh
|
||||||
- name: Set Environment
|
|
||||||
run: sudo xcrun xcode-select -s /Applications/Xcode_12.2.app
|
|
||||||
- name: Update Build Number
|
- name: Update Build Number
|
||||||
env:
|
env:
|
||||||
TAG_NAME: ${{ github.ref }}
|
TAG_NAME: ${{ github.ref }}
|
||||||
RUN_ID: ${{ github.run_id }}
|
|
||||||
run: |
|
run: |
|
||||||
export CLEAN_TAG=$(echo $TAG_NAME | sed -e 's/refs\/tags\/v//')
|
export CLEAN_TAG=$(echo $TAG_NAME | sed -e 's/refs\/tags\/v//')
|
||||||
sed -i '' -e "s/GITHUB_CI_VERSION/$CLEAN_TAG/g" Config/Config.xcconfig
|
sed -i '' -e "s/CI_VERSION = 0.0.0/CI_VERSION = $CLEAN_TAG/g" Config/Config.xcconfig
|
||||||
sed -i '' -e "s/GITHUB_BUILD_NUMBER/1.$RUN_ID/g" Config/Config.xcconfig
|
|
||||||
sed -i '' -e "s/GITHUB_BUILD_URL/https:\/\/github.com\/maxgoedjen\/secretive\/actions\/runs\/$RUN_ID/g" Secretive/Credits.rtf
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: xcrun xcodebuild -project Secretive.xcodeproj -scheme Secretive -configuration Release -archivePath Archive.xcarchive archive
|
run: xcrun xcodebuild -project Secretive.xcodeproj -scheme Secretive -configuration Release -archivePath Archive.xcarchive archive
|
||||||
- name: Create ZIPs
|
- name: Create ZIPs
|
||||||
|
15
.github/workflows/test.yml
vendored
@ -1,13 +1,18 @@
|
|||||||
name: Test
|
name: Test
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: push
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: macos-11.0
|
runs-on: macOS-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v1
|
||||||
- name: Set Environment
|
- name: Setup Signing
|
||||||
run: sudo xcrun xcode-select -s /Applications/Xcode_12.2.app
|
env:
|
||||||
|
SIGNING_DATA: ${{ secrets.SIGNING_DATA }}
|
||||||
|
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
|
||||||
|
HOST_PROFILE_DATA: ${{ secrets.HOST_PROFILE_DATA }}
|
||||||
|
AGENT_PROFILE_DATA: ${{ secrets.AGENT_PROFILE_DATA }}
|
||||||
|
run: ./.github/scripts/signing.sh
|
||||||
- name: Test
|
- name: Test
|
||||||
run: xcrun xcodebuild test -project Secretive.xcodeproj -scheme Secretive
|
run: xcrun xcodebuild test -project Secretive.xcodeproj -scheme Secretive
|
||||||
|
1
.gitignore
vendored
@ -91,4 +91,3 @@ iOSInjectionProject/
|
|||||||
|
|
||||||
# Build script products
|
# Build script products
|
||||||
Archive.xcarchive
|
Archive.xcarchive
|
||||||
.DS_Store
|
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
# Setting up Third Party Apps FAQ
|
|
||||||
|
|
||||||
## Tower
|
|
||||||
|
|
||||||
Tower provides [instructions](https://www.git-tower.com/help/mac/integration/environment).
|
|
||||||
|
|
||||||
## GitHub Desktop
|
|
||||||
|
|
||||||
Should just work, no configuration needed
|
|
||||||
|
|
||||||
## Fork
|
|
||||||
|
|
||||||
Add this to your `~/.ssh/config` (the path should match the socket path from the setup flow).
|
|
||||||
|
|
||||||
```
|
|
||||||
Host *
|
|
||||||
IdentityAgent /Users/$YOUR_USERNAME/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh
|
|
||||||
```
|
|
||||||
|
|
||||||
## VS Code
|
|
||||||
|
|
||||||
Add this to your `~/.ssh/config` (the path should match the socket path from the setup flow).
|
|
||||||
|
|
||||||
```
|
|
||||||
Host *
|
|
||||||
IdentityAgent /Users/$YOUR_USERNAME/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
# The app I use isn't listed here!
|
|
||||||
|
|
||||||
If you know how to get it set up, please open a PR for this page and add it! Contributions are very welcome.
|
|
||||||
If you're not able to get it working, please file a [GitHub issue](https://github.com/maxgoedjen/secretive/issues/new) for it. No guarantees we'll be able to get it working, but chances are someone else in the community might be able to.
|
|
@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Brief.h
|
|
||||||
// Brief
|
|
||||||
//
|
|
||||||
// Created by Max Goedjen on 3/21/20.
|
|
||||||
// Copyright © 2020 Max Goedjen. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
//! Project version number for Brief.
|
|
||||||
FOUNDATION_EXPORT double BriefVersionNumber;
|
|
||||||
|
|
||||||
//! Project version string for Brief.
|
|
||||||
FOUNDATION_EXPORT const unsigned char BriefVersionString[];
|
|
||||||
|
|
||||||
// In this header, you should import all the public headers of your framework using statements like #import <Brief/PublicHeader.h>
|
|
||||||
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>$(PRODUCT_NAME)</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
||||||
<key>NSHumanReadableCopyright</key>
|
|
||||||
<string>$(PRODUCT_NAME) is MIT Licensed.</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
@ -1,145 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import Combine
|
|
||||||
|
|
||||||
public protocol UpdaterProtocol: ObservableObject {
|
|
||||||
|
|
||||||
var update: Release? { get }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Updater: ObservableObject, UpdaterProtocol {
|
|
||||||
|
|
||||||
@Published public var update: Release?
|
|
||||||
|
|
||||||
public init(checkOnLaunch: Bool) {
|
|
||||||
if checkOnLaunch {
|
|
||||||
// Don't do a launch check if the user hasn't seen the setup prompt explaining updater yet.
|
|
||||||
checkForUpdates()
|
|
||||||
}
|
|
||||||
let timer = Timer.scheduledTimer(withTimeInterval: 60*60*24, repeats: true) { _ in
|
|
||||||
self.checkForUpdates()
|
|
||||||
}
|
|
||||||
timer.tolerance = 60*60
|
|
||||||
}
|
|
||||||
|
|
||||||
public func checkForUpdates() {
|
|
||||||
URLSession.shared.dataTask(with: Constants.updateURL) { data, _, _ in
|
|
||||||
guard let data = data else { return }
|
|
||||||
guard let release = try? JSONDecoder().decode(Release.self, from: data) else { return }
|
|
||||||
self.evaluate(release: release)
|
|
||||||
}.resume()
|
|
||||||
}
|
|
||||||
|
|
||||||
public func ignore(release: Release) {
|
|
||||||
guard !release.critical else { return }
|
|
||||||
defaults.set(true, forKey: release.name)
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.update = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Updater {
|
|
||||||
|
|
||||||
func evaluate(release: Release) {
|
|
||||||
guard !userIgnored(release: release) else { return }
|
|
||||||
guard !release.prerelease else { return }
|
|
||||||
let latestVersion = SemVer(release.name)
|
|
||||||
let currentVersion = SemVer(Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String)
|
|
||||||
if latestVersion > currentVersion {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.update = release
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func userIgnored(release: Release) -> Bool {
|
|
||||||
guard !release.critical else { return false }
|
|
||||||
return defaults.bool(forKey: release.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaults: UserDefaults {
|
|
||||||
UserDefaults(suiteName: "com.maxgoedjen.Secretive.updater.ignorelist")!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SemVer {
|
|
||||||
|
|
||||||
let versionNumbers: [Int]
|
|
||||||
|
|
||||||
init(_ version: String) {
|
|
||||||
// Betas have the format 1.2.3_beta1
|
|
||||||
let strippedBeta = version.split(separator: "_").first!
|
|
||||||
var split = strippedBeta.split(separator: ".").compactMap { Int($0) }
|
|
||||||
while split.count < 3 {
|
|
||||||
split.append(0)
|
|
||||||
}
|
|
||||||
versionNumbers = split
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension SemVer: Comparable {
|
|
||||||
|
|
||||||
static func < (lhs: SemVer, rhs: SemVer) -> Bool {
|
|
||||||
for (latest, current) in zip(lhs.versionNumbers, rhs.versionNumbers) {
|
|
||||||
if latest < current {
|
|
||||||
return true
|
|
||||||
} else if latest > current {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Updater {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases/latest")!
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct Release: Codable {
|
|
||||||
|
|
||||||
public let name: String
|
|
||||||
public let prerelease: Bool
|
|
||||||
public let html_url: URL
|
|
||||||
public let body: String
|
|
||||||
|
|
||||||
public init(name: String, prerelease: Bool, html_url: URL, body: String) {
|
|
||||||
self.name = name
|
|
||||||
self.prerelease = prerelease
|
|
||||||
self.html_url = html_url
|
|
||||||
self.body = body
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Release: Identifiable {
|
|
||||||
|
|
||||||
public var id: String {
|
|
||||||
html_url.absoluteString
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Release {
|
|
||||||
|
|
||||||
public var critical: Bool {
|
|
||||||
body.contains(Constants.securityContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Release {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
static let securityContent = "Critical Security Update"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
import XCTest
|
|
||||||
@testable import Brief
|
|
||||||
|
|
||||||
class SemVerTests: XCTestCase {
|
|
||||||
|
|
||||||
func testEqual() {
|
|
||||||
let current = SemVer("1.0.2")
|
|
||||||
let old = SemVer("1.0.2")
|
|
||||||
XCTAssert(!(current > old))
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPatchGreaterButMinorLess() {
|
|
||||||
let current = SemVer("1.1.0")
|
|
||||||
let old = SemVer("1.0.2")
|
|
||||||
XCTAssert(current > old)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testMajorSameMinorGreater() {
|
|
||||||
let current = SemVer("1.0.2")
|
|
||||||
let new = SemVer("1.0.3")
|
|
||||||
XCTAssert(current < new)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testMajorGreaterMinorLesser() {
|
|
||||||
let current = SemVer("1.0.2")
|
|
||||||
let new = SemVer("2.0.0")
|
|
||||||
XCTAssert(current < new)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBeta() {
|
|
||||||
let current = SemVer("1.0.2")
|
|
||||||
let new = SemVer("1.1.0_beta1")
|
|
||||||
XCTAssert(current < new)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>$(PRODUCT_NAME)</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
@ -8,7 +8,7 @@ Security is obviously paramount for a project like Secretive. As such, any contr
|
|||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
Secretive is designed to be easily auditable by people who are considering using it. In keeping with this, Secretive has no third party dependencies, and any contributions which bring in new dependencies will be rejected.
|
Secretive is desigend to be easily auditable by people who are considering using it. In keeping with this, Secretive has no third party dependencies, and any contributions which bring in new dependencies will be rejected.
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
|
@ -1,2 +1 @@
|
|||||||
CI_VERSION = GITHUB_CI_VERSION
|
CI_VERSION = 0.0.0
|
||||||
CI_BUILD_NUMBER = GITHUB_BUILD_NUMBER
|
|
@ -29,21 +29,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"enabled" : false,
|
|
||||||
"parallelizable" : true,
|
"parallelizable" : true,
|
||||||
"target" : {
|
"target" : {
|
||||||
"containerPath" : "container:Secretive.xcodeproj",
|
"containerPath" : "container:Secretive.xcodeproj",
|
||||||
"identifier" : "50617D9323FCE48E0099B055",
|
"identifier" : "50617D9323FCE48E0099B055",
|
||||||
"name" : "SecretiveTests"
|
"name" : "SecretiveTests"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"parallelizable" : true,
|
|
||||||
"target" : {
|
|
||||||
"containerPath" : "container:Secretive.xcodeproj",
|
|
||||||
"identifier" : "5091D31E2519D56D0049FD9B",
|
|
||||||
"name" : "BriefTests"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version" : 1
|
"version" : 1
|
||||||
|
49
FAQ.md
@ -1,49 +0,0 @@
|
|||||||
# FAQ
|
|
||||||
|
|
||||||
### How do I import my current SSH keys, or export my Secretive Keys?
|
|
||||||
|
|
||||||
The secure enclave doesn't allow import or export of private keys. For any new computer, you should just create a new set of keys. If you're using a smart card, you _might_ be able to export your private key from the vendor's software.
|
|
||||||
|
|
||||||
### Secretive doesn't work with my git client/app
|
|
||||||
|
|
||||||
Secretive relies on the `SSH_AUTH_SOCK` environment variable being respected. The `git` and `ssh` command line tools natively respect this, but third party apps may require some configuration to work. A non-exhaustive list of setup steps is provided in the [App Config FAQ](APP_CONFIG.md).
|
|
||||||
|
|
||||||
### Secretive isn't working for me
|
|
||||||
|
|
||||||
Please run `ssh -Tv git@github.com` in your terminal and paste the output in a [new GitHub issue](https://github.com/maxgoedjen/secretive/issues/new) with a description of your issue.
|
|
||||||
|
|
||||||
### Secretive prompts me to type my password instead of using my Apple Watch
|
|
||||||
|
|
||||||
1) Make sure you have enabled "Use your Apple Watch to unlock apps and your Mac" in System Preferences --> Security & Privacy:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
2) Ensure that unlocking your Mac with Apple Watch is working (lock and unlock at least once)
|
|
||||||
3) Now you should get prompted on the watch when your key is accessed. Double click the side button to approve:
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
### Why should I trust you?
|
|
||||||
|
|
||||||
You shouldn't, for a piece of software like this. Secretive, by design, has an auditable build process. Each build has a fully auditable build log, showing the source it was built from and a SHA of the build product. You can check the SHA of the zip you download against the SHA output in the build log (which is linked in the About window).
|
|
||||||
|
|
||||||
### I want to build Secretive from source
|
|
||||||
|
|
||||||
Awesome! Just bear in mind that because an app only has access to the keychain items that it created, if you have secrets that you created with the prebuilt version of Secretive, you'll be unable to access them using your own custom build (since you'll have changed the bundled ID).
|
|
||||||
|
|
||||||
### What's this network request to GitHub?
|
|
||||||
|
|
||||||
Secretive checks in with GitHub's releases API to check if there's a new version of Secretive available. You can audit the source code for this feature [here](https://github.com/maxgoedjen/secretive/blob/main/Brief/Updater.swift).
|
|
||||||
|
|
||||||
### I have a security issue
|
|
||||||
|
|
||||||
Please contact [max.goedjen@gmail.com](mailto:max.goedjen@gmail.com) with a subject containing "SECRETIVE SECURITY" immediately with details, and I'll address the issue and credit you ASAP.
|
|
||||||
|
|
||||||
### I have a non-security related bug
|
|
||||||
|
|
||||||
Please file a [GitHub issue](https://github.com/maxgoedjen/secretive/issues/new) for it. I will not provide email support with the exception of the critical security issues mentioned above.
|
|
||||||
|
|
||||||
### I want to contribute to Secretive
|
|
||||||
|
|
||||||
Sweet! Please check out the [contributing guidelines](CONTRIBUTING.md) and go from there.
|
|
BIN
Icon.sketch
28
README.md
@ -1,11 +1,9 @@
|
|||||||
# Secretive  
|
# Secretive
|
||||||
|
|
||||||
|
|
||||||
Secretive is an app for storing and managing SSH keys in the Secure Enclave. It is inspired by the [sekey project](https://github.com/sekey/sekey), but rewritten in Swift with no external dependencies and with a handy native management app.
|
Secretive is an app for storing and managing SSH keys in the Secure Enclave. It is inspired by the [sekey project](https://github.com/sekey/sekey), but rewritten in Swift with no external dependencies and with a handy native management app.
|
||||||
|
|
||||||
<img src="/.github/readme/app.png" alt="Screenshot of Secretive" width="600">
|
<img src="/.github/readme/app.png" alt="Screenshot of Secretive" width="600">
|
||||||
|
|
||||||
|
|
||||||
## Why?
|
## Why?
|
||||||
|
|
||||||
### Safer Storage
|
### Safer Storage
|
||||||
@ -14,13 +12,13 @@ The most common setup for SSH keys is just keeping them on disk, guarded by prop
|
|||||||
|
|
||||||
### Access Control
|
### Access Control
|
||||||
|
|
||||||
If your Mac has a Secure Enclave, it also has support for strong access controls like Touch ID, or authentication with Apple Watch. You can configure your key so that they require Touch ID (or Watch) authentication before they're accessed.
|
If your Mac has a Secure Enclave, it also has support for strong biometric access controls like Touch ID. You can configure your key so that they require Touch ID (or Watch) authentication before they're accessed.
|
||||||
|
|
||||||
<img src="/.github/readme/touchid.png" alt="Screenshot of Secretive authenticating with Touch ID">
|
<img src="/.github/readme/touchid.png" alt="Screenshot of Secretive authenticating with Touch ID">
|
||||||
|
|
||||||
### Notifications
|
### Notifications
|
||||||
|
|
||||||
Secretive also notifies you whenever your keys are accessed, so you're never caught off guard.
|
Secretive also notifies you whenever your keys are acceessed, so you're never caught off guard.
|
||||||
|
|
||||||
<img src="/.github/readme/notification.png" alt="Screenshot of Secretive notifying the user">
|
<img src="/.github/readme/notification.png" alt="Screenshot of Secretive notifying the user">
|
||||||
|
|
||||||
@ -30,21 +28,15 @@ For Macs without Secure Enclaves, you can configure a Smart Card (such as a Yubi
|
|||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
### Installation
|
### Setup for Third Party Apps
|
||||||
|
|
||||||
#### Direct Download
|
When you first launch Secretive, you'll be prompted to set up your command line environment. You can redisplay this prompt at any time by going to `Menu > Help -> Set Up Helper App`.
|
||||||
|
For non-command-line based apps, like GUI Git clients, you may need to go through app-specific setup.
|
||||||
|
|
||||||
You can download the latest release over on the [Releases Page](https://github.com/maxgoedjen/secretive/releases)
|
[Tower](https://www.git-tower.com/help/mac/integration/environment)
|
||||||
|
|
||||||
#### Using Homebrew
|
|
||||||
|
|
||||||
brew cask install secretive
|
### Security Considerations
|
||||||
|
|
||||||
### FAQ
|
|
||||||
|
|
||||||
There's a [FAQ here](FAQ.md).
|
|
||||||
|
|
||||||
### Auditable Build Process
|
|
||||||
|
|
||||||
Builds are produced by GitHub Actions with an auditable build and release generation process. Each build has a "Document SHAs" step, which will output SHA checksums for the build produced by the GitHub Action, so you can verify that the source code for a given build corresponds to any given release.
|
Builds are produced by GitHub Actions with an auditable build and release generation process. Each build has a "Document SHAs" step, which will output SHA checksums for the build produced by the GitHub Action, so you can verify that the source code for a given build corresponds to any given release.
|
||||||
|
|
||||||
@ -54,8 +46,8 @@ While Secretive uses the Secure Enclave for key storage, it still relies on Keyc
|
|||||||
|
|
||||||
### Backups and Transfers to New Machines
|
### Backups and Transfers to New Machines
|
||||||
|
|
||||||
Because secrets in the Secure Enclave are not exportable, they are not able to be backed up, and you will not be able to transfer them to a new machine. If you get a new Mac, just create a new set of secrets specific to that Mac.
|
Beacuse secrets in the Secure Enclave are not exportable, they are not able to be backed up, and you will not be able to transfer them to a new machine. If you get a new Mac, just create a new set of secrets specific to that Mac.
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
If you discover any vulnerabilities in this project, please notify [max.goedjen@gmail.com](mailto:max.goedjen@gmail.com) with the subject containing "SECRETIVE SECURITY."
|
If you discover any vulnerabilities in this project, please notify max.goedjen@gmail.com
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
# Security Policy
|
|
||||||
|
|
||||||
## Supported Versions
|
|
||||||
|
|
||||||
The latest version on the [Releases page](https://github.com/maxgoedjen/secretive/releases) is the only currently supported version.
|
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
|
||||||
|
|
||||||
If you discover any vulnerabilities in this project, please notify max.goedjen@gmail.com with the subject containing "SECRETIVE SECURITY."
|
|
@ -1,40 +1,36 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
import OSLog
|
|
||||||
import Combine
|
|
||||||
import SecretKit
|
import SecretKit
|
||||||
import SecretAgentKit
|
import SecretAgentKit
|
||||||
import Brief
|
import OSLog
|
||||||
|
|
||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
private let storeList: SecretStoreList = {
|
let storeList: SecretStoreList = {
|
||||||
let list = SecretStoreList()
|
let list = SecretStoreList()
|
||||||
list.add(store: SecureEnclave.Store())
|
list.add(store: SecureEnclave.Store())
|
||||||
list.add(store: SmartCard.Store())
|
list.add(store: SmartCard.Store())
|
||||||
return list
|
return list
|
||||||
}()
|
}()
|
||||||
private let updater = Updater(checkOnLaunch: false)
|
let notifier = Notifier()
|
||||||
private let notifier = Notifier()
|
lazy var agent: Agent = {
|
||||||
private lazy var agent: Agent = {
|
|
||||||
Agent(storeList: storeList, witness: notifier)
|
Agent(storeList: storeList, witness: notifier)
|
||||||
}()
|
}()
|
||||||
private lazy var socketController: SocketController = {
|
lazy var socketController: SocketController = {
|
||||||
let path = (NSHomeDirectory() as NSString).appendingPathComponent("socket.ssh") as String
|
let path = (NSHomeDirectory() as NSString).appendingPathComponent("socket.ssh") as String
|
||||||
return SocketController(path: path)
|
return SocketController(path: path)
|
||||||
}()
|
}()
|
||||||
private var updateSink: AnyCancellable?
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
Logger().debug("SecretAgent finished launching")
|
os_log(.debug, "SecretAgent finished launching")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.socketController.handler = self.agent.handle(reader:writer:)
|
self.socketController.handler = self.agent.handle(fileHandle:)
|
||||||
}
|
}
|
||||||
notifier.prompt()
|
notifier.prompt()
|
||||||
updateSink = updater.$update.sink { update in
|
}
|
||||||
guard let update = update else { return }
|
|
||||||
self.notifier.notify(update: update, ignore: self.updater.ignore(release:))
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
}
|
// Insert code here to tear down your application
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@
|
|||||||
"size" : "128x128"
|
"size" : "128x128"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Mac Icon.png",
|
"filename" : "Icon 2@1x.png",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"scale" : "1x",
|
"scale" : "1x",
|
||||||
"size" : "256x256"
|
"size" : "256x256"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Mac Icon@0.25x.png",
|
"filename" : "Icon 2@2x.png",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"scale" : "2x",
|
"scale" : "2x",
|
||||||
"size" : "256x256"
|
"size" : "256x256"
|
||||||
|
BIN
SecretAgent/Assets.xcassets/AppIcon.appiconset/Icon 2@1x.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
SecretAgent/Assets.xcassets/AppIcon.appiconset/Icon 2@2x.png
Normal file
After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 40 KiB |
@ -25,7 +25,7 @@
|
|||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>$(PRODUCT_NAME) is MIT Licensed.</string>
|
<string>Copyright © 2020 Max Goedjen. All rights reserved.</string>
|
||||||
<key>NSMainStoryboardFile</key>
|
<key>NSMainStoryboardFile</key>
|
||||||
<string>Main</string>
|
<string>Main</string>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
|
@ -1,53 +1,21 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UserNotifications
|
|
||||||
import AppKit
|
|
||||||
import SecretKit
|
import SecretKit
|
||||||
import SecretAgentKit
|
import SecretAgentKit
|
||||||
import Brief
|
import UserNotifications
|
||||||
|
|
||||||
class Notifier {
|
class Notifier {
|
||||||
|
|
||||||
private let notificationDelegate = NotificationDelegate()
|
|
||||||
|
|
||||||
init() {
|
|
||||||
let updateAction = UNNotificationAction(identifier: Constants.updateActionIdentitifier, title: "Update", options: [])
|
|
||||||
let ignoreAction = UNNotificationAction(identifier: Constants.ignoreActionIdentitifier, title: "Ignore", options: [])
|
|
||||||
let updateCategory = UNNotificationCategory(identifier: Constants.updateCategoryIdentitifier, actions: [updateAction, ignoreAction], intentIdentifiers: [], options: [])
|
|
||||||
let criticalUpdateCategory = UNNotificationCategory(identifier: Constants.criticalUpdateCategoryIdentitifier, actions: [updateAction], intentIdentifiers: [], options: [])
|
|
||||||
UNUserNotificationCenter.current().setNotificationCategories([updateCategory, criticalUpdateCategory])
|
|
||||||
UNUserNotificationCenter.current().delegate = notificationDelegate
|
|
||||||
}
|
|
||||||
|
|
||||||
func prompt() {
|
func prompt() {
|
||||||
let notificationCenter = UNUserNotificationCenter.current()
|
let notificationCenter = UNUserNotificationCenter.current()
|
||||||
notificationCenter.requestAuthorization(options: .alert) { _, _ in }
|
notificationCenter.requestAuthorization(options: .alert) { _, _ in
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func notify(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) {
|
func notify(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) {
|
||||||
let notificationCenter = UNUserNotificationCenter.current()
|
let notificationCenter = UNUserNotificationCenter.current()
|
||||||
let notificationContent = UNMutableNotificationContent()
|
let notificationContent = UNMutableNotificationContent()
|
||||||
notificationContent.title = "Signed Request from \(provenance.origin.displayName)"
|
notificationContent.title = "Signed Request"
|
||||||
notificationContent.subtitle = "Using secret \"\(secret.name)\""
|
notificationContent.body = "\(secret.name) was used to sign a request from \(provenance.origin.name)."
|
||||||
if let iconURL = provenance.origin.iconURL, let attachment = try? UNNotificationAttachment(identifier: "icon", url: iconURL, options: nil) {
|
|
||||||
notificationContent.attachments = [attachment]
|
|
||||||
}
|
|
||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
|
|
||||||
notificationCenter.add(request, withCompletionHandler: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func notify(update: Release, ignore: ((Release) -> Void)?) {
|
|
||||||
notificationDelegate.release = update
|
|
||||||
notificationDelegate.ignore = ignore
|
|
||||||
let notificationCenter = UNUserNotificationCenter.current()
|
|
||||||
let notificationContent = UNMutableNotificationContent()
|
|
||||||
if update.critical {
|
|
||||||
notificationContent.title = "Critical Security Update - \(update.name)"
|
|
||||||
} else {
|
|
||||||
notificationContent.title = "Update Available - \(update.name)"
|
|
||||||
}
|
|
||||||
notificationContent.subtitle = "Click to Update"
|
|
||||||
notificationContent.body = update.body
|
|
||||||
notificationContent.categoryIdentifier = update.critical ? Constants.criticalUpdateCategoryIdentitifier : Constants.updateCategoryIdentitifier
|
|
||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
|
||||||
notificationCenter.add(request, withCompletionHandler: nil)
|
notificationCenter.add(request, withCompletionHandler: nil)
|
||||||
}
|
}
|
||||||
@ -56,50 +24,8 @@ class Notifier {
|
|||||||
|
|
||||||
extension Notifier: SigningWitness {
|
extension Notifier: SigningWitness {
|
||||||
|
|
||||||
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
||||||
}
|
|
||||||
|
|
||||||
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
||||||
notify(accessTo: secret, by: provenance)
|
notify(accessTo: secret, by: provenance)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Notifier {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
static let updateCategoryIdentitifier = "com.maxgoedjen.Secretive.SecretAgent.update"
|
|
||||||
static let criticalUpdateCategoryIdentitifier = "com.maxgoedjen.Secretive.SecretAgent.update.critical"
|
|
||||||
static let updateActionIdentitifier = "com.maxgoedjen.Secretive.SecretAgent.update.updateaction"
|
|
||||||
static let ignoreActionIdentitifier = "com.maxgoedjen.Secretive.SecretAgent.update.ignoreaction"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
|
|
||||||
|
|
||||||
fileprivate var release: Release?
|
|
||||||
fileprivate var ignore: ((Release) -> Void)?
|
|
||||||
|
|
||||||
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
||||||
guard let update = release else { return }
|
|
||||||
switch response.actionIdentifier {
|
|
||||||
case Notifier.Constants.updateActionIdentitifier, UNNotificationDefaultActionIdentifier:
|
|
||||||
NSWorkspace.shared.open(update.html_url)
|
|
||||||
case Notifier.Constants.ignoreActionIdentitifier:
|
|
||||||
ignore?(update)
|
|
||||||
default:
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
completionHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
||||||
completionHandler([.list, .banner])
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
<key>com.apple.security.app-sandbox</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.network.client</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.smartcard</key>
|
<key>com.apple.security.smartcard</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>keychain-access-groups</key>
|
<key>keychain-access-groups</key>
|
||||||
|
@ -2,17 +2,18 @@ import Foundation
|
|||||||
import CryptoKit
|
import CryptoKit
|
||||||
import OSLog
|
import OSLog
|
||||||
import SecretKit
|
import SecretKit
|
||||||
|
import SecretAgentKit
|
||||||
import AppKit
|
import AppKit
|
||||||
|
|
||||||
public class Agent {
|
public class Agent {
|
||||||
|
|
||||||
private let storeList: SecretStoreList
|
fileprivate let storeList: SecretStoreList
|
||||||
private let witness: SigningWitness?
|
fileprivate let witness: SigningWitness?
|
||||||
private let writer = OpenSSHKeyWriter()
|
fileprivate let writer = OpenSSHKeyWriter()
|
||||||
private let requestTracer = SigningRequestTracer()
|
fileprivate let requestTracer = SigningRequestTracer()
|
||||||
|
|
||||||
public init(storeList: SecretStoreList, witness: SigningWitness? = nil) {
|
public init(storeList: SecretStoreList, witness: SigningWitness? = nil) {
|
||||||
Logger().debug("Agent is running")
|
os_log(.debug, "Agent is running")
|
||||||
self.storeList = storeList
|
self.storeList = storeList
|
||||||
self.witness = witness
|
self.witness = witness
|
||||||
}
|
}
|
||||||
@ -21,51 +22,47 @@ public class Agent {
|
|||||||
|
|
||||||
extension Agent {
|
extension Agent {
|
||||||
|
|
||||||
public func handle(reader: FileHandleReader, writer: FileHandleWriter) {
|
public func handle(fileHandle: FileHandle) {
|
||||||
Logger().debug("Agent handling new data")
|
os_log(.debug, "Agent handling new data")
|
||||||
let data = reader.availableData
|
let data = fileHandle.availableData
|
||||||
guard !data.isEmpty else { return }
|
guard !data.isEmpty else { return }
|
||||||
let requestTypeInt = data[4]
|
let requestTypeInt = data[4]
|
||||||
guard let requestType = SSHAgent.RequestType(rawValue: requestTypeInt) else {
|
guard let requestType = SSHAgent.RequestType(rawValue: requestTypeInt) else { return }
|
||||||
writer.write(OpenSSHKeyWriter().lengthAndData(of: SSHAgent.ResponseType.agentFailure.data))
|
os_log(.debug, "Agent handling request of type %@", requestType.debugDescription)
|
||||||
Logger().debug("Agent returned \(SSHAgent.ResponseType.agentFailure.debugDescription)")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Logger().debug("Agent handling request of type \(requestType.debugDescription)")
|
|
||||||
let subData = Data(data[5...])
|
let subData = Data(data[5...])
|
||||||
let response = handle(requestType: requestType, data: subData, reader: reader)
|
handle(requestType: requestType, data: subData, fileHandle: fileHandle)
|
||||||
writer.write(response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle(requestType: SSHAgent.RequestType, data: Data, reader: FileHandleReader) -> Data {
|
func handle(requestType: SSHAgent.RequestType, data: Data, fileHandle: FileHandle) {
|
||||||
var response = Data()
|
var response = Data()
|
||||||
do {
|
do {
|
||||||
switch requestType {
|
switch requestType {
|
||||||
case .requestIdentities:
|
case .requestIdentities:
|
||||||
response.append(SSHAgent.ResponseType.agentIdentitiesAnswer.data)
|
response.append(SSHAgent.ResponseType.agentIdentitiesAnswer.data)
|
||||||
response.append(identities())
|
response.append(try identities())
|
||||||
Logger().debug("Agent returned \(SSHAgent.ResponseType.agentIdentitiesAnswer.debugDescription)")
|
os_log(.debug, "Agent returned %@", SSHAgent.ResponseType.agentIdentitiesAnswer.debugDescription)
|
||||||
case .signRequest:
|
case .signRequest:
|
||||||
let provenance = requestTracer.provenance(from: reader)
|
|
||||||
response.append(SSHAgent.ResponseType.agentSignResponse.data)
|
response.append(SSHAgent.ResponseType.agentSignResponse.data)
|
||||||
response.append(try sign(data: data, provenance: provenance))
|
response.append(try sign(data: data, from: fileHandle.fileDescriptor))
|
||||||
Logger().debug("Agent returned \(SSHAgent.ResponseType.agentSignResponse.debugDescription)")
|
os_log(.debug, "Agent returned %@", SSHAgent.ResponseType.agentSignResponse.debugDescription)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
response.removeAll()
|
response.removeAll()
|
||||||
response.append(SSHAgent.ResponseType.agentFailure.data)
|
response.append(SSHAgent.ResponseType.agentFailure.data)
|
||||||
Logger().debug("Agent returned \(SSHAgent.ResponseType.agentFailure.debugDescription)")
|
os_log(.debug, "Agent returned %@", SSHAgent.ResponseType.agentFailure.debugDescription)
|
||||||
}
|
}
|
||||||
let full = OpenSSHKeyWriter().lengthAndData(of: response)
|
let full = OpenSSHKeyWriter().lengthAndData(of: response)
|
||||||
return full
|
fileHandle.write(full)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Agent {
|
extension Agent {
|
||||||
|
|
||||||
func identities() -> Data {
|
func identities() throws -> Data {
|
||||||
let secrets = storeList.stores.flatMap(\.secrets)
|
// TODO: RESTORE ONCE XCODE 11.4 IS GM
|
||||||
|
let secrets = storeList.stores.flatMap { $0.secrets }
|
||||||
|
// let secrets = storeList.stores.flatMap(\.secrets)
|
||||||
var count = UInt32(secrets.count).bigEndian
|
var count = UInt32(secrets.count).bigEndian
|
||||||
let countData = Data(bytes: &count, count: UInt32.bitWidth/8)
|
let countData = Data(bytes: &count, count: UInt32.bitWidth/8)
|
||||||
var keyData = Data()
|
var keyData = Data()
|
||||||
@ -76,24 +73,25 @@ extension Agent {
|
|||||||
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
||||||
keyData.append(writer.lengthAndData(of: curveData))
|
keyData.append(writer.lengthAndData(of: curveData))
|
||||||
}
|
}
|
||||||
Logger().debug("Agent enumerated \(secrets.count) identities")
|
os_log(.debug, "Agent enumerated %@ identities", secrets.count as NSNumber)
|
||||||
return countData + keyData
|
return countData + keyData
|
||||||
}
|
}
|
||||||
|
|
||||||
func sign(data: Data, provenance: SigningRequestProvenance) throws -> Data {
|
func sign(data: Data, from pid: Int32) throws -> Data {
|
||||||
let reader = OpenSSHReader(data: data)
|
let reader = OpenSSHReader(data: data)
|
||||||
let hash = reader.readNextChunk()
|
let hash = try reader.readNextChunk()
|
||||||
guard let (store, secret) = secret(matching: hash) else {
|
guard let (store, secret) = secret(matching: hash) else {
|
||||||
Logger().debug("Agent did not have a key matching \(hash as NSData)")
|
os_log(.debug, "Agent did not have a key matching %@", hash as NSData)
|
||||||
throw AgentError.noMatchingKey
|
throw AgentError.noMatchingKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let provenance = requestTracer.provenance(from: pid)
|
||||||
if let witness = witness {
|
if let witness = witness {
|
||||||
try witness.speakNowOrForeverHoldYourPeace(forAccessTo: secret, by: provenance)
|
try witness.witness(accessTo: secret, by: provenance)
|
||||||
}
|
}
|
||||||
|
|
||||||
let dataToSign = reader.readNextChunk()
|
let dataToSign = try reader.readNextChunk()
|
||||||
let derSignature = try store.sign(data: dataToSign, with: secret, for: provenance)
|
let derSignature = try store.sign(data: dataToSign, with: secret)
|
||||||
|
|
||||||
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
||||||
|
|
||||||
@ -106,22 +104,13 @@ extension Agent {
|
|||||||
case (.ellipticCurve, 384):
|
case (.ellipticCurve, 384):
|
||||||
rawRepresentation = try CryptoKit.P384.Signing.ECDSASignature(derRepresentation: derSignature).rawRepresentation
|
rawRepresentation = try CryptoKit.P384.Signing.ECDSASignature(derRepresentation: derSignature).rawRepresentation
|
||||||
default:
|
default:
|
||||||
throw AgentError.unsupportedKeyType
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let rawLength = rawRepresentation.count/2
|
let rawLength = rawRepresentation.count/2
|
||||||
// Check if we need to pad with 0x00 to prevent certain
|
let r = rawRepresentation[0..<rawLength]
|
||||||
// ssh servers from thinking r or s is negative
|
let s = rawRepresentation[rawLength...]
|
||||||
let paddingRange: ClosedRange<UInt8> = 0x80...0xFF
|
|
||||||
var r = Data(rawRepresentation[0..<rawLength])
|
|
||||||
if paddingRange ~= r.first! {
|
|
||||||
r.insert(0x00, at: 0)
|
|
||||||
}
|
|
||||||
var s = Data(rawRepresentation[rawLength...])
|
|
||||||
if paddingRange ~= s.first! {
|
|
||||||
s.insert(0x00, at: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
var signatureChunk = Data()
|
var signatureChunk = Data()
|
||||||
signatureChunk.append(writer.lengthAndData(of: r))
|
signatureChunk.append(writer.lengthAndData(of: r))
|
||||||
@ -133,11 +122,7 @@ extension Agent {
|
|||||||
sub.append(writer.lengthAndData(of: signatureChunk))
|
sub.append(writer.lengthAndData(of: signatureChunk))
|
||||||
signedData.append(writer.lengthAndData(of: sub))
|
signedData.append(writer.lengthAndData(of: sub))
|
||||||
|
|
||||||
if let witness = witness {
|
os_log(.debug, "Agent signed request")
|
||||||
try witness.witness(accessTo: secret, by: provenance)
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger().debug("Agent signed request")
|
|
||||||
|
|
||||||
return signedData
|
return signedData
|
||||||
}
|
}
|
||||||
@ -166,7 +151,6 @@ extension Agent {
|
|||||||
enum AgentError: Error {
|
enum AgentError: Error {
|
||||||
case unhandledType
|
case unhandledType
|
||||||
case noMatchingKey
|
case noMatchingKey
|
||||||
case unsupportedKeyType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
public protocol FileHandleReader {
|
|
||||||
|
|
||||||
var availableData: Data { get }
|
|
||||||
var fileDescriptor: Int32 { get }
|
|
||||||
var pidOfConnectedProcess: Int32 { get }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public protocol FileHandleWriter {
|
|
||||||
|
|
||||||
func write(_ data: Data)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension FileHandle: FileHandleReader, FileHandleWriter {
|
|
||||||
|
|
||||||
public var pidOfConnectedProcess: Int32 {
|
|
||||||
let pidPointer = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 1)
|
|
||||||
var len = socklen_t(MemoryLayout<Int32>.size)
|
|
||||||
getsockopt(fileDescriptor, SOCK_STREAM, LOCAL_PEERPID, pidPointer, &len)
|
|
||||||
return pidPointer.load(as: Int32.self)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -19,6 +19,6 @@
|
|||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>$(PRODUCT_NAME) is MIT Licensed.</string>
|
<string>Copyright © 2020 Max Goedjen. All rights reserved.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -12,7 +12,7 @@ extension SSHAgent {
|
|||||||
switch self {
|
switch self {
|
||||||
case .requestIdentities:
|
case .requestIdentities:
|
||||||
return "RequestIdentities"
|
return "RequestIdentities"
|
||||||
case .signRequest:
|
default:
|
||||||
return "SignRequest"
|
return "SignRequest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
|
//
|
||||||
|
// SecretAgentKit.h
|
||||||
|
// SecretAgentKit
|
||||||
|
//
|
||||||
|
// Created by Max Goedjen on 2/22/20.
|
||||||
|
// Copyright © 2020 Max Goedjen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <Security/Security.h>
|
|
||||||
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
|
|
||||||
// from libproc.h
|
|
||||||
int proc_pidpath(int pid, void * buffer, uint32_t buffersize);
|
|
||||||
|
|
||||||
// from SecTask.h
|
|
||||||
OSStatus SecCodeCreateWithPID(int32_t, SecCSFlags, SecCodeRef *);
|
|
||||||
|
|
||||||
//! Project version number for SecretAgentKit.
|
//! Project version number for SecretAgentKit.
|
||||||
FOUNDATION_EXPORT double SecretAgentKitVersionNumber;
|
FOUNDATION_EXPORT double SecretAgentKitVersionNumber;
|
||||||
@ -16,4 +14,6 @@ FOUNDATION_EXPORT double SecretAgentKitVersionNumber;
|
|||||||
//! Project version string for SecretAgentKit.
|
//! Project version string for SecretAgentKit.
|
||||||
FOUNDATION_EXPORT const unsigned char SecretAgentKitVersionString[];
|
FOUNDATION_EXPORT const unsigned char SecretAgentKitVersionString[];
|
||||||
|
|
||||||
|
// In this header, you should import all the public headers of your framework using statements like #import <SecretAgentKit/PublicHeader.h>
|
||||||
|
|
||||||
|
|
||||||
|
39
SecretAgentKit/SigningRequestProvenance.swift
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import Foundation
|
||||||
|
import AppKit
|
||||||
|
|
||||||
|
public struct SigningRequestProvenance {
|
||||||
|
|
||||||
|
public var chain: [Process]
|
||||||
|
public init(root: Process) {
|
||||||
|
self.chain = [root]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension SigningRequestProvenance {
|
||||||
|
|
||||||
|
public var origin: Process {
|
||||||
|
chain.last!
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension SigningRequestProvenance {
|
||||||
|
|
||||||
|
public struct Process {
|
||||||
|
|
||||||
|
public let pid: Int32
|
||||||
|
public let name: String
|
||||||
|
public let path: String
|
||||||
|
let parentPID: Int32?
|
||||||
|
|
||||||
|
init(pid: Int32, name: String, path: String, parentPID: Int32?) {
|
||||||
|
self.pid = pid
|
||||||
|
self.name = name
|
||||||
|
self.path = path
|
||||||
|
self.parentPID = parentPID
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,14 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import AppKit
|
import AppKit
|
||||||
import Security
|
|
||||||
import SecretKit
|
|
||||||
|
|
||||||
struct SigningRequestTracer {
|
struct SigningRequestTracer {
|
||||||
}
|
|
||||||
|
|
||||||
extension SigningRequestTracer {
|
func provenance(from pid: Int32) -> SigningRequestProvenance {
|
||||||
|
let pidPointer = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 1)
|
||||||
func provenance(from fileHandleReader: FileHandleReader) -> SigningRequestProvenance {
|
var len = socklen_t(MemoryLayout<Int32>.size)
|
||||||
let firstInfo = process(from: fileHandleReader.pidOfConnectedProcess)
|
getsockopt(pid, SOCK_STREAM, LOCAL_PEERPID, pidPointer, &len)
|
||||||
|
let pid = pidPointer.load(as: Int32.self)
|
||||||
|
let firstInfo = process(from: pid)
|
||||||
|
|
||||||
var provenance = SigningRequestProvenance(root: firstInfo)
|
var provenance = SigningRequestProvenance(root: firstInfo)
|
||||||
while NSRunningApplication(processIdentifier: provenance.origin.pid) == nil && provenance.origin.parentPID != nil {
|
while NSRunningApplication(processIdentifier: provenance.origin.pid) == nil && provenance.origin.parentPID != nil {
|
||||||
@ -30,31 +29,7 @@ extension SigningRequestTracer {
|
|||||||
var pidAndNameInfo = self.pidAndNameInfo(from: pid)
|
var pidAndNameInfo = self.pidAndNameInfo(from: pid)
|
||||||
let ppid = pidAndNameInfo.kp_eproc.e_ppid != 0 ? pidAndNameInfo.kp_eproc.e_ppid : nil
|
let ppid = pidAndNameInfo.kp_eproc.e_ppid != 0 ? pidAndNameInfo.kp_eproc.e_ppid : nil
|
||||||
let procName = String(cString: &pidAndNameInfo.kp_proc.p_comm.0)
|
let procName = String(cString: &pidAndNameInfo.kp_proc.p_comm.0)
|
||||||
let pathPointer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(MAXPATHLEN))
|
return SigningRequestProvenance.Process(pid: pid, name: procName, path: "", parentPID: ppid)
|
||||||
_ = proc_pidpath(pid, pathPointer, UInt32(MAXPATHLEN))
|
|
||||||
let path = String(cString: pathPointer)
|
|
||||||
var secCode: Unmanaged<SecCode>!
|
|
||||||
let flags: SecCSFlags = [.considerExpiration, .enforceRevocationChecks]
|
|
||||||
SecCodeCreateWithPID(pid, SecCSFlags(), &secCode)
|
|
||||||
let valid = SecCodeCheckValidity(secCode.takeRetainedValue(), flags, nil) == errSecSuccess
|
|
||||||
return SigningRequestProvenance.Process(pid: pid, processName: procName, appName: appName(for: pid), iconURL: iconURL(for: pid), path: path, validSignature: valid, parentPID: ppid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func iconURL(for pid: Int32) -> URL? {
|
|
||||||
do {
|
|
||||||
if let app = NSRunningApplication(processIdentifier: pid), let icon = app.icon?.tiffRepresentation {
|
|
||||||
let temporaryURL = URL(fileURLWithPath: (NSTemporaryDirectory() as NSString).appendingPathComponent("\(UUID().uuidString).png"))
|
|
||||||
let bitmap = NSBitmapImageRep(data: icon)
|
|
||||||
try bitmap?.representation(using: .png, properties: [:])?.write(to: temporaryURL)
|
|
||||||
return temporaryURL
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func appName(for pid: Int32) -> String? {
|
|
||||||
NSRunningApplication(processIdentifier: pid)?.localizedName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import SecretKit
|
|||||||
|
|
||||||
public protocol SigningWitness {
|
public protocol SigningWitness {
|
||||||
|
|
||||||
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws
|
|
||||||
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws
|
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,21 @@ import OSLog
|
|||||||
|
|
||||||
public class SocketController {
|
public class SocketController {
|
||||||
|
|
||||||
private var fileHandle: FileHandle?
|
fileprivate var fileHandle: FileHandle?
|
||||||
private var port: SocketPort?
|
fileprivate var port: SocketPort?
|
||||||
public var handler: ((FileHandleReader, FileHandleWriter) -> Void)?
|
public var handler: ((FileHandle) -> Void)?
|
||||||
|
|
||||||
public init(path: String) {
|
public init(path: String) {
|
||||||
Logger().debug("Socket controller setting up at \(path)")
|
os_log(.debug, "Socket controller setting up at %@", path)
|
||||||
if let _ = try? FileManager.default.removeItem(atPath: path) {
|
if let _ = try? FileManager.default.removeItem(atPath: path) {
|
||||||
Logger().debug("Socket controller removed existing socket")
|
os_log(.debug, "Socket controller removed existing socket")
|
||||||
}
|
}
|
||||||
let exists = FileManager.default.fileExists(atPath: path)
|
let exists = FileManager.default.fileExists(atPath: path)
|
||||||
assert(!exists)
|
assert(!exists)
|
||||||
Logger().debug("Socket controller path is clear")
|
os_log(.debug, "Socket controller path is clear")
|
||||||
port = socketPort(at: path)
|
port = socketPort(at: path)
|
||||||
configureSocket(at: path)
|
configureSocket(at: path)
|
||||||
Logger().debug("Socket listening at \(path)")
|
os_log(.debug, "Socket listening at %@", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureSocket(at path: String) {
|
func configureSocket(at path: String) {
|
||||||
@ -33,7 +33,7 @@ public class SocketController {
|
|||||||
addr.sun_family = sa_family_t(AF_UNIX)
|
addr.sun_family = sa_family_t(AF_UNIX)
|
||||||
|
|
||||||
var len: Int = 0
|
var len: Int = 0
|
||||||
withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in
|
_ = withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in
|
||||||
path.withCString { cstring in
|
path.withCString { cstring in
|
||||||
len = strlen(cstring)
|
len = strlen(cstring)
|
||||||
strncpy(pointer, cstring, len)
|
strncpy(pointer, cstring, len)
|
||||||
@ -42,7 +42,7 @@ public class SocketController {
|
|||||||
addr.sun_len = UInt8(len+2)
|
addr.sun_len = UInt8(len+2)
|
||||||
|
|
||||||
var data: Data!
|
var data: Data!
|
||||||
withUnsafePointer(to: &addr) { pointer in
|
_ = withUnsafePointer(to: &addr) { pointer in
|
||||||
data = Data(bytes: pointer, count: MemoryLayout<sockaddr_un>.size)
|
data = Data(bytes: pointer, count: MemoryLayout<sockaddr_un>.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,18 +50,18 @@ public class SocketController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleConnectionAccept(notification: Notification) {
|
@objc func handleConnectionAccept(notification: Notification) {
|
||||||
Logger().debug("Socket controller accepted connection")
|
os_log(.debug, "Socket controller accepted connection")
|
||||||
guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else { return }
|
guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else { return }
|
||||||
handler?(new, new)
|
handler?(new)
|
||||||
new.waitForDataInBackgroundAndNotify()
|
new.waitForDataInBackgroundAndNotify()
|
||||||
fileHandle?.acceptConnectionInBackgroundAndNotify(forModes: [RunLoop.current.currentMode!])
|
fileHandle?.acceptConnectionInBackgroundAndNotify(forModes: [RunLoop.current.currentMode!])
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleConnectionDataAvailable(notification: Notification) {
|
@objc func handleConnectionDataAvailable(notification: Notification) {
|
||||||
Logger().debug("Socket controller has new data available")
|
os_log(.debug, "Socket controller has new data available")
|
||||||
guard let new = notification.object as? FileHandle else { return }
|
guard let new = notification.object as? FileHandle else { return }
|
||||||
Logger().debug("Socket controller received new file handle")
|
os_log(.debug, "Socket controller received new file handle")
|
||||||
handler?(new, new)
|
handler?(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,169 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import XCTest
|
|
||||||
import CryptoKit
|
|
||||||
@testable import SecretKit
|
|
||||||
@testable import SecretAgentKit
|
|
||||||
|
|
||||||
class AgentTests: XCTestCase {
|
|
||||||
|
|
||||||
let stubWriter = StubFileHandleWriter()
|
|
||||||
|
|
||||||
// MARK: Identity Listing
|
|
||||||
|
|
||||||
func testEmptyStores() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestIdentities)
|
|
||||||
let agent = Agent(storeList: SecretStoreList())
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertEqual(stubWriter.data, Constants.Responses.requestIdentitiesEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testIdentitiesList() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestIdentities)
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
|
|
||||||
let agent = Agent(storeList: list)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertEqual(stubWriter.data, Constants.Responses.requestIdentitiesMultiple)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Signatures
|
|
||||||
|
|
||||||
func testNoMatchingIdentities() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignatureWithNoneMatching)
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
|
|
||||||
let agent = Agent(storeList: list)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
// XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testSignature() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
|
||||||
let requestReader = OpenSSHReader(data: Constants.Requests.requestSignature[5...])
|
|
||||||
_ = requestReader.readNextChunk()
|
|
||||||
let dataToSign = requestReader.readNextChunk()
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
|
|
||||||
let agent = Agent(storeList: list)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
let outer = OpenSSHReader(data: stubWriter.data[5...])
|
|
||||||
let payload = outer.readNextChunk()
|
|
||||||
let inner = OpenSSHReader(data: payload)
|
|
||||||
_ = inner.readNextChunk()
|
|
||||||
let signedData = inner.readNextChunk()
|
|
||||||
let rsData = OpenSSHReader(data: signedData)
|
|
||||||
var r = rsData.readNextChunk()
|
|
||||||
var s = rsData.readNextChunk()
|
|
||||||
// This is fine IRL, but it freaks out CryptoKit
|
|
||||||
if r[0] == 0 {
|
|
||||||
r.removeFirst()
|
|
||||||
}
|
|
||||||
if s[0] == 0 {
|
|
||||||
s.removeFirst()
|
|
||||||
}
|
|
||||||
var rs = r
|
|
||||||
rs.append(s)
|
|
||||||
let signature = try! P256.Signing.ECDSASignature(rawRepresentation: rs)
|
|
||||||
let valid = try! P256.Signing.PublicKey(x963Representation: Constants.Secrets.ecdsa256Secret.publicKey).isValidSignature(signature, for: dataToSign)
|
|
||||||
XCTAssertTrue(valid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Witness protocol
|
|
||||||
|
|
||||||
func testWitnessObjectionStopsRequest() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
|
||||||
let witness = StubWitness(speakNow: { _,_ in
|
|
||||||
return true
|
|
||||||
}, witness: { _, _ in })
|
|
||||||
let agent = Agent(storeList: list, witness: witness)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testWitnessSignature() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
|
||||||
var witnessed = false
|
|
||||||
let witness = StubWitness(speakNow: { _, trace in
|
|
||||||
return false
|
|
||||||
}, witness: { _, trace in
|
|
||||||
witnessed = true
|
|
||||||
})
|
|
||||||
let agent = Agent(storeList: list, witness: witness)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertTrue(witnessed)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testRequestTracing() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
|
||||||
var speakNowTrace: SigningRequestProvenance! = nil
|
|
||||||
var witnessTrace: SigningRequestProvenance! = nil
|
|
||||||
let witness = StubWitness(speakNow: { _, trace in
|
|
||||||
speakNowTrace = trace
|
|
||||||
return false
|
|
||||||
}, witness: { _, trace in
|
|
||||||
witnessTrace = trace
|
|
||||||
})
|
|
||||||
let agent = Agent(storeList: list, witness: witness)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertEqual(witnessTrace, speakNowTrace)
|
|
||||||
XCTAssertEqual(witnessTrace.origin.displayName, "Finder")
|
|
||||||
XCTAssertEqual(witnessTrace.origin.validSignature, true)
|
|
||||||
XCTAssertEqual(witnessTrace.origin.parentPID, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Exception Handling
|
|
||||||
|
|
||||||
func testSignatureException() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret, Constants.Secrets.ecdsa384Secret])
|
|
||||||
let store = list.stores.first?.base as! Stub.Store
|
|
||||||
store.shouldThrow = true
|
|
||||||
let agent = Agent(storeList: list)
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Unsupported
|
|
||||||
|
|
||||||
func testUnhandledAdd() {
|
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.addIdentity)
|
|
||||||
let agent = Agent(storeList: SecretStoreList())
|
|
||||||
agent.handle(reader: stubReader, writer: stubWriter)
|
|
||||||
XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension AgentTests {
|
|
||||||
|
|
||||||
func storeList(with secrets: [Stub.Secret]) -> SecretStoreList {
|
|
||||||
let store = Stub.Store()
|
|
||||||
store.secrets.append(contentsOf: secrets)
|
|
||||||
let storeList = SecretStoreList()
|
|
||||||
storeList.add(store: store)
|
|
||||||
return storeList
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
|
|
||||||
enum Requests {
|
|
||||||
static let requestIdentities = Data(base64Encoded: "AAAAAQs=")!
|
|
||||||
static let addIdentity = Data(base64Encoded: "AAAAARE=")!
|
|
||||||
static let requestSignatureWithNoneMatching = Data(base64Encoded: "AAABhA0AAACIAAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBEqCbkJbOHy5S1wVCaJoKPmpS0egM4frMqllgnlRRQ/Uvnn6EVS8oV03cPA2Bz0EdESyRKA/sbmn0aBtgjIwGELxu45UXEW1TEz6TxyS0u3vuIqR3Wo1CrQWRDnkrG/pBQAAAO8AAAAgbqmrqPUtJ8mmrtaSVexjMYyXWNqjHSnoto7zgv86xvcyAAAAA2dpdAAAAA5zc2gtY29ubmVjdGlvbgAAAAlwdWJsaWNrZXkBAAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAACIAAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBEqCbkJbOHy5S1wVCaJoKPmpS0egM4frMqllgnlRRQ/Uvnn6EVS8oV03cPA2Bz0EdESyRKA/sbmn0aBtgjIwGELxu45UXEW1TEz6TxyS0u3vuIqR3Wo1CrQWRDnkrG/pBQAAAAA=")!
|
|
||||||
static let requestSignature = Data(base64Encoded: "AAABRA0AAABoAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzOkUiVJEcACMtAd9X7xalbc0FYZyhbmv2dsWl4IP2GWIi+RcsaHQNw+nAIQ8CKEYmLnl0VLDp5Ef8KMhgIy08AAADPAAAAIBIFsbCZ4/dhBmLNGHm0GKj7EJ4N8k/jXRxlyg+LFIYzMgAAAANnaXQAAAAOc3NoLWNvbm5lY3Rpb24AAAAJcHVibGlja2V5AQAAABNlY2RzYS1zaGEyLW5pc3RwMjU2AAAAaAAAABNlY2RzYS1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQSszpFIlSRHAAjLQHfV+8WpW3NBWGcoW5r9nbFpeCD9hliIvkXLGh0DcPpwCEPAihGJi55dFSw6eRH/CjIYCMtPAAAAAA==")!
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Responses {
|
|
||||||
static let requestIdentitiesEmpty = Data(base64Encoded: "AAAABQwAAAAA")!
|
|
||||||
static let requestIdentitiesMultiple = Data(base64Encoded: "AAABKwwAAAACAAAAaAAAABNlY2RzYS1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQSszpFIlSRHAAjLQHfV+8WpW3NBWGcoW5r9nbFpeCD9hliIvkXLGh0DcPpwCEPAihGJi55dFSw6eRH/CjIYCMtPAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAACIAAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBLKSzA5q3jCb3q0JKigvcxfWVGrJ+bklpG0Zc9YzUwrbsh9SipvlSJi+sHQI+O0m88DOpRBAtuAHX60euD/Yv250tovN7/+MEFbXGZ/hLdd0BoFpWbLfJcQj806KJGlcDAAAABNlY2RzYS1zaGEyLW5pc3RwMzg0")!
|
|
||||||
static let requestFailure = Data(base64Encoded: "AAAAAQU=")!
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Secrets {
|
|
||||||
static let ecdsa256Secret = Stub.Secret(keySize: 256, publicKey: Data(base64Encoded: "BKzOkUiVJEcACMtAd9X7xalbc0FYZyhbmv2dsWl4IP2GWIi+RcsaHQNw+nAIQ8CKEYmLnl0VLDp5Ef8KMhgIy08=")!, privateKey: Data(base64Encoded: "BKzOkUiVJEcACMtAd9X7xalbc0FYZyhbmv2dsWl4IP2GWIi+RcsaHQNw+nAIQ8CKEYmLnl0VLDp5Ef8KMhgIy09nw780wy/TSfUmzj15iJkV234AaCLNl+H8qFL6qK8VIg==")!)
|
|
||||||
static let ecdsa384Secret = Stub.Secret(keySize: 384, publicKey: Data(base64Encoded: "BLKSzA5q3jCb3q0JKigvcxfWVGrJ+bklpG0Zc9YzUwrbsh9SipvlSJi+sHQI+O0m88DOpRBAtuAHX60euD/Yv250tovN7/+MEFbXGZ/hLdd0BoFpWbLfJcQj806KJGlcDA==")!, privateKey: Data(base64Encoded: "BLKSzA5q3jCb3q0JKigvcxfWVGrJ+bklpG0Zc9YzUwrbsh9SipvlSJi+sHQI+O0m88DOpRBAtuAHX60euD/Yv250tovN7/+MEFbXGZ/hLdd0BoFpWbLfJcQj806KJGlcDHNapAOzrt9E+9QC4/KYoXS7Uw4pmdAz53uIj02tttiq3c0ZyIQ7XoscWWRqRrz8Kw==")!)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
19
SecretAgentKitTests/SecretAgentKitTests.swift
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// SecretAgentKitTests.swift
|
||||||
|
// SecretAgentKitTests
|
||||||
|
//
|
||||||
|
// Created by Max Goedjen on 2/22/20.
|
||||||
|
// Copyright © 2020 Max Goedjen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import XCTest
|
||||||
|
@testable import SecretAgentKit
|
||||||
|
|
||||||
|
class SecretAgentKitTests: XCTestCase {
|
||||||
|
|
||||||
|
func testExample() throws {
|
||||||
|
// This is an example of a functional test case.
|
||||||
|
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
import SecretAgentKit
|
|
||||||
import AppKit
|
|
||||||
|
|
||||||
struct StubFileHandleReader: FileHandleReader {
|
|
||||||
|
|
||||||
let availableData: Data
|
|
||||||
var fileDescriptor: Int32 {
|
|
||||||
NSWorkspace.shared.runningApplications.filter({ $0.localizedName == "Finder" }).first!.processIdentifier
|
|
||||||
}
|
|
||||||
var pidOfConnectedProcess: Int32 {
|
|
||||||
fileDescriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import SecretAgentKit
|
|
||||||
|
|
||||||
class StubFileHandleWriter: FileHandleWriter {
|
|
||||||
|
|
||||||
var data = Data()
|
|
||||||
|
|
||||||
func write(_ data: Data) {
|
|
||||||
self.data.append(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
import SecretKit
|
|
||||||
import CryptoKit
|
|
||||||
|
|
||||||
struct Stub {}
|
|
||||||
|
|
||||||
extension Stub {
|
|
||||||
|
|
||||||
public class Store: SecretStore {
|
|
||||||
|
|
||||||
public let isAvailable = true
|
|
||||||
public let id = UUID()
|
|
||||||
public let name = "Stub"
|
|
||||||
public var secrets: [Secret] = []
|
|
||||||
public var shouldThrow = false
|
|
||||||
|
|
||||||
public init() {
|
|
||||||
// try! create(size: 256)
|
|
||||||
// try! create(size: 384)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func create(size: Int) throws {
|
|
||||||
let flags: SecAccessControlCreateFlags = []
|
|
||||||
let access =
|
|
||||||
SecAccessControlCreateWithFlags(kCFAllocatorDefault,
|
|
||||||
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
|
||||||
flags,
|
|
||||||
nil) as Any
|
|
||||||
|
|
||||||
let attributes = [
|
|
||||||
kSecAttrLabel: name,
|
|
||||||
kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
|
|
||||||
kSecAttrKeySizeInBits: size,
|
|
||||||
kSecPrivateKeyAttrs: [
|
|
||||||
kSecAttrIsPermanent: true,
|
|
||||||
kSecAttrAccessControl: access
|
|
||||||
]
|
|
||||||
] as CFDictionary
|
|
||||||
|
|
||||||
var privateKey: SecKey! = nil
|
|
||||||
var publicKey: SecKey! = nil
|
|
||||||
SecKeyGeneratePair(attributes, &publicKey, &privateKey)
|
|
||||||
let publicAttributes = SecKeyCopyAttributes(publicKey) as! [CFString: Any]
|
|
||||||
let privateAttributes = SecKeyCopyAttributes(privateKey) as! [CFString: Any]
|
|
||||||
let publicData = (publicAttributes[kSecValueData] as! Data)
|
|
||||||
let privateData = (privateAttributes[kSecValueData] as! Data)
|
|
||||||
let secret = Secret(keySize: size, publicKey: publicData, privateKey: privateData)
|
|
||||||
print(secret)
|
|
||||||
print("Public Key OpenSSH: \(OpenSSHKeyWriter().openSSHString(secret: secret))")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance) throws -> Data {
|
|
||||||
guard !shouldThrow else {
|
|
||||||
throw NSError()
|
|
||||||
}
|
|
||||||
let privateKey = SecKeyCreateWithData(secret.privateKey as CFData, [
|
|
||||||
kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
|
|
||||||
kSecAttrKeySizeInBits: secret.keySize,
|
|
||||||
kSecAttrKeyClass: kSecAttrKeyClassPrivate
|
|
||||||
] as CFDictionary
|
|
||||||
, nil)!
|
|
||||||
let signatureAlgorithm: SecKeyAlgorithm
|
|
||||||
switch secret.keySize {
|
|
||||||
case 256:
|
|
||||||
signatureAlgorithm = .ecdsaSignatureMessageX962SHA256
|
|
||||||
case 384:
|
|
||||||
signatureAlgorithm = .ecdsaSignatureMessageX962SHA384
|
|
||||||
default:
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
return SecKeyCreateSignature(privateKey, signatureAlgorithm, data as CFData, nil)! as Data
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Stub {
|
|
||||||
|
|
||||||
struct Secret: SecretKit.Secret, CustomDebugStringConvertible {
|
|
||||||
|
|
||||||
let id = UUID().uuidString.data(using: .utf8)!
|
|
||||||
let name = UUID().uuidString
|
|
||||||
let algorithm = Algorithm.ellipticCurve
|
|
||||||
|
|
||||||
let keySize: Int
|
|
||||||
let publicKey: Data
|
|
||||||
let privateKey: Data
|
|
||||||
|
|
||||||
init(keySize: Int, publicKey: Data, privateKey: Data) {
|
|
||||||
self.keySize = keySize
|
|
||||||
self.publicKey = publicKey
|
|
||||||
self.privateKey = privateKey
|
|
||||||
}
|
|
||||||
|
|
||||||
var debugDescription: String {
|
|
||||||
"""
|
|
||||||
Key Size \(keySize)
|
|
||||||
Private: \(privateKey.base64EncodedString())
|
|
||||||
Public: \(publicKey.base64EncodedString())
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extension Stub.Store {
|
|
||||||
|
|
||||||
struct StubError: Error {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
import SecretKit
|
|
||||||
import SecretAgentKit
|
|
||||||
|
|
||||||
struct StubWitness {
|
|
||||||
|
|
||||||
let speakNow: (AnySecret, SigningRequestProvenance) -> Bool
|
|
||||||
let witness: (AnySecret, SigningRequestProvenance) -> ()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension StubWitness: SigningWitness {
|
|
||||||
|
|
||||||
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
||||||
let objection = speakNow(secret, provenance)
|
|
||||||
if objection {
|
|
||||||
throw TheresMyChance()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
||||||
witness(secret, provenance)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension StubWitness {
|
|
||||||
|
|
||||||
struct TheresMyChance: Error {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -3,12 +3,12 @@ import Foundation
|
|||||||
public struct AnySecret: Secret {
|
public struct AnySecret: Secret {
|
||||||
|
|
||||||
let base: Any
|
let base: Any
|
||||||
private let hashable: AnyHashable
|
fileprivate let hashable: AnyHashable
|
||||||
private let _id: () -> AnyHashable
|
fileprivate let _id: () -> AnyHashable
|
||||||
private let _name: () -> String
|
fileprivate let _name: () -> String
|
||||||
private let _algorithm: () -> Algorithm
|
fileprivate let _algorithm: () -> Algorithm
|
||||||
private let _keySize: () -> Int
|
fileprivate let _keySize: () -> Int
|
||||||
private let _publicKey: () -> Data
|
fileprivate let _publicKey: () -> Data
|
||||||
|
|
||||||
public init<T>(_ secret: T) where T: Secret {
|
public init<T>(_ secret: T) where T: Secret {
|
||||||
if let secret = secret as? AnySecret {
|
if let secret = secret as? AnySecret {
|
||||||
|
@ -4,12 +4,12 @@ import Combine
|
|||||||
public class AnySecretStore: SecretStore {
|
public class AnySecretStore: SecretStore {
|
||||||
|
|
||||||
let base: Any
|
let base: Any
|
||||||
private let _isAvailable: () -> Bool
|
fileprivate let _isAvailable: () -> Bool
|
||||||
private let _id: () -> UUID
|
fileprivate let _id: () -> UUID
|
||||||
private let _name: () -> String
|
fileprivate let _name: () -> String
|
||||||
private let _secrets: () -> [AnySecret]
|
fileprivate let _secrets: () -> [AnySecret]
|
||||||
private let _sign: (Data, AnySecret, SigningRequestProvenance) throws -> Data
|
fileprivate let _sign: (Data, AnySecret) throws -> Data
|
||||||
private var sink: AnyCancellable?
|
fileprivate var sink: AnyCancellable?
|
||||||
|
|
||||||
public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStore {
|
public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStore {
|
||||||
base = secretStore
|
base = secretStore
|
||||||
@ -17,7 +17,7 @@ public class AnySecretStore: SecretStore {
|
|||||||
_name = { secretStore.name }
|
_name = { secretStore.name }
|
||||||
_id = { secretStore.id }
|
_id = { secretStore.id }
|
||||||
_secrets = { secretStore.secrets.map { AnySecret($0) } }
|
_secrets = { secretStore.secrets.map { AnySecret($0) } }
|
||||||
_sign = { try secretStore.sign(data: $0, with: $1.base as! SecretStoreType.SecretType, for: $2) }
|
_sign = { try secretStore.sign(data: $0, with: $1.base as! SecretStoreType.SecretType) }
|
||||||
sink = secretStore.objectWillChange.sink { _ in
|
sink = secretStore.objectWillChange.sink { _ in
|
||||||
self.objectWillChange.send()
|
self.objectWillChange.send()
|
||||||
}
|
}
|
||||||
@ -39,16 +39,16 @@ public class AnySecretStore: SecretStore {
|
|||||||
return _secrets()
|
return _secrets()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sign(data: Data, with secret: AnySecret, for provenance: SigningRequestProvenance) throws -> Data {
|
public func sign(data: Data, with secret: AnySecret) throws -> Data {
|
||||||
try _sign(data, secret, provenance)
|
try _sign(data, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable {
|
public class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable {
|
||||||
|
|
||||||
private let _create: (String, Bool) throws -> Void
|
fileprivate let _create: (String, Bool) throws -> Void
|
||||||
private let _delete: (AnySecret) throws -> Void
|
fileprivate let _delete: (AnySecret) throws -> Void
|
||||||
|
|
||||||
public init<SecretStoreType>(modifiable secretStore: SecretStoreType) where SecretStoreType: SecretStoreModifiable {
|
public init<SecretStoreType>(modifiable secretStore: SecretStoreType) where SecretStoreType: SecretStoreModifiable {
|
||||||
_create = { try secretStore.create(name: $0, requiresAuthentication: $1) }
|
_create = { try secretStore.create(name: $0, requiresAuthentication: $1) }
|
||||||
|
@ -8,7 +8,7 @@ public class OpenSSHReader {
|
|||||||
remaining = Data(data)
|
remaining = Data(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func readNextChunk() -> Data {
|
public func readNextChunk() throws -> Data {
|
||||||
let lengthRange = 0..<(UInt32.bitWidth/8)
|
let lengthRange = 0..<(UInt32.bitWidth/8)
|
||||||
let lengthChunk = remaining[lengthRange]
|
let lengthChunk = remaining[lengthRange]
|
||||||
remaining.removeSubrange(lengthRange)
|
remaining.removeSubrange(lengthRange)
|
||||||
|
@ -5,7 +5,7 @@ public class SecretStoreList: ObservableObject {
|
|||||||
|
|
||||||
@Published public var stores: [AnySecretStore] = []
|
@Published public var stores: [AnySecretStore] = []
|
||||||
@Published public var modifiableStore: AnySecretStoreModifiable?
|
@Published public var modifiableStore: AnySecretStoreModifiable?
|
||||||
private var sinks: [AnyCancellable] = []
|
fileprivate var sinks: [AnyCancellable] = []
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
}
|
}
|
||||||
@ -20,15 +20,11 @@ public class SecretStoreList: ObservableObject {
|
|||||||
addInternal(store: modifiable)
|
addInternal(store: modifiable)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var anyAvailable: Bool {
|
|
||||||
stores.reduce(false, { $0 || $1.isAvailable })
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SecretStoreList {
|
extension SecretStoreList {
|
||||||
|
|
||||||
private func addInternal(store: AnySecretStore) {
|
fileprivate func addInternal(store: AnySecretStore) {
|
||||||
stores.append(store)
|
stores.append(store)
|
||||||
let sink = store.objectWillChange.sink {
|
let sink = store.objectWillChange.sink {
|
||||||
self.objectWillChange.send()
|
self.objectWillChange.send()
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import AppKit
|
|
||||||
|
|
||||||
public struct SigningRequestProvenance: Equatable {
|
|
||||||
|
|
||||||
public var chain: [Process]
|
|
||||||
public init(root: Process) {
|
|
||||||
self.chain = [root]
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension SigningRequestProvenance {
|
|
||||||
|
|
||||||
public var origin: Process {
|
|
||||||
chain.last!
|
|
||||||
}
|
|
||||||
|
|
||||||
public var intact: Bool {
|
|
||||||
chain.allSatisfy { $0.validSignature }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension SigningRequestProvenance {
|
|
||||||
|
|
||||||
public struct Process: Equatable {
|
|
||||||
|
|
||||||
public let pid: Int32
|
|
||||||
public let processName: String
|
|
||||||
public let appName: String?
|
|
||||||
public let iconURL: URL?
|
|
||||||
public let path: String
|
|
||||||
public let validSignature: Bool
|
|
||||||
public let parentPID: Int32?
|
|
||||||
|
|
||||||
public init(pid: Int32, processName: String, appName: String?, iconURL: URL?, path: String, validSignature: Bool, parentPID: Int32?) {
|
|
||||||
self.pid = pid
|
|
||||||
self.processName = processName
|
|
||||||
self.appName = appName
|
|
||||||
self.iconURL = iconURL
|
|
||||||
self.path = path
|
|
||||||
self.validSignature = validSignature
|
|
||||||
self.parentPID = parentPID
|
|
||||||
}
|
|
||||||
|
|
||||||
public var displayName: String {
|
|
||||||
appName ?? processName
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -19,6 +19,6 @@
|
|||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>$(PRODUCT_NAME) is MIT Licensed.</string>
|
<string>Copyright © 2020 Max Goedjen. All rights reserved.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -7,7 +7,7 @@ public protocol Secret: Identifiable, Hashable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Algorithm: Hashable {
|
public enum Algorithm {
|
||||||
case ellipticCurve
|
case ellipticCurve
|
||||||
public init(secAttr: NSNumber) {
|
public init(secAttr: NSNumber) {
|
||||||
let secAttrString = secAttr.stringValue as CFString
|
let secAttrString = secAttr.stringValue as CFString
|
@ -1,3 +1,11 @@
|
|||||||
|
//
|
||||||
|
// SecretKit.h
|
||||||
|
// SecretKit
|
||||||
|
//
|
||||||
|
// Created by Max Goedjen on 2/18/20.
|
||||||
|
// Copyright © 2020 Max Goedjen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
//! Project version number for SecretKit.
|
//! Project version number for SecretKit.
|
||||||
|
@ -9,7 +9,7 @@ public protocol SecretStore: ObservableObject, Identifiable {
|
|||||||
var name: String { get }
|
var name: String { get }
|
||||||
var secrets: [SecretType] { get }
|
var secrets: [SecretType] { get }
|
||||||
|
|
||||||
func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> Data
|
func sign(data: Data, with secret: SecretType) throws -> Data
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Security
|
import Security
|
||||||
import CryptoTokenKit
|
import CryptoTokenKit
|
||||||
import LocalAuthentication
|
|
||||||
|
|
||||||
extension SecureEnclave {
|
extension SecureEnclave {
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ extension SecureEnclave {
|
|||||||
}
|
}
|
||||||
public let id = UUID()
|
public let id = UUID()
|
||||||
public let name = NSLocalizedString("Secure Enclave", comment: "Secure Enclave")
|
public let name = NSLocalizedString("Secure Enclave", comment: "Secure Enclave")
|
||||||
@Published public private(set) var secrets: [Secret] = []
|
@Published public fileprivate(set) var secrets: [Secret] = []
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
DistributedNotificationCenter.default().addObserver(forName: .secretStoreUpdated, object: nil, queue: .main) { _ in
|
DistributedNotificationCenter.default().addObserver(forName: .secretStoreUpdated, object: nil, queue: .main) { _ in
|
||||||
@ -76,10 +75,7 @@ extension SecureEnclave {
|
|||||||
reloadSecrets()
|
reloadSecrets()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> Data {
|
public func sign(data: Data, with secret: SecretType) throws -> Data {
|
||||||
let context = LAContext()
|
|
||||||
context.localizedReason = "sign a request from \"\(provenance.origin.displayName)\" using secret \"\(secret.name)\""
|
|
||||||
context.localizedCancelTitle = "Deny"
|
|
||||||
let attributes = [
|
let attributes = [
|
||||||
kSecClass: kSecClassKey,
|
kSecClass: kSecClassKey,
|
||||||
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
|
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
|
||||||
@ -87,7 +83,6 @@ extension SecureEnclave {
|
|||||||
kSecAttrKeyType: Constants.keyType,
|
kSecAttrKeyType: Constants.keyType,
|
||||||
kSecAttrTokenID: kSecAttrTokenIDSecureEnclave,
|
kSecAttrTokenID: kSecAttrTokenIDSecureEnclave,
|
||||||
kSecAttrApplicationTag: Constants.keyTag,
|
kSecAttrApplicationTag: Constants.keyTag,
|
||||||
kSecUseAuthenticationContext: context,
|
|
||||||
kSecReturnRef: true
|
kSecReturnRef: true
|
||||||
] as CFDictionary
|
] as CFDictionary
|
||||||
var untyped: CFTypeRef?
|
var untyped: CFTypeRef?
|
||||||
@ -112,7 +107,7 @@ extension SecureEnclave {
|
|||||||
|
|
||||||
extension SecureEnclave.Store {
|
extension SecureEnclave.Store {
|
||||||
|
|
||||||
private func reloadSecrets(notify: Bool = true) {
|
fileprivate func reloadSecrets(notify: Bool = true) {
|
||||||
secrets.removeAll()
|
secrets.removeAll()
|
||||||
loadSecrets()
|
loadSecrets()
|
||||||
if notify {
|
if notify {
|
||||||
@ -120,7 +115,7 @@ extension SecureEnclave.Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func loadSecrets() {
|
fileprivate func loadSecrets() {
|
||||||
let attributes = [
|
let attributes = [
|
||||||
kSecClass: kSecClassKey,
|
kSecClass: kSecClassKey,
|
||||||
kSecAttrKeyType: SecureEnclave.Constants.keyType,
|
kSecAttrKeyType: SecureEnclave.Constants.keyType,
|
||||||
@ -144,7 +139,7 @@ extension SecureEnclave.Store {
|
|||||||
secrets.append(contentsOf: wrapped)
|
secrets.append(contentsOf: wrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func savePublicKey(_ publicKey: SecKey, name: String) throws {
|
fileprivate func savePublicKey(_ publicKey: SecKey, name: String) throws {
|
||||||
let attributes = [
|
let attributes = [
|
||||||
kSecClass: kSecClassKey,
|
kSecClass: kSecClassKey,
|
||||||
kSecAttrKeyType: SecureEnclave.Constants.keyType,
|
kSecAttrKeyType: SecureEnclave.Constants.keyType,
|
||||||
@ -183,8 +178,8 @@ extension SecureEnclave {
|
|||||||
extension SecureEnclave {
|
extension SecureEnclave {
|
||||||
|
|
||||||
enum Constants {
|
enum Constants {
|
||||||
static let keyTag = "com.maxgoedjen.secretive.secureenclave.key".data(using: .utf8)! as CFData
|
fileprivate static let keyTag = "com.maxgoedjen.secretive.secureenclave.key".data(using: .utf8)! as CFData
|
||||||
static let keyType = kSecAttrKeyTypeECSECPrimeRandom
|
fileprivate static let keyType = kSecAttrKeyTypeECSECPrimeRandom
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Security
|
import Security
|
||||||
import CryptoTokenKit
|
import CryptoTokenKit
|
||||||
import LocalAuthentication
|
|
||||||
|
|
||||||
// TODO: Might need to split this up into "sub-stores?"
|
// TODO: Might need to split this up into "sub-stores?"
|
||||||
// ie, each token has its own Store.
|
// ie, each token has its own Store.
|
||||||
@ -12,17 +11,16 @@ extension SmartCard {
|
|||||||
// TODO: Read actual smart card name, eg "YubiKey 5c"
|
// TODO: Read actual smart card name, eg "YubiKey 5c"
|
||||||
@Published public var isAvailable: Bool = false
|
@Published public var isAvailable: Bool = false
|
||||||
public let id = UUID()
|
public let id = UUID()
|
||||||
public private(set) var name = NSLocalizedString("Smart Card", comment: "Smart Card")
|
public let name = NSLocalizedString("Smart Card", comment: "Smart Card")
|
||||||
@Published public private(set) var secrets: [Secret] = []
|
@Published public fileprivate(set) var secrets: [Secret] = []
|
||||||
private let watcher = TKTokenWatcher()
|
fileprivate let watcher = TKTokenWatcher()
|
||||||
private var tokenID: String?
|
fileprivate var tokenID: String?
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
tokenID = watcher.nonSecureEnclaveTokens.first
|
tokenID = watcher.tokenIDs.filter { !$0.contains("setoken") }.first
|
||||||
watcher.setInsertionHandler { string in
|
watcher.setInsertionHandler { string in
|
||||||
guard self.tokenID == nil else { return }
|
guard self.tokenID == nil else { return }
|
||||||
guard !string.contains("setoken") else { return }
|
guard !string.contains("setoken") else { return }
|
||||||
|
|
||||||
self.tokenID = string
|
self.tokenID = string
|
||||||
self.reloadSecrets()
|
self.reloadSecrets()
|
||||||
self.watcher.addRemovalHandler(self.smartcardRemoved, forTokenID: string)
|
self.watcher.addRemovalHandler(self.smartcardRemoved, forTokenID: string)
|
||||||
@ -44,17 +42,13 @@ extension SmartCard {
|
|||||||
fatalError("Keys must be deleted on the smart card.")
|
fatalError("Keys must be deleted on the smart card.")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> Data {
|
public func sign(data: Data, with secret: SecretType) throws -> Data {
|
||||||
guard let tokenID = tokenID else { fatalError() }
|
guard let tokenID = tokenID else { fatalError() }
|
||||||
let context = LAContext()
|
|
||||||
context.localizedReason = "sign a request from \"\(provenance.origin.displayName)\" using secret \"\(secret.name)\""
|
|
||||||
context.localizedCancelTitle = "Deny"
|
|
||||||
let attributes = [
|
let attributes = [
|
||||||
kSecClass: kSecClassKey,
|
kSecClass: kSecClassKey,
|
||||||
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
|
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
|
||||||
kSecAttrApplicationLabel: secret.id as CFData,
|
kSecAttrApplicationLabel: secret.id as CFData,
|
||||||
kSecAttrTokenID: tokenID,
|
kSecAttrTokenID: tokenID,
|
||||||
kSecUseAuthenticationContext: context,
|
|
||||||
kSecReturnRef: true
|
kSecReturnRef: true
|
||||||
] as CFDictionary
|
] as CFDictionary
|
||||||
var untyped: CFTypeRef?
|
var untyped: CFTypeRef?
|
||||||
@ -88,12 +82,12 @@ extension SmartCard {
|
|||||||
|
|
||||||
extension SmartCard.Store {
|
extension SmartCard.Store {
|
||||||
|
|
||||||
private func smartcardRemoved(for tokenID: String? = nil) {
|
fileprivate func smartcardRemoved(for tokenID: String? = nil) {
|
||||||
self.tokenID = nil
|
self.tokenID = nil
|
||||||
reloadSecrets()
|
reloadSecrets()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func reloadSecrets() {
|
fileprivate func reloadSecrets() {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.isAvailable = self.tokenID != nil
|
self.isAvailable = self.tokenID != nil
|
||||||
self.secrets.removeAll()
|
self.secrets.removeAll()
|
||||||
@ -101,16 +95,8 @@ extension SmartCard.Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func loadSecrets() {
|
fileprivate func loadSecrets() {
|
||||||
guard let tokenID = tokenID else { return }
|
guard let tokenID = tokenID else { return }
|
||||||
// Hack to read name if there's only one smart card
|
|
||||||
let slotNames = TKSmartCardSlotManager().slotNames
|
|
||||||
if watcher.nonSecureEnclaveTokens.count == 1 && slotNames.count == 1 {
|
|
||||||
name = slotNames.first!
|
|
||||||
} else {
|
|
||||||
name = NSLocalizedString("Smart Card", comment: "Smart Card")
|
|
||||||
}
|
|
||||||
|
|
||||||
let attributes = [
|
let attributes = [
|
||||||
kSecClass: kSecClassKey,
|
kSecClass: kSecClassKey,
|
||||||
kSecAttrTokenID: tokenID,
|
kSecAttrTokenID: tokenID,
|
||||||
@ -138,14 +124,6 @@ extension SmartCard.Store {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TKTokenWatcher {
|
|
||||||
|
|
||||||
fileprivate var nonSecureEnclaveTokens: [String] {
|
|
||||||
tokenIDs.filter { !$0.contains("setoken") }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension SmartCard {
|
extension SmartCard {
|
||||||
|
|
||||||
public struct KeychainError: Error {
|
public struct KeychainError: Error {
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import XCTest
|
|
||||||
@testable import SecretKit
|
|
||||||
|
|
||||||
class AnySecretTests: XCTestCase {
|
|
||||||
|
|
||||||
func testEraser() {
|
|
||||||
let secret = SmartCard.Secret(id: UUID().uuidString.data(using: .utf8)!, name: "Name", algorithm: .ellipticCurve, keySize: 256, publicKey: UUID().uuidString.data(using: .utf8)!)
|
|
||||||
let erased = AnySecret(secret)
|
|
||||||
XCTAssert(erased.id == secret.id as AnyHashable)
|
|
||||||
XCTAssert(erased.name == secret.name)
|
|
||||||
XCTAssert(erased.algorithm == secret.algorithm)
|
|
||||||
XCTAssert(erased.keySize == secret.keySize)
|
|
||||||
XCTAssert(erased.publicKey == secret.publicKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import XCTest
|
|
||||||
@testable import SecretKit
|
|
||||||
|
|
||||||
class OpenSSHReaderTests: XCTestCase {
|
|
||||||
|
|
||||||
func testSignatureRequest() {
|
|
||||||
let reader = OpenSSHReader(data: Constants.signatureRequest)
|
|
||||||
let hash = reader.readNextChunk()
|
|
||||||
XCTAssert(hash == Data(base64Encoded: "AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBEqCbkJbOHy5S1wVCaJoKPmpS0egM4frMqllgnlRRQ/Uvnn6EVS8oV03cPA2Bz0EdESyRKA/sbmn0aBtgjIwGELxu45UXEW1TEz6TxyS0u3vuIqR3Wo1CrQWRDnkrG/pBQ=="))
|
|
||||||
let dataToSign = reader.readNextChunk()
|
|
||||||
XCTAssert(dataToSign == Data(base64Encoded: "AAAAICi5xf1ixOestUlxdjvt/BDcM+rzhwy7Vo8cW5YcxA8+MgAAAANnaXQAAAAOc3NoLWNvbm5lY3Rpb24AAAAJcHVibGlja2V5AQAAABNlY2RzYS1zaGEyLW5pc3RwMzg0AAAAiAAAABNlY2RzYS1zaGEyLW5pc3RwMzg0AAAACG5pc3RwMzg0AAAAYQRKgm5CWzh8uUtcFQmiaCj5qUtHoDOH6zKpZYJ5UUUP1L55+hFUvKFdN3DwNgc9BHREskSgP7G5p9GgbYIyMBhC8buOVFxFtUxM+k8cktLt77iKkd1qNQq0FkQ55Kxv6QU="))
|
|
||||||
let empty = reader.readNextChunk()
|
|
||||||
XCTAssert(empty.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension OpenSSHReaderTests {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
static let signatureRequest = Data(base64Encoded: "AAAAiAAAABNlY2RzYS1zaGEyLW5pc3RwMzg0AAAACG5pc3RwMzg0AAAAYQRKgm5CWzh8uUtcFQmiaCj5qUtHoDOH6zKpZYJ5UUUP1L55+hFUvKFdN3DwNgc9BHREskSgP7G5p9GgbYIyMBhC8buOVFxFtUxM+k8cktLt77iKkd1qNQq0FkQ55Kxv6QUAAADvAAAAICi5xf1ixOestUlxdjvt/BDcM+rzhwy7Vo8cW5YcxA8+MgAAAANnaXQAAAAOc3NoLWNvbm5lY3Rpb24AAAAJcHVibGlja2V5AQAAABNlY2RzYS1zaGEyLW5pc3RwMzg0AAAAiAAAABNlY2RzYS1zaGEyLW5pc3RwMzg0AAAACG5pc3RwMzg0AAAAYQRKgm5CWzh8uUtcFQmiaCj5qUtHoDOH6zKpZYJ5UUUP1L55+hFUvKFdN3DwNgc9BHREskSgP7G5p9GgbYIyMBhC8buOVFxFtUxM+k8cktLt77iKkd1qNQq0FkQ55Kxv6QUAAAAA")!
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -67,7 +67,7 @@
|
|||||||
</Testables>
|
</Testables>
|
||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Test"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
import Cocoa
|
|
||||||
import SwiftUI
|
|
||||||
import SecretKit
|
|
||||||
import Brief
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct Secretive: App {
|
|
||||||
|
|
||||||
private let storeList: SecretStoreList = {
|
|
||||||
let list = SecretStoreList()
|
|
||||||
list.add(store: SecureEnclave.Store())
|
|
||||||
list.add(store: SmartCard.Store())
|
|
||||||
return list
|
|
||||||
}()
|
|
||||||
private let agentStatusChecker = AgentStatusChecker()
|
|
||||||
private let justUpdatedChecker = JustUpdatedChecker()
|
|
||||||
|
|
||||||
@AppStorage("defaultsHasRunSetup") var hasRunSetup = false
|
|
||||||
@State private var showingSetup = false
|
|
||||||
@State private var showingCreation = false
|
|
||||||
|
|
||||||
@SceneBuilder var body: some Scene {
|
|
||||||
WindowGroup {
|
|
||||||
ContentView<Updater, AgentStatusChecker>(showingCreation: $showingCreation, runningSetup: $showingSetup, hasRunSetup: $hasRunSetup)
|
|
||||||
.environmentObject(storeList)
|
|
||||||
.environmentObject(Updater(checkOnLaunch: hasRunSetup))
|
|
||||||
.environmentObject(agentStatusChecker)
|
|
||||||
.onAppear {
|
|
||||||
if !hasRunSetup {
|
|
||||||
showingSetup = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
|
|
||||||
guard hasRunSetup else { return }
|
|
||||||
agentStatusChecker.check()
|
|
||||||
if agentStatusChecker.running && justUpdatedChecker.justUpdated {
|
|
||||||
// Relaunch the agent, since it'll be running from earlier update still
|
|
||||||
reinstallAgent()
|
|
||||||
} else if !agentStatusChecker.running {
|
|
||||||
forceLaunchAgent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.commands {
|
|
||||||
CommandGroup(after: CommandGroupPlacement.newItem) {
|
|
||||||
Button("New Secret") {
|
|
||||||
showingCreation = true
|
|
||||||
}
|
|
||||||
.keyboardShortcut(KeyboardShortcut(KeyEquivalent("N"), modifiers: [.command, .shift]))
|
|
||||||
}
|
|
||||||
CommandGroup(replacing: .help) {
|
|
||||||
Button("Help") {
|
|
||||||
NSWorkspace.shared.open(Constants.helpURL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CommandGroup(after: .help) {
|
|
||||||
Button("Setup Secretive") {
|
|
||||||
showingSetup = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SidebarCommands()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Secretive {
|
|
||||||
|
|
||||||
private func reinstallAgent() {
|
|
||||||
justUpdatedChecker.check()
|
|
||||||
LaunchAgentController().install {
|
|
||||||
// Wait a second for launchd to kick in (next runloop isn't enough).
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
||||||
agentStatusChecker.check()
|
|
||||||
if !agentStatusChecker.running {
|
|
||||||
forceLaunchAgent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func forceLaunchAgent() {
|
|
||||||
// We've run setup, we didn't just update, launchd is just not doing it's thing.
|
|
||||||
// Force a launch directly.
|
|
||||||
LaunchAgentController().forceLaunch { _ in
|
|
||||||
agentStatusChecker.check()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private enum Constants {
|
|
||||||
static let helpURL = URL(string: "https://github.com/maxgoedjen/secretive/blob/main/FAQ.md")!
|
|
||||||
}
|
|
||||||
|
|
99
Secretive/AppDelegate.swift
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import Cocoa
|
||||||
|
import SwiftUI
|
||||||
|
import SecretKit
|
||||||
|
|
||||||
|
@NSApplicationMain
|
||||||
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
|
var window: NSWindow!
|
||||||
|
@IBOutlet var newMenuItem: NSMenuItem!
|
||||||
|
@IBOutlet var toolbar: NSToolbar!
|
||||||
|
let storeList: SecretStoreList = {
|
||||||
|
let list = SecretStoreList()
|
||||||
|
list.add(store: SecureEnclave.Store())
|
||||||
|
list.add(store: SmartCard.Store())
|
||||||
|
return list
|
||||||
|
}()
|
||||||
|
let updater = Updater()
|
||||||
|
let agentStatusChecker = AgentStatusChecker()
|
||||||
|
|
||||||
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
|
let contentView = ContentView(storeList: storeList, updater: updater, agentStatusChecker: agentStatusChecker, runSetupBlock: { self.runSetup(sender: nil) })
|
||||||
|
// Create the window and set the content view.
|
||||||
|
window = NSWindow(
|
||||||
|
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
||||||
|
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||||
|
backing: .buffered, defer: false)
|
||||||
|
window.center()
|
||||||
|
window.setFrameAutosaveName("Main Window")
|
||||||
|
window.contentView = NSHostingView(rootView: contentView)
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
window.titleVisibility = .hidden
|
||||||
|
window.toolbar = toolbar
|
||||||
|
window.isReleasedWhenClosed = false
|
||||||
|
if storeList.modifiableStore?.isAvailable ?? false {
|
||||||
|
let plus = NSTitlebarAccessoryViewController()
|
||||||
|
plus.view = NSButton(image: NSImage(named: NSImage.addTemplateName)!, target: self, action: #selector(add(sender:)))
|
||||||
|
plus.layoutAttribute = .right
|
||||||
|
window.addTitlebarAccessoryViewController(plus)
|
||||||
|
newMenuItem.isEnabled = true
|
||||||
|
}
|
||||||
|
runSetupIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
func applicationDidBecomeActive(_ notification: Notification) {
|
||||||
|
agentStatusChecker.check()
|
||||||
|
}
|
||||||
|
|
||||||
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||||
|
guard !flag else { return false }
|
||||||
|
window.makeKeyAndOrderFront(self)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func add(sender: AnyObject?) {
|
||||||
|
var addWindow: NSWindow!
|
||||||
|
let addView = CreateSecretView(store: storeList.modifiableStore!) {
|
||||||
|
self.window.endSheet(addWindow)
|
||||||
|
}
|
||||||
|
addWindow = NSWindow(
|
||||||
|
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
||||||
|
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||||
|
backing: .buffered, defer: false)
|
||||||
|
addWindow.contentView = NSHostingView(rootView: addView)
|
||||||
|
window.beginSheet(addWindow, completionHandler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func runSetup(sender: AnyObject?) {
|
||||||
|
let setupWindow = NSWindow(
|
||||||
|
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
||||||
|
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||||
|
backing: .buffered, defer: false)
|
||||||
|
let setupView = SetupView() { success in
|
||||||
|
self.window.endSheet(setupWindow)
|
||||||
|
self.agentStatusChecker.check()
|
||||||
|
}
|
||||||
|
setupWindow.contentView = NSHostingView(rootView: setupView)
|
||||||
|
window.beginSheet(setupWindow, completionHandler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppDelegate {
|
||||||
|
|
||||||
|
func runSetupIfNeeded() {
|
||||||
|
if !UserDefaults.standard.bool(forKey: Constants.defaultsHasRunSetup) {
|
||||||
|
UserDefaults.standard.set(true, forKey: Constants.defaultsHasRunSetup)
|
||||||
|
runSetup(sender: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppDelegate {
|
||||||
|
|
||||||
|
enum Constants {
|
||||||
|
static let defaultsHasRunSetup = "defaultsHasRunSetup"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -31,13 +31,13 @@
|
|||||||
"size" : "128x128"
|
"size" : "128x128"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Mac Icon.png",
|
"filename" : "Icon 2@1x.png",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"scale" : "1x",
|
"scale" : "1x",
|
||||||
"size" : "256x256"
|
"size" : "256x256"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "Mac Icon@0.25x.png",
|
"filename" : "Icon 2@2x.png",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"scale" : "2x",
|
"scale" : "2x",
|
||||||
"size" : "256x256"
|
"size" : "256x256"
|
||||||
|
BIN
Secretive/Assets.xcassets/AppIcon.appiconset/Icon 2@1x.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
Secretive/Assets.xcassets/AppIcon.appiconset/Icon 2@2x.png
Normal file
After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 40 KiB |
160
Secretive/Base.lproj/Main.storyboard
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16085" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||||
|
<dependencies>
|
||||||
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16085"/>
|
||||||
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
|
</dependencies>
|
||||||
|
<scenes>
|
||||||
|
<!--Application-->
|
||||||
|
<scene sceneID="JPo-4y-FX3">
|
||||||
|
<objects>
|
||||||
|
<application id="hnw-xV-0zn" sceneMemberID="viewController">
|
||||||
|
<menu key="mainMenu" title="Main Menu" systemMenu="main" autoenablesItems="NO" id="AYu-sK-qS6">
|
||||||
|
<items>
|
||||||
|
<menuItem title="Secretive" id="1Xt-HY-uBw">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<menu key="submenu" title="Secretive" systemMenu="apple" id="uQy-DD-JDr">
|
||||||
|
<items>
|
||||||
|
<menuItem title="About Secretive" id="5kV-Vb-QxS">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
|
||||||
|
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
|
||||||
|
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
|
||||||
|
<menuItem title="Services" id="NMo-om-nkz">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
|
||||||
|
<menuItem title="Hide Secretive" keyEquivalent="h" id="Olw-nP-bQN">
|
||||||
|
<connections>
|
||||||
|
<action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="Show All" id="Kd2-mp-pUS">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
|
||||||
|
<menuItem title="Quit Secretive" keyEquivalent="q" id="4sb-4s-VLi">
|
||||||
|
<connections>
|
||||||
|
<action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
</items>
|
||||||
|
</menu>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="File" id="dMs-cI-mzQ">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<menu key="submenu" title="File" autoenablesItems="NO" id="bib-Uj-vzu">
|
||||||
|
<items>
|
||||||
|
<menuItem title="New" enabled="NO" keyEquivalent="n" id="Was-JA-tGl">
|
||||||
|
<connections>
|
||||||
|
<action selector="addWithSender:" target="Voe-Tx-rLC" id="U1t-YZ-Hn5"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
|
||||||
|
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
|
||||||
|
<connections>
|
||||||
|
<action selector="performClose:" target="Ady-hI-5gd" id="HmO-Ls-i7Q"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
</items>
|
||||||
|
</menu>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="Window" id="aUF-d1-5bR">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
|
||||||
|
<items>
|
||||||
|
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
|
||||||
|
<connections>
|
||||||
|
<action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="Zoom" id="R4o-n2-Eq4">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
|
||||||
|
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
</items>
|
||||||
|
</menu>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="Help" id="wpr-3q-Mcd">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
|
||||||
|
<items>
|
||||||
|
<menuItem title="Setup Helper App" id="04y-R6-7bF">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="runSetupWithSender:" target="Voe-Tx-rLC" id="Fty-2m-eng"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="Ddf-5M-Bmf"/>
|
||||||
|
<menuItem title="Secretive Help" keyEquivalent="?" id="FKE-Sm-Kum">
|
||||||
|
<connections>
|
||||||
|
<action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
</items>
|
||||||
|
</menu>
|
||||||
|
</menuItem>
|
||||||
|
</items>
|
||||||
|
</menu>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
|
||||||
|
</connections>
|
||||||
|
</application>
|
||||||
|
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Secretive" customModuleProvider="target">
|
||||||
|
<connections>
|
||||||
|
<outlet property="newMenuItem" destination="Was-JA-tGl" id="C8s-uk-gMA"/>
|
||||||
|
<outlet property="toolbar" destination="bvo-mt-QR4" id="XSF-g2-znt"/>
|
||||||
|
</connections>
|
||||||
|
</customObject>
|
||||||
|
<toolbar implicitIdentifier="09D11707-F4A3-4FD5-970E-AC5832E91C2B" autosavesConfiguration="NO" displayMode="iconAndLabel" sizeMode="regular" id="bvo-mt-QR4">
|
||||||
|
<allowedToolbarItems>
|
||||||
|
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="9Xm-OQ-a7h"/>
|
||||||
|
<toolbarItem implicitItemIdentifier="728E7E6E-F692-41A1-9439-C6EF9BE96CBA" label="Secretive" paletteLabel="" sizingBehavior="auto" id="xbD-W8-Ypr">
|
||||||
|
<nil key="toolTip"/>
|
||||||
|
<textField key="view" horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Mg0-Hm-7bW">
|
||||||
|
<rect key="frame" x="0.0" y="14" width="65" height="16"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<textFieldCell key="cell" lineBreakMode="clipping" title="Secretive" id="EXw-BM-zF7">
|
||||||
|
<font key="font" usesAppearanceFont="YES"/>
|
||||||
|
<color key="textColor" name="windowFrameTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
</textFieldCell>
|
||||||
|
</textField>
|
||||||
|
</toolbarItem>
|
||||||
|
</allowedToolbarItems>
|
||||||
|
<defaultToolbarItems>
|
||||||
|
<toolbarItem reference="9Xm-OQ-a7h"/>
|
||||||
|
<toolbarItem reference="xbD-W8-Ypr"/>
|
||||||
|
<toolbarItem reference="9Xm-OQ-a7h"/>
|
||||||
|
</defaultToolbarItems>
|
||||||
|
</toolbar>
|
||||||
|
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||||
|
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||||
|
</objects>
|
||||||
|
<point key="canvasLocation" x="75" y="0.0"/>
|
||||||
|
</scene>
|
||||||
|
</scenes>
|
||||||
|
</document>
|
@ -15,24 +15,11 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func check() {
|
func check() {
|
||||||
running = instanceSecretAgentProcess != nil
|
running = secretAgentProcess != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// All processes, including ones from older versions, etc
|
var secretAgentProcess: NSRunningApplication? {
|
||||||
var secretAgentProcesses: [NSRunningApplication] {
|
NSRunningApplication.runningApplications(withBundleIdentifier: Constants.secretAgentAppID).first
|
||||||
NSRunningApplication.runningApplications(withBundleIdentifier: Constants.secretAgentAppID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The process corresponding to this instance of Secretive
|
|
||||||
var instanceSecretAgentProcess: NSRunningApplication? {
|
|
||||||
let agents = secretAgentProcesses
|
|
||||||
for agent in agents {
|
|
||||||
guard let url = agent.bundleURL else { continue }
|
|
||||||
if url.absoluteString.hasPrefix(Bundle.main.bundleURL.absoluteString) {
|
|
||||||
return agent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
struct ApplicationDirectoryController {
|
|
||||||
}
|
|
||||||
|
|
||||||
extension ApplicationDirectoryController {
|
|
||||||
|
|
||||||
var isInApplicationsDirectory: Bool {
|
|
||||||
let bundlePath = Bundle.main.bundlePath
|
|
||||||
for directory in NSSearchPathForDirectoriesInDomains(.applicationDirectory, .allDomainsMask, true) {
|
|
||||||
if bundlePath.hasPrefix(directory) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if bundlePath.contains("/Library/Developer/Xcode") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import Combine
|
|
||||||
import AppKit
|
|
||||||
|
|
||||||
protocol JustUpdatedCheckerProtocol: ObservableObject {
|
|
||||||
var justUpdated: Bool { get }
|
|
||||||
}
|
|
||||||
|
|
||||||
class JustUpdatedChecker: ObservableObject, JustUpdatedCheckerProtocol {
|
|
||||||
|
|
||||||
@Published var justUpdated: Bool = false
|
|
||||||
|
|
||||||
init() {
|
|
||||||
check()
|
|
||||||
}
|
|
||||||
|
|
||||||
func check() {
|
|
||||||
let lastBuild = UserDefaults.standard.object(forKey: Constants.previousVersionUserDefaultsKey) as? String ?? "None"
|
|
||||||
let currentBuild = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
|
|
||||||
UserDefaults.standard.set(currentBuild, forKey: Constants.previousVersionUserDefaultsKey)
|
|
||||||
justUpdated = lastBuild != currentBuild
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension JustUpdatedChecker {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
static let previousVersionUserDefaultsKey = "com.maxgoedjen.Secretive.lastBuild"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import ServiceManagement
|
|
||||||
import AppKit
|
|
||||||
import OSLog
|
|
||||||
|
|
||||||
struct LaunchAgentController {
|
|
||||||
|
|
||||||
func install(completion: (() -> Void)? = nil) {
|
|
||||||
Logger().debug("Installing agent")
|
|
||||||
_ = setEnabled(false)
|
|
||||||
// This is definitely a bit of a "seems to work better" thing but:
|
|
||||||
// Seems to more reliably hit if these are on separate runloops, otherwise it seems like it sometimes doesn't kill old
|
|
||||||
// and start new?
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
||||||
_ = setEnabled(true)
|
|
||||||
completion?()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func forceLaunch(completion: ((Bool) -> Void)?) {
|
|
||||||
Logger().debug("Agent is not running, attempting to force launch")
|
|
||||||
let url = Bundle.main.bundleURL.appendingPathComponent("Contents/Library/LoginItems/SecretAgent.app")
|
|
||||||
NSWorkspace.shared.openApplication(at: url, configuration: NSWorkspace.OpenConfiguration()) { app, error in
|
|
||||||
completion?(error == nil)
|
|
||||||
if let error = error {
|
|
||||||
Logger().error("Error force launching \(error.localizedDescription)")
|
|
||||||
} else {
|
|
||||||
Logger().debug("Agent force launched")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func setEnabled(_ enabled: Bool) -> Bool {
|
|
||||||
SMLoginItemSetEnabled("com.maxgoedjen.Secretive.SecretAgent" as CFString, enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
import Cocoa
|
|
||||||
|
|
||||||
struct ShellConfigurationController {
|
|
||||||
|
|
||||||
let socketPath = (NSHomeDirectory().replacingOccurrences(of: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String
|
|
||||||
|
|
||||||
var shellInstructions: [ShellConfigInstruction] {
|
|
||||||
[
|
|
||||||
ShellConfigInstruction(shell: "zsh",
|
|
||||||
shellConfigDirectory: "~/",
|
|
||||||
shellConfigFilename: ".zshrc",
|
|
||||||
text: "export SSH_AUTH_SOCK=\(socketPath)"),
|
|
||||||
ShellConfigInstruction(shell: "bash",
|
|
||||||
shellConfigDirectory: "~/",
|
|
||||||
shellConfigFilename: ".bashrc",
|
|
||||||
text: "export SSH_AUTH_SOCK=\(socketPath)"),
|
|
||||||
ShellConfigInstruction(shell: "fish",
|
|
||||||
shellConfigDirectory: "~/.config/fish",
|
|
||||||
shellConfigFilename: "config.fish",
|
|
||||||
text: "set -x SSH_AUTH_SOCK \(socketPath)"),
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func addToShell(shellInstructions: ShellConfigInstruction) -> Bool {
|
|
||||||
let openPanel = NSOpenPanel()
|
|
||||||
// This is sync, so no need to strongly retain
|
|
||||||
let delegate = Delegate(name: shellInstructions.shellConfigFilename)
|
|
||||||
openPanel.delegate = delegate
|
|
||||||
openPanel.message = "Select \(shellInstructions.shellConfigFilename) to let Secretive configure your shell automatically."
|
|
||||||
openPanel.prompt = "Add to \(shellInstructions.shellConfigFilename)"
|
|
||||||
openPanel.canChooseFiles = true
|
|
||||||
openPanel.canChooseDirectories = false
|
|
||||||
openPanel.showsHiddenFiles = true
|
|
||||||
openPanel.directoryURL = URL(fileURLWithPath: shellInstructions.shellConfigDirectory)
|
|
||||||
openPanel.nameFieldStringValue = shellInstructions.shellConfigFilename
|
|
||||||
openPanel.allowedContentTypes = [.symbolicLink, .data, .plainText]
|
|
||||||
openPanel.runModal()
|
|
||||||
guard let fileURL = openPanel.urls.first else { return false }
|
|
||||||
let handle: FileHandle
|
|
||||||
do {
|
|
||||||
handle = try FileHandle(forUpdating: fileURL)
|
|
||||||
guard let existing = try handle.readToEnd(),
|
|
||||||
let existingString = String(data: existing, encoding: .utf8) else { return false }
|
|
||||||
guard !existingString.contains(shellInstructions.text) else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
try handle.seekToEnd()
|
|
||||||
} catch {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
handle.write("\n# Secretive Config\n\(shellInstructions.text)\n".data(using: .utf8)!)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
82
Secretive/Controllers/Updater.swift
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import Foundation
|
||||||
|
import Combine
|
||||||
|
|
||||||
|
protocol UpdaterProtocol: ObservableObject {
|
||||||
|
|
||||||
|
var update: Release? { get }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Updater: ObservableObject, UpdaterProtocol {
|
||||||
|
|
||||||
|
@Published var update: Release?
|
||||||
|
|
||||||
|
init() {
|
||||||
|
checkForUpdates()
|
||||||
|
let timer = Timer.scheduledTimer(withTimeInterval: 60*60*24, repeats: true) { _ in
|
||||||
|
self.checkForUpdates()
|
||||||
|
}
|
||||||
|
timer.tolerance = 60*60
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkForUpdates() {
|
||||||
|
URLSession.shared.dataTask(with: Constants.updateURL) { data, _, _ in
|
||||||
|
guard let data = data else { return }
|
||||||
|
guard let release = try? JSONDecoder().decode(Release.self, from: data) else { return }
|
||||||
|
self.evaluate(release: release)
|
||||||
|
}.resume()
|
||||||
|
}
|
||||||
|
|
||||||
|
func evaluate(release: Release) {
|
||||||
|
let latestVersion = semVer(from: release.name)
|
||||||
|
let currentVersion = semVer(from: Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String)
|
||||||
|
for (latest, current) in zip(latestVersion, currentVersion) {
|
||||||
|
if latest > current {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.update = release
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func semVer(from stringVersion: String) -> [Int] {
|
||||||
|
var split = stringVersion.split(separator: ".").compactMap { Int($0) }
|
||||||
|
while split.count < 3 {
|
||||||
|
split.append(0)
|
||||||
|
}
|
||||||
|
return split
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Updater {
|
||||||
|
|
||||||
|
enum Constants {
|
||||||
|
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases/latest")!
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Release: Codable {
|
||||||
|
let name: String
|
||||||
|
let html_url: URL
|
||||||
|
let body: String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extension Release {
|
||||||
|
|
||||||
|
var critical: Bool {
|
||||||
|
return body.contains(Constants.securityContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Release {
|
||||||
|
|
||||||
|
enum Constants {
|
||||||
|
static let securityContent = "Critical Security Update"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
{\rtf1\ansi\ansicpg1252\cocoartf2511
|
|
||||||
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
|
||||||
{\colortbl;\red255\green255\blue255;}
|
|
||||||
{\*\expandedcolortbl;;}
|
|
||||||
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
|
|
||||||
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6119\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/maxgoedjen/secretive"}}{\fldrslt
|
|
||||||
\f0\fs24 \cf0 GitHub Repository}}
|
|
||||||
\f0\fs24 \
|
|
||||||
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
|
|
||||||
\cf0 \
|
|
||||||
{\field{\*\fldinst{HYPERLINK "GITHUB_BUILD_URL"}}{\fldrslt Build Log}}\
|
|
||||||
\
|
|
||||||
Special Thanks To:\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/bdash"}}{\fldrslt Mark Rowe}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/danielctull"}}{\fldrslt Daniel Tull}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/davedelong"}}{\fldrslt Dave DeLong}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/esttorhe"}}{\fldrslt Esteban Torres}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/joeblau"}}{\fldrslt Joe Blau}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/marksands"}}{\fldrslt Mark Sands}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/mergesort"}}{\fldrslt Joe Fabisevich}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/phillco"}}{\fldrslt Phil Cohen}}\
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/zackdotcomputer"}}{\fldrslt Zack Sheppard}}}
|
|
||||||
{\field{\*\fldinst{HYPERLINK "https://github.com/zacwest"}}{\fldrslt Zac West}}}
|
|
@ -19,11 +19,13 @@
|
|||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>$(CI_VERSION)</string>
|
<string>$(CI_VERSION)</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>$(CI_BUILD_NUMBER)</string>
|
<string>$(CI_VERSION)</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>$(PRODUCT_NAME) is MIT Licensed.</string>
|
<string>Copyright © 2020 Max Goedjen. All rights reserved.</string>
|
||||||
|
<key>NSMainStoryboardFile</key>
|
||||||
|
<string>Main</string>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>NSSupportsAutomaticTermination</key>
|
<key>NSSupportsAutomaticTermination</key>
|
||||||
|
@ -35,7 +35,7 @@ extension Preview {
|
|||||||
self.secrets.append(contentsOf: new)
|
self.secrets.append(contentsOf: new)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sign(data: Data, with secret: Preview.Secret, for provenance: SigningRequestProvenance) throws -> Data {
|
func sign(data: Data, with secret: Preview.Secret) throws -> Data {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Combine
|
import Combine
|
||||||
import Brief
|
|
||||||
|
|
||||||
class PreviewUpdater: UpdaterProtocol {
|
class PreviewUpdater: UpdaterProtocol {
|
||||||
|
|
||||||
@ -11,9 +10,9 @@ class PreviewUpdater: UpdaterProtocol {
|
|||||||
case .none:
|
case .none:
|
||||||
self.update = nil
|
self.update = nil
|
||||||
case .advisory:
|
case .advisory:
|
||||||
self.update = Release(name: "10.10.10", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Some regular update")
|
self.update = Release(name: "10.10.10", html_url: URL(string: "https://example.com")!, body: "Some regular update")
|
||||||
case .critical:
|
case .critical:
|
||||||
self.update = Release(name: "10.10.10", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
|
self.update = Release(name: "10.10.10", html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,10 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
<key>com.apple.security.app-sandbox</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.files.user-selected.read-write</key>
|
<key>com.apple.security.smartcard</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.network.client</key>
|
<key>com.apple.security.network.client</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.smartcard</key>
|
|
||||||
<true/>
|
|
||||||
<key>keychain-access-groups</key>
|
<key>keychain-access-groups</key>
|
||||||
<array>
|
<array>
|
||||||
<string>$(AppIdentifierPrefix)com.maxgoedjen.Secretive</string>
|
<string>$(AppIdentifierPrefix)com.maxgoedjen.Secretive</string>
|
||||||
|
@ -1,192 +1,143 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SecretKit
|
import SecretKit
|
||||||
import Brief
|
|
||||||
|
|
||||||
struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
|
struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
|
||||||
|
|
||||||
|
@ObservedObject var storeList: SecretStoreList
|
||||||
|
@ObservedObject var updater: UpdaterType
|
||||||
|
@ObservedObject var agentStatusChecker: AgentStatusCheckerType
|
||||||
|
var runSetupBlock: (() -> Void)?
|
||||||
|
|
||||||
@Binding var showingCreation: Bool
|
@State fileprivate var active: AnySecret.ID?
|
||||||
@Binding var runningSetup: Bool
|
@State fileprivate var showingDeletion = false
|
||||||
@Binding var hasRunSetup: Bool
|
@State fileprivate var deletingSecret: AnySecret?
|
||||||
|
|
||||||
@EnvironmentObject private var storeList: SecretStoreList
|
|
||||||
@EnvironmentObject private var updater: UpdaterType
|
|
||||||
@EnvironmentObject private var agentStatusChecker: AgentStatusCheckerType
|
|
||||||
|
|
||||||
@State private var selectedUpdate: Release?
|
|
||||||
@State private var showingAppPathNotice = false
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if storeList.anyAvailable {
|
if updater.update != nil {
|
||||||
StoreListView(showingCreation: $showingCreation)
|
updateNotice()
|
||||||
} else {
|
|
||||||
NoStoresView()
|
|
||||||
}
|
}
|
||||||
}
|
if !agentStatusChecker.running {
|
||||||
.frame(minWidth: 640, minHeight: 320)
|
agentNotice()
|
||||||
.toolbar {
|
}
|
||||||
updateNotice
|
NavigationView {
|
||||||
setupNotice
|
List(selection: $active) {
|
||||||
appPathNotice
|
ForEach(storeList.stores) { store in
|
||||||
newItem
|
if store.isAvailable {
|
||||||
}
|
Section(header: Text(store.name)) {
|
||||||
}
|
if store.secrets.isEmpty {
|
||||||
|
if store is AnySecretStoreModifiable {
|
||||||
}
|
NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: self.$active) {
|
||||||
|
Text("No Secrets")
|
||||||
extension ContentView {
|
}
|
||||||
|
} else {
|
||||||
var updateNotice: ToolbarItem<Void, AnyView> {
|
NavigationLink(destination: EmptyStoreView(), tag: Constants.emptyStoreTag, selection: self.$active) {
|
||||||
guard let update = updater.update else {
|
Text("No Secrets")
|
||||||
return ToolbarItem { AnyView(EmptyView()) }
|
}
|
||||||
}
|
}
|
||||||
let color: Color
|
|
||||||
let text: String
|
|
||||||
if update.critical {
|
|
||||||
text = "Critical Security Update Required"
|
|
||||||
color = .red
|
|
||||||
} else {
|
|
||||||
text = "Update Available"
|
|
||||||
color = .orange
|
|
||||||
}
|
|
||||||
return ToolbarItem {
|
|
||||||
AnyView(
|
|
||||||
Button(action: {
|
|
||||||
selectedUpdate = update
|
|
||||||
}, label: {
|
|
||||||
Text(text)
|
|
||||||
.font(.headline)
|
|
||||||
.foregroundColor(.white)
|
|
||||||
})
|
|
||||||
.background(color)
|
|
||||||
.cornerRadius(5)
|
|
||||||
.popover(item: $selectedUpdate, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { update in
|
|
||||||
UpdateDetailView(update: update)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var newItem: ToolbarItem<Void, AnyView> {
|
|
||||||
guard storeList.modifiableStore?.isAvailable ?? false else {
|
|
||||||
return ToolbarItem { AnyView(EmptyView()) }
|
|
||||||
}
|
|
||||||
return ToolbarItem {
|
|
||||||
AnyView(
|
|
||||||
Button(action: {
|
|
||||||
showingCreation = true
|
|
||||||
}, label: {
|
|
||||||
Image(systemName: "plus")
|
|
||||||
})
|
|
||||||
.popover(isPresented: $showingCreation, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) {
|
|
||||||
if let modifiable = storeList.modifiableStore {
|
|
||||||
CreateSecretView(store: modifiable, showing: $showingCreation)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var setupNotice: ToolbarItem<Void, AnyView> {
|
|
||||||
return ToolbarItem {
|
|
||||||
AnyView(
|
|
||||||
Group {
|
|
||||||
if runningSetup || !hasRunSetup || !agentStatusChecker.running {
|
|
||||||
Button(action: {
|
|
||||||
runningSetup = true
|
|
||||||
}, label: {
|
|
||||||
Group {
|
|
||||||
if hasRunSetup && !agentStatusChecker.running {
|
|
||||||
Text("Secret Agent Is Not Running")
|
|
||||||
} else {
|
} else {
|
||||||
Text("Setup Secretive")
|
ForEach(store.secrets) { secret in
|
||||||
|
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: self.$active) {
|
||||||
|
Text(secret.name)
|
||||||
|
}.contextMenu {
|
||||||
|
if store is AnySecretStoreModifiable {
|
||||||
|
Button(action: { self.delete(secret: secret) }) {
|
||||||
|
Text("Delete")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.font(.headline)
|
}
|
||||||
.foregroundColor(.white)
|
}
|
||||||
})
|
}.onAppear {
|
||||||
.background(Color.orange)
|
self.active = self.nextDefaultSecret
|
||||||
.cornerRadius(5)
|
}
|
||||||
} else {
|
.listStyle(SidebarListStyle())
|
||||||
EmptyView()
|
.frame(minWidth: 100, idealWidth: 240)
|
||||||
|
}
|
||||||
|
.navigationViewStyle(DoubleColumnNavigationViewStyle())
|
||||||
|
.sheet(isPresented: $showingDeletion) {
|
||||||
|
if self.storeList.modifiableStore != nil {
|
||||||
|
DeleteSecretView(secret: self.deletingSecret!, store: self.storeList.modifiableStore!) { deleted in
|
||||||
|
self.showingDeletion = false
|
||||||
|
if deleted {
|
||||||
|
self.active = self.nextDefaultSecret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $runningSetup) {
|
}
|
||||||
SetupView(visible: $runningSetup, setupComplete: $hasRunSetup)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var appPathNotice: ToolbarItem<Void, AnyView> {
|
func updateNotice() -> some View {
|
||||||
let controller = ApplicationDirectoryController()
|
guard let update = updater.update else { return AnyView(Spacer()) }
|
||||||
guard !controller.isInApplicationsDirectory else {
|
let severity: NoticeView.Severity
|
||||||
return ToolbarItem { AnyView(EmptyView()) }
|
let text: String
|
||||||
|
if update.critical {
|
||||||
|
severity = .critical
|
||||||
|
text = "Critical Security Update Required"
|
||||||
|
} else {
|
||||||
|
severity = .advisory
|
||||||
|
text = "Update Available"
|
||||||
}
|
}
|
||||||
return ToolbarItem {
|
return AnyView(NoticeView(text: text, severity: severity, actionTitle: "Update") {
|
||||||
AnyView(
|
NSWorkspace.shared.open(update.html_url)
|
||||||
Button(action: {
|
})
|
||||||
showingAppPathNotice = true
|
}
|
||||||
}, label: {
|
|
||||||
Group {
|
func agentNotice() -> some View {
|
||||||
Text("Secretive Is Not in Applications Folder")
|
NoticeView(text: "Secret Agent isn't running. Run setup again to fix.", severity: .advisory, actionTitle: "Run Setup") {
|
||||||
}
|
self.runSetupBlock?()
|
||||||
.font(.headline)
|
|
||||||
.foregroundColor(.white)
|
|
||||||
})
|
|
||||||
.background(Color.orange)
|
|
||||||
.cornerRadius(5)
|
|
||||||
.popover(isPresented: $showingAppPathNotice, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) {
|
|
||||||
VStack {
|
|
||||||
Image(systemName: "exclamationmark.triangle")
|
|
||||||
.resizable()
|
|
||||||
.aspectRatio(contentMode: .fit)
|
|
||||||
.frame(width: 64)
|
|
||||||
Text("Secretive needs to be in your Applications folder to work properly. Please move it and relaunch.")
|
|
||||||
.frame(maxWidth: 300)
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete<SecretType: Secret>(secret: SecretType) {
|
||||||
|
deletingSecret = AnySecret(secret)
|
||||||
|
self.showingDeletion = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var nextDefaultSecret: AnyHashable? {
|
||||||
|
let fallback: AnyHashable
|
||||||
|
if self.storeList.modifiableStore?.isAvailable ?? false {
|
||||||
|
fallback = Constants.emptyStoreModifiableTag
|
||||||
|
} else {
|
||||||
|
fallback = Constants.emptyStoreTag
|
||||||
|
}
|
||||||
|
return self.storeList.stores.compactMap { $0.secrets.first }.first?.id ?? fallback
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate enum Constants {
|
||||||
|
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
||||||
|
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
|
|
||||||
private static let storeList: SecretStoreList = {
|
|
||||||
let list = SecretStoreList()
|
|
||||||
list.add(store: SecureEnclave.Store())
|
|
||||||
list.add(store: SmartCard.Store())
|
|
||||||
return list
|
|
||||||
}()
|
|
||||||
private static let agentStatusChecker = AgentStatusChecker()
|
|
||||||
private static let justUpdatedChecker = JustUpdatedChecker()
|
|
||||||
|
|
||||||
@State var hasRunSetup = false
|
|
||||||
@State private var showingSetup = false
|
|
||||||
@State private var showingCreation = false
|
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
Group {
|
||||||
// Empty on modifiable and nonmodifiable
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)],
|
||||||
ContentView<PreviewUpdater, AgentStatusChecker>(showingCreation: .constant(false), runningSetup: .constant(false), hasRunSetup: .constant(true))
|
modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]),
|
||||||
.environmentObject(Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]))
|
updater: PreviewUpdater(),
|
||||||
.environmentObject(PreviewUpdater())
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
.environmentObject(agentStatusChecker)
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
// 5 items on modifiable and nonmodifiable
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater(),
|
||||||
ContentView<PreviewUpdater, AgentStatusChecker>(showingCreation: .constant(false), runningSetup: .constant(false), hasRunSetup: .constant(true))
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
.environmentObject(Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]))
|
ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
||||||
.environmentObject(PreviewUpdater())
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
.environmentObject(agentStatusChecker)
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .advisory),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker(running: false))
|
||||||
}
|
}
|
||||||
.environmentObject(agentStatusChecker)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct CopyableView: View {
|
|
||||||
|
|
||||||
var title: String
|
|
||||||
var image: Image
|
|
||||||
var text: String
|
|
||||||
|
|
||||||
@State private var interactionState: InteractionState = .normal
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
HStack {
|
|
||||||
image
|
|
||||||
.renderingMode(.template)
|
|
||||||
.imageScale(.large)
|
|
||||||
.foregroundColor(primaryTextColor)
|
|
||||||
Text(title)
|
|
||||||
.font(.headline)
|
|
||||||
.foregroundColor(primaryTextColor)
|
|
||||||
Spacer()
|
|
||||||
if interactionState != .normal {
|
|
||||||
Text(hoverText)
|
|
||||||
.bold()
|
|
||||||
.textCase(.uppercase)
|
|
||||||
.foregroundColor(secondaryTextColor)
|
|
||||||
.transition(.opacity)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
|
|
||||||
Divider()
|
|
||||||
Text(text)
|
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
.foregroundColor(primaryTextColor)
|
|
||||||
.padding(EdgeInsets(top: 10, leading: 20, bottom: 20, trailing: 20))
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
.font(.system(.body, design: .monospaced))
|
|
||||||
}
|
|
||||||
.background(backgroundColor)
|
|
||||||
.frame(minWidth: 150, maxWidth: .infinity)
|
|
||||||
.cornerRadius(10)
|
|
||||||
.onHover { hovering in
|
|
||||||
withAnimation {
|
|
||||||
interactionState = hovering ? .hovering : .normal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onDrag {
|
|
||||||
NSItemProvider(item: NSData(data: text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
|
|
||||||
}
|
|
||||||
.onTapGesture {
|
|
||||||
copy()
|
|
||||||
withAnimation {
|
|
||||||
interactionState = .clicking
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.gesture(
|
|
||||||
TapGesture()
|
|
||||||
.onEnded {
|
|
||||||
withAnimation {
|
|
||||||
interactionState = .normal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var hoverText: String {
|
|
||||||
switch interactionState {
|
|
||||||
case .hovering:
|
|
||||||
return "Click to Copy"
|
|
||||||
case .clicking:
|
|
||||||
return "Copied"
|
|
||||||
case .normal:
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var backgroundColor: Color {
|
|
||||||
let color: NSColor
|
|
||||||
switch interactionState {
|
|
||||||
case .normal:
|
|
||||||
color = .windowBackgroundColor
|
|
||||||
case .hovering:
|
|
||||||
color = .unemphasizedSelectedContentBackgroundColor
|
|
||||||
case .clicking:
|
|
||||||
color = .selectedContentBackgroundColor
|
|
||||||
}
|
|
||||||
return Color(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
var primaryTextColor: Color {
|
|
||||||
let color: NSColor
|
|
||||||
switch interactionState {
|
|
||||||
case .normal, .hovering:
|
|
||||||
color = .textColor
|
|
||||||
case .clicking:
|
|
||||||
color = .white
|
|
||||||
}
|
|
||||||
return Color(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
var secondaryTextColor: Color {
|
|
||||||
let color: NSColor
|
|
||||||
switch interactionState {
|
|
||||||
case .normal, .hovering:
|
|
||||||
color = .secondaryLabelColor
|
|
||||||
case .clicking:
|
|
||||||
color = .white
|
|
||||||
}
|
|
||||||
return Color(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
func copy() {
|
|
||||||
NSPasteboard.general.declareTypes([.string], owner: nil)
|
|
||||||
NSPasteboard.general.setString(text, forType: .string)
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum InteractionState {
|
|
||||||
case normal, hovering, clicking
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
|
|
||||||
struct CopyableView_Previews: PreviewProvider {
|
|
||||||
static var previews: some View {
|
|
||||||
Group {
|
|
||||||
CopyableView(title: "Title", image: Image(systemName: "figure.wave"), text: "Hello world.")
|
|
||||||
CopyableView(title: "Title", image: Image(systemName: "figure.wave"), text: "Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,14 +1,15 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SecretKit
|
import SecretKit
|
||||||
|
|
||||||
struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
struct CreateSecretView: View {
|
||||||
|
|
||||||
@ObservedObject var store: StoreType
|
@ObservedObject var store: AnySecretStoreModifiable
|
||||||
@Binding var showing: Bool
|
|
||||||
|
@State var name = ""
|
||||||
|
@State var requiresAuthentication = true
|
||||||
|
|
||||||
|
var dismissalBlock: () -> ()
|
||||||
|
|
||||||
@State private var name = ""
|
|
||||||
@State private var requiresAuthentication = true
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
HStack {
|
HStack {
|
||||||
@ -23,7 +24,7 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
|||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
Text("Name:")
|
Text("Name:")
|
||||||
TextField("Shhhhh", text: $name).focusable()
|
TextField("Shhhhh", text: $name)
|
||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
Toggle(isOn: $requiresAuthentication) {
|
Toggle(isOn: $requiresAuthentication) {
|
||||||
@ -32,22 +33,22 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
|||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onExitCommand(perform: dismissalBlock)
|
||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("Cancel") {
|
Button(action: dismissalBlock) {
|
||||||
showing = false
|
Text("Cancel")
|
||||||
}
|
}
|
||||||
.keyboardShortcut(.cancelAction)
|
Button(action: save) {
|
||||||
Button("Create", action: save)
|
Text("Create")
|
||||||
.disabled(name.isEmpty)
|
}.disabled(name.isEmpty)
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
}
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
}
|
}
|
||||||
|
|
||||||
func save() {
|
func save() {
|
||||||
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
||||||
showing = false
|
dismissalBlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,20 @@ import SwiftUI
|
|||||||
import SecretKit
|
import SecretKit
|
||||||
|
|
||||||
struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
||||||
|
|
||||||
@ObservedObject var store: StoreType
|
|
||||||
let secret: StoreType.SecretType
|
let secret: StoreType.SecretType
|
||||||
var dismissalBlock: (Bool) -> ()
|
@ObservedObject var store: StoreType
|
||||||
|
|
||||||
@State private var confirm = ""
|
@State var confirm = ""
|
||||||
|
|
||||||
|
fileprivate var dismissalBlock: (Bool) -> ()
|
||||||
|
|
||||||
|
init(secret: StoreType.SecretType, store: StoreType, dismissalBlock: @escaping (Bool) -> ()) {
|
||||||
|
self.secret = secret
|
||||||
|
self.store = store
|
||||||
|
self.dismissalBlock = dismissalBlock
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
HStack {
|
HStack {
|
||||||
@ -31,27 +38,23 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onExitCommand {
|
.onExitCommand {
|
||||||
dismissalBlock(false)
|
self.dismissalBlock(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("Delete", action: delete)
|
Button(action: delete) {
|
||||||
.disabled(confirm != secret.name)
|
Text("Delete")
|
||||||
.keyboardShortcut(.delete)
|
}.disabled(confirm != secret.name)
|
||||||
Button("Don't Delete") {
|
Button(action: { self.dismissalBlock(false) }) {
|
||||||
dismissalBlock(false)
|
Text("Don't Delete")
|
||||||
}
|
}
|
||||||
.keyboardShortcut(.cancelAction)
|
|
||||||
}
|
}
|
||||||
}
|
}.padding()
|
||||||
.padding()
|
|
||||||
.frame(minWidth: 400)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete() {
|
func delete() {
|
||||||
try! store.delete(secret: secret)
|
try! store.delete(secret: secret)
|
||||||
dismissalBlock(true)
|
self.dismissalBlock(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,6 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SecretKit
|
|
||||||
|
|
||||||
struct EmptyStoreView: View {
|
struct EmptyStoreView: View {
|
||||||
|
|
||||||
@ObservedObject var store: AnySecretStore
|
|
||||||
@Binding var activeSecret: AnySecret.ID?
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
if store is AnySecretStoreModifiable {
|
|
||||||
NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: $activeSecret) {
|
|
||||||
Text("No Secrets")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
NavigationLink(destination: EmptyStoreImmutableView(), tag: Constants.emptyStoreTag, selection: $activeSecret) {
|
|
||||||
Text("No Secrets")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension EmptyStoreView {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
|
||||||
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EmptyStoreImmutableView: View {
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@ -76,7 +48,7 @@ struct EmptyStoreModifiableView: View {
|
|||||||
struct EmptyStoreModifiableView_Previews: PreviewProvider {
|
struct EmptyStoreModifiableView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
Group {
|
||||||
EmptyStoreImmutableView()
|
EmptyStoreView()
|
||||||
EmptyStoreModifiableView()
|
EmptyStoreModifiableView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct NoStoresView: View {
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
Text("No Secure Storage Available").bold()
|
|
||||||
Text("Your Mac doesn't have a Secure Enclave, and there's not a compatible Smart Card inserted.")
|
|
||||||
Link("If you're looking to add one to your Mac, the YubiKey 5 Series are great.", destination: URL(string: "https://www.yubico.com/products/compare-yubikey-5-series/")!)
|
|
||||||
}.padding()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
|
|
||||||
struct NoStoresView_Previews: PreviewProvider {
|
|
||||||
static var previews: some View {
|
|
||||||
NoStoresView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
57
Secretive/Views/NoticeView.swift
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct NoticeView: View {
|
||||||
|
|
||||||
|
let text: String
|
||||||
|
let severity: Severity
|
||||||
|
let actionTitle: String?
|
||||||
|
let action: (() -> Void)?
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
Text(text).bold()
|
||||||
|
Spacer()
|
||||||
|
if action != nil {
|
||||||
|
Button(action: action!) {
|
||||||
|
Text(actionTitle!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.padding().background(color)
|
||||||
|
}
|
||||||
|
|
||||||
|
var color: Color {
|
||||||
|
switch severity {
|
||||||
|
case .advisory:
|
||||||
|
return Color.orange
|
||||||
|
case .critical:
|
||||||
|
return Color.red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension NoticeView {
|
||||||
|
|
||||||
|
enum Severity {
|
||||||
|
case advisory, critical
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
|
||||||
|
struct NoticeView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
Group {
|
||||||
|
NoticeView(text: "Agent Not Running", severity: .advisory, actionTitle: "Run Setup") {
|
||||||
|
print("OK")
|
||||||
|
}
|
||||||
|
NoticeView(text: "Critical Security Update Required", severity: .critical, actionTitle: "Update") {
|
||||||
|
print("OK")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -2,34 +2,58 @@ import SwiftUI
|
|||||||
import SecretKit
|
import SecretKit
|
||||||
|
|
||||||
struct SecretDetailView<SecretType: Secret>: View {
|
struct SecretDetailView<SecretType: Secret>: View {
|
||||||
|
|
||||||
@State var secret: SecretType
|
|
||||||
|
|
||||||
private let keyWriter = OpenSSHKeyWriter()
|
@State var secret: SecretType
|
||||||
|
let keyWriter = OpenSSHKeyWriter()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
CopyableView(title: "Fingerprint", image: Image(systemName: "touchid"), text: keyWriter.openSSHFingerprint(secret: secret))
|
GroupBox(label: Text("Fingerprint")) {
|
||||||
Spacer()
|
HStack {
|
||||||
.frame(height: 20)
|
Text(keyWriter.openSSHFingerprint(secret: secret))
|
||||||
CopyableView(title: "Public Key", image: Image(systemName: "key"), text: keyWriter.openSSHString(secret: secret))
|
Spacer()
|
||||||
|
}
|
||||||
|
.frame(minWidth: 150, maxWidth: .infinity)
|
||||||
|
.padding()
|
||||||
|
}.onDrag {
|
||||||
|
return NSItemProvider(item: NSData(data: self.keyWriter.openSSHFingerprint(secret: self.secret).data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
|
||||||
|
}
|
||||||
|
Spacer().frame(height: 10)
|
||||||
|
GroupBox(label: Text("Public Key")) {
|
||||||
|
VStack {
|
||||||
|
Text(keyWriter.openSSHString(secret: secret))
|
||||||
|
.multilineTextAlignment(.leading)
|
||||||
|
.frame(minWidth: 150, maxWidth: .infinity)
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Button(action: copy) {
|
||||||
|
Text("Copy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.onDrag {
|
||||||
|
return NSItemProvider(item: NSData(data: self.keyString.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
|
||||||
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}.padding()
|
||||||
.padding()
|
.frame(minHeight: 150, maxHeight: .infinity)
|
||||||
.frame(minHeight: 200, maxHeight: .infinity)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyString: String {
|
var keyString: String {
|
||||||
keyWriter.openSSHString(secret: secret)
|
keyWriter.openSSHString(secret: secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func copy() {
|
func copy() {
|
||||||
NSPasteboard.general.declareTypes([.string], owner: nil)
|
NSPasteboard.general.declareTypes([.string], owner: nil)
|
||||||
NSPasteboard.general.setString(keyString, forType: .string)
|
NSPasteboard.general.setString(keyString, forType: .string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import SecretKit
|
|
||||||
|
|
||||||
struct SecretListView: View {
|
|
||||||
|
|
||||||
@ObservedObject var store: AnySecretStore
|
|
||||||
@Binding var activeSecret: AnySecret.ID?
|
|
||||||
@Binding var deletingSecret: AnySecret?
|
|
||||||
|
|
||||||
var deletedSecret: (AnySecret) -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
ForEach(store.secrets) { secret in
|
|
||||||
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: $activeSecret) {
|
|
||||||
Text(secret.name)
|
|
||||||
}.contextMenu {
|
|
||||||
if store is AnySecretStoreModifiable {
|
|
||||||
Button(action: { delete(secret: secret) }) {
|
|
||||||
Text("Delete")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.popover(isPresented: .constant(deletingSecret == secret)) {
|
|
||||||
if let modifiable = store as? AnySecretStoreModifiable {
|
|
||||||
DeleteSecretView(store: modifiable, secret: secret) { deleted in
|
|
||||||
deletingSecret = nil
|
|
||||||
if deleted {
|
|
||||||
deletedSecret(AnySecret(secret))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func delete<SecretType: Secret>(secret: SecretType) {
|
|
||||||
deletingSecret = AnySecret(secret)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,226 +1,101 @@
|
|||||||
|
import Foundation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import ServiceManagement
|
||||||
|
|
||||||
struct SetupView: View {
|
struct SetupView: View {
|
||||||
|
|
||||||
@State var stepIndex = 0
|
var completion: ((Bool) -> Void)?
|
||||||
@Binding var visible: Bool
|
|
||||||
@Binding var setupComplete: Bool
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { proxy in
|
Form {
|
||||||
VStack {
|
SetupStepView<Spacer>(text: "Secretive needs to install a helper app to sign requests when the main app isn't running. This app is called \"SecretAgent\" and you might see it in Activity Manager from time to time.",
|
||||||
StepView(numberOfSteps: 3, currentStep: stepIndex, width: proxy.size.width)
|
index: 1,
|
||||||
GeometryReader { _ in
|
nestedView: nil,
|
||||||
HStack(spacing: 0) {
|
actionText: "Install") {
|
||||||
SecretAgentSetupView(buttonAction: advance)
|
self.installLaunchAgent()
|
||||||
.frame(width: proxy.size.width)
|
}
|
||||||
SSHAgentSetupView(buttonAction: advance)
|
SetupStepView(text: "You need to add a line to your shell config (.bashrc or .zshrc) telling SSH to talk to SecretAgent when it wants to authenticate. Drag this into your config file.",
|
||||||
.frame(width: proxy.size.width)
|
index: 2,
|
||||||
UpdaterExplainerView {
|
nestedView: SetupStepCommandView(text: Constants.socketPrompt),
|
||||||
visible = false
|
actionText: "Added") {
|
||||||
setupComplete = true
|
self.markAsDone()
|
||||||
}
|
|
||||||
.frame(width: proxy.size.width)
|
|
||||||
}
|
|
||||||
.offset(x: -proxy.size.width * CGFloat(stepIndex), y: 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.frame(idealWidth: 500, idealHeight: 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func advance() {
|
|
||||||
withAnimation(.spring()) {
|
|
||||||
stepIndex += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StepView: View {
|
|
||||||
|
|
||||||
let numberOfSteps: Int
|
|
||||||
let currentStep: Int
|
|
||||||
|
|
||||||
// Ideally we'd have a geometry reader inside this view doing this for us, but that crashes on 11.0b7
|
|
||||||
let width: CGFloat
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
ZStack(alignment: .leading) {
|
|
||||||
Rectangle()
|
|
||||||
.foregroundColor(.blue)
|
|
||||||
.frame(height: 5)
|
|
||||||
Rectangle()
|
|
||||||
.foregroundColor(.green)
|
|
||||||
.frame(width: max(0, ((width - (Constants.padding * 2)) / CGFloat(numberOfSteps - 1)) * CGFloat(currentStep) - (Constants.circleWidth / 2)), height: 5)
|
|
||||||
.animation(.spring())
|
|
||||||
HStack {
|
HStack {
|
||||||
ForEach(0..<numberOfSteps) { index in
|
Spacer()
|
||||||
ZStack {
|
Button(action: { self.completion?(true) }) {
|
||||||
if currentStep > index {
|
Text("Finish")
|
||||||
Circle()
|
|
||||||
.foregroundColor(.green)
|
|
||||||
.frame(width: Constants.circleWidth, height: Constants.circleWidth)
|
|
||||||
Text("✓")
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.bold()
|
|
||||||
} else {
|
|
||||||
Circle()
|
|
||||||
.foregroundColor(.blue)
|
|
||||||
.frame(width: Constants.circleWidth, height: Constants.circleWidth)
|
|
||||||
if currentStep == index {
|
|
||||||
Circle()
|
|
||||||
.strokeBorder(Color.white, lineWidth: 3)
|
|
||||||
.frame(width: Constants.circleWidth, height: Constants.circleWidth)
|
|
||||||
}
|
|
||||||
Text(String(describing: index + 1))
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.bold()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if index < numberOfSteps - 1 {
|
.padding()
|
||||||
Spacer(minLength: 30)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.padding(Constants.padding)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension StepView {
|
|
||||||
|
|
||||||
enum Constants {
|
|
||||||
|
|
||||||
static let padding: CGFloat = 15
|
|
||||||
static let circleWidth: CGFloat = 30
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SetupStepView<Content> : View where Content : View {
|
|
||||||
|
|
||||||
let title: String
|
|
||||||
let image: Image
|
|
||||||
let bodyText: String
|
|
||||||
let buttonTitle: String
|
|
||||||
let buttonAction: () -> Void
|
|
||||||
let content: Content
|
|
||||||
|
|
||||||
init(title: String, image: Image, bodyText: String, buttonTitle: String, buttonAction: @escaping () -> Void = {}, @ViewBuilder content: () -> Content) {
|
|
||||||
self.title = title
|
|
||||||
self.image = image
|
|
||||||
self.bodyText = bodyText
|
|
||||||
self.buttonTitle = buttonTitle
|
|
||||||
self.buttonAction = buttonAction
|
|
||||||
self.content = content()
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
Text(title)
|
|
||||||
.font(.title)
|
|
||||||
Spacer()
|
|
||||||
image
|
|
||||||
.resizable()
|
|
||||||
.aspectRatio(contentMode: .fit)
|
|
||||||
.frame(width: 64)
|
|
||||||
Spacer()
|
|
||||||
Text(bodyText)
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
Spacer()
|
|
||||||
content
|
|
||||||
Spacer()
|
|
||||||
Button(buttonTitle) {
|
|
||||||
buttonAction()
|
|
||||||
}
|
|
||||||
}.padding()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SecretAgentSetupView: View {
|
|
||||||
|
|
||||||
let buttonAction: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
SetupStepView(title: "Setup Secret Agent",
|
|
||||||
image: Image(nsImage: NSApp.applicationIconImage),
|
|
||||||
bodyText: "Secretive needs to set up a helper app to work properly. It will sign requests from SSH clients in the background, so you don't need to keep the main Secretive app open.",
|
|
||||||
buttonTitle: "Install",
|
|
||||||
buttonAction: install) {
|
|
||||||
(Text("This helper app is called ") + Text("Secret Agent").bold().underline() + Text(" and you may see it in Activity Manager from time to time."))
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func install() {
|
|
||||||
LaunchAgentController().install()
|
|
||||||
buttonAction()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SSHAgentSetupView: View {
|
|
||||||
|
|
||||||
let buttonAction: () -> Void
|
|
||||||
|
|
||||||
private static let controller = ShellConfigurationController()
|
|
||||||
@State private var selectedShellInstruction: ShellConfigInstruction = controller.shellInstructions.first!
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
SetupStepView(title: "Configure your SSH Agent",
|
|
||||||
image: Image(systemName: "terminal"),
|
|
||||||
bodyText: "Add this line to your shell config telling SSH to talk to Secret Agent when it wants to authenticate. Secretive can either do this for you automatically, or you can copy and paste this into your config file.",
|
|
||||||
buttonTitle: "I Added it Manually",
|
|
||||||
buttonAction: buttonAction) {
|
|
||||||
Link("If you're trying to set up a third party app, check out the FAQ.", destination: URL(string: "https://github.com/maxgoedjen/secretive/blob/main/APP_CONFIG.md")!)
|
|
||||||
Picker(selection: $selectedShellInstruction, label: EmptyView()) {
|
|
||||||
ForEach(SSHAgentSetupView.controller.shellInstructions) { instruction in
|
|
||||||
Text(instruction.shell)
|
|
||||||
.tag(instruction)
|
|
||||||
.padding()
|
|
||||||
}
|
|
||||||
}.pickerStyle(SegmentedPickerStyle())
|
|
||||||
CopyableView(title: "Add to \(selectedShellInstruction.shellConfigPath)", image: Image(systemName: "greaterthan.square"), text: selectedShellInstruction.text)
|
|
||||||
Button("Add it For Me") {
|
|
||||||
let controller = ShellConfigurationController()
|
|
||||||
if controller.addToShell(shellInstructions: selectedShellInstruction) {
|
|
||||||
buttonAction()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Delegate: NSObject, NSOpenSavePanelDelegate {
|
struct SetupStepView<NestedViewType: View>: View {
|
||||||
|
|
||||||
private let name: String
|
let text: String
|
||||||
|
let index: Int
|
||||||
init(name: String) {
|
let nestedView: NestedViewType?
|
||||||
self.name = name
|
@State var completed = false
|
||||||
}
|
let actionText: String
|
||||||
|
let action: (() -> Bool)
|
||||||
func panel(_ sender: Any, shouldEnable url: URL) -> Bool {
|
|
||||||
return url.lastPathComponent == name
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct UpdaterExplainerView: View {
|
|
||||||
|
|
||||||
let buttonAction: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SetupStepView(title: "Updates",
|
Section {
|
||||||
image: Image(systemName: "dot.radiowaves.left.and.right"),
|
HStack {
|
||||||
bodyText: "Secretive will periodically check with GitHub to see if there's a new release. If you see any network requests to GitHub, that's why.",
|
ZStack {
|
||||||
buttonTitle: "Okay",
|
if completed {
|
||||||
buttonAction: buttonAction) {
|
Circle().foregroundColor(.green)
|
||||||
Link("Read more about this here.", destination: SetupView.Constants.updaterFAQURL)
|
.frame(width: 30, height: 30)
|
||||||
|
Text("✓")
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.bold()
|
||||||
|
} else {
|
||||||
|
Circle().foregroundColor(.blue)
|
||||||
|
.frame(width: 30, height: 30)
|
||||||
|
Text(String(describing: index))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.bold()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
VStack {
|
||||||
|
Text(text)
|
||||||
|
.opacity(completed ? 0.5 : 1)
|
||||||
|
.lineLimit(nil)
|
||||||
|
.frame(idealHeight: 0, maxHeight: .infinity)
|
||||||
|
if nestedView != nil {
|
||||||
|
Spacer()
|
||||||
|
nestedView!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
Button(action: {
|
||||||
|
self.completed = self.action()
|
||||||
|
}) {
|
||||||
|
Text(actionText)
|
||||||
|
}.disabled(completed)
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SetupStepCommandView: View {
|
||||||
|
|
||||||
|
let text: String
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(.caption, design: .monospaced))
|
||||||
|
.lineLimit(nil)
|
||||||
|
.frame(idealHeight: 0, maxHeight: .infinity)
|
||||||
|
.padding()
|
||||||
|
.background(Color(white: 0, opacity: 0.10))
|
||||||
|
.cornerRadius(10)
|
||||||
|
.onDrag {
|
||||||
|
return NSItemProvider(item: NSData(data: self.text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,25 +103,21 @@ struct UpdaterExplainerView: View {
|
|||||||
|
|
||||||
extension SetupView {
|
extension SetupView {
|
||||||
|
|
||||||
enum Constants {
|
func installLaunchAgent() -> Bool {
|
||||||
static let updaterFAQURL = URL(string: "https://github.com/maxgoedjen/secretive/blob/main/FAQ.md#whats-this-network-request-to-github")!
|
SMLoginItemSetEnabled("com.maxgoedjen.Secretive.SecretAgent" as CFString, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func markAsDone() -> Bool {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ShellConfigInstruction: Identifiable, Hashable {
|
extension SetupView {
|
||||||
|
|
||||||
var shell: String
|
enum Constants {
|
||||||
var shellConfigDirectory: String
|
static let socketPath = (NSHomeDirectory().replacingOccurrences(of: "com.maxgoedjen.Secretive.Host", with: "com.maxgoedjen.Secretive.SecretAgent") as NSString).appendingPathComponent("socket.ssh") as String
|
||||||
var shellConfigFilename: String
|
static let socketPrompt = "export SSH_AUTH_SOCK=\(socketPath)"
|
||||||
var text: String
|
|
||||||
|
|
||||||
var id: String {
|
|
||||||
shell
|
|
||||||
}
|
|
||||||
|
|
||||||
var shellConfigPath: String {
|
|
||||||
return (shellConfigDirectory as NSString).appendingPathComponent(shellConfigFilename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -254,43 +125,9 @@ struct ShellConfigInstruction: Identifiable, Hashable {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|
||||||
struct SetupView_Previews: PreviewProvider {
|
struct SetupView_Previews: PreviewProvider {
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
SetupView()
|
||||||
SetupView(visible: .constant(true), setupComplete: .constant(false))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SecretAgentSetupView_Previews: PreviewProvider {
|
|
||||||
|
|
||||||
static var previews: some View {
|
|
||||||
Group {
|
|
||||||
SecretAgentSetupView(buttonAction: {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SSHAgentSetupView_Previews: PreviewProvider {
|
|
||||||
|
|
||||||
static var previews: some View {
|
|
||||||
Group {
|
|
||||||
SSHAgentSetupView(buttonAction: {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct UpdaterExplainerView_Previews: PreviewProvider {
|
|
||||||
|
|
||||||
static var previews: some View {
|
|
||||||
Group {
|
|
||||||
UpdaterExplainerView(buttonAction: {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import SecretKit
|
|
||||||
|
|
||||||
struct StoreListView: View {
|
|
||||||
|
|
||||||
@Binding var showingCreation: Bool
|
|
||||||
|
|
||||||
@State private var activeSecret: AnySecret.ID?
|
|
||||||
@State private var deletingSecret: AnySecret?
|
|
||||||
|
|
||||||
@EnvironmentObject private var storeList: SecretStoreList
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
NavigationView {
|
|
||||||
List(selection: $activeSecret) {
|
|
||||||
ForEach(storeList.stores) { store in
|
|
||||||
if store.isAvailable {
|
|
||||||
Section(header: Text(store.name)) {
|
|
||||||
if store.secrets.isEmpty {
|
|
||||||
EmptyStoreView(store: store, activeSecret: $activeSecret)
|
|
||||||
} else {
|
|
||||||
SecretListView(store: store, activeSecret: $activeSecret, deletingSecret: $deletingSecret, deletedSecret: { _ in
|
|
||||||
activeSecret = nextDefaultSecret
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.listStyle(SidebarListStyle())
|
|
||||||
.onAppear {
|
|
||||||
activeSecret = nextDefaultSecret
|
|
||||||
}
|
|
||||||
.frame(minWidth: 100, idealWidth: 240)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extension StoreListView {
|
|
||||||
|
|
||||||
var nextDefaultSecret: AnyHashable? {
|
|
||||||
let fallback: AnyHashable
|
|
||||||
if storeList.modifiableStore?.isAvailable ?? false {
|
|
||||||
fallback = EmptyStoreView.Constants.emptyStoreModifiableTag
|
|
||||||
} else {
|
|
||||||
fallback = EmptyStoreView.Constants.emptyStoreTag
|
|
||||||
}
|
|
||||||
return storeList.stores.compactMap(\.secrets.first).first?.id ?? fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import Brief
|
|
||||||
|
|
||||||
struct UpdateDetailView<UpdaterType: Updater>: View {
|
|
||||||
|
|
||||||
@EnvironmentObject var updater: UpdaterType
|
|
||||||
|
|
||||||
let update: Release
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
Text("Secretive \(update.name)").font(.title)
|
|
||||||
GroupBox(label: Text("Release Notes")) {
|
|
||||||
ScrollView {
|
|
||||||
attributedBody
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HStack {
|
|
||||||
if !update.critical {
|
|
||||||
Button("Ignore") {
|
|
||||||
updater.ignore(release: update)
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
Button("Update") {
|
|
||||||
NSWorkspace.shared.open(update.html_url)
|
|
||||||
}
|
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
.frame(maxWidth: 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
var attributedBody: Text {
|
|
||||||
var text = Text("")
|
|
||||||
for line in update.body.split(whereSeparator: \.isNewline) {
|
|
||||||
let attributed: Text
|
|
||||||
let split = line.split(separator: " ")
|
|
||||||
let unprefixed = split.dropFirst().joined()
|
|
||||||
if let prefix = split.first {
|
|
||||||
switch prefix {
|
|
||||||
case "#":
|
|
||||||
attributed = Text(unprefixed).font(.title) + Text("\n")
|
|
||||||
case "##":
|
|
||||||
attributed = Text(unprefixed).font(.title2) + Text("\n")
|
|
||||||
case "###":
|
|
||||||
attributed = Text(unprefixed).font(.title3) + Text("\n")
|
|
||||||
default:
|
|
||||||
attributed = Text(line) + Text("\n\n")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
attributed = Text(line) + Text("\n\n")
|
|
||||||
}
|
|
||||||
text = text + attributed
|
|
||||||
}
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +1,11 @@
|
|||||||
|
//
|
||||||
|
// SecretiveTests.swift
|
||||||
|
// SecretiveTests
|
||||||
|
//
|
||||||
|
// Created by Max Goedjen on 2/18/20.
|
||||||
|
// Copyright © 2020 Max Goedjen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
import XCTest
|
import XCTest
|
||||||
@testable import Secretive
|
@testable import Secretive
|
||||||
|
|
||||||
|