Skip to content

Commit

Permalink
Update engineIsKeyEntry and engineIsCertificateEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
haimaychao committed Mar 7, 2024
1 parent 97bf0ec commit 5390a42
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ public int engineSize() {
*/
public boolean engineIsKeyEntry(String alias) {
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
return internalEngineIsKeyEntry(entry);
}

private boolean internalEngineIsKeyEntry(Entry entry) {
return entry instanceof KeyEntry;
}

Expand All @@ -1085,8 +1089,13 @@ public boolean engineIsKeyEntry(String alias) {
* @return true if the entry identified by the given alias is a
* <i>trusted certificate entry</i>, false otherwise.
*/

public boolean engineIsCertificateEntry(String alias) {
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
return internalEngineIsCertificateEntry(entry);
}

private boolean internalEngineIsCertificateEntry(Entry entry) {
return entry instanceof CertEntry certEntry &&
certEntry.trustedKeyUsage != null;
}
Expand Down Expand Up @@ -1316,7 +1325,7 @@ public KeyStore.Entry engineGetEntry(String alias,

Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (protParam == null) {
if (engineIsCertificateEntry(alias)) {
if (internalEngineIsCertificateEntry(entry)) {
if (entry instanceof CertEntry &&
((CertEntry) entry).trustedKeyUsage != null) {

Expand All @@ -1335,10 +1344,10 @@ public KeyStore.Entry engineGetEntry(String alias,
}

if (protParam instanceof KeyStore.PasswordProtection) {
if (engineIsCertificateEntry(alias)) {
if (internalEngineIsCertificateEntry(entry)) {
throw new UnsupportedOperationException
("trusted certificate entries are not password-protected");
} else if (engineIsKeyEntry(alias)) {
} else if (internalEngineIsKeyEntry(entry)) {
KeyStore.PasswordProtection pp =
(KeyStore.PasswordProtection)protParam;
char[] password = pp.getPassword();
Expand All @@ -1355,7 +1364,7 @@ public KeyStore.Entry engineGetEntry(String alias,
return new KeyStore.SecretKeyEntry((SecretKey)key,
entry.attributes);
}
} else if (!engineIsKeyEntry(alias)) {
} else if (!internalEngineIsKeyEntry(entry)) {
throw new UnsupportedOperationException
("untrusted certificate entries are not " +
"password-protected");
Expand Down

0 comments on commit 5390a42

Please sign in to comment.