[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] dialog for adding v3 base32 key hashes



commit a8b3e167b369e525fb678698344e3d694d7e0d95
Author: bim <dsnake@xxxxxxxxxxxxxx>
Date:   Wed Jan 27 20:00:11 2021 -0500

    dialog for adding v3 base32 key hashes
---
 app/src/main/AndroidManifest.xml                   |  8 +++
 .../org/torproject/android/OrbotMainActivity.java  |  3 +
 .../ui/hiddenservices/ClientCookiesActivity.java   |  3 +-
 .../AddV3ClientAuthDialogFragment.java             | 80 ++++++++++++++++++++++
 .../ui/v3onionservice/V3ClientAuthActivity.java    | 25 +++++++
 app/src/main/res/layout/activity_v3auth.xml        | 36 ++++++++++
 .../main/res/layout/dialog_add_v3_client_auth.xml  | 33 +++++++++
 app/src/main/res/menu/orbot_main.xml               |  7 +-
 app/src/main/res/values/strings.xml                |  2 +
 9 files changed, 194 insertions(+), 3 deletions(-)

diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0f69c722..51fc720a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -103,6 +103,14 @@
                 android:value=".OrbotMainActivity" />
         </activity>
 
+        <activity android:name=".ui.v3onionservice.V3ClientAuthActivity"
+            android:label="@string/v3_client_auth"
+            android:theme="@style/DefaultTheme">
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value=".OrbotMainActivity"/>
+        </activity>
+
         <activity
             android:name=".ui.hiddenservices.ClientCookiesActivity"
             android:label="@string/client_cookies"
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 773c7fa6..d58381d4 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -75,6 +75,7 @@ import org.torproject.android.ui.onboarding.BridgeWizardActivity;
 import org.torproject.android.ui.onboarding.OnboardingActivity;
 import org.torproject.android.ui.v3onionservice.OnionServiceContentProvider;
 import org.torproject.android.ui.v3onionservice.OnionServicesActivity;
+import org.torproject.android.ui.v3onionservice.V3ClientAuthActivity;
 
 import java.io.File;
 import java.io.UnsupportedEncodingException;
@@ -468,6 +469,8 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
 
         } else if (item.getItemId() == R.id.menu_v3_onion_services) {
             startActivity(new Intent(this, OnionServicesActivity.class));
+        } else if (item.getItemId() == R.id.menu_v3_onion_client_auth) {
+            startActivity(new Intent(this, V3ClientAuthActivity.class));
         } else if (item.getItemId() == R.id.menu_hidden_services) {
             startActivity(new Intent(this, HiddenServicesActivity.class));
         } else if (item.getItemId() == R.id.menu_client_cookies) {
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java
index 93443678..7ffe2b43 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java
@@ -48,8 +48,7 @@ public class ClientCookiesActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.layout_activity_client_cookies);
 
-        Toolbar toolbar = findViewById(R.id.toolbar);
-        setSupportActionBar(toolbar);
+        setSupportActionBar(findViewById(R.id.toolbar));
         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 
         mResolver = getContentResolver();
