This repository is a work in progress.
This application can be used to demonstrate how easy it is to add self-defense checks using AeroGear to an application.
- Node.js v6.11+
- npm 5.6+
- Ionic CLI v3.20.0 (npm install -g [email protected])
- Android/iOS SDK & Tools
- Minishift with Mobile Core Addon
Install dependencies first via npm i
.
npm run ionic:serve
ionic cordova emulate android
ionic cordova emulate ios
- Provision the Metrics service on OpenShift into a new or existing project
- Create an Android/iOS Application in OpenShift and use
com.redhat.acmebank
as the package name. - Bind the Application and Metrics service then copy the resulting
configuration to the
src
folder here and name itmobile-services.json
. It should look something like this:
{
"version": 1,
"clusterName": "https://192.168.64.23:8443",
"namespace": "acmebank",
"clientId": "myapp-android",
"services": [
{
"id": "metrics",
"name": "metrics",
"type": "metrics",
"url": "https://aerogear-app-metrics-acmebank.192.168.64.23.nip.io/metrics",
"config": {}
}
]
}
- Add the following AeroGear modules/plugins to this project:
ionic cordova plugin add @aerogear/cordova-plugin-aerogear-security --save
ionic cordova plugin add @aerogear/cordova-plugin-aerogear-metrics --save
npm install @aerogear/app --save
npm install @aerogear/security --save
- Create a
src/services/security.ts
file and paste the following content:
import { Injectable } from '@angular/core';
import { SecurityService, SecurityCheckType, SecurityCheck } from '@aerogear/security';
@Injectable()
export class DeviceSecurity {
private securityService: SecurityService;
private isBrowser: boolean
constructor() {
this.isBrowser = document.URL.indexOf('http') === 0
if (!this.isBrowser) {
this.securityService = new SecurityService();
this.securityService.checkManyAndPublishMetric(
SecurityCheckType.notDebugMode,
SecurityCheckType.notRooted,
SecurityCheckType.notEmulated,
SecurityCheckType.hasDeviceLock
);
}
}
private check (check: SecurityCheck) {
if (this.isBrowser) {
// Just flag everything as a "pass" in the browser
return Promise.resolve(true)
}
return this.securityService.check(check)
.then(check => check.passed)
}
isRooted() {
return this.check(SecurityCheckType.notRooted)
// invert result since isRooted should be true if the check returns false
.then((pass) => !pass)
}
isDeviceLockEnabled() {
return this.check(SecurityCheckType.hasDeviceLock)
}
}
- In
app.component.ts
add the followingimport
and initialise the SDK beforeplatform.ready()
:
// Add this to the top of the file
import { init } from '@aerogear/app';
// Necessary to prevent compiler warnings
declare var require: any
// Initialise the mobile services SDK
let appConfig = require('../mobile-services.json');
init(appConfig);
-
In
login.ts
add the following snippets:import { DeviceSecurity } from '../../services/security'
private sec: DeviceSecurity
to the constructorionViewDidEnter() {}
to the class
-
Add the following code in the
ionViewDidEnter()
function you created:
this.sec.isRooted()
.then((rooted) => {
if (rooted) {
let alert = this.alertCtrl.create({
title: 'Insecure Device',
subTitle: 'We detected that this device is rooted. Running as root increases the likelihood of your device being compromised by malicious software that is designed to steal passwords and financial information. Continued use of this application is done so at your own risk.',
buttons: ['OK']
});
alert.present();
}
})
- In
login.ts
update theonPersistChange()
function like so:
this.sec.isDeviceLockEnabled()
.then((lockEnabled) => {
if (!lockEnabled) {
let alert = this.alertCtrl.create({
title: 'Device Lock Required',
subTitle: 'The "Stay Logged In" feature requires a device lock to be enabled. Update your device security settings and try again.',
buttons: ['OK']
});
alert.present();
// Don't allow the checkbox to be checked
this.persistentLogin = false
}
})
- Finally update
app.module.ts
by adding:import { DeviceSecurity } from '../services/security';
at the topDeviceSecurity
to theproviders
Array in the@NgModule
block
Icons made by Roundicons from www.flaticon.com are licensed by CC 3.0 BY
Icons made by Freepik from www.flaticon.com are licensed by CC 3.0 BY
Icons made by Pixel Buddha from www.flaticon.com are licensed by CC 3.0 BY