1 /* 2 * Copyright (C) 2020 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 package android.net.ipsec.ike.exceptions; 17 18 import android.net.ipsec.ike.ChildSessionCallback; 19 import android.net.ipsec.ike.IkeSessionCallback; 20 21 import com.android.internal.net.ipsec.ike.utils.IkeMetrics; 22 23 /** 24 * This exception is thrown if the remote server requires a single pair of addresses as selectors. 25 * 26 * <p>This exception indicates that the remote server is only willing to accept Traffic Selectors 27 * specifying a single pair of addresses. Callers may retry Child creation with only the specific 28 * traffic it is trying to forward. 29 * 30 * @see <a href="https://tools.ietf.org/html/rfc7296#section-2.9">RFC 7296, Internet Key Exchange 31 * Protocol Version 2 (IKEv2)</a> 32 * @hide 33 */ 34 public class SinglePairRequiredException extends IkeProtocolException { 35 private static final int EXPECTED_ERROR_DATA_LEN = 0; 36 37 /** 38 * Construct an instance of SinglePairRequiredException. 39 * 40 * <p>Except for testing, IKE library users normally do not instantiate this object themselves 41 * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}. 42 */ SinglePairRequiredException()43 public SinglePairRequiredException() { 44 super(ERROR_TYPE_SINGLE_PAIR_REQUIRED); 45 } 46 47 /** 48 * Construct a instance of SinglePairRequiredException from a notify payload. 49 * 50 * @param notifyData the notify data included in the payload. 51 * @hide 52 */ SinglePairRequiredException(byte[] notifyData)53 public SinglePairRequiredException(byte[] notifyData) { 54 super(ERROR_TYPE_SINGLE_PAIR_REQUIRED, notifyData); 55 } 56 57 /** @hide */ 58 @Override isValidDataLength(int dataLen)59 protected boolean isValidDataLength(int dataLen) { 60 return EXPECTED_ERROR_DATA_LEN == dataLen; 61 } 62 63 /** 64 * Returns the error code for metrics 65 * 66 * @hide 67 */ 68 @Override getMetricsErrorCode()69 public int getMetricsErrorCode() { 70 return IkeMetrics.IKE_ERROR_PROTOCOL_SINGLE_PAIR_REQUIRED; 71 } 72 } 73