Add simple CIF cache for middleware cards
@@ -57,6 +57,7 @@ import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.List;
import org.openecard.common.util.ByteUtils;
import org.openecard.crypto.common.SignatureAlgorithms;
@@ -80,6 +81,8 @@ public class CIFCreator {
private static final Logger LOG = LoggerFactory.getLogger(CIFCreator.class);
+ private static final HashMap<String, CardInfoType> CIF_CACHE = new HashMap<>();
+
private final MwSession session;
private final CardInfoType cif;
private final CardSpecType cardSpec;
@@ -101,6 +104,14 @@ public class CIFCreator {
public CardInfoType addTokenInfo() throws WSMarshallerException, CryptokiException {
LOG.debug("Adding information to CardInfo file for card type {}.", cif.getCardType().getObjectIdentifier());
+ String serial = session.getSlot().getTokenInfo().getSerialNumber();
+ synchronized (CIF_CACHE) {
+ if (CIF_CACHE.containsKey(serial)) {
+ LOG.debug("Reusing previously generated CIF for card with serial={}.", serial);
+ return CIF_CACHE.get(serial);
+ }
+ }
+
PIN_NAME = "USER_PIN";
DIDInfoType pinDid = createPinDID();
List<DIDInfoType> cryptoDids = getSignatureCryptoDIDs();
@@ -111,6 +122,13 @@ public class CIFCreator {
app.getDIDInfo().addAll(cryptoDids);
app.getDataSetInfo().addAll(datasets);
+ synchronized (CIF_CACHE) {
+ if (! CIF_CACHE.containsKey(serial)) {
+ LOG.info("Adding CIF to cache for card with serial={}.", serial);
+ CIF_CACHE.put(serial, cif);
+ }
+ }
+
return cif;
}
