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

supporting EJBCA #63

Open
nponsard opened this issue Jul 28, 2023 · 9 comments
Open

supporting EJBCA #63

nponsard opened this issue Jul 28, 2023 · 9 comments

Comments

@nponsard
Copy link
Contributor

No description provided.

@nponsard
Copy link
Contributor Author

nponsard commented Jul 31, 2023

Current blocking problems:

  • After generating a key, it tries to rename it using C_SetAttributeValue()
  • When generating an EC key, it tries to sign data of an invalid length

@nponsard nponsard changed the title test with EJBCA supporting EJBCA Aug 4, 2023
@nponsard
Copy link
Contributor Author

nponsard commented Aug 4, 2023

Need to find a way to fix the key renaming, maybe the PKCS11 java lib ?

@nponsard
Copy link
Contributor Author

nponsard commented Aug 8, 2023

It seems like the EC key problems are fixed by changes in main.

@nponsard
Copy link
Contributor Author

nponsard commented Aug 8, 2023

The problem seems to come from the Java library.
It uses the java.security.Security class to get the Sun pkc11 provider.
This 'security' library imposes a pattern where a key generation is in 3 steps :

  • generate a key
  • generate a certificate
  • store both the key and the certificate

As the key is generated on the device, it uses the device to sign the certificate. Also in the storing part the key is already on the device so it renames it.

example code :

package com.example;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.cert.Certificate;
import java.util.Base64;
import java.util.Map;

public class App {
    public static void main(String[] args) throws Exception {
        // Load the PKCS#11 provider
        String pkcs11Config = "/opt/pkcs-test/pkcs11.cfg";

        Provider provider = Security.getProvider("SunPKCS11");

        provider = provider.configure(pkcs11Config);
        Security.addProvider(provider);

        // Initialize a session
        char[] pin = "123456".toCharArray();
        KeyStore keyStore = KeyStore.getInstance("PKCS11", provider);
        keyStore.load(null, pin);

        // generate a rsa key pair
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", provider);
        keyPairGenerator.initialize(2048);
        KeyPair keyPair = keyPairGenerator.generateKeyPair();

        Certificate certificate = generateCertificate(keyPair,provider);

        keyStore.setKeyEntry("your_key_alias", keyPair.getPrivate(), pin, certificate);
    }
}

pkcs11.cfg :

name = PKCS11SPY
library = /usr/lib/pkcs11-spy.so

@nponsard
Copy link
Contributor Author

nponsard commented Aug 8, 2023

New error when clicking 'test' on EC keys : Error: Exception testing key: error decoding signature bytes.

@nponsard
Copy link
Contributor Author

nponsard commented Aug 9, 2023

Generating a P-384 EC key now works, there is still problem for the other EC key sizes

@nponsard
Copy link
Contributor Author

The ECDSA problems are now solved

@nponsard
Copy link
Contributor Author

#85 would be a partial fix

@jans23
Copy link
Member

jans23 commented Aug 31, 2023

Potentially PKCS#11 NG would be a solution.

@jans23 jans23 self-assigned this Aug 31, 2023
@jans23 jans23 removed their assignment Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants