From 81e8c422db990c628a0871886e6172fcad31cc7b Mon Sep 17 00:00:00 2001 From: anshulv1401 Date: Fri, 11 Mar 2022 16:33:17 +0530 Subject: [PATCH] #2 Object store and Packet manager #2 Object store and Packet manager added and integrated with key manager for encryption and signing of the packet --- app/.gitignore | 1 + app/build.gradle | 72 +++ app/proguard-rules.pro | 21 + .../app/ExampleInstrumentedTest.java | 26 + app/src/main/AndroidManifest.xml | 42 ++ .../app/ActivityBuildersModule.java | 12 + .../mosip/registration/app/AppComponent.java | 30 ++ .../io/mosip/registration/app/AppModule.java | 43 ++ .../registration/app/BaseApplication.java | 11 + .../mosip/registration/app/MainActivity.java | 164 ++++++ .../registration/app/PacketWriterDemo.java | 322 ++++++++++++ .../registration/app/PosixAdapterDemo.java | 180 +++++++ .../drawable-v24/ic_launcher_foreground.xml | 30 ++ app/src/main/res/drawable/btn_end.xml | 4 + app/src/main/res/drawable/btn_start.xml | 4 + .../res/drawable/ic_launcher_background.xml | 170 ++++++ app/src/main/res/layout/activity_main.xml | 158 ++++++ .../layout/activity_packet_writer_demo.xml | 103 ++++ .../layout/activity_posix_adapter_demo.xml | 60 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes app/src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes app/src/main/res/raw/identity_schema.json | 118 +++++ app/src/main/res/values-night/themes.xml | 16 + app/src/main/res/values/colors.xml | 10 + app/src/main/res/values/strings.xml | 5 + app/src/main/res/values/themes.xml | 16 + .../registration/app/ExampleUnitTest.java | 17 + client/app/build.gradle | 1 + client/app/src/main/AndroidManifest.xml | 6 + .../mosip/registration/app/MainActivity.java | 25 +- .../registration/app/PacketWriterDemo.java | 322 ++++++++++++ .../registration/app/PosixAdapterDemo.java | 180 +++++++ .../app/src/main/res/layout/activity_main.xml | 105 ++-- .../layout/activity_packet_writer_demo.xml | 103 ++++ .../layout/activity_posix_adapter_demo.xml | 60 +++ .../app/src/main/res/raw/identity_schema.json | 118 +++++ client/packetmanager/build.gradle | 8 + .../assets/packetmanagerconfig.properties | 20 + .../cbeffutil/CbeffContainerImpl.java | 54 ++ .../cbeffutil/common/Base64Adapter.java | 17 + .../cbeffutil/common/DateAdapter.java | 26 + .../cbeffutil/jaxbclasses/BDBInfo.java | 319 ++++++++++++ .../cbeffutil/jaxbclasses/BDBInfoType.java | 484 ++++++++++++++++++ .../cbeffutil/jaxbclasses/BIR.java | 175 +++++++ .../cbeffutil/jaxbclasses/BIRInfo.java | 144 ++++++ .../cbeffutil/jaxbclasses/BIRInfoType.java | 210 ++++++++ .../cbeffutil/jaxbclasses/BIRType.java | 290 +++++++++++ .../cbeffutil/jaxbclasses/BIRVersion.java | 66 +++ .../jaxbclasses/ProcessedLevelType.java | 62 +++ .../cbeffutil/jaxbclasses/PurposeType.java | 68 +++ .../cbeffutil/jaxbclasses/QualityType.java | 114 +++++ .../cbeffutil/jaxbclasses/RegistryIDType.java | 87 ++++ .../cbeffutil/jaxbclasses/SBInfo.java | 48 ++ .../cbeffutil/jaxbclasses/SBInfoType.java | 64 +++ .../jaxbclasses/SingleAnySubtypeType.java | 70 +++ .../cbeffutil/jaxbclasses/SingleType.java | 88 ++++ .../cbeffutil/jaxbclasses/VersionType.java | 82 +++ .../dto/PacketWriter/BDBInfo.java | 205 ++++++++ .../packetmanager/dto/PacketWriter/BIR.java | 134 +++++ .../dto/PacketWriter/BIRInfo.java | 117 +++++ .../dto/PacketWriter/BiometricRecord.java | 49 ++ .../dto/PacketWriter/BiometricType.java | 68 +++ .../dto/PacketWriter/BiometricsType.java | 14 + .../dto/PacketWriter/Document.java | 15 + .../dto/PacketWriter/DocumentType.java | 14 + .../packetmanager/dto/PacketWriter/Entry.java | 50 ++ .../PacketWriter/HashSequenceMetaInfo.java | 30 ++ .../dto/PacketWriter/Packet.java | 12 + .../dto/PacketWriter/PacketInfo.java | 20 + .../dto/PacketWriter/ProcessedLevelType.java | 46 ++ .../dto/PacketWriter/PurposeType.java | 51 ++ .../dto/PacketWriter/QualityType.java | 35 ++ .../dto/PacketWriter/RegistrationPacket.java | 103 ++++ .../dto/PacketWriter/RegistryIDType.java | 77 +++ .../dto/PacketWriter/SBInfo.java | 52 ++ .../dto/PacketWriter/VersionType.java | 59 +++ .../exception/BaseCheckedException.java | 83 +++ .../packetmanager/exception/InfoItem.java | 41 ++ .../exception/PacketCreatorException.java | 14 + .../exception/PacketKeeperException.java | 22 + .../service/PacketCryptoServiceImpl.java | 51 ++ .../service/PacketWriterServiceImpl.java | 416 +++++++++++++++ .../service/PosixAdapterServiceImpl.java | 304 +++++++++++ .../spi/IPacketCryptoService.java | 9 + .../spi/ObjectAdapterService.java | 14 +- .../spi/PacketWriterService.java | 25 + .../packetmanager/util/ConfigService.java | 27 + .../packetmanager/util/CryptoUtil.java | 38 ++ .../packetmanager/util/HMACUtils2.java | 29 ++ .../packetmanager/util/JsonUtils.java | 27 + .../packetmanager/util/ObjectStoreUtil.java | 50 ++ .../packetmanager/util/PacketKeeper.java | 97 ++++ .../util/PacketManagerConstant.java | 111 ++++ .../util/PacketManagerErrorCode.java | 49 +- .../util/PacketManagerHelper.java | 151 ++++++ packetmanager/.gitignore | 1 + packetmanager/build.gradle | 55 ++ packetmanager/consumer-rules.pro | 0 packetmanager/proguard-rules.pro | 21 + .../ExampleInstrumentedTest.java | 25 + packetmanager/src/main/AndroidManifest.xml | 5 + .../assets/packetmanagerconfig.properties | 20 + .../cbeffutil/CbeffContainerImpl.java | 54 ++ .../cbeffutil/common/Base64Adapter.java | 17 + .../cbeffutil/common/DateAdapter.java | 26 + .../cbeffutil/jaxbclasses/BDBInfo.java | 319 ++++++++++++ .../cbeffutil/jaxbclasses/BDBInfoType.java | 484 ++++++++++++++++++ .../cbeffutil/jaxbclasses/BIR.java | 175 +++++++ .../cbeffutil/jaxbclasses/BIRInfo.java | 144 ++++++ .../cbeffutil/jaxbclasses/BIRInfoType.java | 210 ++++++++ .../cbeffutil/jaxbclasses/BIRType.java | 290 +++++++++++ .../cbeffutil/jaxbclasses/BIRVersion.java | 66 +++ .../jaxbclasses/ProcessedLevelType.java | 62 +++ .../cbeffutil/jaxbclasses/PurposeType.java | 68 +++ .../cbeffutil/jaxbclasses/QualityType.java | 114 +++++ .../cbeffutil/jaxbclasses/RegistryIDType.java | 87 ++++ .../cbeffutil/jaxbclasses/SBInfo.java | 48 ++ .../cbeffutil/jaxbclasses/SBInfoType.java | 64 +++ .../jaxbclasses/SingleAnySubtypeType.java | 70 +++ .../cbeffutil/jaxbclasses/SingleType.java | 88 ++++ .../cbeffutil/jaxbclasses/VersionType.java | 82 +++ .../packetmanager/dto/Biometrics.java | 15 + .../dto/BiometricsException.java | 18 + .../packetmanager/dto/Document.java | 16 + .../dto/MakerReviewerDetails.java | 20 + .../dto/PacketWriter/BDBInfo.java | 205 ++++++++ .../packetmanager/dto/PacketWriter/BIR.java | 134 +++++ .../dto/PacketWriter/BIRInfo.java | 117 +++++ .../dto/PacketWriter/BiometricRecord.java | 49 ++ .../dto/PacketWriter/BiometricType.java | 68 +++ .../dto/PacketWriter/BiometricsType.java | 14 + .../dto/PacketWriter/Document.java | 15 + .../dto/PacketWriter/DocumentType.java | 14 + .../packetmanager/dto/PacketWriter/Entry.java | 50 ++ .../PacketWriter/HashSequenceMetaInfo.java | 30 ++ .../dto/PacketWriter/Packet.java | 12 + .../dto/PacketWriter/PacketInfo.java | 20 + .../dto/PacketWriter/ProcessedLevelType.java | 46 ++ .../dto/PacketWriter/PurposeType.java | 51 ++ .../dto/PacketWriter/QualityType.java | 35 ++ .../dto/PacketWriter/RegistrationPacket.java | 103 ++++ .../dto/PacketWriter/RegistryIDType.java | 77 +++ .../dto/PacketWriter/SBInfo.java | 52 ++ .../dto/PacketWriter/VersionType.java | 59 +++ .../packetmanager/dto/RegistrationDto.java | 18 + .../packetmanager/dto/SimpleType.java | 15 + .../exception/BaseCheckedException.java | 83 +++ .../packetmanager/exception/InfoItem.java | 41 ++ .../exception/PacketCreatorException.java | 14 + .../exception/PacketKeeperException.java | 22 + .../service/PacketCryptoServiceImpl.java | 51 ++ .../service/PacketWriterServiceImpl.java | 422 +++++++++++++++ .../service/PosixAdapterServiceImpl.java | 310 +++++++++++ .../spi/IPacketCryptoService.java | 9 + .../spi/ObjectAdapterService.java | 16 + .../spi/PacketWriterService.java | 29 ++ .../packetmanager/util/ConfigService.java | 27 + .../packetmanager/util/CryptoUtil.java | 38 ++ .../packetmanager/util/HMACUtils2.java | 29 ++ .../packetmanager/util/JsonUtils.java | 27 + .../packetmanager/util/ObjectStoreUtil.java | 50 ++ .../packetmanager/util/PacketKeeper.java | 97 ++++ .../util/PacketManagerConstant.java | 115 +++++ .../util/PacketManagerErrorCode.java | 51 ++ .../util/PacketManagerHelper.java | 151 ++++++ .../packetmanager/ExampleUnitTest.java | 17 + 176 files changed, 13178 insertions(+), 39 deletions(-) create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/io/mosip/registration/app/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/io/mosip/registration/app/ActivityBuildersModule.java create mode 100644 app/src/main/java/io/mosip/registration/app/AppComponent.java create mode 100644 app/src/main/java/io/mosip/registration/app/AppModule.java create mode 100644 app/src/main/java/io/mosip/registration/app/BaseApplication.java create mode 100644 app/src/main/java/io/mosip/registration/app/MainActivity.java create mode 100644 app/src/main/java/io/mosip/registration/app/PacketWriterDemo.java create mode 100644 app/src/main/java/io/mosip/registration/app/PosixAdapterDemo.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/btn_end.xml create mode 100644 app/src/main/res/drawable/btn_start.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/activity_packet_writer_demo.xml create mode 100644 app/src/main/res/layout/activity_posix_adapter_demo.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/raw/identity_schema.json create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/test/java/io/mosip/registration/app/ExampleUnitTest.java create mode 100644 client/app/src/main/java/io/mosip/registration/app/PacketWriterDemo.java create mode 100644 client/app/src/main/java/io/mosip/registration/app/PosixAdapterDemo.java create mode 100644 client/app/src/main/res/layout/activity_packet_writer_demo.xml create mode 100644 client/app/src/main/res/layout/activity_posix_adapter_demo.xml create mode 100644 client/app/src/main/res/raw/identity_schema.json create mode 100644 client/packetmanager/src/main/assets/packetmanagerconfig.properties create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/CbeffContainerImpl.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/common/Base64Adapter.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/common/DateAdapter.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BDBInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BDBInfoType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIR.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRInfoType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRVersion.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/ProcessedLevelType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/PurposeType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/QualityType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/RegistryIDType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SBInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SBInfoType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SingleAnySubtypeType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SingleType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/VersionType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BDBInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BIR.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BIRInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BiometricRecord.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BiometricType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BiometricsType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/Document.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/DocumentType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/Entry.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/HashSequenceMetaInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/Packet.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/PacketInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/ProcessedLevelType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/PurposeType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/QualityType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/RegistrationPacket.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/RegistryIDType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/SBInfo.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/VersionType.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/BaseCheckedException.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/InfoItem.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/PacketCreatorException.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/PacketKeeperException.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/service/PacketCryptoServiceImpl.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/spi/IPacketCryptoService.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/ConfigService.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/CryptoUtil.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/HMACUtils2.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/JsonUtils.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/ObjectStoreUtil.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/PacketKeeper.java create mode 100644 client/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/PacketManagerHelper.java create mode 100644 packetmanager/.gitignore create mode 100644 packetmanager/build.gradle create mode 100644 packetmanager/consumer-rules.pro create mode 100644 packetmanager/proguard-rules.pro create mode 100644 packetmanager/src/androidTest/java/io/mosip/registration/packetmanager/ExampleInstrumentedTest.java create mode 100644 packetmanager/src/main/AndroidManifest.xml create mode 100644 packetmanager/src/main/assets/packetmanagerconfig.properties create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/CbeffContainerImpl.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/common/Base64Adapter.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/common/DateAdapter.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BDBInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BDBInfoType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIR.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRInfoType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/BIRVersion.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/ProcessedLevelType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/PurposeType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/QualityType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/RegistryIDType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SBInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SBInfoType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SingleAnySubtypeType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/SingleType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/cbeffutil/jaxbclasses/VersionType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/Biometrics.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/BiometricsException.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/Document.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/MakerReviewerDetails.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BDBInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BIR.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BIRInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BiometricRecord.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BiometricType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/BiometricsType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/Document.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/DocumentType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/Entry.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/HashSequenceMetaInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/Packet.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/PacketInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/ProcessedLevelType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/PurposeType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/QualityType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/RegistrationPacket.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/RegistryIDType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/SBInfo.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/PacketWriter/VersionType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/RegistrationDto.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/dto/SimpleType.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/BaseCheckedException.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/InfoItem.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/PacketCreatorException.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/exception/PacketKeeperException.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/service/PacketCryptoServiceImpl.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/service/PacketWriterServiceImpl.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/service/PosixAdapterServiceImpl.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/spi/IPacketCryptoService.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/spi/ObjectAdapterService.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/spi/PacketWriterService.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/ConfigService.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/CryptoUtil.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/HMACUtils2.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/JsonUtils.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/ObjectStoreUtil.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/PacketKeeper.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/PacketManagerConstant.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/PacketManagerErrorCode.java create mode 100644 packetmanager/src/main/java/io/mosip/registration/packetmanager/util/PacketManagerHelper.java create mode 100644 packetmanager/src/test/java/io/mosip/registration/packetmanager/ExampleUnitTest.java diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 000000000..2572c4aee --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,72 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk rootProject.ext.compileSdkVersion + + defaultConfig { + applicationId "io.mosip.registration.app" + minSdk rootProject.ext.minSdkVersion + targetSdk rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + packagingOptions { + pickFirst "com/itextpdf/io/font/cmap/*" + exclude "notice.txt" + exclude "license.txt" + exclude "META-INF/license.txt" + pickFirst "readme.txt" + pickFirst "logback.xml" + pickFirst "com/itextpdf/io/font/cmap_info.txt" + exclude "META-INF/web-fragment.xml" + exclude "META-INF/*spring*" + exclude "META-INF/git*" + exclude "git*" + exclude "changelog.txt" + exclude "META-INF/INDEX.LIST" + exclude "META-INF/notice.txt" + exclude "META-INF/DEPENDENCIES" + + } +} + +configurations { + all { + } +} + +dependencies { + implementation 'com.google.dagger:dagger:2.38.1' + implementation 'com.google.dagger:dagger-android-support:2.38.1' + annotationProcessor 'com.google.dagger:dagger-compiler:2.38.1' + annotationProcessor 'com.google.dagger:dagger-android-processor:2.38.1' + + implementation 'com.github.amitshekhariitbhu:Fast-Android-Networking:1.0.2' + + implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.2' + testImplementation "junit:junit:4.13.2" + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + // added client-manager Android library module as a dependency + implementation project(':keymanager') + implementation project(':packetmanager') +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/io/mosip/registration/app/ExampleInstrumentedTest.java b/app/src/androidTest/java/io/mosip/registration/app/ExampleInstrumentedTest.java new file mode 100644 index 000000000..ec5c01459 --- /dev/null +++ b/app/src/androidTest/java/io/mosip/registration/app/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package io.mosip.registration.app; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("io.mosip.registration.app", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..5c67bf0f6 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/io/mosip/registration/app/ActivityBuildersModule.java b/app/src/main/java/io/mosip/registration/app/ActivityBuildersModule.java new file mode 100644 index 000000000..0ee543247 --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/ActivityBuildersModule.java @@ -0,0 +1,12 @@ +package io.mosip.registration.app; + +import dagger.Module; +import dagger.android.ContributesAndroidInjector; +import io.mosip.registration.app.MainActivity; + +@Module +public abstract class ActivityBuildersModule { + + @ContributesAndroidInjector + abstract MainActivity contributeMainActivity(); +} diff --git a/app/src/main/java/io/mosip/registration/app/AppComponent.java b/app/src/main/java/io/mosip/registration/app/AppComponent.java new file mode 100644 index 000000000..dffbc5096 --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/AppComponent.java @@ -0,0 +1,30 @@ +package io.mosip.registration.app; + +import android.app.Application; + +import javax.inject.Singleton; + +import dagger.BindsInstance; +import dagger.Component; +import dagger.android.AndroidInjector; +import dagger.android.support.AndroidSupportInjectionModule; + +@Singleton +@Component( + modules = { + AndroidSupportInjectionModule.class, + ActivityBuildersModule.class, + AppModule.class, + } +) +public interface AppComponent extends AndroidInjector { + + @Component.Builder + interface Builder{ + @BindsInstance + Builder application(Application application); + Builder appModule(AppModule appModule); + AppComponent build(); + } + +} diff --git a/app/src/main/java/io/mosip/registration/app/AppModule.java b/app/src/main/java/io/mosip/registration/app/AppModule.java new file mode 100644 index 000000000..5d41f6cbd --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/AppModule.java @@ -0,0 +1,43 @@ +package io.mosip.registration.app; + +import android.app.Application; +import android.content.Context; + +import androidx.annotation.NonNull; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; + +import io.mosip.registration.keymanager.service.LocalClientCryptoServiceImpl; +import io.mosip.registration.keymanager.spi.ClientCryptoManagerService; + +@Module +public class AppModule { + + Application application; + Context appContext; + + public AppModule(Application application) { + this.application = application; + this.appContext = application.getApplicationContext(); + } + + @Provides + Application providesApplication() { + return application; + } + + @Provides + @NonNull + public Context provideApplicationContext() { + return appContext; + } + + @Singleton + @Provides + public ClientCryptoManagerService provideClientCryptoManagerService(){ + return new LocalClientCryptoServiceImpl(appContext); + } +} \ No newline at end of file diff --git a/app/src/main/java/io/mosip/registration/app/BaseApplication.java b/app/src/main/java/io/mosip/registration/app/BaseApplication.java new file mode 100644 index 000000000..7874548b8 --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/BaseApplication.java @@ -0,0 +1,11 @@ +package io.mosip.registration.app; + +import dagger.android.AndroidInjector; +import dagger.android.DaggerApplication; + +public class BaseApplication extends DaggerApplication { + @Override + protected AndroidInjector applicationInjector() { + return DaggerAppComponent.builder().application(this).appModule(new AppModule(this)).build(); + } +} diff --git a/app/src/main/java/io/mosip/registration/app/MainActivity.java b/app/src/main/java/io/mosip/registration/app/MainActivity.java new file mode 100644 index 000000000..dfa0f51aa --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/MainActivity.java @@ -0,0 +1,164 @@ +package io.mosip.registration.app; + +import static io.mosip.registration.keymanager.util.KeyManagerConstant.KEY_ENDEC; +import static io.mosip.registration.keymanager.util.KeyManagerConstant.KEY_SIGN; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import javax.inject.Inject; + +import dagger.android.support.DaggerAppCompatActivity; +import io.mosip.registration.keymanager.dto.CryptoRequestDto; +import io.mosip.registration.keymanager.dto.CryptoResponseDto; +import io.mosip.registration.keymanager.dto.PublicKeyRequestDto; +import io.mosip.registration.keymanager.dto.PublicKeyResponseDto; +import io.mosip.registration.keymanager.dto.SignRequestDto; +import io.mosip.registration.keymanager.dto.SignResponseDto; +import io.mosip.registration.keymanager.dto.SignVerifyRequestDto; +import io.mosip.registration.keymanager.dto.SignVerifyResponseDto; +import io.mosip.registration.keymanager.spi.ClientCryptoManagerService; + + +public class MainActivity extends DaggerAppCompatActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + + @Inject + public ClientCryptoManagerService clientCryptoManagerService; + + + EditText messageInput; + TextView endecTextView; + TextView signTextView; + + private String endecMessage; + private String signMessage; + private String encryption; + private String signed_string; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + messageInput = (EditText) findViewById(R.id.msg_input); + endecTextView = (TextView) findViewById(R.id.EnDecTextView); + signTextView = (TextView) findViewById(R.id.SignTextView); + } + public void click_encrypt(View view) { + test_encrypt(view); + }; + public void click_decrypt(View view) { test_decrypt(view); }; + + public void click_sign(View view) { + test_sign(view); + }; + public void click_verify(View view) { test_verify(view); }; + + public void click_objectStoreDemo(View view) { + Intent intent = new Intent(this, PosixAdapterDemo.class); + startActivity(intent); + } + + public void click_PacketWriterDemo(View view) { + Intent intent = new Intent(this, PacketWriterDemo.class); + startActivity(intent); + } + + public void test_encrypt(View view) { + try { + endecMessage = messageInput.getText().toString(); + Log.i(TAG, "test_encrypt: Encrypting...." + endecMessage); + // creating public key request + PublicKeyRequestDto publicKeyRequestDto = new PublicKeyRequestDto(); + publicKeyRequestDto.setAlias(KEY_ENDEC); + + PublicKeyResponseDto publicKeyResponseDto = clientCryptoManagerService.getPublicKey(publicKeyRequestDto); + Log.i(TAG,"Got public key..creating cryptoRequest"); + + CryptoRequestDto cryptoRequestDto = new CryptoRequestDto( + endecMessage, publicKeyResponseDto.getPublicKey()); + + CryptoResponseDto cryptoResponseDto = clientCryptoManagerService.encrypt(cryptoRequestDto); + + Log.i(TAG, "test_encrypt: Encryption completed"); + + endecTextView.setText("Encrypted message is : " + cryptoResponseDto.getValue() ); + encryption = cryptoResponseDto.getValue(); + } catch (Exception e) { + Log.e(TAG, "test_encrypt: Encryption Failed ", e); + } + } + + public void test_decrypt(View view) { + try { + Log.i(TAG, "test_decrypt: Decrypting...."); + PublicKeyRequestDto publicKeyRequestDto = new PublicKeyRequestDto(); + publicKeyRequestDto.setAlias(KEY_ENDEC); + PublicKeyResponseDto publicKeyResponseDto = clientCryptoManagerService.getPublicKey(publicKeyRequestDto); + + CryptoRequestDto cryptoRequestDto = new CryptoRequestDto(encryption, publicKeyResponseDto.getPublicKey()); + Log.i(TAG,"Got public key..creating cryptoRequest"); + + + CryptoResponseDto cryptoResponseDto=clientCryptoManagerService.decrypt(cryptoRequestDto); + Log.i(TAG, "test_decrypt: Decryption Completed"); + + endecTextView.setText("Decrypted message is : " + cryptoResponseDto.getValue() ); + + + } catch(Exception e) { + Log.e(TAG, "test_decrypt: Decryption Failed ", e); + } + + } + + public void test_sign(View view){ + try { + signMessage = messageInput.getText().toString(); + Log.i(TAG, "test_sign: Signing...." + signMessage); + + Log.i(TAG, "test_sign: Creating Sign Request "); + SignRequestDto signRequestDto = new SignRequestDto(signMessage); + + SignResponseDto signResponseDto = clientCryptoManagerService.sign(signRequestDto); + signed_string=signResponseDto.getData(); + + Log.i(TAG, "test_sign: Signing completed"); + signTextView.setText("Signature is: "+ signed_string); + + } + catch (Exception e) { + Log.e(TAG, "test_sign: Signing Failed", e); + } + } + + public void test_verify(View view){ + try{ + Log.i(TAG, "test_verify: SignVerifying...."); + PublicKeyRequestDto publicKeyRequestDto = new PublicKeyRequestDto(); + publicKeyRequestDto.setAlias(KEY_SIGN); + PublicKeyResponseDto publicKeyResponseDto = clientCryptoManagerService.getPublicKey(publicKeyRequestDto); + Log.i(TAG, "test_verify: Got public key..verifying signed data"); + + SignVerifyRequestDto signVerifyRequestDto=new SignVerifyRequestDto(signMessage, signed_string, publicKeyResponseDto.getPublicKey()); + SignVerifyResponseDto signVerifyResponseDto=clientCryptoManagerService.verifySign(signVerifyRequestDto); + + Log.i(TAG, "test_verify: Verification Completed"); + + if(signVerifyResponseDto.isVerified()){ + signTextView.setText("Data is correctly signed and matching"); + } + else{ + signTextView.setText("Incorrect Signature"); + } + + }catch(Exception e){ + Log.e(TAG, "test_verify: SignVerification Failed ", e); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/mosip/registration/app/PacketWriterDemo.java b/app/src/main/java/io/mosip/registration/app/PacketWriterDemo.java new file mode 100644 index 000000000..17d5d8550 --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/PacketWriterDemo.java @@ -0,0 +1,322 @@ +package io.mosip.registration.app; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; + +import com.google.android.material.snackbar.Snackbar; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import io.mosip.registration.packetmanager.dto.PacketWriter.BDBInfo; +import io.mosip.registration.packetmanager.dto.PacketWriter.BIR; +import io.mosip.registration.packetmanager.dto.PacketWriter.BiometricRecord; +import io.mosip.registration.packetmanager.dto.PacketWriter.BiometricType; +import io.mosip.registration.packetmanager.dto.PacketWriter.Document; +import io.mosip.registration.packetmanager.dto.PacketWriter.PacketInfo; +import io.mosip.registration.packetmanager.dto.PacketWriter.QualityType; +import io.mosip.registration.packetmanager.dto.PacketWriter.RegistryIDType; +import io.mosip.registration.packetmanager.service.PacketWriterServiceImpl; + +public class PacketWriterDemo extends AppCompatActivity { + + //TODO implement Dependency Injection singleton + + // Packet meta info constants + private static final String ID = "id"; + private static final String PACKET_NAME = "packetname"; + private static final String SOURCE = "source"; + private static final String PROCESS = "process"; + private static final String SCHEMA_VERSION = "schemaversion"; + private static final String SIGNATURE = "signature"; + private static final String ENCRYPTED_HASH = "encryptedhash"; + private static final String PROVIDER_NAME = "providername"; + private static final String PROVIDER_VERSION = "providerversion"; + private static final String CREATION_DATE = "creationdate"; + private static final String REFID = "refid"; + private static final String PACKET_MANAGER_ACCOUNT = "PACKET_MANAGER_ACCOUNT"; + private static final String source = "reg-client"; + private static final String process = "NEW"; + private static final String id = "110111101120191111121111"; + private static final String objectSuffix = "Test"; + private static final String objectName = id + "_" + objectSuffix; + private static final String refId = "1234512345_121212"; + + private static final String TAG = PacketWriterDemo.class.getSimpleName(); + + public PacketWriterServiceImpl packetWriter; + + TextView packetWriterTextView; + Snackbar snackbar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_packet_writer_demo); + + packetWriter = new PacketWriterServiceImpl(this); + packetWriter.initialize(id); + packetWriterTextView = (TextView) findViewById(R.id.packetWriterTextView); + } + + public void click_SetField(View view) { + String resultMsg = SetField(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + packetWriterTextView.setText(resultMsg); + } + + public void click_SetFields(View view) { + String resultMsg = SetFields(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_SetBiometrics(View view) { + String resultMsg = SetBiometrics(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_SetDocument(View view) { + String resultMsg = SetDocument(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_AddMetaInfo(View view) { + String resultMsg = AddMetaInfo(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_AddMetaInfoKeyValue(View view) { + String resultMsg = AddMetaInfoKeyValue(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_AddAudit(View view) { + String resultMsg = AddAudit(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_AddAudits(View view) { + String resultMsg = AddAudits(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + public void click_PersistPacket(View view) { + String resultMsg = PersistPacket(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = packetWriterTextView.getText(); + packetWriterTextView.setText(resultMsg + "\n" + text); + } + + //---------------------------------------------- + + public String SetField() { + String resultMsg = ""; + try { + + packetWriter.setField(id, "name", "mono"); + resultMsg = "SetField successful"; + + } catch (Exception e) { + resultMsg = "SetField failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + + public String SetFields() { + String resultMsg = ""; + try { + Map fields = new HashMap<>(); + packetWriter.setFields(id, fields); + resultMsg = "SetFields successful"; + + } catch (Exception e) { + resultMsg = "SetFields failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String SetDocument() { + String resultMsg = ""; + try { + Document document = new Document(); + document.setValue("document"); + + packetWriter.setDocument(id, "poa", document); + + resultMsg = "SetDocument successful"; + + } catch (Exception e) { + resultMsg = "SetDocument failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String SetBiometrics() { + String resultMsg = ""; + try { + List birTypeList = new ArrayList<>(); + BIR birType1 = new BIR.BIRBuilder().build(); + BDBInfo bdbInfoType1 = new BDBInfo.BDBInfoBuilder().build(); + RegistryIDType registryIDType = new RegistryIDType("Mosip", "257"); + QualityType quality = new QualityType(); + quality.setAlgorithm(registryIDType); + quality.setScore(90l); + bdbInfoType1.setQuality(quality); + BiometricType singleType1 = BiometricType.FINGER; + List singleTypeList1 = new ArrayList<>(); + singleTypeList1.add(singleType1); + List subtype1 = new ArrayList<>(Arrays.asList("Left", "RingFinger")); + bdbInfoType1.setSubtype(subtype1); + bdbInfoType1.setType(singleTypeList1); + birType1.setBdbInfo(bdbInfoType1); + birTypeList.add(birType1); +// String source = "reg-client"; +// String process = "NEW"; +// String id = "110111101120191111121111"; + BiometricRecord biometricRecord = new BiometricRecord(); + biometricRecord.setSegments(birTypeList); + + packetWriter.setBiometric(id, "individualBiometrics", biometricRecord); + + resultMsg = "SetBiometrics successful"; + + } catch (Exception e) { + resultMsg = "SetBiometrics failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String AddMetaInfo() { + String resultMsg = ""; + try { + Map fields = new HashMap<>(); + packetWriter.addMetaInfo(id, fields); + resultMsg = "AddMetaInfo successful"; + + } catch (Exception e) { + resultMsg = "AddMetaInfo failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String AddMetaInfoKeyValue() { + String resultMsg = ""; + try { + + packetWriter.addMetaInfo(id, "rid", "regid"); + + resultMsg = "AddMetaInfoKeyValue successful"; + + } catch (Exception e) { + resultMsg = "AddMetaInfoKeyValue failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String AddAudit() { + String resultMsg = ""; + try { + Map fields = new HashMap<>(); + packetWriter.addAudit(id, fields); + + resultMsg = "AddAudit successful"; + + } catch (Exception e) { + resultMsg = "AddAudit failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String AddAudits() { + String resultMsg = ""; + try { + Map auditMap = new HashMap<>(); + auditMap.put("audit", "audit1"); + List> auditList = new ArrayList<>(); + auditList.add(auditMap); + + packetWriter.addAudits(id, auditList); + resultMsg = "AddAudits successful"; + + } catch (Exception e) { + resultMsg = "AddAudits failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + public String PersistPacket() { + String resultMsg = ""; + try { + String identitySchema = loadSchemeFile(R.raw.identity_schema); + + List result = packetWriter.persistPacket(id, "0.2", identitySchema, source, process, true); + + if (result != null) { + resultMsg = "Persist Packet successful"; + } else { + resultMsg = "Persist Packet failed"; + } + + } catch (Exception e) { + resultMsg = "Persist Packet failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + private String loadSchemeFile(int rID) throws IOException { + InputStream iS; + iS = getResources().openRawResource(rID); + + byte[] buffer = new byte[iS.available()]; + iS.read(buffer); + ByteArrayOutputStream oS = new ByteArrayOutputStream(); + oS.write(buffer); + oS.close(); + iS.close(); + + return oS.toString(); + } +} \ No newline at end of file diff --git a/app/src/main/java/io/mosip/registration/app/PosixAdapterDemo.java b/app/src/main/java/io/mosip/registration/app/PosixAdapterDemo.java new file mode 100644 index 000000000..800eb26b9 --- /dev/null +++ b/app/src/main/java/io/mosip/registration/app/PosixAdapterDemo.java @@ -0,0 +1,180 @@ +package io.mosip.registration.app; + +import android.os.Build; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; + +import com.google.android.material.snackbar.Snackbar; + +import org.json.JSONObject; + +import java.io.ByteArrayInputStream; +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import io.mosip.registration.packetmanager.service.PosixAdapterServiceImpl; + +public class PosixAdapterDemo extends AppCompatActivity { + + @Inject + public PosixAdapterServiceImpl posixAdapter; + + // Packet meta info constants + private static final String ID = "id"; + private static final String PACKET_NAME = "packetname"; + private static final String SOURCE = "source"; + private static final String PROCESS = "process"; + private static final String SCHEMA_VERSION = "schemaversion"; + private static final String SIGNATURE = "signature"; + private static final String ENCRYPTED_HASH = "encryptedhash"; + private static final String PROVIDER_NAME = "providername"; + private static final String PROVIDER_VERSION = "providerversion"; + private static final String CREATION_DATE = "creationdate"; + private static final String REFID = "refid"; + private static final String PACKET_MANAGER_ACCOUNT = "PACKET_MANAGER_ACCOUNT"; + private static final String source = "reg-client"; + private static final String process = "NEW"; + private static final String id = "110111101120191111121111"; + private static final String objectSuffix = "Test"; + private static final String objectName = id + "_" + objectSuffix; + private static final String refId = "1234512345_121212"; + + private static final String TAG = PosixAdapterDemo.class.getSimpleName(); + + TextView objectStoreTextView; + Snackbar snackbar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_posix_adapter_demo); + posixAdapter = new PosixAdapterServiceImpl(this); + objectStoreTextView = (TextView) findViewById(R.id.objectStoreTextView); + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public void click_putObject(View view) { + String resultMsg = test_putObject(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = objectStoreTextView.getText(); + objectStoreTextView.setText(resultMsg + "\n" + text); + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public void click_addObjectMetaData(View view) { + String resultMsg = test_addObjectMetaData(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = objectStoreTextView.getText(); + objectStoreTextView.setText(resultMsg + "\n" + text); + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public void click_pack(View view) { + String resultMsg = test_pack(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = objectStoreTextView.getText(); + objectStoreTextView.setText(resultMsg + "\n" + text); + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public void click_removeContainer(View view) { + String resultMsg = test_removeContainer(); + snackbar = Snackbar.make(view, resultMsg.substring(0, Math.min(30, resultMsg.length())), Snackbar.LENGTH_SHORT); + snackbar.show(); + CharSequence text = objectStoreTextView.getText(); + objectStoreTextView.setText(resultMsg + "\n" + text); + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public String test_putObject() { + String resultMsg = ""; + try { + Map metaMap = new HashMap<>(); + metaMap.put(ID, id); + metaMap.put(SOURCE, source); + metaMap.put(PROCESS, process); + JSONObject jsonObject = new JSONObject(metaMap); + boolean result = posixAdapter.putObject(PACKET_MANAGER_ACCOUNT, id, source, process, objectName, new ByteArrayInputStream(jsonObject.toString().getBytes())); + if (result == true) { + resultMsg = "Put Object successful"; + } else { + resultMsg = "Put Object test failed"; + } + } catch (Exception e) { + resultMsg = "test_putObject failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public String test_addObjectMetaData() { + String resultMsg = ""; + try { + Map metaMap = new HashMap<>(); + metaMap.put(ID, id); + metaMap.put(SOURCE, source); + metaMap.put(PROCESS, process); + + Map map = posixAdapter.addObjectMetaData(PACKET_MANAGER_ACCOUNT, + id, source, process, objectName, metaMap); + + if (map != null) { + resultMsg = "Object Meta Data added successfully : " + map.toString(); + } else { + resultMsg = "Object Meta Data test failed"; + } + + } catch (Exception e) { + resultMsg = "test_addObjectMetaData failed : " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public String test_pack() { + String resultMsg = ""; + try { + boolean success = posixAdapter.pack(PACKET_MANAGER_ACCOUNT, id, source, process); + + if (success) { + resultMsg = "Packed successfully"; + } else { + resultMsg = "Packing failed"; + } + + } catch (Exception e) { + resultMsg = "test_pack : Failed " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } + + private String test_removeContainer() { + String resultMsg = ""; + try { + boolean deleted = posixAdapter.removeContainer(PACKET_MANAGER_ACCOUNT, id, source, process); + + if (deleted) { + resultMsg = "Container Removed successfully"; + } else { + resultMsg = "Remove Container failed"; + } + } catch (Exception e) { + resultMsg = "test_removeContainer : Failed " + e.getStackTrace(); + Log.e(TAG, resultMsg); + } + return resultMsg; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 000000000..2b068d114 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_end.xml b/app/src/main/res/drawable/btn_end.xml new file mode 100644 index 000000000..00ee894af --- /dev/null +++ b/app/src/main/res/drawable/btn_end.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_start.xml b/app/src/main/res/drawable/btn_start.xml new file mode 100644 index 000000000..480c59c45 --- /dev/null +++ b/app/src/main/res/drawable/btn_start.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..07d5da9cb --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..f6a1d5dca --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_packet_writer_demo.xml b/app/src/main/res/layout/activity_packet_writer_demo.xml new file mode 100644 index 000000000..3adff14a6 --- /dev/null +++ b/app/src/main/res/layout/activity_packet_writer_demo.xml @@ -0,0 +1,103 @@ + + + + +