mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
asdfjkhadsjkghkjaehgf
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol HostPr: Codable, Identifiable {
|
||||
protocol HostPr: Codable, Identifiable, Equatable {
|
||||
var id: UUID { get set }
|
||||
var address: String { get set }
|
||||
var port: Int { get set }
|
||||
|
||||
@@ -17,6 +17,25 @@ struct Key: Identifiable, Hashable {
|
||||
}
|
||||
|
||||
class KeyManager: ObservableObject {
|
||||
private let userdefaults = NSUbiquitousKeyValueStore.default
|
||||
|
||||
var tags: [String] = []
|
||||
|
||||
func loadTags() {
|
||||
let decoder = JSONDecoder()
|
||||
guard let data = userdefaults.data(forKey: "keyTags") else { return }
|
||||
guard let decoded = try? decoder.decode([String].self, from: data) else { return }
|
||||
tags = decoded
|
||||
}
|
||||
|
||||
func saveTags() {
|
||||
let encoder = JSONEncoder()
|
||||
guard let encoded = try? encoder.encode(tags) else { return }
|
||||
userdefaults.set(encoded, forKey: "keyTags")
|
||||
userdefaults.synchronize()
|
||||
}
|
||||
|
||||
//MARK: generate keys
|
||||
func generateEd25519() {
|
||||
let privateKey = Curve25519.Signing.PrivateKey()
|
||||
let publicKeyData = privateKey.publicKey
|
||||
@@ -26,7 +45,8 @@ class KeyManager: ObservableObject {
|
||||
|
||||
func generateRSA() throws {
|
||||
let type = kSecAttrKeyTypeRSA
|
||||
let tag = "com.neon443.ShhSell.keys.\(Date().timeIntervalSince1970)".data(using: .utf8)!
|
||||
let label = Date().ISO8601Format()
|
||||
let tag = label.data(using: .utf8)!
|
||||
let attributes: [String: Any] =
|
||||
[kSecAttrKeyType as String: type,
|
||||
kSecAttrKeySizeInBits as String: 4096,
|
||||
@@ -42,5 +62,10 @@ class KeyManager: ObservableObject {
|
||||
print(privateKey)
|
||||
|
||||
print(SecKeyCopyPublicKey(privateKey))
|
||||
// do {
|
||||
// try storeKey(privateKey, label: label)
|
||||
// } catch {
|
||||
// print(error.localizedDescription)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,5 +91,12 @@ kSecUseDataProtectionKeychain: true,
|
||||
case errSecItemNotFound: return nil
|
||||
case let status: throw KeyStoreError.KeyStoreError("keychain read failed")
|
||||
}
|
||||
return secKey
|
||||
// return secKey
|
||||
|
||||
var error: Unmanaged<CFError>?
|
||||
guard let data = SecKeyCopyExternalRepresentation(secKey, &error) as Data? else {
|
||||
throw KeyStoreError.KeyStoreError(error.debugDescription)
|
||||
}
|
||||
// let key = try T(x963Representation: data)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ struct HostsView: View {
|
||||
} label: {
|
||||
Text(host.address)
|
||||
}
|
||||
.onChange(of: host) { _ in
|
||||
hostsManager.saveSavedHosts()
|
||||
}
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
|
||||
Reference in New Issue
Block a user