Skip to content

Commit f3b03e0

Browse files
RMET-3408 KeyStore Plugin - Prepare release of version 2.6.8-OS19 (#29)
* 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
1 parent b22c283 commit f3b03e0

File tree

6 files changed

+77
-19
lines changed

6 files changed

+77
-19
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Changelog
44
Unreleased
55
------------------
66

7+
2.6.8-OS19 - 2024-05-03
8+
------------------
9+
10+
- Feat: [Android] Add parameters for title, subtitle, and negative button text of Biometric Prompt (https://outsystemsrd.atlassian.net/browse/RMET-3408).
11+
712
2.6.8-OS18 - 2024-01-11
813
------------------
914

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
1-
const et = require('elementtree');
21
const path = require('path');
32
const fs = require('fs');
43
const { ConfigParser } = require('cordova-common');
4+
const { DOMParser, XMLSerializer } = require('xmldom');
55

66
module.exports = function (context) {
7-
var projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
8-
var configXML = path.join(projectRoot, 'config.xml');
9-
var configParser = new ConfigParser(configXML);
10-
var authenticate = configParser.getGlobalPreference("MigratedKeysAuthentication");
7+
const projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
8+
const configXML = path.join(projectRoot, 'config.xml');
9+
const configParser = new ConfigParser(configXML);
10+
const parser = new DOMParser();
11+
12+
const authenticate = configParser.getGlobalPreference('MigratedKeysAuthentication');
13+
const auth_prompt_title = configParser.getPreference('AuthPromptTitle', 'android')
14+
const auth_prompt_subtitle = configParser.getPreference('AuthPromptSubtitle', 'android')
15+
const auth_prompt_negative_button = configParser.getPreference('AuthPromptCancelButton', 'android')
16+
17+
const stringsXmlPath = path.join(projectRoot, 'platforms/android/app/src/main/res/values/strings.xml');
18+
const stringsXmlString = fs.readFileSync(stringsXmlPath, 'utf-8');
19+
const stringsXmlDoc = parser.parseFromString(stringsXmlString, 'text/xml')
1120

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

17-
var migrationAuthTags = etreeStrings.findall('./bool[@name="migration_auth"]');
18-
for (var i = 0; i < migrationAuthTags.length; i++) {
19-
migrationAuthTags[i].text = authenticate;
25+
// set text for each <bool> element
26+
for (let i = 0; i < booleanElements.length; i++) {
27+
const name = booleanElements[i].getAttribute('name');
28+
if (name == "migration_auth") {
29+
booleanElements[i].textContent = authenticate;
30+
}
2031
}
32+
}
2133

22-
var resultXmlStrings = etreeStrings.write();
23-
fs.writeFileSync(stringsXmlPath, resultXmlStrings);
34+
// insert string values in strings.xml
35+
const stringElements = stringsXmlDoc.getElementsByTagName('string');
36+
37+
// set text for each <string> element
38+
for (let i = 0; i < stringElements.length; i++) {
39+
const name = stringElements[i].getAttribute('name');
40+
if (name == "biometric_prompt_title" && auth_prompt_title != "") {
41+
stringElements[i].textContent = auth_prompt_title;
42+
}
43+
else if (name == "biometric_prompt_subtitle" && auth_prompt_subtitle != "") {
44+
stringElements[i].textContent = auth_prompt_subtitle;
45+
}
46+
else if (name == "biometric_prompt_negative_button" && auth_prompt_negative_button != "") {
47+
stringElements[i].textContent = auth_prompt_negative_button;
48+
}
2449
}
50+
51+
// serialize the updated XML document back to string
52+
const serializer = new XMLSerializer();
53+
const updatedXmlString = serializer.serializeToString(stringsXmlDoc);
54+
55+
// write the updated XML string back to the same file
56+
fs.writeFileSync(stringsXmlPath, updatedXmlString, 'utf-8');
57+
2558
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-secure-storage",
3-
"version": "2.6.8-OS18",
3+
"version": "2.6.8-OS19",
44
"description": "Secure storage plugin for iOS & Android",
55
"author": "Yiorgis Gozadinos <ggozad@crypho.com>",
66
"contributors": [
@@ -50,5 +50,8 @@
5050
"bugs": {
5151
"url": "https://github.com/crypho/cordova-plugin-secure-storage/issues"
5252
},
53-
"homepage": "https://github.com/crypho/cordova-plugin-secure-storage#readme"
53+
"homepage": "https://github.com/crypho/cordova-plugin-secure-storage#readme",
54+
"dependencies": {
55+
"xmldom": "^0.6.0"
56+
}
5457
}

plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="cordova-plugin-secure-storage"
5-
version="2.6.8-OS18">
5+
version="2.6.8-OS19">
66

77
<name>SecureStorage</name>
88
<author>Crypho AS</author>
@@ -66,6 +66,9 @@
6666

6767
<config-file parent="/resources" target="res/values/strings.xml">
6868
<bool name="migration_auth">false</bool>
69+
<string name="biometric_prompt_title">Authentication required</string>
70+
<string name="biometric_prompt_subtitle">Please authenticate to continue</string>
71+
<string name="biometric_prompt_negative_button">Cancel</string>
6972
</config-file>
7073

7174
<source-file src="src/android/AES.java" target-dir="src/com/crypho/plugins/" />

src/android/SecureStorage.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.outsystems.plugins.keystore.controller.KeystoreController;
3333
import com.outsystems.plugins.keystore.controller.KeystoreError;
34+
import com.outsystems.plugins.keystore.controller.OSKSTRBiometricPromptInfo;
3435

3536
import org.apache.cordova.CallbackContext;
3637
import org.apache.cordova.CordovaArgs;
@@ -75,8 +76,13 @@ protected void pluginInitialize() {
7576

7677
intentRequestQueue = new IntentRequestQueue(this);
7778

78-
keystoreController = new KeystoreController();
79-
79+
keystoreController = new KeystoreController(
80+
new OSKSTRBiometricPromptInfo(
81+
getStringResource(this.cordova.getActivity(), "biometric_prompt_title"),
82+
getStringResource(this.cordova.getActivity(), "biometric_prompt_subtitle"),
83+
getStringResource(this.cordova.getActivity(), "biometric_prompt_negative_button")
84+
)
85+
);
8086
}
8187

8288

@@ -947,5 +953,13 @@ private String formatErrorCode(int code) {
947953
private int getBooleanResourceId(Activity activity, String name) {
948954
return activity.getResources().getIdentifier(name, "bool", activity.getPackageName());
949955
}
956+
957+
private int getStringResourceId(Activity activity, String name) {
958+
return activity.getResources().getIdentifier(name, "string", activity.getPackageName());
959+
}
960+
961+
private String getStringResource(Activity activity, String name) {
962+
return activity.getString(getStringResourceId(activity, name));
963+
}
950964

951965
}

src/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ dependencies {
2424
implementation("com.github.outsystems:oscordova-android:1.1.0@aar")
2525
implementation("androidx.security:security-crypto:1.1.0-alpha03")
2626
implementation("androidx.biometric:biometric:1.1.0")
27-
implementation("com.github.outsystems:oskeystore-android:1.0.4@aar")
27+
implementation("com.github.outsystems:oskeystore-android:1.1.0@aar")
2828
}

0 commit comments

Comments
 (0)