Expand description
Offline AWS account-ID decode + canary-token classification (single source of truth shared by the scanner’s finding metadata and the verifier’s suppress-live-verification-for-canaries gate). Offline AWS account-ID recovery and canary-token classification.
This is the single source of truth for two credential-string-only facts
about an AWS access-key ID, shared by every keyhog crate (scanner attaches
them as finding metadata with no verify; verifier consults the canary check
to refuse tripping a canary on --verify). It lives in keyhog-core — the
one crate both keyhog-scanner and keyhog-verifier depend on — so there is
exactly one decode and one canary list, never a fork.
-
Account decode. Every modern AWS access-key ID (
AKIA…long-term,ASIA…temporary STS) has the 12-digit account number mathematically embedded in it, recoverable with a pure base32-decode + bit-shift — NO network call, NO STSGetCallerIdentity, and it works on LIVE and revoked keys. Algorithm matches the trufflesecurity write-up https://trufflesecurity.com/blog/research-uncovers-aws-account-numbers-hidden-in-access-keys: drop the 4-char prefix; base32-decode the body; the first 6 decoded bytes are a big-endian u48;account = (u48 & 0x7fff_ffff_ff80) >> 7, rendered as a 12-digit zero-padded decimal string. -
Canary classification. An access key whose decoded account belongs to a known canary issuer (canarytokens.org / Thinkst and off-brand clones) is a tripwire: any live verification alerts whoever planted it. The baseline issuer list is Tier-B data embedded from
data/aws-canary-accounts.tomland unioned at first use with a runtime-extension file pointed to byKEYHOG_AWS_CANARY_ACCOUNTS. Baseline source: https://trufflesecurity.com/blog/canaries.
Constants§
- CANARY_
MESSAGE - Operator-facing note attached to a canary finding so the report explains why verification was skipped. Mirrors trufflehog’s responder message.
Functions§
- account_
is_ canary - True when
account_id(a 12-digit AWS account string) belongs to a known canary-token issuer. - aws_
account_ from_ key_ id - Recover the 12-digit AWS account ID embedded in an access-key ID, fully
offline. Returns
Nonewhenkey_idis not a well-formedAKIA…/ASIA…access-key ID (wrong length, wrong prefix, or a non-base32 body), so a caller can blindly try every credential and only act onSome. - finding_
metadata - Build the offline metadata for an AWS-access-key finding: always
{ "account_id": "<12 digits>" }for a decodableAKIA…/ASIA…key, plus{ "is_canary": "true", "canary_message": <note> }when the decoded account belongs to a known canary issuer.Nonewhencredentialis not a well-formed AWS access-key ID. - key_
id_ is_ canary - True when
key_idis a decodable AWS access-key ID whose offline-decoded account belongs to a known canary issuer. The verifier uses this to refuse sending a live probe (which would trip the canary) without re-implementing the decode.