Hi Andrei,

Did you upgrade only bouncycastle 1.69 or other dependency ?

I remember another deps should be updated.

Regards
JB

On 03/02/2022 14:09, Andrei Petru Mura wrote:
Hi all,

I upgraded bouncycastle to 1.69 in karaf. When trying to run this code:

MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(new String(body), "text/plain");
textPart.setHeader("Content-Type", messageContentType);
textPart.setHeader("Content-Transfer-Encoding", "binary");
textPart.setHeader("Content-Disposition", "attachment; filename=" + fileName);

SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.setContentTransferEncoding("base64");
JcaSimpleSignerInfoGeneratorBuilder signerInfoGenerator = new JcaSimpleSignerInfoGeneratorBuilder();
signerInfoGenerator = signerInfoGenerator.setProvider("BC");
SignerInfoGenerator signerGenerator = signerInfoGenerator.build(alg.algorithmWithRSA(), privateKey, certificate);
gen.addSignerInfoGenerator(signerGenerator);

List<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(certificate);
@SuppressWarnings("rawtypes")
Store certs = new JcaCertStore(certList);

gen.addCertificates(certs);

MimeMultipart signedReport = gen.generate(replyBody);
ByteArrayOutputStream out = new ByteArrayOutputStream();
mimeMsg.writeTo(out); //the line which gives problems
out.close();

I get this:

javax.activation.UnsupportedDataTypeException: text/plain
at javax.activation.DataHandler.writeTo(DataHandler.java:75) ~[!/:2.9.0]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1670) ~[!/:1.6.7] at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:972) ~[!/:1.6.7] at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:537) ~[!/:1.6.7]

Trying to make the long story short, after investigation, I find that BC includes a file at META-INF/mailcap
This shouldn't be a problem, but it seems to me that this is a problem.

If I try to add the mailcap manually before the above code snippet, like this:

  MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");

it has no effect, although I can see that the command handler is set there.

After all this investigation, I conclude that this is related to OSGI class loader. Any idea how to fix this or any hints?

Thanks,
Andrei Mura

Reply via email to