Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build improvements #40

Merged
merged 31 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8a67163
chore: update npm org name to @titanium-sdk
sgtcoolguy Oct 15, 2019
1a631f4
chore(package): add husky 3.0.8
sgtcoolguy Oct 15, 2019
e4f0d12
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
ae56439
chore(package): add @commitlint/cli 8.2.0
sgtcoolguy Oct 15, 2019
532327f
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
88a6253
chore(package): add @commitlint/config-conventional 8.2.0
sgtcoolguy Oct 15, 2019
d577462
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
fd4d9fd
style: enforce conventional commits
sgtcoolguy Oct 15, 2019
8cef55a
chore(package): add lint-staged 9.4.1
sgtcoolguy Oct 15, 2019
c76470b
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
78482d2
chore(package): add clang-format 1.2.3
sgtcoolguy Oct 15, 2019
d56c135
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
e34ab66
style: hook clang-format to lint-staged
sgtcoolguy Oct 15, 2019
8de8ca4
chore(package): add commitizen 4.0.3
sgtcoolguy Oct 15, 2019
474c854
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
a2124bb
style: hook commitizen
sgtcoolguy Oct 15, 2019
228aca9
chore(package): add @seadub/clang-format-lint 0.0.2
sgtcoolguy Oct 15, 2019
4bc7015
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
6f35f79
style: add top-level .clang-format
sgtcoolguy Oct 15, 2019
e8cebf6
build: add npm scripts for linting and formatting
sgtcoolguy Oct 15, 2019
509c0a1
style(ios): fix formatting
sgtcoolguy Oct 15, 2019
bf6fa61
style(android): fix formatting
sgtcoolguy Oct 15, 2019
520b5f6
style: fix clang-format for android
sgtcoolguy Oct 15, 2019
08de425
style: add eslint config files
sgtcoolguy Oct 15, 2019
9e1b82a
chore(package): use clang-format 1.2.3
sgtcoolguy Oct 15, 2019
5ef6882
chore(package): update lockfile
sgtcoolguy Oct 15, 2019
01cbc88
build: add lint:js to main lint script
sgtcoolguy Oct 15, 2019
118bfc8
style(js): fix eslint errors
sgtcoolguy Oct 15, 2019
cfe3f50
chore(npm): add .npmignore file
sgtcoolguy Oct 16, 2019
011262c
ci(jenkins): dry run npm publish
sgtcoolguy Oct 16, 2019
8994b1d
chore: remove unsued files/directories
sgtcoolguy Oct 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules

android/build/

# These should eventually be linted as well
android/example/
ios/example/
20 changes: 20 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": [ "axway/env-titanium", "axway/env-node" ],
"env": {
"node": true,
"jasmine": true
},
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "script"
},
"overrides": [
{
"files": [ "dangerfile.js" ],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
}
}
]
}
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
android/documentation/
android/example/

iphone/documentation/
iphone/example/

test/
apidoc/
Jenkinsfile
dangerfile.js
11 changes: 6 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@Library('pipeline-library') _
library 'pipeline-library'

def isMaster = env.BRANCH_NAME.equals('master')

buildModule {
// defaults:
// nodeVersion = '4.7.3' // Must have version set up on Jenkins master before it can be changed
// sdkVersion = '6.2.0.GA'
// androidAPILevel = '25' // if changed, must install on build nodes
sdkVersion = '8.1.0.GA'
npmPublish = true // By default it'll do github release on master anyways too
npmPublishArgs = '--access public --dry-run'
}
26 changes: 26 additions & 0 deletions android/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
Language: Java
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
# class, constructor, method should be next line
BreakBeforeBraces: Linux
# Keep '=' at end of line when wrapping, but move things like '&&', '||' to beginning of newline
BreakBeforeBinaryOperators: NonAssignment
# FIXME: break for brace after synchronized block, anonymous class declarations
BreakAfterJavaFieldAnnotations: true
ColumnLimit: 120
IndentCaseLabels: true
IndentWidth: 4
MaxEmptyLinesToKeep: 1
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
TabWidth: 4
UseTab: ForContinuationAndIndentation
SpaceAfterCStyleCast: true
# Spaces inside {} for array literals, i.e. "new Object[] { args }"
Cpp11BracedListStyle: false
ReflowComments: false
8 changes: 0 additions & 8 deletions android/Resources/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions android/lib/README

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/README.md

This file was deleted.

75 changes: 43 additions & 32 deletions android/src/ti/identity/FingerPrintHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import java.util.Iterator;
import java.util.Map;

