0

I am trying to decrypt some private keys (.pfx X509Certificate) with Bouncy Castle. If I run the code standalone (junit), it works fine, but when I run it on wildfly with arquillian deployed as a war file, I'm facing some issues:

org.jboss.arquillian.test.spi.ArquillianProxyException: javax.ejb.EJBException : JBAS014580: Unexpected Error 
[Proxied because : Original exception caused: class java.lang.ClassFormatError: Absent Code attribute in method 
that is not native or abstract in class file javax/ejb/EJBException]

I think the arquillian is encapsulating the real exception, but no more errors appear in the log file.

In the pom file I declared it as provided, to use the provided version.

The versions installed are:

$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcmail-jdk15on-1.50.jar
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcpkix-jdk15on-1.50.jar
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcprov-jdk15on-1.50.jar

I also tried to use the version bcprov-jdk16 specified directly in the pom file with scope as compile/runtime, but it didn't work anyway.

The error occurs specifically in this point:

org.bouncycastle.x509.extension.X509ExtensionUtil.getIssuerAlternativeNames(java.security.cert.X509Certificate);

X509ExtensionUtil.getIssuerAlternativeNames(certificate) = >Unknown type "org.bouncycastle.x509.extension.X509ExtensionUtil"<

Anyone else ever had this problem or know how can I fix it? Any tips?

fdam
  • 820
  • 1
  • 11
  • 25

1 Answers1

0

I solved my question using only java 8 api, as the follow:

Collection<?> altNames = certificate.getSubjectAlternativeNames();
        for (Object i : altNames) {
            List<Object> item = (java.util.List) i;
            Integer type = (Integer) item.get(0);
            try {
                if (type > 0) {
                    continue;
                }
                String[] arr = StringEscapeUtils.escapeHtml(new String((byte[]) item.get(1))).split(";");
                return Arrays.asList(arr)
                        .stream()
                        .map(k -> k.trim())
                        .filter(u -> isCNPJ(u))
                        .findFirst().get();
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
        return null;

isCNPJ is just a method to filter only value I need. StringEscapeUtils is a apache commons lang class

fdam
  • 820
  • 1
  • 11
  • 25