ironclad_firmware 0.1.0
ironclad_firmware: ^0.1.0 copied to clipboard
Supply chain and low-level kernel hardware attestation, dm-verity, SELinux, and bootloader integrity analyzer for Flutter & Dart.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:ironclad_firmware/ironclad_firmware.dart';
void main() {
runApp(const FirmwareExampleApp());
}
class FirmwareExampleApp extends StatelessWidget {
const FirmwareExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Ironclad Firmware Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: const Color(0xFF0F172A),
cardColor: const Color(0xFF1E293B),
colorScheme: const ColorScheme.dark(
primary: Color(0xFF38BDF8),
secondary: Color(0xFF10B981),
surface: Color(0xFF1E293B),
),
),
home: const FirmwareHomeScreen(),
);
}
}
class FirmwareHomeScreen extends StatefulWidget {
const FirmwareHomeScreen({super.key});
@override
State<FirmwareHomeScreen> createState() => _FirmwareHomeScreenState();
}
class _FirmwareHomeScreenState extends State<FirmwareHomeScreen> {
FirmwareProbeResult? _probe;
@override
void initState() {
super.initState();
_simulatePristine();
}
void _simulatePristine() async {
final res = await IroncladFirmware.auditFirmware(
systemProperties: {
'ro.boot.flash.locked': '1',
'ro.boot.verifiedbootstate': 'green',
'selinux.mode': 'enforcing',
'ro.boot.veritymode': 'enforcing',
'ro.build.tags': 'release-keys',
'ro.build.display.id': 'UP1A.231005.007',
'kernel.version': 'Linux 5.15.110-g89fa012-android',
},
);
setState(() => _probe = res);
}
void _simulateUnlocked() async {
final res = await IroncladFirmware.auditFirmware(
systemProperties: {
'ro.boot.flash.locked': '0',
'ro.boot.verifiedbootstate': 'orange',
'selinux.mode': 'enforcing',
'ro.boot.veritymode': 'enforcing',
'ro.build.tags': 'release-keys',
},
);
setState(() => _probe = res);
}
void _simulateSpywareCompromise() async {
final res = await IroncladFirmware.auditFirmware(
systemProperties: {
'ro.boot.flash.locked': '0',
'ro.boot.verifiedbootstate': 'red',
'selinux.mode': 'permissive',
'ro.boot.veritymode': 'disabled',
'ro.build.tags': 'test-keys',
'ro.build.display.id': 'lineage_arm64-userdebug',
},
);
setState(() => _probe = res);
}
@override
Widget build(BuildContext context) {
if (_probe == null) return const Scaffold(body: Center(child: CircularProgressIndicator()));
final isSecure = _probe!.isSecureHardware;
final score = _probe!.trustScore;
final scoreColor = score >= 80
? const Color(0xFF10B981)
: score >= 50
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
return Scaffold(
appBar: AppBar(
title: const Text('Ironclad Firmware & Kernel Trust'),
backgroundColor: const Color(0xFF1E293B),
elevation: 0,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildScoreHeader(score, scoreColor, isSecure),
const SizedBox(height: 16),
_buildHardwareGrid(),
const SizedBox(height: 16),
_buildSimulatorActions(),
const SizedBox(height: 16),
_buildAnomaliesList(),
],
),
),
);
}
Widget _buildScoreHeader(double score, Color color, bool isSecure) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(color: color, width: 1.5),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
width: 72,
height: 72,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color.withValues(alpha: 0.15),
border: Border.all(color: color, width: 2),
),
alignment: Alignment.center,
child: Text(
'${score.toInt()}%',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: color),
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
isSecure ? 'HARDWARE ATTESTATION: VERIFIED' : 'HARDWARE ANOMALIES DETECTED',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: color),
),
const SizedBox(height: 4),
Text(
'AVB: ${_probe!.verifiedBootState.name.toUpperCase()} • SELinux: ${_probe!.selinuxMode.name.toUpperCase()}',
style: const TextStyle(fontSize: 12, color: Colors.white70),
),
const SizedBox(height: 4),
Text(
'Kernel: ${_probe!.kernelVersion}',
style: const TextStyle(fontSize: 10, color: Colors.white38),
),
],
),
),
],
),
),
);
}
Widget _buildHardwareGrid() {
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Hardware & Bootloader Checks',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFF38BDF8)),
),
const SizedBox(height: 12),
_buildCheckRow(
'Bootloader Lock',
_probe!.isBootloaderLocked ? 'LOCKED' : 'UNLOCKED',
_probe!.isBootloaderLocked,
),
const Divider(color: Colors.white10),
_buildCheckRow(
'Verified Boot (AVB)',
_probe!.verifiedBootState.name.toUpperCase(),
_probe!.verifiedBootState == VerifiedBootState.green,
),
const Divider(color: Colors.white10),
_buildCheckRow(
'SELinux Sandbox',
_probe!.selinuxMode.name.toUpperCase(),
_probe!.selinuxMode == SelinuxMode.enforcing,
),
const Divider(color: Colors.white10),
_buildCheckRow(
'dm-verity System Partition',
_probe!.isDmVerityEnforcing ? 'ENFORCING' : 'DISABLED',
_probe!.isDmVerityEnforcing,
),
const Divider(color: Colors.white10),
_buildCheckRow(
'OS Build Integrity',
_probe!.isCustomRomDetected ? 'UNOFFICIAL TEST-KEYS' : 'OFFICIAL RELEASE',
!_probe!.isCustomRomDetected,
),
],
),
),
);
}
Widget _buildCheckRow(String title, String value, bool isOk) {
final clr = isOk ? const Color(0xFF10B981) : const Color(0xFFEF4444);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(title, style: const TextStyle(fontSize: 12, color: Colors.white70)),
Row(
children: [
Icon(isOk ? Icons.check_circle : Icons.warning_amber, size: 14, color: clr),
const SizedBox(width: 4),
Text(value, style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: clr)),
],
),
],
),
);
}
Widget _buildSimulatorActions() {
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Simulate Hardware Profiles',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFF38BDF8)),
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
ElevatedButton.icon(
icon: const Icon(Icons.shield, size: 16),
label: const Text('Official OEM (100%)'),
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF059669)),
onPressed: _simulatePristine,
),
ElevatedButton.icon(
icon: const Icon(Icons.lock_open, size: 16),
label: const Text('Unlocked Bootloader'),
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFD97706)),
onPressed: _simulateUnlocked,
),
ElevatedButton.icon(
icon: const Icon(Icons.bug_report, size: 16),
label: const Text('Kernel Spyware / Custom ROM'),
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFDC2626)),
onPressed: _simulateSpywareCompromise,
),
],
),
],
),
),
);
}
Widget _buildAnomaliesList() {
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Detected Hardware Anomalies',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFF38BDF8)),
),
const SizedBox(height: 8),
if (_probe!.anomalies.isEmpty)
const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Text('Zero supply chain or kernel anomalies detected. Hardware integrity intact.',
style: TextStyle(color: Colors.greenAccent, fontSize: 12)),
)
else
..._probe!.anomalies.map(
(a) => Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Icon(Icons.error_outline, size: 16, color: Colors.redAccent),
const SizedBox(width: 8),
Expanded(child: Text(a, style: const TextStyle(fontSize: 12, color: Colors.white70))),
],
),
),
),
],
),
),
);
}
}