Search in sources :

Example 81 with InvalidParameterException

use of java.security.InvalidParameterException in project OpenGrok by OpenGrok.

the class PageConfig method getDataRoot.

/**
     * Get opengrok's configured dataroot directory. It is verified, that the
     * used environment has a valid opengrok data root set and that it is an
     * accessible directory.
     *
     * @return the opengrok data directory.
     * @throws InvalidParameterException if inaccessible or not set.
     */
public File getDataRoot() {
    if (dataRoot == null) {
        String tmp = getEnv().getDataRootPath();
        if (tmp == null || tmp.length() == 0) {
            throw new InvalidParameterException("dataRoot parameter is not " + "set in configuration.xml!");
        }
        dataRoot = new File(tmp);
        if (!(dataRoot.isDirectory() && dataRoot.canRead())) {
            throw new InvalidParameterException("The configured dataRoot '" + tmp + "' refers to a none-existing or unreadable directory!");
        }
    }
    return dataRoot;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) File(java.io.File)

Example 82 with InvalidParameterException

use of java.security.InvalidParameterException in project robovm by robovm.

the class OpenSSLCipherRSA method engineInitInternal.

private void engineInitInternal(int opmode, Key key) throws InvalidKeyException {
    if (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE) {
        encrypting = true;
    } else if (opmode == Cipher.DECRYPT_MODE || opmode == Cipher.UNWRAP_MODE) {
        encrypting = false;
    } else {
        throw new InvalidParameterException("Unsupported opmode " + opmode);
    }
    if (key instanceof OpenSSLRSAPrivateKey) {
        OpenSSLRSAPrivateKey rsaPrivateKey = (OpenSSLRSAPrivateKey) key;
        usingPrivateKey = true;
        this.key = rsaPrivateKey.getOpenSSLKey();
    } else if (key instanceof RSAPrivateCrtKey) {
        RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) key;
        usingPrivateKey = true;
        this.key = OpenSSLRSAPrivateCrtKey.getInstance(rsaPrivateKey);
    } else if (key instanceof RSAPrivateKey) {
        RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) key;
        usingPrivateKey = true;
        this.key = OpenSSLRSAPrivateKey.getInstance(rsaPrivateKey);
    } else if (key instanceof OpenSSLRSAPublicKey) {
        OpenSSLRSAPublicKey rsaPublicKey = (OpenSSLRSAPublicKey) key;
        usingPrivateKey = false;
        this.key = rsaPublicKey.getOpenSSLKey();
    } else if (key instanceof RSAPublicKey) {
        RSAPublicKey rsaPublicKey = (RSAPublicKey) key;
        usingPrivateKey = false;
        this.key = OpenSSLRSAPublicKey.getInstance(rsaPublicKey);
    } else {
        throw new InvalidKeyException("Need RSA private or public key");
    }
    buffer = new byte[NativeCrypto.RSA_size(this.key.getPkeyContext())];
    inputTooLarge = false;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) InvalidKeyException(java.security.InvalidKeyException) RSAPrivateKey(java.security.interfaces.RSAPrivateKey)

Example 83 with InvalidParameterException

use of java.security.InvalidParameterException in project robovm by robovm.

the class OpenSSLECGroupContext method getInstance.

public static OpenSSLECGroupContext getInstance(ECParameterSpec params) throws InvalidAlgorithmParameterException {
    final String curveName = params.getCurveName();
    if (curveName != null) {
        return OpenSSLECGroupContext.getCurveByName(curveName);
    }
    final EllipticCurve curve = params.getCurve();
    final ECField field = curve.getField();
    final int type;
    final BigInteger p;
    if (field instanceof ECFieldFp) {
        type = NativeCrypto.EC_CURVE_GFP;
        p = ((ECFieldFp) field).getP();
    } else if (field instanceof ECFieldF2m) {
        type = NativeCrypto.EC_CURVE_GF2M;
        p = ((ECFieldF2m) field).getReductionPolynomial();
    } else {
        throw new InvalidParameterException("unhandled field class " + field.getClass().getName());
    }
    final ECPoint generator = params.getGenerator();
    return OpenSSLECGroupContext.getInstance(type, p, curve.getA(), curve.getB(), generator.getAffineX(), generator.getAffineY(), params.getOrder(), BigInteger.valueOf(params.getCofactor()));
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint) ECPoint(java.security.spec.ECPoint)

Example 84 with InvalidParameterException

use of java.security.InvalidParameterException in project robovm by robovm.

the class BaseBlockCipher method engineInit.

protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
    CipherParameters param;
    this.pbeSpec = null;
    this.pbeAlgorithm = null;
    this.engineParams = null;
    //
    if (!(key instanceof SecretKey)) {
        throw new InvalidKeyException("Key for algorithm " + key.getAlgorithm() + " not suitable for symmetric enryption.");
    }
    //
    if (params == null && baseEngine.getAlgorithmName().startsWith("RC5-64")) {
        throw new InvalidAlgorithmParameterException("RC5 requires an RC5ParametersSpec to be passed in.");
    }
    //
    if (key instanceof BCPBEKey) {
        BCPBEKey k = (BCPBEKey) key;
        if (k.getOID() != null) {
            pbeAlgorithm = k.getOID().getId();
        } else {
            pbeAlgorithm = k.getAlgorithm();
        }
        if (k.getParam() != null) {
            param = k.getParam();
            if (params instanceof IvParameterSpec) {
                IvParameterSpec iv = (IvParameterSpec) params;
                param = new ParametersWithIV(param, iv.getIV());
            }
        } else if (params instanceof PBEParameterSpec) {
            pbeSpec = (PBEParameterSpec) params;
            param = PBE.Util.makePBEParameters(k, params, cipher.getUnderlyingCipher().getAlgorithmName());
        } else {
            throw new InvalidAlgorithmParameterException("PBE requires PBE parameters to be set.");
        }
        if (param instanceof ParametersWithIV) {
            ivParam = (ParametersWithIV) param;
        }
    } else if (params == null) {
        param = new KeyParameter(key.getEncoded());
    } else if (params instanceof IvParameterSpec) {
        if (ivLength != 0) {
            IvParameterSpec p = (IvParameterSpec) params;
            if (p.getIV().length != ivLength && !isAEADModeName(modeName)) {
                throw new InvalidAlgorithmParameterException("IV must be " + ivLength + " bytes long.");
            }
            if (key instanceof RepeatedSecretKeySpec) {
                param = new ParametersWithIV(null, p.getIV());
                ivParam = (ParametersWithIV) param;
            } else {
                param = new ParametersWithIV(new KeyParameter(key.getEncoded()), p.getIV());
                ivParam = (ParametersWithIV) param;
            }
        } else {
            if (modeName != null && modeName.equals("ECB")) {
                throw new InvalidAlgorithmParameterException("ECB mode does not use an IV");
            }
            param = new KeyParameter(key.getEncoded());
        }
    } else // BEGIN android-removed
    // else if (params instanceof GOST28147ParameterSpec)
    // {
    //     GOST28147ParameterSpec    gost28147Param = (GOST28147ParameterSpec)params;
    //
    //     param = new ParametersWithSBox(
    //                new KeyParameter(key.getEncoded()), ((GOST28147ParameterSpec)params).getSbox());
    //
    //     if (gost28147Param.getIV() != null && ivLength != 0)
    //     {
    //         param = new ParametersWithIV(param, gost28147Param.getIV());
    //         ivParam = (ParametersWithIV)param;
    //     }
    // }
    // else if (params instanceof RC2ParameterSpec)
    // {
    //     RC2ParameterSpec    rc2Param = (RC2ParameterSpec)params;
    //
    //     param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());
    //
    //     if (rc2Param.getIV() != null && ivLength != 0)
    //     {
    //         param = new ParametersWithIV(param, rc2Param.getIV());
    //         ivParam = (ParametersWithIV)param;
    //     }
    // }
    // else if (params instanceof RC5ParameterSpec)
    // {
    //     RC5ParameterSpec    rc5Param = (RC5ParameterSpec)params;
    //
    //     param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
    //     if (baseEngine.getAlgorithmName().startsWith("RC5"))
    //     {
    //         if (baseEngine.getAlgorithmName().equals("RC5-32"))
    //         {
    //             if (rc5Param.getWordSize() != 32)
    //             {
    //                 throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 32 not " + rc5Param.getWordSize() + ".");
    //             }
    //         }
    //         else if (baseEngine.getAlgorithmName().equals("RC5-64"))
    //         {
    //             if (rc5Param.getWordSize() != 64)
    //             {
    //                 throw new InvalidAlgorithmParameterException("RC5 already set up for a word size of 64 not " + rc5Param.getWordSize() + ".");
    //             }
    //         }
    //     }
    //     else
    //     {
    //         throw new InvalidAlgorithmParameterException("RC5 parameters passed to a cipher that is not RC5.");
    //     }
    //     if ((rc5Param.getIV() != null) && (ivLength != 0))
    //     {
    //         param = new ParametersWithIV(param, rc5Param.getIV());
    //         ivParam = (ParametersWithIV)param;
    //     }
    // }
    // END android-removed
    {
        throw new InvalidAlgorithmParameterException("unknown parameter type.");
    }
    if ((ivLength != 0) && !(param instanceof ParametersWithIV)) {
        SecureRandom ivRandom = random;
        if (ivRandom == null) {
            ivRandom = new SecureRandom();
        }
        if ((opmode == Cipher.ENCRYPT_MODE) || (opmode == Cipher.WRAP_MODE)) {
            byte[] iv = new byte[ivLength];
            ivRandom.nextBytes(iv);
            param = new ParametersWithIV(param, iv);
            ivParam = (ParametersWithIV) param;
        } else if (cipher.getUnderlyingCipher().getAlgorithmName().indexOf("PGPCFB") < 0) {
            throw new InvalidAlgorithmParameterException("no IV set when one expected");
        }
    }
    if (random != null && padded) {
        param = new ParametersWithRandom(param, random);
    }
    try {
        switch(opmode) {
            case Cipher.ENCRYPT_MODE:
            case Cipher.WRAP_MODE:
                cipher.init(true, param);
                break;
            case Cipher.DECRYPT_MODE:
            case Cipher.UNWRAP_MODE:
                cipher.init(false, param);
                break;
            default:
                throw new InvalidParameterException("unknown opmode " + opmode + " passed");
        }
    } catch (Exception e) {
        throw new InvalidKeyException(e.getMessage());
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) RepeatedSecretKeySpec(org.bouncycastle.jce.spec.RepeatedSecretKeySpec) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) SecureRandom(java.security.SecureRandom) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) InvalidKeyException(java.security.InvalidKeyException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) DataLengthException(org.bouncycastle.crypto.DataLengthException) InvalidParameterException(java.security.InvalidParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) ShortBufferException(javax.crypto.ShortBufferException) OutputLengthException(org.bouncycastle.crypto.OutputLengthException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CipherParameters(org.bouncycastle.crypto.CipherParameters) ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV) InvalidParameterException(java.security.InvalidParameterException) SecretKey(javax.crypto.SecretKey) IvParameterSpec(javax.crypto.spec.IvParameterSpec) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec)

