6641312: Fix krb5 codes indentation problems

Reviewed-by: xuelei, valeriep, wetmore
This commit is contained in:
Weijun Wang 2008-03-05 09:52:50 +08:00
parent 6797bd9fb2
commit 0f960354ea
21 changed files with 2337 additions and 2245 deletions

View File

@ -54,6 +54,7 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class APRep { public class APRep {
public int pvno; public int pvno;
public int msgType; public int msgType;
public EncryptedData encPart; public EncryptedData encPart;
@ -87,27 +88,34 @@ public class APRep {
if (((encoding.getTag() & (byte) (0x1F)) != Krb5.KRB_AP_REP) if (((encoding.getTag() & (byte) (0x1F)) != Krb5.KRB_AP_REP)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
DerValue der = encoding.getData().getDerValue(); DerValue der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
DerValue subDer = der.getData().getDerValue(); DerValue subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) != (byte)0x00) if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
pvno = subDer.getData().getBigInteger().intValue(); pvno = subDer.getData().getBigInteger().intValue();
if (pvno != Krb5.PVNO) if (pvno != Krb5.PVNO) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) != (byte)0x01) if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x01) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
msgType = subDer.getData().getBigInteger().intValue(); msgType = subDer.getData().getBigInteger().intValue();
if (msgType != Krb5.KRB_AP_REP) if (msgType != Krb5.KRB_AP_REP) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE); throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
}
encPart = EncryptedData.parse(der.getData(), (byte) 0x02, false); encPart = EncryptedData.parse(der.getData(), (byte) 0x02, false);
if (der.getData().available() > 0) if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an APRep object. * Encodes an APRep object.
@ -130,5 +138,4 @@ public class APRep {
aprep.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0F), temp); aprep.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0F), temp);
return aprep.toByteArray(); return aprep.toByteArray();
} }
} }

View File

@ -54,8 +54,8 @@ import java.math.BigInteger;
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> * <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class APReq { public class APReq {
public int pvno; public int pvno;
public int msgType; public int msgType;
public APOptions apOptions; public APOptions apOptions;
@ -65,8 +65,7 @@ public class APReq {
public APReq( public APReq(
APOptions new_apOptions, APOptions new_apOptions,
Ticket new_ticket, Ticket new_ticket,
EncryptedData new_authenticator EncryptedData new_authenticator) {
) {
pvno = Krb5.PVNO; pvno = Krb5.PVNO;
msgType = Krb5.KRB_AP_REQ; msgType = Krb5.KRB_AP_REQ;
apOptions = new_apOptions; apOptions = new_apOptions;
@ -95,29 +94,36 @@ public class APReq {
DerValue der, subDer; DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != Krb5.KRB_AP_REQ) if (((encoding.getTag() & (byte) 0x1F) != Krb5.KRB_AP_REQ)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) != (byte)0x00) if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
pvno = subDer.getData().getBigInteger().intValue(); pvno = subDer.getData().getBigInteger().intValue();
if (pvno != Krb5.PVNO) if (pvno != Krb5.PVNO) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) != (byte)0x01) if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x01) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
msgType = subDer.getData().getBigInteger().intValue(); msgType = subDer.getData().getBigInteger().intValue();
if (msgType != Krb5.KRB_AP_REQ) if (msgType != Krb5.KRB_AP_REQ) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE); throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
}
apOptions = APOptions.parse(der.getData(), (byte) 0x02, false); apOptions = APOptions.parse(der.getData(), (byte) 0x02, false);
ticket = Ticket.parse(der.getData(), (byte) 0x03, false); ticket = Ticket.parse(der.getData(), (byte) 0x03, false);
authenticator = EncryptedData.parse(der.getData(), (byte) 0x04, false); authenticator = EncryptedData.parse(der.getData(), (byte) 0x04, false);
if (der.getData().available() > 0) if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an APReq object. * Encodes an APReq object.
@ -141,7 +147,5 @@ public class APReq {
DerOutputStream apreq = new DerOutputStream(); DerOutputStream apreq = new DerOutputStream();
apreq.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0E), temp); apreq.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0E), temp);
return apreq.toByteArray(); return apreq.toByteArray();
} }
} }

View File

@ -45,8 +45,7 @@ public class ASRep extends KDCRep {
Realm new_crealm, Realm new_crealm,
PrincipalName new_cname, PrincipalName new_cname,
Ticket new_ticket, Ticket new_ticket,
EncryptedData new_encPart EncryptedData new_encPart) throws IOException {
) throws IOException {
super(new_pAData, new_crealm, new_cname, new_ticket, super(new_pAData, new_crealm, new_cname, new_ticket,
new_encPart, Krb5.KRB_AS_REP); new_encPart, Krb5.KRB_AS_REP);
} }
@ -65,5 +64,4 @@ public class ASRep extends KDCRep {
RealmException, KrbApErrException, IOException { RealmException, KrbApErrException, IOException {
init(encoding, Krb5.KRB_AS_REP); init(encoding, Krb5.KRB_AS_REP);
} }
} }

View File

@ -51,5 +51,4 @@ public class ASReq extends KDCReq {
private void init(DerValue encoding) throws Asn1Exception, IOException, KrbException { private void init(DerValue encoding) throws Asn1Exception, IOException, KrbException {
super.init(encoding, Krb5.KRB_AS_REQ); super.init(encoding, Krb5.KRB_AS_REQ);
} }
} }

View File

