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

Dio integration for secure_pinning — an Interceptor-shaped facade for pinned TLS validation on Dio traffic.

example/lib/main.dart

import 'dart:io';

import 'package:dio/dio.dart';
import 'package:secure_pinning/secure_pinning.dart' show SecurePinningException;
import 'package:secure_pinning_dio/secure_pinning_dio.dart';

Future<void> main() async {
  final dio = Dio(BaseOptions(baseUrl: 'https://api.example.com'));
  dio.interceptors.add(
    SecurePinningInterceptor.forHost(
      dio,
      'api.example.com',
      // Replace with your own host's real SPKI pins — compute them with:
      //   openssl s_client -connect HOST:443 -servername HOST < /dev/null 2>/dev/null \
      //     | openssl x509 -pubkey -noout \
      //     | openssl pkey -pubin -outform der \
      //     | openssl dgst -sha256 -hex \
      //     | awk '{print $NF}'
      // Always include a backup pin so a future key rotation doesn't
      // brick the app.
      pins: ['hex-spki-hash-1', 'hex-spki-hash-2'],
    ),
  );

  try {
    final response = await dio.get<String>('/');
    stdout.writeln(
      'HTTP ${response.statusCode} — ${(response.data ?? '').length} bytes',
    );
  } on DioException catch (error) {
    final pinningError = error.error;
    if (pinningError is SecurePinningException) {
      stdout.writeln('Pinning failed: $pinningError');
    } else {
      rethrow;
    }
  } finally {
    dio.close();
  }
}
0
likes
160
points
119
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dio integration for secure_pinning — an Interceptor-shaped facade for pinned TLS validation on Dio traffic.

Repository (GitHub)
View/report issues
Contributing

Topics

#security #networking #certificate-pinning #dio

License

Apache-2.0 (license)

Dependencies

dio, flutter, secure_pinning

More

Packages that depend on secure_pinning_dio