Skip to content

Commit

Permalink
RMET-3408 KeyStore Plugin - Prepare release of version 2.6.8-OS19 (#29
Browse files Browse the repository at this point in the history
)

* RMET-3408 KeyStore Plugin - Set auth prompt text (title, subtitle, and negative button) (#28)

* feat: get biometric prompt info from strings.xml and pass them to library

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* feat: copy biometric prompt info to strings.xml in hook

References:

* feat: check of biometric prompt info is not empty

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* fix: properly use getPreference method, passing in the platform (android)

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* refactor: use const instead of var

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* chore: update dependency to OSKeystoreLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* fix: add dependency to xmldom

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* fix: create DOMParser() instance

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* fix: get android preferences properly

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* refactor: remove unused code

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* revert: revert change in previous commit

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* chore: raise to version 2.6.8-OS19

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* chore: update dependency to OSKeystoreLib-Android

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* fix: properly check if field is empty string

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* misc: set version to an existing one

References: https://outsystemsrd.atlassian.net/browse/RMET-3408

* chore: update dependency to OSKeystoreAndroid-Lib

References: https://outsystemsrd.atlassian.net/browse/RMET-3408
  • Loading branch information
alexgerardojacinto authored May 8, 2024
1 parent b22c283 commit f3b03e0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
Unreleased
------------------

2.6.8-OS19 - 2024-05-03
------------------

- Feat: [Android] Add parameters for title, subtitle, and negative button text of Biometric Prompt (https://outsystemsrd.atlassian.net/browse/RMET-3408).

2.6.8-OS18 - 2024-01-11
------------------

Expand Down
59 changes: 46 additions & 13 deletions hooks/android/androidCopyPreferences.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,58 @@
const et = require('elementtree');
const path = require('path');
const fs = require('fs');
const { ConfigParser } = require('cordova-common');
const { DOMParser, XMLSerializer } = require('xmldom');

module.exports = function (context) {
var projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
var configXML = path.join(projectRoot, 'config.xml');
var configParser = new ConfigParser(configXML);
var authenticate = configParser.getGlobalPreference("MigratedKeysAuthentication");
const projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
const configXML = path.join(projectRoot, 'config.xml');
const configParser = new ConfigParser(configXML);
const parser = new DOMParser();

const authenticate = configParser.getGlobalPreference('MigratedKeysAuthentication');
const auth_prompt_title = configParser.getPreference('AuthPromptTitle', 'android')
const auth_prompt_subtitle = configParser.getPreference('AuthPromptSubtitle', 'android')
const auth_prompt_negative_button = configParser.getPreference('AuthPromptCancelButton', 'android')

const stringsXmlPath = path.join(projectRoot, 'platforms/android/app/src/main/res/values/strings.xml');
const stringsXmlString = fs.readFileSync(stringsXmlPath, 'utf-8');
const stringsXmlDoc = parser.parseFromString(stringsXmlString, 'text/xml')

if(authenticate == "true"){
var stringsXmlPath = path.join(projectRoot, 'platforms/android/app/src/main/res/values/strings.xml');
var stringsXmlContents = fs.readFileSync(stringsXmlPath).toString();
var etreeStrings = et.parse(stringsXmlContents);
// insert bool value in strings.xml
const booleanElements = stringsXmlDoc.getElementsByTagName('bool');

var migrationAuthTags = etreeStrings.findall('./bool[@name="migration_auth"]');
for (var i = 0; i < migrationAuthTags.length; i++) {
migrationAuthTags[i].text = authenticate;
// set text for each <bool> element
for (let i = 0; i < booleanElements.length; i++) {
const name = booleanElements[i].getAttribute('name');
if (name == "migration_auth") {
booleanElements[i].textContent = authenticate;
}
}
}

var resultXmlStrings = etreeStrings.write();
fs.writeFileSync(stringsXmlPath, resultXmlStrings);
// insert string values in strings.xml
const stringElements = stringsXmlDoc.getElementsByTagName('string');

// set text for each <string> element
for (let i = 0; i < stringElements.length; i++) {
const name = stringElements[i].getAttribute('name');
if (name == "biometric_prompt_title" && auth_prompt_title != "") {
stringElements[i].textContent = auth_prompt_title;
}
else if (name == "biometric_prompt_subtitle" && auth_prompt_subtitle != "") {
stringElements[i].textContent = auth_prompt_subtitle;
}
else if (name == "biometric_prompt_negative_button" && auth_prompt_negative_button != "") {
stringElements[i].textContent = auth_prompt_negative_button;
}
}

// serialize the updated XML document back to string
const serializer = new XMLSerializer();
const updatedXmlString = serializer.serializeToString(stringsXmlDoc);

// write the updated XML string back to the same file
fs.writeFileSync(stringsXmlPath, updatedXmlString, 'utf-8');

};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-secure-storage",
"version": "2.6.8-OS18",
"version": "2.6.8-OS19",
"description": "Secure storage plugin for iOS & Android",
"author": "Yiorgis Gozadinos <[email protected]>",
"contributors": [
Expand Down Expand Up @@ -50,5 +50,8 @@
"bugs": {
"url": "https://github.com/crypho/cordova-plugin-secure-storage/issues"
},
"homepage": "https://github.com/crypho/cordova-plugin-secure-storage#readme"
"homepage": "https://github.com/crypho/cordova-plugin-secure-storage#readme",
"dependencies": {
"xmldom": "^0.6.0"
}
}
5 changes: 4 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-secure-storage"
version="2.6.8-OS18">
version="2.6.8-OS19">

<name>SecureStorage</name>
<author>Crypho AS</author>
Expand Down Expand Up @@ -66,6 +66,9 @@

<config-file parent="/resources" target="res/values/strings.xml">
<bool name="migration_auth">false</bool>
<string name="biometric_prompt_title">Authentication required</string>
<string name="biometric_prompt_subtitle">Please authenticate to continue</string>
<string name="biometric_prompt_negative_button">Cancel</string>
</config-file>

<source-file src="src/android/AES.java" target-dir="src/com/crypho/plugins/" />
Expand Down
18 changes: 16 additions & 2 deletions src/android/SecureStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import com.outsystems.plugins.keystore.controller.KeystoreController;
import com.outsystems.plugins.keystore.controller.KeystoreError;
import com.outsystems.plugins.keystore.controller.OSKSTRBiometricPromptInfo;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
Expand Down Expand Up @@ -75,8 +76,13 @@ protected void pluginInitialize() {

intentRequestQueue = new IntentRequestQueue(this);

keystoreController = new KeystoreController();

keystoreController = new KeystoreController(
new OSKSTRBiometricPromptInfo(
getStringResource(this.cordova.getActivity(), "biometric_prompt_title"),
getStringResource(this.cordova.getActivity(), "biometric_prompt_subtitle"),
getStringResource(this.cordova.getActivity(), "biometric_prompt_negative_button")
)
);
}


Expand Down Expand Up @@ -947,5 +953,13 @@ private String formatErrorCode(int code) {
private int getBooleanResourceId(Activity activity, String name) {
return activity.getResources().getIdentifier(name, "bool", activity.getPackageName());
}

private int getStringResourceId(Activity activity, String name) {
return activity.getResources().getIdentifier(name, "string", activity.getPackageName());
}

private String getStringResource(Activity activity, String name) {
return activity.getString(getStringResourceId(activity, name));
}

}
2 changes: 1 addition & 1 deletion src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ dependencies {
implementation("com.github.outsystems:oscordova-android:1.1.0@aar")
implementation("androidx.security:security-crypto:1.1.0-alpha03")
implementation("androidx.biometric:biometric:1.1.0")
implementation("com.github.outsystems:oskeystore-android:1.0.4@aar")
implementation("com.github.outsystems:oskeystore-android:1.1.0@aar")
}

0 comments on commit f3b03e0

Please sign in to comment.