8131051: KDC might issue a renewable ticket even if not requested

Reviewed-by: xuelei
This commit is contained in:
Weijun Wang 2015-07-21 18:02:36 +08:00
parent 8dd9e26db4
commit e81669d5df
4 changed files with 65 additions and 5 deletions

View File

@ -75,10 +75,11 @@ abstract class KrbKdcRep {
}
}
// XXX Can renew a ticket but not ask for a renewable renewed ticket
// See impl of Credentials.renew().
if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE) !=
rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) {
// Reply to a renewable request should be renewable, but if request does
// not contain renewable, KDC is free to issue a renewable ticket (for
// example, if ticket_lifetime is too big).
if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE) &&
!rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);
}

View File

@ -28,6 +28,10 @@ import java.net.*;
import java.io.*;
import java.lang.reflect.Method;
import java.security.SecureRandom;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
import java.util.*;
import java.util.concurrent.*;
@ -939,6 +943,13 @@ public class KDC {
} else if (till.isZero()) {
till = new KerberosTime(
new Date().getTime() + 1000 * DEFAULT_LIFETIME);
} else if (till.greaterThan(new KerberosTime(Instant.now()
.plus(1, ChronoUnit.DAYS)))) {
// If till is more than 1 day later, make it renewable
till = new KerberosTime(
new Date().getTime() + 1000 * DEFAULT_LIFETIME);
body.kdcOptions.set(KDCOptions.RENEWABLE, true);
if (rtime == null) rtime = till;
}
if (rtime == null && body.kdcOptions.get(KDCOptions.RENEWABLE)) {
rtime = new KerberosTime(

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2015, 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 8131051
* @summary KDC might issue a renewable ticket even if not requested
* @compile -XDignore.symbol.file LongLife.java
* @run main/othervm LongLife
*/
import sun.security.krb5.Config;
public class LongLife {
public static void main(String[] args) throws Exception {
OneKDC kdc = new OneKDC(null).writeJAASConf();
// A lifetime 2d will make it renewable
KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
"ticket_lifetime = 2d");
Config.refresh();
Context.fromJAAS("client");
}
}

View File

@ -95,7 +95,7 @@ public class OneKDC extends KDC {
* entries with names using existing OneKDC principals.
* @throws java.lang.Exception if anything goes wrong
*/
public void writeJAASConf() throws IOException {
public OneKDC writeJAASConf() throws IOException {
System.setProperty("java.security.auth.login.config", JAAS_CONF);
File f = new File(JAAS_CONF);
FileOutputStream fos = new FileOutputStream(f);
@ -123,6 +123,7 @@ public class OneKDC extends KDC {
" isInitiator=false;\n};\n"
).getBytes());
fos.close();
return this;
}
/**