Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Nov 2005 13:52:44 +0100 (MET)
From:      =?ISO-8859-1?Q?=22Niels_C=F6lle=22?= <NCoelle@gmx.de>
To:        Panagiotis Astithas <past@ebs.gr>
Cc:        freebsd-java@freebsd.org
Subject:   Re: JDK15: Cipher.getInstance throws UnsupportedOperationException
Message-ID:  <4978.1131108764@www53.gmx.net>
References:  <436B2CB6.8080205@ebs.gr>

next in thread | previous in thread | raw e-mail | index | archive | help
Hello Panagiotis,

> Could you post a small example program that demonstrates the issue? That 
> would help a lot, I think.

I think, I found the problem. We are using the IAIK-Provider. If it is
inserted at the first position, the exception is thrown. If it is added as
last Provider, the test works (See my example below). 

I am not sure if it is a problem of the IAIK Provider or the JDK. On the
other platforms I mentioned, the code works with IAIK as the first provider
in the list. Without the strong encryption policy! Setting the strong
encryption policy for jdk15 does not help... Strange.

Thanks.
Niels

*** snip ***
import iaik.security.provider.IAIK;

import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.Security;

import javax.crypto.Cipher;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class TokenTest {
    //
-------------------------------------------------------------------------
    // ATTRIBUTES
    //
-------------------------------------------------------------------------
    public static final String AES_ALGORITHM = "AES/CBC/NoPadding";

    // Token attributes
    private static Logger mLog = null;

    private Cipher mAesCipher;

    /**
     * Constructor, which adds the IAIK Provider at the end of the provider
     * list.
     * 
     * @throws Exception
     *             If anything goes wrong, thrown an exception.
     */
    public TokenTest() throws Exception {
        init(false);
    }

    /**
     * Constructor which puts the IAIK Provider at the end or beginning of
the
     * provider list.
     * 
     * @param pInsertProvider
     *            <code>true</code> puts the provider at position 1 of the
     *            provider list; <code>false</code> adds the provider at the
     *            end of the provider list.
     * @throws Exception
     *             If anything goes wrong, thrown an exception.
     */
    public TokenTest(final boolean pInsertProvider) throws Exception {
        init(pInsertProvider);
    }

    public Cipher getAesCipher() {
        return mAesCipher;
    }

    /**
     * Does the initialization of the TokenTest. It adds the IAIK Provider
to
     * the provider list and creates an AES-Cipher.
     * 
     * @param pInsertProvider
     *            <code>true</code> puts the provider at position 1 of the
     *            provider list; <code>false</code> adds the provider at the
     *            end of the provider list.
     * @throws Exception
     *             If anything goes wrong, thrown an exception.
     */
    private void init(boolean pInsertProvider) throws Exception {
        mLog.debug("Function -init- called");

        // Check, if the IAIK Provider is already in the provider list. If
so,
        // remove it.
        String providerName = (new IAIK()).getName();
        Provider[] aprovider = Security.getProviders();
        for (int i = 0; i < aprovider.length; i++) {
            Provider provider = aprovider[i];
            if (provider.getName().equals(providerName)) {
                mLog.info("Removing provider '" + providerName + "'");
                Security.removeProvider(providerName);
            }
        }
        
        // Add the IAIK provider to the provider list depending on 
        // pInsertProvider.
        mLog.info("Adding IAIK Provider as default");
        if (pInsertProvider) {
            Security.insertProviderAt(new IAIK(), 1);
        } else {
            Security.addProvider(new IAIK());
        }

        // Create the AES-Cipher
        try {
            mAesCipher = Cipher.getInstance(AES_ALGORITHM);
        } catch (GeneralSecurityException e) {
            mLog.error("Error getting AES cipher object: " +
e.getMessage());
            throw new Exception("Error getting AES cipher object: "
                    + e.getMessage());
        }
        // Debug
        mLog.debug("Token object initialized");
    }

    public static void main(String pArgs[]) {
        // Configure Log4J logging without a properties file.
        mLog = Logger.getLogger("TokenTest");
        BasicConfigurator.configure();

        // Do the test.
        try {
            // TokenTest(false) works fine, TokenTest(true) throws an
exception.
            TokenTest TokenError = new TokenTest(false);
            // TokenTest TokenError = new TokenTest(true);
            mLog.info("Using " + TokenError.getAesCipher().getAlgorithm());
        } catch (Throwable t) {
            mLog.fatal("An exception was thrown: ", t);
        }

        mLog.info("Finished.");
    }
}
*** snap ***

-- 
Niels Cölle
Hauptstr. 30
85586 Poing
+49-(0)8121-71620



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4978.1131108764>