YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.share.LaunchNonces Class Reference

Single-use tokens that prove an intent for the browser came from LauncherActivity after its checks. More...

Collaboration diagram for de.yaacc.share.LaunchNonces:
Collaboration graph

Public Member Functions

 LaunchNonces (LongSupplier nowMillis, Consumer< byte[]> randomBytes, long ttlMillis, int maxOutstanding)
 
synchronized String mint ()
 Makes a new token.
 
synchronized boolean consume (String presented)
 Spends a token.
 

Static Public Member Functions

static LaunchNonces createDefault ()
 The production store: monotonic clock, SecureRandom, the limits of ShareLimits.
 

Static Public Attributes

static final String EXTRA_NAME = "de.yaacc.extra.LAUNCH_NONCE"
 The intent extra that carries the token from the launcher to the browser.
 

Detailed Description

Single-use tokens that prove an intent for the browser came from LauncherActivity after its checks.

Plain Java, memory only.

The browser activities are exported, so any app can start them with a file share and skip the launcher (and with it the checks of the incoming file share). The launcher therefore mint()s a token when its checks have passed and puts it into the fresh intent it forwards; the browser accepts a shared file only if the intent presents a token that consume(String) accepts. The store lives in this process only (another app can neither read nor guess it: 128 bits from a SecureRandom), a token is valid for a short time and once, the store is bounded, and the comparison is constant-time. A token that is replayed (a recents re-delivery, a process restart) is simply not found.

Constructor & Destructor Documentation

◆ LaunchNonces()

de.yaacc.share.LaunchNonces.LaunchNonces ( LongSupplier nowMillis,
Consumer< byte[]> randomBytes,
long ttlMillis,
int maxOutstanding )
Parameters
nowMillisa monotonic clock
randomBytesfills the array with unpredictable bytes
ttlMillishow long a token is valid, positive
maxOutstandinghow many unused tokens are kept, at least 1

Referenced by de.yaacc.share.LaunchNonces.createDefault().

Here is the caller graph for this function:

Member Function Documentation

◆ consume()

synchronized boolean de.yaacc.share.LaunchNonces.consume ( String presented)

Spends a token.

Parameters
presentedwhat the intent carried, may be null
Returns
true exactly once for each minted token, while it is valid; false for a missing, forged, expired, wrong or already spent one

◆ mint()

synchronized String de.yaacc.share.LaunchNonces.mint ( )

Makes a new token.

Expired tokens go first; if the store is still full, the oldest live one is dropped.

Returns
32 lower-case hex characters (128 bits)

The documentation for this class was generated from the following file: