• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.net.ipsec.ike.exceptions;
17 
18 import android.net.ipsec.ike.ChildSessionCallback;
19 import android.net.ipsec.ike.IkeSessionCallback;
20 
21 /**
22  * This exception is thrown when the remote server received a message with out-of-window-size ID.
23  *
24  * @see <a href="https://tools.ietf.org/html/rfc7296#section-2.3">RFC 7296, Internet Key Exchange
25  *     Protocol Version 2 (IKEv2)</a>
26  * @hide
27  */
28 // Notifications based on this exception contains the four-octet invalid message ID. It MUST only
29 // ever be sent in an INFORMATIONAL request. Sending this notification is OPTIONAL, and
30 // notifications of this type MUST be rate limited.
31 public final class InvalidMessageIdException extends IkeProtocolException {
32     private static final int EXPECTED_ERROR_DATA_LEN = 4;
33 
34     /**
35      * Construct a instance of InvalidMessageIdException
36      *
37      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
38      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
39      *
40      * @param messageId the invalid Message ID.
41      */
InvalidMessageIdException(int messageId)42     public InvalidMessageIdException(int messageId) {
43         super(
44                 ERROR_TYPE_INVALID_MESSAGE_ID,
45                 integerToByteArray(messageId, EXPECTED_ERROR_DATA_LEN));
46     }
47 
48     /**
49      * Construct a instance of InvalidMessageIdException from a notify payload.
50      *
51      * @param notifyData the notify data included in the payload.
52      * @hide
53      */
InvalidMessageIdException(byte[] notifyData)54     public InvalidMessageIdException(byte[] notifyData) {
55         super(ERROR_TYPE_INVALID_MESSAGE_ID, notifyData);
56     }
57 
58     /**
59      * Return the invalid message ID included in this exception.
60      *
61      * @return the message ID.
62      */
getMessageId()63     public int getMessageId() {
64         return byteArrayToInteger(getErrorData());
65     }
66 
67     /** @hide */
68     @Override
isValidDataLength(int dataLen)69     protected boolean isValidDataLength(int dataLen) {
70         return EXPECTED_ERROR_DATA_LEN == dataLen;
71     }
72 }
73