PKCS11 Wildfly 13 - Digital certificate

Asked

Viewed 148 times

1

I’m trying to use the following library: https://github.com/Samuel-Oliveira

To use it, it is necessary to upload a digital certificate, in the case of type A1.

When trying to use it with a normal class with a public static void main works normally. I have a jar of my project that I use all the time.

It turns out that using the library in a web project <package>war</package> and deploying in the Wildfly(versão 13), when trying to load the certificate: CertificadoService.certificadoPfx(path, pass);

bursts that Exception:

Caused by: java.lang.NoClassDefFoundError: sun/security/pkcs11/wrapper/PKCS11Exception

Follows class:

@Singleton
public class Worker {

    private AtomicBoolean busy = new AtomicBoolean(false);

    public void work() {
        if (!busy.compareAndSet(false, true)) {
            return;
        }
        try {
            System.out.println("Executing this task at " + new SimpleDateFormat("HH:mm:ss").format(new Date()) + ".");

            String path = "/home/user/certificado.pfx";
            String pass = "4321";


            CertificadoService.certificadoPfx(path, pass);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            busy.set(false);
        }
    }
}

1 answer

1

Some JRE classes are not loaded by default by Wildfly. Some of them are required by the API to load the digital certificate programmatically.

It is necessary, then, to force the upload of them by the file

jboss-Deployment-Structure.xml

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <system export="true">
                <paths>
                    <path name="sun/security/x509"/>
                    <path name="sun/security/pkcs11"/>
                    <path name="sun/security/pkcs11/wrapper"/>
                </paths>
            </system>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.