Esempio n. 1
0
/* Report a GnuTLS error to the user.
   Return true if the error code was successfully handled.  */
static bool
emacs_gnutls_handle_error (gnutls_session_t session, int err)
{
  int max_log_level = 0;

  bool ret;
  const char *str;

  /* TODO: use a Lisp_Object generated by gnutls_make_error?  */
  if (err >= 0)
    return 1;

  max_log_level = global_gnutls_log_level;

  /* TODO: use gnutls-error-fatalp and gnutls-error-string.  */

  str = fn_gnutls_strerror (err);
  if (!str)
    str = "unknown";

  if (fn_gnutls_error_is_fatal (err))
    {
      ret = 0;
      GNUTLS_LOG2 (0, max_log_level, "fatal error:", str);
    }
  else
    {
      ret = 1;

      switch (err)
        {
        case GNUTLS_E_AGAIN:
          GNUTLS_LOG2 (3,
                       max_log_level,
                       "retry:",
                       str);
        default:
          GNUTLS_LOG2 (1,
                       max_log_level,
                       "non-fatal error:",
                       str);
        }
    }

  if (err == GNUTLS_E_WARNING_ALERT_RECEIVED
      || err == GNUTLS_E_FATAL_ALERT_RECEIVED)
    {
      int alert = fn_gnutls_alert_get (session);
      int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1;
      str = fn_gnutls_alert_get_name (alert);
      if (!str)
	str = "unknown";

      GNUTLS_LOG2 (level, max_log_level, "Received alert: ", str);
    }
  return ret;
}
Esempio n. 2
0
static int
init_gnutls_functions (Lisp_Object libraries)
{
  HMODULE library;
  int max_log_level = 1;

  if (!(library = w32_delayed_load (libraries, Qgnutls_dll)))
    {
      GNUTLS_LOG (1, max_log_level, "GnuTLS library not found");
      return 0;
    }

  LOAD_GNUTLS_FN (library, gnutls_alert_get);
  LOAD_GNUTLS_FN (library, gnutls_alert_get_name);
  LOAD_GNUTLS_FN (library, gnutls_alert_send_appropriate);
  LOAD_GNUTLS_FN (library, gnutls_anon_allocate_client_credentials);
  LOAD_GNUTLS_FN (library, gnutls_anon_free_client_credentials);
  LOAD_GNUTLS_FN (library, gnutls_bye);
  LOAD_GNUTLS_FN (library, gnutls_certificate_allocate_credentials);
  LOAD_GNUTLS_FN (library, gnutls_certificate_free_credentials);
  LOAD_GNUTLS_FN (library, gnutls_certificate_get_peers);
  LOAD_GNUTLS_FN (library, gnutls_certificate_set_verify_flags);
  LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_crl_file);
  LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_key_file);
  LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_trust_file);
  LOAD_GNUTLS_FN (library, gnutls_certificate_type_get);
  LOAD_GNUTLS_FN (library, gnutls_certificate_verify_peers2);
  LOAD_GNUTLS_FN (library, gnutls_credentials_set);
  LOAD_GNUTLS_FN (library, gnutls_deinit);
  LOAD_GNUTLS_FN (library, gnutls_dh_set_prime_bits);
  LOAD_GNUTLS_FN (library, gnutls_error_is_fatal);
  LOAD_GNUTLS_FN (library, gnutls_global_init);
  LOAD_GNUTLS_FN (library, gnutls_global_set_log_function);
  LOAD_GNUTLS_FN (library, gnutls_global_set_log_level);
  LOAD_GNUTLS_FN (library, gnutls_global_set_mem_functions);
  LOAD_GNUTLS_FN (library, gnutls_handshake);
  LOAD_GNUTLS_FN (library, gnutls_init);
  LOAD_GNUTLS_FN (library, gnutls_priority_set_direct);
  LOAD_GNUTLS_FN (library, gnutls_record_check_pending);
  LOAD_GNUTLS_FN (library, gnutls_record_recv);
  LOAD_GNUTLS_FN (library, gnutls_record_send);
  LOAD_GNUTLS_FN (library, gnutls_strerror);
  LOAD_GNUTLS_FN (library, gnutls_transport_set_errno);
  LOAD_GNUTLS_FN (library, gnutls_transport_set_lowat);
  LOAD_GNUTLS_FN (library, gnutls_transport_set_ptr2);
  LOAD_GNUTLS_FN (library, gnutls_transport_set_pull_function);
  LOAD_GNUTLS_FN (library, gnutls_transport_set_push_function);
  LOAD_GNUTLS_FN (library, gnutls_x509_crt_check_hostname);
  LOAD_GNUTLS_FN (library, gnutls_x509_crt_deinit);
  LOAD_GNUTLS_FN (library, gnutls_x509_crt_import);
  LOAD_GNUTLS_FN (library, gnutls_x509_crt_init);

  max_log_level = global_gnutls_log_level;

  GNUTLS_LOG2 (1, max_log_level, "GnuTLS library loaded:",
	       SDATA (Fget (Qgnutls_dll, QCloaded_from)));
  return 1;
}
Esempio n. 3
0
/* report a GnuTLS error to the user.
   Returns zero if the error code was successfully handled. */
