ssl_pinning_plugin 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 19

ssl_pinning_plugin

Plugin for check SSL Pinning on request HTTP.

Checks the equality between the known SHA-1 fingerprint and the SHA-1 of the target server.

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Check

###Params

  • serveurUrl : String
  • headerHttp : Map<String, String>
  • allowedSHA1Fingerprint : List<String>
  • timeout : int

###Usage :

await SslPinningPlugin.check(serverURL: url, headerHttp : new Map(), allowedSHA1Fingerprint: new List<String>, timeout : 50);

###Return :

  • On success, return String "CONNECTION_SECURE"
  • On error, return String "CONNECTION_INSECURE"

If an exception, return the stacktrace on String value.

[1.0.0] - 29/05/2018

  • Checks the equality between the known SHA-1 fingerprint and the SHA-1 of the target server.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ssl_pinning_plugin/ssl_pinning_plugin.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _PiningSslData {
  String serverURL = '';
  Map<String, String> headerHttp = new Map();
  String allowedSHA1Fingerprint = '';
  int timeout = 0;
}

class _MyAppState extends State<MyApp> {
  final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
  _PiningSslData _data = new _PiningSslData();
  BuildContext scaffoldContext;

  @override
  initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  check(String url, String fingerprint, Map<String, String> headerHttp, int timeout) async {

    List<String> allowedShA1FingerprintList = new List();
    allowedShA1FingerprintList.add(fingerprint);

    try {
      // Platform messages may fail, so we use a try/catch PlatformException.
      String checkMsg = await SslPinningPlugin.check(serverURL: url,
          headerHttp: headerHttp,
          allowedSHA1Fingerprint: allowedShA1FingerprintList,
          timeout: timeout);

      // If the widget was removed from the tree while the asynchronous platform
      // message was in flight, we want to discard the reply rather than calling
      // setState to update our non-existent appearance.
      if (!mounted)
        return;

      Scaffold.of(scaffoldContext).showSnackBar(
        new SnackBar(
          content: new Text(checkMsg),
          duration: Duration(seconds: 1),
          backgroundColor: Colors.green,
        ),

      );
    }catch (e){
      Scaffold.of(scaffoldContext).showSnackBar(
        new SnackBar(
          content: new Text(e.toString()),
          duration: Duration(seconds: 1),
          backgroundColor: Colors.red,
        ),

      );
    }

  }

  void submit() {
    // First validate form.
    if (_formKey.currentState.validate()) {
      _formKey.currentState.save(); // Save our form now.

      this.check(_data.serverURL, _data.allowedSHA1Fingerprint, _data.headerHttp, _data.timeout);
    }
  }

  @override
  Widget build(BuildContext context) {
    this.scaffoldContext = context;
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Ssl Pinning Plugin'),
        ),
        body:
          new Builder(builder: (BuildContext context) {
            this.scaffoldContext = context;
            return new Container(
              padding: new EdgeInsets.all(20.0),
              child: new Form(
                key: this._formKey,
                child: new ListView(
                children: <Widget>[
                  new TextFormField(
                    keyboardType: TextInputType.url,
                    decoration: new InputDecoration(
                      hintText: 'https://yourdomain.com',
                      labelText: 'URL'
                    ),
                    validator: (value) {
                      if (value.isEmpty) {
                        return 'Please enter some url';
                      }
                    },
                    onSaved: (String value) {
                      this._data.serverURL = value;
                    }
                  ),
                  new TextFormField(
                    keyboardType: TextInputType.text,
                    decoration: new InputDecoration(
                       hintText: 'OO OO OO OO OO OO OO OO OO OO',
                       labelText: 'Fingerprint'
                    ),
                    validator: (value) {
                      if (value.isEmpty) {
                        return 'Please enter some fingerprint';
                      }
                    },
                    onSaved: (String value) {
                      this._data.allowedSHA1Fingerprint = value;
                    }
                  ),
                  new TextFormField(
                      keyboardType: TextInputType.number,
                      initialValue: '60',
                      decoration: new InputDecoration(
                          hintText: '60',
                          labelText: 'Timeout'
                      ),
                      validator: (value) {
                        if (value.isEmpty) {
                          return 'Please enter some timeout';
                        }
                      },
                      onSaved: (String value) {
                        this._data.timeout = int.parse(value);
                      }
                  ),
                  new Container(
                    child: new RaisedButton(
                      child: new Text(
                        'Check',
                        style: new TextStyle(
                          color: Colors.white
                        ),
                      ),
                      onPressed: () => submit(),
                      color: Colors.blue,
                    ),
                    margin: new EdgeInsets.only(
                      top: 20.0
                    ),
                  )
                ],
              ),
            )
          );
        })
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ssl_pinning_plugin: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ssl_pinning_plugin/ssl_pinning_plugin.dart';
  
Version Uploaded Documentation Archive
0.0.1 May 29, 2018 Go to the documentation of ssl_pinning_plugin 0.0.1 Download ssl_pinning_plugin 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
38
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
19
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0