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 received a request for a nonexistent Child SA. 25 * 26 * <p>This exception is usually caused by a request collision. IKE library will handle it internally 27 * by deleting the Child SA (if it still exists). 28 * 29 * @see <a href="https://tools.ietf.org/html/rfc7296#section-2.25">RFC 7296, Internet Key Exchange 30 * Protocol Version 2 (IKEv2)</a> 31 * @hide 32 */ 33 public final class ChildSaNotFoundException extends IkeProtocolException { 34 private static final int EXPECTED_ERROR_DATA_LEN = 0; 35 36 private final int mIpSecSpi; 37 38 /** 39 * Construct an instance of ChildSaNotFoundException. 40 * 41 * <p>Except for testing, IKE library users normally do not instantiate this object themselves 42 * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}. 43 * 44 * @param spi the SPI of the Child SA (IPsec SA) that does not exist. 45 */ ChildSaNotFoundException(int spi)46 public ChildSaNotFoundException(int spi) { 47 super(ERROR_TYPE_CHILD_SA_NOT_FOUND); 48 mIpSecSpi = spi; 49 } 50 51 /** 52 * Construct a instance of ChildSaNotFoundException from a notify payload. 53 * 54 * @param spi the SPI of the Child SA (IPsec SA) that does not exist. 55 * @param notifyData the notify data included in the payload. 56 * @hide 57 */ ChildSaNotFoundException(int spi, byte[] notifyData)58 public ChildSaNotFoundException(int spi, byte[] notifyData) { 59 super(ERROR_TYPE_CHILD_SA_NOT_FOUND, notifyData); 60 mIpSecSpi = spi; 61 } 62 63 /** @hide */ 64 @Override isValidDataLength(int dataLen)65 protected boolean isValidDataLength(int dataLen) { 66 return EXPECTED_ERROR_DATA_LEN == dataLen; 67 } 68 69 /** Returns the SPI of the Child SA (IPsec SA) that does not exist. */ getIpSecSpi()70 public int getIpSecSpi() { 71 return mIpSecSpi; 72 } 73 74 /** 75 * Returns the error code for metrics 76 * 77 * @hide 78 */ 79 @Override getMetricsErrorCode()80 public int getMetricsErrorCode() { 81 return IkeMetrics.IKE_ERROR_PROTOCOL_CHILD_SA_NOT_FOUND; 82 } 83 } 84