Example usage for org.bouncycastle.bcpg PublicKeyAlgorithmTags RSA_GENERAL

List of usage examples for org.bouncycastle.bcpg PublicKeyAlgorithmTags RSA_GENERAL

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg PublicKeyAlgorithmTags RSA_GENERAL.

Prototype

int RSA_GENERAL

To view the source code for org.bouncycastle.bcpg PublicKeyAlgorithmTags RSA_GENERAL.

Click Source Link

Usage

From source file:com.google.e2e.bcdriver.KeyChecker.java

License:Apache License

private static final boolean canSign(int algorithm) {
    return (algorithm == PublicKeyAlgorithmTags.RSA_GENERAL) || (algorithm == PublicKeyAlgorithmTags.RSA_SIGN)
            || (algorithm == PublicKeyAlgorithmTags.DSA) || (algorithm == PublicKeyAlgorithmTags.ECDSA);
}

From source file:divconq.pgp.PGPUtil.java

License:Open Source License

public static String getSignatureName(int keyAlgorithm, int hashAlgorithm) throws PGPException {
    String encAlg;//from   ww  w.ja  v  a  2s. co  m

    switch (keyAlgorithm) {
    case PublicKeyAlgorithmTags.RSA_GENERAL:
    case PublicKeyAlgorithmTags.RSA_SIGN:
        encAlg = "RSA";
        break;
    case PublicKeyAlgorithmTags.DSA:
        encAlg = "DSA";
        break;
    case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: // in some malformed cases.
    case PublicKeyAlgorithmTags.ELGAMAL_GENERAL:
        encAlg = "ElGamal";
        break;
    default:
        throw new PGPException("unknown algorithm tag in signature:" + keyAlgorithm);
    }

    return getDigestName(hashAlgorithm) + "with" + encAlg;
}

From source file:org.sufficientlysecure.keychain.pgp.PgpKeyOperation.java

License:Open Source License

private static boolean checkSecurityTokenCompatibility(PGPSecretKey key, OperationLog log, int indent) {
    PGPPublicKey publicKey = key.getPublicKey();
    int algorithm = publicKey.getAlgorithm();
    if (algorithm != PublicKeyAlgorithmTags.RSA_ENCRYPT && algorithm != PublicKeyAlgorithmTags.RSA_SIGN
            && algorithm != PublicKeyAlgorithmTags.RSA_GENERAL) {
        log.add(LogType.MSG_MF_ERROR_BAD_SECURITY_TOKEN_ALGO, indent + 1);
        return false;
    }/*from   w  ww  . j a  va2 s .c om*/

    // Key size must be 2048
    int keySize = publicKey.getBitStrength();
    if (keySize != 2048) {
        log.add(LogType.MSG_MF_ERROR_BAD_SECURITY_TOKEN_SIZE, indent + 1);
        return false;
    }

    // Secret key parts must be available
    if (isDivertToCard(key) || isDummy(key)) {
        log.add(LogType.MSG_MF_ERROR_BAD_SECURITY_TOKEN_STRIPPED, indent + 1);
        return false;
    }

    return true;
}

From source file:org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.java

License:Open Source License

public static boolean isSecureKey(CanonicalizedPublicKey key) {
    switch (key.getAlgorithm()) {
    case PublicKeyAlgorithmTags.RSA_GENERAL: {
        return (key.getBitStrength() >= 2048);
    }//  w  w  w.  j a  va  2  s  .  c om
    // RSA_ENCRYPT, RSA_SIGN: deprecated in RFC 4880, use RSA_GENERAL with key flags
    case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: {
        return (key.getBitStrength() >= 2048);
    }
    case PublicKeyAlgorithmTags.DSA: {
        return (key.getBitStrength() >= 2048);
    }
    case PublicKeyAlgorithmTags.ECDH:
    case PublicKeyAlgorithmTags.ECDSA: {
        return PgpSecurityConstants.sCurveWhitelist.contains(key.getCurveOid());
    }
    // ELGAMAL_GENERAL: deprecated in RFC 4880, use ELGAMAL_ENCRYPT
    // DIFFIE_HELLMAN: unsure
    default:
        return false;
    }
}

From source file:org.sufficientlysecure.keychain.securitytoken.KeyFormat.java

License:Open Source License

