コード例 #1
0
  @SuppressWarnings("unchecked")
  public static boolean isCertificationKey(PGPPublicKey key) {
    if (key.getVersion() <= 3) {
      return true;
    }

    for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
      if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) {
        continue;
      }
      PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();

      if (hashed != null && (hashed.getKeyFlags() & KeyFlags.CERTIFY_OTHER) != 0) {
        return true;
      }

      PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();

      if (unhashed != null && (unhashed.getKeyFlags() & KeyFlags.CERTIFY_OTHER) != 0) {
        return true;
      }
    }

    return false;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public static boolean isSigningKey(PGPPublicKey key) {
    if (key.getVersion() <= 3) {
      return true;
    }

    // special case
    if (key.getAlgorithm() == PGPPublicKey.RSA_SIGN) {
      return true;
    }

    for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
      if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) {
        continue;
      }
      PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();

      if (hashed != null && (hashed.getKeyFlags() & KeyFlags.SIGN_DATA) != 0) {
        return true;
      }

      PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();

      if (unhashed != null && (unhashed.getKeyFlags() & KeyFlags.SIGN_DATA) != 0) {
        return true;
      }
    }

    return false;
  }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public static PGPPublicKey getMasterKey(PGPPublicKeyRing keyRing) {
    if (keyRing == null) {
      return null;
    }
    for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(keyRing.getPublicKeys())) {
      if (key.isMasterKey()) {
        return key;
      }
    }

    return null;
  }
コード例 #4
0
  public static Date getExpiryDate(PGPPublicKey key) {
    Date creationDate = getCreationDate(key);
    if (key.getValidDays() == 0) {
      // no expiry
      return null;
    }
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(creationDate);
    calendar.add(Calendar.DATE, key.getValidDays());
    Date expiryDate = calendar.getTime();

    return expiryDate;
  }
コード例 #5
0
  public static String getFingerPrint(Context context, long keyId) {
    PGPPublicKey key = ProviderHelper.getPGPPublicKeyByKeyId(context, keyId);
    // if it is no public key get it from your own keys...
    if (key == null) {
      PGPSecretKey secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, keyId);
      if (secretKey == null) {
        Log.e(Constants.TAG, "Key could not be found!");
        return null;
      }
      key = secretKey.getPublicKey();
    }

    return convertFingerprintToHex(key.getFingerprint(), true);
  }
コード例 #6
0
 @SuppressWarnings("unchecked")
 public static String getMainUserId(PGPPublicKey key) {
   for (String userId : new IterableIterator<String>(key.getUserIDs())) {
     return userId;
   }
   return null;
 }
コード例 #7
0
 public static Vector<PGPPublicKey> getUsableEncryptKeys(PGPPublicKeyRing keyRing) {
   Vector<PGPPublicKey> usableKeys = new Vector<PGPPublicKey>();
   Vector<PGPPublicKey> encryptKeys = getEncryptKeys(keyRing);
   PGPPublicKey masterKey = null;
   for (int i = 0; i < encryptKeys.size(); ++i) {
     PGPPublicKey key = encryptKeys.get(i);
     if (!isExpired(key) && !key.isRevoked()) {
       if (key.isMasterKey()) {
         masterKey = key;
       } else {
         usableKeys.add(key);
       }
     }
   }
   if (masterKey != null) {
     usableKeys.add(masterKey);
   }
   return usableKeys;
 }
コード例 #8
0
  @SuppressWarnings("unchecked")
  public static boolean isEncryptionKey(PGPPublicKey key) {
    if (!key.isEncryptionKey()) {
      return false;
    }

    if (key.getVersion() <= 3) {
      // this must be true now
      return key.isEncryptionKey();
    }

    // special cases
    if (key.getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT) {
      return true;
    }

    if (key.getAlgorithm() == PGPPublicKey.RSA_ENCRYPT) {
      return true;
    }

    for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
      if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) {
        continue;
      }
      PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();

      if (hashed != null
          && (hashed.getKeyFlags() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0) {
        return true;
      }

      PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();

      if (unhashed != null
          && (unhashed.getKeyFlags() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0) {
        return true;
      }
    }
    return false;
  }
コード例 #9
0
 public static Date getCreationDate(PGPPublicKey key) {
   return key.getCreationTime();
 }
コード例 #10
0
 public static String getAlgorithmInfo(PGPPublicKey key) {
   return getAlgorithmInfo(key.getAlgorithm(), key.getBitStrength());
 }