yuruhimesama opened a new issue, #412:
URL: https://github.com/apache/mina-sshd/issues/412

   ### Version
   
   2.10
   
   ### Bug description
   
   I am trying to integrate the [Azure Keyvault JCA 
library](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/keyvault/azure-security-keyvault-jca)
 when creating client connections. Idea is that I can keep a bespoke keypair 
for each remote host and call upon the correct keypair to establish the 
connection for the desired host at runtime. The trouble is that somewhere deep 
in the java security configuration is a configuration mismatch: when calling 
`ClientSession.auth()`, Java is unable to figure out how to use the underlying 
`PrivateKey`, which is strange given that the Keyvault implementation is native 
JCE -- standard `KeyStore`, `PublicKey`, `PrivateKey`. I am not doing anything 
bespoke for the security provider beyond `Security.addProvider().`
   
   ### Code Snippets
   ```java
           KeyVaultJcaProvider provider = new KeyVaultJcaProvider();
           Security.addProvider(provider);
   //...
           X509Certificate cert = (X509Certificate) 
ks.getCertificate("sshcert");
           PublicKey pk = cert.getPublicKey();
           
           PrivateKey privkey = (PrivateKey) ks.getKey("sshcert", null);
   
           KeyPair clientIdentityKeypair = new KeyPair(pk, privkey);
   
   //...
           ClientSession session = 
client.connect("ssh://user@remotehost:22").verify(Duration.ofMinutes(1), 
CancelOption.CANCEL_ON_TIMEOUT).getClientSession();
           session.addPublicKeyIdentity(clientIdentityKeypair);
   
           
session.auth().verify(Duration.ofSeconds(15),CancelOption.CANCEL_ON_TIMEOUT);
   
   ```
   
   
   
   ### Actual behavior
   
   ### Stack Trace
   
   ```java
   Exception in thread "main" org.apache.sshd.common.SshException: 
[ssh-connection]: Failed (InvalidKeyException) to execute: No installed 
provider supports this key: 
com.azure.security.keyvault.jca.implementation.KeyVaultPrivateKey
           at 
org.apache.sshd.common.future.AbstractSshFuture.lambda$verifyResult$2(AbstractSshFuture.java:146)
           at 
org.apache.sshd.common.future.AbstractSshFuture.formatExceptionMessage(AbstractSshFuture.java:206)
           at 
org.apache.sshd.common.future.AbstractSshFuture.verifyResult(AbstractSshFuture.java:145)
           at 
org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:56)
           at 
org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:35)
           at 
org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:74)
           at com.boeing.fleetlink.Mina.main(Mina.java:97)
   Caused by: java.security.InvalidKeyException: No installed provider supports 
this key: com.azure.security.keyvault.jca.implementation.KeyVaultPrivateKey
           at 
java.base/java.security.Signature$Delegate.chooseProvider(Signature.java:1284)
           at 
java.base/java.security.Signature$Delegate.engineInitSign(Signature.java:1354)
           at java.base/java.security.Signature.initSign(Signature.java:636)
           at 
org.apache.sshd.common.signature.AbstractSignature.initSigner(AbstractSignature.java:104)
           at 
org.apache.sshd.client.auth.pubkey.KeyPairIdentity.sign(KeyPairIdentity.java:81)
           at 
org.apache.sshd.client.auth.pubkey.UserAuthPublicKey.appendSignature(UserAuthPublicKey.java:446)
           at 
org.apache.sshd.client.auth.pubkey.UserAuthPublicKey.processAuthDataRequest(UserAuthPublicKey.java:413)
           at 
org.apache.sshd.client.auth.AbstractUserAuth.process(AbstractUserAuth.java:88)
           at 
org.apache.sshd.client.session.ClientUserAuthService.processUserAuth(ClientUserAuthService.java:345)
           at 
org.apache.sshd.client.session.ClientUserAuthService.process(ClientUserAuthService.java:267)
           at 
org.apache.sshd.common.session.helpers.CurrentService.process(CurrentService.java:109)
           at 
org.apache.sshd.common.session.helpers.AbstractSession.doHandleMessage(AbstractSession.java:592)
           at 
org.apache.sshd.common.session.helpers.AbstractSession.lambda$handleMessage$0(AbstractSession.java:523)
           at 
org.apache.sshd.common.util.threads.ThreadUtils.runAsInternal(ThreadUtils.java:68)
           at 
org.apache.sshd.common.session.helpers.AbstractSession.handleMessage(AbstractSession.java:522)
           at 
org.apache.sshd.common.session.helpers.AbstractSession.decode(AbstractSession.java:1649)
           at 
org.apache.sshd.common.session.helpers.AbstractSession.messageReceived(AbstractSession.java:483)
           at 
org.apache.sshd.common.session.helpers.AbstractSessionIoHandler.messageReceived(AbstractSessionIoHandler.java:64)
           at 
org.apache.sshd.common.io.nio2.Nio2Session.handleReadCycleCompletion(Nio2Session.java:407)
           at 
org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:380)
           at 
org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:375)
           at 
org.apache.sshd.common.io.nio2.Nio2CompletionHandler.lambda$completed$0(Nio2CompletionHandler.java:38)
           at java.base/java.security.AccessController.doPrivileged(Native 
Method)
           at 
org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:37)
           at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127)
           at java.base/sun.nio.ch.Invoker$2.run(Invoker.java:219)
           at 
java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
           at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
           at 
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
           at java.base/java.lang.Thread.run(Thread.java:829)
   ```
   
   
   ### Expected behavior
   
   A successful connection.
   
   ### Relevant log output
   
   _No response_
   
   ### Other information
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to