factors

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: BSD-3-Clause Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

factors

Go Reference License CI

macOS's authentication factors, as factors — mfa.Factor values a policy can ask. Pure Go, CGO_ENABLED=0.

r, err := mfa.Verify(ctx, mfa.Policy{Count: 2, DistinctKinds: true},
    factors.TouchID("unlock the vault"),          // something you are
    factors.SecurityKey("example.test", credID, pubKey),  // something you have
)
if err != nil {
    fmt.Println(err)  // "2 factor(s) needed, 1 answered: your security key: not plugged in"
}

Almost none of the key factor is here any more

Asking a security key is the same everywhere CTAP is, so it lives once, in go-authn/keyfactor: the challenge, the assertion, the flag checks, the refusal to spend somebody's last PIN attempt. It lived HERE first, and was one copy away from living in a Linux package too.

What stays is what macOS owns — platformAskSensor, and platformOpen finding the key and knowing that an empty USB port has refused nobody.

Why this is a separate package

Nothing in go-macos/localauthentication or go-authn/fido should know what a policy is. A binding's job is to reach a framework. If either imported a policy package, that decision would be dragged into every program that only wanted to show a Touch ID prompt.

So the adapters live here, above both, and the layering is: bindings reach hardware, go-authn/mfa decides, this package is the four lines in between.

The distinctions it refuses to blur

Touch ID is not "Touch ID or your password". The framework will happily accept either, and a factor that did would report Inherence when what happened was Knowledge — a password dressed up as a fingerprint. TouchID asks for biometry only. DeviceOwner accepts either and returns mfa.Unknown, so a two-kind policy never counts it. Being honest about not knowing is what stops one factor from passing for two.

A key's PIN is not a second factor. It never reaches the platform, and it protects the key rather than identifying anyone to us. VerifiedSecurityKey is still Possession; what the PIN changes is the strength of that one proof, which shows up as the verified bit in the assertion. Counting it separately would let a single object masquerade as two factors, which is the exact failure two-factor authentication exists to prevent.

Nothing here to ask is not a refusal. A Mac with no sensor, an empty USB port, and Linux all report mfa.ErrUnavailable, which a policy tallies separately. Only three LocalAuthentication conditions get that treatment; a sensor that is locked out is a real answer — it has refused too often — and is reported as one, because the person can act on it by using their password.

A wrong PIN costs the key an attempt, and the last one is not spent on a guess. pinToken asks how many are left first and refuses at one, or when the key says it will take no more until it is unplugged. A key that runs out locks permanently, taking every credential on it.

The challenge is random. This factor does not verify the signature, so there is no protocol to bind a challenge to — and a fixed one would let a recorded assertion be replayed here forever. A caller who needs a verifiable assertion should use go-authn/fido directly.

Coverage

Everything portable is covered to 100%, on Linux, with no hardware: the classification, the kinds, the incomplete-request refusals, and the absent-versus-refused split all go through the askSensor/askKey seams.

The two platform functions are not covered, and the gate says so rather than pretending otherwise. They reach a fingerprint sensor and a plugged-in key; a test that popped a biometric prompt would be a test nobody could run twice, and a runner has neither device. They have been exercised by hand against a real YubiKey FIDO 5.7.4.

The verified path — VerifiedSecurityKey, uv, pinToken — is not yet proven on hardware. Doing that means setting a PIN on a key, and a PIN cannot be removed afterwards except by authenticatorReset, which erases every credential on it. That waits for a key kept for development.

Documentation

Overview

Package factors makes macOS's authentication factors usable by github.com/go-authn/mfa.

It exists so the bindings do not have to know about policy. A binding's job is to reach a framework; deciding how much proof is enough is somebody else's, and a low-level package that imported a policy package would drag that decision into every program that only wanted Touch ID.

r, err := mfa.Verify(ctx, mfa.Policy{Count: 2, DistinctKinds: true},
    factors.TouchID("unlock the vault"),
    factors.SecurityKey("example.test", credentialID, publicKey),
)

What each factor actually proves

TouchID proves that whoever is at this machine can satisfy the sensor the account owner enrolled — something they ARE. SecurityKey proves that a particular credential is present and that a human touched it — something they HAVE. Those are different kinds, which is what lets a policy asking for distinct kinds be satisfied by the two together and not by either twice.

Unavailable is not refused

A Mac with no Touch ID sensor has refused nobody, and neither has an empty USB port. Both report mfa.ErrUnavailable, which a policy counts separately: a person can be told to plug their key in, which is not the same as being told they failed.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("factors: these are macOS factors")

ErrUnsupported is what these factors report off macOS.

It is wrapped as unavailable rather than as a refusal: a Linux machine has not failed anyone's Touch ID, it has no Touch ID. The Linux and Windows adapters are go-gnulinux/factors and go-mswin/factors.

Functions

func DeviceOwner

func DeviceOwner(reason string) mfa.Factor

DeviceOwner is the sensor OR the login password, whichever the person chooses.

Its kind is mfa.Unknown, honestly: which one they used is not reported back, so this factor cannot say what it proved. A policy asking for distinct kinds will therefore never count it towards them -- which is the right answer rather than a limitation, because two factors that might both be passwords are not two factors.

func SecurityKey

func SecurityKey(rpID string, credentialID []byte, publicKey *ecdsa.PublicKey) mfa.Factor

SecurityKey is a registered credential as a factor: the key must be present and a human must touch it.

credentialID and publicKey are what a registration returned: the credential's id, and the P-256 key from its attestation (fido.AuthData.PublicKey). Passing no id asks the key for a discoverable credential, which it has only if one was registered with the "rk" option.

⛔ The public key is required. Without it nothing could check the assertion's signature, and any device that speaks CTAPHID -- a programmable USB board -- would pass as the key (go-authn/keyfactor v0.3.0, after a security audit). A factor built without one refuses when asked.

This proves POSSESSION and nothing more. A key on a desk that anybody can reach is still a key anybody can reach, which is exactly why it belongs alongside a factor of another kind rather than alone.

The asking itself is keyfactor's: it is the same everywhere CTAP is, and this package once carried its own copy. What is macOS's is [platformOpen] — finding the key, and knowing what its absence means.

func TouchID

func TouchID(reason string) mfa.Factor

TouchID is the sensor as a factor. reason is what macOS shows the person in its own prompt, so it should say what is being unlocked.

It asks for BIOMETRY only. The framework can also be asked to accept the login password, and this deliberately does not: a factor that answered yes to either would be reporting mfa.Inherence when what happened was mfa.Knowledge. Use DeviceOwner when either will do, and it says so.

func VerifiedSecurityKey

func VerifiedSecurityKey(rpID string, credentialID []byte, publicKey *ecdsa.PublicKey, pin string) mfa.Factor

VerifiedSecurityKey is the same, with the key asked to verify who holds it.

The PIN travels no further than the key: what goes over the wire is the first sixteen bytes of its SHA-256, encrypted under a secret agreed for that one exchange. It is still a secret in a Go string, so a caller that can avoid holding one should.

A wrong PIN costs the key a retry and a key that runs out locks. The key is asked how many are left first, and refuses rather than spending the last one blindly.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址