mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
made the functions makeSSH[priv,pub]key take in a Keypair
This commit is contained in:
@@ -59,16 +59,16 @@ class KeyManager: ObservableObject {
|
|||||||
return pubdata
|
return pubdata
|
||||||
}
|
}
|
||||||
|
|
||||||
static func makeSSHPubkey(pub: Data, comment: String) -> Data {
|
static func makeSSHPubkey(_ keypair: Keypair) -> Data {
|
||||||
let header = "ssh-ed25519"
|
let header = "ssh-ed25519"
|
||||||
var keyBlob: Data = Data()
|
var keyBlob: Data = Data()
|
||||||
//key type bit
|
//key type bit
|
||||||
keyBlob += encode(str: header)
|
keyBlob += encode(str: header)
|
||||||
//base64 blob bit
|
//base64 blob bit
|
||||||
keyBlob += encode(data: pub)
|
keyBlob += encode(data: keypair.publicKey)
|
||||||
|
|
||||||
let b64key = keyBlob.base64EncodedString()
|
let b64key = keyBlob.base64EncodedString()
|
||||||
let pubkeyline = "\(header) \(b64key) \(comment)\n"
|
let pubkeyline = "\(header) \(b64key) \(keypair.publicKey)\n"
|
||||||
return Data(pubkeyline.utf8)
|
return Data(pubkeyline.utf8)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class KeyManager: ObservableObject {
|
|||||||
return Keypair(type: .ecdsa, name: comment, privateKey: privatekeyData)
|
return Keypair(type: .ecdsa, name: comment, privateKey: privatekeyData)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func makeSSHPrivkey(pub: Data, priv: Data, comment: String) -> Data {
|
static func makeSSHPrivkey(_ keypair: Keypair) -> Data {
|
||||||
var content: Data = Data()
|
var content: Data = Data()
|
||||||
var blob: Data = Data()
|
var blob: Data = Data()
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class KeyManager: ObservableObject {
|
|||||||
var pubkeyBlob = Data()
|
var pubkeyBlob = Data()
|
||||||
let keyType = "ssh-ed25519"
|
let keyType = "ssh-ed25519"
|
||||||
pubkeyBlob += encode(str: keyType)
|
pubkeyBlob += encode(str: keyType)
|
||||||
pubkeyBlob += encode(data: pub)
|
pubkeyBlob += encode(data: keypair.publicKey)
|
||||||
blob += encode(data: pubkeyBlob)
|
blob += encode(data: pubkeyBlob)
|
||||||
|
|
||||||
//priv
|
//priv
|
||||||
@@ -144,9 +144,9 @@ class KeyManager: ObservableObject {
|
|||||||
privBlob.append(contentsOf: withUnsafeBytes(of: checkint.bigEndian, Array.init))
|
privBlob.append(contentsOf: withUnsafeBytes(of: checkint.bigEndian, Array.init))
|
||||||
privBlob.append(contentsOf: withUnsafeBytes(of: checkint.bigEndian, Array.init))
|
privBlob.append(contentsOf: withUnsafeBytes(of: checkint.bigEndian, Array.init))
|
||||||
privBlob += encode(str: keyType)
|
privBlob += encode(str: keyType)
|
||||||
privBlob += encode(data: pub)
|
privBlob += encode(data: keypair.publicKey)
|
||||||
privBlob += encode(data: priv + pub)
|
privBlob += encode(data: keypair.privateKey + keypair.publicKey)
|
||||||
privBlob += encode(str: comment)
|
privBlob += encode(str: keypair.name)
|
||||||
|
|
||||||
let padLegth = (8 - (privBlob.count % 8)) % 8
|
let padLegth = (8 - (privBlob.count % 8)) % 8
|
||||||
if padLegth > 0 {
|
if padLegth > 0 {
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ struct Keypair: KeypairProtocol {
|
|||||||
var passphrase: String = ""
|
var passphrase: String = ""
|
||||||
|
|
||||||
var openSshPubkey: String {
|
var openSshPubkey: String {
|
||||||
String(data: KeyManager.makeSSHPubkey(pub: publicKey, comment: name), encoding: .utf8) ?? "OpenSSH key format error"
|
String(data: KeyManager.makeSSHPubkey(self), encoding: .utf8) ?? "OpenSSH key format error"
|
||||||
}
|
}
|
||||||
|
|
||||||
var openSshPrivkey: String {
|
var openSshPrivkey: String {
|
||||||
String(data: KeyManager.makeSSHPrivkey(pub: publicKey, priv: privateKey, comment: name), encoding: .utf8) ?? "OpenSSH key format error"
|
String(data: KeyManager.makeSSHPrivkey(self), encoding: .utf8) ?? "OpenSSH key format error"
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init(
|
||||||
|
|||||||
@@ -12,13 +12,6 @@ struct KeyDetailView: View {
|
|||||||
@State var keypair: Keypair
|
@State var keypair: Keypair
|
||||||
@State private var reveal: Bool = false
|
@State private var reveal: Bool = false
|
||||||
|
|
||||||
var publicKey: Data {
|
|
||||||
return keypair.publicKey ?? "".data(using: .utf8)!
|
|
||||||
}
|
|
||||||
var privateKey: Data {
|
|
||||||
return keypair.privateKey ?? "".data(using: .utf8)!
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
hostsManager.selectedTheme.background.suiColor.opacity(0.7)
|
hostsManager.selectedTheme.background.suiColor.opacity(0.7)
|
||||||
@@ -66,10 +59,17 @@ struct KeyDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
UIPasteboard.general.string = String(data: KeyManager.makeSSHPubkey(keypair), encoding: .utf8) ?? ""
|
||||||
|
} label: {
|
||||||
|
CenteredLabel(title: "Copy private key", systemName: "document.on.document")
|
||||||
|
}
|
||||||
|
.listRowSeparator(.hidden)
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
Task {
|
Task {
|
||||||
guard await hostsManager.authWithBiometrics() else { return }
|
guard await hostsManager.authWithBiometrics() else { return }
|
||||||
UIPasteboard.general.string = String(data: privateKey, encoding: .utf8)
|
UIPasteboard.general.string = String(data: KeyManager.makeSSHPrivkey(keypair), encoding: .utf8) ?? ""
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
CenteredLabel(title: "Copy private key", systemName: "document.on.document")
|
CenteredLabel(title: "Copy private key", systemName: "document.on.document")
|
||||||
|
|||||||
Reference in New Issue
Block a user