Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
use known facets in prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews committed Aug 18, 2017
1 parent 4085c78 commit 5bc1c31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions SoftU2FTool/KeyPair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ class KeyPair {
}

// Find a key pair with the given label and application label.
init?(label l: String, appLabel al: Data) {
init?(label l: String, appLabel al: Data, signPrompt sp: String) {
label = l
applicationLabel = al

// Lookup private key.
guard let priv = Keychain.getPrivateSecKey(attrAppLabel: applicationLabel as CFData) else { return nil }
guard let priv = Keychain.getPrivateSecKey(attrAppLabel: applicationLabel as CFData, signPrompt: sp as CFString) else { return nil }
privateKey = priv

// Generate public key from private key
Expand Down
15 changes: 8 additions & 7 deletions SoftU2FTool/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,14 @@ class Keychain {
return result
}

static func getPrivateSecKey(attrAppLabel: CFData) -> SecKey? {
static func getPrivateSecKey(attrAppLabel: CFData, signPrompt: CFString) -> SecKey? {
let query = makeCFDictionary(
(kSecClass, kSecClassKey),
(kSecAttrKeyType, kSecAttrKeyTypeEC),
(kSecAttrKeyClass, kSecAttrKeyClassPrivate),
(kSecAttrApplicationLabel, attrAppLabel),
(kSecReturnRef, kCFBooleanTrue)
(kSecClass, kSecClassKey),
(kSecAttrKeyType, kSecAttrKeyTypeEC),
(kSecAttrKeyClass, kSecAttrKeyClassPrivate),
(kSecAttrApplicationLabel, attrAppLabel),
(kSecReturnRef, kCFBooleanTrue),
(kSecUseOperationPrompt, signPrompt as CFString)
)

var optionalOpaqueResult: CFTypeRef? = nil
Expand Down Expand Up @@ -332,7 +333,7 @@ class Keychain {
return
}

guard let _ = getPrivateSecKey(attrAppLabel: attrAppLabel as CFData) else {
guard let _ = getPrivateSecKey(attrAppLabel: attrAppLabel as CFData, signPrompt: "" as CFString) else {
print("error getting private key for public key")
return
}
Expand Down
6 changes: 5 additions & 1 deletion SoftU2FTool/U2FRegistration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class U2FRegistration {
// Find a registration with the given key handle.
init?(keyHandle kh: Data, applicationParameter ap: Data) {
let appLabel = unpadKeyHandle(kh)
guard let kp = KeyPair(label: U2FRegistration.namespace, appLabel: appLabel) else { return nil }

let kf = KnownFacets[ap] ?? "site"
let prompt = "authenticate with \(kf)"

guard let kp = KeyPair(label: U2FRegistration.namespace, appLabel: appLabel, signPrompt: prompt) else { return nil }
keyPair = kp

// Read our application parameter from the keychain and make sure it matches.
Expand Down
1 change: 0 additions & 1 deletion SoftU2FTool/UserPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import LocalAuthentication

class UserPresence: NSObject {
enum Notification {
Expand Down

0 comments on commit 5bc1c31

Please sign in to comment.