Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.onosproject.lisp.msg.authentication; |
| 17 | |
| 18 | /** |
| 19 | * Authentication key enumeration class. |
| 20 | * |
| 21 | * By far, LISP also support two types of MAC authentication which are |
| 22 | * HMAC-SHA-1-96 and HMAC-SHA-256-128. |
| 23 | * |
| 24 | * https://tools.ietf.org/html/rfc6830#page-39 |
| 25 | */ |
| 26 | public enum LispAuthenticationKeyEnum { |
| 27 | |
| 28 | /** No authentication. */ |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 29 | NONE(0, null, 0), |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 30 | |
| 31 | /** HMAC SHA1 encryption. */ |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 32 | SHA1(1, "HmacSHA1", 20), |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 33 | |
| 34 | /** HMAC SHA256 encryption. */ |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 35 | SHA256(2, "HmacSHA256", 32), |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 36 | |
| 37 | /** Unsupported authentication type. */ |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 38 | UNKNOWN(-1, "UNKNOWN", 0); |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 39 | |
| 40 | private short keyId; |
| 41 | private String name; |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 42 | private short length; |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 43 | |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 44 | LispAuthenticationKeyEnum(int keyId, String name, int length) { |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 45 | this.keyId = (short) keyId; |
| 46 | this.name = name; |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 47 | this.length = (short) length; |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Obtains authentication key identifier. |
| 52 | * |
| 53 | * @return authentication key identifier |
| 54 | */ |
| 55 | public short getKeyId() { |
| 56 | return keyId; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Obtains authentication name. |
| 61 | * |
| 62 | * @return authentication name |
| 63 | */ |
| 64 | public String getName() { |
| 65 | return name; |
| 66 | } |
| 67 | |
| 68 | /** |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 69 | * Obtains hash length. |
| 70 | * |
| 71 | * @return hash length |
| 72 | */ |
| 73 | public short getHashLength() { |
| 74 | return length; |
| 75 | } |
| 76 | |
| 77 | /** |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 78 | * Obtains LISP authentication key enum by providing key identifier. |
| 79 | * |
| 80 | * @param keyId LISP authentication key identifier |
| 81 | * @return LISP authentication key enum |
| 82 | */ |
| 83 | public static LispAuthenticationKeyEnum valueOf(short keyId) { |
| 84 | for (LispAuthenticationKeyEnum val : values()) { |
| 85 | if (val.getKeyId() == keyId) { |
| 86 | return val; |
| 87 | } |
| 88 | } |
| 89 | return UNKNOWN; |
| 90 | } |
| 91 | } |