Security
Custom Base URL & Certificate Pinning
For enterprise deployments, you can configure a custom base URL (for custom domains/proxies) and implement certificate pinning for enhanced security:
StorifyMeSDK.init(
context = this,
apiKey = ACCESS_TOKEN,
accountId = ACCOUNT_ID,
environment = StorifyMeEnvironment.EU,
customBaseUrl = "https://stories.yourapp.com/", // Optional: custom domain/proxy
certificatePins = listOf( // Optional: SHA-256 public key pins
"sha256/YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="
)
)
Both parameters are optional and independent. See the Complete Guide for detailed instructions, security best practices, and how to obtain certificate pins.
Content Integrity Verification
For accounts with content signing enabled, pass your PEM-encoded ECDSA P-256 public keys during SDK initialization. Include multiple keys during key rotation so stories signed with either key continue to verify.
val publicKeys = listOf("YOUR_PEM_ENCODED_ECDSA_P256_PUBLIC_KEY")
StorifyMeSDK.init(
context = applicationContext,
apiKey = "YOUR_API_KEY",
accountId = "YOUR_ACCOUNT_ID",
environment = StorifyMeEnvironment.EU,
integrityPublicKeys = publicKeys,
)
When keys are configured, the SDK drops stories with missing or invalid signatures before rendering. An empty key list (the default) disables verification. Observe rejected stories through the widget listener:
storiesView.widgetListener = object : StorifyMeWidgetListener {
override fun onIntegrityFailed(
widgetId: Long,
experienceId: Long,
reason: StorifyMeIntegrityFailureReason,
) {
Log.w("StorifyMe", "Story $experienceId failed integrity verification: $reason")
}
}
Set the listener before calling load(). See Android events for other widget callbacks.
Custom Gateway Request Headers
If your custom gateway requires an app-owned session header, register the request interceptor before
initializing the SDK. It runs synchronously for each stories, base-template, audience, and ads content
API request routed through customBaseUrl, so the app can provide a refreshed token on every request.
The callback receives the absolute request URL and current headers, including accountId; return the
complete header map to send.
StorifyMeSDK.setRequestInterceptor { url, headers ->
headers + ("Authorization" to "Bearer ${session.currentToken()}")
}
StorifyMeSDK.init(
context = this,
apiKey = "YOUR_API_KEY",
accountId = "YOUR_ACCOUNT_ID",
customBaseUrl = "https://gateway.example.com",
)
The interceptor only applies to content API requests using the configured custom base URL. It does not add headers to media or WebView traffic. The SDK does not store or log returned header values. If the callback throws, the request fails. Keep it synchronous and make sure the gateway does not redirect requests to a different origin; the SDK does not reapply headers after redirects.
Pass null to StorifyMeSDK.setRequestInterceptor to unregister the callback.
Private Certificate Authority (CA)
If your customBaseUrl uses a private CA, include the public X.509 CA certificate in the Android
app and pass its DER bytes to trustedCACertificates. The SDK applies this trust to API requests
for the hostname in customBaseUrl; system CAs remain trusted. If you set certificatePins, the
SDK checks them after validating the TLS chain and hostname. Do not include the CA's private key.
Place the certificate at app/src/main/res/raw/partner_root_ca.der, then read it when initializing:
val partnerRootCa = applicationContext.resources
.openRawResource(R.raw.partner_root_ca)
.use { it.readBytes() }
StorifyMeSDK.init(
context = applicationContext,
apiKey = "YOUR_API_KEY",
accountId = "YOUR_ACCOUNT_ID",
environment = StorifyMeEnvironment.EU,
customBaseUrl = "https://stories.example.com/api/",
certificatePins = listOf("sha256/YOUR_BASE64_SPKI_HASH="), // Optional
trustedCACertificates = listOf(partnerRootCa),
)
The SDK applies trustedCACertificates and certificatePins to its API client and to SDK-managed
image, GIF, and video downloads when those URLs use the exact hostname in customBaseUrl. Media on a
different CDN hostname and WebView traffic use Android's platform networking, so add a domain-scoped
Network Security Configuration
for those hosts.
Add android:networkSecurityConfig to the <application> element in AndroidManifest.xml:
<application
android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
Create app/src/main/res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain includeSubdomains="false">stories.example.com</domain>
<trust-anchors>
<certificates src="@raw/partner_root_ca" />
<certificates src="system" />
</trust-anchors>
</domain-config>
</network-security-config>
Android accepts PEM or DER certificates in res/raw; the SDK initialization parameter expects
DER-encoded X.509 CA data. Add every media or WebView hostname that uses the private CA, or set
includeSubdomains="true" only when all subdomains should trust it. A domain-scoped configuration
keeps the CA from becoming a trust anchor for every host used by the app.
If media or WebView traffic also needs public-key pinning, add a domain-scoped <pin-set> to the
same domain-config and include a backup pin. The Network Security Configuration <pin> value is
the Base64 SHA-256 SPKI hash without the sha256/ prefix; certificatePins in SDK initialization
uses the sha256/ prefix:
<pin-set expiration="2028-12-31">
<pin digest="SHA-256">YOUR_BASE64_SPKI_HASH</pin>
<pin digest="SHA-256">YOUR_BACKUP_BASE64_SPKI_HASH</pin>
</pin-set>
Network Security Configuration is available from Android 7.0 (API 24). The SDK's
trustedCACertificates option configures its API client and same-host media downloads on supported
older Android versions too. Different CDN hosts and WebView requests on Android 5.x and 6.x need
another compatible trust configuration or a publicly trusted host.