1 /* 2 * Copyright (C) 2021 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 android.net.eap; 18 19 import static android.net.eap.EapSessionConfig.EapMethodConfig.EAP_TYPE_AKA; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.net.ipsec.ike.IkeSessionConfiguration; 24 25 import com.android.internal.annotations.VisibleForTesting; 26 27 import java.util.Objects; 28 29 /** 30 * EapAkaInfo represents data provided by the server during EAP AKA authentication 31 */ 32 public final class EapAkaInfo extends EapInfo { 33 /** 34 * Re-authentication ID for next use 35 * 36 * <p>This identity encoding MUST follow the UTF-8 transformation format[RFC3629]. 37 * 38 * @hide 39 */ 40 private final byte[] mReauthId; 41 42 /** @hide */ 43 @VisibleForTesting EapAkaInfo(@ullable byte[] reauthId)44 public EapAkaInfo(@Nullable byte[] reauthId) { 45 super(EAP_TYPE_AKA); 46 mReauthId = reauthId; 47 } 48 EapAkaInfo(Builder builder)49 private EapAkaInfo(Builder builder) { 50 super(EAP_TYPE_AKA); 51 mReauthId = builder.mReauthId; 52 } 53 54 /** 55 * Retrieves re-authentication ID from server for next use. 56 * 57 * @return re-authentication ID 58 * 59 * @see <a href="https://datatracker.ietf.org/doc/html/rfc4187#section-5">RFC 4186, 60 * Extensible Authentication Protocol Method for 3rd Generation Authentication and 61 * Key Agreement (EAP-AKA)</a> 62 */ 63 @Nullable getReauthId()64 public byte[] getReauthId() { 65 return mReauthId; 66 } 67 68 /** 69 * This class can be used to incrementally construct an {@link EapAkaInfo}. 70 * 71 * <p>Except for testing, IKE library users normally do not instantiate {@link EapAkaInfo} 72 * themselves but instead get a reference via {@link IkeSessionConfiguration} 73 */ 74 public static final class Builder { 75 private byte[] mReauthId; 76 77 /** 78 * Sets the re-authentication ID for next use. 79 * 80 * @param reauthId byte[] representing the client's EAP Identity. 81 * @return Builder this, to facilitate chaining. 82 */ 83 @NonNull setReauthId(@onNull byte[] reauthId)84 public Builder setReauthId(@NonNull byte[] reauthId) { 85 Objects.requireNonNull(reauthId, "reauthId must not be null"); 86 this.mReauthId = new byte[reauthId.length]; 87 System.arraycopy(reauthId, 0, this.mReauthId, 0, reauthId.length); 88 return this; 89 } 90 91 /** 92 * Constructs and returns an EapAkaInfo with the information applied to this 93 * Builder. 94 * 95 * @return the EapAkaInfo constructed by this Builder. 96 */ 97 @NonNull build()98 public EapAkaInfo build() { 99 return new EapAkaInfo(this); 100 } 101 } 102 } 103