@ -34,6 +34,7 @@ import sun.security.util.*;
import java.util.Vector; import java.util.Vector;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* Implements the ASN.1 Authenticator type. * Implements the ASN.1 Authenticator type.
* *
@ -58,6 +59,7 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class Authenticator { public class Authenticator {
public int authenticator_vno; public int authenticator_vno;
public Realm crealm; public Realm crealm;
public PrincipalName cname; public PrincipalName cname;
@ -76,8 +78,7 @@ public class Authenticator {
KerberosTime new_ctime, KerberosTime new_ctime,
EncryptionKey new_subKey, EncryptionKey new_subKey,
Integer new_seqNumber, Integer new_seqNumber,
AuthorizationData new_authorizationData AuthorizationData new_authorizationData) {
) {
authenticator_vno = Krb5.AUTHNETICATOR_VNO; authenticator_vno = Krb5.AUTHNETICATOR_VNO;
crealm = new_crealm; crealm = new_crealm;
cname = new_cname; cname = new_cname;
@ -115,30 +116,34 @@ public class Authenticator {
//mismatch on an encrypted structure //mismatch on an encrypted structure
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x02) if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x02)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) != (byte)0x00) if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
authenticator_vno = subDer.getData().getBigInteger().intValue(); authenticator_vno = subDer.getData().getBigInteger().intValue();
if (authenticator_vno != 5) if (authenticator_vno != 5) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
}
crealm = Realm.parse(der.getData(), (byte) 0x01, false); crealm = Realm.parse(der.getData(), (byte) 0x01, false);
cname = PrincipalName.parse(der.getData(), (byte) 0x02, false); cname = PrincipalName.parse(der.getData(), (byte) 0x02, false);
cksum = Checksum.parse(der.getData(), (byte) 0x03, true); cksum = Checksum.parse(der.getData(), (byte) 0x03, true);
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte) 0x1F) == 0x04) { if ((subDer.getTag() & (byte) 0x1F) == 0x04) {
cusec = subDer.getData().getBigInteger().intValue(); cusec = subDer.getData().getBigInteger().intValue();
} else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
ctime = KerberosTime.parse(der.getData(), (byte) 0x05, false); ctime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
subKey = EncryptionKey.parse(der.getData(), (byte) 0x06, true); subKey = EncryptionKey.parse(der.getData(), (byte) 0x06, true);
} } else {
else {
subKey = null; subKey = null;
seqNumber = null; seqNumber = null;
authorizationData = null; authorizationData = null;
@ -146,21 +151,23 @@ public class Authenticator {
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
if ((der.getData().peekByte() & 0x1F) == 0x07) { if ((der.getData().peekByte() & 0x1F) == 0x07) {
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) == (byte)0x07) if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x07) {
seqNumber = new Integer(subDer.getData().getBigInteger().intValue()); seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
} }
} }
else { } else {
seqNumber = null; seqNumber = null;
authorizationData = null; authorizationData = null;
} }
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x08, true); authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x08, true);
} else {
authorizationData = null;
} }
else authorizationData = null; if (der.getData().available() > 0) {
if (der.getData().available() > 0)
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an Authenticator object. * Encodes an Authenticator object.
@ -175,22 +182,25 @@ public class Authenticator {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), crealm.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), crealm.asn1Encode()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode()));
if (cksum != null) if (cksum != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode()));
}
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(cusec)); temp.putInteger(BigInteger.valueOf(cusec));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), temp.toByteArray())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), temp.toByteArray()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), ctime.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), ctime.asn1Encode()));
if (subKey != null) if (subKey != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), subKey.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), subKey.asn1Encode()));
}
if (seqNumber != null) { if (seqNumber != null) {
temp = new DerOutputStream(); temp = new DerOutputStream();
// encode as an unsigned integer (UInt32) // encode as an unsigned integer (UInt32)
temp.putInteger(BigInteger.valueOf(seqNumber.longValue())); temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), temp.toByteArray())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), temp.toByteArray()));
} }
if (authorizationData != null) if (authorizationData != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), authorizationData.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), authorizationData.asn1Encode()));
}
DerValue der[] = new DerValue[v.size()]; DerValue der[] = new DerValue[v.size()];
v.copyInto(der); v.copyInto(der);
temp = new DerOutputStream(); temp = new DerOutputStream();
@ -211,5 +221,4 @@ public class Authenticator {
public final EncryptionKey getSubKey() { public final EncryptionKey getSubKey() {
return subKey; return subKey;
} }
} }

View File

