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

#2 Update KeyManagerService #7

Merged
merged 27 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a9c0b36
Load dagger
EricJohnEastwood Aug 31, 2021
49f8e25
Implement DTOs
EricJohnEastwood Sep 1, 2021
2078083
Implement Sign
EricJohnEastwood Sep 2, 2021
fda1209
Implement verifySign
EricJohnEastwood Sep 2, 2021
1fade3b
Implement encrypt
EricJohnEastwood Sep 3, 2021
941efd0
Implement encrypt
EricJohnEastwood Sep 3, 2021
f59bcda
Implement encrypt
EricJohnEastwood Sep 3, 2021
d0c4d3c
Initialize keystore
EricJohnEastwood Sep 3, 2021
48b9890
Implement decrypt
EricJohnEastwood Sep 3, 2021
e718dda
Add AAD
EricJohnEastwood Sep 4, 2021
f10b480
Implement AAD
EricJohnEastwood Sep 4, 2021
f88f330
Construct Client Crypto Service
EricJohnEastwood Sep 11, 2021
0057d07
Add initLocalClientCryptoService
EricJohnEastwood Sep 11, 2021
8d86ba3
Add secret key generation
EricJohnEastwood Sep 13, 2021
e397f7e
Add secret key generation
EricJohnEastwood Sep 13, 2021
5b27df7
Add mosipSecretKey store
EricJohnEastwood Sep 15, 2021
7caa06d
Fix encoding ambiguity
EricJohnEastwood Sep 15, 2021
b041dba
Fix sign padding
EricJohnEastwood Sep 15, 2021
ed9724f
Cleanup LocalClientCryptoServiceImpl
EricJohnEastwood Sep 28, 2021
4bf3815
Cleanup LocalClientCryptoServiceImpl
EricJohnEastwood Sep 28, 2021
edaf467
Update buttons
EricJohnEastwood Sep 28, 2021
fa3d006
Add Dependency Injection
EricJohnEastwood Sep 30, 2021
c64c417
Add Instrumented Test
EricJohnEastwood Oct 3, 2021
fc25a03
Update PublicKeyRequestDto and Base64Enc/Dec
EricJohnEastwood Oct 5, 2021
f99e3e5
Update PublicKeyRequestDto and Base64Enc/Dec
EricJohnEastwood Oct 5, 2021
067e651
Add deatiled exceptions
EricJohnEastwood Oct 6, 2021
869e72e
Add KeyManagerErrorCode
EricJohnEastwood Oct 9, 2021
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
6 changes: 4 additions & 2 deletions client/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ configurations {
}
}



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 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.3.0'
Expand Down
4 changes: 4 additions & 0 deletions client/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
package="io.mosip.registration.app">

<application
android:name=".BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.registration_client">

<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -18,6 +20,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name="io.mosip.registration.clientmanager.service.crypto.LocalClientCryptoServiceImpl" android:exported="false"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.mosip.registration.app;

import dagger.android.AndroidInjector;
import dagger.android.DaggerApplication;
import io.mosip.registration.app.di.AppModule;
import io.mosip.registration.app.di.DaggerAppComponent;


public class BaseApplication extends DaggerApplication {
@Override
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
return DaggerAppComponent.builder().application(this).appModule(new AppModule(this)).build();
}
}
141 changes: 135 additions & 6 deletions client/app/src/main/java/io/mosip/registration/app/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,153 @@
package io.mosip.registration.app;

import static io.mosip.registration.clientmanager.constant.KeyManagerConstant.KEY_ENDEC;
import static io.mosip.registration.clientmanager.constant.KeyManagerConstant.KEY_SIGN;

import dagger.android.support.DaggerAppCompatActivity;
import io.mosip.registration.clientmanager.dto.crypto.*;
import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import javax.inject.Inject;

import io.mosip.registration.clientmanager.service.crypto.LocalClientCryptoServiceImpl;

public class MainActivity extends DaggerAppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();

@Inject
public LocalClientCryptoServiceImpl localClientCryptoService;

EditText messageInput;
TextView endecTextView;
TextView signTextView;

private String endecMessage;
private String signMessage;
private String encryption;
private String signed_string;

public class MainActivity extends AppCompatActivity {

@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 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 = localClientCryptoService.getPublicKey(publicKeyRequestDto);
Log.i(TAG,"Got public key..creating cryptoRequest");

CryptoRequestDto cryptoRequestDto = new CryptoRequestDto(
endecMessage, publicKeyResponseDto.getPublicKey());

CryptoResponseDto cryptoResponseDto = localClientCryptoService.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 click_start(View view) {
openStart();
public void test_decrypt(View view) {
try {
Log.i(TAG, "test_decrypt: Decrypting....");
PublicKeyRequestDto publicKeyRequestDto = new PublicKeyRequestDto();
publicKeyRequestDto.setAlias(KEY_ENDEC);
PublicKeyResponseDto publicKeyResponseDto = localClientCryptoService.getPublicKey(publicKeyRequestDto);

CryptoRequestDto cryptoRequestDto = new CryptoRequestDto(encryption, publicKeyResponseDto.getPublicKey());
Log.i(TAG,"Got public key..creating cryptoRequest");


CryptoResponseDto cryptoResponseDto=localClientCryptoService.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 openStart() {
OpenDialog od1 = new OpenDialog();
od1.show(getSupportFragmentManager(),"od1");
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 = localClientCryptoService.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 = localClientCryptoService.getPublicKey(publicKeyRequestDto);
Log.i(TAG, "test_verify: Got public key..verifying signed data");

SignVerifyRequestDto signVerifyRequestDto=new SignVerifyRequestDto(signMessage, signed_string, publicKeyResponseDto.getPublicKey());
SignVerifyResponseDto signVerifyResponseDto=localClientCryptoService.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);
}
}
}
27 changes: 0 additions & 27 deletions client/app/src/main/java/io/mosip/registration/app/OpenDialog.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.mosip.registration.app.di;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;
import io.mosip.registration.app.MainActivity;

@Module
public abstract class ActivityBuildersModule {

@ContributesAndroidInjector
abstract MainActivity contributeMainActivity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.mosip.registration.app.di;

import android.app.Application;

import dagger.BindsInstance;
import dagger.Component;
import dagger.android.AndroidInjector;
import dagger.android.support.AndroidSupportInjectionModule;
import io.mosip.registration.app.BaseApplication;
import io.mosip.registration.clientmanager.service.crypto.LocalClientCryptoServiceImpl;

@Component(
modules = {
AndroidSupportInjectionModule.class,
ActivityBuildersModule.class,
AppModule.class,
}
)
public interface AppComponent extends AndroidInjector<BaseApplication> {

@Component.Builder
interface Builder{
@BindsInstance
Builder application(Application application);
Builder appModule(AppModule appModule);
AppComponent build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.mosip.registration.app.di;

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.clientmanager.service.crypto.LocalClientCryptoServiceImpl;

@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;
}

@Provides
public LocalClientCryptoServiceImpl provideLocalClientCryptoServiceImpl(){
return new LocalClientCryptoServiceImpl(appContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//package io.mosip.registration.app.di;
//
//import android.content.Context;
//
//import javax.inject.Inject;
//
//import dagger.Module;
//import dagger.Provides;
//import io.mosip.registration.clientmanager.service.crypto.LocalClientCryptoServiceImpl;
//
//@Module
//public class ClientManagerModule {
// @Provides
// static LocalClientCryptoServiceImpl provideLocalClientCryptoServiceImpl(){
// return new LocalClientCryptoServiceImpl();
// }
//
//}
Loading