Merge branch 'v3.0.x' into tr-integ
authorKevin Wasserman <krwasserman@painless-security.com>
Sun, 7 Sep 2014 15:11:18 +0000 (11:11 -0400)
committerKevin Wasserman <krwasserman@painless-security.com>
Sun, 7 Sep 2014 15:11:18 +0000 (11:11 -0400)
Conflicts:
raddb/mods-available/abfab_psk_sql
raddb/policy.d/abfab-tr
raddb/sites-available/abfab-tls
raddb/sites-available/abfab-tr-idp
raddb/sites-available/channel_bindings
share/dictionary.ukerna
src/modules/rlm_realm/all.mk

1  2 
raddb/mods-available/abfab_psk_sql
raddb/policy.d/abfab-tr
raddb/sites-available/abfab-tls
src/main/process.c
src/main/realms.c

@@@ -1,10 -1,15 +1,25 @@@
++<<<<<<< HEAD
 +#Module for PSK authorizations from ABFAb trust router
++=======
+ # -*- text -*-
+ ##
+ ## Module for PSK authorizations from ABFAB trust router
+ ##
+ ##    $Id$
++>>>>>>> v3.0.x
  sql psksql {
  
          driver = "rlm_sql_sqlite"
  
        sqlite {
                filename = "/var/lib/trust_router/keys"
++<<<<<<< HEAD
 +              }
 +
 +      }
++=======
+       }
+ }
++>>>>>>> v3.0.x
diff --combined raddb/policy.d/abfab-tr
@@@ -1,10 -1,18 +1,18 @@@
  #
+ #  ABFAB Trust router policies.
+ #
+ #     $Id$
+ #
+ #
  # Verify rp parameters
  #
  psk_authorize {
-       if (tls-psk-identity =* ANY) {
-               # TODO: may need to check moonshot-apc as well
+       if (TLS-PSK-Identity) {
+               # TODO: may need to check trust-router-apc as well
                if ("%{psksql:select distinct keyid from authorizations_keys where keyid = '%{tls-psk-identity}' and '%{trust-router-coi}' like coi and '%{gss-acceptor-realm-name}' like acceptor_realm and '%{gss-acceptor-host-name}' like hostname;}") {
+                       # do things here
                }
                else {
                        reject
  }
  
  abfab_pre_proxy {
-       # check acceptor host name is correct
+       # check that the acceptor host name is correct
        if ("%{client:gss_acceptor_host_name}" && "%{gss-acceptor-host-name}") {
                if ("%{client:gss_acceptor_host_name}" != "%{gss-acceptor-host-name}") {
                        reject
                }
        }
-       # set trust-router-coi attribute from client configuration
+       # set trust-router-coi attribute from the client configuration
 -      if ("%{client:trust-router_coi}") {
 +      if ("%{client:trust_router_coi}") {
                update proxy-request {
-                       trust-router-coi := "%{client:trust_router_coi}"
 -                      Trust-Router-COI := "%{client:moonshot_coi}"
++                      Trust-Router-COI := "%{client:trust_router_coi}"
                }
        }
-       # set gss-acceptor-realm-name attribute from client configuration
+       # set gss-acceptor-realm-name attribute from the client configuration
        if ("%{client:gss_acceptor_realm_name}") {
                update proxy-request {
-                       gss-acceptor-realm-name := "%{client:gss_acceptor_realm_name}"
+                       GSS-Acceptor-Realm-Name := "%{client:gss_acceptor_realm_name}"
                }
        }
  }
  
--#
- #  A virtual server which is used to validate channel-bindings.
+ #  A policy which is used to validate channel-bindings.
  #
  abfab_channel_bindings {
        if (GSS-Acceptor-Service-Name && (outer.request:GSS-Acceptor-Service-Name != GSS-Acceptor-Service-Name)) {
                reject
        }
        if (GSS-Acceptor-Host-Name && outer.request:GSS-Acceptor-Host-Name != GSS-Acceptor-Host-Name ) {
                reject
        }
        if (GSS-Acceptor-Realm-Name && outer.request:GSS-Acceptor-Realm-Name != GSS-Acceptor-Realm-Name ) {
                reject
        }
@@@ -1,12 -1,17 +1,26 @@@
++<<<<<<< HEAD
++=======
+ #
+ #     Example configuration for ABFAB listening on TLS.
+ #
+ #     $Id$
+ #
++>>>>>>> v3.0.x
  listen {
        ipaddr = *
        port = 2083
        type = auth
        proto = tcp
  
++<<<<<<< HEAD
 +      clients = radsec-abfab
 +      tls {
 +              private_key_password = whatever
++=======
+       tls {
+               private_key_password = whatever
++>>>>>>> v3.0.x
                # Moonshot tends to distribute certs separate from keys
                private_key_file = ${certdir}/server.key
                certificate_file = ${certdir}/server.pem
                fragment_size = 8192
                ca_path = ${cadir}
                cipher_list = "DEFAULT"
++<<<<<<< HEAD
 +              cache {
 +                enable = no
 +                lifetime = 24 # hours
 +                max_entries = 255
 +                }
 +
 +                require_client_cert = yes
 +                verify {
 +      }
 +                psk_query = "%{psksql:select hex(key) from psk_keys where keyid = '%{tls-psk-identity}';}"
 +              }
 +      virtual_server = abfab-idp
 +}
 +      clients radsec-abfab {
 +              client default {
 +                      ipaddr = 0.0.0.0/0
 +
 +                      proto = tls
 +
++=======
+               cache {
+                       enable = no
+                       lifetime = 24 # hours
+                       max_entries = 255
+               }
+               require_client_cert = yes
+               verify {
+               }
+               psk_query = "%{psksql:select hex(key) from psk_keys where keyid = '%{TLS-PSK-Udentity}'}"
+       }
+       virtual_server = abfab-idp
+       clients = radsec-abfab
+ }
+ clients radsec-abfab {
+       #
+       #  Allow all clients, but require TLS.
+       #
+         client default {
+               ipaddr = 0.0.0.0/0
+               proto = tls
++>>>>>>> v3.0.x
        }
  }
diff --combined src/main/process.c
@@@ -1211,31 -1211,6 +1211,31 @@@ STATE_MACHINE_DECL(request_response_del
        }
  }
  
 +static void retrieve_tls_identity(REQUEST *request)
 +{
 +      /* 
 +       * copy tls identity from sock vps to new request
 +       */
 +      listen_socket_t *sock = NULL;
 +#ifdef WITH_ACCOUNTING
 +      if (request->listener->type != RAD_LISTEN_DETAIL)
 +#endif
 +      {
 +              sock = request->listener->data;
 +      }
 +
 +      if (sock && sock->ssn && sock->ssn->ssl) {
 +              const char *identity = SSL_get_psk_identity(sock->ssn->ssl);
 +              if (identity) {
 +                      RDEBUG("Retrieved psk identity: %s", identity);
 +                      VALUE_PAIR *vp = pairmake_packet("TLS-PSK-Identity", identity, T_OP_SET);
 +                      if (vp) {
 +                              RDEBUG("Set tls-psk-identity: %s", identity);
 +                      }
 +              }
 +      }
 +}
 +
  
  static int CC_HINT(nonnull) request_pre_handler(REQUEST *request, UNUSED int action)
  {
        }
  
        if (!request->packet->vps) { /* FIXME: check for correct state */
 +              retrieve_tls_identity(request);
 +
                rcode = request->listener->decode(request->listener, request);
  
  #ifdef WITH_UNLANG
@@@ -1701,7 -1674,6 +1701,7 @@@ skip_dup
        }
  
        request = request_setup(listener, packet, client, fun);
 +
        if (!request) return 1;
  
        /*
@@@ -2214,7 -2186,7 +2214,7 @@@ static int process_proxy_reply(REQUEST 
        /*
         *      There may be a proxy reply, but it may be too late.
         */
-       if (!request->proxy_listener) return 0;
+       if (!request->home_server->server && !request->proxy_listener) return 0;
  
        /*
         *      Delete any reply we had accumulated until now.
  
        if (reply) {
                VERIFY_PACKET(reply);
-               /*
-                *      Decode the packet.
-                */
-               rcode = request->proxy_listener->decode(request->proxy_listener, request);
-               DEBUG_PACKET(request, reply, 0);
  
                /*
-                *      Pro-actively remove it from the proxy hash.
-                *      This is later than in 2.1.x, but it means that
-                *      the replies are authenticated before being
-                *      removed from the hash.
+                *      Decode the packet if required.
                 */
-               if ((rcode == 0) &&
-                   (request->num_proxied_requests <= request->num_proxied_responses)) {
-                       remove_from_proxy_hash(request);
+               if (request->proxy_listener) {
+                       rcode = request->proxy_listener->decode(request->proxy_listener, request);
+                       DEBUG_PACKET(request, reply, 0);
+                       /*
+                        *      Pro-actively remove it from the proxy hash.
+                        *      This is later than in 2.1.x, but it means that
+                        *      the replies are authenticated before being
+                        *      removed from the hash.
+                        */
+                       if ((rcode == 0) &&
+                           (request->num_proxied_requests <= request->num_proxied_responses)) {
+                               remove_from_proxy_hash(request);
+                       }
+               } else {
+                       rad_assert(!request->in_proxy_hash);
                }
        } else {
                remove_from_proxy_hash(request);
@@@ -4272,6 -4249,7 +4277,7 @@@ static int event_new_fd(rad_listen_t *t
        if (this->status == RAD_LISTEN_STATUS_INIT) {
                listen_socket_t *sock = this->data;
  
+               rad_assert(sock != NULL);
                if (just_started) {
                        DEBUG("Listening on %s", buffer);
  
                 */
                case RAD_LISTEN_PROXY:
  #ifdef WITH_TCP
+                       rad_assert(sock->home != NULL);
                        /*
                         *      Add timers to outgoing child sockets, if necessary.
                         */
diff --combined src/main/realms.c
@@@ -36,7 -36,7 +36,7 @@@ static rbtree_t *realms_byname = NULL
  bool home_servers_udp = false;
  #endif
  
- #ifdef HAVE_REGEX_H
+ #ifdef HAVE_REGEX
  typedef struct realm_regex_t {
        REALM   *realm;
        struct realm_regex_t *next;
@@@ -44,7 -44,7 +44,7 @@@
  
  static realm_regex_t *realms_regex = NULL;
  
- #endif /* HAVE_REGEX_H */
+ #endif /* HAVE_REGEX */
  
  typedef struct realm_config_t {
        CONF_SECTION    *cs;
@@@ -251,7 -251,7 +251,7 @@@ void realms_free(void
        rbtree_free(realms_byname);
        realms_byname = NULL;
  
- #ifdef HAVE_REGEX_H
+ #ifdef HAVE_REGEX
        if (realms_regex) {
                realm_regex_t *this, *next;
  
@@@ -700,6 -700,7 +700,6 @@@ static int home_server_add(realm_config
        return realm_home_server_add(home, cs, dual);
  }
  
 -
  int realm_home_server_add(home_server_t *home, CONF_SECTION *cs, int dual)
  {
        const char *name2 = home->name;
@@@ -1806,8 -1807,11 +1806,11 @@@ static int realm_add(realm_config_t *rc
        return 0;
  }
  
+ #ifdef HAVE_REGEX
  int realm_realm_add(REALM *r, CONF_SECTION *cs)
+ #else
+ int realm_realm_add(REALM *r, UNUSED CONF_SECTION *cs)
+ #endif
  {
        /*
         *      The structs aren't mutex protected.  Refuse to destroy
                return 0;
        }
  
- #ifdef HAVE_REGEX_H
+ #ifdef HAVE_REGEX
        /*
         *      It's a regex.  Sanity check it, and add it to a
         *      separate list.
@@@ -2056,7 -2060,7 +2059,7 @@@ REALM *realm_find2(char const *name
        realm = rbtree_finddata(realms_byname, &myrealm);
        if (realm) return realm;
  
- #ifdef HAVE_REGEX_H
+ #ifdef HAVE_REGEX
        if (realms_regex) {
                realm_regex_t *this;
  
@@@ -2090,7 -2094,7 +2093,7 @@@ REALM *realm_find(char const *name
        realm = rbtree_finddata(realms_byname, &myrealm);
        if (realm) return realm;
  
- #ifdef HAVE_REGEX_H
+ #ifdef HAVE_REGEX
        if (realms_regex) {
                realm_regex_t *this;
  
@@@ -2188,7 -2192,6 +2191,7 @@@ void home_server_update_request(home_se
        request->proxy->proto = home->proto;
  #endif
        request->home_server = home;
 +      talloc_reference(request, request->home_server);
  
        /*
         *      Access-Requests have a Message-Authenticator added,