I got a Java application which is using BouncyCastle bcprov-jdk15on version 1.62. I'll show the following source code:
Pom file:
<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.62</version>
<scope>provided</scope>
</dependency>
</dependencies>
CSR.java
import org.bouncycastle.asn1.DEROutputStream;
...
public String createSigningRequest(String signAlgorithm, String subject, PublicKey publicKey, PrivateKey privateKey, String provName) {
StringBuilder sb = null;
try {
sb = new StringBuilder();
X509Name xname = new X509Name(subject);
PKCS10CertificationRequest csr = new PKCS10CertificationRequest(signAlgorithm, xname, publicKey , null, privateKey, provName);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DEROutputStream deros = new DEROutputStream(baos);
deros.writeObject(csr.toASN1Primitive());
String sTmp = new String(org.bouncycastle.util.encoders.Base64.encode(baos.toByteArray()));
sb.append(HEADER_CSR_PEM);
for (int iCnt=0; iCnt < sTmp.length(); iCnt+=CERT_REQ_LINE_LENGTH) {
int iLineLength;
if ((iCnt + CERT_REQ_LINE_LENGTH) > sTmp.length()) {
iLineLength=sTmp.length() - iCnt;
}
else {
iLineLength=CERT_REQ_LINE_LENGTH;
}
sb.append(sTmp.substring(iCnt,iCnt + iLineLength)).append("\n");
}
sb.append(FOOTER_CSR_PEM);
return sb.toString();
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | SignatureException | IOException ex) {
errorMessage = ex.getLocalizedMessage();
LOG.error("createSigningRequest : " + ex.getLocalizedMessage());
}
return "";
}
On the other side, there are BouncyCastle bcprov-jdk15on 1.69 from Maven repository. So I upgraded the pom file with this new version. Even though, I have the following misspelling instructions:
import org.bouncycastle.asn1.DEROutputStream; //DEROutputStream is not public in org.bouncycastle.asn1; cannot be accessed from outside package
...
DEROutputStream deros = new DEROutputStream(baos); //DEROutputStream is not public in org.bouncycastle.asn1; cannot be accessed from outside package
...
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | SignatureException | IOException ex) { //exception IOException is never thrown in body of corresponding try statement
These three instruccions are not recognized. My question is what are the new instructions in order to change according to bcprov-jdk15on 1.69?
I get the following error:
Cannot upload deployment:
{"WFLYCTL0080: Failed services" =>
{"jboss.undertow.deployment.default-server.default-host./myJavaApp" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./myJavaApp: java.lang.ArrayIndexOutOfBoundsException: 51201
Caused by: java.lang.ArrayIndexOutOfBoundsException: 51201"},
"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./myJavaApp"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}
If you look at the documentation of DEROutputStream
then you can read the following text for the constructor (I've pointed to 1.66 but this is already in 1.64 as well and possibly before):
Deprecated. Use
ASN1OutputStream.create(OutputStream, String)
withASN1Encoding.DER
instead.
Yes, the changes to the lightweight API of Bouncy are a bit of an annoyance, and the entire class should probably have been deprecated.