@ -53,14 +53,14 @@ import sun.security.krb5.internal.ccache.CCacheOutputStream;
* } * }
*/ */
public class AuthorizationData implements Cloneable { public class AuthorizationData implements Cloneable {
private AuthorizationDataEntry[] entry = null; private AuthorizationDataEntry[] entry = null;
private AuthorizationData() { private AuthorizationData() {
} }
public AuthorizationData( public AuthorizationData(AuthorizationDataEntry[] new_entries)
AuthorizationDataEntry[] new_entries throws IOException {
) throws IOException {
if (new_entries != null) { if (new_entries != null) {
entry = new AuthorizationDataEntry[new_entries.length]; entry = new AuthorizationDataEntry[new_entries.length];
for (int i = 0; i < new_entries.length; i++) { for (int i = 0; i < new_entries.length; i++) {
@ -73,9 +73,7 @@ public class AuthorizationData implements Cloneable {
} }
} }
public AuthorizationData( public AuthorizationData(AuthorizationDataEntry new_entry) {
AuthorizationDataEntry new_entry
) {
entry = new AuthorizationDataEntry[1]; entry = new AuthorizationDataEntry[1];
entry[0] = new_entry; entry[0] = new_entry;
} }
@ -86,10 +84,11 @@ public class AuthorizationData implements Cloneable {
if (entry != null) { if (entry != null) {
new_authorizationData.entry = new_authorizationData.entry =
new AuthorizationDataEntry[entry.length]; new AuthorizationDataEntry[entry.length];
for (int i = 0; i < entry.length; i++) for (int i = 0; i < entry.length; i++) {
new_authorizationData.entry[i] = new_authorizationData.entry[i] =
(AuthorizationDataEntry) entry[i].clone(); (AuthorizationDataEntry) entry[i].clone();
} }
}
return new_authorizationData; return new_authorizationData;
} }
@ -150,8 +149,7 @@ public class AuthorizationData implements Cloneable {
DerValue der = data.getDerValue(); DerValue der = data.getDerValue();
if (explicitTag != (der.getTag() & (byte) 0x1F)) { if (explicitTag != (der.getTag() & (byte) 0x1F)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} } else {
else {
DerValue subDer = der.getData().getDerValue(); DerValue subDer = der.getData().getDerValue();
return new AuthorizationData(subDer); return new AuthorizationData(subDer);
} }

View File

@ -35,6 +35,7 @@ import sun.security.krb5.Asn1Exception;
import sun.security.krb5.internal.ccache.CCacheOutputStream; import sun.security.krb5.internal.ccache.CCacheOutputStream;
public class AuthorizationDataEntry implements Cloneable { public class AuthorizationDataEntry implements Cloneable {
public int adType; public int adType;
public byte[] adData; public byte[] adData;
@ -43,8 +44,7 @@ public class AuthorizationDataEntry implements Cloneable {
public AuthorizationDataEntry( public AuthorizationDataEntry(
int new_adType, int new_adType,
byte[] new_adData byte[] new_adData) {
) {
adType = new_adType; adType = new_adType;
adData = new_adData; adData = new_adData;
} }
@ -73,18 +73,19 @@ public class AuthorizationDataEntry implements Cloneable {
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) { if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) {
adType = der.getData().getBigInteger().intValue(); adType = der.getData().getBigInteger().intValue();
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) { if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) {
adData = der.getData().getOctetString(); adData = der.getData().getOctetString();
} else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
else if (encoding.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
if (encoding.getData().available() > 0)
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an AuthorizationDataEntry object. * Encodes an AuthorizationDataEntry object.
@ -120,5 +121,4 @@ public class AuthorizationDataEntry implements Cloneable {
public String toString() { public String toString() {
return ("adType=" + adType + " adData.length=" + adData.length); return ("adType=" + adType + " adData.length=" + adData.length);
} }
} }

View File

@ -55,6 +55,7 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class EncAPRepPart { public class EncAPRepPart {
public KerberosTime ctime; public KerberosTime ctime;
public int cusec; public int cusec;
EncryptionKey subKey; //optional EncryptionKey subKey; //optional
@ -64,8 +65,7 @@ public class EncAPRepPart {
KerberosTime new_ctime, KerberosTime new_ctime,
int new_cusec, int new_cusec,
EncryptionKey new_subKey, EncryptionKey new_subKey,
Integer new_seqNumber Integer new_seqNumber) {
) {
ctime = new_ctime; ctime = new_ctime;
cusec = new_cusec; cusec = new_cusec;
subKey = new_subKey; subKey = new_subKey;
@ -92,22 +92,23 @@ public class EncAPRepPart {
DerValue der, subDer; DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1B) if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1B)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
ctime = KerberosTime.parse(der.getData(), (byte) 0x00, true); ctime = KerberosTime.parse(der.getData(), (byte) 0x00, true);
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x01) { if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x01) {
cusec = subDer.getData().getBigInteger().intValue(); cusec = subDer.getData().getBigInteger().intValue();
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
subKey = EncryptionKey.parse(der.getData(), (byte) 0x02, true); subKey = EncryptionKey.parse(der.getData(), (byte) 0x02, true);
} } else {
else {
subKey = null; subKey = null;
seqNumber = null; seqNumber = null;
} }
@ -117,11 +118,13 @@ public class EncAPRepPart {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
seqNumber = new Integer(subDer.getData().getBigInteger().intValue()); seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
} else {
seqNumber = null;
} }
else seqNumber = null; if (der.getData().available() > 0) {
if (der.getData().available() > 0)
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an EncAPRepPart object. * Encodes an EncAPRepPart object.
@ -132,23 +135,29 @@ public class EncAPRepPart {
public byte[] asn1Encode() throws Asn1Exception, IOException { public byte[] asn1Encode() throws Asn1Exception, IOException {
Vector<DerValue> v = new Vector<DerValue>(); Vector<DerValue> v = new Vector<DerValue>();
DerOutputStream temp = new DerOutputStream(); DerOutputStream temp = new DerOutputStream();
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), ctime.asn1Encode())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x00), ctime.asn1Encode()));
temp.putInteger(BigInteger.valueOf(cusec)); temp.putInteger(BigInteger.valueOf(cusec));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp.toByteArray())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
if (subKey != null) true, (byte) 0x01), temp.toByteArray()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), subKey.asn1Encode())); if (subKey != null) {
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x02), subKey.asn1Encode()));
}
if (seqNumber != null) { if (seqNumber != null) {
temp = new DerOutputStream(); temp = new DerOutputStream();
// encode as an unsigned integer (UInt32) // encode as an unsigned integer (UInt32)
temp.putInteger(BigInteger.valueOf(seqNumber.longValue())); temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp.toByteArray())); v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x03), temp.toByteArray()));
} }
DerValue der[] = new DerValue[v.size()]; DerValue der[] = new DerValue[v.size()];
v.copyInto(der); v.copyInto(der);
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putSequence(der); temp.putSequence(der);
DerOutputStream out = new DerOutputStream(); DerOutputStream out = new DerOutputStream();
out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1B), temp); out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
true, (byte) 0x1B), temp);
return out.toByteArray(); return out.toByteArray();
} }
@ -159,5 +168,4 @@ public class EncAPRepPart {
public final Integer getSeqNumber() { public final Integer getSeqNumber() {
return seqNumber; return seqNumber;
} }
} }

View File

@ -48,8 +48,7 @@ public class EncASRepPart extends EncKDCRepPart {
KerberosTime new_renewTill, KerberosTime new_renewTill,
Realm new_srealm, Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr HostAddresses new_caddr) {
) {
super( super(
new_key, new_key,
new_lastReq, new_lastReq,
@ -64,9 +63,9 @@ public class EncASRepPart extends EncKDCRepPart {
new_sname, new_sname,
new_caddr, new_caddr,
Krb5.KRB_ENC_AS_REP_PART Krb5.KRB_ENC_AS_REP_PART
);
//may need to use Krb5.KRB_ENC_TGS_REP_PART to mimic //may need to use Krb5.KRB_ENC_TGS_REP_PART to mimic
//behavior of other implementaions, instead of above //behavior of other implementaions, instead of above
);
} }
public EncASRepPart(byte[] data) throws Asn1Exception, public EncASRepPart(byte[] data) throws Asn1Exception,
@ -88,5 +87,4 @@ public class EncASRepPart extends EncKDCRepPart {
IOException { IOException {
return asn1Encode(Krb5.KRB_ENC_AS_REP_PART); return asn1Encode(Krb5.KRB_ENC_AS_REP_PART);
} }
} }

View File