Example 85 with InvalidParameterException

use of java.security.InvalidParameterException in project robovm by robovm.

the class KeyPairGenerator1Test method testKeyPairGenerator12.

/**
     * Test for methods: <code>initialize(int keysize)</code>
     * <code>initialize(int keysize, SecureRandom random)</code>
     * <code>initialize(AlgorithmParameterSpec param)</code>
     * <code>initialize(AlgorithmParameterSpec param, SecureRandom random)</code>
     * <code>generateKeyPair()</code>
     * <code>genKeyPair()</code>
     * Assertion: throws InvalidParameterException or
     * InvalidAlgorithmParameterException when parameters keysize or param are
     * incorrect Assertion: generateKeyPair() and genKeyPair() return null
     * KeyPair Additional class MyKeyPairGenerator1 is used
     */
public void testKeyPairGenerator12() {
    int[] keys = { -1, -250, 1, 64, 512, 1024 };
    SecureRandom random = new SecureRandom();
    AlgorithmParameterSpec aps;
    KeyPairGenerator mKPG = new MyKeyPairGenerator1("");
    assertEquals("Incorrect algorithm", mKPG.getAlgorithm(), MyKeyPairGenerator1.getResAlgorithm());
    mKPG.generateKeyPair();
    mKPG.genKeyPair();
    for (int i = 0; i < keys.length; i++) {
        try {
            mKPG.initialize(keys[i]);
            fail("InvalidParameterException must be thrown (key: " + Integer.toString(keys[i]) + ")");
        } catch (InvalidParameterException e) {
        }
        try {
            mKPG.initialize(keys[i], random);
            fail("InvalidParameterException must be thrown (key: " + Integer.toString(keys[i]) + ")");
        } catch (InvalidParameterException e) {
        }
    }
    try {
        mKPG.initialize(100, null);
        fail("InvalidParameterException must be thrown when random is null");
    } catch (InvalidParameterException e) {
    }
    mKPG.initialize(100, random);
    assertEquals("Incorrect random", random, ((MyKeyPairGenerator1) mKPG).secureRandom);
    assertEquals("Incorrect keysize", 100, ((MyKeyPairGenerator1) mKPG).keySize);
    try {
        mKPG.initialize(null, random);
        fail("InvalidAlgorithmParameterException must be thrown when param is null");
    } catch (InvalidAlgorithmParameterException e) {
    }
    if (DSASupported) {
        BigInteger bInt = new BigInteger("1");
        aps = new java.security.spec.DSAParameterSpec(bInt, bInt, bInt);
        try {
            mKPG.initialize(aps, null);
            fail("InvalidParameterException must be thrown when random is null");
        } catch (InvalidParameterException e) {
        } catch (InvalidAlgorithmParameterException e) {
            fail("Unexpected InvalidAlgorithmParameterException was thrown");
        }
        try {
            mKPG.initialize(aps, random);
            assertEquals("Incorrect random", random, ((MyKeyPairGenerator1) mKPG).secureRandom);
            assertEquals("Incorrect params", aps, ((MyKeyPairGenerator1) mKPG).paramSpec);
        } catch (InvalidAlgorithmParameterException e) {
            fail("Unexpected InvalidAlgorithmParameterException was thrown");
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) MyKeyPairGenerator1(org.apache.harmony.security.tests.support.MyKeyPairGenerator1) SecureRandom(java.security.SecureRandom) BigInteger(java.math.BigInteger) KeyPairGenerator(java.security.KeyPairGenerator) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

InvalidParameterException (java.security.InvalidParameterException)135 SecureRandom (java.security.SecureRandom)15 ActionEvent (com.cloud.event.ActionEvent)11 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)9 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 Paint (android.graphics.Paint)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 DB (com.cloud.utils.db.DB)7 File (java.io.File)7 Properties (java.util.Properties)7 NimbusClient (backtype.storm.utils.NimbusClient)6 FirewallRule (com.cloud.network.rules.FirewallRule)6 InvalidKeyException (java.security.InvalidKeyException)6 Time (android.text.format.Time)4 FileNotFoundException (java.io.FileNotFoundException)4