J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. Sun designates this |
| 7 | * particular file as subject to the "Classpath" exception as provided |
| 8 | * by Sun in the LICENSE file that accompanied this code. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | * accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License version |
| 17 | * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * |
| 27 | * (C) Copyright IBM Corp. 1999 All Rights Reserved. |
| 28 | * Copyright 1997 The Open Group Research Institute. All rights reserved. |
| 29 | */ |
| 30 | |
| 31 | package sun.security.krb5; |
| 32 | |
| 33 | import sun.security.krb5.internal.*; |
| 34 | |
| 35 | abstract class KrbKdcRep { |
| 36 | |
| 37 | static void check( |
| 38 | KDCReq req, |
| 39 | KDCRep rep |
| 40 | ) throws KrbApErrException { |
| 41 | |
| 42 | if (!req.reqBody.cname.equalsWithoutRealm(rep.cname)) { |
| 43 | rep.encKDCRepPart.key.destroy(); |
| 44 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 45 | } |
| 46 | |
| 47 | /**** XXX |
| 48 | if (!req.reqBody.crealm.equals(rep.crealm)) { |
| 49 | rep.encKDCRepPart.key.destroy(); |
| 50 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 51 | } |
| 52 | *****/ |
| 53 | |
| 54 | if (!req.reqBody.sname.equalsWithoutRealm(rep.encKDCRepPart.sname)) { |
| 55 | rep.encKDCRepPart.key.destroy(); |
| 56 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 57 | } |
| 58 | |
| 59 | if (!req.reqBody.crealm.equals(rep.encKDCRepPart.srealm)) { |
| 60 | rep.encKDCRepPart.key.destroy(); |
| 61 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 62 | } |
| 63 | |
| 64 | if (req.reqBody.getNonce() != rep.encKDCRepPart.nonce) { |
| 65 | rep.encKDCRepPart.key.destroy(); |
| 66 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 67 | } |
| 68 | |
| 69 | if ( |
| 70 | ((req.reqBody.addresses != null && rep.encKDCRepPart.caddr != null) && |
| 71 | !req.reqBody.addresses.equals(rep.encKDCRepPart.caddr))) { |
| 72 | rep.encKDCRepPart.key.destroy(); |
| 73 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | for (int i = 1; i < 6; i++) { |
| 78 | if (req.reqBody.kdcOptions.get(i) != |
| 79 | rep.encKDCRepPart.flags.get(i)) { |
| 80 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // XXX Can renew a ticket but not ask for a renewable renewed ticket |
| 85 | // See impl of Credentials.renew(). |
| 86 | if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE) != |
| 87 | rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) { |
| 88 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 89 | } |
| 90 | if ((req.reqBody.from == null) || req.reqBody.from.isZero()) |
| 91 | // verify this is allowed |
| 92 | if ((rep.encKDCRepPart.starttime != null) && |
| 93 | !rep.encKDCRepPart.starttime.inClockSkew()) { |
| 94 | rep.encKDCRepPart.key.destroy(); |
| 95 | throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW); |
| 96 | } |
| 97 | |
| 98 | if ((req.reqBody.from != null) && !req.reqBody.from.isZero()) |
| 99 | // verify this is allowed |
| 100 | if ((rep.encKDCRepPart.starttime != null) && |
| 101 | !req.reqBody.from.equals(rep.encKDCRepPart.starttime)) { |
| 102 | rep.encKDCRepPart.key.destroy(); |
| 103 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 104 | } |
| 105 | |
| 106 | if (!req.reqBody.till.isZero() && |
| 107 | rep.encKDCRepPart.endtime.greaterThan(req.reqBody.till)) { |
| 108 | rep.encKDCRepPart.key.destroy(); |
| 109 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 110 | } |
| 111 | |
| 112 | if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE)) |
| 113 | if (req.reqBody.rtime != null && !req.reqBody.rtime.isZero()) |
| 114 | // verify this is required |
| 115 | if ((rep.encKDCRepPart.renewTill == null) || |
| 116 | rep.encKDCRepPart.renewTill.greaterThan(req.reqBody.rtime) |
| 117 | ) { |
| 118 | rep.encKDCRepPart.key.destroy(); |
| 119 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 120 | } |
| 121 | |
| 122 | if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE_OK) && |
| 123 | rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) |
| 124 | if (!req.reqBody.till.isZero()) |
| 125 | // verify this is required |
| 126 | if ((rep.encKDCRepPart.renewTill == null) || |
| 127 | rep.encKDCRepPart.renewTill.greaterThan(req.reqBody.till) |
| 128 | ) { |
| 129 | rep.encKDCRepPart.key.destroy(); |
| 130 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | |
| 135 | } |