@ -36,6 +36,7 @@ import sun.security.util.*;
import java.util.Vector; import java.util.Vector;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* Implements the ASN.1 EncKDCRepPart type. * Implements the ASN.1 EncKDCRepPart type.
* *
@ -63,6 +64,7 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class EncKDCRepPart { public class EncKDCRepPart {
public EncryptionKey key; public EncryptionKey key;
public LastReq lastReq; public LastReq lastReq;
public int nonce; public int nonce;
@ -90,8 +92,7 @@ public class EncKDCRepPart {
Realm new_srealm, Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr, HostAddresses new_caddr,
int new_msgType int new_msgType) {
) {
key = new_key; key = new_key;
lastReq = new_lastReq; lastReq = new_lastReq;
nonce = new_nonce; nonce = new_nonce;
@ -116,8 +117,7 @@ public class EncKDCRepPart {
} }
public EncKDCRepPart(DerValue encoding, int rep_type) public EncKDCRepPart(DerValue encoding, int rep_type)
throws Asn1Exception, IOException, RealmException throws Asn1Exception, IOException, RealmException {
{
init(encoding, rep_type); init(encoding, rep_type);
} }
@ -131,24 +131,27 @@ public class EncKDCRepPart {
* @exception RealmException if an error occurs while decoding an Realm object. * @exception RealmException if an error occurs while decoding an Realm object.
*/ */
protected void init(DerValue encoding, int rep_type) protected void init(DerValue encoding, int rep_type)
throws Asn1Exception, IOException, RealmException throws Asn1Exception, IOException, RealmException {
{
DerValue der, subDer; DerValue der, subDer;
//implementations return the incorrect tag value, so //implementations return the incorrect tag value, so
//we don't use the above line; instead we use the following //we don't use the above line; instead we use the following
msgType = (encoding.getTag() & (byte) 0x1F); msgType = (encoding.getTag() & (byte) 0x1F);
if (msgType != Krb5.KRB_ENC_AS_REP_PART && if (msgType != Krb5.KRB_ENC_AS_REP_PART &&
msgType != Krb5.KRB_ENC_TGS_REP_PART) msgType != Krb5.KRB_ENC_TGS_REP_PART) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
key = EncryptionKey.parse(der.getData(), (byte) 0x00, false); key = EncryptionKey.parse(der.getData(), (byte) 0x00, false);
lastReq = LastReq.parse(der.getData(), (byte) 0x01, false); lastReq = LastReq.parse(der.getData(), (byte) 0x01, false);
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte)0x1F) == (byte)0x02) if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x02) {
nonce = subDer.getData().getBigInteger().intValue(); nonce = subDer.getData().getBigInteger().intValue();
else throw new Asn1Exception(Krb5.ASN1_BAD_ID); } else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
keyExpiration = KerberosTime.parse(der.getData(), (byte) 0x03, true); keyExpiration = KerberosTime.parse(der.getData(), (byte) 0x03, true);
flags = TicketFlags.parse(der.getData(), (byte) 0x04, false); flags = TicketFlags.parse(der.getData(), (byte) 0x04, false);
authtime = KerberosTime.parse(der.getData(), (byte) 0x05, false); authtime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
@ -157,11 +160,13 @@ public class EncKDCRepPart {
renewTill = KerberosTime.parse(der.getData(), (byte) 0x08, true); renewTill = KerberosTime.parse(der.getData(), (byte) 0x08, true);
srealm = Realm.parse(der.getData(), (byte) 0x09, false); srealm = Realm.parse(der.getData(), (byte) 0x09, false);
sname = PrincipalName.parse(der.getData(), (byte) 0x0A, false); sname = PrincipalName.parse(der.getData(), (byte) 0x0A, false);
if (der.getData().available() > 0) if (der.getData().available() > 0) {
caddr = HostAddresses.parse(der.getData(), (byte) 0x0B, true); caddr = HostAddresses.parse(der.getData(), (byte) 0x0B, true);
if (der.getData().available() > 0) }
if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an EncKDCRepPart object. * Encodes an EncKDCRepPart object.
@ -174,32 +179,48 @@ public class EncKDCRepPart {
IOException { IOException {
DerOutputStream temp = new DerOutputStream(); DerOutputStream temp = new DerOutputStream();
DerOutputStream bytes = new DerOutputStream(); DerOutputStream bytes = new DerOutputStream();
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), lastReq.asn1Encode()); true, (byte) 0x00), key.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), lastReq.asn1Encode());
temp.putInteger(BigInteger.valueOf(nonce)); temp.putInteger(BigInteger.valueOf(nonce));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x02), temp);
if (keyExpiration != null) if (keyExpiration != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), keyExpiration.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), flags.asn1Encode()); true, (byte) 0x03), keyExpiration.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), authtime.asn1Encode()); }
if (starttime != null) bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), starttime.asn1Encode()); true, (byte) 0x04), flags.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), endtime.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
if (renewTill != null) true, (byte) 0x05), authtime.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), renewTill.asn1Encode()); if (starttime != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), srealm.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode()); true, (byte) 0x06), starttime.asn1Encode());
if (caddr != null) }
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), caddr.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x07), endtime.asn1Encode());
if (renewTill != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x08), renewTill.asn1Encode());
}
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x09), srealm.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x0A), sname.asn1Encode());
if (caddr != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x0B), caddr.asn1Encode());
}
//should use the rep_type to build the encoding //should use the rep_type to build the encoding
//but other implementations do not; it is ignored and //but other implementations do not; it is ignored and
//the cached msgType is used instead //the cached msgType is used instead
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.write(DerValue.tag_Sequence, bytes); temp.write(DerValue.tag_Sequence, bytes);
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)msgType), temp); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION,
true, (byte) msgType), temp);
return bytes.toByteArray(); return bytes.toByteArray();
} }
} }

View File

@ -36,6 +36,7 @@ import sun.security.krb5.RealmException;
import java.util.Vector; import java.util.Vector;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* Implements the ASN.1 EncKrbCredPart type. * Implements the ASN.1 EncKrbCredPart type.
* *
@ -57,9 +58,9 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class EncKrbCredPart { public class EncKrbCredPart {
public KrbCredInfo[] ticketInfo = null; public KrbCredInfo[] ticketInfo = null;
public KerberosTime timeStamp; //optional public KerberosTime timeStamp; //optional
private Integer nonce; //optional private Integer nonce; //optional
private Integer usec; //optional private Integer usec; //optional
private HostAddress sAddress; //optional private HostAddress sAddress; //optional
@ -71,8 +72,7 @@ public class EncKrbCredPart {
Integer new_usec, Integer new_usec,
Integer new_nonce, Integer new_nonce,
HostAddress new_sAddress, HostAddress new_sAddress,
HostAddresses new_rAddress HostAddresses new_rAddress) throws IOException {
) throws IOException {
if (new_ticketInfo != null) { if (new_ticketInfo != null) {
ticketInfo = new KrbCredInfo[new_ticketInfo.length]; ticketInfo = new KrbCredInfo[new_ticketInfo.length];
for (int i = 0; i < new_ticketInfo.length; i++) { for (int i = 0; i < new_ticketInfo.length; i++) {
@ -119,11 +119,13 @@ public class EncKrbCredPart {
rAddress = null; rAddress = null;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1D) if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1D)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) { if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) {
@ -132,9 +134,9 @@ public class EncKrbCredPart {
for (int i = 0; i < derValues.length; i++) { for (int i = 0; i < derValues.length; i++) {
ticketInfo[i] = new KrbCredInfo(derValues[i]); ticketInfo[i] = new KrbCredInfo(derValues[i]);
} }
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x01) { if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x01) {
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
@ -156,9 +158,10 @@ public class EncKrbCredPart {
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
rAddress = HostAddresses.parse(der.getData(), (byte) 0x05, true); rAddress = HostAddresses.parse(der.getData(), (byte) 0x05, true);
} }
if (der.getData().available() >0) if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an EncKrbCredPart object. * Encodes an EncKrbCredPart object.
@ -171,34 +174,42 @@ public class EncKrbCredPart {
DerOutputStream bytes = new DerOutputStream(); DerOutputStream bytes = new DerOutputStream();
DerOutputStream temp = new DerOutputStream(); DerOutputStream temp = new DerOutputStream();
DerValue[] tickets = new DerValue[ticketInfo.length]; DerValue[] tickets = new DerValue[ticketInfo.length];
for (int i = 0; i < ticketInfo.length; i++) for (int i = 0; i < ticketInfo.length; i++) {
tickets[i] = new DerValue(ticketInfo[i].asn1Encode()); tickets[i] = new DerValue(ticketInfo[i].asn1Encode());
}
temp.putSequence(tickets); temp.putSequence(tickets);
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x00), temp);
if (nonce != null) { if (nonce != null) {
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(nonce.intValue())); temp.putInteger(BigInteger.valueOf(nonce.intValue()));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), temp);
} }
if (timeStamp != null) { if (timeStamp != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), timeStamp.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x02), timeStamp.asn1Encode());
} }
if (usec != null) { if (usec != null) {
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(usec.intValue())); temp.putInteger(BigInteger.valueOf(usec.intValue()));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x03), temp);
} }
if (sAddress != null) { if (sAddress != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sAddress.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x04), sAddress.asn1Encode());
} }
if (rAddress != null) { if (rAddress != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), rAddress.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x05), rAddress.asn1Encode());
} }
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.write(DerValue.tag_Sequence, bytes); temp.write(DerValue.tag_Sequence, bytes);
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1D), temp); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION,
true, (byte) 0x1D), temp);
return bytes.toByteArray(); return bytes.toByteArray();
} }
} }

