Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java
41161 views
/*1* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26*27* (C) Copyright IBM Corp. 1999 All Rights Reserved.28* Copyright 1997 The Open Group Research Institute. All rights reserved.29*/3031package sun.security.krb5.internal;3233import sun.security.action.GetBooleanAction;3435import java.util.Hashtable;3637// Constants and other defined values from RFC 41203839public class Krb5 {4041//Recommended KDC values42public static final int DEFAULT_ALLOWABLE_CLOCKSKEW = 5 * 60; //5 minutes43public static final int DEFAULT_MINIMUM_LIFETIME = 5 * 60; //5 minutes44public static final int DEFAULT_MAXIMUM_RENEWABLE_LIFETIME = 7 * 24 * 60 * 60; //1 week45public static final int DEFAULT_MAXIMUM_TICKET_LIFETIME = 24 * 60 * 60; //1 day46public static final boolean DEFAULT_FORWARDABLE_ALLOWED = true;47public static final boolean DEFAULT_PROXIABLE_ALLOWED = true;48public static final boolean DEFAULT_POSTDATE_ALLOWED = true;49public static final boolean DEFAULT_RENEWABLE_ALLOWED = true;50public static final boolean AP_EMPTY_ADDRESSES_ALLOWED = true;5152//AP_REQ Options5354public static final int AP_OPTS_RESERVED = 0;55public static final int AP_OPTS_USE_SESSION_KEY = 1;56public static final int AP_OPTS_MUTUAL_REQUIRED = 2;57public static final int AP_OPTS_MAX = 31;5859//Ticket Flags6061public static final int TKT_OPTS_RESERVED = 0;62public static final int TKT_OPTS_FORWARDABLE = 1;63public static final int TKT_OPTS_FORWARDED = 2;64public static final int TKT_OPTS_PROXIABLE = 3;65public static final int TKT_OPTS_PROXY = 4;66public static final int TKT_OPTS_MAY_POSTDATE = 5;67public static final int TKT_OPTS_POSTDATED = 6;68public static final int TKT_OPTS_INVALID = 7;69public static final int TKT_OPTS_RENEWABLE = 8;70public static final int TKT_OPTS_INITIAL = 9;71public static final int TKT_OPTS_PRE_AUTHENT = 10;72public static final int TKT_OPTS_HW_AUTHENT = 11;73public static final int TKT_OPTS_DELEGATE = 13;74public static final int TKT_OPTS_ENC_PA_REP = 15;75public static final int TKT_OPTS_MAX = 31;7677// KDC Options78// (option values defined in KDCOptions.java)79public static final int KDC_OPTS_MAX = 31;8081// KerberosFlags82public static final int KRB_FLAGS_MAX = 31;8384//Last Request types8586public static final int LRTYPE_NONE = 0;87public static final int LRTYPE_TIME_OF_INITIAL_TGT = 1;88public static final int LRTYPE_TIME_OF_INITIAL_REQ = 2;89public static final int LRTYPE_TIME_OF_NEWEST_TGT = 3;90public static final int LRTYPE_TIME_OF_LAST_RENEWAL = 4;91public static final int LRTYPE_TIME_OF_LAST_REQ = 5;9293//Host address lengths9495public static final int ADDR_LEN_INET = 4;96public static final int ADDR_LEN_CHAOS = 2;97public static final int ADDR_LEN_OSI = 0; //means variable98public static final int ADDR_LEN_XNS = 6;99public static final int ADDR_LEN_APPLETALK = 3;100public static final int ADDR_LEN_DECNET = 2;101102//Host address types103104public static final int ADDRTYPE_UNIX = 1; // Local105public static final int ADDRTYPE_INET = 2; // Internet106public static final int ADDRTYPE_IMPLINK = 3; // Arpanet107public static final int ADDRTYPE_PUP = 4; // PUP108public static final int ADDRTYPE_CHAOS = 5; // CHAOS109public static final int ADDRTYPE_XNS = 6; // XEROX Network Services110public static final int ADDRTYPE_IPX = 6; // IPX111public static final int ADDRTYPE_ISO = 7; // ISO112public static final int ADDRTYPE_ECMA = 8; // European Computer Manufacturers113public static final int ADDRTYPE_DATAKIT = 9; // Datakit114public static final int ADDRTYPE_CCITT = 10; // CCITT115public static final int ADDRTYPE_SNA = 11; // SNA116public static final int ADDRTYPE_DECNET = 12; // DECnet117public static final int ADDRTYPE_DLI = 13; // Direct Data Link Interface118public static final int ADDRTYPE_LAT = 14; // LAT119public static final int ADDRTYPE_HYLINK = 15; // NSC Hyperchannel120public static final int ADDRTYPE_APPLETALK = 16; // AppleTalk121public static final int ADDRTYPE_NETBIOS = 17; // NetBios122public static final int ADDRTYPE_VOICEVIEW = 18; // VoiceView123public static final int ADDRTYPE_FIREFOX = 19; // Firefox124public static final int ADDRTYPE_BAN = 21; // Banyan125public static final int ADDRTYPE_ATM = 22; // ATM126public static final int ADDRTYPE_INET6 = 24; // Internet Protocol V6127128//IP Transport UDP Port for KDC Messages129130public static final int KDC_INET_DEFAULT_PORT = 88;131132// number of retries before giving up133134public static final int KDC_RETRY_LIMIT = 3;135public static final int KDC_DEFAULT_UDP_PREF_LIMIT = 1465;136public static final int KDC_HARD_UDP_LIMIT = 32700;137138//OSI authentication mechanism OID139140//public static final int[] OSI_AUTH_MECH_TYPE = { /*iso*/ 1, /*org*/ 3,141// /*dod*/ 5, /*internet*/ 1, /*security*/ 5, /*kerberosv5*/ 2 };142143//Protocol constants and associated values144145//Key Types146public static final int KEYTYPE_NULL = 0;147public static final int KEYTYPE_DES = 1;148149public static final int KEYTYPE_DES3 = 2;150public static final int KEYTYPE_AES = 3;151public static final int KEYTYPE_ARCFOUR_HMAC = 4;152153154//----------------------------------------+-----------------155// padata type |padata-type value156//----------------------------------------+-----------------157public static final int PA_TGS_REQ = 1;158public static final int PA_ENC_TIMESTAMP = 2;159public static final int PA_PW_SALT = 3;160161// new preauth types162public static final int PA_ETYPE_INFO = 11;163public static final int PA_ETYPE_INFO2 = 19;164165// S4U2user info166public static final int PA_FOR_USER = 129;167public static final int PA_PAC_OPTIONS = 167;168169// FAST (RFC 6806)170public static final int PA_REQ_ENC_PA_REP = 149;171172//-------------------------------+-------------173//authorization data type |ad-type value174//-------------------------------+-------------175//reserved values 0-63176public static final int OSF_DCE = 64;177public static final int SESAME = 65;178179//----------------------------------------------+-----------------180//alternate authentication type |method-type value181//----------------------------------------------+-----------------182// reserved values 0-63183public static final int ATT_CHALLENGE_RESPONSE = 64;184185//--------------------------------------------+-------------186//transited encoding type |tr-type value187//--------------------------------------------+-------------188public static final int DOMAIN_X500_COMPRESS = 1;189// reserved values all others190191//----------------------------+-------+-----------------------------------------192// Label |Value |Meaning193//----------------------------+-------+-----------------------------------------194public static final int PVNO = 5; // current Kerberos protocol version number195public static final int AUTHNETICATOR_VNO = 5; // current authenticator version number196public static final int TICKET_VNO = 5; // current ticket version number197198//message types199200// there are several message sub-components not included here201public static final int KRB_AS_REQ = 10; //Request for initial authentication202public static final int KRB_AS_REP = 11; //Response to KRB_AS_REQ request203public static final int KRB_TGS_REQ = 12; //Request for authentication based on TGT204public static final int KRB_TGS_REP = 13; //Response to KRB_TGS_REQ request205public static final int KRB_AP_REQ = 14; //application request to server206public static final int KRB_AP_REP = 15; //Response to KRB_AP_REQ_MUTUAL207public static final int KRB_SAFE = 20; //Safe (checksummed) application message208public static final int KRB_PRIV = 21; //Private (encrypted) application message209public static final int KRB_CRED = 22; //Private (encrypted) message to forward credentials210public static final int KRB_ERROR = 30; //Error response211212//message component types213214public static final int KRB_TKT = 1; //Ticket215public static final int KRB_AUTHENTICATOR = 2; //Authenticator216public static final int KRB_ENC_TKT_PART = 3; //Encrypted ticket part217public static final int KRB_ENC_AS_REP_PART = 25; //Encrypted initial authentication part218public static final int KRB_ENC_TGS_REP_PART = 26; //Encrypted TGS request part219public static final int KRB_ENC_AP_REP_PART = 27; //Encrypted application request part220public static final int KRB_ENC_KRB_PRIV_PART = 28; //Encrypted application message part221public static final int KRB_ENC_KRB_CRED_PART = 29; //Encrypted credentials forward part222223224//error codes225226public static final int KDC_ERR_NONE = 0; //No error227public static final int KDC_ERR_NAME_EXP = 1; //Client's entry in database expired228public static final int KDC_ERR_SERVICE_EXP = 2; //Server's entry in database has expired229public static final int KDC_ERR_BAD_PVNO = 3; //Requested protocol version number not supported230public static final int KDC_ERR_C_OLD_MAST_KVNO = 4; //Client's key encrypted in old master key231public static final int KDC_ERR_S_OLD_MAST_KVNO = 5; //Server's key encrypted in old master key232public static final int KDC_ERR_C_PRINCIPAL_UNKNOWN = 6; //Client not found in Kerberos database233public static final int KDC_ERR_S_PRINCIPAL_UNKNOWN = 7; //Server not found in Kerberos database234public static final int KDC_ERR_PRINCIPAL_NOT_UNIQUE = 8; //Multiple principal entries in database235public static final int KDC_ERR_NULL_KEY = 9; //The client or server has a null key236public static final int KDC_ERR_CANNOT_POSTDATE = 10; //Ticket not eligible for postdating237public static final int KDC_ERR_NEVER_VALID = 11; //Requested start time is later than end time238public static final int KDC_ERR_POLICY = 12; //KDC policy rejects request239public static final int KDC_ERR_BADOPTION = 13; //KDC cannot accommodate requested option240public static final int KDC_ERR_ETYPE_NOSUPP = 14; //KDC has no support for encryption type241public static final int KDC_ERR_SUMTYPE_NOSUPP = 15; //KDC has no support for checksum type242public static final int KDC_ERR_PADATA_TYPE_NOSUPP = 16; //KDC has no support for padata type243public static final int KDC_ERR_TRTYPE_NOSUPP = 17; //KDC has no support for transited type244public static final int KDC_ERR_CLIENT_REVOKED = 18; //Clients credentials have been revoked245public static final int KDC_ERR_SERVICE_REVOKED = 19; //Credentials for server have been revoked246public static final int KDC_ERR_TGT_REVOKED = 20; //TGT has been revoked247public static final int KDC_ERR_CLIENT_NOTYET = 21; //Client not yet valid - try again later248public static final int KDC_ERR_SERVICE_NOTYET = 22; //Server not yet valid - try again later249public static final int KDC_ERR_KEY_EXPIRED = 23; //Password has expired - change password to reset250public static final int KDC_ERR_PREAUTH_FAILED = 24; //Pre-authentication information was invalid251public static final int KDC_ERR_PREAUTH_REQUIRED = 25; //Additional pre-authentication required252public static final int KRB_AP_ERR_BAD_INTEGRITY = 31; //Integrity check on decrypted field failed253public static final int KRB_AP_ERR_TKT_EXPIRED = 32; //Ticket expired254public static final int KRB_AP_ERR_TKT_NYV = 33; //Ticket not yet valid255public static final int KRB_AP_ERR_REPEAT = 34; //Request is a replay256public static final int KRB_AP_ERR_NOT_US = 35; //The ticket isn't for us257public static final int KRB_AP_ERR_BADMATCH = 36; //Ticket and authenticator don't match258public static final int KRB_AP_ERR_SKEW = 37; //Clock skew too great259public static final int KRB_AP_ERR_BADADDR = 38; //Incorrect net address260public static final int KRB_AP_ERR_BADVERSION = 39; //Protocol version mismatch261public static final int KRB_AP_ERR_MSG_TYPE = 40; //Invalid msg type262public static final int KRB_AP_ERR_MODIFIED = 41; //Message stream modified263public static final int KRB_AP_ERR_BADORDER = 42; //Message out of order264public static final int KRB_AP_ERR_BADKEYVER = 44; //Specified version of key is not available265public static final int KRB_AP_ERR_NOKEY = 45; //Service key not available266public static final int KRB_AP_ERR_MUT_FAIL = 46; //Mutual authentication failed267public static final int KRB_AP_ERR_BADDIRECTION = 47; //Incorrect message direction268public static final int KRB_AP_ERR_METHOD = 48; //Alternative authentication method required269public static final int KRB_AP_ERR_BADSEQ = 49; //Incorrect sequence number in message270public static final int KRB_AP_ERR_INAPP_CKSUM = 50; //Inappropriate type of checksum in message271public static final int KRB_ERR_RESPONSE_TOO_BIG = 52; //Response too big for UDP, retry with TCP272public static final int KRB_ERR_GENERIC = 60; //Generic error (description in e-text)273public static final int KRB_ERR_FIELD_TOOLONG = 61; //Field is too long for this implementation274public static final int KRB_ERR_WRONG_REALM = 68; //Wrong realm275public static final int KRB_CRYPTO_NOT_SUPPORT = 100; //Client does not support this crypto type276public static final int KRB_AP_ERR_NOREALM = 62;277public static final int KRB_AP_ERR_GEN_CRED = 63;278// public static final int KRB_AP_ERR_CKSUM_NOKEY =101; //Lack of the key to generate the checksum279// error codes specific to this implementation280public static final int KRB_AP_ERR_REQ_OPTIONS = 101; //Invalid TGS_REQ281public static final int API_INVALID_ARG = 400; //Invalid argument282283public static final int BITSTRING_SIZE_INVALID = 500; //BitString size does not match input byte array284public static final int BITSTRING_INDEX_OUT_OF_BOUNDS = 501; //BitString bit index does not fall within size285public static final int BITSTRING_BAD_LENGTH = 502; //BitString length is wrong for the expected type286287public static final int REALM_ILLCHAR = 600; //Illegal character in realm name; one of: '/', ':', '\0'288public static final int REALM_NULL = 601; //Null realm name289290public static final int ASN1_BAD_TIMEFORMAT = 900; //Input not in GeneralizedTime format291public static final int ASN1_MISSING_FIELD = 901; //Structure is missing a required field292public static final int ASN1_MISPLACED_FIELD = 902; //Unexpected field number293public static final int ASN1_TYPE_MISMATCH = 903; //Type numbers are inconsistent294public static final int ASN1_OVERFLOW = 904; //Value too large295public static final int ASN1_OVERRUN = 905; //Encoding ended unexpectedly296public static final int ASN1_BAD_ID = 906; //Identifier doesn't match expected value297public static final int ASN1_BAD_LENGTH = 907; //Length doesn't match expected value298public static final int ASN1_BAD_FORMAT = 908; //Badly-formatted encoding299public static final int ASN1_PARSE_ERROR = 909; //Parse error300public static final int ASN1_BAD_CLASS = 910; //Bad class number301public static final int ASN1_BAD_TYPE = 911; //Bad type number302public static final int ASN1_BAD_TAG = 912; //Bad tag number303public static final int ASN1_UNSUPPORTED_TYPE = 913; //Unsupported ASN.1 type encountered304public static final int ASN1_CANNOT_ENCODE = 914; //Encoding failed due to invalid parameter(s)305306private static Hashtable<Integer,String> errMsgList;307308public static String getErrorMessage(int i) {309return errMsgList.get(i);310}311312// Warning: used by NativeCreds.c313public static final boolean DEBUG = GetBooleanAction314.privilegedGetProperty("sun.security.krb5.debug");315316public static final sun.security.util.HexDumpEncoder hexDumper =317new sun.security.util.HexDumpEncoder();318319static {320errMsgList = new Hashtable<Integer,String> ();321errMsgList.put(KDC_ERR_NONE, "No error");322errMsgList.put(KDC_ERR_NAME_EXP, "Client's entry in database expired");323errMsgList.put(KDC_ERR_SERVICE_EXP, "Server's entry in database has expired");324errMsgList.put(KDC_ERR_BAD_PVNO, "Requested protocol version number not supported");325errMsgList.put(KDC_ERR_C_OLD_MAST_KVNO, "Client's key encrypted in old master key");326errMsgList.put(KDC_ERR_S_OLD_MAST_KVNO, "Server's key encrypted in old master key");327errMsgList.put(KDC_ERR_C_PRINCIPAL_UNKNOWN, "Client not found in Kerberos database");328errMsgList.put(KDC_ERR_S_PRINCIPAL_UNKNOWN, "Server not found in Kerberos database");329errMsgList.put(KDC_ERR_PRINCIPAL_NOT_UNIQUE, "Multiple principal entries in database");330errMsgList.put(KDC_ERR_NULL_KEY, "The client or server has a null key");331errMsgList.put(KDC_ERR_CANNOT_POSTDATE, "Ticket not eligible for postdating");332errMsgList.put(KDC_ERR_NEVER_VALID, "Requested start time is later than end time");333errMsgList.put(KDC_ERR_POLICY, "KDC policy rejects request");334errMsgList.put(KDC_ERR_BADOPTION, "KDC cannot accommodate requested option");335errMsgList.put(KDC_ERR_ETYPE_NOSUPP, "KDC has no support for encryption type");336errMsgList.put(KDC_ERR_SUMTYPE_NOSUPP, "KDC has no support for checksum type");337errMsgList.put(KDC_ERR_PADATA_TYPE_NOSUPP, "KDC has no support for padata type");338errMsgList.put(KDC_ERR_TRTYPE_NOSUPP, "KDC has no support for transited type");339errMsgList.put(KDC_ERR_CLIENT_REVOKED, "Clients credentials have been revoked");340errMsgList.put(KDC_ERR_SERVICE_REVOKED, "Credentials for server have been revoked");341errMsgList.put(KDC_ERR_TGT_REVOKED, "TGT has been revoked");342errMsgList.put(KDC_ERR_CLIENT_NOTYET, "Client not yet valid - try again later");343errMsgList.put(KDC_ERR_SERVICE_NOTYET, "Server not yet valid - try again later");344errMsgList.put(KDC_ERR_KEY_EXPIRED, "Password has expired - change password to reset");345errMsgList.put(KDC_ERR_PREAUTH_FAILED, "Pre-authentication information was invalid");346errMsgList.put(KDC_ERR_PREAUTH_REQUIRED, "Additional pre-authentication required");347errMsgList.put(KRB_AP_ERR_BAD_INTEGRITY, "Integrity check on decrypted field failed");348errMsgList.put(KRB_AP_ERR_TKT_EXPIRED, "Ticket expired");349errMsgList.put(KRB_AP_ERR_TKT_NYV, "Ticket not yet valid");350errMsgList.put(KRB_AP_ERR_REPEAT, "Request is a replay");351errMsgList.put(KRB_AP_ERR_NOT_US, "The ticket isn't for us");352errMsgList.put(KRB_AP_ERR_BADMATCH, "Ticket and authenticator don't match");353errMsgList.put(KRB_AP_ERR_SKEW, "Clock skew too great");354errMsgList.put(KRB_AP_ERR_BADADDR, "Incorrect net address");355errMsgList.put(KRB_AP_ERR_BADVERSION, "Protocol version mismatch");356errMsgList.put(KRB_AP_ERR_MSG_TYPE, "Invalid msg type");357errMsgList.put(KRB_AP_ERR_MODIFIED, "Message stream modified");358errMsgList.put(KRB_AP_ERR_BADORDER, "Message out of order");359errMsgList.put(KRB_AP_ERR_BADKEYVER, "Specified version of key is not available");360errMsgList.put(KRB_AP_ERR_NOKEY, "Service key not available");361errMsgList.put(KRB_AP_ERR_MUT_FAIL, "Mutual authentication failed");362errMsgList.put(KRB_AP_ERR_BADDIRECTION, "Incorrect message direction");363errMsgList.put(KRB_AP_ERR_METHOD, "Alternative authentication method required");364errMsgList.put(KRB_AP_ERR_BADSEQ, "Incorrect sequence number in message");365errMsgList.put(KRB_AP_ERR_INAPP_CKSUM, "Inappropriate type of checksum in message");366errMsgList.put(KRB_ERR_RESPONSE_TOO_BIG, "Response too big for UDP, retry with TCP");367errMsgList.put(KRB_ERR_GENERIC, "Generic error (description in e-text)");368errMsgList.put(KRB_ERR_FIELD_TOOLONG, "Field is too long for this implementation");369errMsgList.put(KRB_AP_ERR_NOREALM, "Realm name not available"); //used in setDefaultCreds() in sun.security.krb5.Credentials370371// error messages specific to this implementation372373errMsgList.put(API_INVALID_ARG, "Invalid argument");374375errMsgList.put(BITSTRING_SIZE_INVALID, "BitString size does not match input byte array");376errMsgList.put(BITSTRING_INDEX_OUT_OF_BOUNDS, "BitString bit index does not fall within size");377errMsgList.put(BITSTRING_BAD_LENGTH, "BitString length is wrong for the expected type");378379errMsgList.put(REALM_ILLCHAR, "Illegal character in realm name; one of: '/', ':', '\0'");380errMsgList.put(REALM_NULL, "Null realm name");381382errMsgList.put(ASN1_BAD_TIMEFORMAT, "Input not in GeneralizedTime format");383errMsgList.put(ASN1_MISSING_FIELD, "Structure is missing a required field");384errMsgList.put(ASN1_MISPLACED_FIELD, "Unexpected field number");385errMsgList.put(ASN1_TYPE_MISMATCH, "Type numbers are inconsistent");386errMsgList.put(ASN1_OVERFLOW, "Value too large");387errMsgList.put(ASN1_OVERRUN, "Encoding ended unexpectedly");388errMsgList.put(ASN1_BAD_ID, "Identifier doesn't match expected value");389errMsgList.put(ASN1_BAD_LENGTH, "Length doesn't match expected value");390errMsgList.put(ASN1_BAD_FORMAT, "Badly-formatted encoding");391errMsgList.put(ASN1_PARSE_ERROR, "Parse error");392errMsgList.put(ASN1_BAD_CLASS, "Bad class number");393errMsgList.put(ASN1_BAD_TYPE, "Bad type number");394errMsgList.put(ASN1_BAD_TAG, "Bad tag number");395errMsgList.put(ASN1_UNSUPPORTED_TYPE, "Unsupported ASN.1 type encountered");396errMsgList.put(ASN1_CANNOT_ENCODE, "Encoding failed due to invalid parameter(s)");397errMsgList.put(KRB_CRYPTO_NOT_SUPPORT, "Client has no support for crypto type");398errMsgList.put(KRB_AP_ERR_REQ_OPTIONS, "Invalid option setting in ticket request.");399errMsgList.put(KRB_AP_ERR_GEN_CRED, "Fail to create credential.");400}401402}403404405