~ubuntu-branches/debian/sid/postfix/sid

« back to all changes in this revision

Viewing changes to src/tls/tls_misc.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2012-03-20 13:47:16 UTC
  • mfrom: (1.1.34) (39.1.16 trunk)
  • Revision ID: package-import@ubuntu.com-20120320134716-o62kosz3odzt1rh6
Tags: 2.9.1-2
Drop unnecessary openssl check, since sonames will save us.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
/*      bool    var_tls_append_def_CA;
19
19
/*      bool    var_tls_preempt_clist;
20
20
/*
21
 
/*      TLS_APPL_STATE *tls_alloc_app_context(ssl_ctx)
 
21
/*      TLS_APPL_STATE *tls_alloc_app_context(ssl_ctx, log_mask)
22
22
/*      SSL_CTX *ssl_ctx;
 
23
/*      int     log_mask;
23
24
/*
24
25
/*      void    tls_free_app_context(app_ctx)
25
26
/*      void    *app_ctx;
26
27
/*
27
 
/*      TLS_SESS_STATE *tls_alloc_sess_context(log_level, namaddr)
28
 
/*      int     log_level;
 
28
/*      TLS_SESS_STATE *tls_alloc_sess_context(log_mask, namaddr)
 
29
/*      int     log_mask;
29
30
/*      const char *namaddr;
30
31
/*
31
32
/*      void    tls_free_context(TLScontext)
66
67
/*      int     argi;
67
68
/*      long    argl; /* unused */
68
69
/*      long    ret;
 
70
/*
 
71
/*      int     tls_log_mask(log_param, log_level)
 
72
/*      const char *log_param;
 
73
/*      const char *log_level;
69
74
/* DESCRIPTION
70
75
/*      This module implements routines that support the TLS client
71
76
/*      and server internals.
126
131
/*      tls_bio_dump_cb() is a call-back routine for the
127
132
/*      BIO_set_callback() routine. It logs SSL content to the
128
133
/*      Postfix logfile.
 
134
/*
 
135
/*      tls_log_mask() converts a TLS log_level value from string
 
136
/*      to mask.  The main.cf parameter name is passed along for
 
137
/*      diagnostics.
129
138
/* LICENSE
130
139
/* .ad
131
140
/* .fi
294
303
};
295
304
 
296
305
 /*
 
306
  * Log keyword <=> mask conversion.
 
307
  */
 
308
#define TLS_LOG_0 TLS_LOG_NONE
 
309
#define TLS_LOG_1 TLS_LOG_SUMMARY
 
310
#define TLS_LOG_2 (TLS_LOG_1 | TLS_LOG_VERBOSE | TLS_LOG_CACHE | TLS_LOG_DEBUG)
 
311
#define TLS_LOG_3 (TLS_LOG_2 | TLS_LOG_TLSPKTS)
 
312
#define TLS_LOG_4 (TLS_LOG_3 | TLS_LOG_ALLPKTS)
 
313
 
 
314
static const NAME_MASK tls_log_table[] = {
 
315
    "0", TLS_LOG_0,
 
316
    "none", TLS_LOG_NONE,
 
317
    "1", TLS_LOG_1,
 
318
    "routine", TLS_LOG_1,
 
319
    "2", TLS_LOG_2,
 
320
    "debug", TLS_LOG_2,
 
321
    "3", TLS_LOG_3,
 
322
    "ssl-expert", TLS_LOG_3,
 
323
    "4", TLS_LOG_4,
 
324
    "ssl-developer", TLS_LOG_4,
 
325
    "5", TLS_LOG_4,                     /* for good measure */
 
326
    "6", TLS_LOG_4,                     /* for good measure */
 
327
    "7", TLS_LOG_4,                     /* for good measure */
 
328
    "8", TLS_LOG_4,                     /* for good measure */
 
329
    "9", TLS_LOG_4,                     /* for good measure */
 
330
    "summary", TLS_LOG_SUMMARY,
 
331
    "untrusted", TLS_LOG_UNTRUSTED,
 
332
    "peercert", TLS_LOG_PEERCERT,
 
333
    "certmatch", TLS_LOG_CERTMATCH,
 
334
    "verbose", TLS_LOG_VERBOSE,         /* Postfix TLS library verbose */
 
335
    "cache", TLS_LOG_CACHE,
 
336
    "ssl-debug", TLS_LOG_DEBUG,         /* SSL library debug/verbose */
 
337
    "ssl-handshake-packet-dump", TLS_LOG_TLSPKTS,
 
338
    "ssl-session-packet-dump", TLS_LOG_TLSPKTS | TLS_LOG_ALLPKTS,
 
339
    0, 0,
 
340
};
 
