setup method
- TrustPinConfiguration configuration
Initializes this TrustPin instance with the specified configuration.
This method configures TrustPin with your organization credentials and fetches the pinning configuration from the TrustPin service. The configuration is cached for 10 minutes to optimize performance and reduce network requests.
Example Usage
// Production setup with strict mode
const config = TrustPinConfiguration(
organizationId: 'prod-org-123',
projectId: 'mobile-app-v2',
publicKey: 'LS0tLS1CRUdJTi...',
mode: TrustPinMode.strict,
);
await TrustPin.shared.setup(config);
// Development setup with permissive mode
const devConfig = TrustPinConfiguration(
organizationId: 'dev-org-456',
projectId: 'mobile-app-staging',
publicKey: 'LS0tLS1CRUdJTk...',
mode: TrustPinMode.permissive,
);
await TrustPin.shared.setup(devConfig);
Security Considerations
- Production: Always use TrustPinMode.strict mode to ensure all connections are validated
- Development: Use TrustPinMode.permissive mode to allow connections to unregistered domains
- Credentials: Keep your public key secure and never commit it to version control in plain text
Network Requirements
This method requires network access to fetch the pinning configuration from
https://cdn.trustpin.cloud. Ensure your app has appropriate network permissions
and can reach this endpoint.
-
Parameter
configuration: A TrustPinConfiguration containing your organization credentials, project info, and pinning settings -
Throws TrustPinException with code
INVALID_PROJECT_CONFIGif credentials are invalid or empty -
Throws TrustPinException with code
ERROR_FETCHING_PINNING_INFOif network request fails -
Throws TrustPinException with code
CONFIGURATION_VALIDATION_FAILEDif configuration validation fails -
Important: This method must be called before any certificate verification operations.
-
Note: Configuration is automatically cached for 10 minutes to improve performance.
Implementation
Future<void> setup(TrustPinConfiguration configuration) async {
try {
await TrustPinSDKPlatform.instance.setup(
configuration.organizationId,
configuration.projectId,
configuration.publicKey,
configurationURL: configuration.configurationURL,
mode: configuration.mode.value,
instanceId: _instanceId,
);
} catch (e) {
throw TrustPinException.fromPlatformException(e);
}
}