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.test.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 = "[email protected]"
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     // Next reauth identity = "4OLUpQCqFyhm1/UgD56anTzYTqJDckibqjU6PlS4sZaiuLc="
48     public static final String REAUTH_IDENTITY_HEX_STRING =
49             "344F4C55705143714679686D312F5567443536616E547A59"
50                     + "54714A44636B6962716A5536506C5334735A6169754C633D";
51     public static final byte[] REAUTH_IDENTITY = hexStringToByteArray(REAUTH_IDENTITY_HEX_STRING);
52     public static final byte[] AT_NEXT_REAUTH_IDENTITY =
53             hexStringToByteArray("850D0030" + REAUTH_IDENTITY_HEX_STRING);
54     public static final String RAND_1 = "00112233445566778899AABBCCDDEEFF";
55     public static final byte[] RAND_1_BYTES = hexStringToByteArray(RAND_1);
56     public static final String RAND_2 = "FFEEDDCCBBAA99887766554433221100";
57     public static final byte[] RAND_2_BYTES = hexStringToByteArray(RAND_2);
58     public static final byte[] AT_RAND_SIM = hexStringToByteArray("01090000" + RAND_1 + RAND_2);
59     public static final byte[] AT_RAND_AKA = hexStringToByteArray("01050000" + RAND_1);
60     public static final byte[] AT_PADDING = hexStringToByteArray("0602000000000000");
61     public static final String MAC = "112233445566778899AABBCCDDEEFF11";
62     public static final byte[] MAC_BYTES = hexStringToByteArray(MAC);
63     public static final byte[] AT_MAC = hexStringToByteArray("0B050000" + MAC);
64     public static final String COUNTER = "000A";
65     public static final int COUNTER_INT = Integer.parseInt(COUNTER, 16 /* radix */);
66     public static final byte[] AT_COUNTER = hexStringToByteArray("1301" + COUNTER);
67     public static final byte[] AT_COUNTER_TOO_SMALL = hexStringToByteArray("14010000");
68     public static final String NONCE_S = "0123456789ABCDEFFEDCBA9876543210";
69     public static final byte[] AT_NONCE_S = hexStringToByteArray("15050000" + NONCE_S);
70     public static final String NOTIFICATION_CODE = "8000";
71     public static final byte[] AT_NOTIFICATION = hexStringToByteArray("0C01" + NOTIFICATION_CODE);
72     public static final String ERROR_CODE = "0001";
73     public static final byte[] AT_CLIENT_ERROR_CODE = hexStringToByteArray("1601" + ERROR_CODE);
74     public static final String AUTN = "0123456789ABCDEFFEDCBA9876543210";
75     public static final byte[] AUTN_BYTES = hexStringToByteArray(AUTN);
76     public static final byte[] AT_AUTN = hexStringToByteArray("02050000" + AUTN);
77     public static final String RES = "1122334455";
78     public static final byte[] RES_BYTES = hexStringToByteArray(RES);
79     public static final byte[] AT_RES = hexStringToByteArray("03030028" + RES + "000000");
80     public static final String AUTS = "112233445566778899AABBCCDDEE";
81     public static final byte[] AUTS_BYTES = hexStringToByteArray(AUTS);
82     public static final byte[] AT_AUTS = hexStringToByteArray("0404" + AUTS);
83     public static final byte[] AT_BIDDING_SUPPORTS_AKA_PRIME = hexStringToByteArray("88018000");
84     public static final byte[] AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME =
85             hexStringToByteArray("88010000");
86     public static final String IV = "DB4786A0ABC44CBB85669F34C72FD604";
87     public static final byte[] IV_BYTES = hexStringToByteArray(IV);
88     public static final byte[] AT_IV = hexStringToByteArray("81050000" + IV);
89     // Network Name = "android.net"
90     public static final String NETWORK_NAME_HEX = "616E64726F69642E6E6574";
91     public static final byte[] NETWORK_NAME_BYTES = hexStringToByteArray(NETWORK_NAME_HEX);
92     public static final byte[] AT_KDF_INPUT =
93             hexStringToByteArray("1704000B" + NETWORK_NAME_HEX + "00");
94     public static final byte[] AT_KDF_INPUT_EMPTY_NETWORK_NAME = hexStringToByteArray("17010000");
95     public static final int KDF_VERSION = 1;
96     public static final byte[] AT_KDF = hexStringToByteArray("18010001");
97 
98     public static final byte[] AT_VERSION_LIST_INVALID_LENGTH = hexStringToByteArray("0F020003");
99     public static final byte[] AT_SELECTED_VERSION_INVALID_LENGTH =
100             hexStringToByteArray("10020001");
101     public static final byte[] AT_NONCE_INVALID_LENGTH =
102             hexStringToByteArray("07060000" + NONCE_MT_STRING);
103     public static final byte[] PERMANENT_ID_INVALID_LENGTH = hexStringToByteArray("0A020000");
104     public static final byte[] ANY_ID_INVALID_LENGTH = hexStringToByteArray("0D020000");
105     public static final byte[] FULL_AUTH_ID_INVALID_LENGTH = hexStringToByteArray("11020000");
106     public static final byte[] AT_RAND_SIM_INVALID_NUM_RANDS =
107             hexStringToByteArray("01050000" + RAND_1);
108     public static final byte[] AT_RAND_SIM_DUPLICATE_RANDS =
109             hexStringToByteArray("01090000" + RAND_1 + RAND_1);
110     public static final byte[] AT_RAND_AKA_INVALID_LENGTH = hexStringToByteArray("01010000");
111     public static final byte[] AT_PADDING_INVALID_PADDING = hexStringToByteArray("0601FFFF");
112     public static final byte[] AT_MAC_INVALID_LENGTH = hexStringToByteArray("0B06");
113     public static final byte[] AT_COUNTER_INVALID_LENGTH = hexStringToByteArray("1302");
114     public static final byte[] AT_COUNTER_TOO_SMALL_INVALID_LENGTH = hexStringToByteArray("1402");
115     public static final byte[] AT_NONCE_S_INVALID_LENGTH = hexStringToByteArray("1506");
116     public static final byte[] AT_NOTIFICATION_INVALID_LENGTH = hexStringToByteArray("0C02");
117     public static final byte[] AT_NOTIFICATION_INVALID_STATE = hexStringToByteArray("0C01C000");
118     public static final byte[] AT_CLIENT_ERROR_CODE_INVALID_LENGTH = hexStringToByteArray("1602");
119     public static final byte[] AT_AUTN_INVALID_LENGTH = hexStringToByteArray("02010000");
120     public static final byte[] AT_RES_INVALID_RES_LENGTH =
121             hexStringToByteArray("030300241122334450000000");
122     public static final byte[] AT_RES_SHORT_RES =
123             hexStringToByteArray("0302000811000000");
124     public static final byte[] AT_RES_LONG_RES =
125             hexStringToByteArray("0306008800112233445566778899AABBCCDDEEFF11000000");
126     public static final byte[] AT_AUTS_INVALID_LENGTH = hexStringToByteArray("03010000");
127     public static final byte[] AT_KDF_INVALID_LENGTH = hexStringToByteArray("18020001");
128     public static final byte[] AT_BIDDING_INVALID_LENGTH = hexStringToByteArray("88020000");
129     public static final byte[] AT_IV_INVALID_LENGTH = hexStringToByteArray("81060000");
130 }
131