/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Algorithm constraints for disabled algorithms property
*
* See the "jdk.certpath.disabledAlgorithms" specification in java.security
* for the syntax of the disabled algorithm string.
*/
// the known security property, jdk.certpath.disabledAlgorithms
"jdk.certpath.disabledAlgorithms";
// the known security property, jdk.tls.disabledAlgorithms
"jdk.tls.disabledAlgorithms";
/**
* Initialize algorithm constraints with the specified security property.
*
* @param propertyName the security property name that define the disabled
* algorithm constraints
*/
synchronized (disabledAlgorithmsMap) {
}
}
}
throw new IllegalArgumentException("No algorithm name specified");
}
throw new IllegalArgumentException(
"No cryptographic primitive specified");
}
continue;
}
// check the full name
return false;
}
// decompose the algorithm into sub-elements
}
// check the items of the algorithm
return false;
}
}
}
return true;
}
}
throw new IllegalArgumentException("No algorithm name specified");
}
}
/**
* Decompose the standard algorithm name into sub-elements.
* <p>
* For example, we need to decompose "SHA1WithRSA" into "SHA1" and "RSA"
* so that we can check the "SHA1" and "RSA" algorithm constraints
* separately.
* <p>
* Please override the method if need to support more name pattern.
*/
}
continue;
}
// PBEWith<digest>And<encryption>
// PBEWith<prf>And<encryption>
// OAEPWith<digest>And<mgf>Padding
// <digest>with<encryption>
// <digest>with<encryption>and<mgf>
continue;
}
}
}
// In Java standard algorithm name specification, for different
// purpose, the SHA-1 and SHA-2 algorithm names are different. For
// example, for MessageDigest, the standard name is "SHA-256", while
// for Signature, the digest algorithm component is "SHA256" for
// signature algorithm "SHA256withRSA". So we need to check both
// "SHA-256" and "SHA256" to make the right constraint checking.
// handle special name: SHA-1 and SHA1
}
}
// handle special name: SHA-224 and SHA224
}
}
// handle special name: SHA-256 and SHA256
}
}
// handle special name: SHA-384 and SHA384
}
}
// handle special name: SHA-512 and SHA512
}
}
return elements;
}
// Check algorithm constraints
// check the key parameter, it cannot be null.
throw new IllegalArgumentException("The key cannot be null");
}
// check the target algorithm
return false;
}
}
// check the key algorithm
return false;
}
// check the key constraints
return false;
}
return true;
}
// Get disabled algorithm constraints from the specified security property.
private static void loadDisabledAlgorithmsMap(
final String propertyName) {
new PrivilegedAction<String>() {
}
});
}
}
}
// map the disabled algorithms
if (algorithmsInProperty == null) {
}
// map the key constraints
}
/**
* key constraints
*/
private static class KeySizeConstraints {
"(\\S+)\\s+keySize\\s*(<=|<|==|!=|>|>=)\\s*(\\d+)");
continue;
}
synchronized (constraintsMap) {
new HashSet<KeySizeConstraint>());
}
}
}
}
}
// Does this KeySizeConstraints disable the specified key?
synchronized (constraintsMap) {
return true;
}
}
}
}
return false;
}
}
/**
* Key size constraint.
*
* e.g. "keysize <= 1024"
*/
private static class KeySizeConstraint {
// operator
static enum Operator {
switch (s) {
case "==":
return EQ;
case "!=":
return NE;
case "<":
return LT;
case "<=":
return LE;
case ">":
return GT;
case ">=":
return GE;
}
throw new IllegalArgumentException(
s + " is not a legal Operator");
}
}
switch (operator) {
case EQ: // an unavailable key size
this.minSize = 0;
break;
case NE:
break;
case LT:
break;
case LE:
break;
case GT:
this.minSize = 0;
break;
case GE:
this.minSize = 0;
break;
default:
// unlikely to happen
this.maxSize = -1;
}
}
// Does this key constraint disable the specified key?
if (size == 0) {
return true; // we don't allow any key of size 0.
} else if (size > 0) {
(prohibitedSize == size));
} // Otherwise, the key size is not accessible. Conservatively,
// please don't disable such keys.
return false;
}
}
}