View File

@ -55,8 +55,8 @@ import java.math.BigInteger;
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> * <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class EncKrbPrivPart { public class EncKrbPrivPart {
public byte[] userData = null; public byte[] userData = null;
public KerberosTime timestamp; //optional public KerberosTime timestamp; //optional
public Integer usec; //optional public Integer usec; //optional
@ -70,8 +70,7 @@ public class EncKrbPrivPart {
Integer new_usec, Integer new_usec,
Integer new_seqNumber, Integer new_seqNumber,
HostAddress new_sAddress, HostAddress new_sAddress,
HostAddress new_rAddress HostAddress new_rAddress) {
) {
if (new_userData != null) { if (new_userData != null) {
userData = new_userData.clone(); userData = new_userData.clone();
} }
@ -100,35 +99,40 @@ public class EncKrbPrivPart {
DerValue der, subDer; DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C) if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) { if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) {
userData = subDer.getData().getOctetString(); userData = subDer.getData().getOctetString();
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true); timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true);
if ((der.getData().peekByte() & 0x1F) == 0x02) { if ((der.getData().peekByte() & 0x1F) == 0x02) {
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
usec = new Integer(subDer.getData().getBigInteger().intValue()); usec = new Integer(subDer.getData().getBigInteger().intValue());
} else {
usec = null;
} }
else usec = null;
if ((der.getData().peekByte() & 0x1F) == 0x03) { if ((der.getData().peekByte() & 0x1F) == 0x03) {
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
seqNumber = new Integer(subDer.getData().getBigInteger().intValue()); seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
} else {
seqNumber = null;
} }
else seqNumber = null;
sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false); sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false);
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true); rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true);
} }
if (der.getData().available() > 0) if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an EncKrbPrivPart object. * Encodes an EncKrbPrivPart object.
@ -142,8 +146,9 @@ public class EncKrbPrivPart {
temp.putOctetString(userData); temp.putOctetString(userData);
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
if (timestamp != null) if (timestamp != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), timestamp.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), timestamp.asn1Encode());
}
if (usec != null) { if (usec != null) {
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(usec.intValue())); temp.putInteger(BigInteger.valueOf(usec.intValue()));

View File

@ -47,8 +47,7 @@ public class EncTGSRepPart extends EncKDCRepPart {
KerberosTime new_renewTill, KerberosTime new_renewTill,
Realm new_srealm, Realm new_srealm,
PrincipalName new_sname, PrincipalName new_sname,
HostAddresses new_caddr HostAddresses new_caddr) {
) {
super( super(
new_key, new_key,
new_lastReq, new_lastReq,
@ -62,8 +61,7 @@ public class EncTGSRepPart extends EncKDCRepPart {
new_srealm, new_srealm,
new_sname, new_sname,
new_caddr, new_caddr,
Krb5.KRB_ENC_TGS_REP_PART Krb5.KRB_ENC_TGS_REP_PART);
);
} }
public EncTGSRepPart(byte[] data) throws Asn1Exception, public EncTGSRepPart(byte[] data) throws Asn1Exception,
@ -85,5 +83,4 @@ public class EncTGSRepPart extends EncKDCRepPart {
IOException { IOException {
return asn1Encode(Krb5.KRB_ENC_TGS_REP_PART); return asn1Encode(Krb5.KRB_ENC_TGS_REP_PART);
} }
} }

View File

