代码之家  ›  专栏  ›  技术社区  ›  xeroqu

sbt会话中不允许多个SSH连接

  •  0
  • xeroqu  · 技术社区  · 9 年前

    scala-ssh (0.8版)通过SSH连接到远程机器并从那里传输文件。

    如果我运行集成测试 在一个 sbt

    private lazy val fileInventory: AnsibleYamlFileInventory = {
        val inventory = SSH(ansibleHost, HostResourceConfig()) { client =>
          client.fileTransfer {
            scp =>
              val tmpLocalFile = Files.createTempFile("inventory", ".yaml")
              scp.download(remoteYamlInventoryFile, tmpLocalFile.toAbsolutePath.toString)
              new AnsibleYamlFileInventory(tmpLocalFile)
          }
        }
    
        inventory.fold(s => throw new RuntimeException(s), identity)
    }
    

    如果我试图在同一个测试中运行同一个测试(或另一个集成测试),就会出现问题 一场我收到与上述相同的错误消息 here :

        14:32:11.751 [reader] ERROR net.schmizz.sshj.transport.TransportImpl - Dying because - {}
    net.schmizz.sshj.common.SSHRuntimeException: null
            at net.schmizz.sshj.common.Buffer.readPublicKey(Buffer.java:432)
            at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:75)
            at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:367)
            at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:509)
            at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:107)
            at net.schmizz.sshj.transport.Decoder.received(Decoder.java:175)
            at net.schmizz.sshj.transport.Reader.run(Reader.java:60)
    Caused by: java.security.GeneralSecurityException: java.security.spec.InvalidKeySpecException: key spec not recognised
            at net.schmizz.sshj.common.KeyType$3.readPubKeyFromBuffer(KeyType.java:156)
            at net.schmizz.sshj.common.Buffer.readPublicKey(Buffer.java:430)
            ... 6 common frames omitted
    Caused by: java.security.spec.InvalidKeySpecException: key spec not recognised
            at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic(Unknown Source)
            at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source)
            at java.security.KeyFactory.generatePublic(KeyFactory.java:334)
            at net.schmizz.sshj.common.KeyType$3.readPubKeyFromBuffer(KeyType.java:154)
            ... 7 common frames omitted
    

    如果我杀了它 会话并重新启动另一个,在问题再次出现之前,我只能再次运行一个集成测试。

    我已经按照建议安装了JCE 8文件。所以,我想知道我需要修复什么才能使多个测试成功运行,让它们可以通过ssh连接到远程机器。

    1 回复  |  直到 9 年前
        1
  •  0
  •   xeroqu    9 年前

    经过一些调试,我发现问题是由于 BouncyCastle

    INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle already registered as a JCE provider
    

    security provider dynamically

    def doTests(): Unit = {
    
      import org.bouncycastle.jce.provider.BouncyCastleProvider
      import java.security.Security
    
      Security.addProvider(new BouncyCastleProvider)
    
      "Some test" should {
        "be BLABLA" in {
          assert(...) // some test
        }
      }
    
      "Some other test" should {
        "be BLABLABLA" in {
          assert(...) // some other test
        }
      }
    
      Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
    }