1 /*
2  * Copyright (C) 2019 The Android Open Source Project
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 
17 package com.android.internal.net.eap.message.simaka.attributes;
18 
19 import static com.android.internal.net.TestUtils.hexStringToByteArray;
20 
21 /**
22  * EapTestAttributeDefinitions provides byte[] encodings of commonly used EAP Messages.
23  *
24  * @ee <a href="https://tools.ietf.org/html/rfc4186#section-10">RFC 4186, EAP-SIM Authentication,
25  * Section 10</a>
26  * @see <a href="https://tools.ietf.org/html/rfc4187#section-10">RFC 4187, EAP-AKA Authentication,
27  * Section 10</a>
28  */
29 public class EapTestAttributeDefinitions {
30     public static final String VERSION = "0001";
31     public static final String AT_VERSION_LIST_DATA = "0002" + VERSION + "0000";
32     public static final byte[] AT_VERSION_LIST =
33             hexStringToByteArray("0F02" + AT_VERSION_LIST_DATA);
34     public static final byte[] AT_SELECTED_VERSION = hexStringToByteArray("10010001");
35     public static final String NONCE_MT_STRING = "0123456789ABCDEFFEDCBA9876543210";
36     public static final byte[] NONCE_MT = hexStringToByteArray(NONCE_MT_STRING);
37     public static final byte[] AT_NONCE_MT = hexStringToByteArray("07050000" + NONCE_MT_STRING);
38     public static final byte[] AT_PERMANENT_ID_REQ = hexStringToByteArray("0A010000");
39     public static final byte[] AT_ANY_ID_REQ = hexStringToByteArray("0D010000");
40     public static final byte[] AT_FULL_AUTH_ID_REQ = hexStringToByteArray("11010000");
41 
42     // Identity = "test1@android.net"
43     public static final String IDENTITY_STRING = "746573743140616E64726F69642E6E6574";
44     public static final byte[] IDENTITY = hexStringToByteArray(IDENTITY_STRING);
45     public static final byte[] AT_IDENTITY =
46             hexStringToByteArray("0E060011" + IDENTITY_STRING + "000000");
47     public static final String RAND_1 = "00112233445566778899AABBCCDDEEFF";
48     public static final byte[] RAND_1_BYTES = hexStringToByteArray(RAND_1);
49     public static final String RAND_2 = "FFEEDDCCBBAA99887766554433221100";
50     public static final byte[] RAND_2_BYTES = hexStringToByteArray(RAND_2);
51     public static final byte[] AT_RAND_SIM = hexStringToByteArray("01090000" + RAND_1 + RAND_2);
52     public static final byte[] AT_RAND_AKA = hexStringToByteArray("01050000" + RAND_1);
53     public static final byte[] AT_PADDING = hexStringToByteArray("0602000000000000");
54     public static final String MAC = "112233445566778899AABBCCDDEEFF11";
55     public static final byte[] MAC_BYTES = hexStringToByteArray(MAC);
56     public static final byte[] AT_MAC = hexStringToByteArray("0B050000" + MAC);
57     public static final String COUNTER = "000A";
58     public static final int COUNTER_INT = Integer.parseInt(COUNTER, 16 /* radix */);
59     public static final byte[] AT_COUNTER = hexStringToByteArray("1301" + COUNTER);
60     public static final byte[] AT_COUNTER_TOO_SMALL = hexStringToByteArray("14010000");
61     public static final String NONCE_S = "0123456789ABCDEFFEDCBA9876543210";
62     public static final byte[] AT_NONCE_S = hexStringToByteArray("15050000" + NONCE_S);
63     public static final String NOTIFICATION_CODE = "8000";
64     public static final byte[] AT_NOTIFICATION = hexStringToByteArray("0C01" + NOTIFICATION_CODE);
65     public static final String ERROR_CODE = "0001";
66     public static final byte[] AT_CLIENT_ERROR_CODE = hexStringToByteArray("1601" + ERROR_CODE);
67     public static final String AUTN = "0123456789ABCDEFFEDCBA9876543210";
68     public static final byte[] AUTN_BYTES = hexStringToByteArray(AUTN);
69     public static final byte[] AT_AUTN = hexStringToByteArray("02050000" + AUTN);
70     public static final String RES = "1122334455";
71     public static final byte[] RES_BYTES = hexStringToByteArray(RES);
72     public static final byte[] AT_RES = hexStringToByteArray("03030028" + RES + "000000");
73     public static final String AUTS = "112233445566778899AABBCCDDEE";
74     public static final byte[] AUTS_BYTES = hexStringToByteArray(AUTS);
75     public static final byte[] AT_AUTS = hexStringToByteArray("0404" + AUTS);
76     public static final byte[] AT_BIDDING_SUPPORTS_AKA_PRIME = hexStringToByteArray("88018000");
77     public static final byte[] AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME =
78             hexStringToByteArray("88010000");
79 
80     // Network Name = "android.net"
81     public static final String NETWORK_NAME_HEX = "616E64726F69642E6E6574";
82     public static final byte[] NETWORK_NAME_BYTES = hexStringToByteArray(NETWORK_NAME_HEX);
83     public static final byte[] AT_KDF_INPUT =
84             hexStringToByteArray("1704000B" + NETWORK_NAME_HEX + "00");
85     public static final byte[] AT_KDF_INPUT_EMPTY_NETWORK_NAME = hexStringToByteArray("17010000");
86     public static final int KDF_VERSION = 1;
87     public static final byte[] AT_KDF = hexStringToByteArray("18010001");
88 
89     public static final byte[] AT_VERSION_LIST_INVALID_LENGTH = hexStringToByteArray("0F020003");
90     public static final byte[] AT_SELECTED_VERSION_INVALID_LENGTH =
91             hexStringToByteArray("10020001");
92     public static final byte[] AT_NONCE_INVALID_LENGTH =
93             hexStringToByteArray("07060000" + NONCE_MT_STRING);
94     public static final byte[] PERMANENT_ID_INVALID_LENGTH = hexStringToByteArray("0A020000");
95     public static final byte[] ANY_ID_INVALID_LENGTH = hexStringToByteArray("0D020000");
96     public static final byte[] FULL_AUTH_ID_INVALID_LENGTH = hexStringToByteArray("11020000");
97     public static final byte[] AT_RAND_SIM_INVALID_NUM_RANDS =
98             hexStringToByteArray("01050000" + RAND_1);
99     public static final byte[] AT_RAND_SIM_DUPLICATE_RANDS =
100             hexStringToByteArray("01090000" + RAND_1 + RAND_1);
101     public static final byte[] AT_RAND_AKA_INVALID_LENGTH = hexStringToByteArray("01010000");
102     public static final byte[] AT_PADDING_INVALID_PADDING = hexStringToByteArray("0601FFFF");
103     public static final byte[] AT_MAC_INVALID_LENGTH = hexStringToByteArray("0B06");
104     public static final byte[] AT_COUNTER_INVALID_LENGTH = hexStringToByteArray("1302");
105     public static final byte[] AT_COUNTER_TOO_SMALL_INVALID_LENGTH = hexStringToByteArray("1402");
106     public static final byte[] AT_NONCE_S_INVALID_LENGTH = hexStringToByteArray("1506");
107     public static final byte[] AT_NOTIFICATION_INVALID_LENGTH = hexStringToByteArray("0C02");
108     public static final byte[] AT_NOTIFICATION_INVALID_STATE = hexStringToByteArray("0C01C000");
109     public static final byte[] AT_CLIENT_ERROR_CODE_INVALID_LENGTH = hexStringToByteArray("1602");
110     public static final byte[] AT_AUTN_INVALID_LENGTH = hexStringToByteArray("02010000");
111     public static final byte[] AT_RES_INVALID_RES_LENGTH =
112             hexStringToByteArray("030300241122334450000000");
113     public static final byte[] AT_RES_SHORT_RES =
114             hexStringToByteArray("0302000811000000");
115     public static final byte[] AT_RES_LONG_RES =
116             hexStringToByteArray("0306008800112233445566778899AABBCCDDEEFF11000000");
117     public static final byte[] AT_AUTS_INVALID_LENGTH = hexStringToByteArray("03010000");
118     public static final byte[] AT_KDF_INVALID_LENGTH = hexStringToByteArray("18020001");
119     public static final byte[] AT_BIDDING_INVALID_LENGTH = hexStringToByteArray("88020000");
120 }
121