Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/krb5/KrbTgsRep.java
38830 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;3233import sun.security.krb5.internal.*;34import sun.security.krb5.internal.crypto.KeyUsage;35import sun.security.util.*;36import java.io.IOException;3738/**39* This class encapsulates a TGS-REP that is sent from the KDC to the40* Kerberos client.41*/42public class KrbTgsRep extends KrbKdcRep {43private TGSRep rep;44private Credentials creds;45private Ticket secondTicket;46private static final boolean DEBUG = Krb5.DEBUG;4748KrbTgsRep(byte[] ibuf, KrbTgsReq tgsReq)49throws KrbException, IOException {50DerValue ref = new DerValue(ibuf);51TGSReq req = tgsReq.getMessage();52TGSRep rep = null;53try {54rep = new TGSRep(ref);55} catch (Asn1Exception e) {56rep = null;57KRBError err = new KRBError(ref);58String errStr = err.getErrorString();59String eText = null; // pick up text sent by the server (if any)60if (errStr != null && errStr.length() > 0) {61if (errStr.charAt(errStr.length() - 1) == 0)62eText = errStr.substring(0, errStr.length() - 1);63else64eText = errStr;65}66KrbException ke;67if (eText == null) {68// no text sent from server69ke = new KrbException(err.getErrorCode());70} else {71// override default text with server text72ke = new KrbException(err.getErrorCode(), eText);73}74ke.initCause(e);75throw ke;76}77byte[] enc_tgs_rep_bytes = rep.encPart.decrypt(tgsReq.tgsReqKey,78tgsReq.usedSubkey() ? KeyUsage.KU_ENC_TGS_REP_PART_SUBKEY :79KeyUsage.KU_ENC_TGS_REP_PART_SESSKEY);8081byte[] enc_tgs_rep_part = rep.encPart.reset(enc_tgs_rep_bytes);82ref = new DerValue(enc_tgs_rep_part);83EncTGSRepPart enc_part = new EncTGSRepPart(ref);84rep.encKDCRepPart = enc_part;8586check(false, req, rep, tgsReq.tgsReqKey);8788PrincipalName serverAlias = tgsReq.getServerAlias();89if (serverAlias != null) {90PrincipalName repSname = enc_part.sname;91if (serverAlias.equals(repSname) ||92isReferralSname(repSname)) {93serverAlias = null;94}95}9697PrincipalName clientAlias = null;98if (rep.cname.equals(req.reqBody.cname)) {99// Only propagate the client alias if it is not an100// impersonation ticket (S4U2Self or S4U2Proxy).101clientAlias = tgsReq.getClientAlias();102}103104this.creds = new Credentials(rep.ticket,105rep.cname,106clientAlias,107enc_part.sname,108serverAlias,109enc_part.key,110enc_part.flags,111enc_part.authtime,112enc_part.starttime,113enc_part.endtime,114enc_part.renewTill,115enc_part.caddr116);117this.rep = rep;118this.secondTicket = tgsReq.getSecondTicket();119}120121/**122* Return the credentials that were contained in this KRB-TGS-REP.123*/124public Credentials getCreds() {125return creds;126}127128sun.security.krb5.internal.ccache.Credentials setCredentials() {129return new sun.security.krb5.internal.ccache.Credentials(rep, secondTicket);130}131132private static boolean isReferralSname(PrincipalName sname) {133if (sname != null) {134String[] snameStrings = sname.getNameStrings();135if (snameStrings.length == 2 &&136snameStrings[0].equals(137PrincipalName.TGS_DEFAULT_SRV_NAME)) {138return true;139}140}141return false;142}143}144145146