@ -62,6 +62,7 @@ import java.io.*;
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class EncTicketPart { public class EncTicketPart {
public TicketFlags flags; public TicketFlags flags;
public EncryptionKey key; public EncryptionKey key;
public Realm crealm; public Realm crealm;
@ -85,8 +86,7 @@ public class EncTicketPart {
KerberosTime new_endtime, KerberosTime new_endtime,
KerberosTime new_renewTill, KerberosTime new_renewTill,
HostAddresses new_caddr, HostAddresses new_caddr,
AuthorizationData new_authorizationData AuthorizationData new_authorizationData) {
) {
flags = new_flags; flags = new_flags;
key = new_key; key = new_key;
crealm = new_crealm; crealm = new_crealm;
@ -117,7 +117,6 @@ public class EncTicketPart {
* @exception IOException if an I/O error occurs while reading encoded data. * @exception IOException if an I/O error occurs while reading encoded data.
* @exception RealmException if an error occurs while parsing a Realm object. * @exception RealmException if an error occurs while parsing a Realm object.
*/ */
private static String getHexBytes(byte[] bytes, int len) private static String getHexBytes(byte[] bytes, int len)
throws IOException { throws IOException {
@ -143,11 +142,13 @@ public class EncTicketPart {
authorizationData = null; authorizationData = null;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x03) if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x03)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
flags = TicketFlags.parse(der.getData(), (byte) 0x00, false); flags = TicketFlags.parse(der.getData(), (byte) 0x00, false);
key = EncryptionKey.parse(der.getData(), (byte) 0x01, false); key = EncryptionKey.parse(der.getData(), (byte) 0x01, false);
crealm = Realm.parse(der.getData(), (byte) 0x02, false); crealm = Realm.parse(der.getData(), (byte) 0x02, false);
@ -165,8 +166,9 @@ public class EncTicketPart {
if (der.getData().available() > 0) { if (der.getData().available() > 0) {
authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x0A, true); authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x0A, true);
} }
if (der.getData().available() > 0) if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
} }
@ -176,31 +178,46 @@ public class EncTicketPart {
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
* @exception IOException if an I/O error occurs while reading encoded data. * @exception IOException if an I/O error occurs while reading encoded data.
*/ */
public byte[] asn1Encode() throws Asn1Exception, IOException { public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream bytes = new DerOutputStream(); DerOutputStream bytes = new DerOutputStream();
DerOutputStream temp = new DerOutputStream(); DerOutputStream temp = new DerOutputStream();
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), flags.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), key.asn1Encode()); true, (byte) 0x00), flags.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), crealm.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), cname.asn1Encode()); true, (byte) 0x01), key.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), transited.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), authtime.asn1Encode()); true, (byte) 0x02), crealm.asn1Encode());
if (starttime != null) bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), starttime.asn1Encode()); true, (byte) 0x03), cname.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), endtime.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x04), transited.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x05), authtime.asn1Encode());
if (starttime != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x06), starttime.asn1Encode());
}
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x07), endtime.asn1Encode());
if (renewTill != null) if (renewTill != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), renewTill.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x08), renewTill.asn1Encode());
}
if (caddr != null) if (caddr != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), caddr.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x09), caddr.asn1Encode());
}
if (authorizationData != null) if (authorizationData != null) {
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), authorizationData.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x0A), authorizationData.asn1Encode());
}
temp.write(DerValue.tag_Sequence, bytes); temp.write(DerValue.tag_Sequence, bytes);
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x03), temp); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION,
true, (byte) 0x03), temp);
return bytes.toByteArray(); return bytes.toByteArray();
} }
} }

View File