public static KeyFormat fromBytes(byte[] bytes) {
    switch (bytes[0]) {
    case PublicKeyAlgorithmTags.RSA_GENERAL:
        if (bytes.length < 6) {
            throw new IllegalArgumentException("Bad length for RSA attributes");
        }/*  w  ww .  j av a2 s. c o m*/
        return new RSAKeyFormat(bytes[1] << 8 | bytes[2], bytes[3] << 8 | bytes[4],
                RSAKeyFormat.RSAAlgorithmFormat.from(bytes[5]));

    case PublicKeyAlgorithmTags.ECDH:
    case PublicKeyAlgorithmTags.ECDSA:
        if (bytes.length < 2) {
            throw new IllegalArgumentException("Bad length for RSA attributes");
        }
        int len = bytes.length - 1;
        if (bytes[bytes.length - 1] == (byte) 0xff) {
            len -= 1;
        }
        final byte[] boid = new byte[2 + len];
        boid[0] = (byte) 0x06;
        boid[1] = (byte) len;
        System.arraycopy(bytes, 1, boid, 2, len);
        final ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(boid);
        return new ECKeyFormat(oid, ECKeyFormat.ECAlgorithmFormat.from(bytes[0], bytes[bytes.length - 1]));

    default:
        throw new IllegalArgumentException("Unsupported Algorithm id " + bytes[0]);
    }
}

From source file:org.sufficientlysecure.keychain.support.KeyringBuilder.java

License:Open Source License

private static PublicKeyPacket createPgpPublicKey(BigInteger modulus) {
    return new PublicKeyPacket(PublicKeyAlgorithmTags.RSA_GENERAL, SIGNATURE_DATE,
            new RSAPublicBCPGKey(modulus, EXPONENT));
}

From source file:org.sufficientlysecure.keychain.support.KeyringBuilder.java

License:Open Source License

private static PublicKeyPacket createPgpPublicSubKey(BigInteger modulus) {
    return new PublicSubkeyPacket(PublicKeyAlgorithmTags.RSA_GENERAL, SIGNATURE_DATE,
            new RSAPublicBCPGKey(modulus, EXPONENT));
}

From source file:org.sufficientlysecure.keychain.ui.EditKeyFragment.java

License:Open Source License

