Android Open Source - Swinedroid Server Hash Dialog






From Project

Back to project page Swinedroid.

License

The source code is released under:

GNU General Public License

If you think the Android project Swinedroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.legind.swinedroid;
/*from w w w. ja v  a  2  s  . c o  m*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class ServerHashDialog extends Activity {
  private TextView mMessageText;
  private TextView mMd5Text;
  private TextView mSha1Text;
  private Button mAcceptButton;
  private Button mRejectButton;
  private final int CERT_REJECTED = 0;
  private final int CERT_ACCEPTED = 1;
  private final String MSG_NEW_STRING = "Authenticity of host cannot be established.  Please review the following fingerprints to authenticate host.";
  private final String MSG_INVALID_STRING = "This hosts certificate information differs from the previously accepted certificate.  This may indicate an attack on your session is taking place.  Please review the following fingerprints carefully before accepting the server authenticity.";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    // get rid of title, also set the layout to fill parent.  this doesn't function properly in the layout XML
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.server_hash_dialog);
    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    
      mMessageText = (TextView) findViewById(R.id.server_hash_dialog_message);
      mMd5Text = (TextView) findViewById(R.id.md5_hash);
      mSha1Text = (TextView) findViewById(R.id.sha1_hash);
      mAcceptButton = (Button) findViewById(R.id.server_hash_dialog_accept);
      mRejectButton = (Button) findViewById(R.id.server_hash_dialog_reject);
      
      /*
       * If the accept button is clicked, send the sha1 and md5 hashes back
       * to the parent activity.
       */
    mAcceptButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        Intent i = new Intent();
        i.putExtra("MD5", mMd5Text.getText().toString());
        i.putExtra("SHA1", mSha1Text.getText().toString());
        setResult(CERT_ACCEPTED, i);
        finish();
      }
    });
    
    mRejectButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        setResult(CERT_REJECTED);
        finish();
      }
    });
    
    if(savedInstanceState != null){
      // if we have a savedInstanceState, load the strings directly
      mMessageText.setText(savedInstanceState.getString("mMessageText"));
      mMd5Text.setText(savedInstanceState.getString("mMd5Text"));
      mSha1Text.setText(savedInstanceState.getString("mSha1Text"));
    } else {
      Bundle extras = getIntent().getExtras();
      if(extras != null){
        // if we have an intent, construct the strings from intent
        if(extras.getBoolean("CERT_INVALID") == true){
          mMessageText.setText(MSG_INVALID_STRING);
        } else {
          mMessageText.setText(MSG_NEW_STRING);
        }
        mMd5Text.setText(extras.getString("MD5"));
        mSha1Text.setText(extras.getString("SHA1"));
      }
    }
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("mMessageText", mMessageText.getText().toString());
    outState.putString("mMd5Text", mMd5Text.getText().toString());
    outState.putString("mSha1Text", mSha1Text.getText().toString());
  }
}




Java Source Code List

com.legind.Dialogs.ErrorMessageHandler.java
com.legind.Dialogs.MessageHandler.java
com.legind.sqlite.AlertDbAdapter.java
com.legind.sqlite.DbAdapter.java
com.legind.sqlite.ServerDbAdapter.java
com.legind.ssl.CertificateInspect.CertificateInspect.java
com.legind.ssl.SSLHandler.SSLHandler.java
com.legind.ssl.TrustManagerFactory.TrustManagerFactory.java
com.legind.swinedroid.AlertList.java
com.legind.swinedroid.AlertSearch.java
com.legind.swinedroid.AlertView.java
com.legind.swinedroid.ServerEdit.java
com.legind.swinedroid.ServerHashDialog.java
com.legind.swinedroid.ServerView.java
com.legind.swinedroid.Swinedroid.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableBindRequires.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableManager.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableRequires.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableUniqueRequires.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnable.java
com.legind.swinedroid.RequestService.RequestElement.java
com.legind.swinedroid.RequestService.Request.java
com.legind.swinedroid.xml.AlertListXMLElement.java
com.legind.swinedroid.xml.AlertListXMLHandler.java
com.legind.swinedroid.xml.AlertXMLElement.java
com.legind.swinedroid.xml.AlertXMLHandler.java
com.legind.swinedroid.xml.OverviewXMLElement.java
com.legind.swinedroid.xml.OverviewXMLHandler.java
com.legind.swinedroid.xml.XMLHandlerException.java
com.legind.swinedroid.xml.XMLHandler.java
com.legind.web.WebTransport.WebTransportConnection.java
com.legind.web.WebTransport.WebTransportException.java
com.legind.web.WebTransport.WebTransport.java
org.achartengine.chartlib.AbstractChart.java
org.achartengine.chartlib.AlertChart.java