341
 
 
342
 /*
297
343
  * Parsed OpenSSL version number.
298
344
  */
299
345
typedef struct {
320
366
    0, 0, 0,
321
367
};
322
368
 
 
369
/* tls_log_mask - Convert user TLS loglevel to internal log feature mask */
 
370
 
 
371
int     tls_log_mask(const char *log_param, const char *log_level)
 
372
{
 
373
    int     mask;
 
374
 
 
375
    mask = name_mask_opt(log_param, tls_log_table, log_level,
 
376
                         NAME_MASK_ANY_CASE | NAME_MASK_RETURN);
 
377
    return (mask);
 
378
}
 
379
 
323
380
/* tls_exclude_missing - Append exclusions for missing ciphers */
324
381
 
325
382
static const char *tls_exclude_missing(SSL_CTX *ctx, VSTRING *buf)
602
659
 
603
660
/* tls_alloc_app_context - allocate TLS application context */
604
661
 
605
 
TLS_APPL_STATE *tls_alloc_app_context(SSL_CTX *ssl_ctx)
 
662
TLS_APPL_STATE *tls_alloc_app_context(SSL_CTX *ssl_ctx, int log_mask)
606
663
{
607
664
    TLS_APPL_STATE *app_ctx;
608
665
 
609
666
    app_ctx = (TLS_APPL_STATE *) mymalloc(sizeof(*app_ctx));
610
667
 
 
668
    /* See portability note below with other memset() call. */
611
669
    memset((char *) app_ctx, 0, sizeof(*app_ctx));
612
670
    app_ctx->ssl_ctx = ssl_ctx;
 
671
    app_ctx->log_mask = log_mask;
613
672
 
614
673
    /* See also: cache purging code in tls_set_ciphers(). */
615
674
    app_ctx->cipher_grade = TLS_CIPHER_NONE;
641
700
 
642
701
/* tls_alloc_sess_context - allocate TLS session context */
643
702
 
644
 
TLS_SESS_STATE *tls_alloc_sess_context(int log_level, const char *namaddr)
 
703
TLS_SESS_STATE *tls_alloc_sess_context(int log_mask, const char *namaddr)
645
704
{
646
705
    TLS_SESS_STATE *TLScontext;
647
706
 
662
721
    TLScontext->peer_CN = 0;
663
722
    TLScontext->issuer_CN = 0;
664
723
    TLScontext->peer_fingerprint = 0;
 
724
    TLScontext->peer_pkey_fprint = 0;
665
725
    TLScontext->protocol = 0;
666
726
    TLScontext->cipher_name = 0;
667
 
    TLScontext->log_level = log_level;
 
727
    TLScontext->log_mask = log_mask;
668
728
    TLScontext->namaddr = lowercase(mystrdup(namaddr));
669
729
    TLScontext->fpt_dgst = 0;
670
730
 
695
755
        myfree(TLScontext->issuer_CN);
696
756
    if (TLScontext->peer_fingerprint)
697
757
        myfree(TLScontext->peer_fingerprint);
 
758
    if (TLScontext->peer_pkey_fprint)
 
759
        myfree(TLScontext->peer_pkey_fprint);
698
760
    if (TLScontext->fpt_dgst)
699
761
        myfree(TLScontext->fpt_dgst);
700
762
 
772
834
 
773
835
void    tls_check_version(void)
774
836
{
775
 
    TLS_VINFO hdr_info;
776
 
    TLS_VINFO lib_info;
777
 
 
778
 
    tls_version_split(OPENSSL_VERSION_NUMBER, &hdr_info);
779
 
    tls_version_split(SSLeay(), &lib_info);
780
 
 
781
 
    if (lib_info.major != hdr_info.major
782
 
        || lib_info.minor != hdr_info.minor
783
 
        || lib_info.micro != hdr_info.micro)
784
 
        msg_warn("run-time library vs. compile-time header version mismatch: "
785
 
             "OpenSSL %d.%d.%d may not be compatible with OpenSSL %d.%d.%d",
786
 
                 lib_info.major, lib_info.minor, lib_info.micro,
787
 
                 hdr_info.major, hdr_info.minor, hdr_info.micro);
 
837
        /* Debian will change the soname if openssl is ever incompatible. */
788
838
}
789
839
 
790
840
/* tls_bug_bits - SSL bug compatibility bits for this OpenSSL version */
792
842
long    tls_bug_bits(void)
793
843
{
794
844
    long    bits = SSL_OP_ALL;          /* Work around all known bugs */
795
 
    long    mask;
796
845
 
797
846
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
798
847
    long    lib_version = SSLeay();