ThalesGroup / java-buildpack-luna-sample

Sample application demonstrating the Gemalto Luna Java Security Provider framework for the Java Buildpack
Apache License 2.0
16 stars 11 forks source link

No logged in tokens available #5

Open jtremiel opened 5 years ago

jtremiel commented 5 years ago

The boot application fails at startup. Slot Manager bean logon correctly, but the depending KeyPair gets an exception indicating no logged in tokens available.Calling SlotManager isLoggedin method inside Keypair bean method returns false. MayBe a classloader issue with boot?Same example runned as simple java class works like a charm

priitserk commented 4 years ago

Hello

Have you found any solution on this? I'm running the example with Spring Boot jar and getting the same error.

Caused by: com.safenetinc.luna.exception.LunaException: No logged in tokens available at com.safenetinc.luna.LunaSessionManager.getSession(LunaSessionManager.java:150) ~[hsm-1.jar!/:na] at com.safenetinc.luna.provider.keygen.LunaKeyPairGeneratorRsa.generateKeyPair(LunaKeyPairGeneratorRsa.java:107) ~[hsm-1.jar!/:na] at java.base/java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:722) ~[na:na]

priitserk commented 4 years ago

Tried aswell with simple class but the exception is same:

public static void main(String[] args) throws GeneralSecurityException {
    Security.addProvider(new LunaProvider());

    LunaSlotManager slotManager = LunaSlotManager.getInstance();
    slotManager.login("xxx", "xxx");

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "LunaProvider");
    keyPairGenerator.initialize(1024);
    KeyPair keyPair = keyPairGenerator.generateKeyPair();

    Cipher dec = decryptionCipher(keyPair);
    System.out.println("decryptionCipher " + dec.toString());
    Cipher enc = encryptionCipher(keyPair);
    System.out.println("encryptionCipher " + enc.toString());
}

[root@pre-rak HSM]# java -cp /usr/safenet/lunaclient/jsp/lib/LunaProvider.jar NoBootHSM.java modifying root logger's ConsoleHandler Exception in thread "main" com.safenetinc.luna.exception.LunaException: No logged in tokens available at com.safenetinc.luna.LunaSessionManager.getSession(LunaSessionManager.java:150) at com.safenetinc.luna.provider.keygen.LunaKeyPairGeneratorRsa.generateKeyPair(LunaKeyPairGeneratorRsa.java:107) at java.base/java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:722) at io.pivotal.luna.NoBootHSM.main(NoBootHSM.java:24)

priitserk commented 4 years ago

Got it running. No boot issue. Just salogin utility was not running. Works fine.