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

QR Code JWT Integration #125

Merged
merged 53 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
509e476
Add jjwt library dependency
rjmangubat23 Oct 14, 2022
301ca9b
Refactor send result and add initial ability to read JWT
rjmangubat23 Oct 14, 2022
a4a56fa
Add isJWT string check and ES256 public key generation in JWTUtils.kt
rjmangubat23 Oct 17, 2022
22a22d8
Add initial decode and verify JWT signature
rjmangubat23 Oct 17, 2022
76522bb
Refactor public key names, code clean up and add JSON flattening to s…
rjmangubat23 Oct 18, 2022
e6a8633
Refactor Results screen and intent passing to separate QR code mode
rjmangubat23 Oct 18, 2022
59cbc56
Add initial QR code call and separate from GZIP QR code for initial s…
rjmangubat23 Oct 18, 2022
877f595
Fix missing image display result
rjmangubat23 Oct 18, 2022
663a949
Clean up onActivityResult intent result passing
rjmangubat23 Oct 18, 2022
0e07b02
Fix crash when QR scan result is invalid json
rjmangubat23 Oct 19, 2022
3480b7c
Use signing key resolver for public key lookup via key id
rjmangubat23 Oct 19, 2022
583cb7e
Clean up and refactor package placement for util related classes
rjmangubat23 Oct 19, 2022
7a31edb
Fix verify signature check crash due to wrong instance and charset
rjmangubat23 Oct 20, 2022
cf2ea81
Clean up logs and add passing of verified signature to intent response
rjmangubat23 Oct 20, 2022
fcc683e
Initial implementation of load configuration as QR Code
rjmangubat23 Oct 21, 2022
eaf81d4
Clean up QRCodeAnalyzer public key loading by updating JWT and JSON u…
rjmangubat23 Oct 21, 2022
8c565b4
Initial QR code JWT results list display
rjmangubat23 Oct 21, 2022
9a171ad
WIP: add missing todos for load configuration QR code and verify sign…
rjmangubat23 Oct 21, 2022
018f0ef
Initial zxing pdf417 integration
rjmangubat23 Oct 4, 2022
5402c1a
Add jjwt library dependency
rjmangubat23 Oct 14, 2022
e97d80a
Refactor Results screen and intent passing to separate QR code mode
rjmangubat23 Oct 18, 2022
c877183
Add initial QR code call and separate from GZIP QR code for initial s…
rjmangubat23 Oct 18, 2022
fb159c9
Clean up and refactor package placement for util related classes
rjmangubat23 Oct 19, 2022
bd1bfe7
Initial implementation of load configuration as QR Code
rjmangubat23 Oct 21, 2022
5e14e67
Fix bugs and improve JWT util and apply config preference
nicholemnl Nov 1, 2022
58a64b0
Handle error and exception of JWT invalid conversion
nicholemnl Nov 2, 2022
a5d6998
Add config set information after jwt decode
nicholemnl Nov 2, 2022
ce9aaa6
Improve QR scan handler and UI
nicholemnl Nov 7, 2022
83a5ed7
Add ic beta launcher
nicholemnl Nov 8, 2022
0e88772
Add armore to publickeys and fix reupdate config
nicholemnl Nov 8, 2022
8a35003
Fix scan result and rid of gzip qrscanner
nicholemnl Nov 8, 2022
d34a8f3
Fix image not showing after scanning PDF417
nicholemnl Nov 9, 2022
7281277
Fix Invalid QR code result
nicholemnl Nov 9, 2022
088ca7e
Add arab translation of the new texts
nicholemnl Nov 10, 2022
3a1e92a
Fix after rebasing from the main branch
nicholemnl Nov 10, 2022
08c13f6
Fix QR scanning fallback only config jwt
nicholemnl Nov 10, 2022
02985f8
Fix show raw result for non jwt qr code
nicholemnl Nov 10, 2022
bb8b578
Fix fallback should check conf only
nicholemnl Nov 11, 2022
13b7442
Fix translation arab retain english as English
nicholemnl Nov 11, 2022
d672934
Add scroll into raw result
nicholemnl Nov 15, 2022
2990865
Change default public key
nicholemnl Nov 18, 2022
8e6ed6c
Fix default public key
nicholemnl Nov 21, 2022
411c7f9
Fix handler of config update
nicholemnl Nov 28, 2022
16c0ac3
Fix overlapping ui issue in settings page
nicholemnl Nov 28, 2022
fed968a
Fix xml issue in .aar core-lib integration
nicholemnl Nov 28, 2022
989f5f5
Fix make QR result clickable
nicholemnl Dec 22, 2022
9b4cf8f
Fix MRZ and improve MRZ scanning
nicholemnl Dec 4, 2022
dbb4be1
Fix mrz resizing bitmap to make it work with passport
nicholemnl Dec 4, 2022
e898bac
Fix distorted scaled up image and store images
nicholemnl Dec 5, 2022
d74dfbc
fix mrz cropping
wenge8n Dec 7, 2022
a34fb12
Fix crash mrz scan and clean up
nicholemnl Dec 8, 2022
e1a7721
Clean up unused code
nicholemnl Dec 9, 2022
3e06f57
Clean code todo
nicholemnl Jan 13, 2023
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.newlogic.smartscanner">