diff --git a/app/src/main/java/org/torproject/android/ui/v3onionservice/AddV3ClientAuthDialogFragment.java b/app/src/main/java/org/torproject/android/ui/v3onionservice/AddV3ClientAuthDialogFragment.java
new file mode 100644
index 00000000..a3efe0d6
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/ui/v3onionservice/AddV3ClientAuthDialogFragment.java
@@ -0,0 +1,80 @@
+package org.torproject.android.ui.v3onionservice;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+import android.widget.EditText;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.DialogFragment;
+
+import org.torproject.android.R;
+
+public class AddV3ClientAuthDialogFragment extends DialogFragment {
+
+    private EditText etOnionUrl, etKeyHash;
+    private TextWatcher inputValidator;
+
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        final View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_add_v3_client_auth, null);
+        final AlertDialog ad = new AlertDialog.Builder(getActivity())
+                .setView(dialogView)
+                .setTitle(R.string.v3_client_auth)
+                .setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
+                .setPositiveButton(R.string.save, (dialog, which) -> doSave(getContext()))
+                .create();
+
+
+        etOnionUrl = dialogView.findViewById(R.id.cookie_onion);
+        etKeyHash = dialogView.findViewById(R.id.cookie_value);
+
+        inputValidator = new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+                ad.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(checkInput());
+            }
+        };
+
+        etOnionUrl.addTextChangedListener(inputValidator);
+        etKeyHash.addTextChangedListener(inputValidator);
+
+        return ad;
+    }
+
+    private void doSave(Context context) {
+
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        inputValidator.afterTextChanged(null);
+    }
+
+    private boolean checkInput() {
+        String domain = ".onion";
+        String onion = etOnionUrl.getText().toString();
+        if (onion.endsWith(domain))
+            onion = onion.substring(0, onion.indexOf(domain));
+        if (!onion.matches("([a-z0-9]{56})")) return false;
+        String hash = etKeyHash.getText().toString();
+        return hash.matches("([A-Z2-7]{52})");
+    }
+
+}
diff --git a/app/src/main/java/org/torproject/android/ui/v3onionservice/V3ClientAuthActivity.java b/app/src/main/java/org/torproject/android/ui/v3onionservice/V3ClientAuthActivity.java
new file mode 100644
index 00000000..53a35f30
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/ui/v3onionservice/V3ClientAuthActivity.java
@@ -0,0 +1,25 @@
+package org.torproject.android.ui.v3onionservice;
+
+import android.os.Bundle;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+
+import org.torproject.android.R;
+
+public class V3ClientAuthActivity extends AppCompatActivity {
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_v3auth);
+
+        setSupportActionBar(findViewById(R.id.toolbar));
+        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+        findViewById(R.id.fab).setOnClickListener(v -> {
+            new AddV3ClientAuthDialogFragment().show(getSupportFragmentManager(), "AddV3ClientAuthDialogFragment");
+        });
+
+
+    }
+}
diff --git a/app/src/main/res/layout/activity_v3auth.xml b/app/src/main/res/layout/activity_v3auth.xml
new file mode 100644
index 00000000..a0e66741
--- /dev/null
+++ b/app/src/main/res/layout/activity_v3auth.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android";
+    xmlns:app="http://schemas.android.com/apk/res-auto";
+    xmlns:tools="http://schemas.android.com/tools";
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:fitsSystemWindows="true"
+    tools:context="org.torproject.android.ui.hiddenservices.ClientCookiesActivity">
+
+    <com.google.android.material.appbar.AppBarLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:theme="@style/DefaultTheme.AppBarOverlay">
+
+        <androidx.appcompat.widget.Toolbar
+            android:id="@+id/toolbar"
+            android:layout_width="match_parent"
+            android:layout_height="?attr/actionBarSize"
+            android:background="?attr/colorPrimary"
+            app:popupTheme="@style/DefaultTheme.PopupOverlay" />
+
+    </com.google.android.material.appbar.AppBarLayout>
+
+    <include layout="@layout/layout_content_client_cookies" />
+
+    <com.google.android.material.floatingactionbutton.FloatingActionButton
+        android:id="@+id/fab"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom|end"
+        android:layout_margin="@dimen/fab_margin"
+        android:tint="@android:color/black"
+        app:backgroundTint="@android:color/darker_gray"
+        app:srcCompat="@android:drawable/ic_input_add" />
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/app/src/main/res/layout/dialog_add_v3_client_auth.xml b/app/src/main/res/layout/dialog_add_v3_client_auth.xml
new file mode 100644
index 00000000..ec310a0c
--- /dev/null
+++ b/app/src/main/res/layout/dialog_add_v3_client_auth.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:padding="?dialogPreferredPadding">
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/onion"
+        android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small" />
+
+    <org.torproject.android.core.ui.NoPersonalizedLearningEditText
+        android:id="@+id/cookie_onion"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:ems="10"
+        android:inputType="text" />
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/auth_cookie"
+        android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small" />
+
+    <org.torproject.android.core.ui.NoPersonalizedLearningEditText
+        android:id="@+id/cookie_value"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:ems="10"
+        android:inputType="text" />
+</LinearLayout>
diff --git a/app/src/main/res/menu/orbot_main.xml b/app/src/main/res/menu/orbot_main.xml
index c0133d44..1f96b968 100644
--- a/app/src/main/res/menu/orbot_main.xml
+++ b/app/src/main/res/menu/orbot_main.xml
@@ -38,7 +38,12 @@
 
             <item
                 android:id="@+id/menu_v3_onion_services"
-                android:title="@string/hosted_services"
+                android:title="@string/v3_hosted_services"
+                yourapp:showAsAction="never" />
+
+            <item
+                android:id="@+id/menu_v3_onion_client_auth"
+                android:title="@string/v3_client_auth"
                 yourapp:showAsAction="never" />
 
             <item
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c888c856..a312d6da 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -170,6 +170,8 @@
     <string name="vpn_default_world">Global (Auto)</string>
     <string name="hidden_services">Onion Services</string>
     <string name="v2_hidden_services">V2 Onion Services (Deprecated)</string>
+    <string name="v3_hosted_services">Hosted V3 Onion Services</string>
+    <string name="v3_client_auth">V3 Onion Service Client Authorization</string>
     <string name="title_activity_hidden_services">Onion Services</string>
     <string name="menu_hidden_services">Onion Services</string>
     <string name="save">Save</string>



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits