예제 #1
0
  public SSLResult fingerprint() throws IOException, FingerprintError {

    SSLConfigCollector scc;

    scc = new SSLConfigCollector(host, port, si);
    scc.setCertValidator(cv);

    startDate = new Date();

    sslSupport = SSLResult.UNKNOWN;

    // If a delay is set, wait some time, except for
    // the first request
    if (!initial && (delay > 0)) {
      if (Debug.get(Debug.Delay)) {
        System.err.println("Delaying request.");
      }
      try {
        Thread.sleep(delay);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
    initial = false;

    try {
      scc.probe();
      sslSupport = SSLResult.SUPPORTED;
      sslSupportReason = null;
    } catch (NoSSLException e) {
      // This exception is thrown when the protocol support
      // for ssl is not available
      sslSupport = SSLResult.UNSUPPORTED;
      sslSupportReason = e.toString();
    } catch (FingerprintException e) {
      sslSupport = SSLResult.UNSUPPORTED;
      sslSupportReason = e.toString();
    } catch (IOException e) {
      sslSupport = SSLResult.UNKNOWN;
      sslSupportReason = e.toString();
    }
    endDate = new Date();

    protos = scc.getSupportedProtos();

    ProbeResult pres =
        new ProbeResult(
            host,
            port,
            startDate,
            endDate,
            sslSupport,
            sslSupportReason,
            scc.getServerCertificates(),
            scc.serverCertificateVerifies(),
            scc.serverCertNameMatch());

    pres.setProtosResult(protos);
    return pres;
  }
예제 #2
0
  private static TrustManager[] createTrustManagers() throws GeneralSecurityException, IOException {
    InputStream keyStoreStream =
        Thread.currentThread().getContextClassLoader().getResourceAsStream("ssltest-keystore.jks");
    char[] keyStorePassword = "******".toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(keyStoreStream, keyStorePassword);
    assert (ks.size() > 0);

    TrustManagerFactory tmf =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);
    return tmf.getTrustManagers();
  }
예제 #3
0
  private static KeyManager[] createKeyManagers() throws GeneralSecurityException, IOException {
    InputStream keyStoreStream =
        Thread.currentThread().getContextClassLoader().getResourceAsStream("ssltest-cacerts.jks");
    char[] keyStorePassword = "******".toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(keyStoreStream, keyStorePassword);
    assert (ks.size() > 0);

    // Set up key manager factory to use our key store
    char[] certificatePassword = "******".toCharArray();
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, certificatePassword);

    // Initialize the SSLContext to work with our key managers.
    return kmf.getKeyManagers();
  }
예제 #4
0
  public static File getClasspathFile(String file) throws FileNotFoundException {
    ClassLoader cl = null;
    try {
      cl = Thread.currentThread().getContextClassLoader();
    } catch (Throwable ex) {
    }
    if (cl == null) {
      cl = TestUtils.class.getClassLoader();
    }
    URL resourceUrl = cl.getResource(file);

    try {
      return new File(new URI(resourceUrl.toString()).getSchemeSpecificPart());
    } catch (URISyntaxException e) {
      throw new FileNotFoundException(file);
    }
  }
예제 #5
0
 public static StackTraceElement getCallerStackTraceElement() {
   return Thread.currentThread().getStackTrace()[4];
 }
