fast_rsa package integration

pull/1/head
Zachary Atkins 3 years ago
parent 5bff5a0c42
commit 7e14d242c9

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"

@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end

@ -0,0 +1,28 @@
PODS:
- fast_rsa (0.6.0):
- Flutter
- Flutter (1.0.0)
- path_provider (0.0.1):
- Flutter
DEPENDENCIES:
- fast_rsa (from `.symlinks/plugins/fast_rsa/ios`)
- Flutter (from `Flutter`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
EXTERNAL SOURCES:
fast_rsa:
:path: ".symlinks/plugins/fast_rsa/ios"
Flutter:
:path: Flutter
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
SPEC CHECKSUMS:
fast_rsa: 348fa9c4afd02ab8659480e679f647f454acc80e
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
COCOAPODS: 1.10.1

@ -13,6 +13,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
E1C832068AB674471A23DFC7 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C427E90E3BB69D6B911A804 /* Pods_Runner.framework */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -31,10 +32,14 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2C427E90E3BB69D6B911A804 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
31DACBD0B66191129EC4BA7F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
65E120A3551B34655C1793C5 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
8F26C49D78C6505C4C9F3FDA /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -49,12 +54,24 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E1C832068AB674471A23DFC7 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
69EB72FA53A9891457653AAB /* Pods */ = {
isa = PBXGroup;
children = (
8F26C49D78C6505C4C9F3FDA /* Pods-Runner.debug.xcconfig */,
65E120A3551B34655C1793C5 /* Pods-Runner.release.xcconfig */,
31DACBD0B66191129EC4BA7F /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
@ -72,6 +89,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
69EB72FA53A9891457653AAB /* Pods */,
FCDA85F51884D241BBF6E2C7 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -98,6 +117,14 @@
path = Runner;
sourceTree = "<group>";
};
FCDA85F51884D241BBF6E2C7 /* Frameworks */ = {
isa = PBXGroup;
children = (
2C427E90E3BB69D6B911A804 /* Pods_Runner.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -105,12 +132,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
26B33161B5A1B29F50036AAB /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
10B41FA962D6462BEAB7F8B2 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
@ -169,6 +198,45 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
10B41FA962D6462BEAB7F8B2 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
26B33161B5A1B29F50036AAB /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;

@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

@ -1,7 +1,54 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rsa_encrypt/rsa_encrypt.dart' as rsa;
import 'package:pointycastle/api.dart' as crypto;
import 'package:flutter/widgets.dart';
import 'package:fast_rsa/rsa.dart';
import 'package:fast_rsa/model/bridge.pb.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:io';
class KeyFileManager {
static Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
static Future<File> get _pubKeyFile async {
final path = await _localPath;
return File('$path/rsa.pub');
}
static Future<File> get _privKeyFile async {
final path = await _localPath;
return File('$path/rsa');
}
static Future<KeyPair> readKeyPair() async {
try {
String privKey = await _privKeyFile.then(
(file) => file.readAsString(),
);
String pubKey = await _pubKeyFile.then(
(file) => file.readAsString(),
);
return KeyPair(
privateKey: privKey,
publicKey: pubKey,
);
} catch (e) {
print(e);
return KeyPair();
}
}
static Future<void> writeKeyPair(KeyPair pair) async {
final File privKeyFile = await _privKeyFile;
final File pubKeyFile = await _pubKeyFile;
pubKeyFile.writeAsString(pair.publicKey);
privKeyFile.writeAsString(pair.privateKey);
}
}
class KeygenPage extends StatefulWidget {
KeygenPage({Key key, this.title}) : super(key: key);
@ -12,76 +59,81 @@ class KeygenPage extends StatefulWidget {
}
class _KeygenState extends State<KeygenPage> {
static crypto.AsymmetricKeyPair _keyPair;
KeyPair _keyPair = KeyPair();
@override
void initState() {
super.initState();
KeyFileManager.readKeyPair().then((keyPair) {
if (!keyPair.hasPublicKey()) {
initKeyPair();
} else {
setState(() => _keyPair = keyPair);
}
});
}
void _regenerateKey() {
Future<void> initKeyPair() async {
var keyPair = await RSA.generate(2048);
await KeyFileManager.writeKeyPair(keyPair);
setState(() {
_keyPair = rsa.getRsaKeyPair(rsa.RsaKeyHelper().getSecureRandom());
_keyPair = keyPair;
});
}
String _getPublicKey() {
if (_keyPair == null)
return 'Press the button below to generate your key pair!';
return '${rsa.RsaKeyHelper().encodePublicKeyToPemPKCS1(_keyPair.publicKey)}';
void copyPublicKey() {
if (_keyPair.hasPublicKey()) {
Clipboard.setData(
new ClipboardData(
text: _keyPair.publicKey,
),
).then((_) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("RSA public key copied to keyboard"),
),
);
});
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("You need to generate an RSA keypair before copying."),
),
);
}
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text('RSA Key Configuration'),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () => Clipboard.setData(
new ClipboardData(
text: _getPublicKey(),
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return ListView(
children: <Widget>[
Container(
padding: const EdgeInsets.all(32),
child: TextButton(
onPressed: copyPublicKey,
child: Text(
_keyPair.publicKey,
style: Theme.of(context).textTheme.bodyText1,
softWrap: true,
),
style: Theme.of(context).outlinedButtonTheme.style,
),
),
ElevatedButton(
onPressed: initKeyPair,
child: Text('Reset RSA Key'),
style: Theme.of(context).elevatedButtonTheme.style,
),
).then((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("RSA public key copied to keyboard"),
));
}),
child: Text(
_getPublicKey(),
style: Theme.of(context).textTheme.bodyText1,
),
style: Theme.of(context).outlinedButtonTheme.style,
),
ElevatedButton(
onPressed: _regenerateKey,
child: Text('Reset RSA Key'),
style: Theme.of(context).elevatedButtonTheme.style,
),
],
],
);
},
),
),
);

@ -1,13 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
asn1lib:
dependency: transitive
description:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.1"
async:
dependency: transitive
description:
@ -64,6 +57,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
fast_rsa:
dependency: "direct main"
description:
name: fast_rsa
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.6"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
fixnum:
dependency: transitive
description:
name: fixnum
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.11"
flutter:
dependency: "direct main"
description: flutter
@ -74,6 +95,18 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
matcher:
dependency: transitive
description:
@ -95,20 +128,69 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pointycastle:
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.28"
path_provider_linux:
dependency: transitive
description:
name: pointycastle
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
rsa_encrypt:
dependency: "direct main"
version: "0.0.1+2"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+8"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+3"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
plugin_platform_interface:
dependency: transitive
description:
name: rsa_encrypt
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.0.3"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.1"
protobuf:
dependency: transitive
description:
name: protobuf
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
sky_engine:
dependency: transitive
description: flutter
@ -170,5 +252,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.4+1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"

@ -28,7 +28,8 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
rsa_encrypt: ^1.0.5
path_provider: ^1.6.28
fast_rsa: ^1.1.4
dev_dependencies:
flutter_test:

Loading…
Cancel
Save