difi/oxalis — Issue #4: Problem retrieving private key from keystore
Author: estromsnes
Created: 2012-03-02 11:31:39+00:00
State: open

I'm trying to send a document to my own access point using the oxalis-standalone program using the following commandline:

```
java -jar oxalis-standalone.jar ^
-kf .keystore ^
-kp=xxxyyzz ^
-f ehf-test.xml ^
-p INVOICE_ONLY ^
-c CH1 ^
-r 9908:976098897 ^
-s 9908:976098897 ^
-u https://localhost:9443/oxalis/accessPointService
```

The following exception occurs:
```
java.lang.RuntimeException: java.lang.RuntimeException: Failed to get our private key
at com.sun.xml.wss.impl.misc.DefaultCallbackHandler.getDefaultPrivKeyCert(DefaultCallbackHandler.java:1468)
at com.sun.xml.wss.impl.misc.DefaultCallbackHandler.handle(DefaultCallbackHandler.java:551)
at com.sun.xml.wss.impl.misc.DefaultSecurityEnvironmentImpl.getDefaultPrivKeyCertRequest(DefaultSecurityEnvironmentImpl.java:261)
at com.sun.xml.wss.impl.filter.SignatureFilter.process(SignatureFilter.java:235)
at com.sun.xml.wss.impl.HarnessUtil.processWSSPolicy(HarnessUtil.java:99)
at com.sun.xml.wss.impl.HarnessUtil.processDeep(HarnessUtil.java:278)
at com.sun.xml.wss.impl.SecurityAnnotator.processMessagePolicy(SecurityAnnotator.java:194)
at com.sun.xml.wss.impl.SecurityAnnotator.secureMessage(SecurityAnnotator.java:155)
at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.secureOutboundMessage(SecurityTubeBase.java:386)
at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processClientRequestPacket(SecurityClientTube.java:323)
at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processRequest(SecurityClientTube.java:247)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:641)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482)
at com.sun.xml.ws.rx.util.FiberExecutor.runSync(FiberExecutor.java:94)
at com.sun.xml.ws.rx.util.Communicator.send(Communicator.java:423)
at com.sun.xml.ws.rx.rm.runtime.ClientTube.sendSessionControlMessage(ClientTube.java:564)
at com.sun.xml.ws.rx.rm.runtime.ClientTube.createSequences(ClientTube.java:424)
at com.sun.xml.ws.rx.rm.runtime.ClientTube.openRmSession(ClientTube.java:347)
at com.sun.xml.ws.rx.rm.runtime.ClientTube.processRequest(ClientTube.java:188)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:641)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482)
at com.sun.xml.ws.client.Stub.process(Stub.java:323)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:161)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:113)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at $Proxy43.create(Unknown Source)
at eu.peppol.outbound.soap.SoapDispatcher.sendSoapMessage(SoapDispatcher.java:136)
at eu.peppol.outbound.soap.SoapDispatcher.send(SoapDispatcher.java:91)
at eu.peppol.outbound.api.DocumentSender.send(DocumentSender.java:165)
at eu.peppol.outbound.api.DocumentSender.sendInvoice(DocumentSender.java:119)
at eu.sendregning.oxalis.Main.main(Main.java:107)
Caused by: java.lang.RuntimeException: Failed to get our private key
at eu.peppol.start.identifier.KeystoreManager.getOurPrivateKey(KeystoreManager.java:109)
at eu.peppol.outbound.callbacks.KeyStoreCallbackHandler.handle(KeyStoreCallbackHandler.java:34)
at com.sun.xml.wss.impl.misc.DefaultCallbackHandler.getPrivateKey(DefaultCallbackHandler.java:2394)
at com.sun.xml.wss.impl.misc.DefaultCallbackHandler.getDefaultPrivKeyCert(DefaultCallbackHandler.java:1457)
... 35 more
Caused by: java.lang.RuntimeException: Private key is not first element in keystore at .keystore
at eu.peppol.start.identifier.KeystoreManager.getOurPrivateKey(KeystoreManager.java:105)
... 38 more
```

I have done some simple debugging in the KeystoreManager.getOurPrivateKey method and here's what happens:

The alias is "peppol_ap" which is the alias I used when adding the certificate to my keystore.

But when trying to retrieve the corresponding key the following call returns null which causes the exception to be thrown:
```
Key key = keystore.getKey(alias, keystorePassword.toCharArray());
```
Any ideas what's causing this?