How simformsolutionspvtltd/flutter_ssl_pinning works
Project type and purpose
• This is a Flutter cross-platform client application (mobile, desktop, web) whose sole responsibility is to demonstrate and implement SSL/TLS certificate pinning in outgoing HTTP requests.
• There is no backend code in this repo; instead the app communicates with an external API server over HTTPS and ensures only a pinned certificate is accepted.
File structure
• Top-level “android”, “ios”, “linux”, “macos”, “windows”, “web” directories: platform shells and build scripts generated by Flutter.
• “lib/” contains the entire Dart codebase:
• main.dart – entry point and UI widget tree
• model/ – data model classes (e.g. UserResponseDm)
• network/ – repository and networking code:
· api_base_repository.dart – base class that configures Dio and HttpClient
· certificate_utils.dart – loads and pins the certificate into a SecurityContext
· user_repository.dart – concrete repository for user-related API calls
• pubspec.yaml – declares dependencies (dio, flutter) and asset (certificate file) locations.
• test/ – example widget test.
Key README insights
• Emphasizes use of dio package for network requests.
• Instructs on placing the server’s SSL certificate in assets.
• Describes creating and wiring a SecurityContext to an HttpClient for strict pinning and rejecting all other certificates.
Main components
A. Platform Shells
• Android / iOS / macOS / Linux / Windows / Web containers (Flutter engine + native bootstrap)
B. Flutter Engine & Runtime
• Skia/OpenGL renderer, Dart VM (in debug/profile) or AOT runtime (in release)
C. Dart Layers
1. Presentation Layer
– Widgets and UI in main.dart
2. Data Model Layer
– user_response_dm.dart and other DTOs
3. Network Layer
a. CertificateUtils
• Loads PEM file from assets → sets up SecurityContext
b. ApiBaseRepository
• Configures Dio’s HttpClientAdapter to use the SecurityContext
• Overrides badCertificateCallback → rejects untrusted certs
c. UserRepository
• Exposes methods (e.g., fetchUser) that call ApiBaseRepository
D. External Services
• Remote HTTPS API Server with pinned certificate
Interactions and data flow
• UI Widget issues a “fetch” action → calls UserRepository.fetchUser()
• UserRepository → ApiBaseRepository → constructs Dio request
• ApiBaseRepository → SecurityContext (from CertificateUtils) is attached to HttpClient
• HttpClient performs TLS handshake
• Only accepts the exact pinned certificate
• Rejects others via badCertificateCallback
• On success, JSON is returned → parsed into UserResponseDm → bubbled back to UI
Architectural patterns & principles
• Layered architecture: clear separation between UI, business logic (repositories), models, and networking.
• Single-responsibility: Certificate pinning logic isolated in CertificateUtils.
• Dependency inversion: repository depends on abstracted ApiBaseRepository rather than on Dio directly.