Exemplo n.º 1
0
static void handshake_io_slowly(void **state)
{
  selene_error_t *err;
  sln_parser_baton_t *baton;
  selene_conf_t *conf = NULL;
  selene_t *s = NULL;
  sln_bucket_t *e1;
  size_t maxlen = sizeof(openssl_client_hello_basic);
  size_t i;

  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &s));
  SLN_ASSERT_CONTEXT(s);

  baton = (sln_parser_baton_t *)s->backend_baton;

  for (i = maxlen; i <= maxlen; i++) {
    SLN_ERR(sln_bucket_create_copy_bytes(sln_test_alloc, &e1,
                                         openssl_client_hello_basic,
                                         i));
    SLN_BRIGADE_INSERT_TAIL(baton->in_handshake, e1);
    err  = sln_io_handshake_read(s, baton);
    if (err) {
      SLN_ASSERT(err->err == SELENE_EINVAL);
    }
    else {
      /* TODO: more asserts */
    }
    sln_brigade_clear(baton->in_handshake);
  }

  selene_destroy(s);
  selene_conf_destroy(conf);
}
Exemplo n.º 2
0
static void tls_http_accident(void **state)
{
  selene_error_t *err;
  sln_parser_baton_t *baton;
  selene_conf_t *conf = NULL;
  selene_t *s = NULL;
  http_cb_t cbb;
  sln_bucket_t *e1;

  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &s));
  SLN_ASSERT_CONTEXT(s);

  baton = (sln_parser_baton_t *)s->backend_baton;

  cbb.gotit = 0;
  selene_handler_set(s, SELENE_EVENT_TLS_GOT_HTTP, http_cb, &cbb);

  SLN_ERR(sln_bucket_create_copy_bytes(sln_test_alloc, &e1,
                                       http_message,
                                       strlen(http_message)));
  SLN_BRIGADE_INSERT_TAIL(s->bb.in_enc, e1);
  err  = sln_io_tls_read(s, baton);
  SLN_ASSERT(err != NULL);
  SLN_ASSERT(err->err == SELENE_EINVAL);
  selene_error_clear(err);
  assert_int_equal(1, cbb.gotit);
  selene_destroy(s);
  selene_conf_destroy(conf);
}
Exemplo n.º 3
0
static void init_server(void **state)
{
  selene_conf_t *conf = NULL;
  selene_t *ctxt = NULL;
  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &ctxt));
  SLN_ASSERT_CONTEXT(ctxt);
  selene_destroy(ctxt);
  selene_conf_destroy(conf);
}
Exemplo n.º 4
0
static void init_ctxt(void **state, selene_t **s_, selene_conf_t **conf_) {
  selene_t *s = NULL;
  selene_conf_t *conf = NULL;

  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &s));
  SLN_ASSERT_CONTEXT(s);

  *s_ = s;
  *conf_ = conf;
}
Exemplo n.º 5
0
static void logging_levels(void **state) {
  selene_conf_t *conf = NULL;
  selene_t *ctxt = NULL;
  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &ctxt));
  SLN_ASSERT_CONTEXT(ctxt);

  sln_log_level_set(ctxt, SLN_LOG_NOTHING);
  assert_int_equal(SLN_LOG_NOTHING, sln_log_level_get(ctxt));
  sln_log_level_set(ctxt, SLN_LOG_EVERYTHING);
  assert_int_equal(SLN_LOG_EVERYTHING, sln_log_level_get(ctxt));

  selene_destroy(ctxt);
  selene_conf_destroy(conf);
}
Exemplo n.º 6
0
static void logging_types(void **state) {
  selene_conf_t *conf = NULL;
  selene_t *s = NULL;
  log_cb_t b;
  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &s));
  SLN_ASSERT_CONTEXT(s);

  sln_log_level_set(s, SLN_LOG_EVERYTHING);
  selene_handler_set(s, SELENE_EVENT_LOG_MSG, log_cb, &b);

  b.cmp = "CRT: test:0\n";
  slnCrit(s, "test:%u", 0);

  b.cmp = "ERR: test:1\n";
  slnErr(s, "test:%u", 1);

  b.cmp = "INF: test:2\n";
  slnInfo(s, "test:%u", 2);

  b.cmp = "WRN: test:3\n";
  slnWarn(s, "test:%u", 3);

  b.cmp = "DBG: test:4\n";
  slnDbg(s, "test:%u", 4);

  b.cmp = "TRC: test:5\n";
  slnTrace(s, "test:%u", 5);

  b.cmp = "UNK: test:6\n";
  sln_log_fmt(s, 44, "test:%u", 6);

  sln_log_level_set(s, SLN_LOG_NOTHING);
  slnDbg(s, "test:%u", 4);

  selene_destroy(s);
  selene_conf_destroy(conf);
}
Exemplo n.º 7
0
static void prf_vector_from_book(void **state) {
  selene_conf_t *conf = NULL;
  selene_t *s = NULL;
  char buf[20];

  selene_conf_create(&conf);
  SLN_ERR(selene_conf_use_reasonable_defaults(conf));
  SLN_ERR(selene_server_create(conf, &s));
  SLN_ASSERT_CONTEXT(s);

  /**
   * Test vector from Implementing SSL/TLS....
   * inputs: secret label seed 20
   * output: b5baf4722b91851a8816d22ebd8c1d8cc2e94d55
   */
  SLN_ERR(sln_prf(s, "label", strlen("label"), "secret", strlen("secret"),
                  "seed", strlen("seed"), buf, sizeof(buf)));

  assert_memory_equal(buf, ssl_test_vector, 20);

  selene_destroy(s);
  selene_conf_destroy(conf);
}
Exemplo n.º 8
0
int main(int argc, char *argv[]) {
  const char *host = SELENE_SERVER_DEFAULT_HOST;
  int port = SELENE_SERVER_DEFAULT_PORT;
  const char *cert_path = SELENE_SERVER_DEFAULT_CERT_PATH;
  const char *key_path = NULL;
  selene_conf_t *conf = NULL;
  const char *cert = NULL;
  const char *pkey = NULL;
  int rv = 0;
  int i;

  for (i = 1; i < argc; i++) {
    /* TODO: s_server compat */
    if (!strcmp("-host", argv[i]) && argc > i + 1) {
      host = argv[i + 1];
      i++;
    } else if (!strcmp("-port", argv[i]) && argc > i + 1) {
      port = atoi(argv[i + 1]);
      i++;
    } else if (!strcmp("-listen", argv[i]) && argc > i + 1) {
      char *p;
      host = argv[i + 1];
      if ((p = strstr(host, ":")) == NULL) {
        fprintf(stderr, "no port found\n");
        exit(EXIT_FAILURE);
      }
      *(p++) = '\0';
      port = atoi(p);
      i++;
    } else {
      fprintf(stderr, "Invalid args\n");
      usage();
      exit(EXIT_FAILURE);
    }
  }

  if (host == NULL) {
    fprintf(stderr, "-host must be set\n");
    exit(EXIT_FAILURE);
  }

  if (port <= 0) {
    fprintf(stderr, "-port must be set\n");
    exit(EXIT_FAILURE);
  }

  if (key_path == NULL) {
    /* assume its a pem encoded cert + key in one */
    key_path = cert_path;
  }

  SERR(selene_conf_create(&conf));

  SERR(selene_conf_use_reasonable_defaults(conf));

  cert = load_cert(cert_path);
  pkey = load_cert(key_path);
  SERR(selene_conf_cert_chain_add(conf, cert, pkey));

  rv = listen_to(conf, host, port, stdin);

  selene_conf_destroy(conf);

  if (cert) {
    free((void *)cert);
  }

  if (pkey) {
    free((void *)pkey);
  }

  return rv;
}