@ -35,6 +35,7 @@ import sun.security.util.*;
import java.util.Vector; import java.util.Vector;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* Implements the ASN.1 KDC-REP type. * Implements the ASN.1 KDC-REP type.
* *
@ -59,14 +60,13 @@ import java.math.BigInteger;
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> * <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class KDCRep { public class KDCRep {
public Realm crealm; public Realm crealm;
public PrincipalName cname; public PrincipalName cname;
public Ticket ticket; public Ticket ticket;
public EncryptedData encPart; public EncryptedData encPart;
public EncKDCRepPart encKDCRepPart; //not part of ASN.1 encoding public EncKDCRepPart encKDCRepPart; //not part of ASN.1 encoding
private int pvno; private int pvno;
private int msgType; private int msgType;
private PAData[] pAData = null; //optional private PAData[] pAData = null; //optional
@ -78,8 +78,7 @@ public class KDCRep {
PrincipalName new_cname, PrincipalName new_cname,
Ticket new_ticket, Ticket new_ticket,
EncryptedData new_encPart, EncryptedData new_encPart,
int req_type int req_type) throws IOException {
) throws IOException {
pvno = Krb5.PVNO; pvno = Krb5.PVNO;
msgType = req_type; msgType = req_type;
if (new_pAData != null) { if (new_pAData != null) {
@ -101,7 +100,8 @@ public class KDCRep {
public KDCRep() { public KDCRep() {
} }
public KDCRep(byte[] data, int req_type) throws Asn1Exception, KrbApErrException, RealmException, IOException { public KDCRep(byte[] data, int req_type) throws Asn1Exception,
KrbApErrException, RealmException, IOException {
init(new DerValue(data), req_type); init(new DerValue(data), req_type);
} }
@ -112,14 +112,11 @@ public class KDCRep {
/* /*
// Not used? Don't know what keyusage to use here %%% // Not used? Don't know what keyusage to use here %%%
public void decrypt(EncryptionKey key) throws Asn1Exception, public void decrypt(EncryptionKey key) throws Asn1Exception,
IOException, KrbException, RealmException { IOException, KrbException, RealmException {
encKDCRepPart = new EncKDCRepPart(encPart.decrypt(key), encKDCRepPart = new EncKDCRepPart(encPart.decrypt(key), msgType);
msgType);
} }
*/ */
/** /**
* Initializes an KDCRep object. * Initializes an KDCRep object.
* *
@ -127,8 +124,10 @@ public class KDCRep {
* @param req_type reply message type. * @param req_type reply message type.
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
* @exception IOException if an I/O error occurs while reading encoded data. * @exception IOException if an I/O error occurs while reading encoded data.
* @exception RealmException if an error occurs while constructing a Realm object from DER-encoded data. * @exception RealmException if an error occurs while constructing
* @exception KrbApErrException if the value read from the DER-encoded data stream does not match the pre-defined value. * a Realm object from DER-encoded data.
* @exception KrbApErrException if the value read from the DER-encoded
* data stream does not match the pre-defined value.
* *
*/ */
protected void init(DerValue encoding, int req_type) protected void init(DerValue encoding, int req_type)
@ -151,8 +150,9 @@ public class KDCRep {
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x00) { if ((subDer.getTag() & 0x1F) == 0x00) {
pvno = subDer.getData().getBigInteger().intValue(); pvno = subDer.getData().getBigInteger().intValue();
if (pvno != Krb5.PVNO) if (pvno != Krb5.PVNO) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
}
} else { } else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
@ -184,7 +184,6 @@ public class KDCRep {
} }
} }
/** /**
* Encodes this object to a byte array. * Encodes this object to a byte array.
* @return byte array of encoded APReq object. * @return byte array of encoded APReq object.
@ -197,10 +196,12 @@ public class KDCRep {
DerOutputStream bytes = new DerOutputStream(); DerOutputStream bytes = new DerOutputStream();
DerOutputStream temp = new DerOutputStream(); DerOutputStream temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(pvno)); temp.putInteger(BigInteger.valueOf(pvno));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x00), temp);
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(msgType)); temp.putInteger(BigInteger.valueOf(msgType));
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), temp);
if (pAData != null && pAData.length > 0) { if (pAData != null && pAData.length > 0) {
DerOutputStream padata_stream = new DerOutputStream(); DerOutputStream padata_stream = new DerOutputStream();
for (int i = 0; i < pAData.length; i++) { for (int i = 0; i < pAData.length; i++) {
@ -208,12 +209,17 @@ public class KDCRep {
} }
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.write(DerValue.tag_SequenceOf, padata_stream); temp.write(DerValue.tag_SequenceOf, padata_stream);
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x02), temp);
} }
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), crealm.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), cname.asn1Encode()); true, (byte) 0x03), crealm.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), ticket.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), encPart.asn1Encode()); true, (byte) 0x04), cname.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x05), ticket.asn1Encode());
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x06), encPart.asn1Encode());
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.write(DerValue.tag_Sequence, bytes); temp.write(DerValue.tag_Sequence, bytes);
return temp.toByteArray(); return temp.toByteArray();

View File

@ -56,10 +56,9 @@ import java.math.BigInteger;
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> * <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class KDCReq { public class KDCReq {
public KDCReqBody reqBody;
public KDCReqBody reqBody;
private int pvno; private int pvno;
private int msgType; private int msgType;
private PAData[] pAData = null; //optional private PAData[] pAData = null; //optional
@ -129,20 +128,22 @@ public class KDCReq {
if ((subDer.getTag() & 0x01F) == 0x01) { if ((subDer.getTag() & 0x01F) == 0x01) {
bint = subDer.getData().getBigInteger(); bint = subDer.getData().getBigInteger();
this.pvno = bint.intValue(); this.pvno = bint.intValue();
if (this.pvno != Krb5.PVNO) if (this.pvno != Krb5.PVNO) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
} }
else } else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x01F) == 0x02) { if ((subDer.getTag() & 0x01F) == 0x02) {
bint = subDer.getData().getBigInteger(); bint = subDer.getData().getBigInteger();
this.msgType = bint.intValue(); this.msgType = bint.intValue();
if (this.msgType != req_type) if (this.msgType != req_type) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE); throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
} }
else } else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x01F) == 0x03) { if ((subDer.getTag() & 0x01F) == 0x03) {
DerValue subsubDer = subDer.getData().getDerValue(); DerValue subsubDer = subDer.getData().getDerValue();
@ -157,16 +158,17 @@ public class KDCReq {
pAData = new PAData[v.size()]; pAData = new PAData[v.size()];
v.copyInto(pAData); v.copyInto(pAData);
} }
} else {
pAData = null;
} }
else pAData = null;
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x01F) == 0x04) { if ((subDer.getTag() & 0x01F) == 0x04) {
DerValue subsubDer = subDer.getData().getDerValue(); DerValue subsubDer = subDer.getData().getDerValue();
reqBody = new KDCReqBody(subsubDer, msgType); reqBody = new KDCReqBody(subsubDer, msgType);
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes this object to a byte array. * Encodes this object to a byte array.
@ -181,10 +183,12 @@ public class KDCReq {
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(pvno)); temp.putInteger(BigInteger.valueOf(pvno));
out = new DerOutputStream(); out = new DerOutputStream();
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), temp);
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(msgType)); temp.putInteger(BigInteger.valueOf(msgType));
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x02), temp);
if (pAData != null && pAData.length > 0) { if (pAData != null && pAData.length > 0) {
temp = new DerOutputStream(); temp = new DerOutputStream();
for (int i = 0; i < pAData.length; i++) { for (int i = 0; i < pAData.length; i++) {
@ -192,19 +196,20 @@ public class KDCReq {
} }
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.tag_SequenceOf, temp); bytes.write(DerValue.tag_SequenceOf, temp);
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), bytes); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x03), bytes);
} }
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), reqBody.asn1Encode(msgType)); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x04), reqBody.asn1Encode(msgType));
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.tag_Sequence, out); bytes.write(DerValue.tag_Sequence, out);
out = new DerOutputStream(); out = new DerOutputStream();
out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)msgType), bytes); out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
true, (byte) msgType), bytes);
return out.toByteArray(); return out.toByteArray();
} }
public byte[] asn1EncodeReqBody() throws Asn1Exception, IOException public byte[] asn1EncodeReqBody() throws Asn1Exception, IOException {
{
return reqBody.asn1Encode(msgType); return reqBody.asn1Encode(msgType);
} }
} }

View File

@ -56,11 +56,10 @@ import java.math.BigInteger;
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> * <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
*/ */
public class KRBCred { public class KRBCred {
public Ticket[] tickets = null; public Ticket[] tickets = null;
public EncryptedData encPart; public EncryptedData encPart;
private int pvno; private int pvno;
private int msgType; private int msgType;
@ -103,29 +102,32 @@ public class KRBCred {
RealmException, KrbApErrException, IOException { RealmException, KrbApErrException, IOException {
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x16) if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x16)
|| (encoding.isApplication() != true) || (encoding.isApplication() != true)
|| (encoding.isConstructed() != true)) || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
DerValue der, subDer; DerValue der, subDer;
der = encoding.getData().getDerValue(); der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence) if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x00) { if ((subDer.getTag() & 0x1F) == 0x00) {
pvno = subDer.getData().getBigInteger().intValue(); pvno = subDer.getData().getBigInteger().intValue();
if (pvno != Krb5.PVNO) { if (pvno != Krb5.PVNO) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
} }
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x01) { if ((subDer.getTag() & 0x1F) == 0x01) {
msgType = subDer.getData().getBigInteger().intValue(); msgType = subDer.getData().getBigInteger().intValue();
if (msgType != Krb5.KRB_CRED) if (msgType != Krb5.KRB_CRED) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE); throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
} }
else } else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
subDer = der.getData().getDerValue(); subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x02) { if ((subDer.getTag() & 0x1F) == 0x02) {
DerValue subsubDer = subDer.getData().getDerValue(); DerValue subsubDer = subDer.getData().getDerValue();
@ -140,15 +142,15 @@ public class KRBCred {
tickets = new Ticket[v.size()]; tickets = new Ticket[v.size()];
v.copyInto(tickets); v.copyInto(tickets);
} }
} } else {
else
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
encPart = EncryptedData.parse(der.getData(), (byte) 0x03, false); encPart = EncryptedData.parse(der.getData(), (byte) 0x03, false);
if (der.getData().available() > 0) if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID); throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} }
}
/** /**
* Encodes an KRBCred object. * Encodes an KRBCred object.
@ -161,23 +163,27 @@ public class KRBCred {
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(pvno)); temp.putInteger(BigInteger.valueOf(pvno));
out = new DerOutputStream(); out = new DerOutputStream();
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x00), temp);
temp = new DerOutputStream(); temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(msgType)); temp.putInteger(BigInteger.valueOf(msgType));
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), temp);
temp = new DerOutputStream(); temp = new DerOutputStream();
for (int i = 0; i < tickets.length; i++) { for (int i = 0; i < tickets.length; i++) {
temp.write(tickets[i].asn1Encode()); temp.write(tickets[i].asn1Encode());
} }
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.tag_SequenceOf, temp); bytes.write(DerValue.tag_SequenceOf, temp);
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), bytes); out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode()); true, (byte) 0x02), bytes);
out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x03), encPart.asn1Encode());
bytes = new DerOutputStream(); bytes = new DerOutputStream();
bytes.write(DerValue.tag_Sequence, out); bytes.write(DerValue.tag_Sequence, out);
out = new DerOutputStream(); out = new DerOutputStream();
out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x16), bytes); out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
true, (byte) 0x16), bytes);
return out.toByteArray(); return out.toByteArray();
} }
} }

View File

@ -34,6 +34,7 @@ import sun.security.krb5.*;
import sun.security.krb5.internal.*; import sun.security.krb5.internal.*;
public class Credentials { public class Credentials {
PrincipalName cname; PrincipalName cname;
Realm crealm; Realm crealm;
PrincipalName sname; PrincipalName sname;
@ -66,12 +67,14 @@ public class Credentials {
Ticket new_ticket, Ticket new_ticket,
Ticket new_secondTicket) { Ticket new_secondTicket) {
cname = (PrincipalName) new_cname.clone(); cname = (PrincipalName) new_cname.clone();
if (new_cname.getRealm() != null) if (new_cname.getRealm() != null) {
crealm = (Realm) new_cname.getRealm().clone(); crealm = (Realm) new_cname.getRealm().clone();
}
sname = (PrincipalName) new_sname.clone(); sname = (PrincipalName) new_sname.clone();
if (new_sname.getRealm() != null) if (new_sname.getRealm() != null) {
srealm = (Realm) new_sname.getRealm().clone(); srealm = (Realm) new_sname.getRealm().clone();
}
key = (EncryptionKey) new_key.clone(); key = (EncryptionKey) new_key.clone();
@ -79,30 +82,30 @@ public class Credentials {
starttime = (KerberosTime) new_starttime.clone(); starttime = (KerberosTime) new_starttime.clone();
endtime = (KerberosTime) new_endtime.clone(); endtime = (KerberosTime) new_endtime.clone();
renewTill = (KerberosTime) new_renewTill.clone(); renewTill = (KerberosTime) new_renewTill.clone();
if (new_caddr != null) if (new_caddr != null) {
caddr = (HostAddresses) new_caddr.clone(); caddr = (HostAddresses) new_caddr.clone();
}
if (new_authData != null) { if (new_authData != null) {
authorizationData authorizationData = (AuthorizationData) new_authData.clone();
= (AuthorizationData)new_authData.clone();
} }
isEncInSKey = new_isEncInSKey; isEncInSKey = new_isEncInSKey;
flags = (TicketFlags) new_flags.clone(); flags = (TicketFlags) new_flags.clone();
ticket = (Ticket) (new_ticket.clone()); ticket = (Ticket) (new_ticket.clone());
if (new_secondTicket != null) if (new_secondTicket != null) {
secondTicket = (Ticket) new_secondTicket.clone(); secondTicket = (Ticket) new_secondTicket.clone();
} }
}
public Credentials( public Credentials(
KDCRep kdcRep, KDCRep kdcRep,
Ticket new_secondTicket, Ticket new_secondTicket,
AuthorizationData new_authorizationData, AuthorizationData new_authorizationData,
boolean new_isEncInSKey boolean new_isEncInSKey) {
) {
if (kdcRep.encKDCRepPart == null) //can't store while encrypted if (kdcRep.encKDCRepPart == null) //can't store while encrypted
{
return; return;
}
crealm = (Realm) kdcRep.crealm.clone(); crealm = (Realm) kdcRep.crealm.clone();
cname = (PrincipalName) kdcRep.cname.clone(); cname = (PrincipalName) kdcRep.cname.clone();
ticket = (Ticket) kdcRep.ticket.clone(); ticket = (Ticket) kdcRep.ticket.clone();
@ -130,35 +133,37 @@ public class Credentials {
srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone(); srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone();
try { try {
sname.setRealm(srealm); sname.setRealm(srealm);
} } catch (RealmException e) {
catch (RealmException e) {
} }
cname = (PrincipalName) kdcRep.cname.clone(); cname = (PrincipalName) kdcRep.cname.clone();
crealm = (Realm) kdcRep.crealm.clone(); crealm = (Realm) kdcRep.crealm.clone();
try { try {
cname.setRealm(crealm); cname.setRealm(crealm);
} } catch (RealmException e) {
catch (RealmException e) {
} }
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone();
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone(); authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone();
if (kdcRep.encKDCRepPart.starttime != null) { if (kdcRep.encKDCRepPart.starttime != null) {
starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone(); starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone();
} else {
starttime = null;
} }
else starttime = null;
endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone(); endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone();
if (kdcRep.encKDCRepPart.renewTill != null) { if (kdcRep.encKDCRepPart.renewTill != null) {
renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone(); renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone();
} else {
renewTill = null;
} }
else renewTill = null;
// if (kdcRep.msgType == Krb5.KRB_AS_REP) { // if (kdcRep.msgType == Krb5.KRB_AS_REP) {
// isEncInSKey = false; // isEncInSKey = false;
// secondTicket = null; // secondTicket = null;
// } // }
flags = kdcRep.encKDCRepPart.flags; flags = kdcRep.encKDCRepPart.flags;
if (kdcRep.encKDCRepPart.caddr != null) if (kdcRep.encKDCRepPart.caddr != null) {
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone(); caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone();
else caddr = null; } else {
caddr = null;
}
ticket = (Ticket) kdcRep.ticket.clone(); ticket = (Ticket) kdcRep.ticket.clone();
if (new_ticket != null) { if (new_ticket != null) {
secondTicket = (Ticket) new_ticket.clone(); secondTicket = (Ticket) new_ticket.clone();
@ -176,10 +181,8 @@ public class Credentials {
boolean valid = true; boolean valid = true;
if (endtime.getTime() < System.currentTimeMillis()) { if (endtime.getTime() < System.currentTimeMillis()) {
valid = false; valid = false;
} } else if ((starttime.getTime() > System.currentTimeMillis())
else if ((starttime.getTime() > System.currentTimeMillis()) || ((starttime == null) && (authtime.getTime() > System.currentTimeMillis()))) {
|| ((starttime == null) && (authtime.getTime() > System.currentTimeMillis())))
{
valid = false; valid = false;
} }
return valid; return valid;