mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
WORKS!!!!! PUBKEY ON IOS!!!!!!
no file import rn
This commit is contained in:
@@ -171,29 +171,32 @@ class SSHHandler: ObservableObject {
|
||||
withAnimation { authorized = false }
|
||||
return
|
||||
}
|
||||
|
||||
var status: Int32
|
||||
let fileManager = FileManager.default
|
||||
let tempDir = fileManager.temporaryDirectory
|
||||
let tempPubkey = tempDir.appendingPathComponent("key.pub")
|
||||
let tempKey = tempDir.appendingPathComponent("key")
|
||||
|
||||
print(pubInp)
|
||||
var pubInpCChar: [Int8] = []
|
||||
for byte in pubInp {
|
||||
pubInpCChar.append(Int8(byte))
|
||||
}
|
||||
fileManager.createFile(atPath: tempPubkey.path(), contents: nil)
|
||||
fileManager.createFile(atPath: tempKey.path(), contents: nil)
|
||||
|
||||
var privInpCChar: [Int8] = []
|
||||
for byte in privInp {
|
||||
privInpCChar.append(Int8(byte))
|
||||
}
|
||||
let attributes: [FileAttributeKey: Any] = [.posixPermissions: 0o600]
|
||||
try? fileManager.setAttributes(attributes, ofItemAtPath: tempPubkey.path())
|
||||
try? fileManager.setAttributes(attributes, ofItemAtPath: tempKey.path())
|
||||
|
||||
try? pubInp.write(to: tempPubkey)
|
||||
try? privInp.write(to: tempKey)
|
||||
|
||||
var pubkey: ssh_key?
|
||||
|
||||
ssh_pki_import_pubkey_base64(&pubInpCChar, SSH_KEYTYPE_SK_ED25519, &pubkey)
|
||||
ssh_pki_import_pubkey_file(tempPubkey.path(), &pubkey)
|
||||
status = ssh_userauth_try_publickey(session, nil, pubkey)
|
||||
print(status)
|
||||
|
||||
var privkey: ssh_key?
|
||||
if ssh_pki_import_privkey_base64(&privInpCChar, pass, nil, nil, &privkey) != 0 {
|
||||
if ssh_pki_import_privkey_file(tempKey.path(), pass, nil, nil, &privkey) != 0 {
|
||||
print("help?!?")
|
||||
print("likeley passphrase is incorrect")
|
||||
print("likeley password is incorrect")
|
||||
}
|
||||
|
||||
status = ssh_userauth_publickey(session, nil, privkey)
|
||||
@@ -206,6 +209,11 @@ class SSHHandler: ObservableObject {
|
||||
withAnimation { authorized = true }
|
||||
return
|
||||
//if u got this far, youre authed!
|
||||
//cleanpu here:
|
||||
//ssh_key_free(pubkey)
|
||||
//ssh_key_free(privkey)
|
||||
//try? fileManager.removeItem(at: tempPubkey)
|
||||
//try? fileManager.removeItem(at: tempKey)
|
||||
}
|
||||
|
||||
func authWithPw() -> Bool {
|
||||
|
||||
@@ -64,7 +64,8 @@ struct ConnectionView: View {
|
||||
HStack {
|
||||
TextField("", text: $pubkeyStr, prompt: Text("Public Key"))
|
||||
.onSubmit {
|
||||
pubkey = Data(pubkeyStr.utf8)
|
||||
let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "")
|
||||
pubkey = Data(newStr.utf8)
|
||||
}
|
||||
Button() {
|
||||
pubPickerPresented.toggle()
|
||||
@@ -75,6 +76,11 @@ struct ConnectionView: View {
|
||||
.fileImporter(isPresented: $pubPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||
do {
|
||||
let fileURL = try Result.get()
|
||||
guard fileURL.startAccessingSecurityScopedResource() else {
|
||||
print("cant acces file")
|
||||
return
|
||||
}
|
||||
defer { fileURL.stopAccessingSecurityScopedResource() }
|
||||
pubkey = try? Data(contentsOf: fileURL)
|
||||
print(fileURL)
|
||||
} catch {
|
||||
@@ -86,7 +92,8 @@ struct ConnectionView: View {
|
||||
HStack {
|
||||
TextField("", text: $privkeyStr, prompt: Text("Private Key"))
|
||||
.onSubmit {
|
||||
privkey = Data(privkeyStr.utf8)
|
||||
let newStr = privkeyStr.replacingOccurrences(of: "\r\n", with: "")
|
||||
privkey = Data(newStr.utf8)
|
||||
}
|
||||
Button() {
|
||||
privPickerPresented.toggle()
|
||||
@@ -97,6 +104,11 @@ struct ConnectionView: View {
|
||||
.fileImporter(isPresented: $privPickerPresented, allowedContentTypes: [.item, .content, .data]) { (Result) in
|
||||
do {
|
||||
let fileURL = try Result.get()
|
||||
guard fileURL.startAccessingSecurityScopedResource() else {
|
||||
print("cant access file")
|
||||
return
|
||||
}
|
||||
defer { fileURL.stopAccessingSecurityScopedResource() }
|
||||
privkey = try? Data(contentsOf: fileURL)
|
||||
print(privkey)
|
||||
print(fileURL)
|
||||
@@ -150,7 +162,7 @@ struct ConnectionView: View {
|
||||
handler.host.key = hostsManager.getHostMatching(handler.host)?.key
|
||||
}
|
||||
} message: {
|
||||
Text("Expected \(hostsManager.getHostMatching(handler.host)!.key?.base64EncodedString() ?? "null")\nbut recieved \(handler.host.key?.base64EncodedString() ?? "null" ) from the server")
|
||||
Text("Expected \(hostsManager.getHostMatching(handler.host)?.key?.base64EncodedString() ?? "null")\nbut recieved \(handler.host.key?.base64EncodedString() ?? "null" ) from the server")
|
||||
}
|
||||
.transition(.opacity)
|
||||
.toolbar {
|
||||
|
||||
@@ -23,6 +23,7 @@ class ShhTerminalViewDelegate: TerminalViewDelegate {
|
||||
|
||||
func send(source: TerminalView, data: ArraySlice<UInt8>) {
|
||||
print(data)
|
||||
print("send")
|
||||
}
|
||||
|
||||
func scrolled(source: TerminalView, position: Double) {
|
||||
|
||||
Reference in New Issue
Block a user