Key selection.

This commit is contained in:
Max Goedjen 2025-08-18 00:06:03 -05:00
parent 7aba3c374d
commit 6a8926f177
No known key found for this signature in database
3 changed files with 24 additions and 9 deletions

View File

@ -72,14 +72,16 @@ extension OpenSSHKeyWriter {
/// - length: The key length of the algorithm. /// - length: The key length of the algorithm.
/// - Returns: The OpenSSH identifier for the algorithm. /// - Returns: The OpenSSH identifier for the algorithm.
public func curveType(for keyType: KeyType) -> String { public func curveType(for keyType: KeyType) -> String {
switch keyType.algorithm { switch (keyType.algorithm, keyType.size) {
case .ecdsa: case (.ecdsa, 256), (.ecdsa, 384):
"ecdsa-sha2-nistp" + String(describing: keyType.size) "ecdsa-sha2-nistp" + String(describing: keyType.size)
case .rsa: case (.mldsa, 65), (.mldsa, 87):
"ssh-mldsa-" + String(describing: keyType.size)
case (.rsa, _):
// All RSA keys use the same 512 bit hash function, per // All RSA keys use the same 512 bit hash function, per
// https://security.stackexchange.com/questions/255074/why-are-rsa-sha2-512-and-rsa-sha2-256-supported-but-not-reported-by-ssh-q-key // https://security.stackexchange.com/questions/255074/why-are-rsa-sha2-512-and-rsa-sha2-256-supported-but-not-reported-by-ssh-q-key
"rsa-sha2-512" "rsa-sha2-512"
case .mldsa: default:
"unknown" "unknown"
} }
} }

View File

@ -65,7 +65,11 @@ extension Preview {
var name: String { "Modifiable Preview Store" } var name: String { "Modifiable Preview Store" }
let secrets: [Secret] let secrets: [Secret]
var supportedKeyTypes: [KeyType] { var supportedKeyTypes: [KeyType] {
[.init(algorithm: .ecdsa, size: 256)] [
.init(algorithm: .ecdsa, size: 256),
.init(algorithm: .mldsa, size: 65),
.init(algorithm: .mldsa, size: 87),
]
} }
init(secrets: [Secret]) { init(secrets: [Secret]) {

View File

@ -30,10 +30,19 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
} }
if advanced { if advanced {
Section { Section {
Picker("Key Type", selection: $keyType) { VStack {
ForEach(store.supportedKeyTypes, id: \.self) { option in Picker("Key Type", selection: $keyType) {
Text(String(describing: option)) ForEach(store.supportedKeyTypes, id: \.self) { option in
.tag(option) Text(String(describing: option))
.tag(option)
.font(.caption)
}
}
if keyType?.algorithm == .mldsa {
Text("Warning: ML-DSA keys are very new, and not supported by many servers yet. Please verify the server you'll be using this key for accepts ML-DSA keys.")
.padding(.horizontal, 10)
.padding(.vertical, 3)
.background(.red.opacity(0.5), in: RoundedRectangle(cornerRadius: 5))
} }
} }
TextField("Key Attribution", text: $keyAttribution, prompt: Text("test@example.com")) TextField("Key Attribution", text: $keyAttribution, prompt: Text("test@example.com"))