Jaspersoft / jrs-rest-java-client

Java Rest Client for JasperReports Server
GNU Lesser General Public License v3.0
100 stars 101 forks source link

get the EncryptionKey from the server #16

Closed frandevel closed 10 years ago

frandevel commented 10 years ago

Is there any way to get the server's encryption key with the library?

boryskolesnykov commented 10 years ago

Hi Fran,

No, there is no way to get the server's encryption key with the library. You need to do it manually. Firstly you need to get public key from server with GET request on /GetEncryptionKey URL and then use it to encrypt password. I've sent you a small application which helps to encrypt password to f.serrano@devel.es.

frandevel commented 10 years ago

That was so nice from your side. Thanks a lot. I already implemented a method to get the encryption key from the server using a Spring Rest Template. For other readers on this thread, please note that login encryption must be enabled on the server prior to being able to get the key. This is done in:

...\WEB-INF\classes\esapi\security-config.properties
encryption.on=true

As documented in the "JasperReports-Server-Admin-Guide"

frandevel commented 10 years ago

Hi Borys, From the image you sent I read "copy and paste server Public key values here" with two arrows. The method signature asks for tow BigInteger values and I wonder what I have to paste for the second as I'm getting:

java.lang.NumberFormatException: For input string: "b852"

when I use the server key for both. This "b852" are the first 4 characters of the encryption key I get from the server. Any idea? Thanks a lot Fran

boryskolesnykov commented 10 years ago

Hi Fran,

I've specified each parameter in separate variable which is named as it is named in server response, hope it will help you:

{"maxdigits":"131","e":"10001","n":"b4e5e3db6df39057afc36750a97c2903ff1d32e8edf2e92d9b2e8748e2fd9deb22de9b987accc55750a5d0f3376b8b6bb4793dae47cd4eace519d27b6fc3678bdb4b00f9e5010c4d9458a780e36d07b5d83adf23135f73c0040d48fe89baccc7143fea3b9c0179d07acbd3848edf02f1903e1f8f852bff3065e07335b8da7123"}
        String n = "b4e5e3db6df39057afc36750a97c2903ff1d32e8edf2e92d9b2e8748e2fd9deb22de9b987accc55750a5d0f3376b8b6bb4793dae47cd4eace519d27b6fc3678bdb4b00f9e5010c4d9458a780e36d07b5d83adf23135f73c0040d48fe89baccc7143fea3b9c0179d07acbd3848edf02f1903e1f8f852bff3065e07335b8da7123";
        int radix = 16;
        String e = "10001";
        BigInteger modulus = new BigInteger(n, radix);
        BigInteger publicExponent = new BigInteger(e, radix);
        RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(modulus, publicExponent);