Search in sources :

Example 1 with DefaultSet

use of de.carne.jfx.util.DefaultSet in project certmgr by hdecarne.

the class CRLUpdatePeriod method getDefaultSet.

/**
 * Get the standard CRL Update Periods.
 *
 * @param defaultHint The default to return (may be {@code null}). If this period is contained in the default set,
 *        it is also set as the default.
 * @return The standard CRL Update Periods.
 */
public static DefaultSet<CRLUpdatePeriod> getDefaultSet(@Nullable Days defaultHint) {
    DefaultSet<Days> defaultPeriods = SecurityDefaults.getCRLUpdatedPeriods();
    DefaultSet<CRLUpdatePeriod> crlUpdatePeriods = new DefaultSet<>();
    if (defaultHint != null) {
        crlUpdatePeriods.addDefault(new CRLUpdatePeriod(defaultHint));
    } else {
        crlUpdatePeriods.addDefault(new CRLUpdatePeriod(Check.notNull(defaultPeriods.getDefault())));
    }
    for (Days period : defaultPeriods) {
        crlUpdatePeriods.add(new CRLUpdatePeriod(period));
    }
    return crlUpdatePeriods;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Days(de.carne.certmgr.util.Days)

Example 2 with DefaultSet

use of de.carne.jfx.util.DefaultSet in project certmgr by hdecarne.

the class CRTValidityPeriod method getDefaultSet.

/**
 * Get the standard CRT Validity Periods.
 *
 * @param defaultHint The default to return (may be {@code null}). If this period is contained in the default set,
 *        it is also set as the default.
 * @return The standard CRT Validity Periods.
 */
public static DefaultSet<CRTValidityPeriod> getDefaultSet(@Nullable Days defaultHint) {
    DefaultSet<Days> defaultPeriods = SecurityDefaults.getCRTValidityPeriods();
    DefaultSet<CRTValidityPeriod> crlUpdatePeriods = new DefaultSet<>();
    if (defaultHint != null) {
        crlUpdatePeriods.addDefault(new CRTValidityPeriod(defaultHint));
    } else {
        crlUpdatePeriods.addDefault(new CRTValidityPeriod(Check.notNull(defaultPeriods.getDefault())));
    }
    for (Days period : defaultPeriods) {
        crlUpdatePeriods.add(new CRTValidityPeriod(period));
    }
    return crlUpdatePeriods;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Days(de.carne.certmgr.util.Days)

Example 3 with DefaultSet

use of de.carne.jfx.util.DefaultSet in project certmgr by hdecarne.

the class KeyPairAlgorithm method getDefaultSet.

/**
 * Get the available key pair algorithms.
 *
 * @param defaultHint The default to return (may be {@code null}). If this algorithm is contained in the default
 *        set, it is also set as the default.
 * @param expertMode Whether only standard algorithms are considered ({@code false}) or all algorithms available on
 *        the current platform ({@code true}).
 * @return The available key pair algorithms
 */
public static DefaultSet<KeyPairAlgorithm> getDefaultSet(@Nullable String defaultHint, boolean expertMode) {
    DefaultSet<KeyPairAlgorithm> keyPairAlgorithms = new DefaultSet<>();
    DefaultSet<String> defaultNames = SecurityDefaults.getKeyAlgorithmNames();
    @Nullable String defaultName = (defaultHint != null && defaultNames.contains(defaultHint) ? defaultHint : defaultNames.getDefault());
    for (Provider provider : SecurityDefaults.getProviders(expertMode)) {
        for (Provider.Service service : provider.getServices()) {
            if (!SERVICE_TYPE_KEY_PAIR_GENERATOR.equals(service.getType())) {
                continue;
            }
            String algorithm = service.getAlgorithm();
            if (!expertMode && !defaultNames.contains(algorithm)) {
                continue;
            }
            KeyPairAlgorithm keyPairAlgorithm = (expertMode ? new ExpertKeyPairAlgorithm(service) : new StandardKeyPairAlgorithm(service));
            if (algorithm.equals(defaultName)) {
                keyPairAlgorithms.addDefault(keyPairAlgorithm);
            } else {
                keyPairAlgorithms.add(keyPairAlgorithm);
            }
        }
    }
    return keyPairAlgorithms;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Service(java.security.Provider.Service) Nullable(de.carne.check.Nullable) Provider(java.security.Provider)

Example 4 with DefaultSet

use of de.carne.jfx.util.DefaultSet in project certmgr by hdecarne.

the class PlatformKeyStore method getDefaultSet.

/**
 * Get the available platform key stores.
 *
 * @return The available platform key stores.
 */
public static DefaultSet<PlatformKeyStore> getDefaultSet() {
    DefaultSet<PlatformKeyStore> platformKeyStores = new DefaultSet<>();
    DefaultSet<String> defaultNames = SecurityDefaults.getPlatformKeyStoreNames();
    String defaultName = defaultNames.getDefault();
    for (Provider provider : Security.getProviders()) {
        for (Provider.Service service : provider.getServices()) {
            if (!SERVICE_TYPE_KEY_STORE.equals(service.getType())) {
                continue;
            }
            String algorithm = service.getAlgorithm();
            if (!defaultNames.contains(algorithm)) {
                continue;
            }
            PlatformKeyStore platformKeyStore = new PlatformKeyStore(service);
            if (algorithm.equals(defaultName)) {
                platformKeyStores.addDefault(platformKeyStore);
            } else {
                platformKeyStores.add(platformKeyStore);
            }
        }
    }
    return platformKeyStores;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Service(java.security.Provider.Service) Provider(java.security.Provider)

Example 5 with DefaultSet

use of de.carne.jfx.util.DefaultSet in project certmgr by hdecarne.

the class LocalCertGenerator method getIssuers.

@Override
public DefaultSet<Issuer> getIssuers(UserCertStore store, @Nullable UserCertStoreEntry defaultHint) {
    DefaultSet<Issuer> issuers = new DefaultSet<>();
    issuers.addDefault(this.selfSignedIssuer);
    if (store != null) {
        for (UserCertStoreEntry storeEntry : store.getEntries()) {
            if (storeEntry.canIssue()) {
                if (storeEntry.equals(defaultHint)) {
                    issuers.addDefault(new LocalIssuer(storeEntry));
                } else {
                    issuers.add(new LocalIssuer(storeEntry));
                }
            }
        }
    }
    return issuers;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry)

Aggregations

DefaultSet (de.carne.jfx.util.DefaultSet)6 Provider (java.security.Provider)3 Service (java.security.Provider.Service)3 Days (de.carne.certmgr.util.Days)2 Nullable (de.carne.check.Nullable)2 UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)1