trustpin_sdk 0.0.2 copy "trustpin_sdk: ^0.0.2" to clipboard
trustpin_sdk: ^0.0.2 copied to clipboard

A Flutter plugin for TrustPin SSL certificate pinning SDK that provides enhanced security for network connections by validating SSL certificates against configured pins.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:trustpin_sdk/trustpin_sdk.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _status = 'Not initialized';
  bool _isSetup = false;
  final _trustpinSdkPlugin = TrustPinSDK();
  
  final _orgIdController = TextEditingController();
  final _projectIdController = TextEditingController();
  final _publicKeyController = TextEditingController();
  final _domainController = TextEditingController();
  final _certificateController = TextEditingController();

  @override
  void initState() {
    super.initState();
    initPlatformState();
    
    // Pre-fill some example values for testing
    _orgIdController.text = 'your-org-id';
    _projectIdController.text = 'your-project-id';
    _publicKeyController.text = 'your-base64-public-key';
    _domainController.text = 'api.example.com';
    _certificateController.text = '''-----BEGIN CERTIFICATE-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
-----END CERTIFICATE-----''';
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion =
          await _trustpinSdkPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> _setupTrustPin() async {
    try {
      await _trustpinSdkPlugin.setup(
        organizationId: _orgIdController.text,
        projectId: _projectIdController.text,
        publicKey: _publicKeyController.text,
        mode: TrustPinMode.strict,
      );
      
      setState(() {
        _status = 'Setup successful!';
        _isSetup = true;
      });
    } catch (e) {
      setState(() {
        _status = 'Setup failed: $e';
        _isSetup = false;
      });
    }
  }

  Future<void> _verifyDomain() async {
    if (!_isSetup) {
      setState(() {
        _status = 'Please setup TrustPin first';
      });
      return;
    }

    try {
      await _trustpinSdkPlugin.verify(
        _domainController.text,
        _certificateController.text,
      );
      
      setState(() {
        _status = 'Certificate verification successful!';
      });
    } catch (e) {
      setState(() {
        _status = 'Verification failed: $e';
      });
    }
  }

  Future<void> _setDebugLogging() async {
    try {
      await _trustpinSdkPlugin.setLogLevel(TrustPinLogLevel.debug);
      setState(() {
        _status = 'Debug logging enabled';
      });
    } catch (e) {
      setState(() {
        _status = 'Failed to set log level: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('TrustPin SDK Example'),
          backgroundColor: Colors.blue,
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Text(
                  'Running on: $_platformVersion',
                  style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 16),
                
                Text(
                  'Status: $_status',
                  style: TextStyle(
                    fontSize: 14,
                    color: _status.contains('successful') ? Colors.green : 
                           _status.contains('failed') || _status.contains('Failed') ? Colors.red : 
                           Colors.orange,
                  ),
                ),
                const SizedBox(height: 24),

                // Setup Section
                Card(
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const Text(
                          'Setup TrustPin',
                          style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                        ),
                        const SizedBox(height: 16),
                        TextField(
                          controller: _orgIdController,
                          decoration: const InputDecoration(
                            labelText: 'Organization ID',
                            border: OutlineInputBorder(),
                          ),
                        ),
                        const SizedBox(height: 8),
                        TextField(
                          controller: _projectIdController,
                          decoration: const InputDecoration(
                            labelText: 'Project ID',
                            border: OutlineInputBorder(),
                          ),
                        ),
                        const SizedBox(height: 8),
                        TextField(
                          controller: _publicKeyController,
                          decoration: const InputDecoration(
                            labelText: 'Public Key (Base64)',
                            border: OutlineInputBorder(),
                          ),
                          maxLines: 3,
                        ),
                        const SizedBox(height: 16),
                        ElevatedButton(
                          onPressed: _setupTrustPin,
                          child: const Text('Setup TrustPin'),
                        ),
                      ],
                    ),
                  ),
                ),
                const SizedBox(height: 16),

                // Verify Section
                Card(
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const Text(
                          'Verify Certificate',
                          style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                        ),
                        const SizedBox(height: 16),
                        TextField(
                          controller: _domainController,
                          decoration: const InputDecoration(
                            labelText: 'Domain',
                            border: OutlineInputBorder(),
                          ),
                        ),
                        const SizedBox(height: 8),
                        TextField(
                          controller: _certificateController,
                          decoration: const InputDecoration(
                            labelText: 'PEM Certificate',
                            border: OutlineInputBorder(),
                          ),
                          maxLines: 5,
                        ),
                        const SizedBox(height: 16),
                        ElevatedButton(
                          onPressed: _isSetup ? _verifyDomain : null,
                          child: const Text('Verify Certificate'),
                        ),
                      ],
                    ),
                  ),
                ),
                const SizedBox(height: 16),

                // Utilities Section
                Card(
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const Text(
                          'Utilities',
                          style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                        ),
                        const SizedBox(height: 16),
                        ElevatedButton(
                          onPressed: _setDebugLogging,
                          child: const Text('Enable Debug Logging'),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _orgIdController.dispose();
    _projectIdController.dispose();
    _publicKeyController.dispose();
    _domainController.dispose();
    _certificateController.dispose();
    super.dispose();
  }
}
3
likes
0
points
8
downloads

Publisher

verified publishertrustpin.cloud

Weekly Downloads

A Flutter plugin for TrustPin SSL certificate pinning SDK that provides enhanced security for network connections by validating SSL certificates against configured pins.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on trustpin_sdk

Packages that implement trustpin_sdk