KeyStoreService usage | Community
Skip to main content
August 17, 2020
Solved

KeyStoreService usage

  • August 17, 2020
  • 3 replies
  • 1609 views

I'm trying to follow the code example in http://www.sgaemsolutions.com/2020/01/how-to-manage-certificates-in-aem.html but can't figure out how to properly set KeyStoreService. 

 

Always getting a null keyStoreService in the line: KeyStore trustStore = this.keyStoreService.getTrustStore(resourceResolver);

 

Any help or hint would be very welcome. Thanks in advance

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vijayalakshmi_S

Hi @xrisc,

Can you check if the "KeyStoreService" bundle (Adobe Granite Crypto Keystorecom.adobe.granite.crypto.keystore) is active in your instance. 

And OSGI component that you have written referring the KeyStoreService is active in OSGI components section (In particular, Reference is satisfied)

3 replies

vanegi
Adobe Employee
Adobe Employee
August 17, 2020

Can you try with below sample code, may be this can help:

 

// create truststore
ResourceResolver adminResolver = getResourceResolver(ADMIN, ADMIN);
keyStoreService.createTrustStore(adminResolver, STORE_PASSWD.toCharArray());
KeyStore trustStore = keyStoreService.getTrustStore(adminResolver);
assertNotNull(trustStore);
InputStream is = ResourceReader.getResourceAsStream("/root-ca.crt");
CertificateFactory cf = CertificateFactory.getInstance(GraniteSecurityProvider.X509);
Certificate certificate = cf.generateCertificate(is);
is.close();
trustStore.setCertificateEntry("root_ca", certificate);
adminResolver.close();

 

Thanks!!

xriscAuthor
August 17, 2020
keyStoreService.createTrustStore(adminResolver, STORE_PASSWD.toCharArray()) still throws a NullPointerException due to a null keyStoreService. I have the following already defined: @3214626 private KeyStoreService keyStoreService; Any idea on why it's still throwing a NullPointerException? and how to resolve?
xriscAuthor
August 17, 2020

keyStoreService.createTrustStore(adminResolver, STORE_PASSWD.toCharArray()) still throws a NullPointerException due to a null keyStoreService.

 

I have the following already defined: 

@reference 

private KeyStoreService keyStoreService;

 

Any idea on why it's still throwing a NullPointerException? and how to resolve?

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
August 18, 2020

Hi @xrisc,

Can you check if the "KeyStoreService" bundle (Adobe Granite Crypto Keystorecom.adobe.granite.crypto.keystore) is active in your instance. 

And OSGI component that you have written referring the KeyStoreService is active in OSGI components section (In particular, Reference is satisfied)