public OpenPgpSignatureResult build() {
    if (!mSignatureAvailable) {
      Log.d(Constants.TAG, "RESULT_NO_SIGNATURE");
      return OpenPgpSignatureResult.createWithNoSignature();
    }

    if (!mKnownKey) {
      Log.d(Constants.TAG, "RESULT_KEY_MISSING");
      return OpenPgpSignatureResult.createWithKeyMissing(mKeyId, mSignatureTimestamp);
    }

    if (!mValidSignature) {
      Log.d(Constants.TAG, "RESULT_INVALID_SIGNATURE");
      return OpenPgpSignatureResult.createWithInvalidSignature();
    }

    int signatureStatus;
    if (mIsKeyRevoked) {
      Log.d(Constants.TAG, "RESULT_INVALID_KEY_REVOKED");
      signatureStatus = OpenPgpSignatureResult.RESULT_INVALID_KEY_REVOKED;
    } else if (mIsKeyExpired) {
      Log.d(Constants.TAG, "RESULT_INVALID_KEY_EXPIRED");
      signatureStatus = OpenPgpSignatureResult.RESULT_INVALID_KEY_EXPIRED;
    } else if (mInsecure) {
      Log.d(Constants.TAG, "RESULT_INVALID_INSECURE");
      signatureStatus = OpenPgpSignatureResult.RESULT_INVALID_KEY_INSECURE;
    } else if (mIsSignatureKeyCertified) {
      Log.d(Constants.TAG, "RESULT_VALID_CONFIRMED");
      signatureStatus = OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED;
    } else {
      Log.d(Constants.TAG, "RESULT_VALID_UNCONFIRMED");
      signatureStatus = OpenPgpSignatureResult.RESULT_VALID_KEY_UNCONFIRMED;
    }

    return OpenPgpSignatureResult.createWithValidSignature(
        signatureStatus,
        mPrimaryUserId,
        mKeyId,
        mUserIds,
        mConfirmedUserIds,
        mSenderStatusResult,
        mSignatureTimestamp);
  }
  @SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated
  public static void setStatus(Context context, StatusHolder holder, DecryptVerifyResult result) {

    OpenPgpSignatureResult signatureResult = result.getSignatureResult();

    if (holder.hasEncrypt()) {
      int encText, encIcon, encColor;
      if (signatureResult != null && signatureResult.isSignatureOnly()) {
        encIcon = R.drawable.status_lock_open_24dp;
        encText = R.string.decrypt_result_not_encrypted;
        encColor = R.color.android_red_light;
      } else {
        encIcon = R.drawable.status_lock_closed_24dp;
        encText = R.string.decrypt_result_encrypted;
        encColor = R.color.android_green_light;
      }

      int encColorRes = context.getResources().getColor(encColor);
      holder.getEncryptionStatusIcon().setColorFilter(encColorRes, PorterDuff.Mode.SRC_IN);
      holder
          .getEncryptionStatusIcon()
          .setImageDrawable(context.getResources().getDrawable(encIcon));
      holder.getEncryptionStatusText().setText(encText);
      holder.getEncryptionStatusText().setTextColor(encColorRes);
    }

    int sigText, sigIcon, sigColor;
    int sigActionText, sigActionIcon;

    if (signatureResult == null) {

      sigText = R.string.decrypt_result_no_signature;
      sigIcon = R.drawable.status_signature_invalid_cutout_24dp;
      sigColor = R.color.bg_gray;

      // won't be used, but makes compiler happy
      sigActionText = 0;
      sigActionIcon = 0;

    } else
      switch (signatureResult.getStatus()) {
        case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED:
          {
            sigText = R.string.decrypt_result_signature_certified;
            sigIcon = R.drawable.status_signature_verified_cutout_24dp;
            sigColor = R.color.android_green_light;

            sigActionText = R.string.decrypt_result_action_show;
            sigActionIcon = R.drawable.ic_vpn_key_grey_24dp;
            break;
          }

        case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED:
          {
            sigText = R.string.decrypt_result_signature_uncertified;
            sigIcon = R.drawable.status_signature_unverified_cutout_24dp;
            sigColor = R.color.android_orange_light;

            sigActionText = R.string.decrypt_result_action_show;
            sigActionIcon = R.drawable.ic_vpn_key_grey_24dp;
            break;
          }

        case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED:
          {
            sigText = R.string.decrypt_result_signature_revoked_key;
            sigIcon = R.drawable.status_signature_revoked_cutout_24dp;
            sigColor = R.color.android_red_light;

            sigActionText = R.string.decrypt_result_action_show;
            sigActionIcon = R.drawable.ic_vpn_key_grey_24dp;
            break;
          }

        case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED:
          {
            sigText = R.string.decrypt_result_signature_expired_key;
            sigIcon = R.drawable.status_signature_expired_cutout_24dp;
            sigColor = R.color.android_red_light;

            sigActionText = R.string.decrypt_result_action_show;
            sigActionIcon = R.drawable.ic_vpn_key_grey_24dp;
            break;
          }

        case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING:
          {
            sigText = R.string.decrypt_result_signature_missing_key;
            sigIcon = R.drawable.status_signature_unknown_cutout_24dp;
            sigColor = R.color.android_red_light;

            sigActionText = R.string.decrypt_result_action_Lookup;
            sigActionIcon = R.drawable.ic_file_download_grey_24dp;
            break;
          }

        default:
        case OpenPgpSignatureResult.SIGNATURE_ERROR:
          {
            sigText = R.string.decrypt_result_invalid_signature;
            sigIcon = R.drawable.status_signature_invalid_cutout_24dp;
            sigColor = R.color.android_red_light;

            sigActionText = R.string.decrypt_result_action_show;
            sigActionIcon = R.drawable.ic_vpn_key_grey_24dp;
            break;
          }
      }

    int sigColorRes = context.getResources().getColor(sigColor);
    holder.getSignatureStatusIcon().setColorFilter(sigColorRes, PorterDuff.Mode.SRC_IN);
    holder.getSignatureStatusIcon().setImageDrawable(context.getResources().getDrawable(sigIcon));
    holder.getSignatureStatusText().setText(sigText);
    holder.getSignatureStatusText().setTextColor(sigColorRes);

    if (signatureResult != null) {

      holder.getSignatureLayout().setVisibility(View.VISIBLE);

      holder.getSignatureAction().setText(sigActionText);
      holder.getSignatureAction().setCompoundDrawablesWithIntrinsicBounds(0, 0, sigActionIcon, 0);

      String userId = signatureResult.getPrimaryUserId();
      KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
      if (userIdSplit.name != null) {
        holder.getSignatureUserName().setText(userIdSplit.name);
      } else {
        holder.getSignatureUserName().setText(R.string.user_id_no_name);
      }
      if (userIdSplit.email != null) {
        holder.getSignatureUserEmail().setVisibility(View.VISIBLE);
        holder.getSignatureUserEmail().setText(userIdSplit.email);
      } else {
        holder.getSignatureUserEmail().setVisibility(View.GONE);
      }

    } else {

      holder.getSignatureLayout().setVisibility(View.GONE);
    }
  }
예제 #3
0
 public boolean hasSignatureResult() {
   return openPgpSignatureResult != null
       && openPgpSignatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE;
 }