Class ShieldToken
A short-lived attestation token, ready to be attached to a request.
The value is opaque to the app. It is meaningful only to the backend that verifies it against the published Codename One signing keys -- do not parse it, and do not make a security decision on the device based on its contents, because a device the attacker controls can be made to say anything.
Expiry is measured locally, on purpose
Validity is tracked as "fetched at + time to live" using local elapsed time, never by reading an
expiry field out of the token and comparing it against the device clock. On a rooted device the
clock is attacker-controlled, so a token-embedded expiry can be made to look valid forever. The
verifying backend does its own absolute-time check regardless; isValid() exists so the client
knows when to refresh, not to enforce anything.
-
Constructor Summary
ConstructorsConstructorDescriptionShieldToken(String value, ShieldStatus status, long fetchedAt, long ttlMillis, String binding) -
Method Summary
Modifier and TypeMethodDescriptionThe request-binding data this token was minted for, or null when it is a plain time-limited token not tied to a specific request.longWhen this token was fetched, in wall-clock time.longMilliseconds until this token stops being worth sending, or 0 once it has lapsed.Outcome of the fetch that produced this token.getValue()The opaque token to place in the request header.booleanTrue when this token was minted for exactly the supplied binding data.booleanisValid()True when the token has a value, was fetched successfully, and has not lapsed.booleanshouldRefresh(int thresholdPercent) True once the token is far enough through its lifetime to be worth refreshing in the background.toString()Never renders the token value -- these strings end up in logs.
-
Constructor Details
-
ShieldToken
public ShieldToken(String value, ShieldStatus status, long fetchedAt, long ttlMillis, String binding)
-
-
Method Details
-
getValue
The opaque token to place in the request header. May be null whengetStatus()is notShieldStatus.OK. -
getStatus
Outcome of the fetch that produced this token. -
getMillisUntilExpiry
public long getMillisUntilExpiry()Milliseconds until this token stops being worth sending, or 0 once it has lapsed. -
isValid
public boolean isValid()True when the token has a value, was fetched successfully, and has not lapsed. -
shouldRefresh
public boolean shouldRefresh(int thresholdPercent) True once the token is far enough through its lifetime to be worth refreshing in the background. Refreshing before expiry is what keeps a request from ever having to block. -
getBinding
The request-binding data this token was minted for, or null when it is a plain time-limited token not tied to a specific request. -
isBoundTo
True when this token was minted for exactly the supplied binding data. A token bound to one request must not be reused for another; that is the whole point of binding. -
getFetchedAt
public long getFetchedAt()When this token was fetched, in wall-clock time.
For correlating a client log with a server log, and nothing else -- lifetime decisions use the monotonic reference instead, for the reasons in the class documentation.
-
toString
-