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 | |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 18 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.net.InetAddress; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 22 | import java.net.UnknownHostException; |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 23 | import java.nio.ByteBuffer; |
| 24 | import java.util.Map; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 25 | import java.util.Dictionary; |
| 26 | import java.util.HashSet; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 27 | import java.util.Arrays; |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 28 | |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 29 | import org.apache.commons.lang3.builder.ToStringBuilder; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 30 | import org.apache.felix.scr.annotations.Component; |
| 31 | import org.apache.felix.scr.annotations.Deactivate; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 32 | import org.apache.felix.scr.annotations.Property; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 33 | import org.apache.felix.scr.annotations.Reference; |
| 34 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 35 | import org.apache.felix.scr.annotations.Service; |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 36 | import org.onlab.packet.DeserializationException; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 37 | import org.onlab.packet.EAP; |
| 38 | import org.onlab.packet.EAPOL; |
| 39 | import org.onlab.packet.EthType; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 40 | import org.onlab.packet.Ethernet; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 41 | import org.onlab.packet.MacAddress; |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 42 | import org.onlab.packet.RADIUS; |
| 43 | import org.onlab.packet.RADIUSAttribute; |
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; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 52 | import org.onosproject.net.PortNumber; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 53 | import org.onosproject.net.config.ConfigFactory; |
| 54 | import org.onosproject.net.config.NetworkConfigEvent; |
| 55 | import org.onosproject.net.config.NetworkConfigListener; |
| 56 | import org.onosproject.net.config.NetworkConfigRegistry; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 57 | import org.onosproject.net.device.DeviceEvent; |
| 58 | import org.onosproject.net.device.DeviceListener; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 59 | import org.onosproject.net.device.DeviceService; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 60 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 61 | import org.onosproject.net.flow.TrafficTreatment; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 62 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 63 | import org.onosproject.net.packet.InboundPacket; |
| 64 | import org.onosproject.net.packet.OutboundPacket; |
| 65 | import org.onosproject.net.packet.PacketContext; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 66 | import org.onosproject.net.packet.PacketProcessor; |
| 67 | import org.onosproject.net.packet.PacketService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 68 | import org.opencord.aaa.AaaConfig; |
| 69 | import org.opencord.aaa.AuthenticationEvent; |
| 70 | import org.opencord.aaa.AuthenticationEventListener; |
| 71 | import org.opencord.aaa.AuthenticationService; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 72 | import org.opencord.aaa.AuthenticationStatisticsEvent; |
| 73 | import org.opencord.aaa.AuthenticationStatisticsService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 74 | import org.opencord.aaa.RadiusCommunicator; |
| 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; |
Kartikey Dubey | f72e195 | 2019-06-24 07:09:00 +0000 | [diff] [blame] | 80 | import org.apache.felix.scr.annotations.Modified; |
| 81 | import org.apache.felix.scr.annotations.Activate; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 82 | import org.slf4j.Logger; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 83 | import com.google.common.base.Strings; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 84 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 85 | import java.util.concurrent.Executors; |
| 86 | import java.util.concurrent.ScheduledExecutorService; |
| 87 | import java.util.concurrent.ScheduledFuture; |
| 88 | import java.util.concurrent.TimeUnit; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 89 | |
| 90 | import javax.crypto.Mac; |
| 91 | import javax.crypto.spec.SecretKeySpec; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 92 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 93 | * AAA application for ONOS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 94 | */ |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 95 | @Service |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 96 | @Component(immediate = true) |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 97 | public class AaaManager |
| 98 | extends AbstractListenerManager<AuthenticationEvent, AuthenticationEventListener> |
| 99 | implements AuthenticationService { |
| 100 | |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 101 | private static final String APP_NAME = "org.opencord.aaa"; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 102 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 103 | private final Logger log = getLogger(getClass()); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 104 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 106 | protected CoreService coreService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 107 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 109 | protected PacketService packetService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 110 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 112 | protected NetworkConfigRegistry netCfgService; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 113 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 115 | protected DeviceService deviceService; |
| 116 | |
| 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 118 | protected SadisService sadisService; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 119 | |
| 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 121 | protected MastershipService mastershipService; |
| 122 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 124 | protected AuthenticationStatisticsService aaaStatisticsManager; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 125 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 127 | protected ComponentConfigService cfgService; |
| 128 | |
| 129 | protected AuthenticationStatisticsEventPublisher authenticationStatisticsPublisher; |
| 130 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 131 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 132 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 133 | private static final int DEFAULT_REPEAT_DELAY = 20; |
| 134 | @Property(name = "statisticsGenerationEvent", intValue = DEFAULT_REPEAT_DELAY, |
| 135 | label = "statisticsGenerationEvent") |
| 136 | private int statisticsGenerationEvent = DEFAULT_REPEAT_DELAY; |
| 137 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 138 | // NAS IP address |
| 139 | protected InetAddress nasIpAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 140 | |
| 141 | // self MAC address |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 142 | protected String nasMacAddress; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 143 | |
| 144 | // Parsed RADIUS server addresses |
| 145 | protected InetAddress radiusIpAddress; |
| 146 | |
| 147 | // MAC address of RADIUS server or net hop router |
| 148 | protected String radiusMacAddress; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 149 | |
| 150 | // RADIUS server secret |
| 151 | protected String radiusSecret; |
| 152 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 153 | // bindings |
| 154 | protected CustomizationInfo customInfo; |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 155 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 156 | // our application-specific event handler |
| 157 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 158 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 159 | // our unique identifier |
| 160 | private ApplicationId appId; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 161 | |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 162 | // TimeOut time for cleaning up stateMachines stuck due to pending AAA/EAPOL message. |
| 163 | protected int cleanupTimerTimeOutInMins; |
| 164 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 165 | // Setup specific customization/attributes on the RADIUS packets |
| 166 | PacketCustomizer pktCustomizer; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 167 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 168 | // packet customizer to use |
| 169 | private String customizer; |
| 170 | |
| 171 | // Type of connection to use to communicate with Radius server, options are |
| 172 | // "socket" or "packet_out" |
| 173 | private String radiusConnectionType; |
| 174 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 175 | // Object for the specific type of communication with the RADIUS |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 176 | // server, socket based or packet_out based |
| 177 | RadiusCommunicator impl = null; |
| 178 | |
| 179 | // latest configuration |
| 180 | AaaConfig newCfg; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 181 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 182 | ScheduledFuture<?> scheduledFuture; |
| 183 | |
| 184 | ScheduledExecutorService executor; |
| 185 | String configuredAaaServerAddress; |
| 186 | HashSet<Byte> outPacketSet = new HashSet<Byte>(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 187 | // Configuration properties factory |
| 188 | private final ConfigFactory factory = |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 189 | new ConfigFactory<ApplicationId, AaaConfig>(APP_SUBJECT_FACTORY, |
| 190 | AaaConfig.class, |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 191 | "AAA") { |
| 192 | @Override |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 193 | public AaaConfig createConfig() { |
| 194 | return new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 195 | } |
| 196 | }; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 197 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 198 | // Listener for config changes |
| 199 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 200 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 201 | private StateMachineDelegate delegate = new InternalStateMachineDelegate(); |
| 202 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 203 | /** |
| 204 | * Builds an EAPOL packet based on the given parameters. |
| 205 | * |
| 206 | * @param dstMac destination MAC address |
| 207 | * @param srcMac source MAC address |
| 208 | * @param vlan vlan identifier |
| 209 | * @param eapolType EAPOL type |
| 210 | * @param eap EAP payload |
| 211 | * @return Ethernet frame |
| 212 | */ |
| 213 | private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 214 | short vlan, byte eapolType, EAP eap, byte priorityCode) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 215 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 216 | Ethernet eth = new Ethernet(); |
| 217 | eth.setDestinationMACAddress(dstMac.toBytes()); |
| 218 | eth.setSourceMACAddress(srcMac.toBytes()); |
| 219 | eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); |
| 220 | if (vlan != Ethernet.VLAN_UNTAGGED) { |
| 221 | eth.setVlanID(vlan); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 222 | eth.setPriorityCode(priorityCode); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 223 | } |
| 224 | //eapol header |
| 225 | EAPOL eapol = new EAPOL(); |
| 226 | eapol.setEapolType(eapolType); |
| 227 | eapol.setPacketLength(eap.getLength()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 228 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 229 | //eap part |
| 230 | eapol.setPayload(eap); |
| 231 | |
| 232 | eth.setPayload(eapol); |
| 233 | eth.setPad(true); |
| 234 | return eth; |
| 235 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 236 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 237 | @Activate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 238 | public void activate(ComponentContext context) { |
Charles Chan | df7ff86 | 2017-01-20 11:22:05 -0800 | [diff] [blame] | 239 | appId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 240 | eventDispatcher.addSink(AuthenticationEvent.class, listenerRegistry); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 241 | netCfgService.addListener(cfgListener); |
| 242 | netCfgService.registerConfigFactory(factory); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 243 | cfgService.registerProperties(getClass()); |
| 244 | modified(context); |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 245 | subsService = sadisService.getSubscriberInfoService(); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 246 | customInfo = new CustomizationInfo(subsService, deviceService); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 247 | cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AaaConfig.class)); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 248 | log.info("Starting with config {} {}", this, newCfg); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 249 | configureRadiusCommunication(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 250 | // register our event handler |
Brian O'Connor | d9c7da0 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 251 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 252 | StateMachine.initializeMaps(); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 253 | StateMachine.setDelegate(delegate); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 254 | cleanupTimerTimeOutInMins = newCfg.sessionCleanupTimer(); |
| 255 | StateMachine.setcleanupTimerTimeOutInMins(cleanupTimerTimeOutInMins); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 256 | impl.initializeLocalState(newCfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 257 | impl.requestIntercepts(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 258 | deviceService.addListener(deviceListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 259 | getConfiguredAaaServerAddress(); |
| 260 | authenticationStatisticsPublisher = |
| 261 | new AuthenticationStatisticsEventPublisher(); |
| 262 | executor = Executors.newScheduledThreadPool(1); |
| 263 | scheduledFuture = executor.scheduleAtFixedRate(authenticationStatisticsPublisher, |
| 264 | 0, statisticsGenerationEvent, TimeUnit.SECONDS); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 265 | |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 266 | log.info("Started"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | @Deactivate |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 270 | public void deactivate(ComponentContext context) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 271 | impl.withdrawIntercepts(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 272 | packetService.removeProcessor(processor); |
Deepa Vaddireddy | b9c24c6 | 2017-09-21 13:45:30 +0530 | [diff] [blame] | 273 | netCfgService.removeListener(cfgListener); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 274 | cfgService.unregisterProperties(getClass(), false); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 275 | StateMachine.unsetDelegate(delegate); |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 276 | StateMachine.destroyMaps(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 277 | impl.deactivate(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 278 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 279 | eventDispatcher.removeSink(AuthenticationEvent.class); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 280 | scheduledFuture.cancel(true); |
| 281 | executor.shutdown(); |
Jian Li | 13c6716 | 2015-12-09 13:20:34 -0800 | [diff] [blame] | 282 | log.info("Stopped"); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 283 | } |
| 284 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 285 | @Modified |
| 286 | public void modified(ComponentContext context) { |
| 287 | Dictionary<?, ?> properties = context.getProperties(); |
| 288 | String s = Tools.get(properties, "statisticsGenerationEvent"); |
| 289 | statisticsGenerationEvent = Strings.isNullOrEmpty(s) ? DEFAULT_REPEAT_DELAY : Integer.parseInt(s.trim()); |
| 290 | } |
| 291 | |
Shubham Sharma | 1ad1663 | 2019-11-26 11:09:21 +0000 | [diff] [blame^] | 292 | protected void configureRadiusCommunication() { |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 293 | if (radiusConnectionType.toLowerCase().equals("socket")) { |
| 294 | impl = new SocketBasedRadiusCommunicator(appId, packetService, this); |
| 295 | } else { |
| 296 | impl = new PortBasedRadiusCommunicator(appId, packetService, mastershipService, |
| 297 | deviceService, subsService, pktCustomizer, this); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | private void configurePacketCustomizer() { |
| 302 | switch (customizer.toLowerCase()) { |
| 303 | case "sample": |
| 304 | pktCustomizer = new SamplePacketCustomizer(customInfo); |
| 305 | log.info("Created SamplePacketCustomizer"); |
| 306 | break; |
Saurav Das | e72358a | 2018-11-13 21:56:46 -0800 | [diff] [blame] | 307 | case "att": |
| 308 | pktCustomizer = new AttPacketCustomizer(customInfo); |
| 309 | log.info("Created AttPacketCustomizer"); |
| 310 | break; |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 311 | default: |
| 312 | pktCustomizer = new PacketCustomizer(customInfo); |
| 313 | log.info("Created default PacketCustomizer"); |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 318 | private void getConfiguredAaaServerAddress() { |
| 319 | try { |
| 320 | InetAddress address; |
| 321 | if (newCfg.radiusHostName() != null) { |
| 322 | address = InetAddress.getByName(newCfg.radiusHostName()); |
| 323 | } else { |
| 324 | address = newCfg.radiusIp(); |
| 325 | } |
| 326 | |
| 327 | configuredAaaServerAddress = address.getHostAddress(); |
| 328 | } catch (UnknownHostException uhe) { |
| 329 | log.warn("Unable to resolve host {}", newCfg.radiusHostName()); |
| 330 | } |
| 331 | } |
| 332 | |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 333 | private void checkReceivedPacketForValidValidator(RADIUS radiusPacket, byte[] requestAuthenticator) { |
| 334 | if (!checkResponseMessageAuthenticator(radiusSecret, radiusPacket, requestAuthenticator)) { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 335 | aaaStatisticsManager.getAaaStats().increaseInvalidValidatorsRx(); |
| 336 | } |
| 337 | } |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 338 | |
| 339 | private boolean checkResponseMessageAuthenticator(String key, RADIUS radiusPacket, byte[] requestAuthenticator) { |
| 340 | byte[] newHash = new byte[16]; |
| 341 | Arrays.fill(newHash, (byte) 0); |
| 342 | byte[] messageAuthenticator = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH).getValue(); |
| 343 | byte[] authenticator = radiusPacket.getAuthenticator(); |
| 344 | radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, newHash); |
| 345 | radiusPacket.setAuthenticator(requestAuthenticator); |
| 346 | // Calculate the MD5 HMAC based on the message |
| 347 | try { |
| 348 | SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacMD5"); |
| 349 | Mac mac = Mac.getInstance("HmacMD5"); |
| 350 | mac.init(keySpec); |
| 351 | newHash = mac.doFinal(radiusPacket.serialize()); |
| 352 | } catch (Exception e) { |
| 353 | log.error("Failed to generate message authenticator: {}", e.getMessage()); |
| 354 | } |
| 355 | radiusPacket.updateAttribute(RADIUSAttribute.RADIUS_ATTR_MESSAGE_AUTH, messageAuthenticator); |
| 356 | radiusPacket.setAuthenticator(authenticator); |
| 357 | // Compare the calculated Message-Authenticator with the one in the message |
| 358 | return Arrays.equals(newHash, messageAuthenticator); |
| 359 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 360 | public void checkForPacketFromUnknownServer(String hostAddress) { |
| 361 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
Vijaykumar Kushwaha | fffd3d1 | 2019-08-01 11:09:59 +0000 | [diff] [blame] | 362 | getConfiguredAaaServerAddress(); |
| 363 | if (!hostAddress.equals(configuredAaaServerAddress)) { |
| 364 | aaaStatisticsManager.getAaaStats().incrementUnknownServerRx(); |
| 365 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 369 | /** |
| 370 | * Send RADIUS packet to the RADIUS server. |
| 371 | * |
| 372 | * @param radiusPacket RADIUS packet to be sent to server. |
| 373 | * @param inPkt Incoming EAPOL packet |
| 374 | */ |
| 375 | protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 376 | outPacketSet.add(radiusPacket.getIdentifier()); |
| 377 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(true); |
| 378 | aaaStatisticsManager.getAaaStats().increaseAccessRequestsTx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 379 | impl.sendRadiusPacket(radiusPacket, inPkt); |
| 380 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 381 | |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 382 | /** |
| 383 | * For scheduling the timer required for cleaning up StateMachine |
| 384 | * when no response |
| 385 | * from RADIUS SERVER. |
| 386 | * |
| 387 | * @param sessionId SessionId of the current session |
| 388 | * @param stateMachine StateMachine for the id |
| 389 | */ |
| 390 | public void scheduleStateMachineCleanupTimer(String sessionId, StateMachine stateMachine) { |
| 391 | StateMachine.CleanupTimerTask cleanupTask = stateMachine.new CleanupTimerTask(sessionId, this); |
| 392 | ScheduledFuture<?> cleanupTimer = executor.schedule(cleanupTask, cleanupTimerTimeOutInMins, TimeUnit.MINUTES); |
| 393 | stateMachine.setCleanupTimer(cleanupTimer); |
| 394 | |
| 395 | } |
| 396 | |
| 397 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 398 | * Handles RADIUS packets. |
| 399 | * |
| 400 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
| 401 | * @throws StateMachineException if an illegal state transition is triggered |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 402 | * @throws DeserializationException if packet deserialization fails |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 403 | */ |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 404 | public void handleRadiusPacket(RADIUS radiusPacket) |
| 405 | throws StateMachineException, DeserializationException { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 406 | if (log.isTraceEnabled()) { |
| 407 | log.trace("Received RADIUS packet {}", radiusPacket); |
| 408 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 409 | StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); |
| 410 | if (stateMachine == null) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 411 | log.error("Invalid packet identifier {}, could not find corresponding " |
| 412 | + "state machine ... exiting", radiusPacket.getIdentifier()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 413 | aaaStatisticsManager.getAaaStats().incrementNumberOfSessionsExpired(); |
| 414 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 415 | return; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 416 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 417 | EAP eapPayload; |
| 418 | Ethernet eth; |
Vijaykumar Kushwaha | 056e4cd | 2019-08-06 13:16:25 +0000 | [diff] [blame] | 419 | checkReceivedPacketForValidValidator(radiusPacket, stateMachine.requestAuthenticator()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 420 | if (outPacketSet.contains(radiusPacket.getIdentifier())) { |
| 421 | aaaStatisticsManager.getAaaStats().increaseOrDecreasePendingRequests(false); |
| 422 | outPacketSet.remove(new Byte(radiusPacket.getIdentifier())); |
| 423 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 424 | switch (radiusPacket.getCode()) { |
| 425 | case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 426 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_CHALLENGE"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 427 | RADIUSAttribute radiusAttrState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE); |
| 428 | byte[] challengeState = null; |
| 429 | if (radiusAttrState != null) { |
| 430 | challengeState = radiusAttrState.getValue(); |
| 431 | } |
| 432 | eapPayload = radiusPacket.decapsulateMessage(); |
| 433 | stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); |
| 434 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 435 | MacAddress.valueOf(nasMacAddress), |
| 436 | stateMachine.vlanId(), |
| 437 | EAPOL.EAPOL_PACKET, |
| 438 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 439 | log.debug("Send EAP challenge response to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 440 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), true); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 441 | aaaStatisticsManager.getAaaStats().increaseChallengeResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 442 | break; |
| 443 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 444 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_ACCEPT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 445 | //send an EAPOL - Success to the supplicant. |
| 446 | byte[] eapMessageSuccess = |
| 447 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 448 | eapPayload = EAP.deserializer().deserialize( |
| 449 | eapMessageSuccess, 0, eapMessageSuccess.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 450 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 451 | MacAddress.valueOf(nasMacAddress), |
| 452 | stateMachine.vlanId(), |
| 453 | EAPOL.EAPOL_PACKET, |
| 454 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 455 | log.info("Send EAP success message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 456 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 457 | aaaStatisticsManager.getAaaStats().incrementEapolAuthSuccessTrans(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 458 | |
| 459 | stateMachine.authorizeAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 460 | aaaStatisticsManager.getAaaStats().increaseAcceptResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 461 | break; |
| 462 | case RADIUS.RADIUS_CODE_ACCESS_REJECT: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 463 | log.debug("RADIUS packet: RADIUS_CODE_ACCESS_REJECT"); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 464 | //send an EAPOL - Failure to the supplicant. |
| 465 | byte[] eapMessageFailure; |
| 466 | eapPayload = new EAP(); |
| 467 | RADIUSAttribute radiusAttrEap = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE); |
| 468 | if (radiusAttrEap == null) { |
| 469 | eapPayload.setCode(EAP.FAILURE); |
| 470 | eapPayload.setIdentifier(stateMachine.challengeIdentifier()); |
| 471 | eapPayload.setLength(EAP.EAP_HDR_LEN_SUC_FAIL); |
| 472 | } else { |
| 473 | eapMessageFailure = radiusAttrEap.getValue(); |
Jonathan Hart | 4731dd9 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 474 | eapPayload = EAP.deserializer().deserialize( |
| 475 | eapMessageFailure, 0, eapMessageFailure.length); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 476 | } |
| 477 | eth = buildEapolResponse(stateMachine.supplicantAddress(), |
| 478 | MacAddress.valueOf(nasMacAddress), |
| 479 | stateMachine.vlanId(), |
| 480 | EAPOL.EAPOL_PACKET, |
| 481 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 482 | log.warn("Send EAP failure message to supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 483 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
| 484 | aaaStatisticsManager.getAaaStats().incrementEapolauthFailureTrans(); |
| 485 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 486 | stateMachine.denyAccess(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 487 | aaaStatisticsManager.getAaaStats().increaseRejectResponsesRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 488 | break; |
| 489 | default: |
| 490 | log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 491 | aaaStatisticsManager.getAaaStats().increaseUnknownTypeRx(); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 492 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 493 | aaaStatisticsManager.getAaaStats().countDroppedResponsesRx(); |
Aaron Kruglikov | d39d99e | 2015-07-03 13:30:57 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 496 | /** |
| 497 | * Send the ethernet packet to the supplicant. |
| 498 | * |
| 499 | * @param ethernetPkt the ethernet packet |
| 500 | * @param connectPoint the connect point to send out |
| 501 | */ |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 502 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint, boolean isChallengeResponse) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 503 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); |
| 504 | OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), |
| 505 | treatment, ByteBuffer.wrap(ethernetPkt.serialize())); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 506 | EAPOL eap = ((EAPOL) ethernetPkt.getPayload()); |
| 507 | EAP eapPkt = (EAP) eap.getPayload(); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 508 | if (log.isTraceEnabled()) { |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 509 | log.trace("Sending eapol payload {} enclosed in {} to supplicant at {}", |
| 510 | eap, ethernetPkt, connectPoint); |
| 511 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 512 | packetService.emit(packet); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 513 | if (isChallengeResponse) { |
| 514 | aaaStatisticsManager.getAaaStats().incrementEapPktTxauthEap(); |
| 515 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 518 | @Override |
| 519 | public String toString() { |
| 520 | return ToStringBuilder.reflectionToString(this); |
| 521 | } |
| 522 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 523 | // our handler defined as a private inner class |
| 524 | |
| 525 | /** |
| 526 | * Packet processor responsible for forwarding packets along their paths. |
| 527 | */ |
| 528 | private class ReactivePacketProcessor implements PacketProcessor { |
| 529 | @Override |
| 530 | public void process(PacketContext context) { |
| 531 | |
| 532 | // Extract the original Ethernet frame from the packet information |
| 533 | InboundPacket pkt = context.inPacket(); |
| 534 | Ethernet ethPkt = pkt.parsed(); |
| 535 | if (ethPkt == null) { |
| 536 | return; |
| 537 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 538 | |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 539 | try { |
| 540 | // identify if incoming packet comes from supplicant (EAP) or RADIUS |
| 541 | switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { |
| 542 | case EAPOL: |
| 543 | handleSupplicantPacket(context.inPacket()); |
| 544 | break; |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 545 | default: |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 546 | // any other packets let the specific implementation handle |
| 547 | impl.handlePacketFromServer(context); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 548 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 549 | } catch (StateMachineException e) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 550 | log.warn("Unable to process packet:", e); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 554 | /** |
| 555 | * Creates and initializes common fields of a RADIUS packet. |
| 556 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 557 | * @param stateMachine state machine for the request |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 558 | * @param eapPacket EAP packet |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 559 | * @return RADIUS packet |
| 560 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 561 | private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 562 | RADIUS radiusPayload = |
| 563 | new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, |
| 564 | eapPacket.getIdentifier()); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 565 | |
| 566 | // set Request Authenticator in StateMachine |
| 567 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
| 568 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 569 | radiusPayload.setIdentifier(identifier); |
| 570 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 571 | stateMachine.username()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 572 | |
| 573 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 574 | AaaManager.this.nasIpAddress.getAddress()); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 575 | |
| 576 | radiusPayload.encapsulateMessage(eapPacket); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 577 | |
| 578 | return radiusPayload; |
| 579 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 580 | |
| 581 | /** |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 582 | * Handles PAE packets (supplicant). |
| 583 | * |
| 584 | * @param inPacket Ethernet packet coming from the supplicant |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 585 | */ |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 586 | private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException { |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 587 | Ethernet ethPkt = inPacket.parsed(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 588 | // Where does it come from? |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 589 | MacAddress srcMac = ethPkt.getSourceMAC(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 590 | |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 591 | DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
| 592 | PortNumber portNumber = inPacket.receivedFrom().port(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 593 | String sessionId = deviceId.toString() + portNumber.toString(); |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 594 | EAPOL eapol = (EAPOL) ethPkt.getPayload(); |
| 595 | if (log.isTraceEnabled()) { |
| 596 | log.trace("Received EAPOL packet {} in enclosing packet {} from " |
| 597 | + "dev/port: {}/{}", eapol, ethPkt, deviceId, |
| 598 | portNumber); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 599 | } |
Jonathan Hart | a46dddf | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 600 | |
Saurav Das | 987441a | 2018-09-18 16:33:47 -0700 | [diff] [blame] | 601 | StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId); |
| 602 | if (stateMachine == null) { |
| 603 | log.debug("Creating new state machine for sessionId: {} for " |
| 604 | + "dev/port: {}/{}", sessionId, deviceId, portNumber); |
| 605 | stateMachine = new StateMachine(sessionId); |
| 606 | } else { |
| 607 | log.debug("Using existing state-machine for sessionId: {}", sessionId); |
| 608 | } |
| 609 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 610 | switch (eapol.getEapolType()) { |
| 611 | case EAPOL.EAPOL_START: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 612 | log.debug("EAP packet: EAPOL_START"); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 613 | stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 614 | if (stateMachine.getCleanupTimer() == null) { |
| 615 | scheduleStateMachineCleanupTimer(sessionId, stateMachine); |
| 616 | } |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 617 | stateMachine.start(); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 618 | aaaStatisticsManager.getAaaStats().incrementEapolStartReqTrans(); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 619 | //send an EAP Request/Identify to the supplicant |
| 620 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 621 | if (ethPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
| 622 | stateMachine.setPriorityCode(ethPkt.getPriorityCode()); |
| 623 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 624 | Ethernet eth = buildEapolResponse(srcMac, MacAddress.valueOf(nasMacAddress), |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 625 | ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 626 | eapPayload, stateMachine.priorityCode()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 627 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 628 | stateMachine.setSupplicantAddress(srcMac); |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 629 | stateMachine.setVlanId(ethPkt.getVlanID()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 630 | log.debug("Getting EAP identity from supplicant {}", stateMachine.supplicantAddress().toString()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 631 | sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint(), false); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 632 | |
| 633 | break; |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 634 | case EAPOL.EAPOL_LOGOFF: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 635 | log.debug("EAP packet: EAPOL_LOGOFF"); |
Ray Milkey | b34b496 | 2016-01-04 10:24:43 -0800 | [diff] [blame] | 636 | if (stateMachine.state() == StateMachine.STATE_AUTHORIZED) { |
| 637 | stateMachine.logoff(); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 638 | aaaStatisticsManager.getAaaStats().incrementEapolLogoffRx(); |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 642 | case EAPOL.EAPOL_PACKET: |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 643 | RADIUS radiusPayload; |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 644 | // check if this is a Response/Identify or a Response/TLS |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 645 | EAP eapPacket = (EAP) eapol.getPayload(); |
| 646 | |
| 647 | byte dataType = eapPacket.getDataType(); |
| 648 | switch (dataType) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 649 | |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 650 | case EAP.ATTR_IDENTITY: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 651 | log.debug("EAP packet: EAPOL_PACKET ATTR_IDENTITY"); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 652 | //Setting the time of this response from RG, only when its not a re-transmission. |
| 653 | if (stateMachine.getLastPacketReceivedTime() == 0) { |
| 654 | stateMachine.setLastPacketReceivedTime(System.currentTimeMillis()); |
| 655 | } |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 656 | // request id access to RADIUS |
| 657 | stateMachine.setUsername(eapPacket.getData()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 658 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 659 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 660 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 661 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 662 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 663 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 664 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 665 | aaaStatisticsManager.getAaaStats().incrementEapolAtrrIdentity(); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 666 | // change the state to "PENDING" |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 667 | if (stateMachine.state() == StateMachine.STATE_PENDING) { |
| 668 | aaaStatisticsManager.getAaaStats().increaseRequestReTx(); |
| 669 | } |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 670 | stateMachine.requestAccess(); |
| 671 | break; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 672 | case EAP.ATTR_MD5: |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 673 | stateMachine.setLastPacketReceivedTime(System.currentTimeMillis()); |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 674 | log.debug("EAP packet: EAPOL_PACKET ATTR_MD5"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 675 | // verify if the EAP identifier corresponds to the |
| 676 | // challenge identifier from the client state |
| 677 | // machine. |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 678 | if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 679 | //send the RADIUS challenge response |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 680 | radiusPayload = |
| 681 | getRadiusPayload(stateMachine, |
| 682 | stateMachine.identifier(), |
| 683 | eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 684 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 685 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 686 | if (stateMachine.challengeState() != null) { |
| 687 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 688 | stateMachine.challengeState()); |
| 689 | } |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 690 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 691 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 692 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 693 | aaaStatisticsManager.getAaaStats().incrementEapolMd5RspChall(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 694 | } |
| 695 | break; |
| 696 | case EAP.ATTR_TLS: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 697 | log.debug("EAP packet: EAPOL_PACKET ATTR_TLS"); |
Ray Milkey | 9eb293f | 2015-09-30 15:09:17 -0700 | [diff] [blame] | 698 | // request id access to RADIUS |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 699 | radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 700 | radiusPayload = pktCustomizer.customizePacket(radiusPayload, inPacket); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 701 | |
Qianqian Hu | b55a1ac | 2015-12-23 20:44:48 +0800 | [diff] [blame] | 702 | if (stateMachine.challengeState() != null) { |
| 703 | radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, |
| 704 | stateMachine.challengeState()); |
| 705 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 706 | stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 707 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 708 | radiusPayload.addMessageAuthenticator(AaaManager.this.radiusSecret); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 709 | sendRadiusPacket(radiusPayload, inPacket); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 710 | stateMachine.setWaitingForRadiusResponse(true); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 711 | aaaStatisticsManager.getAaaStats().incrementEapolTlsRespChall(); |
Ray Milkey | 5493b51 | 2015-10-21 12:13:49 -0700 | [diff] [blame] | 712 | |
Ray Milkey | f3790b8 | 2015-10-21 16:28:08 -0700 | [diff] [blame] | 713 | if (stateMachine.state() != StateMachine.STATE_PENDING) { |
| 714 | stateMachine.requestAccess(); |
| 715 | } |
Ray Milkey | f51eba2 | 2015-09-25 10:24:23 -0700 | [diff] [blame] | 716 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 717 | break; |
| 718 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 719 | log.warn("Unknown EAP packet type"); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 720 | return; |
| 721 | } |
| 722 | break; |
| 723 | default: |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 724 | log.debug("Skipping EAPOL message {}", eapol.getEapolType()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 725 | } |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 726 | aaaStatisticsManager.getAaaStats().countTransRespNotNak(); |
| 727 | aaaStatisticsManager.getAaaStats().countEapolResIdentityMsgTrans(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 728 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 731 | /** |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 732 | * Delegate allowing the StateMachine to notify us of events. |
| 733 | */ |
| 734 | private class InternalStateMachineDelegate implements StateMachineDelegate { |
| 735 | |
| 736 | @Override |
| 737 | public void notify(AuthenticationEvent authenticationEvent) { |
| 738 | log.info("Auth event {} for {}", |
| 739 | authenticationEvent.type(), authenticationEvent.subject()); |
| 740 | post(authenticationEvent); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 745 | * Configuration Listener, handles change in configuration. |
| 746 | */ |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 747 | private class InternalConfigListener implements NetworkConfigListener { |
| 748 | |
| 749 | /** |
Ray Milkey | c9e8dcc | 2015-12-30 10:31:32 -0800 | [diff] [blame] | 750 | * Reconfigures the AAA application according to the |
| 751 | * configuration parameters passed. |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 752 | * |
| 753 | * @param cfg configuration object |
| 754 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 755 | private void reconfigureNetwork(AaaConfig cfg) { |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 756 | log.info("Reconfiguring AaaConfig from config: {}", cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 757 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 758 | if (cfg == null) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 759 | newCfg = new AaaConfig(); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 760 | } else { |
| 761 | newCfg = cfg; |
| 762 | } |
| 763 | if (newCfg.nasIp() != null) { |
| 764 | nasIpAddress = newCfg.nasIp(); |
| 765 | } |
| 766 | if (newCfg.radiusIp() != null) { |
| 767 | radiusIpAddress = newCfg.radiusIp(); |
| 768 | } |
| 769 | if (newCfg.radiusMac() != null) { |
| 770 | radiusMacAddress = newCfg.radiusMac(); |
| 771 | } |
| 772 | if (newCfg.nasMac() != null) { |
| 773 | nasMacAddress = newCfg.nasMac(); |
| 774 | } |
| 775 | if (newCfg.radiusSecret() != null) { |
| 776 | radiusSecret = newCfg.radiusSecret(); |
| 777 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 778 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 779 | boolean reconfigureCustomizer = false; |
| 780 | if (customizer == null || !customizer.equals(newCfg.radiusPktCustomizer())) { |
| 781 | customizer = newCfg.radiusPktCustomizer(); |
| 782 | configurePacketCustomizer(); |
| 783 | reconfigureCustomizer = true; |
| 784 | } |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 785 | |
Deepa Vaddireddy | e0e1072 | 2017-09-27 05:00:10 +0530 | [diff] [blame] | 786 | if (radiusConnectionType == null |
| 787 | || reconfigureCustomizer |
| 788 | || !radiusConnectionType.equals(newCfg.radiusConnectionType())) { |
| 789 | radiusConnectionType = newCfg.radiusConnectionType(); |
| 790 | if (impl != null) { |
| 791 | impl.withdrawIntercepts(); |
| 792 | impl.clearLocalState(); |
| 793 | } |
| 794 | configureRadiusCommunication(); |
| 795 | impl.initializeLocalState(newCfg); |
| 796 | impl.requestIntercepts(); |
| 797 | } else if (impl != null) { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 798 | impl.clearLocalState(); |
| 799 | impl.initializeLocalState(newCfg); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 800 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public void event(NetworkConfigEvent event) { |
| 805 | |
| 806 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 807 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 808 | event.configClass().equals(AaaConfig.class)) { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 809 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 810 | AaaConfig cfg = netCfgService.getConfig(appId, AaaConfig.class); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 811 | reconfigureNetwork(cfg); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 812 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 813 | log.info("Reconfigured: {}", cfg.toString()); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | } |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 817 | |
| 818 | private class InternalDeviceListener implements DeviceListener { |
| 819 | @Override |
| 820 | public void event(DeviceEvent event) { |
| 821 | |
| 822 | switch (event.type()) { |
| 823 | case PORT_REMOVED: |
| 824 | DeviceId devId = event.subject().id(); |
| 825 | PortNumber portNumber = event.port().number(); |
| 826 | String sessionId = devId.toString() + portNumber.toString(); |
| 827 | |
| 828 | Map<String, StateMachine> sessionIdMap = StateMachine.sessionIdMap(); |
| 829 | StateMachine removed = sessionIdMap.remove(sessionId); |
| 830 | if (removed != null) { |
| 831 | StateMachine.deleteStateMachineMapping(removed); |
| 832 | } |
| 833 | |
| 834 | break; |
| 835 | default: |
| 836 | return; |
| 837 | } |
| 838 | } |
| 839 | } |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 840 | private class AuthenticationStatisticsEventPublisher implements Runnable { |
| 841 | private final Logger log = getLogger(getClass()); |
| 842 | public void run() { |
| 843 | log.info("Notifying AuthenticationStatisticsEvent"); |
| 844 | aaaStatisticsManager.calculatePacketRoundtripTime(); |
| 845 | log.debug("AcceptResponsesRx---" + aaaStatisticsManager.getAaaStats().getAcceptResponsesRx()); |
| 846 | log.debug("AccessRequestsTx---" + aaaStatisticsManager.getAaaStats().getAccessRequestsTx()); |
| 847 | log.debug("ChallengeResponsesRx---" + aaaStatisticsManager.getAaaStats().getChallengeResponsesRx()); |
| 848 | log.debug("DroppedResponsesRx---" + aaaStatisticsManager.getAaaStats().getDroppedResponsesRx()); |
| 849 | log.debug("InvalidValidatorsRx---" + aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx()); |
| 850 | log.debug("MalformedResponsesRx---" + aaaStatisticsManager.getAaaStats().getMalformedResponsesRx()); |
| 851 | log.debug("PendingRequests---" + aaaStatisticsManager.getAaaStats().getPendingRequests()); |
| 852 | log.debug("RejectResponsesRx---" + aaaStatisticsManager.getAaaStats().getRejectResponsesRx()); |
| 853 | log.debug("RequestReTx---" + aaaStatisticsManager.getAaaStats().getRequestReTx()); |
| 854 | log.debug("RequestRttMilis---" + aaaStatisticsManager.getAaaStats().getRequestRttMilis()); |
| 855 | log.debug("UnknownServerRx---" + aaaStatisticsManager.getAaaStats().getUnknownServerRx()); |
| 856 | log.debug("UnknownTypeRx---" + aaaStatisticsManager.getAaaStats().getUnknownTypeRx()); |
Shubham Sharma | a3b1bd3 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 857 | log.debug("TimedOutPackets----" + aaaStatisticsManager.getAaaStats().getTimedOutPackets()); |
Shubham Sharma | c155ef8 | 2019-07-11 12:12:41 +0000 | [diff] [blame] | 858 | log.debug("EapolLogoffRx---" + aaaStatisticsManager.getAaaStats().getEapolLogoffRx()); |
| 859 | log.debug("EapolAuthSuccessTrans---" + aaaStatisticsManager.getAaaStats().getEapolAuthSuccessTrans()); |
| 860 | log.debug("EapolAuthFailureTrans---" + |
| 861 | aaaStatisticsManager.getAaaStats().getEapolAuthFailureTrans()); |
| 862 | log.debug("EapolStartReqTrans---" + |
| 863 | aaaStatisticsManager.getAaaStats().getEapolStartReqTrans()); |
| 864 | log.debug("EapolTransRespNotNak---" + |
| 865 | aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak()); |
| 866 | log.debug("EapPktTxauthChooseEap---" + |
| 867 | aaaStatisticsManager.getAaaStats().getEapPktTxauthChooseEap()); |
| 868 | log.debug("EapolResIdentityMsgTrans---" + |
| 869 | aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 870 | aaaStatisticsManager.getStatsDelegate(). |
| 871 | notify(new AuthenticationStatisticsEvent(AuthenticationStatisticsEvent.Type.STATS_UPDATE, |
| 872 | aaaStatisticsManager.getAaaStats())); |
| 873 | } |
| 874 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 875 | } |