@SuppressWarnings("deprecation")
 @Test
 public void testUpgradePropertiesFileFrom5_0_11() {
   Properties slotPropertiesWithNumber = new Properties();
   slotPropertiesWithNumber.setProperty("slot", "SLOT_ID:7");
   Properties newSlotPropertiesWithNumber =
       PKCS11CryptoToken.upgradePropertiesFileFrom5_0_x(slotPropertiesWithNumber);
   assertEquals("7", newSlotPropertiesWithNumber.getProperty(PKCS11CryptoToken.SLOT_LABEL_VALUE));
   assertEquals(
       Pkcs11SlotLabelType.SLOT_NUMBER.getKey(),
       newSlotPropertiesWithNumber.getProperty(PKCS11CryptoToken.SLOT_LABEL_TYPE));
   Properties slotPropertiesWithIndex = new Properties();
   slotPropertiesWithIndex.setProperty("slot", "SLOT_LIST_IX:i7");
   Properties newSlotPropertiesWithIndex =
       PKCS11CryptoToken.upgradePropertiesFileFrom5_0_x(slotPropertiesWithIndex);
   assertEquals("i7", newSlotPropertiesWithIndex.getProperty(PKCS11CryptoToken.SLOT_LABEL_VALUE));
   assertEquals(
       Pkcs11SlotLabelType.SLOT_INDEX.getKey(),
       newSlotPropertiesWithIndex.getProperty(PKCS11CryptoToken.SLOT_LABEL_TYPE));
   Properties slotPropertiesWithLabel = new Properties();
   slotPropertiesWithLabel.setProperty("slot", "TOKEN_LABEL:foo");
   Properties newSlotPropertiesWithLabel =
       PKCS11CryptoToken.upgradePropertiesFileFrom5_0_x(slotPropertiesWithLabel);
   assertEquals("foo", newSlotPropertiesWithLabel.getProperty(PKCS11CryptoToken.SLOT_LABEL_VALUE));
   assertEquals(
       Pkcs11SlotLabelType.SLOT_LABEL.getKey(),
       newSlotPropertiesWithLabel.getProperty(PKCS11CryptoToken.SLOT_LABEL_TYPE));
 }
Exemplo n.º 2
0
 /**
  * A workaround for the feature in SignServer 2.0 that property keys are always converted to upper
  * case. The EJBCA CA Tokens usually use mixed case properties
  */
 public static Properties fixP11Properties(final Properties props) {
   String prop = props.getProperty(PROPERTY_AUTHCODE);
   if (prop != null) {
     props.setProperty("authCode", prop);
   }
   prop = props.getProperty(PROPERTY_DEFAULTKEY);
   if (prop != null) {
     props.setProperty("defaultKey", prop);
   }
   prop = props.getProperty(PROPERTY_PIN);
   if (prop != null) {
     props.setProperty("pin", prop);
   }
   prop = props.getProperty(PROPERTY_SHAREDLIBRARY);
   if (prop != null) {
     props.setProperty("sharedLibrary", prop);
   }
   prop = props.getProperty(PROPERTY_SHAREDLIBRARYNAME);
   if (prop != null) {
     props.setProperty("sharedLibraryName", prop);
   }
   prop = props.getProperty(PROPERTY_SLOTLABELVALUE);
   if (prop != null) {
     props.setProperty(org.cesecore.keys.token.PKCS11CryptoToken.SLOT_LABEL_VALUE, prop);
   }
   prop = props.getProperty(PROPERTY_SLOT);
   if (prop != null) {
     props.setProperty("slot", prop);
     props.setProperty(PROPERTY_SLOTLABELTYPE, Pkcs11SlotLabelType.SLOT_NUMBER.getKey());
     props.setProperty(org.cesecore.keys.token.PKCS11CryptoToken.SLOT_LABEL_VALUE, prop);
     props.setProperty(PROPERTY_SLOTLABELVALUE, prop);
   }
   prop = props.getProperty(PROPERTY_SLOTLISTINDEX);
   if (prop != null) {
     props.setProperty("slotListIndex", prop);
     props.setProperty(PROPERTY_SLOTLABELTYPE, Pkcs11SlotLabelType.SLOT_INDEX.getKey());
     props.setProperty(org.cesecore.keys.token.PKCS11CryptoToken.SLOT_LABEL_VALUE, prop);
     props.setProperty(PROPERTY_SLOTLABELVALUE, prop);
   }
   prop = props.getProperty(PROPERTY_ATTRIBUTESFILE);
   if (prop != null) {
     props.setProperty("attributesFile", prop);
   }
   prop = props.getProperty(PROPERTY_NEXTCERTSIGNKEY);
   if (prop != null) {
     props.setProperty("nextCertSignKey", prop);
   }
   prop = props.getProperty(PROPERTY_SLOTLABELTYPE);
   if (prop != null) {
     props.setProperty(org.cesecore.keys.token.PKCS11CryptoToken.SLOT_LABEL_TYPE, prop);
   }
   return props;
 }
 @SuppressWarnings(
     "deprecation") // This test will be removed when the deprecated methods it tests are.
 @Test
 public void testUpgradePropertiesFileFrom5_0_x() {
   Properties slotNumberProperties = new Properties();
   slotNumberProperties.setProperty("slot", "7");
   Properties indexProperties = new Properties();
   indexProperties.setProperty("slotListIndex", "7");
   Properties newSlotNumber =
       PKCS11CryptoToken.upgradePropertiesFileFrom5_0_x(slotNumberProperties);
   assertEquals("7", newSlotNumber.getProperty(PKCS11CryptoToken.SLOT_LABEL_VALUE));
   assertEquals(
       Pkcs11SlotLabelType.SLOT_NUMBER.getKey(),
       newSlotNumber.getProperty(PKCS11CryptoToken.SLOT_LABEL_TYPE));
   Properties newIndexNumber = PKCS11CryptoToken.upgradePropertiesFileFrom5_0_x(indexProperties);
   assertEquals("i7", newIndexNumber.getProperty(PKCS11CryptoToken.SLOT_LABEL_VALUE));
   assertEquals(
       Pkcs11SlotLabelType.SLOT_INDEX.getKey(),
       newIndexNumber.getProperty(PKCS11CryptoToken.SLOT_LABEL_TYPE));
 }