package be.iminds.ilabt.jfed.util;

import be.iminds.ilabt.jfed.lowlevel.connection.JFedConnection;
import be.iminds.ilabt.jfed.lowlevel.ssh_key_info.SshKeyInfo;
import be.iminds.ilabt.jfed.lowlevel.ssh_key_info.SshKeyInfoFactory;
import org.testng.annotations.Test;

import java.net.URL;

import static org.hamcrest.MatcherAssert.assertThat;

public class SSLCertificateDownloaderTest {

    @Test(enabled = false)
    public void testGetCertificateInfo() throws Exception {
        URL serverUrl = new URL("https://10.216.69.141:18440/xmlrpc/geni/3/");
//        URL serverUrl = new URL("https://www.wall2.ilabt.iminds.be");
//        URL serverUrl = new URL("https://sfa3.planet-lab.eu:12345");
//        URL serverUrl = new URL("https://nitlab.inf.uth.gr:8001/RPC2");
//        URL serverUrl = new URL("https://ch.geni.net/SA");

        SshKeyInfo sshKeyInfo = SshKeyInfoFactory.createBasicSshKeyInfoFromPrivateKeyOnly(KeyUtil.pemToRsaPrivateKey(IOUtils.fileToString("/home/wim/.ssl/freq/geni_cert_wall2_wvdemeer_decrypted.pem"), null));
//        SshKeyInfo sshKeyInfo = BasicSshKeyInfo.createBasicSshKeyInfoFromPrivateKeyOnly(KeyUtil.pemToRsaPrivateKey(IOUtils.fileToString("/home/wim/.ssl/freq/geni_cert_gpo_wvdemeer.pem"), null));
//        SshKeyInfo sshKeyInfo = BasicSshKeyInfo.createBasicSshKeyInfoFromPrivateKeyOnly(KeyUtil.pemToRsaPrivateKey(IOUtils.fileToString("/home/wim/.ssl/freq/geni_cert_emulab_wvdemeer_decrypted.pem"), null));

        String hostname = "bastion.test.iminds.be";
        int port = 22;
        String username = "wvdemeer";
        String hostKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWxjv7A1BF66nFkWB+fCzCGHVsPEyxVEoe4arT+wcjZSSEtEZYYy+veOb+H28+A+aur1RBAleLfTTa9w5qiPmD/ILeKt5LHsA8cxr2dtgxadGgNxIqyWKJw+3L59qUj7YNLDHmlPEBxroBWWQMqSWKeiGd0JXvUFTRj7RaPenaGD3XzSW1Z+fuYGK2zqKKPAwdTp6woPyn98bPggwV0TcwU6ch1ceJOwS74l3cdcEglXBQ6hNp9e6kMMYtfaxVpFrQtnr+lOLldZdkbCNtx5TR6X1MGLsQUIjLiShM4mKE06et3vO9kqjbcvjE0FI3IIE8ps3AZqzJAjHscsRQ14fB";
        JFedConnection.SshProxyInfo proxyInfo = new JFedConnection.SshProxyInfo(hostname, port, username, sshKeyInfo, hostKey, false);
//        JFedConnection.SshProxyInfo proxyInfo = null;

        SSLCertificateDownloader.SSLCertificateJFedInfo certInfo =
                SSLCertificateDownloader.getCertificateInfo(serverUrl,
                        (proxyInfo != null && proxyInfo instanceof JFedConnection.SshProxyInfo) ? (JFedConnection.SshProxyInfo) proxyInfo : null);

        System.out.println("certInfo="+certInfo);
    }
}
