Search in sources :

Example 1 with HashAlgorithm

use of fr.xephi.authme.security.HashAlgorithm in project AuthMeReloaded by AuthMe.

the class AbstractResourceClosingTest method data.

/**
     * Initialization method -- provides the parameters to run the test with by scanning all DataSource
     * methods. By default, we run one test per method with the default hash algorithm, XFBCRYPT.
     * If the map of custom algorithms has an entry for the method name, we add an entry for each algorithm
     * supplied by the map.
     *
     * @return Test parameters
     */
@Parameterized.Parameters(name = "{1}({2})")
public static Collection<Object[]> data() {
    List<Method> methods = getDataSourceMethods();
    List<Object[]> data = new ArrayList<>();
    // Use XFBCRYPT if nothing else specified as there is a lot of specific behavior to this hash algorithm in MySQL
    final HashAlgorithm[] defaultAlgorithm = new HashAlgorithm[] { HashAlgorithm.XFBCRYPT };
    for (Method method : methods) {
        HashAlgorithm[] algorithms = MoreObjects.firstNonNull(CUSTOM_ALGORITHMS.get(method.getName()), defaultAlgorithm);
        for (HashAlgorithm algorithm : algorithms) {
            data.add(new Object[] { method, method.getName(), algorithm });
        }
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) HashAlgorithm(fr.xephi.authme.security.HashAlgorithm)

Example 2 with HashAlgorithm

use of fr.xephi.authme.security.HashAlgorithm in project AuthMeReloaded by AuthMe.

the class HashAlgorithmsDescriptionTask method constructMethodRows.

private static NestedTagValue constructMethodRows(Map<HashAlgorithm, MethodDescription> descriptions) {
    NestedTagValue methodTags = new NestedTagValue();
    for (Map.Entry<HashAlgorithm, MethodDescription> entry : descriptions.entrySet()) {
        MethodDescription description = entry.getValue();
        TagValueHolder tags = TagValueHolder.create().put("name", asString(entry.getKey())).put("recommendation", asString(description.getUsage())).put("hash_length", asString(description.getHashLength())).put("ascii_restricted", asString(description.isAsciiRestricted())).put("salt_type", asString(description.getSaltType())).put("salt_length", asString(description.getSaltLength())).put("separate_salt", asString(description.hasSeparateSalt()));
        methodTags.add(tags);
    }
    return methodTags;
}
Also used : TagValueHolder(tools.utils.TagValueHolder) NestedTagValue(tools.utils.TagValue.NestedTagValue) Map(java.util.Map) HashAlgorithm(fr.xephi.authme.security.HashAlgorithm)

Example 3 with HashAlgorithm

use of fr.xephi.authme.security.HashAlgorithm in project AuthMeReloaded by AuthMe.

the class SettingsMigrationService method moveDeprecatedHashAlgorithmIntoLegacySection.

/**
 * If a deprecated hash is used, it is added to the legacy hashes option and the active hash
 * is changed to SHA256.
 *
 * @param reader The property reader
 * @param configData Configuration data
 * @return True if the configuration has changed, false otherwise
 */
private static boolean moveDeprecatedHashAlgorithmIntoLegacySection(PropertyReader reader, ConfigurationData configData) {
    HashAlgorithm currentHash = SecuritySettings.PASSWORD_HASH.determineValue(reader).getValue();
    // Skip CUSTOM (has no class) and PLAINTEXT (is force-migrated later on in the startup process)
    if (currentHash != HashAlgorithm.CUSTOM && currentHash != HashAlgorithm.PLAINTEXT) {
        Class<?> encryptionClass = currentHash.getClazz();
        if (encryptionClass.isAnnotationPresent(Deprecated.class)) {
            configData.setValue(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
            Set<HashAlgorithm> legacyHashes = SecuritySettings.LEGACY_HASHES.determineValue(reader).getValue();
            legacyHashes.add(currentHash);
            configData.setValue(SecuritySettings.LEGACY_HASHES, legacyHashes);
            logger.warning("The hash algorithm '" + currentHash + "' is no longer supported for active use. New hashes will be in SHA256.");
            return true;
        }
    }
    return false;
}
Also used : HashAlgorithm(fr.xephi.authme.security.HashAlgorithm)

Example 4 with HashAlgorithm

use of fr.xephi.authme.security.HashAlgorithm in project AuthMeReloaded by AuthMe.

the class EncryptionMethodInfoGatherer method constructDescriptions.

private void constructDescriptions() {
    for (HashAlgorithm algorithm : HashAlgorithm.values()) {
        if (algorithm.getClazz() != null && !algorithm.getClazz().isAnnotationPresent(Deprecated.class)) {
            MethodDescription description = createDescription(algorithm);
            descriptions.put(algorithm, description);
        }
    }
}
Also used : HashAlgorithm(fr.xephi.authme.security.HashAlgorithm)

Example 5 with HashAlgorithm

use of fr.xephi.authme.security.HashAlgorithm in project AuthMeReloaded by AuthMe.

the class HashAlgorithmsDescriptionTask method executeDefault.

@Override
public void executeDefault() {
    // Gather info and construct a row for each method
    EncryptionMethodInfoGatherer infoGatherer = new EncryptionMethodInfoGatherer();
    Map<HashAlgorithm, MethodDescription> descriptions = infoGatherer.getDescriptions();
    final NestedTagValue methodRows = constructMethodRows(descriptions);
    // Write to the docs file
    TagValueHolder tags = TagValueHolder.create().put("algorithms", methodRows);
    FileIoUtils.generateFileFromTemplate(CUR_FOLDER + "hash_algorithms.tpl.md", OUTPUT_FILE, tags);
    System.out.println("Wrote to '" + OUTPUT_FILE + "'");
}
Also used : TagValueHolder(tools.utils.TagValueHolder) NestedTagValue(tools.utils.TagValue.NestedTagValue) HashAlgorithm(fr.xephi.authme.security.HashAlgorithm)

Aggregations

HashAlgorithm (fr.xephi.authme.security.HashAlgorithm)5 NestedTagValue (tools.utils.TagValue.NestedTagValue)2 TagValueHolder (tools.utils.TagValueHolder)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1