Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKCS11 not working on linux #319

Open
thuck opened this issue Dec 8, 2023 · 5 comments
Open

PKCS11 not working on linux #319

thuck opened this issue Dec 8, 2023 · 5 comments
Labels
answered question answered

Comments

@thuck
Copy link

thuck commented Dec 8, 2023

Hi;

I'm trying to use the pkcs11 and I keep getting the error:

davmail.http.DavMailX509KeyManager  - No Private Keys found

I setup the configuration as:

davmail.ssl.pkcs11Library=/usr/lib/libIDPrimePKCS11.so
davmail.ssl.clientKeystoreType=PKCS11
davmail.ssl.clientKeystorePass=XXXX

I tested also with:

keytool -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg pkcs11.config -list

And I can see all the certificates; although on keytool the list is always in lower case and in davmail it is case sensitive.
For example on davmail log I can see something like: 0=Xxxx in the keytool output I see o=xxx

Am I missing something in the configuration or is it possible that we have a bug on the detection of the certificates on the pkcs11?

@thuck
Copy link
Author

thuck commented Dec 8, 2023

I did the same exercise on Windows, on Windows the list of certificates are showed as a pop up to be selected.
Maybe this is a problem because I'm using wayland? But all other windows shows up properly, the internal browser, the pop up for O365Manual. On Windows I'm using the native PKCS11 implementation.

And just to clarify since I didn't include this in the original post I'm using the latest release on Linux and Windows.

@mguessan
Copy link
Owner

Look for the "Find client certificates issued by" message in DavMail logs, client certificates are filtered in issuer requested by server.

Relevant code is in DavMailX509KeyManager

@mguessan mguessan added the answered question answered label Dec 12, 2023
@thuck
Copy link
Author

thuck commented Dec 12, 2023

Hi @mguessan, thanks for your reply.
I can see the "find client certificates"; they list my certs, but after it prints the No Private Keys found.
On windows for the same operation the list is showed as a pop up, on linux it doesn't show up.
The certificates should be fine, since I can connect on the proper services using Firefox without any problem.

Any suggestion? Maybe I can force the certificates somehow?

@mguessan
Copy link
Owner

no private keys found means no alias matched criteria.

You may want to enable ssl logging with:
-Djavax.net.debug=ssl

or
-Djavax.net.debug=keymanager

@thuck
Copy link
Author

thuck commented Dec 13, 2023

Enabled:
javax.net.ssl|DEBUG|26|URL-Loader-15|2023-12-12 10:32:49.233 CST|X509KeyManagerImpl.java:451|KeyMgr: no matching alias found

But as I mentioned this works when using firefox, I can select the proper certificate.
I did a lot tests, did some code modifications to understand better the situation, and looks like that the PKCS11 is not being used.
The PIN is never asked, so the keys are never enabled.
I tried to force the code to use my pin, with something like:

+        String password = "XXXXXXXXX";
+        KeyStore.Builder scBuilder = KeyStore.Builder.newInstance("PKCS11", null, getProtectionParameter(password));

I know that the smartcard is being read when davmail starts, because if I change the library to something incorrect I get an exception, but I guess the Keystore and the TLS part have some interaction that is not working? I'm not sure what could be the problem here, or if I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered question answered
Projects
None yet
Development

No branches or pull requests

2 participants