xmpp-compliance-tester

XMPP Compliance Tester, forked from github.com/iNPUTmice/ComplianceTester
git clone https://git.in0rdr.ch/xmpp-compliance-tester.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

XmppOverTls.java (2097B)


      1 package eu.siacs.compliance.tests;
      2 
      3 import de.measite.minidns.hla.ResolverApi;
      4 import de.measite.minidns.hla.ResolverResult;
      5 import de.measite.minidns.record.SRV;
      6 import eu.siacs.compliance.Result;
      7 import eu.siacs.utils.XmppDomainVerifier;
      8 import rocks.xmpp.core.session.XmppClient;
      9 
     10 import javax.net.ssl.SNIHostName;
     11 import javax.net.ssl.SSLParameters;
     12 import javax.net.ssl.SSLSocket;
     13 import javax.net.ssl.SSLSocketFactory;
     14 import java.io.IOException;
     15 import java.util.Arrays;
     16 
     17 public class XmppOverTls extends AbstractTest {
     18 
     19     public XmppOverTls(XmppClient client) {
     20         super(client);
     21     }
     22 
     23     @Override
     24     public Result run() {
     25         final String domain = client.getDomain().getDomain();
     26         final SSLParameters parameters = new SSLParameters();
     27         parameters.setServerNames(Arrays.asList(new SNIHostName(domain)));
     28         try {
     29             final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
     30             ResolverResult<SRV> results = ResolverApi.INSTANCE.resolve("_xmpps-client._tcp." + domain, SRV.class);
     31             for(SRV record : results.getAnswers()) {
     32                 try {
     33                     SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(record.name.toString(),record.port);
     34                     socket.setSSLParameters(parameters);
     35                     socket.setSoTimeout(1000);
     36                     socket.startHandshake();
     37                     final Result result;
     38                     if (XmppDomainVerifier.getInstance().verify(domain,socket.getSession())) {
     39                         result = Result.PASSED;
     40                     } else {
     41                         result = Result.FAILED;
     42                     }
     43                     socket.close();
     44                     return result;
     45                 } catch (IOException e) {
     46                     //ignored
     47                 }
     48             }
     49         } catch (Exception e) {
     50             return Result.FAILED;
     51         }
     52         return Result.FAILED;
     53     }
     54 
     55     @Override
     56     public String getName() {
     57         return "XEP-0368: SRV records for XMPP over TLS";
     58     }
     59 }