~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/net/SSLUtils.cc

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-05-09 01:00:04 UTC
  • mto: (1.1.11) (5.3.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20130509010004-9fqq9n0adseg3f8w
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "ink_config.h"
23
23
#include "libts.h"
24
24
#include "I_Layout.h"
25
 
#include "P_EventSystem.h"
26
 
#include "P_SSLUtils.h"
27
 
#include "P_SSLConfig.h"
28
 
#include "P_SSLCertLookup.h"
 
25
#include "P_Net.h"
29
26
 
30
27
#include <openssl/err.h>
31
28
#include <openssl/bio.h>
123
120
static int
124
121
ssl_servername_callback(SSL * ssl, int * ad, void * arg)
125
122
{
126
 
  SSL_CTX *       ctx = NULL;
127
 
  SSLCertLookup * lookup = (SSLCertLookup *) arg;
128
 
  const char *    servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
 
123
  SSL_CTX *           ctx = NULL;
 
124
  SSLCertLookup *     lookup = (SSLCertLookup *) arg;
 
125
  const char *        servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
 
126
  SSLNetVConnection * netvc = (SSLNetVConnection *)SSL_get_app_data(ssl);
129
127
 
130
128
  Debug("ssl", "ssl=%p ad=%d lookup=%p server=%s", ssl, *ad, lookup, servername);
131
129
 
136
134
    ctx = lookup->findInfoInHash((char *)servername);
137
135
  }
138
136
 
 
137
  // If there's no match on the server name, try to match on the peer address.
 
138
  if (ctx == NULL) {
 
139
    IpEndpoint ip;
 
140
    int namelen = sizeof(ip);
 
141
 
 
142
    safe_getsockname(netvc->get_socket(), &ip.sa, &namelen);
 
143
    ctx = lookup->findInfoInHash(ip);
 
144
  }
 
145
 
139
146
  if (ctx != NULL) {
140
147
    SSL_set_SSL_CTX(ssl, ctx);
141
148
  }
176
183
SSLInitializeLibrary()
177
184
{
178
185
  if (!open_ssl_initialized) {
 
186
    CRYPTO_set_mem_functions(ats_malloc, ats_realloc, ats_free);
 
187
 
179
188
    SSL_load_error_strings();
180
189
    SSL_library_init();
181
190
 
440
449
  explicit ats_x509_certificate(X509 * x) : x509(x) {}
441
450
  ~ats_x509_certificate() { if (x509) X509_free(x509); }
442
451
 
 
452
  operator bool() const {
 
453
      return x509 != NULL;
 
454
  }
 
455
 
443
456
  X509 * x509;
444
457
 
445
458
private:
545
558
  xptr<char>  certpath;
546
559
 
547
560
  ctx = ssl_context_enable_sni(SSLInitServerContext(params, cert, ca, key), lookup);
548
 
  if (!cert) {
 
561
  if (!ctx) {
549
562
    SSLError("failed to create new SSL server context");
550
563
    return;
551
564
  }
670
683
      if (errPtr != NULL) {
671
684
        snprintf(errBuf, sizeof(errBuf), "%s: discarding %s entry at line %d: %s",
672
685
                     __func__, params->configFilePath, line_num, errPtr);
673
 
        IOCORE_SignalError(errBuf, alarmAlready);
 
686
        REC_SignalError(errBuf, alarmAlready);
674
687
      } else {
675
688
        if (ssl_extract_certificate(&line_info, addr, cert, ca, key)) {
676
689
          ssl_store_ssl_context(params, lookup, addr, cert, ca, key);
677
690
        } else {
678
691
          snprintf(errBuf, sizeof(errBuf), "%s: discarding invalid %s entry at line %u",
679
692
                       __func__, params->configFilePath, line_num);
680
 
          IOCORE_SignalError(errBuf, alarmAlready);
 
693
          REC_SignalError(errBuf, alarmAlready);
681
694
        }
682
695
      }
683
696