Example #1
0
static lagopus_result_t
connect_check_tls(struct session *s) {
  long res = -1;
  X509 *peer = NULL;
  lagopus_result_t ret = 0;

  lagopus_msg_debug(10, "connect check in\n");
  if (IS_CTX_NULL(s)) {
    lagopus_msg_warning("session ctx is null.\n");
    return LAGOPUS_RESULT_INVALID_ARGS;
  }

  if (IS_TLS_NOT_INIT(s) == false) {
    res = SSL_get_verify_result(GET_TLS_CTX(s)->ssl);
    peer = SSL_get_peer_certificate(GET_TLS_CTX(s)->ssl);
  }

  if (res != X509_V_OK || peer == NULL
      || GET_TLS_CTX(s)->verified == false) {
    ret = connect_tls(s, NULL, NULL);
  }
  lagopus_msg_debug(10, "connect check out ret:%d\n", (int) ret);

  return ret;
}
Example #2
0
//get scm symbols: scm_from_utf8_symbol(name)
SCM scm_connect_tls(SCM host, SCM port){
  char hostbuf[256], portbuf[16];
  //Assume the current locale is utf8, as the only function that lets
  //use use our own buffers implicitly uses the current locale
  if(!scm_is_string(host)){
    scm_raise_error("wrong-type-arg", "expected string in position 1");
  } else {
    size_t len = scm_to_locale_stringbuf(host, hostbuf, 256);
    if(len >= 256){
      scm_raise_error("too-long", "hostname too long");
    } else {
      hostbuf[len] = '\0';
    }
  }
  if(scm_is_string(port)){
    //make sure port looks like a number
    if(scm_is_false(scm_string_to_number(port, scm_from_int(10)))){
      scm_raise_error("wrong-type-arg",
                      "expected number or number as string in position 2");
    }
    size_t len = scm_to_locale_stringbuf(port, portbuf, 32);
    if(len >= 16){
      scm_raise_error("out-of-range", "Maximum port number is 65535");
    } else {
      portbuf[len] = '\0';
    }
  } else if(scm_is_integer(port)){
    uint16_t portno = scm_to_uint16(port);
    snprintf(portbuf, 16, "%d", portno);
  } else {
    scm_raise_error("wrong-type-arg",
                    "expected number or number as string in position 2");
  }
  BIO *bio = connect_tls(hostbuf, portbuf);
  if(!bio){
    scm_raise_error("system-error", "Failed to make tls connection");
  }
  return scm_new_smob(tls_tag, (scm_t_bits)bio);
}