static int
emacs_gnutls_handle_error (gnutls_session_t session, int err)
{
  int max_log_level = 0;

  int ret;
  const char *str;

  /* TODO: use a Lisp_Object generated by gnutls_make_error?  */
  if (err >= 0)
    return 0;

  max_log_level = global_gnutls_log_level;

  /* TODO: use gnutls-error-fatalp and gnutls-error-string.  */

  str = fn_gnutls_strerror (err);
  if (!str)
    str = "unknown";

  if (fn_gnutls_error_is_fatal (err))
    {
      ret = err;
      GNUTLS_LOG2 (0, max_log_level, "fatal error:", str);
    }
  else
    {
      ret = 0;
      GNUTLS_LOG2 (1, max_log_level, "non-fatal error:", str);
      /* TODO: EAGAIN AKA Qgnutls_e_again should be level 2.  */
    }

  if (err == GNUTLS_E_WARNING_ALERT_RECEIVED
      || err == GNUTLS_E_FATAL_ALERT_RECEIVED)
    {
      int alert = fn_gnutls_alert_get (session);
      int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1;
      str = fn_gnutls_alert_get_name (alert);
      if (!str)
	str = "unknown";

      GNUTLS_LOG2 (level, max_log_level, "Received alert: ", str);
    }
  return ret;
}
Esempio n. 4
0
static int
init_gnutls_functions (Lisp_Object libraries)
{
    HMODULE library;
    int max_log_level = 1;

    if (!(library = w32_delayed_load (libraries, Qgnutls_dll)))
    {
        GNUTLS_LOG (1, max_log_level, "GnuTLS library not found");
        return 0;
    }

    LOAD_GNUTLS_FN (library, gnutls_alert_get);
    LOAD_GNUTLS_FN (library, gnutls_alert_get_name);
    LOAD_GNUTLS_FN (library, gnutls_alert_send_appropriate);
    LOAD_GNUTLS_FN (library, gnutls_anon_allocate_client_credentials);
    LOAD_GNUTLS_FN (library, gnutls_anon_free_client_credentials);
    LOAD_GNUTLS_FN (library, gnutls_bye);
    LOAD_GNUTLS_FN (library, gnutls_certificate_allocate_credentials);
    LOAD_GNUTLS_FN (library, gnutls_certificate_free_credentials);
    LOAD_GNUTLS_FN (library, gnutls_certificate_get_peers);
    LOAD_GNUTLS_FN (library, gnutls_certificate_set_verify_flags);
    LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_crl_file);
    LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_key_file);
    LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_trust_file);
    LOAD_GNUTLS_FN (library, gnutls_certificate_type_get);
    LOAD_GNUTLS_FN (library, gnutls_certificate_verify_peers2);
    LOAD_GNUTLS_FN (library, gnutls_credentials_set);
    LOAD_GNUTLS_FN (library, gnutls_deinit);
    LOAD_GNUTLS_FN (library, gnutls_dh_set_prime_bits);
    LOAD_GNUTLS_FN (library, gnutls_error_is_fatal);
    LOAD_GNUTLS_FN (library, gnutls_global_init);
    LOAD_GNUTLS_FN (library, gnutls_global_set_log_function);
    LOAD_GNUTLS_FN (library, gnutls_global_set_log_level);
    LOAD_GNUTLS_FN (library, gnutls_global_set_mem_functions);
    LOAD_GNUTLS_FN (library, gnutls_handshake);
    LOAD_GNUTLS_FN (library, gnutls_init);
    LOAD_GNUTLS_FN (library, gnutls_priority_set_direct);
    LOAD_GNUTLS_FN (library, gnutls_record_check_pending);
    LOAD_GNUTLS_FN (library, gnutls_record_recv);
    LOAD_GNUTLS_FN (library, gnutls_record_send);
    LOAD_GNUTLS_FN (library, gnutls_strerror);
    LOAD_GNUTLS_FN (library, gnutls_transport_set_errno);
    LOAD_GNUTLS_FN (library, gnutls_check_version);
    /* We don't need to call gnutls_transport_set_lowat in GnuTLS 2.11.1
       and later, and the function was removed entirely in 3.0.0.  */
    if (!fn_gnutls_check_version ("2.11.1"))
        LOAD_GNUTLS_FN (library, gnutls_transport_set_lowat);
    LOAD_GNUTLS_FN (library, gnutls_transport_set_ptr2);
    LOAD_GNUTLS_FN (library, gnutls_transport_set_pull_function);
    LOAD_GNUTLS_FN (library, gnutls_transport_set_push_function);
    LOAD_GNUTLS_FN (library, gnutls_x509_crt_check_hostname);
    LOAD_GNUTLS_FN (library, gnutls_x509_crt_deinit);
    LOAD_GNUTLS_FN (library, gnutls_x509_crt_import);
    LOAD_GNUTLS_FN (library, gnutls_x509_crt_init);

    max_log_level = global_gnutls_log_level;

    {
        Lisp_Object name = CAR_SAFE (Fget (Qgnutls_dll, QCloaded_from));
        GNUTLS_LOG2 (1, max_log_level, "GnuTLS library loaded:",
                     STRINGP (name) ? (const char *) SDATA (name) : "unknown");
    }

    return 1;
}