/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.id.auth.modules.eidas.utils; import java.util.regex.Pattern; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import com.google.common.collect.ImmutableSet; import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils; /** * @author tlenz * */ public class MOAWhiteListConfigurator { private static final Pattern WHITE_LIST_SPLITTER = Pattern.compile("[;,]"); public static ImmutableSet getAllowedAlgorithms( ImmutableSet defaultWhiteList, ImmutableSet allowedValues, String algorithmWhiteListValue) { if (StringUtils.isBlank(algorithmWhiteListValue)) { return defaultWhiteList; } ImmutableSet.Builder allowed = ImmutableSet.builder(); String[] wlAlgorithms = WHITE_LIST_SPLITTER.split(algorithmWhiteListValue); //BugFix: remove newlines from configuration for (int i=0; i 0) { return getAllowedAlgorithms(defaultWhiteList, allowedValues, ImmutableSet.copyOf(wlAlgorithms)); } return defaultWhiteList; } public static ImmutableSet getAllowedAlgorithms( ImmutableSet defaultWhiteList, ImmutableSet allowedValues, ImmutableSet candidateValues) { if (CollectionUtils.isEmpty(candidateValues)) { return defaultWhiteList; } ImmutableSet.Builder allowed = ImmutableSet.builder(); boolean modified = false; for (String candidateValue : candidateValues) { /**FIX: * fix problem with lowerCase and MGF1 signature algorithms * */ candidateValue = StringUtils.trimToNull( KeyValueUtils.removeAllNewlineFromString(candidateValue)); if (StringUtils.isNotBlank(candidateValue)) { //BUGFIX: eIDAS SAML-engine MPF1 signature schemes problem String candidateAlgorithm = candidateValue; //String candidateAlgorithm = StringUtils.lowerCase(candidateValue, Locale.ENGLISH); if (allowedValues.contains(candidateAlgorithm)) { allowed.add(candidateValue); if (!modified && !candidateAlgorithm.equals(candidateValue)) { modified = true; } } else { modified = true; } } } if (!modified) { return candidateValues; } ImmutableSet set = allowed.build(); if (set.isEmpty()) { return defaultWhiteList; } return set; } }