Beispiel #1
0
  static {
    Class<Object> clazz;

    logger = LoggerManager.getLogger(Base64.class.getName());

    try {
      clazz = (Class<Object>) Class.forName("android.util.Base64");
      // Looking for encode( byte[] input, int flags)
      aMethod = clazz.getMethod("encode", byte[].class, Integer.TYPE);
      logger.info(clazz.getName() + " is available.");
    } catch (ClassNotFoundException x) {
    } // Ignore
    catch (Exception x) {
      logger.error("Failed to initialize use of android.util.Base64", x);
    }

    try {
      clazz = (Class<Object>) Class.forName("org.bouncycastle.util.encoders.Base64Encoder");
      bEncoder = clazz.newInstance();
      // Looking for encode( byte[] input, int offset, int length, OutputStream output)
      bMethod =
          clazz.getMethod("encode", byte[].class, Integer.TYPE, Integer.TYPE, OutputStream.class);
      logger.info(clazz.getName() + " is available.");
    } catch (ClassNotFoundException x) {
    } // Ignore
    catch (Exception x) {
      logger.error("Failed to initialize use of org.bouncycastle.util.encoders.Base64Encoder", x);
    }

    if (aMethod == null && bMethod == null)
      throw new IllegalStateException("No base64 encoder implementation is available.");
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.zip_picker);

    LoggerManager.setLoggerFactory(new AndroidLoggerFactory());

    logger = (AndroidLogger) LoggerManager.getLogger(this.getClass().getName());
    // enable toasts for info level logging.  toasts are default for error and warnings.
    logger.setToastContext(getBaseContext());
    logger.setInfoToastEnabled(true);

    Button createButton = (Button) findViewById(R.id.SignButton);
    createButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View view) {
            invokeZipSignerActivity();
          }
        });

    String extStorageDir = Environment.getExternalStorageDirectory().toString();
    // Strip /mnt from /sdcard
    if (extStorageDir.startsWith("/mnt/sdcard")) extStorageDir = extStorageDir.substring(4);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String inputFile = prefs.getString(PREFERENCE_IN_FILE, extStorageDir + "/unsigned.zip");
    String outputFile = prefs.getString(PREFERENCE_OUT_FILE, extStorageDir + "/signed.zip");
    int keyIndex = prefs.getInt(PREFERENCE_KEY_INDEX, 0);

    EditText inputText = (EditText) findViewById(R.id.InFileEditText);
    inputText.setText(inputFile);

    EditText outputText = (EditText) findViewById(R.id.OutFileEditText);
    outputText.setText(outputFile);

    Button button = (Button) findViewById(R.id.OpenPickButton);
    button.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View arg0) {
            pickInputFile();
          }
        });

    button = (Button) findViewById(R.id.SaveAsPickButton);
    button.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View arg0) {
            pickOutputFile();
          }
        });

    button = (Button) findViewById(R.id.InOutPickButton);
    button.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View arg0) {
            pickInputOutputFiles();
          }
        });

    Spinner spinner = (Spinner) findViewById(R.id.KeyModeSpinner);
    keyModeSpinnerAdapter =
        KeyListSpinnerAdapter.createInstance(this, android.R.layout.simple_spinner_item);
    keyModeSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(keyModeSpinnerAdapter);
    if (keyIndex >= keyModeSpinnerAdapter.getCount()) keyIndex = 0;
    spinner.setSelection(keyIndex);
    spinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putInt(PREFERENCE_KEY_INDEX, position);
            editor.commit();
            updateAlgorithmSpinner(position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> adapter) {}
        });

    algorithmSpinner = (Spinner) findViewById(R.id.CertSignatureAlgorithm);
    sha1WithRsaSpinnerAdapter =
        ArrayAdapter.createFromResource(
            this, R.array.Sha1WithRsaAlgorithmArray, android.R.layout.simple_spinner_item);
    sha1WithRsaSpinnerAdapter.setDropDownViewResource(
        android.R.layout.simple_spinner_dropdown_item);
    allAlgorithmsSpinnerAdapter =
        ArrayAdapter.createFromResource(
            this, R.array.AllShaWithRsaAlgorithmsArray, android.R.layout.simple_spinner_item);
    allAlgorithmsSpinnerAdapter.setDropDownViewResource(
        android.R.layout.simple_spinner_dropdown_item);

    updateAlgorithmSpinner(keyIndex);

    algorithmSpinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            if (algorithmSpinnerAdapter.getCount() > 1) {
              SharedPreferences.Editor editor = prefs.edit();
              editor.putInt(PREFERENCE_ALG_INDEX, position);
              editor.commit();
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> adapter) {}
        });
  }
Beispiel #3
0
 public static LoggerInterface getLogger() {
   if (log == null) log = LoggerManager.getLogger(ZipSigner.class.getName());
   return log;
 }
 private static LoggerInterface getLogger() {
   if (logger != null) return logger;
   logger = LoggerManager.getLogger(EnterPasswordDialog.class.getName());
   return logger;
 }