KeyStoreService usage

Avatar

Avatar
Boost 1
Level 1
xrisc
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
xrisc
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
xrisc
Level 1

17-08-2020

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

586 likes

Total Posts

734 posts

Correct reply

246 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

586 likes

Total Posts

734 posts

Correct reply

246 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

18-08-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)

Answers (2)

Answers (2)

Avatar

Avatar
Boost 1
Level 1
xrisc
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
xrisc
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
xrisc
Level 1

17-08-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?

Avatar

Avatar
Give Back 5
Employee
vanegi
Employee

Likes

392 likes

Total Posts

378 posts

Correct reply

148 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile

Avatar
Give Back 5
Employee
vanegi
Employee

Likes

392 likes

Total Posts

378 posts

Correct reply

148 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile
vanegi
Employee

17-08-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!!