Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 16 | package org.opencord.aaa.impl; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 17 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 20 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 21 | import static org.slf4j.LoggerFactory.getLogger; |
| 22 | |
| 23 | import com.google.common.collect.Sets; |
| 24 | import java.net.InetAddress; |
| 25 | import java.net.UnknownHostException; |
| 26 | import java.nio.ByteBuffer; |
| 27 | import java.util.Dictionary; |
| 28 | import java.util.HashSet; |
| 29 | import java.util.Arrays; |
| 30 | import java.util.List; |
| 31 | import java.util.Set; |
| 32 | import java.util.Map.Entry; |
| 33 | |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 34 | import org.apache.commons.lang3.builder.ToStringBuilder; |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 35 | import org.onlab.packet.DeserializationException; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 36 | import org.onlab.packet.EAP; |
| 37 | import org.onlab.packet.EAPOL; |
| 38 | import org.onlab.packet.EthType; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 39 | import org.onlab.packet.Ethernet; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 40 | import org.onlab.packet.MacAddress; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 41 | import org.onlab.packet.RADIUS; |
| 42 | import org.onlab.packet.RADIUSAttribute; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 43 | import org.onlab.util.KryoNamespace; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 44 | import org.onlab.util.Tools; |
| 45 | import org.onosproject.cfg.ComponentConfigService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 46 | import org.onosproject.core.ApplicationId; |
| 47 | import org.onosproject.core.CoreService; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 48 | import org.onosproject.event.AbstractListenerManager; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 49 | import org.onosproject.mastership.MastershipService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 50 | import org.onosproject.net.ConnectPoint; |
| 51 | import org.onosproject.net.DeviceId; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 52 | import org.onosproject.net.ElementId; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 53 | import org.onosproject.net.PortNumber; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 54 | import org.onosproject.net.config.ConfigFactory; |
| 55 | import org.onosproject.net.config.NetworkConfigEvent; |
| 56 | import org.onosproject.net.config.NetworkConfigListener; |
| 57 | import org.onosproject.net.config.NetworkConfigRegistry; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 58 | import org.onosproject.net.device.DeviceEvent; |
| 59 | import org.onosproject.net.device.DeviceListener; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 60 | import org.onosproject.net.device.DeviceService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 61 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 62 | import org.onosproject.net.flow.TrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 63 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 64 | import org.onosproject.net.packet.InboundPacket; |
| 65 | import org.onosproject.net.packet.OutboundPacket; |
| 66 | import org.onosproject.net.packet.PacketContext; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 67 | import org.onosproject.net.packet.PacketProcessor; |
| 68 | import org.onosproject.net.packet.PacketService; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 69 | import org.onosproject.store.service.ConsistentMap; |
| 70 | import org.onosproject.store.service.MapEvent; |
| 71 | import org.onosproject.store.service.MapEventListener; |
| 72 | import org.onosproject.store.service.Serializer; |
| 73 | import org.onosproject.store.service.StorageService; |
| 74 | import org.onosproject.store.service.Versioned; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 75 | import org.opencord.aaa.AaaConfig; |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 76 | import org.opencord.aaa.AaaMachineStatisticsEvent; |
| 77 | import org.opencord.aaa.AaaMachineStatisticsService; |
| 78 | import org.opencord.aaa.AaaSupplicantMachineStats; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 79 | import org.opencord.aaa.AuthenticationEvent; |
| 80 | import org.opencord.aaa.AuthenticationEventListener; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 81 | import org.opencord.aaa.AuthenticationRecord; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 82 | import org.opencord.aaa.AuthenticationService; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 83 | import org.opencord.aaa.AuthenticationStatisticsEvent; |
| 84 | import org.opencord.aaa.AuthenticationStatisticsService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 85 | import org.opencord.aaa.RadiusCommunicator; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 86 | import org.opencord.aaa.RadiusOperationalStatusEvent; |
| 87 | import org.opencord.aaa.RadiusOperationalStatusService; |
| 88 | import org.opencord.aaa.RadiusOperationalStatusService.RadiusOperationalStatusEvaluationMode; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 89 | import org.opencord.aaa.StateMachineDelegate; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 90 | import org.opencord.sadis.BaseInformationService; |
| 91 | import org.opencord.sadis.SadisService; |
| 92 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 93 | import org.osgi.service.component.ComponentContext; |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 94 | import org.osgi.service.component.annotations.Activate; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 95 | import org.osgi.service.component.annotations.Component; |
| 96 | import org.osgi.service.component.annotations.Deactivate; |
| 97 | import org.osgi.service.component.annotations.Modified; |
| 98 | import org.osgi.service.component.annotations.Reference; |
| 99 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 100 | import org.slf4j.Logger; |
| 101 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 102 | import javax.crypto.Mac; |
| 103 | import javax.crypto.spec.SecretKeySpec; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 104 | import java.net.URI; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 105 | import java.util.Optional; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 106 | import java.util.concurrent.ConcurrentMap; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 107 | import java.util.concurrent.Executors; |
| 108 | import java.util.concurrent.ScheduledExecutorService; |
| 109 | import java.util.concurrent.ScheduledFuture; |
| 110 | import java.util.concurrent.TimeUnit; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 111 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 112 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_EVENT_GENERATION; |
| 113 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT; |
| 114 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_TIMEOUT; |
| 115 | import static org.opencord.aaa.impl.OsgiPropertyConstants.OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT; |
| 116 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD; |
| 117 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD_DEFAULT; |
| 118 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATUS_SERVER_MODE; |
| 119 | import static org.opencord.aaa.impl.OsgiPropertyConstants.STATUS_SERVER_MODE_DEFAULT; |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 120 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 121 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 122 | * AAA application for ONOS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 123 | */ |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 124 | @Component(immediate = true, property = { |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 125 | STATISTICS_GENERATION_PERIOD + ":Integer=" + STATISTICS_GENERATION_PERIOD_DEFAULT, |
| 126 | OPERATIONAL_STATUS_SERVER_EVENT_GENERATION + ":Integer=" + OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT, |
| 127 | OPERATIONAL_STATUS_SERVER_TIMEOUT + ":Integer=" + OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT, |
| 128 | STATUS_SERVER_MODE + ":String=" + STATUS_SERVER_MODE_DEFAULT, |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 129 | }) |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 130 | public class AaaManager |
| 131 | extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener> |
| 132 | implements AuthenticationService { |
| 133 | |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 134 | private static final String APP_NAME = "org.opencord.aaa"; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 135 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 136 | private final Logger log = getLogger(getClass()); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 137 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 139 | protected CoreService coreService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 140 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 142 | protected StorageService storageService; |
| 143 | |
| 144 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 145 | protected PacketService packetService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 146 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 147 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 148 | protected NetworkConfigRegistry netCfgService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 149 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 150 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 151 | protected DeviceService deviceService; |
| 152 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 153 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 154 | protected SadisService sadisService; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 155 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 156 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 157 | protected MastershipService mastershipService; |
| 158 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 159 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 160 | protected AuthenticationStatisticsService aaaStatisticsManager; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 161 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 162 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 163 | protected AaaMachineStatisticsService aaaSupplicantStatsManager; |
| 164 | |
| 165 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 166 | protected ComponentConfigService cfgService; |
| 167 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 168 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 169 | protected RadiusOperationalStatusService radiusOperationalStatusService; |
| 170 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 171 | protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher; |
| 172 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 173 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 174 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 175 | // Properties |
| 176 | private int statisticsGenerationPeriodInSeconds = STATISTICS_GENERATION_PERIOD_DEFAULT; |
| 177 | private int operationalStatusEventGenerationPeriodInSeconds = OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT; |
| 178 | private int operationalStatusServerTimeoutInSeconds = OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT; |
| 179 | protected String operationalStatusEvaluationMode = STATUS_SERVER_MODE_DEFAULT; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 180 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 181 | private IdentifierManager idManager; |
| 182 | |
| 183 | private ConcurrentMap<String, StateMachine> stateMachines; |
| 184 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 185 | private ConsistentMap<ConnectPoint, AuthenticationRecord> authentications; |
| 186 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 187 | // NAS IP address |
| 188 | protected InetAddress nasIpAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 189 | |
| 190 | // self MAC address |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 191 | protected String nasMacAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 192 | |
| 193 | // Parsed RADIUS server addresses |
| 194 | protected InetAddress radiusIpAddress; |
| 195 | |
| 196 | // MAC address of RADIUS server or net hop router |
| 197 | protected String radiusMacAddress; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 198 | |
| 199 | // RADIUS server secret |
| 200 | protected String radiusSecret; |
| 201 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 202 | // bindings |
| 203 | protected CustomizationInfo customInfo; |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 204 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 205 | // our application-specific event handler |
| 206 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 207 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 208 | // our unique identifier |
| 209 | private ApplicationId appId; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 210 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 211 | // TimeOut time for cleaning up stateMachines stuck due to pending AAA/EAPOL message. |
| 212 | protected int cleanupTimerTimeOutInMins; |
| 213 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 214 | // Setup specific customization/attributes on the RADIUS packets |
| 215 | PacketCustomizer pktCustomizer; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 216 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 217 | // packet customizer to use |
| 218 | private String customizer; |
| 219 | |
| 220 | // Type of connection to use to communicate with Radius server, options are |
| 221 | // "socket" or "packet_out" |
| 222 | private String radiusConnectionType; |
| 223 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 224 | // Object for the specific type of communication with the RADIUS |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 225 | // server, socket based or packet_out based |
| 226 | RadiusCommunicator impl = null; |
| 227 | |
| 228 | // latest configuration |
| 229 | AaaConfig newCfg; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 230 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 231 | ScheduledFuture<?> scheduledFuture; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 232 | ScheduledFuture<?> scheduledStatusServerChecker; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 233 | ScheduledExecutorService executor; |
| 234 | String configuredAaaServerAddress; |
| 235 | HashSet<Byte> outPacketSet = new HashSet<Byte>(); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 236 | HashSet<Byte> outPacketSupp = new HashSet<Byte>(); |
| 237 | static final List<Byte> VALID_EAPOL_TYPE = Arrays.asList(EAPOL.EAPOL_START, EAPOL.EAPOL_LOGOFF, EAPOL.EAPOL_PACKET); |
| 238 | static final int HEADER_LENGTH = 4; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 239 | // Configuration properties factory |
| 240 | private final ConfigFactory factory = |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 241 | new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY, |
| 242 | AaaConfig.class, |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 243 | "AAA") { |
| 244 | @Override |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 245 | public AaaConfig createConfig() { |
| 246 | return new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 247 | } |
| 248 | }; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 249 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 250 | // Listener for config changes |
| 251 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 252 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 253 | private final InternalMapEventListener mapListener = new InternalMapEventListener(); |
| 254 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 255 | private StateMachineDelegate delegate = new InternalStateMachineDelegate(); |
| 256 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 257 | /** |
| 258 | * Builds an EAPOL packet based on the given parameters. |
| 259 | * |
| 260 | * @param dstMac destination MAC address |
| 261 | * @param srcMac source MAC address |
| 262 | * @param vlan vlan identifier |
| 263 | * @param eapolType EAPOL type |
| 264 | * @param eap EAP payload |
| 265 | * @return Ethernet frame |
| 266 | */ |
| 267 | private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 268 | short vlan, byte eapolType, EAP eap, byte priorityCode) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 269 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 270 | Ethernet eth = new Ethernet(); |
| 271 | eth.setDestinationMACAddress(dstMac.toBytes()); |
| 272 | eth.setSourceMACAddress(srcMac.toBytes()); |
| 273 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 274 | if (vlan != Ethernet.VLAN_UNTAGGED) { |
| 275 | eth.setVlanID(vlan); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 276 | eth.setPriorityCode(priorityCode); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 277 | } |
| 278 | //eapol header |
| 279 | EAPOL eapol = new EAPOL(); |
| 280 | eapol.setEapolType(eapolType); |
| 281 | eapol.setPacketLength(eap.getLength()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 282 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 283 | //eap part |
| 284 | eapol.setPayload(eap); |
| 285 | |
| 286 | eth.setPayload(eapol); |
| 287 | eth.setPad(true); |
| 288 | return eth; |
| 289 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 290 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 291 | @Activate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 292 | public void activate(ComponentContext context) { |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 293 | idManager = new IdentifierManager(); |
| 294 | stateMachines = Maps.newConcurrentMap(); |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 295 | appId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 296 | |
| 297 | KryoNamespace authSerializer = KryoNamespace.newBuilder() |
| 298 | .register(byte[].class) |
| 299 | .register(String.class) |
| 300 | .register(long.class) |
| 301 | .register(boolean.class) |
| 302 | .register(URI.class) |
| 303 | .register(DeviceId.class) |
| 304 | .register(ElementId.class) |
| 305 | .register(PortNumber.class) |
| 306 | .register(ConnectPoint.class) |
| 307 | .register(MacAddress.class) |
| 308 | .register(AuthenticationRecord.class) |
| 309 | .build(); |
| 310 | |
| 311 | authentications = storageService.<ConnectPoint, AuthenticationRecord>consistentMapBuilder() |
| 312 | .withApplicationId(appId) |
| 313 | .withName("authentications") |
| 314 | .withSerializer(Serializer.using(authSerializer)) |
| 315 | .build(); |
| 316 | authentications.addListener(mapListener); |
| 317 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 318 | eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 319 | netCfgService.addListener(cfgListener); |
| 320 | netCfgService.registerConfigFactory(factory); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 321 | cfgService.registerProperties(getClass()); |
| 322 | modified(context); |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 323 | subsService = sadisService.getSubscriberInfoService(); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 324 | customInfo = new CustomizationInfo(subsService, deviceService); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 325 | cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class)); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 326 | log.info("Starting with config {} {}", this, newCfg); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 327 | configureRadiusCommunication(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 328 | // register our event handler |
Brian O'Connor | d9c7da0 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 329 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 330 | StateMachine.setDelegate(delegate); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 331 | cleanupTimerTimeOutInMins = newCfg.sessionCleanupTimer(); |
| 332 | StateMachine.setcleanupTimerTimeOutInMins(cleanupTimerTimeOutInMins); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 333 | impl.initializeLocalState(newCfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 334 | impl.requestIntercepts(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 335 | deviceService.addListener(deviceListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 336 | getConfiguredAaaServerAddress(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 337 | radiusOperationalStatusService.initialize(nasIpAddress.getAddress(), radiusSecret, impl); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 338 | authenticationStatisticsPublisher = |
| 339 | new AuthenticationStatisticsEventPublisher(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 340 | executor = Executors.newScheduledThreadPool(3); |
| 341 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 342 | scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher, |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 343 | 0, statisticsGenerationPeriodInSeconds, TimeUnit.SECONDS); |
| 344 | scheduledStatusServerChecker = executor.scheduleAtFixedRate(new ServerStatusChecker(), 0, |
| 345 | operationalStatusEventGenerationPeriodInSeconds, TimeUnit.SECONDS); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 346 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 347 | log.info("Started"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | @Deactivate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 351 | public void deactivate(ComponentContext context) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 352 | impl.withdrawIntercepts(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 353 | packetService.removeProcessor(processor); |
Deepa Vaddireddy | b9c24c6 | 2017-09-21 13:45:30 +0530 | [diff] [blame] | 354 | netCfgService.removeListener(cfgListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 355 | cfgService.unregisterProperties(getClass(), false); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 356 | StateMachine.unsetDelegate(delegate); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 357 | impl.deactivate(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 358 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 359 | eventDispatcher.removeSink(AuthenticationEvent.class); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 360 | scheduledFuture.cancel(true); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 361 | scheduledStatusServerChecker.cancel(true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 362 | executor.shutdown(); |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 363 | |
| 364 | authentications.removeListener(mapListener); |
| 365 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 366 | log.info("Stopped"); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 367 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 368 | @Modified |
| 369 | public void modified(ComponentContext context) { |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 370 | Dictionary<String, Object> properties = context.getProperties(); |
| 371 | |
| 372 | String s = Tools.get(properties, "statisticsGenerationPeriodInSeconds"); |
| 373 | statisticsGenerationPeriodInSeconds = Strings.isNullOrEmpty(s) ? STATISTICS_GENERATION_PERIOD_DEFAULT |
| 374 | : Integer.parseInt(s.trim()); |
| 375 | |
| 376 | s = Tools.get(properties, "operationalStatusEventGenerationPeriodInSeconds"); |
| 377 | operationalStatusEventGenerationPeriodInSeconds = Strings.isNullOrEmpty(s) |
| 378 | ? OPERATIONAL_STATUS_SERVER_EVENT_GENERATION_DEFAULT |
| 379 | : Integer.parseInt(s.trim()); |
| 380 | |
| 381 | s = Tools.get(properties, "operationalStatusServerTimeoutInSeconds"); |
| 382 | operationalStatusServerTimeoutInSeconds = Strings.isNullOrEmpty(s) ? OPERATIONAL_STATUS_SERVER_TIMEOUT_DEFAULT |
| 383 | : Integer.parseInt(s.trim()); |
| 384 | |
| 385 | s = Tools.get(properties, "operationalStatusEvaluationMode"); |
| 386 | String newEvaluationModeString = Strings.isNullOrEmpty(s) ? STATUS_SERVER_MODE_DEFAULT : s.trim(); |
| 387 | |
| 388 | radiusOperationalStatusService |
| 389 | .setOperationalStatusServerTimeoutInMillis(operationalStatusServerTimeoutInSeconds * 1000); |
| 390 | RadiusOperationalStatusEvaluationMode newEvaluationMode = |
| 391 | RadiusOperationalStatusEvaluationMode.getValue(newEvaluationModeString); |
| 392 | if (newEvaluationMode != null) { |
| 393 | radiusOperationalStatusService.setRadiusOperationalStatusEvaluationMode(newEvaluationMode); |
| 394 | operationalStatusEvaluationMode = newEvaluationModeString; |
| 395 | } else { |
| 396 | properties.put("operationalStatusEvaluationMode", operationalStatusEvaluationMode); |
| 397 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Shubham Sharma | cf5e503 | 2019-11-26 11:09:21 +0000 | [diff] [blame] | 400 | protected void configureRadiusCommunication() { |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 401 | if (radiusConnectionType.toLowerCase().equals("socket")) { |
| 402 | impl = new SocketBasedRadiusCommunicator(appId, packetService, this); |
| 403 | } else { |
| 404 | impl = new PortBasedRadiusCommunicator(appId, packetService, mastershipService, |
| 405 | deviceService, subsService, pktCustomizer, this); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | private void configurePacketCustomizer() { |
| 410 | switch (customizer.toLowerCase()) { |
| 411 | case "sample": |
| 412 | pktCustomizer = new SamplePacketCustomizer(customInfo); |
| 413 | log.info("Created SamplePacketCustomizer"); |
| 414 | break; |
Saurav Das | e72358a | 2018-11-13 21:56:46 -0800 | [diff] [blame] | 415 | case "att": |
| 416 | pktCustomizer = new AttPacketCustomizer(customInfo); |
| 417 | log.info("Created AttPacketCustomizer"); |
| 418 | break; |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 419 | default: |
| 420 | pktCustomizer = new PacketCustomizer(customInfo); |
| 421 | log.info("Created default PacketCustomizer"); |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 426 | private void getConfiguredAaaServerAddress() { |
| 427 | try { |
| 428 | InetAddress address; |
| 429 | if (newCfg.radiusHostName() != null) { |
| 430 | address = InetAddress.getByName(newCfg.radiusHostName()); |
| 431 | } else { |
| 432 | address = newCfg.radiusIp(); |
| 433 | } |
| 434 | |
| 435 | configuredAaaServerAddress = address.getHostAddress(); |
| 436 | } catch (UnknownHostException uhe) { |
| 437 | log.warn("Unable to resolve host {}", newCfg.radiusHostName()); |
| 438 | } |
| 439 | } |
| 440 | |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 441 | private void checkReceivedPacketForValidValidator(RADIUS radiusPacket, byte[] requestAuthenticator) { |
| 442 | if (!checkResponseMessageAuthenticator(radiusSecret, radiusPacket, requestAuthenticator)) { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 443 | aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx(); |
| 444 | } |
| 445 | } |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 446 | |
| 447 | private boolean checkResponseMessageAuthenticator(String key, RADIUS radiusPacket, byte[] requestAuthenticator) { |
| 448 | byte[] newHash = new byte[16]; |
| 449 | Arrays.fill(newHash, (byte) 0); |
| 450 | byte[] messageAuthenticator = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH).getValue(); |
| 451 | byte[] authenticator = radiusPacket.getAuthenticator(); |
| 452 | radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, newHash); |
| 453 | radiusPacket.setAuthenticator(requestAuthenticator); |
| 454 | // Calculate the MD5 HMAC based on the message |
| 455 | try { |
| 456 | SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacMD5"); |
| 457 | Mac mac = Mac.getInstance("HmacMD5"); |
| 458 | mac.init(keySpec); |
| 459 | newHash = mac.doFinal(radiusPacket.serialize()); |
| 460 | } catch (Exception e) { |
| 461 | log.error("Failed to generate message authenticator: {}", e.getMessage()); |
| 462 | } |
| 463 | radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, messageAuthenticator); |
| 464 | radiusPacket.setAuthenticator(authenticator); |
| 465 | // Compare the calculated Message-Authenticator with the one in the message |
| 466 | return Arrays.equals(newHash, messageAuthenticator); |
| 467 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 468 | public void checkForPacketFromUnknownServer(String hostAddress) { |
| 469 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
Vijaykumar Kushwaha | fffd3d1 | 2019-08-01 11:09:59 +0000 | [diff] [blame] | 470 | getConfiguredAaaServerAddress(); |
| 471 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
| 472 | aaaStatisticsManager.getAaaStats().incrementUnknownServerRx(); |
| 473 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 477 | /** |
| 478 | * Send RADIUS packet to the RADIUS server. |
| 479 | * |
| 480 | * @param radiusPacket RADIUS packet to be sent to server. |
| 481 | * @param inPkt Incoming EAPOL packet |
| 482 | */ |
| 483 | protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 484 | outPacketSet.add(radiusPacket.getIdentifier()); |
| 485 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true); |
| 486 | aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 487 | aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 488 | impl.sendRadiusPacket(radiusPacket, inPkt); |
| 489 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 490 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 491 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 492 | * Handles RADIUS packets. |
| 493 | * |
| 494 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 495 | * @throws DeserializationException if packet deserialization fails |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 496 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 497 | public void handleRadiusPacket(RADIUS radiusPacket) throws DeserializationException { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 498 | if (log.isTraceEnabled()) { |
| 499 | log.trace("Received RADIUS packet {}", radiusPacket); |
| 500 | } |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 501 | if (radiusOperationalStatusService.isRadiusResponseForOperationalStatus(radiusPacket.getIdentifier())) { |
| 502 | radiusOperationalStatusService.handleRadiusPacketForOperationalStatus(radiusPacket); |
| 503 | return; |
| 504 | } |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 505 | |
| 506 | RequestIdentifier identifier = RequestIdentifier.of(radiusPacket.getIdentifier()); |
| 507 | String sessionId = idManager.getSessionId(identifier); |
| 508 | |
| 509 | if (sessionId == null) { |
| 510 | log.error("Invalid packet identifier {}, could not find corresponding " |
| 511 | + "state machine ... exiting", radiusPacket.getIdentifier()); |
| 512 | aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired(); |
| 513 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | idManager.releaseIdentifier(identifier); |
| 518 | StateMachine stateMachine = stateMachines.get(sessionId); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 519 | if (stateMachine == null) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 520 | log.error("Invalid packet identifier {}, could not find corresponding " |
| 521 | + "state machine ... exiting", radiusPacket.getIdentifier()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 522 | aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired(); |
| 523 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 524 | return; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 525 | } |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 526 | |
| 527 | //instance of StateMachine using the sessionId for updating machine stats |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 528 | StateMachine machineStats = stateMachines.get(stateMachine.sessionId()); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 529 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 530 | EAP eapPayload; |
| 531 | Ethernet eth; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 532 | checkReceivedPacketForValidValidator(radiusPacket, stateMachine.requestAuthenticator()); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 533 | |
| 534 | //increasing packets and octets received from server |
| 535 | machineStats.incrementTotalPacketsReceived(); |
| 536 | machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength()); |
| 537 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 538 | if (outPacketSet.contains(radiusPacket.getIdentifier())) { |
| 539 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false); |
| 540 | outPacketSet.remove(new Byte(radiusPacket.getIdentifier())); |
| 541 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 542 | switch (radiusPacket.getCode()) { |
| 543 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 544 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 545 | RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE); |
| 546 | byte[] challengeState = null; |
| 547 | if (radiusAttrState != null) { |
| 548 | challengeState = radiusAttrState.getValue(); |
| 549 | } |
| 550 | eapPayload = radiusPacket.decapsulateMessage(); |
| 551 | stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); |
| 552 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 553 | MacAddress.valueOf(nasMacAddress), |
| 554 | stateMachine.vlanId(), |
| 555 | EAPOL.EAPOL_PACKET, |
| 556 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 557 | log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 558 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 559 | aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx(); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 560 | outPacketSupp.add(eapPayload.getIdentifier()); |
| 561 | aaaStatisticsManager.getAaaStats().incrementPendingResSupp(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 562 | //increasing packets send to server |
| 563 | machineStats.incrementTotalPacketsSent(); |
| 564 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 565 | break; |
| 566 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 567 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 568 | //send an EAPOL - Success to the supplicant. |
| 569 | byte[] eapMessageSuccess = |
| 570 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 571 | eapPayload = EAP.deserializer().deserialize( |
| 572 | eapMessageSuccess, 0, eapMessageSuccess.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 573 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 574 | MacAddress.valueOf(nasMacAddress), |
| 575 | stateMachine.vlanId(), |
| 576 | EAPOL.EAPOL_PACKET, |
| 577 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 578 | log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 579 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 580 | aaaStatisticsManager.getAaaStats().incrementEapolAuthSuccessTrans(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 581 | |
| 582 | stateMachine.authorizeAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 583 | aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 584 | //increasing packets send to server |
| 585 | machineStats.incrementTotalPacketsSent(); |
| 586 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 587 | break; |
| 588 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 589 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 590 | //send an EAPOL - Failure to the supplicant. |
| 591 | byte[] eapMessageFailure; |
| 592 | eapPayload = new EAP(); |
| 593 | RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE); |
| 594 | if (radiusAttrEap == null) { |
| 595 | eapPayload.setCode(EAP.FAILURE); |
| 596 | eapPayload.setIdentifier(stateMachine.challengeIdentifier()); |
| 597 | eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL); |
| 598 | } else { |
| 599 | eapMessageFailure = radiusAttrEap.getValue(); |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 600 | eapPayload = EAP.deserializer().deserialize( |
| 601 | eapMessageFailure, 0, eapMessageFailure.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 602 | } |
| 603 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 604 | MacAddress.valueOf(nasMacAddress), |
| 605 | stateMachine.vlanId(), |
| 606 | EAPOL.EAPOL_PACKET, |
| 607 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 608 | log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 609 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 610 | aaaStatisticsManager.getAaaStats().incrementEapolauthFailureTrans(); |
| 611 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 612 | stateMachine.denyAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 613 | aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 614 | //increasing packets send to server |
| 615 | machineStats.incrementTotalPacketsSent(); |
| 616 | machineStats.incrementTotalOctetSent(eapPayload.getLength()); |
| 617 | //pushing machine stats to kafka |
| 618 | AaaSupplicantMachineStats machineObj = aaaSupplicantStatsManager.getSupplicantStats(machineStats); |
| 619 | aaaSupplicantStatsManager.getMachineStatsDelegate() |
| 620 | .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, machineObj)); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 621 | break; |
| 622 | default: |
| 623 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 624 | aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 625 | //increasing packets received to server |
| 626 | machineStats.incrementTotalPacketsReceived(); |
| 627 | machineStats.incrementTotalOctetReceived(radiusPacket.decapsulateMessage().getLength()); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 628 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 629 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 632 | /** |
| 633 | * Send the ethernet packet to the supplicant. |
| 634 | * |
| 635 | * @param ethernetPkt the ethernet packet |
| 636 | * @param connectPoint the connect point to send out |
| 637 | */ |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 638 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint, boolean isChallengeResponse) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 639 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 640 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), |
| 641 | treatment, ByteBuffer.wrap(ethernetPkt.serialize())); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 642 | EAPOL eap = ((EAPOL) ethernetPkt.getPayload()); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 643 | if (log.isTraceEnabled()) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 644 | log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}", |
| 645 | eap, ethernetPkt, connectPoint); |
| 646 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 647 | packetService.emit(packet); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 648 | if (isChallengeResponse) { |
| 649 | aaaStatisticsManager.getAaaStats().incrementEapPktTxauthEap(); |
| 650 | } |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 651 | aaaStatisticsManager.getAaaStats().incrementEapolFramesTx(); |
| 652 | aaaStatisticsManager.getAaaStats().countReqEapFramesTx(); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 655 | @Override |
| 656 | public String toString() { |
| 657 | return ToStringBuilder.reflectionToString(this); |
| 658 | } |
| 659 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 660 | @Override |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 661 | public Iterable<AuthenticationRecord> getAuthenticationRecords() { |
| 662 | return authentications.asJavaMap().values(); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public boolean removeAuthenticationStateByMac(MacAddress mac) { |
| 667 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 668 | Optional<Versioned<AuthenticationRecord>> r = authentications.values().stream() |
| 669 | .filter(v -> v.value().supplicantAddress().equals(mac)) |
| 670 | .findFirst(); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 671 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 672 | if (r.isEmpty()) { |
| 673 | return false; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 676 | Versioned<AuthenticationRecord> removed = |
| 677 | authentications.remove(r.get().value().supplicantConnectPoint()); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 678 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 679 | return removed != null; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 682 | StateMachine getStateMachine(String sessionId) { |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 683 | return stateMachines.get(sessionId); |
| 684 | } |
| 685 | |
| 686 | private String sessionId(ConnectPoint cp) { |
| 687 | return cp.deviceId().toString() + cp.port().toString(); |
| 688 | } |
| 689 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 690 | // our handler defined as a private inner class |
| 691 | |
| 692 | /** |
| 693 | * Packet processor responsible for forwarding packets along their paths. |
| 694 | */ |
| 695 | private class ReactivePacketProcessor implements PacketProcessor { |
| 696 | @Override |
| 697 | public void process(PacketContext context) { |
| 698 | |
| 699 | // Extract the original Ethernet frame from the packet information |
| 700 | InboundPacket pkt = context.inPacket(); |
| 701 | Ethernet ethPkt = pkt.parsed(); |
| 702 | if (ethPkt == null) { |
| 703 | return; |
| 704 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 705 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 706 | // identify if incoming packet comes from supplicant (EAP) or RADIUS |
| 707 | switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { |
| 708 | case EAPOL: |
| 709 | handleSupplicantPacket(context.inPacket()); |
| 710 | break; |
| 711 | default: |
| 712 | // any other packets let the specific implementation handle |
| 713 | impl.handlePacketFromServer(context); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 717 | /** |
| 718 | * Creates and initializes common fields of a RADIUS packet. |
| 719 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 720 | * @param stateMachine state machine for the request |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 721 | * @param eapPacket EAP packet |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 722 | * @return RADIUS packet |
| 723 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 724 | private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 725 | RADIUS radiusPayload = |
| 726 | new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
| 727 | eapPacket.getIdentifier()); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 728 | |
| 729 | // set Request Authenticator in StateMachine |
| 730 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
| 731 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 732 | radiusPayload.setIdentifier(identifier); |
| 733 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 734 | stateMachine.username()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 735 | |
| 736 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 737 | AaaManager.this.nasIpAddress.getAddress()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 738 | |
| 739 | radiusPayload.encapsulateMessage(eapPacket); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 740 | |
| 741 | return radiusPayload; |
| 742 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 743 | |
| 744 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 745 | * Handles PAE packets (supplicant). |
| 746 | * |
| 747 | * @param inPacket Ethernet packet coming from the supplicant |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 748 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 749 | private void handleSupplicantPacket(InboundPacket inPacket) { |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 750 | Ethernet ethPkt = inPacket.parsed(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 751 | // Where does it come from? |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 752 | MacAddress srcMac = ethPkt.getSourceMAC(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 753 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 754 | DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
| 755 | PortNumber portNumber = inPacket.receivedFrom().port(); |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 756 | String sessionId = sessionId(inPacket.receivedFrom()); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 757 | EAPOL eapol = (EAPOL) ethPkt.getPayload(); |
| 758 | if (log.isTraceEnabled()) { |
| 759 | log.trace("Received EAPOL packet {} in enclosing packet {} from " |
| 760 | + "dev/port: {}/{}", eapol, ethPkt, deviceId, |
| 761 | portNumber); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 762 | } |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 763 | |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 764 | short pktlen = eapol.getPacketLength(); |
| 765 | byte[] eapPayLoadBuffer = eapol.serialize(); |
| 766 | int len = eapPayLoadBuffer.length; |
| 767 | if (len != (HEADER_LENGTH + pktlen)) { |
| 768 | aaaStatisticsManager.getAaaStats().incrementInvalidBodyLength(); |
| 769 | return; |
| 770 | } |
| 771 | if (!VALID_EAPOL_TYPE.contains(eapol.getEapolType())) { |
| 772 | aaaStatisticsManager.getAaaStats().incrementInvalidPktType(); |
| 773 | return; |
| 774 | } |
| 775 | if (pktlen >= 0 && ethPkt.getEtherType() == EthType.EtherType.EAPOL.ethType().toShort()) { |
| 776 | aaaStatisticsManager.getAaaStats().incrementValidEapolFramesRx(); |
| 777 | } |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 778 | |
| 779 | StateMachine stateMachine = stateMachines.computeIfAbsent(sessionId, id -> new StateMachine(id, executor)); |
| 780 | stateMachine.setEapolTypeVal(eapol.getEapolType()); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 781 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 782 | switch (eapol.getEapolType()) { |
| 783 | case EAPOL.EAPOL_START: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 784 | log.debug("EAP packet: EAPOL_START"); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 785 | stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 786 | stateMachine.setSupplicantAddress(srcMac); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 787 | stateMachine.start(); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 788 | |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 789 | aaaStatisticsManager.getAaaStats().incrementEapolStartReqTrans(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 790 | //send an EAP Request/Identify to the supplicant |
| 791 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 792 | if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
| 793 | stateMachine.setPriorityCode(ethPkt.getPriorityCode()); |
| 794 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 795 | Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress), |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 796 | ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 797 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 798 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 799 | stateMachine.setVlanId(ethPkt.getVlanID()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 800 | log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 801 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 802 | aaaStatisticsManager.getAaaStats().incrementRequestIdFramesTx(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 803 | |
| 804 | break; |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 805 | case EAPOL.EAPOL_LOGOFF: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 806 | log.debug("EAP packet: EAPOL_LOGOFF"); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 807 | //posting the machine stat data for current supplicant device. |
| 808 | if (stateMachine.getSessionTerminateReason() == null || |
| 809 | stateMachine.getSessionTerminateReason().equals("")) { |
| 810 | stateMachine.setSessionTerminateReason( |
| 811 | StateMachine.SessionTerminationReasons.SUPPLICANT_LOGOFF.getReason()); |
| 812 | } |
| 813 | AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine); |
| 814 | aaaSupplicantStatsManager.getMachineStatsDelegate() |
| 815 | .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj)); |
Ray Milkey | b34b496 | 2016-01-04 10:24:43 -0800 | [diff] [blame] | 816 | if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) { |
| 817 | stateMachine.logoff(); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 818 | aaaStatisticsManager.getAaaStats().incrementEapolLogoffRx(); |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 819 | } |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 820 | if (stateMachine.state() == StateMachine.STATE_IDLE) { |
| 821 | aaaStatisticsManager.getAaaStats().incrementAuthStateIdle(); |
| 822 | } |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 823 | |
| 824 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 825 | case EAPOL.EAPOL_PACKET: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 826 | RADIUS radiusPayload; |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 827 | // check if this is a Response/Identify or a Response/TLS |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 828 | EAP eapPacket = (EAP) eapol.getPayload(); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 829 | Byte identifier = new Byte(eapPacket.getIdentifier()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 830 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 831 | // get identifier for request and store mapping to session ID |
| 832 | RequestIdentifier radiusIdentifier = idManager.getNewIdentifier(sessionId); |
| 833 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 834 | byte dataType = eapPacket.getDataType(); |
| 835 | switch (dataType) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 836 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 837 | case EAP.ATTR_IDENTITY: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 838 | log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY"); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 839 | //Setting the time of this response from RG, only when its not a re-transmission. |
| 840 | if (stateMachine.getLastPacketReceivedTime() == 0) { |
| 841 | stateMachine.setLastPacketReceivedTime(System.currentTimeMillis()); |
| 842 | } |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 843 | // request id access to RADIUS |
| 844 | stateMachine.setUsername(eapPacket.getData()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 845 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 846 | radiusPayload = getRadiusPayload(stateMachine, radiusIdentifier.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 847 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 848 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 849 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 850 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 851 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 852 | aaaStatisticsManager.getAaaStats().incrementEapolAtrrIdentity(); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 853 | // change the state to "PENDING" |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 854 | if (stateMachine.state() == StateMachine.STATE_PENDING) { |
| 855 | aaaStatisticsManager.getAaaStats().increaseRequestReTx(); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 856 | stateMachine.incrementTotalPacketsSent(); |
| 857 | stateMachine.incrementTotalOctetSent(eapol.getPacketLength()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 858 | } |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 859 | stateMachine.requestAccess(); |
| 860 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 861 | case EAP.ATTR_MD5: |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 862 | stateMachine.setLastPacketReceivedTime(System.currentTimeMillis()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 863 | log.debug("EAP packet: EAPOL_PACKET ATTR_MD5"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 864 | // verify if the EAP identifier corresponds to the |
| 865 | // challenge identifier from the client state |
| 866 | // machine. |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 867 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 868 | //send the RADIUS challenge response |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 869 | radiusPayload = getRadiusPayload(stateMachine, |
| 870 | radiusIdentifier.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 871 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 872 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 873 | if (stateMachine.challengeState() != null) { |
| 874 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 875 | stateMachine.challengeState()); |
| 876 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 877 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 878 | if (outPacketSupp.contains(eapPacket.getIdentifier())) { |
| 879 | aaaStatisticsManager.getAaaStats().decrementPendingResSupp(); |
| 880 | outPacketSupp.remove(identifier); |
| 881 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 882 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 883 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 884 | aaaStatisticsManager.getAaaStats().incrementEapolMd5RspChall(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 885 | } |
| 886 | break; |
| 887 | case EAP.ATTR_TLS: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 888 | log.debug("EAP packet: EAPOL_PACKET ATTR_TLS"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 889 | // request id access to RADIUS |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 890 | radiusPayload = getRadiusPayload(stateMachine, radiusIdentifier.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 891 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 892 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 893 | if (stateMachine.challengeState() != null) { |
| 894 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 895 | stateMachine.challengeState()); |
| 896 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 897 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 898 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 899 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 900 | if (outPacketSupp.contains(eapPacket.getIdentifier())) { |
| 901 | aaaStatisticsManager.getAaaStats().decrementPendingResSupp(); |
| 902 | outPacketSupp.remove(identifier); |
| 903 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 904 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 905 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 906 | aaaStatisticsManager.getAaaStats().incrementEapolTlsRespChall(); |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 907 | |
Ray Milkey | f3790b8 | 2015-10-21 16:28:08 -0700 | [diff] [blame] | 908 | if (stateMachine.state() != StateMachine.STATE_PENDING) { |
| 909 | stateMachine.requestAccess(); |
| 910 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 911 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 912 | break; |
| 913 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 914 | log.warn("Unknown EAP packet type"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 915 | return; |
| 916 | } |
| 917 | break; |
| 918 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 919 | log.debug("Skipping EAPOL message {}", eapol.getEapolType()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 920 | } |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 921 | aaaStatisticsManager.getAaaStats().countTransRespNotNak(); |
| 922 | aaaStatisticsManager.getAaaStats().countEapolResIdentityMsgTrans(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 923 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 926 | /** |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 927 | * Delegate allowing the StateMachine to notify us of events. |
| 928 | */ |
| 929 | private class InternalStateMachineDelegate implements StateMachineDelegate { |
| 930 | |
| 931 | @Override |
| 932 | public void notify(AuthenticationEvent authenticationEvent) { |
| 933 | log.info("Auth event {} for {}", |
| 934 | authenticationEvent.type(), authenticationEvent.subject()); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 935 | |
| 936 | if (authenticationEvent.type() == AuthenticationEvent.Type.TIMEOUT) { |
| 937 | handleStateMachineTimeout(authenticationEvent.subject()); |
| 938 | } |
| 939 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 940 | AuthenticationRecord record = authenticationEvent.authenticationRecord(); |
| 941 | if (record == null) { |
| 942 | authentications.remove(authenticationEvent.subject()); |
| 943 | } else { |
| 944 | authentications.put(authenticationEvent.subject(), record); |
| 945 | } |
| 946 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 947 | post(authenticationEvent); |
| 948 | } |
| 949 | } |
| 950 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 951 | private void handleStateMachineTimeout(ConnectPoint supplicantConnectPoint) { |
| 952 | StateMachine stateMachine = stateMachines.remove(sessionId(supplicantConnectPoint)); |
| 953 | |
Andrea Campanella | e66466a | 2020-02-03 14:05:45 +0000 | [diff] [blame] | 954 | //pushing captured machine stats to kafka |
| 955 | stateMachine.setSessionTerminateReason("Time out"); |
| 956 | AaaSupplicantMachineStats obj = aaaSupplicantStatsManager |
| 957 | .getSupplicantStats(stateMachine); |
| 958 | aaaSupplicantStatsManager.getMachineStatsDelegate() |
| 959 | .notify(new AaaMachineStatisticsEvent( |
| 960 | AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj)); |
| 961 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 962 | if (stateMachine.state() == StateMachine.STATE_PENDING && stateMachine.isWaitingForRadiusResponse()) { |
| 963 | aaaStatisticsManager.getAaaStats().increaseTimedOutPackets(); |
| 964 | } |
| 965 | |
| 966 | StateMachine.deleteStateMachineMapping(stateMachine); |
| 967 | } |
| 968 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 969 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 970 | * Configuration Listener, handles change in configuration. |
| 971 | */ |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 972 | private class InternalConfigListener implements NetworkConfigListener { |
| 973 | |
| 974 | /** |
Ray Milkey | c9e8dcc | 2015-12-30 10:31:32 -0800 | [diff] [blame] | 975 | * Reconfigures the AAA application according to the |
| 976 | * configuration parameters passed. |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 977 | * |
| 978 | * @param cfg configuration object |
| 979 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 980 | private void reconfigureNetwork(AaaConfig cfg) { |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 981 | log.info("Reconfiguring AaaConfig from config: {}", cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 982 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 983 | if (cfg == null) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 984 | newCfg = new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 985 | } else { |
| 986 | newCfg = cfg; |
| 987 | } |
| 988 | if (newCfg.nasIp() != null) { |
| 989 | nasIpAddress = newCfg.nasIp(); |
| 990 | } |
| 991 | if (newCfg.radiusIp() != null) { |
| 992 | radiusIpAddress = newCfg.radiusIp(); |
| 993 | } |
| 994 | if (newCfg.radiusMac() != null) { |
| 995 | radiusMacAddress = newCfg.radiusMac(); |
| 996 | } |
| 997 | if (newCfg.nasMac() != null) { |
| 998 | nasMacAddress = newCfg.nasMac(); |
| 999 | } |
| 1000 | if (newCfg.radiusSecret() != null) { |
| 1001 | radiusSecret = newCfg.radiusSecret(); |
| 1002 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 1003 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 1004 | boolean reconfigureCustomizer = false; |
| 1005 | if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) { |
| 1006 | customizer = newCfg.radiusPktCustomizer(); |
| 1007 | configurePacketCustomizer(); |
| 1008 | reconfigureCustomizer = true; |
| 1009 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 1010 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 1011 | if (radiusConnectionType == null |
| 1012 | || reconfigureCustomizer |
| 1013 | || !radiusConnectionType.equals(newCfg.radiusConnectionType())) { |
| 1014 | radiusConnectionType = newCfg.radiusConnectionType(); |
| 1015 | if (impl != null) { |
| 1016 | impl.withdrawIntercepts(); |
| 1017 | impl.clearLocalState(); |
| 1018 | } |
| 1019 | configureRadiusCommunication(); |
| 1020 | impl.initializeLocalState(newCfg); |
| 1021 | impl.requestIntercepts(); |
| 1022 | } else if (impl != null) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 1023 | impl.clearLocalState(); |
| 1024 | impl.initializeLocalState(newCfg); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 1025 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | @Override |
| 1029 | public void event(NetworkConfigEvent event) { |
| 1030 | |
| 1031 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 1032 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 1033 | event.configClass().equals(AaaConfig.class)) { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 1034 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 1035 | AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 1036 | reconfigureNetwork(cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 1037 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 1038 | log.info("Reconfigured: {}", cfg.toString()); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | } |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1042 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 1043 | private class InternalMapEventListener implements MapEventListener<ConnectPoint, AuthenticationRecord> { |
| 1044 | @Override |
| 1045 | public void event(MapEvent<ConnectPoint, AuthenticationRecord> event) { |
| 1046 | if (event.type() == MapEvent.Type.REMOVE) { |
| 1047 | // remove local state machine if user has requested remove |
| 1048 | StateMachine sm = stateMachines.remove(sessionId(event.key())); |
| 1049 | if (sm != null) { |
| 1050 | sm.stop(); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1056 | private class InternalDeviceListener implements DeviceListener { |
| 1057 | @Override |
| 1058 | public void event(DeviceEvent event) { |
Andrea Campanella | bba3367 | 2020-02-11 14:03:01 +0100 | [diff] [blame^] | 1059 | DeviceId deviceId = event.subject().id(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1060 | switch (event.type()) { |
| 1061 | case PORT_REMOVED: |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1062 | PortNumber portNumber = event.port().number(); |
Andrea Campanella | bba3367 | 2020-02-11 14:03:01 +0100 | [diff] [blame^] | 1063 | String sessionId = deviceId.toString() + portNumber.toString(); |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1064 | log.debug("Received PORT_REMOVED event. Clearing AAA Session with Id {}", sessionId); |
| 1065 | flushStateMachineSession(sessionId, |
| 1066 | StateMachine.SessionTerminationReasons.PORT_REMOVED.getReason()); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 1067 | |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1068 | break; |
Andrea Campanella | bba3367 | 2020-02-11 14:03:01 +0100 | [diff] [blame^] | 1069 | case DEVICE_AVAILABILITY_CHANGED: |
| 1070 | if (!deviceService.isAvailable(deviceId)) { |
| 1071 | log.debug("Received DEVICE_AVAILABILITY_CHANGED event for {}, " + |
| 1072 | "went available to un-available", deviceId); |
| 1073 | clearAllSessionStateForDevice(deviceId); |
| 1074 | } |
| 1075 | break; |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1076 | case DEVICE_REMOVED: |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1077 | log.debug("Received DEVICE_REMOVED event for {}", deviceId); |
Andrea Campanella | bba3367 | 2020-02-11 14:03:01 +0100 | [diff] [blame^] | 1078 | clearAllSessionStateForDevice(deviceId); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1079 | break; |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1080 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1081 | default: |
| 1082 | return; |
| 1083 | } |
| 1084 | } |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1085 | |
Andrea Campanella | bba3367 | 2020-02-11 14:03:01 +0100 | [diff] [blame^] | 1086 | private void clearAllSessionStateForDevice(DeviceId deviceId) { |
| 1087 | Set<String> associatedSessions = Sets.newHashSet(); |
| 1088 | for (Entry<String, StateMachine> stateMachineEntry : stateMachines.entrySet()) { |
| 1089 | ConnectPoint cp = stateMachineEntry.getValue().supplicantConnectpoint(); |
| 1090 | if (cp != null && cp.deviceId().toString().equals(deviceId.toString())) { |
| 1091 | associatedSessions.add(stateMachineEntry.getKey()); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | for (String session : associatedSessions) { |
| 1096 | log.debug("Clearing AAA Session {} associated with Removed Device", session); |
| 1097 | flushStateMachineSession(session, |
| 1098 | StateMachine.SessionTerminationReasons.DEVICE_REMOVED.getReason()); |
| 1099 | } |
| 1100 | } |
| 1101 | |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1102 | private void flushStateMachineSession(String sessionId, String terminationReason) { |
| 1103 | StateMachine stateMachine = stateMachines.get(sessionId); |
| 1104 | if (stateMachine != null) { |
| 1105 | stateMachine.setSessionTerminateReason(terminationReason); |
| 1106 | } |
| 1107 | |
| 1108 | //pushing captured machine stats to kafka |
| 1109 | AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine); |
| 1110 | aaaSupplicantStatsManager.getMachineStatsDelegate() |
| 1111 | .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj)); |
| 1112 | |
| 1113 | StateMachine removed = stateMachines.remove(sessionId); |
| 1114 | if (removed != null) { |
| 1115 | StateMachine.deleteStateMachineMapping(removed); |
| 1116 | } |
| 1117 | } |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 1118 | } |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 1119 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1120 | private class AuthenticationStatisticsEventPublisher implements Runnable { |
| 1121 | private final Logger log = getLogger(getClass()); |
| 1122 | public void run() { |
| 1123 | log.info("Notifying AuthenticationStatisticsEvent"); |
| 1124 | aaaStatisticsManager.calculatePacketRoundtripTime(); |
| 1125 | log.debug("AcceptResponsesRx---" + aaaStatisticsManager.getAaaStats().getAcceptResponsesRx()); |
| 1126 | log.debug("AccessRequestsTx---" + aaaStatisticsManager.getAaaStats().getAccessRequestsTx()); |
| 1127 | log.debug("ChallengeResponsesRx---" + aaaStatisticsManager.getAaaStats().getChallengeResponsesRx()); |
| 1128 | log.debug("DroppedResponsesRx---" + aaaStatisticsManager.getAaaStats().getDroppedResponsesRx()); |
| 1129 | log.debug("InvalidValidatorsRx---" + aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx()); |
| 1130 | log.debug("MalformedResponsesRx---" + aaaStatisticsManager.getAaaStats().getMalformedResponsesRx()); |
| 1131 | log.debug("PendingRequests---" + aaaStatisticsManager.getAaaStats().getPendingRequests()); |
| 1132 | log.debug("RejectResponsesRx---" + aaaStatisticsManager.getAaaStats().getRejectResponsesRx()); |
| 1133 | log.debug("RequestReTx---" + aaaStatisticsManager.getAaaStats().getRequestReTx()); |
| 1134 | log.debug("RequestRttMilis---" + aaaStatisticsManager.getAaaStats().getRequestRttMilis()); |
| 1135 | log.debug("UnknownServerRx---" + aaaStatisticsManager.getAaaStats().getUnknownServerRx()); |
| 1136 | log.debug("UnknownTypeRx---" + aaaStatisticsManager.getAaaStats().getUnknownTypeRx()); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 1137 | log.debug("TimedOutPackets----" + aaaStatisticsManager.getAaaStats().getTimedOutPackets()); |
Shubham Sharma | 1f19358 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 1138 | log.debug("EapolLogoffRx---" + aaaStatisticsManager.getAaaStats().getEapolLogoffRx()); |
| 1139 | log.debug("EapolAuthSuccessTrans---" + aaaStatisticsManager.getAaaStats().getEapolAuthSuccessTrans()); |
| 1140 | log.debug("EapolAuthFailureTrans---" + |
| 1141 | aaaStatisticsManager.getAaaStats().getEapolAuthFailureTrans()); |
| 1142 | log.debug("EapolStartReqTrans---" + |
| 1143 | aaaStatisticsManager.getAaaStats().getEapolStartReqTrans()); |
| 1144 | log.debug("EapolTransRespNotNak---" + |
| 1145 | aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak()); |
| 1146 | log.debug("EapPktTxauthChooseEap---" + |
| 1147 | aaaStatisticsManager.getAaaStats().getEapPktTxauthChooseEap()); |
| 1148 | log.debug("EapolResIdentityMsgTrans---" + |
| 1149 | aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans()); |
Shubham Sharma | 3c8c702 | 2019-09-13 10:39:47 +0000 | [diff] [blame] | 1150 | log.debug("EapolFramesTx---" + aaaStatisticsManager.getAaaStats().getEapolFramesTx()); |
| 1151 | log.debug("AuthStateIdle---" + aaaStatisticsManager.getAaaStats().getAuthStateIdle()); |
| 1152 | log.debug("RequestIdFramesTx---" + aaaStatisticsManager.getAaaStats().getRequestIdFramesTx()); |
| 1153 | log.debug("ReqEapFramesTx---" + aaaStatisticsManager.getAaaStats().getReqEapFramesTx()); |
| 1154 | log.debug("InvalidPktType---" + aaaStatisticsManager.getAaaStats().getInvalidPktType()); |
| 1155 | log.debug("InvalidBodyLength---" + aaaStatisticsManager.getAaaStats().getInvalidBodyLength()); |
| 1156 | log.debug("ValidEapolFramesRx---" + aaaStatisticsManager.getAaaStats().getValidEapolFramesRx()); |
| 1157 | log.debug("PendingResSupp---" + aaaStatisticsManager.getAaaStats().getPendingResSupp()); |
| 1158 | log.debug("ResIdEapFramesRx---" + aaaStatisticsManager.getAaaStats().getEapolattrIdentity()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1159 | aaaStatisticsManager.getStatsDelegate(). |
| 1160 | notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE, |
| 1161 | aaaStatisticsManager.getAaaStats())); |
| 1162 | } |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | private class ServerStatusChecker implements Runnable { |
| 1166 | @Override |
| 1167 | public void run() { |
Matteo Scandolo | 3498bc0 | 2020-01-08 09:54:12 -0800 | [diff] [blame] | 1168 | log.debug("Notifying RadiusOperationalStatusEvent"); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1169 | radiusOperationalStatusService.checkServerOperationalStatus(); |
Matteo Scandolo | 3498bc0 | 2020-01-08 09:54:12 -0800 | [diff] [blame] | 1170 | log.trace("--POSTING--" + radiusOperationalStatusService.getRadiusServerOperationalStatus()); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1171 | radiusOperationalStatusService.getRadiusOprStDelegate() |
| 1172 | .notify(new RadiusOperationalStatusEvent( |
| 1173 | RadiusOperationalStatusEvent.Type.RADIUS_OPERATIONAL_STATUS, |
| 1174 | radiusOperationalStatusService. |
| 1175 | getRadiusServerOperationalStatus())); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 1176 | } |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 1177 | |
| 1178 | } |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 1179 | } |