public final class ShieldConfig

  1. Object
  2. ShieldConfig

Configuration for AppShield.init(ShieldConfig). Chainable.

AppShield.init(new ShieldConfig()
    .protect("api.mybank.example", HostPolicy.PROTECTED)
    .protect("*.mybank.example", HostPolicy.PROTECTED));

The defaults are chosen so that adding the shield to an existing app changes nothing until hosts are explicitly protected: no host is touched, failures are open, and signal collection is on because reporting costs nothing and is what makes the service useful.

Fields

public static final String DEFAULT_TOKEN_HEADER = "X-CN1-Attest"Header that carries the attestation token.

Constructors

public ShieldConfig()

Methods

public ShieldConfig endpoint(String url)Overrides the attestation service endpoint.
public ShieldConfig tokenHeader(String name)Overrides the header used to carry the token.
public ShieldConfig defaultFailureMode(FailureMode mode)The failure mode applied to hosts registered without an explicit one.
public ShieldConfig refreshThresholdPercent(int percent)How far through a token’s lifetime to trigger a background refresh, as a percentage.
public ShieldConfig collectSignals(boolean collect)Whether to gather runtime self-protection observations.
public ShieldConfig protect(String hostPattern, HostPolicy policy)Registers a host to protect.
public ShieldConfig protect(String hostPattern)Registers a host with the default policy, which honours defaultFailureMode(FailureMode).
public String getEndpoint()
public String getTokenHeader()
public FailureMode getDefaultFailureMode()
public int getRefreshThresholdPercent()
public boolean isCollectSignals()
public HostPolicy policyFor(String host)Resolves a host to its policy: exact match first, then the nearest *. wildcard, then HostPolicy.UNPROTECTED.
public boolean hasProtectedHosts()True when at least one host is registered, so callers can skip work entirely.
public Enumeration protectedHosts()The registered host patterns, explicit and implicit alike.

Inherited methods

Field details

DEFAULT_TOKEN_HEADER

public static final String DEFAULT_TOKEN_HEADER = "X-CN1-Attest"

Header that carries the attestation token.

Deliberately not Authorization: that slot belongs to the app’s own user authentication, and the two answer different questions – who the user is, versus whether this is a genuine unmodified app on an uncompromised device. A backend needs both, so they must compose.

Constructor details

ShieldConfig

public ShieldConfig()

Method details

endpoint

public ShieldConfig endpoint(String url)
Overrides the attestation service endpoint. Only needed for a private deployment or a test double.

tokenHeader

public ShieldConfig tokenHeader(String name)

Overrides the header used to carry the token. Change this only if it collides with something already in use on your backend.

Content-Type is refused. ConnectionRequest.addRequestHeader special-cases that name into the request’s own content type rather than the header map, so the token would replace the request’s media type and – because the removal path only clears the map – would survive a redirect to an unprotected host and be handed to it. A leak with no symptom on the way there.

Throws

IllegalArgumentException
if the name cannot carry a token safely

defaultFailureMode

public ShieldConfig defaultFailureMode(FailureMode mode)
The failure mode applied to hosts registered without an explicit one.

refreshThresholdPercent

public ShieldConfig refreshThresholdPercent(int percent)
How far through a token’s lifetime to trigger a background refresh, as a percentage. Refreshing early is what stops a request ever having to wait on the network.

collectSignals

public ShieldConfig collectSignals(boolean collect)
Whether to gather runtime self-protection observations. On by default; they ride along with the token fetch, so there is no extra request and no extra battery cost.

protect

public ShieldConfig protect(String hostPattern, HostPolicy policy)
Registers a host to protect. Accepts an exact host or a leading *. wildcard covering its subdomains. Hosts not registered here are never touched.

protect

public ShieldConfig protect(String hostPattern)
Registers a host with the default policy, which honours defaultFailureMode(FailureMode).

getEndpoint

public String getEndpoint()

getTokenHeader

public String getTokenHeader()

getDefaultFailureMode

public FailureMode getDefaultFailureMode()

getRefreshThresholdPercent

public int getRefreshThresholdPercent()

isCollectSignals

public boolean isCollectSignals()

policyFor

public HostPolicy policyFor(String host)
Resolves a host to its policy: exact match first, then the nearest *. wildcard, then HostPolicy.UNPROTECTED. Never returns null.

hasProtectedHosts

public boolean hasProtectedHosts()
True when at least one host is registered, so callers can skip work entirely.

protectedHosts

public Enumeration protectedHosts()
The registered host patterns, explicit and implicit alike.