Skip to content

Commit 149aa77

Browse files
author
Carlos Cabanero
committed
Default Agent configuration
1 parent 840b3c1 commit 149aa77

File tree

11 files changed

+497
-158
lines changed

11 files changed

+497
-158
lines changed

Blink.xcodeproj/project.pbxproj

+16-4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
BD8DB648279B512900497C88 /* CodeFileSystemService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8DB646279B512900497C88 /* CodeFileSystemService.swift */; };
140140
BD90BE4A2A18466E00DA5686 /* AgentForwardPromptPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD90BE492A18466E00DA5686 /* AgentForwardPromptPickerView.swift */; };
141141
BD98AC84260BD8DC00B4E6A1 /* SSHAgentAdd.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD98AC83260BD8DC00B4E6A1 /* SSHAgentAdd.swift */; };
142-
BD98AC95260BE20000B4E6A1 /* SSHAgentPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD98AC94260BE20000B4E6A1 /* SSHAgentPool.swift */; };
142+
BD98AC95260BE20000B4E6A1 /* SSHDefaultAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD98AC94260BE20000B4E6A1 /* SSHDefaultAgent.swift */; };
143143
BD9BF7E7262A6B0300B02074 /* SOCKS.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD9BF7E3262A6B0300B02074 /* SOCKS.swift */; };
144144
BD9BF7E9262A6B0F00B02074 /* SOCKSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD9BF7E8262A6B0F00B02074 /* SOCKSTests.swift */; };
145145
BD9EA1802718D6C400874007 /* NSFileProviderError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD9EA17C2718D6C400874007 /* NSFileProviderError.swift */; };
@@ -199,6 +199,7 @@
199199
BDF2B8D82BC4820F00B9C7EA /* curl_ios.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BDF2B8D62BC481F000B9C7EA /* curl_ios.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
200200
BDF2B8DD2BC48D2800B9C7EA /* LibSSH.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2334EC425C1C04700385378 /* LibSSH.xcframework */; };
201201
BDF2B8DF2BC48D2D00B9C7EA /* libssh2.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2F64C9525CA99AD00F2225D /* libssh2.xcframework */; };
202+
BDF40FEB2C14A6CE00DF41C1 /* AgentSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF40FE92C14A6CE00DF41C1 /* AgentSettingsView.swift */; };
202203
BDF471BA268CD17B00A7A41B /* SSH.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 07FABB8425C9AEC000E1CC2C /* SSH.framework */; };
203204
C94437571D8311960096F84E /* BKResource.m in Sources */ = {isa = PBXBuildFile; fileRef = C94437561D8311960096F84E /* BKResource.m */; };
204205
C94437601D831CD30096F84E /* Themes in Resources */ = {isa = PBXBuildFile; fileRef = C944375F1D831CD30096F84E /* Themes */; };
@@ -861,7 +862,7 @@
861862
BD8DB646279B512900497C88 /* CodeFileSystemService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodeFileSystemService.swift; sourceTree = "<group>"; };
862863
BD90BE492A18466E00DA5686 /* AgentForwardPromptPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgentForwardPromptPickerView.swift; sourceTree = "<group>"; };
863864
BD98AC83260BD8DC00B4E6A1 /* SSHAgentAdd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHAgentAdd.swift; sourceTree = "<group>"; };
864-
BD98AC94260BE20000B4E6A1 /* SSHAgentPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHAgentPool.swift; sourceTree = "<group>"; };
865+
BD98AC94260BE20000B4E6A1 /* SSHDefaultAgent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHDefaultAgent.swift; sourceTree = "<group>"; };
865866
BD9BF7E3262A6B0300B02074 /* SOCKS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SOCKS.swift; sourceTree = "<group>"; };
866867
BD9BF7E8262A6B0F00B02074 /* SOCKSTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SOCKSTests.swift; sourceTree = "<group>"; };
867868
BD9EA17C2718D6C400874007 /* NSFileProviderError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSFileProviderError.swift; sourceTree = "<group>"; };
@@ -913,6 +914,7 @@
913914
BDE84C772BB33AD700457391 /* vim.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = vim.xcframework; path = xcfs/.build/artifacts/xcfs/vim/vim.xcframework; sourceTree = SOURCE_ROOT; };
914915
BDEEE36B2B8951D3003003FD /* get_frameworks.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = get_frameworks.sh; sourceTree = "<group>"; };
915916
BDF2B8D62BC481F000B9C7EA /* curl_ios.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = curl_ios.xcframework; path = xcfs/.build/artifacts/xcfs/curl_ios/curl_ios.xcframework; sourceTree = SOURCE_ROOT; };
917+
BDF40FE92C14A6CE00DF41C1 /* AgentSettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgentSettingsView.swift; sourceTree = "<group>"; };
916918
C94437551D8311960096F84E /* BKResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BKResource.h; sourceTree = "<group>"; };
917919
C94437561D8311960096F84E /* BKResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BKResource.m; sourceTree = "<group>"; };
918920
C944375F1D831CD30096F84E /* Themes */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Themes; sourceTree = "<group>"; };
@@ -1535,7 +1537,7 @@
15351537
07FAB8EE25C8E6C500E1CC2C /* SSHConfig.swift */,
15361538
07FAB8EF25C8E6C500E1CC2C /* SSHConfigProvider.swift */,
15371539
BD98AC83260BD8DC00B4E6A1 /* SSHAgentAdd.swift */,
1538-
BD98AC94260BE20000B4E6A1 /* SSHAgentPool.swift */,
1540+
BD98AC94260BE20000B4E6A1 /* SSHDefaultAgent.swift */,
15391541
BDE7125C2A141E3100164F70 /* SSHAgentUserPrompt.swift */,
15401542
);
15411543
path = ssh;
@@ -1833,6 +1835,14 @@
18331835
path = BlinkConfigTests;
18341836
sourceTree = "<group>";
18351837
};
1838+
BDF40FEA2C14A6CE00DF41C1 /* AgentSettings */ = {
1839+
isa = PBXGroup;
1840+
children = (
1841+
BDF40FE92C14A6CE00DF41C1 /* AgentSettingsView.swift */,
1842+
);
1843+
path = AgentSettings;
1844+
sourceTree = "<group>";
1845+
};
18361846
C989E53B1D6CC488003E0079 /* BKHosts */ = {
18371847
isa = PBXGroup;
18381848
children = (
@@ -1924,6 +1934,7 @@
19241934
C9B2E0141D6B612300B89F69 /* ViewControllers */ = {
19251935
isa = PBXGroup;
19261936
children = (
1937+
BDF40FEA2C14A6CE00DF41C1 /* AgentSettings */,
19271938
D21076992A69231D00B3D77E /* Snippets */,
19281939
D2B788862949E8A400F19E4F /* Build */,
19291940
D2AD8E8527A2C81900DED28D /* Subscriptions */,
@@ -3298,7 +3309,7 @@
32983309
07F670761D05EEE200C0A53C /* SSHCopyIDSession.m in Sources */,
32993310
D264D2B428F84592002B1B14 /* Models.swift in Sources */,
33003311
D22B16D828CF6ED20004EEC1 /* NewPasskeyView.swift in Sources */,
3301-
BD98AC95260BE20000B4E6A1 /* SSHAgentPool.swift in Sources */,
3312+
BD98AC95260BE20000B4E6A1 /* SSHDefaultAgent.swift in Sources */,
33023313
D2C244352390FEEF0082C69C /* KeyBindingAction.swift in Sources */,
33033314
D241CBDA23040734003D64A5 /* KBTraits.swift in Sources */,
33043315
B752EE2B1DFEF19D00E305C8 /* BKUserConfigurationManager.m in Sources */,
@@ -3441,6 +3452,7 @@
34413452
D22277FE2A26204900D4C708 /* SnippetView.swift in Sources */,
34423453
D2499BEC2362EFD40009C701 /* cpp.cpp in Sources */,
34433454
D264D2B328F84592002B1B14 /* UnavailErrorView.swift in Sources */,
3455+
BDF40FEB2C14A6CE00DF41C1 /* AgentSettingsView.swift in Sources */,
34443456
D2B788852949C53100F19E4F /* BuildView.swift in Sources */,
34453457
D20CBA5A2360324100D93301 /* CompleteUtils.swift in Sources */,
34463458
D265FBC9231905AC0017EAC4 /* NSCoder+CodingKey.swift in Sources */,

Blink/Commands/ssh/SSHAgentAdd.swift

+38-47
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,43 @@ import ios_system
4040
struct BlinkSSHAgentAddCommand: ParsableCommand {
4141
static var configuration = CommandConfiguration(
4242
commandName: "ssh-agent",
43-
abstract: "Blink Agent Control",
43+
abstract: "Blink Default Agent Control",
4444
discussion: """
45+
You can also configure the default agent from Settings > Agent.
4546
""",
4647
version: "1.0.0"
4748
)
48-
49+
4950
@Flag(name: [.customShort("L")],
5051
help: "List keys stored on agent")
5152
var list: Bool = false
52-
53+
5354
@Flag(name: [.customShort("l")],
5455
help: "Lists fingerprints of keys stored on agent")
5556
var listFingerprints: Bool = false
56-
57+
5758
// Remove
5859
@Flag(name: [.customShort("d")],
5960
help: "Remove key from agent")
6061
var remove: Bool = false
61-
62+
6263
// Hash algorithm
6364
@Option(
6465
name: [.customShort("E")],
6566
help: "Specify hash algorithm used for fingerprints"
6667
)
6768
var hashAlgorithm: String = "sha256"
68-
69-
@Flag(name: [.customShort("c")],
70-
help: "Confirm before using identity"
71-
)
72-
var askConfirmation: Bool = false
69+
70+
// @Flag(name: [.customShort("c")],
71+
// help: "Confirm before using identity"
72+
// )
73+
// var askConfirmation: Bool = false
7374

7475
@Argument(help: "Key name")
7576
var keyName: String?
76-
77-
@Argument(help: "Agent name")
78-
var agentName: String?
77+
78+
// @Argument(help: "Agent name")
79+
// var agentName: String?
7980
}
8081

8182
@_cdecl("blink_ssh_add")
@@ -91,80 +92,70 @@ public func blink_ssh_add(argc: Int32, argv: Argv) -> Int32 {
9192

9293
public class BlinkSSHAgentAdd: NSObject {
9394
var command: BlinkSSHAgentAddCommand!
94-
95+
9596
var stdout = OutputStream(file: thread_stdout)
9697
var stderr = OutputStream(file: thread_stderr)
9798
let currentRunLoop = RunLoop.current
98-
99+
99100
public func start(_ argc: Int32, argv: [String], session: MCPSession) -> Int32 {
100-
let bkConfig: BKConfig
101-
do {
102-
bkConfig = try BKConfig()
103-
command = try BlinkSSHAgentAddCommand.parse(Array(argv[1...]))
101+
do {
102+
command = try BlinkSSHAgentAddCommand.parse(Array(argv[1...]))
104103
} catch {
105104
let message = BlinkSSHAgentAddCommand.message(for: error)
106105
print(message, to: &stderr)
107106
return -1
108107
}
109-
108+
109+
let _ = SSHDefaultAgent.instance
110+
110111
if command.remove {
111112
let keyName = command.keyName ?? "id_rsa"
112-
if let _ = SSHAgentPool.removeKey(named: keyName) {
113+
do {
114+
let _ = try SSHDefaultAgent.removeKey(named: keyName)
113115
print("Key \(keyName) removed.", to: &stdout)
114116
return 0
115-
} else {
116-
print("Key not found on Agent", to: &stderr)
117+
} catch {
118+
print("Couldn't remove key: \(error)", to: &stderr)
117119
return -1
118120
}
119121
}
120-
122+
121123
if command.list {
122-
for key in SSHAgentPool.get()?.ring ?? [] {
124+
for key in SSHDefaultAgent.instance.ring {
123125
let str = BKPubKey.withID(key.name)?.publicKey ?? ""
124126
print("\(str) \(key.name)", to: &stdout)
125127
}
126-
128+
127129
return 0;
128130
}
129-
131+
130132
if command.listFingerprints {
131133
guard
132134
let alg = SSHDigest(rawValue: command.hashAlgorithm)
133135
else {
134136
print("Invalid hash algorithm \"\(command.hashAlgorithm)\"", to: &stderr)
135137
return -1;
136138
}
137-
138-
for key in SSHAgentPool.get()?.ring ?? [] {
139+
140+
for key in SSHDefaultAgent.instance.ring {
139141
if let blob = try? key.signer.publicKey.encode()[4...],
140142
let sshkey = try? SSHKey(fromPublicBlob: blob)
141143
{
142144
let str = sshkey.fingerprint(digest: alg)
143-
145+
144146
print("\(sshkey.size) \(str) \(key.name) (\(sshkey.sshKeyType.shortName))", to: &stdout)
145147
}
146148
}
147149
return 0
148150
}
149-
150-
// TODO Can we have the same key under different constraints?
151-
151+
152152
// Default case: add key
153-
if let (signer, name) = bkConfig.signer(forIdentity: command.keyName ?? "id_rsa") {
154-
if let signer = signer as? BlinkConfig.InputPrompter {
155-
signer.setPromptOnView(session.device.view)
156-
}
157-
var constraints: [SSHAgentConstraint]? = nil
158-
if command.askConfirmation {
159-
constraints = [SSHAgentUserPrompt()]
160-
}
161-
162-
SSHAgentPool.addKey(signer, named: name, constraints: constraints)
163-
print("Key \(name) - added to agent.", to: &stdout)
153+
do {
154+
try SSHDefaultAgent.addKey(named: command.keyName ?? "id_rsa")
164155
return 0
165-
} else {
166-
print("Key not found", to: &stderr)
167-
return -1
156+
} catch {
157+
print("Could not add key \(error)", to: &stderr)
158+
return -1;
168159
}
169160
}
170161
}

Blink/Commands/ssh/SSHAgentPool.swift

-74
This file was deleted.

Blink/Commands/ssh/SSHConfigProvider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ extension SSHClientConfigProvider {
142142
}
143143

144144
// Link to Default Agent
145-
agent.linkTo(agent: SSHAgentPool.defaultAgent)
145+
agent.linkTo(agent: SSHDefaultAgent.instance)
146146
return agent
147147
}
148148

0 commit comments

Comments
 (0)