Navigation


Changeset 1256:bd6b40c9f731 in freeDiameter for libfdcore


Ignore:
Timestamp:
Feb 2, 2014, 7:06:43 PM (10 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Children:
1257:55d0867dd8b8, 1258:97caad40b665
Phase:
public
Message:

Fix messages display level on TLS errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/cnxctx.c

    r1211 r1256  
    11901190                gnutls_credentials_type_t cred;
    11911191               
    1192                 LOG_A("TLS Session information for connection '%s':", conn->cc_id);
     1192                LOG_D("TLS Session information for connection '%s':", conn->cc_id);
    11931193
    11941194                /* print the key exchange's algorithm name */
    11951195                GNUTLS_TRACE( kx = gnutls_kx_get (session) );
    11961196                GNUTLS_TRACE( tmp = gnutls_kx_get_name (kx) );
    1197                 LOG_A("\t - Key Exchange: %s", tmp);
     1197                LOG_D("\t - Key Exchange: %s", tmp);
    11981198
    11991199                /* Check the authentication type used and switch
     
    12031203                {
    12041204                        case GNUTLS_CRD_IA:
    1205                                 LOG_A("\t - TLS/IA session");
     1205                                LOG_D("\t - TLS/IA session");
    12061206                                break;
    12071207
     
    12091209                                /* This returns NULL in server side. */
    12101210                                if (gnutls_psk_client_get_hint (session) != NULL)
    1211                                         LOG_A("\t - PSK authentication. PSK hint '%s'",
     1211                                        LOG_D("\t - PSK authentication. PSK hint '%s'",
    12121212                                                gnutls_psk_client_get_hint (session));
    12131213                                /* This returns NULL in client side. */
    12141214                                if (gnutls_psk_server_get_username (session) != NULL)
    1215                                         LOG_A("\t - PSK authentication. Connected as '%s'",
     1215                                        LOG_D("\t - PSK authentication. Connected as '%s'",
    12161216                                                gnutls_psk_server_get_username (session));
    12171217                                break;
    12181218
    12191219                        case GNUTLS_CRD_ANON:   /* anonymous authentication */
    1220                                 LOG_A("\t - Anonymous DH using prime of %d bits",
     1220                                LOG_D("\t - Anonymous DH using prime of %d bits",
    12211221                                        gnutls_dh_get_prime_bits (session));
    12221222                                break;
     
    12251225                                /* Check if we have been using ephemeral Diffie-Hellman. */
    12261226                                if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS) {
    1227                                         LOG_A("\t - Ephemeral DH using prime of %d bits",
     1227                                        LOG_D("\t - Ephemeral DH using prime of %d bits",
    12281228                                                gnutls_dh_get_prime_bits (session));
    12291229                                }
     
    12311231#ifdef ENABLE_SRP                               
    12321232                        case GNUTLS_CRD_SRP:
    1233                                 LOG_A("\t - SRP session with username %s",
     1233                                LOG_D("\t - SRP session with username %s",
    12341234                                        gnutls_srp_server_get_username (session));
    12351235                                break;
     
    12441244                /* print the protocol's name (ie TLS 1.0) */
    12451245                tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session));
    1246                 LOG_A("\t - Protocol: %s", tmp);
     1246                LOG_D("\t - Protocol: %s", tmp);
    12471247
    12481248                /* print the certificate type of the peer. ie X.509 */
    12491249                tmp = gnutls_certificate_type_get_name (gnutls_certificate_type_get (session));
    1250                 LOG_A("\t - Certificate Type: %s", tmp);
     1250                LOG_D("\t - Certificate Type: %s", tmp);
    12511251
    12521252                /* print the compression algorithm (if any) */
    12531253                tmp = gnutls_compression_get_name (gnutls_compression_get (session));
    1254                 LOG_A("\t - Compression: %s", tmp);
     1254                LOG_D("\t - Compression: %s", tmp);
    12551255
    12561256                /* print the name of the cipher used. ie 3DES. */
    12571257                tmp = gnutls_cipher_get_name (gnutls_cipher_get (session));
    1258                 LOG_A("\t - Cipher: %s", tmp);
     1258                LOG_D("\t - Cipher: %s", tmp);
    12591259
    12601260                /* Print the MAC algorithms name. ie SHA1 */
    12611261                tmp = gnutls_mac_get_name (gnutls_mac_get (session));
    1262                 LOG_A("\t - MAC: %s", tmp);
     1262                LOG_D("\t - MAC: %s", tmp);
    12631263        }
    12641264        #endif /* DEBUG */
     
    12671267        CHECK_GNUTLS_DO( gnutls_certificate_verify_peers2 (session, &gtret), return EINVAL );
    12681268        if (gtret) {
    1269                 if (TRACE_BOOL(INFO)) {
    1270                         fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    1271                         if (gtret & GNUTLS_CERT_INVALID)
    1272                                 fd_log_debug(" - The certificate is not trusted (unknown CA? expired?)");
    1273                         if (gtret & GNUTLS_CERT_REVOKED)
    1274                                 fd_log_debug(" - The certificate has been revoked.");
    1275                         if (gtret & GNUTLS_CERT_SIGNER_NOT_FOUND)
    1276                                 fd_log_debug(" - The certificate hasn't got a known issuer.");
    1277                         if (gtret & GNUTLS_CERT_SIGNER_NOT_CA)
    1278                                 fd_log_debug(" - The certificate signer is not a CA, or uses version 1, or 3 without basic constraints.");
    1279                         if (gtret & GNUTLS_CERT_INSECURE_ALGORITHM)
    1280                                 fd_log_debug(" - The certificate signature uses a weak algorithm.");
    1281                 }
     1269                LOG_E("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1270                if (gtret & GNUTLS_CERT_INVALID)
     1271                        LOG_E(" - The certificate is not trusted (unknown CA? expired?)");
     1272                if (gtret & GNUTLS_CERT_REVOKED)
     1273                        LOG_E(" - The certificate has been revoked.");
     1274                if (gtret & GNUTLS_CERT_SIGNER_NOT_FOUND)
     1275                        LOG_E(" - The certificate hasn't got a known issuer.");
     1276                if (gtret & GNUTLS_CERT_SIGNER_NOT_CA)
     1277                        LOG_E(" - The certificate signer is not a CA, or uses version 1, or 3 without basic constraints.");
     1278                if (gtret & GNUTLS_CERT_INSECURE_ALGORITHM)
     1279                        LOG_E(" - The certificate signature uses a weak algorithm.");
    12821280                return EINVAL;
    12831281        }
    12841282       
    12851283        /* Code from http://www.gnu.org/software/gnutls/manual/gnutls.html#Verifying-peer_0027s-certificate */
    1286         if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
     1284        if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) {
     1285                LOG_E("TLS: Remote peer did not present a certificate, other mechanisms are not supported yet. socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    12871286                return EINVAL;
     1287        }
    12881288       
    12891289        GNUTLS_TRACE( cert_list = gnutls_certificate_get_peers (session, &cert_list_size) );
     
    13601360                GNUTLS_TRACE( deadline = gnutls_x509_crt_get_expiration_time(cert) );
    13611361                if ((deadline != (time_t)-1) && (deadline < now)) {
    1362                         if (TRACE_BOOL(INFO)) {
    1363                                 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    1364                                 fd_log_debug(" - The certificate %d in the chain is expired", i);
    1365                         }
     1362                        LOG_E("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1363                        LOG_E(" - The certificate %d in the chain is expired", i);
    13661364                        ret = EINVAL;
    13671365                }
     
    13691367                GNUTLS_TRACE( deadline = gnutls_x509_crt_get_activation_time(cert) );
    13701368                if ((deadline != (time_t)-1) && (deadline > now)) {
    1371                         if (TRACE_BOOL(INFO)) {
    1372                                 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    1373                                 fd_log_debug(" - The certificate %d in the chain is not yet activated", i);
    1374                         }
     1369                        LOG_E("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1370                        LOG_E(" - The certificate %d in the chain is not yet activated", i);
    13751371                        ret = EINVAL;
    13761372                }
     
    13781374                if ((i == 0) && (conn->cc_tls_para.cn)) {
    13791375                        if (!gnutls_x509_crt_check_hostname (cert, conn->cc_tls_para.cn)) {
    1380                                 if (TRACE_BOOL(INFO)) {
    1381                                         fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    1382                                         fd_log_debug(" - The certificate hostname does not match '%s'", conn->cc_tls_para.cn);
    1383                                 }
     1376                                LOG_E("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1377                                LOG_E(" - The certificate hostname does not match '%s'", conn->cc_tls_para.cn);
    13841378                                ret = EINVAL;
    13851379                        }
     
    14251419                GNUTLS_TRACE( kx = gnutls_kx_get (session) );
    14261420                GNUTLS_TRACE( tmp = gnutls_kx_get_name (kx) );
    1427                 LOG_A("\t- Key Exchange: %s", tmp);
     1421                LOG_D("\t- Key Exchange: %s", tmp);
    14281422
    14291423                /* Check the authentication type used and switch
     
    14341428                {
    14351429                        case GNUTLS_CRD_IA:
    1436                                 LOG_A("\t - TLS/IA session");
     1430                                LOG_D("\t - TLS/IA session");
    14371431                                break;
    14381432
     
    14401434                        #ifdef ENABLE_SRP
    14411435                        case GNUTLS_CRD_SRP:
    1442                                 LOG_A("\t - SRP session with username %s",
     1436                                LOG_D("\t - SRP session with username %s",
    14431437                                        gnutls_srp_server_get_username (session));
    14441438                                break;
     
    14491443                                */
    14501444                                if (gnutls_psk_client_get_hint (session) != NULL)
    1451                                         LOG_A("\t - PSK authentication. PSK hint '%s'",
     1445                                        LOG_D("\t - PSK authentication. PSK hint '%s'",
    14521446                                                gnutls_psk_client_get_hint (session));
    14531447                                /* This returns NULL in client side.
    14541448                                */
    14551449                                if (gnutls_psk_server_get_username (session) != NULL)
    1456                                         LOG_A("\t - PSK authentication. Connected as '%s'",
     1450                                        LOG_D("\t - PSK authentication. Connected as '%s'",
    14571451                                                gnutls_psk_server_get_username (session));
    14581452
     
    14641458
    14651459                        case GNUTLS_CRD_ANON:      /* anonymous authentication */
    1466                                 LOG_A("\t - Anonymous DH using prime of %d bits",
     1460                                LOG_D("\t - Anonymous DH using prime of %d bits",
    14671461                                        gnutls_dh_get_prime_bits (session));
    14681462                                if (kx == GNUTLS_KX_ANON_ECDH)
     
    14871481                                        cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
    14881482
    1489                                         LOG_A("\t Peer provided %d certificates.", cert_list_size);
     1483                                        LOG_D("\t Peer provided %d certificates.", cert_list_size);
    14901484
    14911485                                        if (cert_list_size > 0)
     
    15071501                                                if (ret == 0)
    15081502                                                {
    1509                                                   LOG_A("\t\t%s", cinfo.data);
     1503                                                  LOG_D("\t\t%s", cinfo.data);
    15101504                                                  gnutls_free (cinfo.data);
    15111505                                                }
     
    15131507                                                if (conn->cc_tls_para.cn) {
    15141508                                                        if (!gnutls_x509_crt_check_hostname (cert, conn->cc_tls_para.cn)) {
    1515                                                                 fd_log_debug("\tTLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    1516                                                                 fd_log_debug("\t - The certificate hostname does not match '%s'", conn->cc_tls_para.cn);
     1509                                                                LOG_E("\tTLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1510                                                                LOG_E("\t - The certificate hostname does not match '%s'", conn->cc_tls_para.cn);
    15171511                                                                gnutls_x509_crt_deinit (cert);
    15181512                                                                return GNUTLS_E_CERTIFICATE_ERROR;
     
    15301524
    15311525                        default:
    1532                                 LOG_A("\t - unknown session type (%d)", cred);
     1526                                LOG_E("\t - unknown session type (%d)", cred);
    15331527
    15341528                }                           /* switch */
    15351529
    15361530                if (ecdh != 0)
    1537                         LOG_A("\t - Ephemeral ECDH using curve %s",
     1531                        LOG_D("\t - Ephemeral ECDH using curve %s",
    15381532                                gnutls_ecc_curve_get_name (gnutls_ecc_curve_get (session)));
    15391533                else if (dhe != 0)
    1540                         LOG_A("\t - Ephemeral DH using prime of %d bits",
     1534                        LOG_D("\t - Ephemeral DH using prime of %d bits",
    15411535                                gnutls_dh_get_prime_bits (session));
    15421536
     
    15441538                */
    15451539                tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session));
    1546                 LOG_A("\t - Protocol: %s", tmp);
     1540                LOG_D("\t - Protocol: %s", tmp);
    15471541
    15481542                /* print the certificate type of the peer.
     
    15501544                */
    15511545                tmp = gnutls_certificate_type_get_name (gnutls_certificate_type_get (session));
    1552                 LOG_A("\t - Certificate Type: %s", tmp);
     1546                LOG_D("\t - Certificate Type: %s", tmp);
    15531547
    15541548                /* print the compression algorithm (if any)
    15551549                */
    15561550                tmp = gnutls_compression_get_name (gnutls_compression_get (session));
    1557                 LOG_A("\t - Compression: %s", tmp);
     1551                LOG_D("\t - Compression: %s", tmp);
    15581552
    15591553                /* print the name of the cipher used.
     
    15611555                */
    15621556                tmp = gnutls_cipher_get_name (gnutls_cipher_get (session));
    1563                 LOG_A("\t - Cipher: %s", tmp);
     1557                LOG_D("\t - Cipher: %s", tmp);
    15641558
    15651559                /* Print the MAC algorithms name.
     
    15671561                */
    15681562                tmp = gnutls_mac_get_name (gnutls_mac_get (session));
    1569                 LOG_A("\t - MAC: %s", tmp);
     1563                LOG_D("\t - MAC: %s", tmp);
    15701564       
    15711565#endif /* DEBUG */             
     
    15751569        */
    15761570        CHECK_GNUTLS_DO( gnutls_certificate_verify_peers2 (session, &status), return GNUTLS_E_CERTIFICATE_ERROR );
    1577         if (TRACE_BOOL(INFO) && (status & GNUTLS_CERT_INVALID)) {
    1578                 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1571        if (status & GNUTLS_CERT_INVALID) {
     1572                LOG_E("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    15791573                if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
    1580                         fd_log_debug(" - The certificate hasn't got a known issuer.");
     1574                        LOG_E(" - The certificate hasn't got a known issuer.");
    15811575
    15821576                if (status & GNUTLS_CERT_REVOKED)
    1583                         fd_log_debug(" - The certificate has been revoked.");
     1577                        LOG_E(" - The certificate has been revoked.");
    15841578
    15851579                if (status & GNUTLS_CERT_EXPIRED)
    1586                         fd_log_debug(" - The certificate has expired.");
     1580                        LOG_E(" - The certificate has expired.");
    15871581
    15881582                if (status & GNUTLS_CERT_NOT_ACTIVATED)
    1589                         fd_log_debug(" - The certificate is not yet activated.");
     1583                        LOG_E(" - The certificate is not yet activated.");
    15901584        }       
    15911585        if (status & GNUTLS_CERT_INVALID)
     
    16001594        if ((!hostname_verified) && (conn->cc_tls_para.cn)) {
    16011595                if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) {
    1602                         TRACE_DEBUG(INFO, "TLS: Remote credentials are not x509, rejected on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1596                        LOG_E("TLS: Remote credentials are not x509, rejected on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    16031597                        return GNUTLS_E_CERTIFICATE_ERROR;
    16041598                }
     
    16121606
    16131607                if (!gnutls_x509_crt_check_hostname (cert, conn->cc_tls_para.cn)) {
    1614                         if (TRACE_BOOL(INFO)) {
    1615                                 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
    1616                                 fd_log_debug(" - The certificate hostname does not match '%s'", conn->cc_tls_para.cn);
    1617                         }
     1608                        LOG_E("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id);
     1609                        LOG_E(" - The certificate hostname does not match '%s'", conn->cc_tls_para.cn);
    16181610                        gnutls_x509_crt_deinit (cert);
    16191611                        return GNUTLS_E_CERTIFICATE_ERROR;
Note: See TracChangeset for help on using the changeset viewer.