I'm trying to generate a Certificate Signing Request (CSR) using Bouncy Castle in CFML/Lucee. The CSR needs to include Subject Alternative Names (SANs) for both DNS names and IP addresses. However, I'm getting an argument type mismatch error when trying to create GeneralName objects. Here's my current approach:
// Add Subject Alternative Names
var vector = createObject("java", "org.bouncycastle.asn1.ASN1EncodableVector").init();
// Add FQDN as DNS name
var dnsType = javacast("int", 2); // DNS type is 2
var GeneralName = createObject("java", "org.bouncycastle.asn1.x509.GeneralName");
var DERIA5String = createObject("java", "org.bouncycastle.asn1.DERIA5String");
// Convert FQDN to ASN1String
var fqdnStr = DERIA5String.getInstance(arguments.fqdn);
vector.add(GeneralName.init(dnsType, fqdnStr));
// Add IP address
if (len(trim(arguments.ipAddress))) {
var inetAddress = createObject("java", "java.InetAddress").getByName(arguments.ipAddress);
var DEROctetString = createObject("java", "org.bouncycastle.asn1.DEROctetString");
var ipStr = DEROctetString.getInstance(inetAddress.getAddress());
vector.add(GeneralName.init(javacast("int", 7), ipStr)); // IP type is 7
}
var derSequence = createObject("java", "org.bouncycastle.asn1.DERSequence").init(vector);
var generalNames = createObject("java", "org.bouncycastle.asn1.x509.GeneralNames").init(derSequence);
Error:
[ERROR] 2025-02-03 14:50:36 modules_app.dod-csr-generator.models.CertificateGenerator Error generating CSR: argument type mismatch | ExtraInfo:
ErrorType = java.lang.IllegalArgumentException Message = argument type mismatch StackTrace = lucee.runtime.exp.NativeException: argument type mismatch
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance
I've tried several approaches including:
Using GeneralName.dNSName and GeneralName.iPAddress constants Directly creating ASN1 strings Using different constructor patterns Using DERSequence with ASN1EncodableVector Using different javacast types
The CSR itself works when I don't include SANs, but I need to support both DNS names and IP addresses in the SAN extension. I'm using Bouncy Castle 1.76 with Lucee 5.x. Any insights on the correct way to create GeneralName objects in CFML would be appreciated.
I'm trying to generate a Certificate Signing Request (CSR) using Bouncy Castle in CFML/Lucee. The CSR needs to include Subject Alternative Names (SANs) for both DNS names and IP addresses. However, I'm getting an argument type mismatch error when trying to create GeneralName objects. Here's my current approach:
// Add Subject Alternative Names
var vector = createObject("java", "org.bouncycastle.asn1.ASN1EncodableVector").init();
// Add FQDN as DNS name
var dnsType = javacast("int", 2); // DNS type is 2
var GeneralName = createObject("java", "org.bouncycastle.asn1.x509.GeneralName");
var DERIA5String = createObject("java", "org.bouncycastle.asn1.DERIA5String");
// Convert FQDN to ASN1String
var fqdnStr = DERIA5String.getInstance(arguments.fqdn);
vector.add(GeneralName.init(dnsType, fqdnStr));
// Add IP address
if (len(trim(arguments.ipAddress))) {
var inetAddress = createObject("java", "java.net.InetAddress").getByName(arguments.ipAddress);
var DEROctetString = createObject("java", "org.bouncycastle.asn1.DEROctetString");
var ipStr = DEROctetString.getInstance(inetAddress.getAddress());
vector.add(GeneralName.init(javacast("int", 7), ipStr)); // IP type is 7
}
var derSequence = createObject("java", "org.bouncycastle.asn1.DERSequence").init(vector);
var generalNames = createObject("java", "org.bouncycastle.asn1.x509.GeneralNames").init(derSequence);
Error:
[ERROR] 2025-02-03 14:50:36 modules_app.dod-csr-generator.models.CertificateGenerator Error generating CSR: argument type mismatch | ExtraInfo:
ErrorType = java.lang.IllegalArgumentException Message = argument type mismatch StackTrace = lucee.runtime.exp.NativeException: argument type mismatch
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance
I've tried several approaches including:
Using GeneralName.dNSName and GeneralName.iPAddress constants Directly creating ASN1 strings Using different constructor patterns Using DERSequence with ASN1EncodableVector Using different javacast types
The CSR itself works when I don't include SANs, but I need to support both DNS names and IP addresses in the SAN extension. I'm using Bouncy Castle 1.76 with Lucee 5.x. Any insights on the correct way to create GeneralName objects in CFML would be appreciated.
(Using Java syntax for code)
I expect the problem is here:
DEROctetString.getInstance(inetAddress.getAddress())
That tries to parse the IP address octets, but they only need to be wrapped:
new DEROctetString(inetAddress.getAddress())
Actually it may be simpler to pass the IP address String directly to a different GeneralName constructor:
new GeneralName(GeneralName.iPAddress, arguments.ipAddress)