<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
tools:ignore="CoarseFineLocation" />

<uses-feature
android:name="android.hardware.camera"
android:required="true" />
Expand Down Expand Up @@ -41,6 +47,11 @@
android:exported="true"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="nosensor" />
<activity
android:name=".result.RawResultActivity"
android:exported="true"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="nosensor" />
<activity
android:name=".settings.SettingsActivity"
android:exported="true"
Expand Down
130 changes: 89 additions & 41 deletions app/src/main/java/org/newlogic/smartscanner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@ import com.google.android.material.snackbar.Snackbar
import org.idpass.smartscanner.api.ScannerConstants
import org.idpass.smartscanner.api.ScannerIntent
import org.idpass.smartscanner.lib.SmartScannerActivity
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_FAIL_RESULT
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_HEADER_RESULT
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_IMAGE_TYPE
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_JWT_CONFIG_UPDATE
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_RAW_RESULT
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_RESULT
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_RESULT_BYTES
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_SIGNATURE_VERIFICATION
import org.idpass.smartscanner.lib.nfc.NFCActivity
import org.idpass.smartscanner.lib.scanner.config.*
import org.idpass.smartscanner.lib.scanner.config.Config.Companion.OP_SCANNER
import org.idpass.smartscanner.lib.scanner.config.Config.Companion.ORIENTATION
import org.newlogic.smartscanner.databinding.ActivityMainBinding
import org.newlogic.smartscanner.result.IDPassResultActivity
import org.newlogic.smartscanner.result.ResultActivity
import org.newlogic.smartscanner.settings.SettingsActivity
import org.newlogic.smartscanner.settings.SettingsActivity.Companion.ORIENTATION