public class FingerPrintHelper extends FingerprintManager.AuthenticationCallback {
public class FingerPrintHelper extends FingerprintManager.AuthenticationCallback
{

protected KeyguardManager mKeyguardManager;
protected FingerprintManager mFingerprintManager;
Expand All @@ -50,43 +51,47 @@ public class FingerPrintHelper extends FingerprintManager.AuthenticationCallback
protected boolean mSelfCancelled;
private boolean mGeneratedKey = false;

public FingerPrintHelper() {
public FingerPrintHelper()
{
Activity activity = TiApplication.getAppRootOrCurrentActivity();
mFingerprintManager = activity.getSystemService(FingerprintManager.class);
mKeyguardManager = activity.getSystemService(KeyguardManager.class);

try {
mKeyStore = KeyStore.getInstance("AndroidKeyStore");
mKeyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
mCipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"
+ KeyProperties.BLOCK_MODE_CBC + "/"
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);

mCipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/"
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);

} catch (KeyStoreException e) {
throw new RuntimeException("Failed to get an instance of KeyStore", e);
} catch (Exception e) {
throw new RuntimeException("Unknown Ti.Identity exception thrown", e);
}
}

public static CancellationSignal cancellationSignal(KeychainItemProxy keychainItemProxy) {
public static CancellationSignal cancellationSignal(KeychainItemProxy keychainItemProxy)
{
CancellationSignal signal = new CancellationSignal();
cancellationSignals.put(signal, keychainItemProxy);
return signal;
}

public static CancellationSignal cancellationSignal() {
public static CancellationSignal cancellationSignal()
{
return cancellationSignal(null);
}

protected boolean isDeviceSupported() {
protected boolean isDeviceSupported()
{
if (Build.VERSION.SDK_INT >= 23 && mFingerprintManager != null) {
return mFingerprintManager.isHardwareDetected();
}
return false;
}

public void stopListening() {
public void stopListening()
{
Iterator cancellationSignalIterator = cancellationSignals.entrySet().iterator();

while (cancellationSignalIterator.hasNext()) {
Expand All @@ -104,11 +109,12 @@ public void stopListening() {
}
}

public void startListening(KrollFunction callback, KrollObject obj) {
public void startListening(KrollFunction callback, KrollObject obj)
{
if (!(mFingerprintManager.isHardwareDetected() && mFingerprintManager.hasEnrolledFingerprints())) {
return;
}

try {
if (initCipher()) {
mCryptoObject = new FingerprintManager.CryptoObject(mCipher);
Expand All @@ -118,16 +124,16 @@ public void startListening(KrollFunction callback, KrollObject obj) {
} catch (Exception e) {
Log.e(TAG, "Unable to initialize cipher");
}

this.callback = callback;
this.krollObject = obj;

mSelfCancelled = false;
mFingerprintManager
.authenticate(mCryptoObject, cancellationSignal(), 0 /* flags */, this, null);
mFingerprintManager.authenticate(mCryptoObject, cancellationSignal(), 0 /* flags */, this, null);
}

private void onError(String errMsg) {
private void onError(String errMsg)
{
if (callback != null && krollObject != null) {
KrollDict dict = new KrollDict();
dict.put("success", false);
Expand All @@ -140,7 +146,8 @@ private void onError(String errMsg) {
* Tries to encrypt some data with the generated key in {@link #createKey} which is
* only works if the user has just authenticated via fingerprint.
*/
private void tryEncrypt() {
private void tryEncrypt()
{
try {
byte[] encrypted = mCipher.doFinal(SECRET_MESSAGE.getBytes());
if (callback != null && krollObject != null) {
Expand All @@ -155,32 +162,35 @@ private void tryEncrypt() {
}

@Override
public void onAuthenticationError(int errMsgId, CharSequence errString) {
public void onAuthenticationError(int errMsgId, CharSequence errString)
{
onError(errString.toString());
}

@Override
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString)
{
Log.w(TAG, helpString.toString());

}

@Override
public void onAuthenticationFailed() {
public void onAuthenticationFailed()
{
onError("Unable to recognize fingerprint");

}

@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result)
{
tryEncrypt();
}

/**
* Creates a symmetric key in the Android Key Store which can only be used after the user has
* authenticated with fingerprint.
*/
protected void createKey() {
protected void createKey()
{
if (mGeneratedKey) {
return;
}
Expand All @@ -191,9 +201,8 @@ protected void createKey() {
try {
mKeyStore.load(null);

mKeyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME,
KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
mKeyGenerator.init(
new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
Expand All @@ -207,7 +216,8 @@ protected void createKey() {
}
}

private boolean initCipher() {
private boolean initCipher()
{
try {
if (!mGeneratedKey) {
createKey();
Expand All @@ -222,7 +232,8 @@ private boolean initCipher() {
}
}

public KrollDict deviceCanAuthenticate(int policy) {
public KrollDict deviceCanAuthenticate(int policy)
{
String error = "";
KrollDict response = new KrollDict();

Expand All @@ -245,14 +256,14 @@ public KrollDict deviceCanAuthenticate(int policy) {
if (error.isEmpty()) {
error = error + "Device is not secure, passcode not set";
} else {
error = error +", and no passcode detected";
error = error + ", and no passcode detected";
}
response.put("code", TitaniumIdentityModule.ERROR_PASSCODE_NOT_SET);
} else if (policy == TitaniumIdentityModule.AUTHENTICATION_POLICY_BIOMETRICS && !hasFingerprints) {
if (error.isEmpty()) {
error = error + "No enrolled fingerprints";
} else {
error = error +", and no enrolled fingerprints";
error = error + ", and no enrolled fingerprints";
}
response.put("code", TitaniumIdentityModule.ERROR_TOUCH_ID_NOT_ENROLLED);
}
Expand Down
Loading