# HG changeset patch # User mbalao # Date 1590891184 -28800 # Node ID d8bd882cfd2ae393e7dbffed7fbd455449c32d88 # Parent e78cf577654bc4c297b277b97ad6afcd773081a9 8246193: Possible NPE in ENC-PA-REP search in AS-REQ Reviewed-by: zgu, andrew diff -r e78cf577654b -r d8bd882cfd2a src/share/classes/sun/security/krb5/KrbKdcRep.java --- a/src/share/classes/sun/security/krb5/KrbKdcRep.java Mon Aug 31 07:09:57 2020 +0100 +++ b/src/share/classes/sun/security/krb5/KrbKdcRep.java Sun May 31 10:13:04 2020 +0800 @@ -134,12 +134,14 @@ boolean reqPaReqEncPaRep = false; boolean repPaReqEncPaRepValid = false; - for (PAData pa : req.pAData) { - if (pa.getType() == Krb5.PA_REQ_ENC_PA_REP) { - // The KDC supports RFC 6806 and ENC-PA-REP was sent in - // the request (AS-REQ). A valid checksum is now required. - reqPaReqEncPaRep = true; - break; + if (req.pAData != null) { + for (PAData pa : req.pAData) { + if (pa.getType() == Krb5.PA_REQ_ENC_PA_REP) { + // The KDC supports RFC 6806 and ENC-PA-REP was sent in + // the request (AS-REQ). A valid checksum is now required. + reqPaReqEncPaRep = true; + break; + } } } diff -r e78cf577654b -r d8bd882cfd2a test/sun/security/krb5/auto/AlwaysEncPaReq.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/security/krb5/auto/AlwaysEncPaReq.java Sun May 31 10:13:04 2020 +0800 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8246193 + * @summary Possible NPE in ENC-PA-REP search in AS-REQ + * @library /lib/testlibrary + * @compile -XDignore.symbol.file AlwaysEncPaReq.java + * @run main/othervm -Dtest.kdc.always.enc.pa.rep + * -Dsun.net.spi.nameservice.provider.1=ns,mock AlwaysEncPaReq + */ + +public class AlwaysEncPaReq { + public static void main(String[] args) throws Exception { + new OneKDC(null).writeJAASConf() + .setOption(KDC.Option.PREAUTH_REQUIRED, false); + Context.fromJAAS("client"); + } +} diff -r e78cf577654b -r d8bd882cfd2a test/sun/security/krb5/auto/KDC.java --- a/test/sun/security/krb5/auto/KDC.java Mon Aug 31 07:09:57 2020 +0100 +++ b/test/sun/security/krb5/auto/KDC.java Sun May 31 10:13:04 2020 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1178,6 +1178,9 @@ bFlags[Krb5.TKT_OPTS_MAY_POSTDATE] = true; } bFlags[Krb5.TKT_OPTS_INITIAL] = true; + if (System.getProperty("test.kdc.always.enc.pa.rep") != null) { + bFlags[Krb5.TKT_OPTS_ENC_PA_REP] = true; + } // Creating PA-DATA DerValue[] pas2 = null, pas = null;