use of de.carne.certmgr.certs.UserCertStorePreferences in project certmgr by hdecarne.
the class CertOptionsController method initKeyAlgOptions.
private void initKeyAlgOptions() {
UserCertStorePreferences storePreferences = this.storePreferencesParam.get();
Controls.resetComboBoxOptions(this.ctlKeyAlgOption, KeyPairAlgorithm.getDefaultSet(storePreferences.defaultKeyPairAlgorithm.get(), this.expertModeParam), (o1, o2) -> o1.toString().compareTo(o2.toString()));
}
use of de.carne.certmgr.certs.UserCertStorePreferences in project certmgr by hdecarne.
the class CertOptionsController method resetValidityInput.
private void resetValidityInput(@Nullable CertGenerator generator) {
if (generator != null && generator.hasFeature(CertGenerator.Feature.CUSTOM_VALIDITY)) {
UserCertStorePreferences storePreferences = this.storePreferencesParam.get();
LocalDate notBeforeValue = LocalDate.now();
LocalDate notAfterValue = notBeforeValue.plus(storePreferences.defaultCRTValidityPeriod.getInt(0), ChronoUnit.DAYS);
this.ctlNotBeforeInput.setValue(notBeforeValue);
this.ctlNotBeforeInput.setDisable(false);
this.ctlNotAfterInput.setValue(notAfterValue);
this.ctlNotAfterInput.setDisable(false);
} else {
this.ctlNotBeforeInput.setValue(null);
this.ctlNotBeforeInput.setDisable(true);
this.ctlNotAfterInput.setValue(null);
this.ctlNotAfterInput.setDisable(true);
}
}
use of de.carne.certmgr.certs.UserCertStorePreferences in project certmgr by hdecarne.
the class CertOptionsController method onKeyAlgChanged.
private void onKeyAlgChanged(@Nullable KeyPairAlgorithm keyAlg) {
DefaultSet<Integer> keySizes = null;
if (keyAlg != null) {
UserCertStorePreferences storePreferences = this.storePreferencesParam.get();
Integer defaultHint = null;
if (keyAlg.algorithm().equals(storePreferences.defaultKeyPairAlgorithm.get())) {
defaultHint = storePreferences.defaultKeySize.get();
}
keySizes = keyAlg.getStandardKeySizes(defaultHint);
}
Controls.resetComboBoxOptions(this.ctlKeySizeOption, keySizes, (o1, o2) -> o1.compareTo(o2));
resetSigAlgOptions(keyAlg);
}
use of de.carne.certmgr.certs.UserCertStorePreferences in project certmgr by hdecarne.
the class CertOptionsController method resetSigAlgOptions.
private void resetSigAlgOptions(@Nullable CertGenerator generator, @Nullable KeyPairAlgorithm keyPairAlgorithm, @Nullable Issuer issuer) {
DefaultSet<SignatureAlgorithm> sigAlgs = null;
if (generator != null) {
String defaultHint = null;
if (keyPairAlgorithm != null) {
UserCertStorePreferences storePreferences = this.storePreferencesParam.get();
if (keyPairAlgorithm.algorithm().equals(storePreferences.defaultKeyPairAlgorithm.get())) {
defaultHint = storePreferences.defaultSignatureAlgorithm.get();
}
}
sigAlgs = generator.getSignatureAlgorithms(issuer, keyPairAlgorithm, defaultHint, this.expertModeParam);
}
Controls.resetComboBoxOptions(this.ctlSigAlgOption, sigAlgs, (o1, o2) -> o1.toString().compareTo(o2.toString()));
}
use of de.carne.certmgr.certs.UserCertStorePreferences in project certmgr by hdecarne.
the class UserCertStoreTest method testAccessStore.
/**
* Test access store operations.
*/
@Test
public void testAccessStore() {
try {
UserCertStore store = UserCertStore.openStore(testStorePath.get());
Assert.assertEquals(11, store.size());
Assert.assertEquals(TestCerts.TEST_STORE_NAME, store.storeName());
Assert.assertEquals(11, store.getEntries().size());
Assert.assertEquals(1, traverseStore(store.getRootEntries()));
// Check preferences access
UserCertStorePreferences loadPreferences = Check.notNull(store.storePreferences());
Assert.assertEquals(Integer.valueOf(365), loadPreferences.defaultCRTValidityPeriod.get());
Assert.assertEquals(Integer.valueOf(30), loadPreferences.defaultCRLUpdatePeriod.get());
Assert.assertEquals("EC", loadPreferences.defaultKeyPairAlgorithm.get());
Assert.assertEquals(Integer.valueOf(384), loadPreferences.defaultKeySize.get());
Assert.assertEquals("SHA256WITHECDSA", loadPreferences.defaultSignatureAlgorithm.get());
UserCertStorePreferences setPreferences = Check.notNull(store.storePreferences());
setPreferences.defaultCRTValidityPeriod.putInt(180);
setPreferences.defaultCRLUpdatePeriod.putInt(7);
setPreferences.defaultKeyPairAlgorithm.put("EC");
setPreferences.defaultKeySize.putInt(521);
setPreferences.defaultSignatureAlgorithm.put("SHA256WITHECDSA");
setPreferences.sync();
UserCertStorePreferences getPreferences = Check.notNull(store.storePreferences());
Assert.assertEquals(Integer.valueOf(180), getPreferences.defaultCRTValidityPeriod.get());
Assert.assertEquals(Integer.valueOf(7), getPreferences.defaultCRLUpdatePeriod.get());
Assert.assertEquals("EC", getPreferences.defaultKeyPairAlgorithm.get());
Assert.assertEquals(Integer.valueOf(521), getPreferences.defaultKeySize.get());
Assert.assertEquals("SHA256WITHECDSA", getPreferences.defaultSignatureAlgorithm.get());
// Import access (with already existing entries)
UserCertStore importStore = UserCertStore.createFromFiles(collectDirectoryFiles(testStorePath.get()), TestCerts.password());
for (UserCertStoreEntry importStoreEntry : importStore.getEntries()) {
store.importEntry(importStoreEntry, TestCerts.password(), "Imported");
}
Assert.assertEquals(11, store.size());
// Revoke access
for (UserCertStoreEntry storeEntry : store.getEntries()) {
if (storeEntry.hasCRT() && !storeEntry.isSelfSigned() && !storeEntry.isRevoked()) {
UserCertStoreEntry issuerEntry = storeEntry.issuer();
if (issuerEntry.canIssue()) {
Date lastUpdate = new Date(System.currentTimeMillis());
Date nextUpdate = new Date(lastUpdate.getTime() + 1000);
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.getDefaultSet(issuerEntry.getPublicKey().getAlgorithm(), storeEntry.getCRT().getSigAlgName(), false).getDefault();
Assert.assertNotNull(signatureAlgorithm);
UpdateCRLRequest updateCRLRequest = new UpdateCRLRequest(lastUpdate, nextUpdate, signatureAlgorithm);
updateCRLRequest.addRevokeEntry(storeEntry.getCRT().getSerialNumber(), ReasonFlag.PRIVILEGE_WITHDRAWN);
issuerEntry.updateCRL(updateCRLRequest, TestCerts.password());
Assert.assertTrue(storeEntry.isRevoked());
}
}
}
// Delete access
List<UserCertStoreEntryId> deleteIds = new ArrayList<>();
for (UserCertStoreEntry storeEntry : store.getEntries()) {
deleteIds.add(storeEntry.id());
}
for (UserCertStoreEntryId deleteId : deleteIds) {
store.deleteEntry(deleteId);
}
Assert.assertEquals(0, store.size());
// Import access (now with empty store)
for (UserCertStoreEntry importStoreEntry : importStore.getEntries()) {
store.importEntry(importStoreEntry, TestCerts.password(), "Imported");
}
Assert.assertEquals(11, store.size());
} catch (IOException | BackingStoreException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations