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