Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/KrbPriv.java
41159 views
/*1* Copyright (c) 2000, 2012, 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.*;35import sun.security.util.*;36import java.io.IOException;3738/** XXX This class does not appear to be used. **/3940class KrbPriv extends KrbAppMessage {41private byte[] obuf;42private byte[] userData;4344private KrbPriv(byte[] userData,45Credentials creds,46EncryptionKey subKey,47KerberosTime timestamp,48SeqNumber seqNumber,49HostAddress saddr,50HostAddress raddr51) throws KrbException, IOException {52EncryptionKey reqKey = null;53if (subKey != null)54reqKey = subKey;55else56reqKey = creds.key;5758obuf = mk_priv(59userData,60reqKey,61timestamp,62seqNumber,63saddr,64raddr65);66}6768private KrbPriv(byte[] msg,69Credentials creds,70EncryptionKey subKey,71SeqNumber seqNumber,72HostAddress saddr,73HostAddress raddr,74boolean timestampRequired,75boolean seqNumberRequired76) throws KrbException, IOException {7778KRBPriv krb_priv = new KRBPriv(msg);79EncryptionKey reqKey = null;80if (subKey != null)81reqKey = subKey;82else83reqKey = creds.key;84userData = rd_priv(krb_priv,85reqKey,86seqNumber,87saddr,88raddr,89timestampRequired,90seqNumberRequired,91creds.client92);93}9495public byte[] getMessage() throws KrbException {96return obuf;97}9899public byte[] getData() {100return userData;101}102103private byte[] mk_priv(byte[] userData,104EncryptionKey key,105KerberosTime timestamp,106SeqNumber seqNumber,107HostAddress sAddress,108HostAddress rAddress109) throws Asn1Exception, IOException,110KdcErrException, KrbCryptoException {111112Integer usec = null;113Integer seqno = null;114115if (timestamp != null)116usec = timestamp.getMicroSeconds();117118if (seqNumber != null) {119seqno = seqNumber.current();120seqNumber.step();121}122123EncKrbPrivPart unenc_encKrbPrivPart =124new EncKrbPrivPart(userData,125timestamp,126usec,127seqno,128sAddress,129rAddress130);131132byte[] temp = unenc_encKrbPrivPart.asn1Encode();133134EncryptedData encKrbPrivPart =135new EncryptedData(key, temp,136KeyUsage.KU_ENC_KRB_PRIV_PART);137138KRBPriv krb_priv = new KRBPriv(encKrbPrivPart);139140temp = krb_priv.asn1Encode();141142return krb_priv.asn1Encode();143}144145private byte[] rd_priv(KRBPriv krb_priv,146EncryptionKey key,147SeqNumber seqNumber,148HostAddress sAddress,149HostAddress rAddress,150boolean timestampRequired,151boolean seqNumberRequired,152PrincipalName cname153) throws Asn1Exception, KdcErrException,154KrbApErrException, IOException, KrbCryptoException {155156byte[] bytes = krb_priv.encPart.decrypt(key,157KeyUsage.KU_ENC_KRB_PRIV_PART);158byte[] temp = krb_priv.encPart.reset(bytes);159DerValue ref = new DerValue(temp);160EncKrbPrivPart enc_part = new EncKrbPrivPart(ref);161162check(enc_part.timestamp,163enc_part.usec,164enc_part.seqNumber,165enc_part.sAddress,166enc_part.rAddress,167seqNumber,168sAddress,169rAddress,170timestampRequired,171seqNumberRequired,172cname173);174175return enc_part.userData;176}177}178179180