Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.opencord.aaa.impl; |
| 17 | |
| 18 | import org.onlab.packet.EAP; |
| 19 | |
| 20 | /** |
| 21 | * Class that is responsible to generate fake EAPOL packets in case that |
| 22 | * FORGE_EAPOL_PACKETS is set to true in the config. |
| 23 | */ |
| 24 | public final class EapolPacketGenerator { |
| 25 | |
| 26 | private EapolPacketGenerator() {} |
| 27 | |
| 28 | public static EAP forgeEapolChallengeAuth() { |
| 29 | EAP eapPayload = new EAP( |
| 30 | new Integer(1).byteValue(), new Integer(1).byteValue(), |
| 31 | new Integer(4).byteValue(), |
| 32 | hexStringToByteArray("108b4eb55f859c501b3e14a594c4997bed")); |
| 33 | return eapPayload; |
| 34 | } |
| 35 | |
| 36 | public static EAP forgeEapolSuccess() { |
| 37 | EAP eapPayload = new EAP( |
| 38 | new Integer(3).byteValue(), |
| 39 | new Integer(2).byteValue(), |
| 40 | new Integer(0).byteValue(), |
| 41 | hexStringToByteArray("") |
| 42 | ); |
| 43 | return eapPayload; |
| 44 | } |
| 45 | |
| 46 | public static byte[] hexStringToByteArray(String s) { |
| 47 | int len = s.length(); |
| 48 | byte[] data = new byte[len / 2]; |
| 49 | for (int i = 0; i < len; i += 2) { |
| 50 | data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) |
| 51 | + Character.digit(s.charAt(i + 1), 16)); |
| 52 | } |
| 53 | return data; |
| 54 | } |
| 55 | } |