1 /* 2 * Copyright (C) 2018 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.annotation.NonNull; 19 import android.net.ipsec.ike.ChildSessionCallback; 20 import android.net.ipsec.ike.IkeSessionCallback; 21 22 /** 23 * This exception is thrown if any IKE message has a syntax error. 24 * 25 * <p>This exception indicates that the IKE message that was received was invalid because some type, 26 * length, or value was out of range or because the request was rejected for policy reasons. 27 * 28 * @see <a href="https://tools.ietf.org/html/rfc7296#section-3.10.1">RFC 7296, Internet Key Exchange 29 * Protocol Version 2 (IKEv2)</a> 30 * @hide 31 */ 32 // Include INVALID_SYNTAX Notify payload in an encrypted response message if current message is 33 // an encrypted request and cryptographic checksum is valid. Fatal error. 34 public final class InvalidSyntaxException extends IkeProtocolException { 35 private static final int EXPECTED_ERROR_DATA_LEN = 0; 36 37 /** 38 * Construct an instance of InvalidSyntaxException. 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 * 43 * @param message the descriptive message (which is saved for later retrieval by the {@link 44 * #getMessage()} method). 45 */ InvalidSyntaxException(@onNull String message)46 public InvalidSyntaxException(@NonNull String message) { 47 super(ERROR_TYPE_INVALID_SYNTAX, message); 48 } 49 50 /** 51 * Construct a instance of InvalidSyntaxException. 52 * 53 * <p>Except for testing, IKE library users normally do not instantiate this object themselves 54 * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}. 55 * 56 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} 57 * method). 58 */ InvalidSyntaxException(@onNull Throwable cause)59 public InvalidSyntaxException(@NonNull Throwable cause) { 60 super(ERROR_TYPE_INVALID_SYNTAX, cause); 61 } 62 63 /** 64 * Construct a instance of InvalidSyntaxException. 65 * 66 * <p>Except for testing, IKE library users normally do not instantiate this object themselves 67 * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}. 68 * 69 * @param message the descriptive message (which is saved for later retrieval by the {@link 70 * #getMessage()} method). 71 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} 72 * method). 73 */ InvalidSyntaxException(@onNull String message, @NonNull Throwable cause)74 public InvalidSyntaxException(@NonNull String message, @NonNull Throwable cause) { 75 super(ERROR_TYPE_INVALID_SYNTAX, message, cause); 76 } 77 78 /** 79 * Construct a instance of InvalidSyntaxException from a notify payload. 80 * 81 * @param notifyData the notify data included in the payload. 82 * @hide 83 */ InvalidSyntaxException(byte[] notifyData)84 public InvalidSyntaxException(byte[] notifyData) { 85 super(ERROR_TYPE_INVALID_SYNTAX, notifyData); 86 } 87 88 /** @hide */ 89 @Override isValidDataLength(int dataLen)90 protected boolean isValidDataLength(int dataLen) { 91 return EXPECTED_ERROR_DATA_LEN == dataLen; 92 } 93 } 94