private void editSubkey(final int position) {
    final long keyId = mSubkeysAdapter.getKeyId(position);

    Handler returnHandler = new Handler() {
        @Override//ww  w . ja  va2 s  .com
        public void handleMessage(Message message) {
            switch (message.what) {
            case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
                editSubkeyExpiry(position);
                break;
            case EditSubkeyDialogFragment.MESSAGE_REVOKE:
                // toggle
                if (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId)) {
                    mSaveKeyringParcel.mRevokeSubKeys.remove(keyId);
                } else {
                    mSaveKeyringParcel.mRevokeSubKeys.add(keyId);
                }
                break;
            case EditSubkeyDialogFragment.MESSAGE_STRIP: {
                SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position);
                if (secretKeyType == SecretKeyType.GNU_DUMMY) {
                    // Key is already stripped; this is a no-op.
                    break;
                }

                SubkeyChange change = mSaveKeyringParcel.getSubkeyChange(keyId);
                if (change == null) {
                    mSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false));
                    break;
                }
                // toggle
                change.mDummyStrip = !change.mDummyStrip;
                if (change.mDummyStrip && change.mMoveKeyToSecurityToken) {
                    // User had chosen to divert key, but now wants to strip it instead.
                    change.mMoveKeyToSecurityToken = false;
                }
                break;
            }
            case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN: {
                SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position);
                if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || secretKeyType == SecretKeyType.GNU_DUMMY) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_stripped,
                            Notify.Style.ERROR).show();
                    break;
                }

                int algorithm = mSubkeysAdapter.getAlgorithm(position);
                if (algorithm != PublicKeyAlgorithmTags.RSA_GENERAL
                        && algorithm != PublicKeyAlgorithmTags.RSA_ENCRYPT
                        && algorithm != PublicKeyAlgorithmTags.RSA_SIGN) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_algo,
                            Notify.Style.ERROR).show();
                    break;
                }

                if (mSubkeysAdapter.getKeySize(position) != 2048) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_size,
                            Notify.Style.ERROR).show();
                    break;
                }

                SubkeyChange change;
                change = mSaveKeyringParcel.getSubkeyChange(keyId);
                if (change == null) {
                    mSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true));
                    break;
                }
                // toggle
                change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken;
                if (change.mMoveKeyToSecurityToken && change.mDummyStrip) {
                    // User had chosen to strip key, but now wants to divert it.
                    change.mDummyStrip = false;
                }
                break;
            }
            }
            getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
        }
    };

    // Create a new Messenger for the communication back
    final Messenger messenger = new Messenger(returnHandler);

    DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
        public void run() {
            EditSubkeyDialogFragment dialogFragment = EditSubkeyDialogFragment.newInstance(messenger);

            dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyDialog");
        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.java

License:Open Source License

/**
 * Based on <a href="http://tools.ietf.org/html/rfc2440#section-9.1">OpenPGP Message Format</a>
 *///from   www.ja v  a 2  s  .co m
public static String getAlgorithmInfo(Context context, int algorithm, Integer keySize, String oid) {
    String algorithmStr;

    switch (algorithm) {
    case PublicKeyAlgorithmTags.RSA_GENERAL:
    case PublicKeyAlgorithmTags.RSA_ENCRYPT:
    case PublicKeyAlgorithmTags.RSA_SIGN: {
        algorithmStr = "RSA";
        break;
    }
    case PublicKeyAlgorithmTags.DSA: {
        algorithmStr = "DSA";
        break;
    }

    case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:
    case PublicKeyAlgorithmTags.ELGAMAL_GENERAL: {
        algorithmStr = "ElGamal";
        break;
    }

    case PublicKeyAlgorithmTags.ECDSA: {
        if (oid == null) {
            return "ECDSA";
        }
        String oidName = KeyFormattingUtils.getCurveInfo(context, oid);
        return "ECDSA (" + oidName + ")";
    }
    case PublicKeyAlgorithmTags.ECDH: {
        if (oid == null) {
            return "ECDH";
        }
        String oidName = KeyFormattingUtils.getCurveInfo(context, oid);
        return "ECDH (" + oidName + ")";
    }

    default: {
        if (context != null) {
            algorithmStr = context.getResources().getString(R.string.unknown_algorithm);
        } else {
            algorithmStr = "unknown";
        }
        break;
    }
    }
    if (keySize != null && keySize > 0)
        return algorithmStr + ", " + keySize + " bit";
    else
        return algorithmStr;
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.java

License:Open Source License

private void editSubkey(final int position) {
    final long keyId = mSubkeysAdapter.getKeyId(position);

    Handler returnHandler = new Handler() {
        @Override//from w  w  w  .  j  a va2 s. c o  m
        public void handleMessage(Message message) {
            switch (message.what) {
            case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
                editSubkeyExpiry(position);
                break;
            case EditSubkeyDialogFragment.MESSAGE_REVOKE:
                // toggle
                if (mEditModeSaveKeyringParcel.mRevokeSubKeys.contains(keyId)) {
                    mEditModeSaveKeyringParcel.mRevokeSubKeys.remove(keyId);
                } else {
                    mEditModeSaveKeyringParcel.mRevokeSubKeys.add(keyId);
                }
                break;
            case EditSubkeyDialogFragment.MESSAGE_STRIP: {
                SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position);
                if (secretKeyType == SecretKeyType.GNU_DUMMY) {
                    // Key is already stripped; this is a no-op.
                    break;
                }

                SubkeyChange change = mEditModeSaveKeyringParcel.getSubkeyChange(keyId);
                if (change == null) {
                    mEditModeSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false));
                    break;
                }
                // toggle
                change.mDummyStrip = !change.mDummyStrip;
                if (change.mDummyStrip && change.mMoveKeyToSecurityToken) {
                    // User had chosen to divert key, but now wants to strip it instead.
                    change.mMoveKeyToSecurityToken = false;
                }
                break;
            }
            case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN: {
                SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position);
                if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || secretKeyType == SecretKeyType.GNU_DUMMY) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_stripped,
                            Notify.Style.ERROR).show();
                    break;
                }

                int algorithm = mSubkeysAdapter.getAlgorithm(position);
                if (algorithm != PublicKeyAlgorithmTags.RSA_GENERAL
                        && algorithm != PublicKeyAlgorithmTags.RSA_ENCRYPT
                        && algorithm != PublicKeyAlgorithmTags.RSA_SIGN) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_algo,
                            Notify.Style.ERROR).show();
                    break;
                }

                if (mSubkeysAdapter.getKeySize(position) != 2048) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_size,
                            Notify.Style.ERROR).show();
                    break;
                }

                SubkeyChange change;
                change = mEditModeSaveKeyringParcel.getSubkeyChange(keyId);
                if (change == null) {
                    mEditModeSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true));
                    break;
                }
                // toggle
                change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken;
                if (change.mMoveKeyToSecurityToken && change.mDummyStrip) {
                    // User had chosen to strip key, but now wants to divert it.
                    change.mDummyStrip = false;
                }
                break;
            }
            }
            getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
        }
    };

    // Create a new Messenger for the communication back
    final Messenger messenger = new Messenger(returnHandler);

    DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
        public void run() {
            EditSubkeyDialogFragment dialogFragment = EditSubkeyDialogFragment.newInstance(messenger);

            dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyDialog");
        }
    });
}