Showing the changes to java/pkg/sun/security/krb5/KrbAppMessage.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,110 @@ | |||
| 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. Oracle designates this | ||
| 7 | * particular file as subject to the "Classpath" exception as provided | ||
| 8 | * 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 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 21 | * or visit www.oracle.com if you need additional information or have any | ||
| 22 | * 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 KrbAppMessage { | ||
| 36 | |||
| 37 | private static boolean DEBUG = Krb5.DEBUG; | ||
| 38 | /** | ||
| 39 | * Common checks for KRB-PRIV and KRB-SAFE | ||
| 40 | */ | ||
| 41 | void check(KerberosTime packetTimestamp, | ||
| 42 | Integer packetUsec, | ||
| 43 | Integer packetSeqNumber, | ||
| 44 | HostAddress packetSAddress, | ||
| 45 | HostAddress packetRAddress, | ||
| 46 | SeqNumber seqNumber, | ||
| 47 | HostAddress sAddress, | ||
| 48 | HostAddress rAddress, | ||
| 49 | boolean timestampRequired, | ||
| 50 | boolean seqNumberRequired, | ||
| 51 | PrincipalName packetPrincipal, | ||
| 52 | Realm packetRealm) | ||
| 53 | throws KrbApErrException { | ||
| 54 | |||
| 55 | if (!Krb5.AP_EMPTY_ADDRESSES_ALLOWED || sAddress != null) { | ||
| 56 | if (packetSAddress == null || sAddress == null || | ||
| 57 | !packetSAddress.equals(sAddress)) { | ||
| 58 | if (DEBUG && packetSAddress == null) { | ||
| 59 | System.out.println("packetSAddress is null"); | ||
| 60 | } | ||
| 61 | if (DEBUG && sAddress == null) { | ||
| 62 | System.out.println("sAddress is null"); | ||
| 63 | } | ||
| 64 | throw new KrbApErrException(Krb5.KRB_AP_ERR_BADADDR); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | if (!Krb5.AP_EMPTY_ADDRESSES_ALLOWED || rAddress != null) { | ||
| 69 | if (packetRAddress == null || rAddress == null || | ||
| 70 | !packetRAddress.equals(rAddress)) | ||
| 71 | throw new KrbApErrException(Krb5.KRB_AP_ERR_BADADDR); | ||
| 72 | } | ||
| 73 | |||
| 74 | if (packetTimestamp != null) { | ||
| 75 | packetTimestamp.setMicroSeconds(packetUsec); | ||
| 76 | if (!packetTimestamp.inClockSkew()) | ||
| 77 | throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW); | ||
| 78 | } else | ||
| 79 | if (timestampRequired) | ||
| 80 | throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW); | ||
| 81 | |||
| 82 | // XXX check replay cache | ||
| 83 | // if (rcache.repeated(packetTimestamp, packetUsec, packetSAddress)) | ||
| 84 | // throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT); | ||
| 85 | |||
| 86 | // XXX consider moving up to api level | ||
| 87 | if (seqNumber == null && seqNumberRequired == true) | ||
| 88 | throw new KrbApErrException(Krb5.API_INVALID_ARG); | ||
| 89 | |||
| 90 | if (packetSeqNumber != null && seqNumber != null) { | ||
| 91 | if (packetSeqNumber.intValue() != seqNumber.current()) | ||
| 92 | throw new KrbApErrException(Krb5.KRB_AP_ERR_BADORDER); | ||
| 93 | // should be done only when no more exceptions are possible | ||
| 94 | seqNumber.step(); | ||
| 95 | } else { | ||
| 96 | if (seqNumberRequired) { | ||
| 97 | throw new KrbApErrException(Krb5.KRB_AP_ERR_BADORDER); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | // Must not be relaxed, per RFC 4120 | ||
| 102 | if (packetTimestamp == null && packetSeqNumber == null) | ||
| 103 | throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); | ||
| 104 | |||
| 105 | // XXX check replay cache | ||
| 106 | // rcache.save_identifier(packetTimestamp, packetUsec, packetSAddress, | ||
| 107 | // packetPrincipal, pcaketRealm); | ||
| 108 | } | ||
| 109 | |||
| 110 | } | ||