diff --git a/README.md b/README.md index 5458fee..0fa3981 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,17 @@ # Screenshots +## Login + +![Login](./screenshots/mispbump-login.png) + ## Home -Entrypoint of the app. Actions: **Profile View** (Menubar) and **New Sync** (Floating Action Button) ![Home (Empty)](./screenshots/mispbump-home-0.png) ## Profile -Basic information about the organisation that is currently logged in. +Organisation information loaded automatically from your MISP instance Actions: **Delete and logout** (Menubar) and **Update Info** (Floating Action Button) @@ -34,7 +37,7 @@ After a successfull exchange an entry for this organisation will appear. Actions: **Delete Sync information** (Menubar) and **Upload** (Floating Action Button in settings tab) -**Credentials:** With this credentials you will be able to log in on the other MISP instance (SyncUser) +**Credentials:** With these credentials you will be able to log in on the other MISP instance (SyncUser) ![Profile](./screenshots/mispbump-sync-info-credentials.png) diff --git a/app/src/main/java/lu/circl/mispbump/activities/LoginActivity.java b/app/src/main/java/lu/circl/mispbump/activities/LoginActivity.java index fdcbd5f..b53a874 100644 --- a/app/src/main/java/lu/circl/mispbump/activities/LoginActivity.java +++ b/app/src/main/java/lu/circl/mispbump/activities/LoginActivity.java @@ -33,6 +33,8 @@ import lu.circl.mispbump.models.restModels.User; public class LoginActivity extends AppCompatActivity { private PreferenceManager preferenceManager; + private MispRestClient mispRestClient; + private ConstraintLayout constraintLayout; private TextInputLayout serverAutomationKey; private TextInputLayout serverUrl; @@ -42,6 +44,12 @@ public class LoginActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); + + preferenceManager = PreferenceManager.getInstance(this); + mispRestClient = MispRestClient.getInstance(LoginActivity.this); + + getWindow().setStatusBarColor(getColor(R.color.colorPrimary)); + initializeViews(); } @@ -62,26 +70,25 @@ public class LoginActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } + private void initializeViews() { + constraintLayout = findViewById(R.id.rootLayout); + // populate Toolbar (Actionbar) Toolbar myToolbar = findViewById(R.id.appbar); setSupportActionBar(myToolbar); - ActionBar ab = getSupportActionBar(); if (ab != null) { ab.setDisplayHomeAsUpEnabled(false); + ab.setDisplayShowTitleEnabled(false); } - constraintLayout = findViewById(R.id.rootLayout); - Button downloadInfoButton = findViewById(R.id.login_download_button); downloadInfoButton.setOnClickListener(onClickDownload); serverUrl = findViewById(R.id.login_server_url); serverAutomationKey = findViewById(R.id.login_automation_key); progressBar = findViewById(R.id.login_progressbar); - - preferenceManager = PreferenceManager.getInstance(this); } /** @@ -91,8 +98,8 @@ public class LoginActivity extends AppCompatActivity { @Override public void onClick(View v) { - String url = Objects.requireNonNull(serverUrl.getEditText()).getText().toString(); - String authkey = Objects.requireNonNull(serverAutomationKey.getEditText()).getText().toString(); + final String url = Objects.requireNonNull(serverUrl.getEditText()).getText().toString(); + final String authkey = Objects.requireNonNull(serverAutomationKey.getEditText()).getText().toString(); boolean error = false; @@ -113,14 +120,7 @@ public class LoginActivity extends AppCompatActivity { return; } - // save authkey - preferenceManager.setAutomationKey(authkey); - - // save url - preferenceManager.setServerUrl(url); - - // instance of MispRestClient with given URL - final MispRestClient mispRestClient = MispRestClient.getInstance(getApplicationContext()); + mispRestClient.initMispRestInterface(url); // display progress bar progressBar.setVisibility(View.VISIBLE); @@ -137,6 +137,13 @@ public class LoginActivity extends AppCompatActivity { @Override public void success(Organisation organisation) { preferenceManager.setUserOrgInfo(organisation); + + // save authkey + preferenceManager.setAutomationKey(authkey); + + // save url + preferenceManager.setServerUrl(url); + progressBar.setVisibility(View.GONE); Intent home = new Intent(getApplicationContext(), HomeActivity.class); startActivity(home); @@ -170,7 +177,7 @@ public class LoginActivity extends AppCompatActivity { }; /** - * Check if url is valid. + * TODO: Check if url is valid. * * @param url url to check * @return true or false @@ -186,7 +193,7 @@ public class LoginActivity extends AppCompatActivity { } /** - * Check if automation key is valid. + * TODO: Check if automation key is valid. * * @param automationKey the key to check * @return true or false diff --git a/app/src/main/java/lu/circl/mispbump/auxiliary/MispRestClient.java b/app/src/main/java/lu/circl/mispbump/auxiliary/MispRestClient.java index 2657063..c72257e 100644 --- a/app/src/main/java/lu/circl/mispbump/auxiliary/MispRestClient.java +++ b/app/src/main/java/lu/circl/mispbump/auxiliary/MispRestClient.java @@ -59,26 +59,31 @@ public class MispRestClient { public interface AllUsersCallback { void success(User[] users); + void failure(String error); } public interface OrganisationCallback { void success(Organisation organisation); + void failure(String error); } public interface AllOrganisationsCallback { void success(Organisation[] organisations); + void failure(String error); } public interface ServerCallback { void success(Server server); + void failure(String error); } public interface AllServersCallback { void success(Server[] servers); + void failure(String error); } @@ -97,21 +102,41 @@ public class MispRestClient { return instance; } + public static MispRestClient getInstance(Context context, String url) { + if (instance == null) { + instance = new MispRestClient(context, url); + } + + return instance; + } + + + private MispRestClient(Context context) { + this(context, null); + } + /** * Initializes the rest client to communicate with a MISP instance. * * @param context needed to access the preferences for loading credentials */ - private MispRestClient(Context context) { + private MispRestClient(Context context, String url) { + preferenceManager = PreferenceManager.getInstance(context); - String url = preferenceManager.getServerUrl(); + if (url == null) { + url = preferenceManager.getServerUrl(); + } + initMispRestInterface(url); + } + + public void initMispRestInterface(String url) { try { Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .addConverterFactory(GsonConverterFactory.create()) - .client(getCustomClient(true, true)) + .client(getCustomClient(true, false)) .build(); mispRestInterface = retrofit.create(MispRestInterface.class); @@ -120,9 +145,9 @@ public class MispRestClient { } } + /** - * - * @param unsafe whether to accept all certificates or only trusted ones + * @param unsafe whether to accept all certificates or only trusted ones * @param logging whether to log Retrofit calls (for debugging) * @return {@link OkHttpClient} */ @@ -159,7 +184,7 @@ public class MispRestClient { // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); - builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]); + builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]); builder.hostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { @@ -224,7 +249,6 @@ public class MispRestClient { } - /** * Fetches information about the user that is associated with saved auth key. * @@ -549,8 +573,9 @@ public class MispRestClient { /** * Converts error {@link Response}s to human readable info. + * * @param response erroneous response - * @param type of response + * @param type of response * @return human readable String that describes the error */ private String extractError(Response response) { @@ -603,6 +628,7 @@ public class MispRestClient { /** * Converts a {@link Throwable} to a human readable error message. + * * @param t throwable * @return human readable String that describes the error. */ diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 671a44b..f7bce35 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -1,23 +1,44 @@ - + tools:context=".activities.LoginActivity" + android:focusableInTouchMode="true" + android:animateLayoutChanges="true"> - + android:layout_height="wrap_content" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintEnd_toEndOf="parent"> + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/login_progressbar" /> + app:layout_constraintTop_toBottomOf="@+id/login_automation_key" /> + app:layout_constraintGuide_percent="0.4" /> \ No newline at end of file diff --git a/screenshots/mispbump-home-0.png b/screenshots/mispbump-home-0.png index 8610614..9359118 100644 Binary files a/screenshots/mispbump-home-0.png and b/screenshots/mispbump-home-0.png differ diff --git a/screenshots/mispbump-home.png b/screenshots/mispbump-home.png index b515900..7ff3975 100644 Binary files a/screenshots/mispbump-home.png and b/screenshots/mispbump-home.png differ diff --git a/screenshots/mispbump-login.png b/screenshots/mispbump-login.png new file mode 100644 index 0000000..3fcda41 Binary files /dev/null and b/screenshots/mispbump-login.png differ diff --git a/screenshots/mispbump-profile.png b/screenshots/mispbump-profile.png index 4d233ec..3bfe4f0 100644 Binary files a/screenshots/mispbump-profile.png and b/screenshots/mispbump-profile.png differ diff --git a/screenshots/mispbump-sync-0.png b/screenshots/mispbump-sync-0.png index ec5ef4d..ef53d07 100644 Binary files a/screenshots/mispbump-sync-0.png and b/screenshots/mispbump-sync-0.png differ diff --git a/screenshots/mispbump-sync-1.png b/screenshots/mispbump-sync-1.png index 761febf..e796a28 100644 Binary files a/screenshots/mispbump-sync-1.png and b/screenshots/mispbump-sync-1.png differ diff --git a/screenshots/mispbump-sync-2.png b/screenshots/mispbump-sync-2.png index 1449306..3c49de0 100644 Binary files a/screenshots/mispbump-sync-2.png and b/screenshots/mispbump-sync-2.png differ diff --git a/screenshots/mispbump-sync-3.png b/screenshots/mispbump-sync-3.png index 8209280..bd0d7b9 100644 Binary files a/screenshots/mispbump-sync-3.png and b/screenshots/mispbump-sync-3.png differ diff --git a/screenshots/mispbump-sync-info-credentials.png b/screenshots/mispbump-sync-info-credentials.png index f0769bd..3751290 100644 Binary files a/screenshots/mispbump-sync-info-credentials.png and b/screenshots/mispbump-sync-info-credentials.png differ diff --git a/screenshots/mispbump-sync-info-settings.png b/screenshots/mispbump-sync-info-settings.png index 3179020..04d4526 100644 Binary files a/screenshots/mispbump-sync-info-settings.png and b/screenshots/mispbump-sync-info-settings.png differ diff --git a/screenshots/mispbump-upload-0.png b/screenshots/mispbump-upload-0.png index 4a0a2a0..6616cb7 100644 Binary files a/screenshots/mispbump-upload-0.png and b/screenshots/mispbump-upload-0.png differ diff --git a/screenshots/mispbump-upload-1.png b/screenshots/mispbump-upload-1.png index 368720f..14dab90 100644 Binary files a/screenshots/mispbump-upload-1.png and b/screenshots/mispbump-upload-1.png differ diff --git a/screenshots/mispbump-upload-2.png b/screenshots/mispbump-upload-2.png index 6702beb..544cc14 100644 Binary files a/screenshots/mispbump-upload-2.png and b/screenshots/mispbump-upload-2.png differ