• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import com.android.internal.net.ipsec.ike.utils.IkeMetrics;
23 
24 /**
25  * This exception is thrown when IKE authentication failed.
26  *
27  * @see <a href="https://tools.ietf.org/html/rfc7296#section-2.21.2">RFC 7296, Internet Key Exchange
28  *     Protocol Version 2 (IKEv2)</a>
29  * @hide
30  */
31 public final class AuthenticationFailedException extends IkeProtocolException {
32     private static final int EXPECTED_ERROR_DATA_LEN = 0;
33 
34     /**
35      * Construct a instance of AuthenticationFailedException.
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 message the descriptive message (which is saved for later retrieval by the {@link
41      *     #getMessage()} method).
42      */
AuthenticationFailedException(@onNull String message)43     public AuthenticationFailedException(@NonNull String message) {
44         super(ERROR_TYPE_AUTHENTICATION_FAILED, message);
45     }
46 
47     /**
48      * Construct a instance of AuthenticationFailedException.
49      *
50      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
51      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
52      *
53      * @param cause the cause (which is saved for later retrieval by the {@link #getCause()}
54      *     method).
55      */
AuthenticationFailedException(@onNull Throwable cause)56     public AuthenticationFailedException(@NonNull Throwable cause) {
57         super(ERROR_TYPE_AUTHENTICATION_FAILED, cause);
58     }
59 
60     /**
61      * Construct a instance of AuthenticationFailedException from a notify payload.
62      *
63      * @param notifyData the notify data included in the payload.
64      * @hide
65      */
AuthenticationFailedException(byte[] notifyData)66     public AuthenticationFailedException(byte[] notifyData) {
67         super(ERROR_TYPE_AUTHENTICATION_FAILED, notifyData);
68     }
69 
70     /** @hide */
71     @Override
isValidDataLength(int dataLen)72     protected boolean isValidDataLength(int dataLen) {
73         return EXPECTED_ERROR_DATA_LEN == dataLen;
74     }
75 
76     /**
77      * Returns the error code for metrics
78      *
79      * @hide
80      */
81     @Override
getMetricsErrorCode()82     public int getMetricsErrorCode() {
83         return IkeMetrics.IKE_ERROR_PROTOCOL_AUTHENTICATION_FAILED;
84     }
85 }
86