代码之家  ›  专栏  ›  技术社区  ›  Balázs Németh

隧道上的HTTPS

  •  0
  • Balázs Németh  · 技术社区  · 5 年前

    ssh -L 8000:dev.mycompany.com:443 jump.mycompany.com

    现在我想用Jsch来模拟:

        public static void openTunnel() {
        JSch jsch = new JSch();
        String privateKey = "~/.ssh/id_rsa";
        try {
            jsch.addIdentity(privateKey);
            log.info("Connecting to {}@{}", getJumpUser(), getJumpServer());
            Session session = jsch.getSession(getJumpUser(), getJumpServer(), 22);
            session.connect();
            session.setPortForwardingL(8000, getHost(), 433);
        } catch (JSchException e) {
            log.error("", e);
        }
    }
    

    但是,在隧道设置之后,我遇到了以下异常,并尝试使用restemplate连接到它(Spring HTTP Client-但是curl也给出了一个错误):

    ssl.SSLHandshakeException: Remote host closed connection during handshake
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
    

    0 回复  |  直到 5 年前
        1
  •  2
  •   jeb    5 年前

    端口转发可以工作,但https不能工作本地主机:8000,因为证书是针对 dev.mycompany.com 而不是 localhost .

    hosts 文件。

    127.0.0.1 dev.mycompany.com
    

    不过,试试袜子可能更容易些。

    ssh jump.mycompany.com -D 8005
    

    选择:手动代理配置:
    Socks主机:本地主机
    端口:8005
    袜子5