Ben Walding
2005-08-31 04:25:59 UTC
(This is all in relation to PKCS12 KeyStore objects)
I was recently converting some existing code that was half SunJSSE/half BC
across to use BC across the board.
One of our routines "getOnlyAlias" attempts to retrieve the only alias of a
PKCS12 KeyStore.
Our code creates a PKCS12 keystore, and then inserts a single entry
containing 2 certificates in an array (the client cert and the public CA
cert). Later on we reopen the keystore to perform other operations on it.
With the JSSE, reopening this KeyStore yields a keystore with only 1 alias -
the alias we created. However when using the BouncyCastle provider, we end
up with a keystore that contains 2 aliases - quite surprising.
I have attached some test code that demonstrates this behaviour.
The output I get from this code is as follows -
----------------------------------------------------------
Using provider : SunJSSE
Saving CA keystore...
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=authority
Certificate: CN=Authority
Loaded CA keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=authority
Certificate: CN=Authority
Creating client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=client
Certificate: CN=Client
Certificate: CN=Authority
Loaded client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=client
Certificate: CN=Client
Certificate: CN=Authority
----------------------------------------------------------
Using provider : BC
Saving CA keystore...
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Authority
Certificate: CN=Authority
Loaded CA keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Authority
Certificate: CN=Authority
Creating client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Client
Certificate: CN=Client
Certificate: CN=Authority
Loaded client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Client
Certificate: CN=Client
Certificate: CN=Authority
Alias: CN=Authority
Certificate: CN=Authority
----------------------------------------------------------
Note the 2 alias entries in the last section (last 5 lines)
My question is this: is this behaviour (store a KeyStore with 1 alias, will
load back with 2) by design?
Cheers,
Ben
I was recently converting some existing code that was half SunJSSE/half BC
across to use BC across the board.
One of our routines "getOnlyAlias" attempts to retrieve the only alias of a
PKCS12 KeyStore.
Our code creates a PKCS12 keystore, and then inserts a single entry
containing 2 certificates in an array (the client cert and the public CA
cert). Later on we reopen the keystore to perform other operations on it.
With the JSSE, reopening this KeyStore yields a keystore with only 1 alias -
the alias we created. However when using the BouncyCastle provider, we end
up with a keystore that contains 2 aliases - quite surprising.
I have attached some test code that demonstrates this behaviour.
The output I get from this code is as follows -
----------------------------------------------------------
Using provider : SunJSSE
Saving CA keystore...
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=authority
Certificate: CN=Authority
Loaded CA keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=authority
Certificate: CN=Authority
Creating client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=client
Certificate: CN=Client
Certificate: CN=Authority
Loaded client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: SunJSSE version 1.5
Alias: cn=client
Certificate: CN=Client
Certificate: CN=Authority
----------------------------------------------------------
Using provider : BC
Saving CA keystore...
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Authority
Certificate: CN=Authority
Loaded CA keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Authority
Certificate: CN=Authority
Creating client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Client
Certificate: CN=Client
Certificate: CN=Authority
Loaded client keystore
KeyStore Class: java.security.KeyStore
KeyStore Type: PKCS12
KeyStore Provider: BC version 1.29
Alias: CN=Client
Certificate: CN=Client
Certificate: CN=Authority
Alias: CN=Authority
Certificate: CN=Authority
----------------------------------------------------------
Note the 2 alias entries in the last section (last 5 lines)
My question is this: is this behaviour (store a KeyStore with 1 alias, will
load back with 2) by design?
Cheers,
Ben