| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.net; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
|
| 22 |
import com.android.internal.net.VpnProfile; |
| 23 |
|
| 24 |
import java.io.IOException; |
| 25 |
import java.lang.annotation.Retention; |
| 26 |
import java.lang.annotation.RetentionPolicy; |
| 27 |
import java.security.GeneralSecurityException; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public abstract class PlatformVpnProfile { |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
@Retention(RetentionPolicy.SOURCE) |
| 47 |
@IntDef({ |
| 48 |
TYPE_IKEV2_IPSEC_USER_PASS, |
| 49 |
TYPE_IKEV2_IPSEC_PSK, |
| 50 |
TYPE_IKEV2_IPSEC_RSA, |
| 51 |
}) |
| 52 |
public static @interface PlatformVpnType {} |
| 53 |
|
| 54 |
public static final int TYPE_IKEV2_IPSEC_USER_PASS = VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS; |
| 55 |
public static final int TYPE_IKEV2_IPSEC_PSK = VpnProfile.TYPE_IKEV2_IPSEC_PSK; |
| 56 |
public static final int TYPE_IKEV2_IPSEC_RSA = VpnProfile.TYPE_IKEV2_IPSEC_RSA; |
| 57 |
|
| 58 |
|
| 59 |
public static final int MAX_MTU_DEFAULT = 1360; |
| 60 |
|
| 61 |
|
| 62 |
@PlatformVpnType protected final int mType; |
| 63 |
|
| 64 |
|
| 65 |
protected final boolean mExcludeLocalRoutes; |
| 66 |
|
| 67 |
protected final boolean mRequiresInternetValidation; |
| 68 |
|
| 69 |
|
| 70 |
PlatformVpnProfile(@PlatformVpnType int type, boolean excludeLocalRoutes, |
| 71 |
boolean requiresValidation) { |
| 72 |
mType = type; |
| 73 |
mExcludeLocalRoutes = excludeLocalRoutes; |
| 74 |
mRequiresInternetValidation = requiresValidation; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
@PlatformVpnType |
| 79 |
public final int getType() { |
| 80 |
return mType; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public final boolean areLocalRoutesExcluded() { |
| 87 |
return mExcludeLocalRoutes; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public final boolean isInternetValidationRequired() { |
| 104 |
return mRequiresInternetValidation; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
@NonNull |
| 109 |
public final String getTypeString() { |
| 110 |
switch (mType) { |
| 111 |
case TYPE_IKEV2_IPSEC_USER_PASS: |
| 112 |
return "IKEv2/IPsec Username/Password"; |
| 113 |
case TYPE_IKEV2_IPSEC_PSK: |
| 114 |
return "IKEv2/IPsec Preshared key"; |
| 115 |
case TYPE_IKEV2_IPSEC_RSA: |
| 116 |
return "IKEv2/IPsec RSA Digital Signature"; |
| 117 |
default: |
| 118 |
return "Unknown VPN profile type"; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
@NonNull |
| 124 |
public abstract VpnProfile toVpnProfile() throws IOException, GeneralSecurityException; |
| 125 |
|
| 126 |
|
| 127 |
@NonNull |
| 128 |
public static PlatformVpnProfile fromVpnProfile(@NonNull VpnProfile profile) |
| 129 |
throws IOException, GeneralSecurityException { |
| 130 |
switch (profile.type) { |
| 131 |
case TYPE_IKEV2_IPSEC_USER_PASS: |
| 132 |
case TYPE_IKEV2_IPSEC_PSK: |
| 133 |
case TYPE_IKEV2_IPSEC_RSA: |
| 134 |
return Ikev2VpnProfile.fromVpnProfile(profile); |
| 135 |
default: |
| 136 |
throw new IllegalArgumentException("Unknown VPN Profile type"); |
| 137 |
} |
| 138 |
} |
| 139 |
} |