tei_shield_flutter 0.2.0 copy "tei_shield_flutter: ^0.2.0" to clipboard
tei_shield_flutter: ^0.2.0 copied to clipboard

Configurable TEI Shield native Android and iOS assessments for Flutter.

example/lib/main.dart

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

void main() => runApp(const MaterialApp(home: ShieldExample()));

class ShieldExample extends StatefulWidget {
  const ShieldExample({super.key});
  @override
  State<ShieldExample> createState() => _ShieldExampleState();
}

class _ShieldExampleState extends State<ShieldExample> {
  TeiShieldClient? _client;
  StreamSubscription<TeiShieldAssessment>? _subscription;
  StreamSubscription<TeiShieldSignal>? _vpnSubscription;
  TeiShieldSignal? _vpn;
  TeiShieldAssessment? _value;
  String _error = '';

  @override
  void initState() {
    super.initState();
    _vpnSubscription = TeiShield.vpnChanges.listen(
      (signal) { if (mounted) setState(() => _vpn = signal); },
      onError: (Object error) { if (mounted) setState(() => _error = '$error'); },
    );
    unawaited(_start());
  }

  Future<void> _start() async {
    try {
      final client = await TeiShieldClient.initialize(
        options: AssessmentOptions(
            checks: [ShieldCheck.emulator, ShieldCheck.sdkTextIntegrity]),
        runPolicy: const ShieldRunPolicy(
            assessOnInitialize: true, reassessOnForeground: true),
      );
      if (!mounted) {
        await client.close();
        return;
      }
      _subscription = client.assessments.listen(
        (value) {
          if (mounted) setState(() => _value = value);
        },
        onError: (Object error) {
          if (mounted) setState(() => _error = '$error');
        },
      );
      setState(() {
        _client = client;
        _value = client.lastAssessment;
      });
    } catch (error) {
      if (mounted) setState(() => _error = '$error');
    }
  }

  Future<void> _run(bool emulatorOnly) async {
    try {
      if (emulatorOnly) {
        await _client?.check(ShieldCheck.emulator);
      } else {
        await _client?.assess();
      }
    } catch (error) {
      if (mounted) setState(() => _error = '$error');
    }
  }

  @override
  void dispose() {
    unawaited(_subscription?.cancel());
    unawaited(_vpnSubscription?.cancel());
    unawaited(_client?.close());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: const Text('TEI Shield')),
        body: ListView(padding: const EdgeInsets.all(24), children: [
          Text('VPN: ${_vpn?.status.name ?? "waiting"} (network state, not proof of attack)'),
          ElevatedButton(
              onPressed: _client == null ? null : () => _run(true),
              child: const Text('Check emulator only')),
          ElevatedButton(
              onPressed: _client == null ? null : () => _run(false),
              child: const Text('Assess configured checks')),
          for (final signal in _value?.signals ?? <TeiShieldSignal>[])
            ListTile(
                title: Text(signal.code),
                subtitle: Text('${signal.status.name} (${signal.confidence})')),
          Text(_error),
        ]),
      );
}
0
likes
140
points
365
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Configurable TEI Shield native Android and iOS assessments for Flutter.

Homepage
Repository (GitHub)
View/report issues

Topics

#security #integrity #jailbreak-detection #root-detection

License

MIT (license)

Dependencies

flutter

More

Packages that depend on tei_shield_flutter

Packages that implement tei_shield_flutter