class MainActivity : AppCompatActivity() {

companion object {

const val OP_SCANNER = 1001
var imageType = ImageResultType.PATH.value
private val imageType = ImageResultType.PATH.value

private fun sampleConfig(isManualCapture: Boolean, label: String = "", orientation : String? = Orientation.PORTRAIT.value) = Config(
branding = true,
Expand All @@ -63,7 +71,7 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
preference = getSharedPreferences(SmartScannerApplication.SHARED, Context.MODE_PRIVATE)
preference = getSharedPreferences(Config.SHARED, Context.MODE_PRIVATE)
}

override fun onStart() {
Expand All @@ -72,6 +80,8 @@ class MainActivity : AppCompatActivity() {
binding.itemBarcode.item.setOnClickListener { scanBarcode(BarcodeOptions.default) }
binding.itemIdpassLite.item.setOnClickListener { scanIDPassLite() }
binding.itemMrz.item.setOnClickListener { scanMRZ() }
binding.itemQr.item.setOnClickListener { scanQRCode() }
// binding.itemQrGzip.item.setOnClickListener { scanQRCodeGzip() }
binding.itemNfc.item.setOnClickListener { scanNFC() }
binding.itemPdf417.item.setOnClickListener { scanPDF417() }
binding.itemQr.item.setOnClickListener { scanQRCode() }
Expand Down Expand Up @@ -122,7 +132,14 @@ class MainActivity : AppCompatActivity() {
ScannerOptions(
mode = Modes.MRZ.value,
language = getLanguage(preference),
config = sampleConfig(isManualCapture = true, orientation = getOrientation(preference)),
config = Config(
branding = true,
imageResultType = imageType,
label = "",
isManualCapture = true,
orientation = getOrientation(preference),
showGuide = true
)
)
)
startActivityForResult(intent, OP_SCANNER)
Expand All @@ -143,7 +160,8 @@ class MainActivity : AppCompatActivity() {
header = getString(R.string.label_scan_nfc_capture),
subHeader = getString(R.string.label_scan_nfc_via_mrz),
isManualCapture = false,
branding = true
branding = true,
showGuide = true
)
)
)
Expand All @@ -155,22 +173,28 @@ class MainActivity : AppCompatActivity() {
private fun scanPDF417() {
val intent = Intent(this, SmartScannerActivity::class.java)
intent.putExtra(
SmartScannerActivity.SCANNER_OPTIONS,
ScannerOptions(
mode = Modes.PDF_417.value,
language = getLanguage(preference),
scannerSize = ScannerSize.SMALL.value,
config = sampleConfig(false)
)
SmartScannerActivity.SCANNER_OPTIONS,
ScannerOptions(
mode = Modes.PDF_417.value,
language = getLanguage(preference),
scannerSize = ScannerSize.SMALL.value,
config = sampleConfig(false)
)
)
startActivityForResult(intent, OP_SCANNER)
}

private fun scanQRCode() {
val intent = ScannerIntent.intentQRCode(
isGzipped = true,
isJson = true,
jsonPath = "" // ex: "$.members[1].lastName"
val intent = Intent(this, SmartScannerActivity::class.java)
intent.putExtra(
SmartScannerActivity.SCANNER_OPTIONS,
ScannerOptions(
mode = Modes.QRCODE.value,
language = preference?.getString(Language.NAME, Language.EN),
scannerSize = ScannerSize.LARGE.value,
qrCodeOptions = QRcodeOptions(isJson = true),
config = sampleConfig(false)
)
)
startActivityForResult(intent, OP_SCANNER)
}
Expand All @@ -185,37 +209,61 @@ class MainActivity : AppCompatActivity() {
if (requestCode == OP_SCANNER) {
Log.d(SmartScannerActivity.TAG, "Scanner resultCode $resultCode")
if (resultCode == RESULT_OK) {
// Get Result from Bundle Intent Call Out
intent?.getBundleExtra(ScannerConstants.RESULT)?.let { bundleResult ->
Log.d(SmartScannerActivity.TAG, "Scanner result bundle: $bundleResult")
if (bundleResult.getString(ScannerConstants.MODE) == Modes.IDPASS_LITE.value) {
val bundle = intent?.getBundleExtra(ScannerConstants.RESULT)
val mIntent: Intent;

if (bundle != null) {
// Get Result from Bundle Intent Call Out
if (bundle.getString(ScannerConstants.MODE) == Modes.IDPASS_LITE.value) {
// Go to ID PASS Lite Results Screen via bundle
val myIntent = Intent(this, IDPassResultActivity::class.java)
myIntent.putExtra(IDPassResultActivity.BUNDLE_RESULT, bundleResult)
startActivity(myIntent)
mIntent = Intent(this, IDPassResultActivity::class.java)
mIntent.putExtra(IDPassResultActivity.BUNDLE_RESULT, bundle)
} else {
// Go to Barcode/MRZ Results Screen via bundle
val resultIntent = Intent(this, ResultActivity::class.java)
resultIntent.putExtra(ResultActivity.BUNDLE_RESULT, bundleResult)
startActivity(resultIntent)
// Go to Results Screen via bundle
mIntent = Intent(this, ResultActivity::class.java)
mIntent.putExtra(ResultActivity.BUNDLE_RESULT, bundle)
}
} ?: run {
// Get Result from JSON String
val result = intent?.getStringExtra(SCANNER_RESULT)
Log.d(SmartScannerActivity.TAG, "Scanner result string: $result")
if (!result.isNullOrEmpty()) {
// Go to Barcode/MRZ Results Screen
val resultIntent = Intent(this, ResultActivity::class.java)
resultIntent.putExtra(ResultActivity.RESULT, result)
startActivity(resultIntent)
} else {
} else {
// Get Result from Intent extras
if (intent?.getStringExtra(ScannerConstants.MODE) == Modes.IDPASS_LITE.value) {
// Go to ID PASS Lite Results Screen
val resultBytes = intent?.getByteArrayExtra(SCANNER_RESULT_BYTES)
val myIntent = Intent(this, IDPassResultActivity::class.java)
myIntent.putExtra(IDPassResultActivity.RESULT, resultBytes)
startActivity(myIntent)
val resultBytes = intent.getByteArrayExtra(SCANNER_RESULT_BYTES)
mIntent = Intent(this, IDPassResultActivity::class.java)
mIntent.putExtra(IDPassResultActivity.RESULT, resultBytes)
} else {

// Check if it should go to the settings instead
val isConfigUpdated = intent?.getBooleanExtra(SCANNER_JWT_CONFIG_UPDATE, false)

// should go to settings
if (isConfigUpdated == true) {
val sIntent = Intent(this, SettingsActivity::class.java)
sIntent.putExtra(SettingsActivity.CONFIG_UPDATED, true)
startActivity(sIntent)
return
}

// Go to Results Screen
val result = intent?.getStringExtra(SCANNER_RESULT)
val verified = intent?.getBooleanExtra(SCANNER_SIGNATURE_VERIFICATION, false)
val rawResult = intent?.getStringExtra(SCANNER_RAW_RESULT)
val failResult = intent?.getStringExtra(SCANNER_FAIL_RESULT)
val headerResult = intent?.getStringExtra(SCANNER_HEADER_RESULT)

mIntent = Intent(this, ResultActivity::class.java)
mIntent.putExtra(ResultActivity.SIGNATURE_VERIFIED, verified)
mIntent.putExtra(ResultActivity.IMAGE_TYPE, intent?.getStringExtra(SCANNER_IMAGE_TYPE))
mIntent.putExtra(ResultActivity.RESULT, result)
mIntent.putExtra(ResultActivity.FAIL_RESULT, failResult)
mIntent.putExtra(ResultActivity.RAW_RESULT, rawResult)
mIntent.putExtra(ResultActivity.HEADER_RESULT, headerResult)

}
}


mIntent.putExtra(ScannerConstants.MODE, intent?.getStringExtra(ScannerConstants.MODE))
startActivity(mIntent)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ class SmartScannerApplication : MultiDexApplication() {
}
}
}

companion object {
const val SHARED = "SHARED"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.newlogic.smartscanner.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import org.newlogic.smartscanner.R

class RecyclerResultAdapter (private var results: HashMap<String, String>): RecyclerView.Adapter<RecyclerResultAdapter.ViewHolder>() {

inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
val itemLabel: TextView = itemView.findViewById(R.id.tv_label)
val itemValue: TextView = itemView.findViewById(R.id.tv_value)

// no click listener here
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.recycler_result_item, parent, false)
return ViewHolder(v)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {

val keyByIndex = results.keys.elementAt(position)
val valueByKey = results.getValue(keyByIndex)
holder.itemLabel.text = keyByIndex
holder.itemValue.text = valueByKey
}

override fun getItemCount(): Int {
return results.size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import org.idpass.lite.exceptions.InvalidKeyException
import org.idpass.smartscanner.api.ScannerConstants
import org.idpass.smartscanner.lib.SmartScannerActivity
import org.idpass.smartscanner.lib.idpasslite.IDPassManager
import org.idpass.smartscanner.lib.platform.extension.empty
import org.idpass.smartscanner.lib.platform.extension.hideKeyboard
import org.idpass.smartscanner.lib.platform.utils.DateUtils.formatDate
import org.idpass.smartscanner.lib.platform.utils.DateUtils.isValidDate
import org.idpass.smartscanner.lib.utils.DateUtils.formatDate
import org.idpass.smartscanner.lib.utils.DateUtils.isValidDate
import org.idpass.smartscanner.lib.utils.extension.empty
import org.idpass.smartscanner.lib.utils.extension.hideKeyboard
import org.newlogic.smartscanner.R

class IDPassResultActivity : AppCompatActivity(), View.OnClickListener {
Expand Down
Loading