예제 #6
0
  @Override
  public void run() {
    _init();
    Thread thread = Thread.currentThread();
    thread.setName("ExcellerisController" + "[" + thread.getId() + "]");

    logger.debug("Running [" + thread.getName() + "]");

    Node rootTag = null;
    String messageCount = null;
    String messageFormat = null;
    String messageVersion = null;
    // NamedNodeMap nodemap = null;
    // Document response = null;
    // Node code = null;
    String ackReturnCode = null;
    setLastFileCount(0);

    if (hostLogin()) {

      try {
        // fetch data
        logger.info("Fetching Excelleris labs from " + FETCH);
        getLabConnection().fetch(FETCH);
      } catch (SocketTimeoutException e) {
        handleError(
            "Connection timeout occured while attempting to fetch lab files. Check internet connectivity. ",
            e,
            ERROR);
      } catch (IOException e) {
        handleError("Expedius has failed to fetch lab files. Contact support. ", e, ERROR);
      } /*catch (ParserConfigurationException e) {
        	handleError("There was a problem with parsing the server response while fetching lab files.", e, ERROR);
        }  */ finally {
        // for maintenance.
        close();
      }

      // save data
      if (getLabConnection().getResponseCode() == HttpsURLConnection.HTTP_OK) {

        if (getLabConnection().hasResponse()) {

          rootTag = getDocumentHandler().getRoot();

          if (NODE_HL7MESSAGES.equalsIgnoreCase(rootTag.getNodeName())) {
            messageCount = getDocumentHandler().getNodeAttributeValue(NODE_MESSAGECOUNT, rootTag);
            messageFormat = getDocumentHandler().getNodeAttributeValue(NODE_MESSAGEFORMAT, rootTag);
            messageVersion = getDocumentHandler().getNodeAttributeValue(NODE_VERSION, rootTag);

            logger.info(NODE_MESSAGECOUNT + ": " + messageCount);
            logger.info(NODE_MESSAGEFORMAT + ": " + messageFormat);
            logger.info(NODE_VERSION + ": " + messageVersion);
          }
        }

        if (getLastFileCount() > 0) {
          getLabHandler().setLabType(EXCELLERIS_LAB_TYPE);
          super.processResults(getDocumentHandler().getDocument(), labType);
        }
      }

      //						response = getLabConnection().getResponse();
      //						rootTag = response.getDocumentElement();
      //
      //						if(rootTag.getNodeName().equalsIgnoreCase(NODE_HL7MESSAGES)) {
      //
      //							nodemap = rootTag.getAttributes();
      //
      //							if(nodemap.getLength() > 0) {
      //
      //								messageCount = nodemap.getNamedItem(NODE_MESSAGECOUNT).getNodeValue();
      //								messageFormat = nodemap.getNamedItem(NODE_MESSAGEFORMAT).getNodeValue();
      //								messageVersion = nodemap.getNamedItem(NODE_VERSION).getNodeValue();
      //
      //								logger.info(NODE_MESSAGECOUNT + ": " + messageCount);
      //								logger.info(NODE_MESSAGEFORMAT + ": " + messageFormat);
      //								logger.info(NODE_VERSION + ": " + messageVersion);
      //
      //								if(messageCount != null) {
      //									setLastFileCount(Integer.parseInt(messageCount));
      //									logger.info( messageCount + " Excelleris labs downloaded");
      //								}
      //
      //							}
      //
      //						} else {
      //							logger.error("Error: No, or incorrect, content from server. Root Tag:
      // "+rootTag.toString());
      //						}
      //					}

      // }

      // CAUTION - disable acknowledge for testing. You will loose all your test labs.
      if ((ACKNOWLEDGE_DOWNLOADS.equalsIgnoreCase("true"))
          && (getLabHandler().getResponseCode() == HttpsURLConnection.HTTP_OK)) {
        try {
          getLabConnection().acknowledge(ACKNOWLEDGE);
        } catch (SocketTimeoutException e) {
          handleError(
              "Connection timeout occured while attempting to fetch lab files. Check internet connectivity. ",
              e,
              ERROR);
        } catch (IOException e) {
          handleError("Expedius has failed to fetch lab files. Contact support. ", e, ERROR);
        }

        if (getLabConnection().hasResponse()) {

          ackReturnCode =
              getDocumentHandler()
                  .getNodeAttributeValue(NODE_RETURNCODE, getDocumentHandler().getRoot());

          if (ACK_RETURN_CODE.equalsIgnoreCase(ackReturnCode)) {
            logger.info("All Labs Acknowledged: " + ackReturnCode);
          } else {
            handleError(
                "Expedius has failed to acknowledge the last lab download. "
                    + "This could result in multiple copies of the same lab. Excelleris server acknowledge return code was "
                    + ackReturnCode
                    + "If this error does not resolve in 24 hours, contact support.",
                null,
                DISMISSABLE_ERROR);
          }
        }
      }
      //
      //							rootTag = getLabConnection().getResponse().getDocumentElement();
      //							nodemap = rootTag.getAttributes();
      //
      //							if(nodemap.getLength() > 0) {
      //
      //								code = nodemap.getNamedItem(NODE_RETURNCODE);
      //
      //								if(Integer.parseInt(code.getNodeValue().toString()) == 0) {
      //
      //								} else {
      //									logger.error(rootTag.toString() + " Invalid response code");
      //								}
      //
      //							} else {
      //
      //							}
      //						}
      //
      //					} else {
      //
      //					}
      //
      //				} else {
      //					logger.info("Acknowledge not enabled. This lab file will be downloaded again.");
      //				}

      // catch all server response codes.
      processServerResponse(getLabConnection().getResponseCode());

      //			} catch (SocketTimeoutException e) {
      //				handleError("Connection timeout occured while attempting to fetch lab files. Check
      // internet connectivity. ", e, ERROR);
      //			} catch (IOException e) {
      //				handleError("Expedius has failed to fetch lab files. Contact support. ", e, ERROR);
      //			} catch (ParserConfigurationException e) {
      //				handleError("There was a problem with parsing the server response while fetching lab
      // files.", e, ERROR);
      //			}  finally {
      //				close();
      //			}
    }
  }