link start!

This commit is contained in:
cherubin
2026-03-17 13:31:18 -07:00
commit 08abe87cfb
5910 changed files with 386288 additions and 0 deletions
@@ -0,0 +1,141 @@
/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* javax.baja.file.BDataFile
* javax.baja.file.BDirectory
* javax.baja.file.BFileSpace
* javax.baja.file.BIFile
* javax.baja.file.FilePath
* javax.baja.file.FileUtil
* javax.baja.sys.Context
*/
package com.tridium.platform.pki;
import com.tridium.platform.pki.PemInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import javax.baja.file.BDataFile;
import javax.baja.file.BDirectory;
import javax.baja.file.BFileSpace;
import javax.baja.file.BIFile;
import javax.baja.file.FilePath;
import javax.baja.file.FileUtil;
import javax.baja.sys.Context;
/*
* Illegal identifiers - consider using --renameillegalidents true
*/
public class ClientPrivateKeyInfo {
public static final FilePath CLIENT_KEYS_PATH = new FilePath("!pki/clientkeys");
public static final FilePath CLIENT_CERTS_PATH = new FilePath("!pki/clientcerts");
public static final ClientPrivateKeyInfo BLANK_KEY_CERTIFICATE = new ClientPrivateKeyInfo();
public BIFile keyFile;
public BIFile certFile;
public boolean hasKey;
public Exception parseException;
public static ClientPrivateKeyInfo[] list(BFileSpace bFileSpace) throws Exception {
return ClientPrivateKeyInfo.list(bFileSpace, CLIENT_KEYS_PATH, CLIENT_CERTS_PATH);
}
public static ClientPrivateKeyInfo[] list(BFileSpace bFileSpace, FilePath filePath, FilePath filePath2) throws Exception {
BDirectory bDirectory = (BDirectory)bFileSpace.findFile(filePath);
BDirectory bDirectory2 = (BDirectory)bFileSpace.findFile(filePath2);
if (bDirectory == null || bDirectory2 == null) {
return new ClientPrivateKeyInfo[0];
}
return ClientPrivateKeyInfo.make(bDirectory.listFiles(), bDirectory2);
}
public static ClientPrivateKeyInfo[] make(BIFile[] bIFileArray, BDirectory bDirectory) throws Exception {
if (bIFileArray == null) {
return new ClientPrivateKeyInfo[0];
}
ClientPrivateKeyInfo[] clientPrivateKeyInfoArray = new ClientPrivateKeyInfo[bIFileArray.length];
int n = 0;
while (n < bIFileArray.length) {
clientPrivateKeyInfoArray[n] = new ClientPrivateKeyInfo(bIFileArray[n]);
if (clientPrivateKeyInfoArray[n].keyFile != null && clientPrivateKeyInfoArray[n].certFile == null && bDirectory != null) {
clientPrivateKeyInfoArray[n].certFile = clientPrivateKeyInfoArray[n].keyFile.getFileSpace().findFile(bDirectory.getFilePath().merge(clientPrivateKeyInfoArray[n].getNormalCertFilename()));
}
++n;
}
return clientPrivateKeyInfoArray;
}
public String getNormalCertFilename() {
return FileUtil.getBase((String)this.keyFile.getFileName()) + "_cert.pem";
}
/*
* WARNING - Removed back jump from a try to a catch block - possible behaviour change.
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
public void load(BIFile bIFile) throws Exception {
this.keyFile = bIFile;
String string = this.keyFile.getExtension();
if ("PFX".equalsIgnoreCase(string) || "P12".equalsIgnoreCase(string)) {
this.hasKey = true;
this.certFile = bIFile;
return;
}
if (!"PEM".equalsIgnoreCase(string)) return;
InputStream inputStream = bIFile.getInputStream();
PemInputStream pemInputStream = new PemInputStream(new BufferedInputStream(inputStream));
try {
try {
this.certFile = null;
if (pemInputStream.readToEntry(2) > 0) {
this.hasKey = true;
}
}
catch (Exception exception) {
this.hasKey = false;
}
}
catch (Throwable throwable) {
Object var6_7 = null;
pemInputStream.close();
throw throwable;
}
{
Object var6_8 = null;
}
pemInputStream.close();
}
public String toString() {
return this.toString(null);
}
public String toString(Context context) {
if (this == BLANK_KEY_CERTIFICATE) {
return "NONE";
}
return this.keyFile.getFileName();
}
private final /* synthetic */ void this() {
this.keyFile = null;
this.certFile = null;
this.hasKey = false;
this.parseException = null;
}
public ClientPrivateKeyInfo(BIFile bIFile) throws Exception {
this.this();
this.load(bIFile);
}
private ClientPrivateKeyInfo() {
this.this();
this.keyFile = new BDataFile();
this.certFile = new BDataFile();
this.hasKey = false;
this.parseException = null;
}
}
@@ -0,0 +1,302 @@
/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* javax.baja.file.BDataFile
* javax.baja.file.BDirectory
* javax.baja.file.BFileSpace
* javax.baja.file.BIFile
* javax.baja.file.FilePath
* javax.baja.nre.util.Array
* javax.baja.nre.util.TextUtil
* javax.baja.sys.BAbsTime
* javax.baja.sys.Context
*/
package com.tridium.platform.pki;
import com.tridium.platform.pki.PemInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.baja.file.BDataFile;
import javax.baja.file.BDirectory;
import javax.baja.file.BFileSpace;
import javax.baja.file.BIFile;
import javax.baja.file.FilePath;
import javax.baja.nre.util.Array;
import javax.baja.nre.util.TextUtil;
import javax.baja.sys.BAbsTime;
import javax.baja.sys.Context;
/*
* Illegal identifiers - consider using --renameillegalidents true
*/
public class PemCertInfo {
public static final FilePath CA_CERTS_PATH = new FilePath("!pki/cacerts");
public static final FilePath SERVER_CERTS_PATH = new FilePath("!pki/servercerts");
public static final PemCertInfo BLANK_CERTIFICATE = new PemCertInfo();
public static final int CERT_USAGE_CERT_SIGN = 5;
public BIFile file;
public X509Certificate cert;
public String subjectCn;
public String subject;
public String issuerCn;
public String issuer;
public Exception parseException;
static /* synthetic */ Class class$com$tridium$platform$pki$PemCertInfo;
public static PemCertInfo[] listCACerts(BFileSpace bFileSpace) throws Exception {
return PemCertInfo.list(bFileSpace, CA_CERTS_PATH);
}
public static PemCertInfo[] listServerCerts(BFileSpace bFileSpace) throws Exception {
return PemCertInfo.list(bFileSpace, SERVER_CERTS_PATH);
}
public static PemCertInfo[] list(BFileSpace bFileSpace, FilePath filePath) throws Exception {
BDirectory bDirectory = (BDirectory)bFileSpace.findFile(filePath);
if (bDirectory == null) {
return new PemCertInfo[0];
}
return PemCertInfo.makeCertificates(bDirectory.listFiles());
}
public static PemCertInfo[] makeCACertificates(BFileSpace bFileSpace) throws Exception {
BDirectory bDirectory = (BDirectory)bFileSpace.findFile(CA_CERTS_PATH);
return PemCertInfo.makeCertificates(bDirectory == null ? null : bDirectory.listFiles());
}
public static PemCertInfo[] makeServerCertificates(BFileSpace bFileSpace) throws Exception {
BDirectory bDirectory = (BDirectory)bFileSpace.findFile(SERVER_CERTS_PATH);
return PemCertInfo.makeCertificates(bDirectory == null ? null : bDirectory.listFiles());
}
public static PemCertInfo[] makeCertificates(BIFile[] bIFileArray) throws Exception {
if (bIFileArray == null) {
return new PemCertInfo[0];
}
Class clazz = class$com$tridium$platform$pki$PemCertInfo;
if (clazz == null) {
clazz = class$com$tridium$platform$pki$PemCertInfo = PemCertInfo.class("[Lcom.tridium.platform.pki.PemCertInfo;", false);
}
Array array = new Array(clazz);
int n = 0;
while (n < bIFileArray.length) {
if (!bIFileArray[n].getFileName().endsWith(".0")) {
array.add((Object)new PemCertInfo(bIFileArray[n], new int[]{5}));
}
++n;
}
return (PemCertInfo[])array.trim();
}
public static X509Certificate getPEMCertificate(BIFile bIFile, int n) {
return PemCertInfo.getPEMCertificate(bIFile, new int[]{n});
}
/*
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
public static X509Certificate getPEMCertificate(BIFile bIFile, int[] nArray) {
if (bIFile == null) return null;
if (bIFile instanceof BDirectory) return null;
try {
PemInputStream pemInputStream;
block18: {
X509Certificate x509Certificate;
block21: {
X509Certificate x509Certificate2;
block20: {
InputStream inputStream = bIFile.getInputStream();
pemInputStream = new PemInputStream(new BufferedInputStream(inputStream));
try {
if (pemInputStream.readToEntry(1) <= 0) break block18;
X509Certificate x509Certificate3 = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(pemInputStream);
if (nArray != null) {
if (x509Certificate3.getKeyUsage() != null) {
int n = 0;
while (n < nArray.length) {
if (!x509Certificate3.getKeyUsage()[nArray[n]]) {
X509Certificate x509Certificate4 = null;
Object var5_11 = null;
try {
pemInputStream.close();
return x509Certificate4;
}
catch (Exception exception) {}
return x509Certificate4;
}
++n;
}
} else {
int n = 0;
while (n < nArray.length) {
if (nArray[n] == 5) {
if (x509Certificate3.getBasicConstraints() != -1) break;
x509Certificate2 = null;
break block20;
}
++n;
}
}
}
x509Certificate = x509Certificate3;
break block21;
}
catch (Throwable throwable) {
Object var5_14 = null;
try {}
catch (Exception exception) {}
pemInputStream.close();
throw throwable;
throw throwable;
}
}
Object var5_12 = null;
try {}
catch (Exception exception) {}
pemInputStream.close();
return x509Certificate2;
}
Object var5_13 = null;
try {}
catch (Exception exception) {}
pemInputStream.close();
return x509Certificate;
}
Object var5_15 = null;
try {}
catch (Exception exception) {
return null;
}
pemInputStream.close();
return null;
}
catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
protected void load(BIFile bIFile, int[] nArray) throws Exception {
this.file = bIFile;
this.cert = PemCertInfo.getPEMCertificate(bIFile, nArray);
this.subject = this.cert == null ? null : this.cert.getSubjectX500Principal().toString();
this.issuer = this.cert == null ? null : this.cert.getIssuerX500Principal().toString();
this.subjectCn = this.subject == null ? null : PemCertInfo.getX500Cn(this.subject);
this.issuerCn = this.issuer == null ? null : PemCertInfo.getX500Cn(this.issuer);
}
public static String getX500Cn(String string) {
String[] stringArray = TextUtil.split((String)string, (char)',');
int n = 0;
while (n < stringArray.length) {
int n2 = stringArray[n].indexOf(61);
String string2 = stringArray[n].substring(0, n2).trim();
String string3 = stringArray[n].substring(n2 + 1);
if (string3.charAt(0) == '\"') {
while (string3.charAt(string3.length() - 1) != '\"') {
string3 = string3 + stringArray[++n];
}
}
if (string2.equals("CN")) {
return string3;
}
++n;
}
return null;
}
public String getSubject() {
return this.subjectCn == null ? this.subject : this.subjectCn;
}
public BAbsTime getStart() {
if (this.cert != null) {
return BAbsTime.make((long)this.cert.getNotBefore().getTime());
}
return null;
}
public BAbsTime getEnd() {
if (this.cert != null) {
return BAbsTime.make((long)this.cert.getNotAfter().getTime());
}
return null;
}
public String getSignatureAlgName() {
if (this.cert != null) {
return this.cert.getSigAlgName();
}
return null;
}
public String getIssuer() {
return this.issuerCn == null ? this.issuer : this.issuerCn;
}
public String toString() {
return this.toString(null);
}
public String toString(Context context) {
if (this == BLANK_CERTIFICATE) {
return "NONE";
}
if (this.subjectCn == null) {
if (this.subject == null) {
return this.file.getFileName();
}
return this.subject;
}
return this.subjectCn;
}
static /* synthetic */ Class class(String string, boolean bl) {
try {
Class<?> clazz = Class.forName(string);
if (!bl) {
clazz = clazz.getComponentType();
}
return clazz;
}
catch (ClassNotFoundException classNotFoundException) {
throw new NoClassDefFoundError(classNotFoundException.getMessage());
}
}
private final /* synthetic */ void this() {
this.file = null;
this.cert = null;
this.subjectCn = null;
this.subject = null;
this.issuerCn = null;
this.issuer = null;
this.parseException = null;
}
private PemCertInfo() {
this.this();
this.file = new BDataFile();
this.cert = null;
this.subjectCn = null;
this.subject = null;
this.issuerCn = null;
this.issuer = null;
this.parseException = null;
}
public PemCertInfo(BIFile bIFile, int n) throws Exception {
this(bIFile, new int[]{n});
}
public PemCertInfo(BIFile bIFile, int[] nArray) throws Exception {
this.this();
this.load(bIFile, nArray);
}
}
@@ -0,0 +1,313 @@
/*
* Decompiled with CFR 0.152.
*/
package com.tridium.platform.pki;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
/*
* Illegal identifiers - consider using --renameillegalidents true
*/
public class PemInputStream
extends PushbackInputStream {
public static final String HEADER_CERT = "-----BEGIN CERTIFICATE-----";
public static final String FOOTER_CERT = "-----END CERTIFICATE-----\n";
public static final String HEADER_KEY = "-----BEGIN RSA PRIVATE KEY-----";
public static final String FOOTER_KEY = "-----END RSA PRIVATE KEY-----\n";
public static final int ENTRY_CERT = 1;
public static final int ENTRY_KEY = 2;
public static final int ENTRY_UNSUPPORTED = 128;
public static final int ENTRY_ANY = 255;
public static final int ENTRY_NONE = -1;
public static int POSITION_BEFORE_HEADER = 1;
public static int POSITION_AFTER_HEADER = 2;
public static int POSITION_UNKNOWN = 0;
public static int POSITION_EOF = -1;
protected int entryPosition;
protected int entryType;
protected int markedEntryPosition;
protected int markedEntryType;
protected CircularByteBuffer recentlyRead;
protected boolean bypassSpecialReadProcessing;
/*
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
protected synchronized void determineEntryType() throws IOException {
boolean bl;
block12: {
if (this.entryPosition != POSITION_BEFORE_HEADER) {
throw new IllegalStateException("determineEntryType() can only be called at entry start");
}
bl = this.bypassSpecialReadProcessing;
this.bypassSpecialReadProcessing = true;
try {
int n;
byte[] byArray = new byte[40];
if (n < 0) {
this.entryPosition = POSITION_EOF;
this.entryType = -1;
Object var3_4 = null;
this.bypassSpecialReadProcessing = bl;
return;
}
for (n = super.read(byArray, 0, 40); n < 40; n += super.read(byArray, n, 40 - n)) {
try {
continue;
}
catch (EOFException eOFException) {
if (n > 0) {
this.unread(byArray, 0, n);
}
Object var3_5 = null;
this.bypassSpecialReadProcessing = bl;
return;
}
}
this.unread(byArray, 0, byArray.length);
String string = new String(byArray);
if (string.startsWith(HEADER_CERT)) {
this.entryType = 1;
break block12;
}
if (string.startsWith(HEADER_KEY)) {
this.entryType = 2;
break block12;
}
this.entryType = 128;
}
catch (Throwable throwable) {
Object var3_6 = null;
this.bypassSpecialReadProcessing = bl;
throw throwable;
}
}
Object var3_7 = null;
this.bypassSpecialReadProcessing = bl;
}
public void unread(byte[] byArray) throws IOException {
if (!this.bypassSpecialReadProcessing) {
throw new UnsupportedOperationException();
}
super.unread(byArray);
}
public void unread(byte[] byArray, int n, int n2) throws IOException {
if (!this.bypassSpecialReadProcessing) {
throw new UnsupportedOperationException();
}
super.unread(byArray, n, n2);
}
public void unread(int n) throws IOException {
if (!this.bypassSpecialReadProcessing) {
throw new UnsupportedOperationException();
}
super.unread(n);
}
public synchronized int readToEntry(int n) throws IOException {
while (this.entryPosition == POSITION_UNKNOWN || (this.entryType & n) == 0) {
int n2 = this.read();
if (n2 < 0) break;
}
if (this.entryPosition == POSITION_AFTER_HEADER) {
this.bypassSpecialReadProcessing = true;
if (this.entryType == 1) {
this.unread(HEADER_CERT.getBytes());
} else if (this.entryType == 2) {
this.unread(HEADER_KEY.getBytes());
}
this.bypassSpecialReadProcessing = false;
this.entryPosition = POSITION_BEFORE_HEADER;
}
return this.entryType;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public synchronized int read() throws IOException {
if (this.bypassSpecialReadProcessing) {
return super.read();
}
boolean bl = this.bypassSpecialReadProcessing;
this.bypassSpecialReadProcessing = true;
try {
int n = super.read();
if (n < 0) {
this.entryPosition = POSITION_EOF;
this.entryType = -1;
} else {
this.recentlyRead.append((byte)n);
if (this.entryPosition == POSITION_BEFORE_HEADER) {
this.entryPosition = POSITION_UNKNOWN;
} else if (this.entryType == 1 && this.recentlyRead.endsWith(FOOTER_CERT)) {
this.entryPosition = POSITION_BEFORE_HEADER;
this.determineEntryType();
} else if (this.entryType == 2 && this.recentlyRead.endsWith(FOOTER_KEY)) {
this.entryPosition = POSITION_BEFORE_HEADER;
this.determineEntryType();
} else if (this.entryType == 128) {
if (this.recentlyRead.endsWith(HEADER_CERT)) {
this.entryPosition = POSITION_AFTER_HEADER;
this.entryType = 1;
} else if (this.recentlyRead.endsWith(HEADER_KEY)) {
this.entryPosition = POSITION_AFTER_HEADER;
this.entryType = 2;
}
}
}
int n2 = n;
Object var3_4 = null;
this.bypassSpecialReadProcessing = bl;
return n2;
}
catch (Throwable throwable) {
Object var3_5 = null;
this.bypassSpecialReadProcessing = bl;
throw throwable;
}
}
public int read(byte[] byArray) throws IOException {
return this.read(byArray, 0, byArray.length);
}
public int read(byte[] byArray, int n, int n2) throws IOException {
int n3 = n;
while (n3 < n2) {
int n4 = this.read();
if (n4 < 0) {
return n3 == n ? -1 : n3 - n;
}
byArray[n + n3] = (byte)n4;
++n3;
}
return n2;
}
public long skip(long l) throws IOException {
long l2 = 0L;
while (l2 < l) {
int n = this.read();
if (n < 0) {
return l2;
}
++l2;
}
return l;
}
public synchronized void mark(int n) {
this.markedEntryPosition = this.entryPosition;
this.markedEntryType = this.entryType;
super.mark(n);
}
public synchronized void reset() throws IOException {
super.reset();
this.entryType = this.markedEntryType;
this.entryPosition = this.markedEntryPosition;
}
private final /* synthetic */ void this() {
this.entryPosition = POSITION_BEFORE_HEADER;
this.bypassSpecialReadProcessing = false;
}
public PemInputStream(InputStream inputStream) throws IOException {
super(inputStream, 40);
this.this();
this.entryPosition = POSITION_BEFORE_HEADER;
this.recentlyRead = new CircularByteBuffer(40);
this.determineEntryType();
}
protected static class CircularByteBuffer {
private byte[] buf;
int len;
int nextWrite;
public void clear() {
this.len = 0;
this.nextWrite = 0;
}
public void append(byte by) {
if (this.nextWrite >= this.buf.length) {
this.buf[0] = by;
this.nextWrite = 1;
} else {
this.buf[this.nextWrite] = by;
++this.nextWrite;
if (this.len < this.buf.length) {
++this.len;
}
}
}
public boolean endsWith(String string) {
if (string.length() > this.len) {
return false;
}
byte[] byArray = string.getBytes();
int n = 1;
while (n <= byArray.length) {
if (byArray[byArray.length - n] != this.get(-n)) {
return false;
}
++n;
}
return true;
}
public byte get(int n) {
int n2;
if (n < 0) {
if (n < -1 * this.len) {
throw new ArrayIndexOutOfBoundsException();
}
n2 = this.nextWrite + n;
if (n2 < 0) {
n2 += this.buf.length;
}
} else {
if (n > this.len - 1) {
throw new ArrayIndexOutOfBoundsException();
}
n2 = this.nextWrite + n;
if (n2 >= this.buf.length) {
n2 -= this.buf.length;
}
}
return this.buf[n2];
}
public int len() {
return this.len;
}
public String toString() {
byte[] byArray = new byte[this.len];
int n = 0;
while (n < this.len) {
byArray[n] = this.get(n);
++n;
}
return new String(byArray);
}
public CircularByteBuffer(int n) {
this.buf = new byte[n];
this.clear();
}
}
}