krb.txt
Please, see krb.txt uploaded to the case. The file contains standard Windows Domain Controller Kerberos ticket issued by Windows AD to a specific user account. It is a corp network, all patches and versions are up to date. The sample code below works just fine with version 1.60 (bcprov-jdk15on-1.60.jar). At some point after version 1.60, the implementation of ASN1InputStream.readObject() changed in a way that it no longer works. Verified that version 1.77 fails. Version 1.71 fails as well (bcprov-jdk18on-1.71).
The production use case is of course is more complex vs what the sample code below does. In production it parses out an then decyptes kerberos/spnego token to extract Windows PAC data (user authorization data aka user groups, roles etc).
package com;
import java.io.File;
import java.io.FileInputStream;
import java.security.Security;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class TestASN1 {
public static void main(String[] args) {
File f = new File("c:/temp/krb.txt");
FileInputStream fis = null;
ASN1InputStream ais = null;
try {
Security.addProvider(new BouncyCastleProvider());
fis = new FileInputStream(f);
ais = new ASN1InputStream(fis);
ASN1Primitive asn1p = ais.readObject();
System.out.println(asn1p);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (ais != null) {
ais.close();
}
if (fis != null) {
fis.close();
}
}
catch (Exception e) {
}
}
}
}
The code throws an error on line ASN1Primitive asn1p = ais.readObject();. Stack trace:
org.bouncycastle.asn1.ASN1Exception: corrupted stream detected
at org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.readVector(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.readVector(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.readTaggedObjectDL(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.buildObject(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
at com.TestASN1.main(TestASN1.java:22)
Caused by: java.lang.IllegalArgumentException: BOOLEAN value should have 1 byte in it
at org.bouncycastle.asn1.ASN1Boolean.createPrimitive(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.createPrimitiveDERObject(Unknown Source)
at org.bouncycastle.asn1.ASN1InputStream.buildObject(Unknown Source)
... 7 more
Edited for formatting by @cipherboy.
krb.txt
Please, see krb.txt uploaded to the case. The file contains standard Windows Domain Controller Kerberos ticket issued by Windows AD to a specific user account. It is a corp network, all patches and versions are up to date. The sample code below works just fine with version 1.60 (bcprov-jdk15on-1.60.jar). At some point after version 1.60, the implementation of ASN1InputStream.readObject() changed in a way that it no longer works. Verified that version 1.77 fails. Version 1.71 fails as well (bcprov-jdk18on-1.71).
The production use case is of course is more complex vs what the sample code below does. In production it parses out an then decyptes kerberos/spnego token to extract Windows PAC data (user authorization data aka user groups, roles etc).
The code throws an error on line ASN1Primitive asn1p = ais.readObject();. Stack trace:
Edited for formatting by @cipherboy.