Skip to content

Commit

Permalink
User toggle certificate verification
Browse files Browse the repository at this point in the history
  • Loading branch information
GreaterFire committed Jan 18, 2019
1 parent 432feab commit 93b0983
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import android.app.Activity;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

private EditText remoteAddrText;
private EditText remotePortText;
private EditText passwordText;
private ToggleButton verifyButton;
private Button startStopButton;

private String getConfig(String remoteAddr, short remotePort, String password, boolean verify) {
Expand Down Expand Up @@ -52,6 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
remoteAddrText = findViewById(R.id.remoteAddrText);
remotePortText = findViewById(R.id.remotePortText);
passwordText = findViewById(R.id.passwordText);
verifyButton = findViewById(R.id.verifyButton);
startStopButton = findViewById(R.id.startStopButton);
startStopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Expand All @@ -60,7 +63,7 @@ public void onClick(View v) {
String config = getConfig(remoteAddrText.getText().toString(),
Short.parseShort(remotePortText.getText().toString()),
passwordText.getText().toString(),
true);
verifyButton.isChecked());
File file = new File(getFilesDir(), "config.json");
try {
FileOutputStream os = new FileOutputStream(file);
Expand Down Expand Up @@ -90,6 +93,7 @@ public void onClick(View v) {
remoteAddrText.setText(json.getString("remote_addr"));
remotePortText.setText(String.valueOf(json.getInt("remote_port")));
passwordText.setText(json.getJSONArray("password").getString(0));
verifyButton.setChecked(json.getJSONObject("ssl").getBoolean("verify"));
is.close();
} catch (Exception e) {
e.printStackTrace();
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@
android:hint="@string/password"
android:inputType="textPassword" />

<ToggleButton
android:id="@+id/verifyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="ToggleButton"
android:textOff="@string/verify_certificate"
android:textOn="@string/verify_certificate" />

<Button
android:id="@+id/startStopButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/startStop" />
android:text="@string/start_stop" />
</LinearLayout>
</ScrollView>

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<string name="remote_port">Remote Port</string>
<string name="default_port">443</string>
<string name="password">Password</string>
<string name="startStop">Start/Stop</string>
<string name="start_stop">Start/Stop</string>
<string name="verify_certificate">Verify Certificate</string>
</resources>

0 comments on commit 93b0983

Please sign in to comment.