35
35
import java .time .format .DateTimeParseException ;
36
36
import java .util .ArrayList ;
37
37
import java .util .Deque ;
38
+ import java .util .Enumeration ;
38
39
import java .util .HashMap ;
39
40
import java .util .HashSet ;
40
41
import java .util .Iterator ;
41
- import java .util .LinkedList ;
42
42
import java .util .List ;
43
43
import java .util .Map ;
44
44
import java .util .Objects ;
@@ -994,6 +994,9 @@ private static final class ProfileParser {
994
994
// The java.security properties.
995
995
private final Properties securityProps ;
996
996
997
+ private final Set <String > profileCheckPropertyNames ;
998
+ private final Set <String > profileCheckProviderNames ;
999
+
997
1000
/**
998
1001
*
999
1002
* @param id the restricted security custom profile ID
@@ -1016,8 +1019,13 @@ private ProfileParser(String id, Properties props) {
1016
1019
1017
1020
parsedProfiles = new HashSet <>();
1018
1021
1022
+ profileCheckPropertyNames = new HashSet <>();
1023
+ profileCheckProviderNames = new HashSet <>();
1024
+
1019
1025
// Initialize the properties.
1020
1026
init (profileID );
1027
+
1028
+ checkProfileCheck (profileID );
1021
1029
}
1022
1030
1023
1031
private RestrictedSecurityProperties getProperties () {
@@ -1040,12 +1048,17 @@ private void init(String profileID) {
1040
1048
printStackTraceAndExit (profileID + " has already been parsed. Potential infinite recursion." );
1041
1049
}
1042
1050
1043
- String potentialExtendsProfileID = parseProperty (securityProps .getProperty (profileID + ".extends" ));
1051
+ loadProfileCheck (profileID );
1052
+
1053
+ String profileExtends = profileID + ".extends" ;
1054
+ String potentialExtendsProfileID = parseProperty (securityProps .getProperty (profileExtends ));
1044
1055
if (potentialExtendsProfileID != null ) { // If profile extends another profile.
1045
1056
if (debug != null ) {
1046
1057
debug .println ("\t '" + profileID + "' extends '" + potentialExtendsProfileID + "'." );
1047
1058
}
1048
1059
1060
+ profileCheckPropertyNames .remove (profileExtends );
1061
+
1049
1062
// Check if extended profile exists.
1050
1063
String extendsProfileID = null ;
1051
1064
if (potentialExtendsProfileID .indexOf ('.' ) != potentialExtendsProfileID .lastIndexOf ('.' )) {
@@ -1098,6 +1111,7 @@ private void init(String profileID) {
1098
1111
// Save info to be hashed and expected result to be checked later.
1099
1112
profilesHashes .put (profileID , hashValue );
1100
1113
profilesInfo .put (profileID , allInfo );
1114
+ profileCheckPropertyNames .remove (hashProperty );
1101
1115
} else if (!isFIPS1402Profile (profileID )) {
1102
1116
// A hash is mandatory, but not for older 140-2 profiles.
1103
1117
printStackTraceAndExit (profileID + " is a base profile, so a hash value is mandatory." );
@@ -1134,6 +1148,7 @@ private void update(String profileExtensionId) {
1134
1148
// Save info to be hashed and expected result to be checked later.
1135
1149
profilesHashes .put (profileID , hashValue );
1136
1150
profilesInfo .put (profileID , allInfo );
1151
+ profileCheckPropertyNames .remove (hashProperty );
1137
1152
}
1138
1153
} catch (Exception e ) {
1139
1154
if (debug != null ) {
@@ -1254,6 +1269,7 @@ private void initProviders(String profileID, List<String> allInfo) {
1254
1269
allInfo .add (property + "=" + providerInfo );
1255
1270
1256
1271
parseProvider (providerInfo , pNum , false );
1272
+ profileCheckProviderNames .remove (property );
1257
1273
}
1258
1274
1259
1275
if (providers .isEmpty ()) {
@@ -1284,6 +1300,7 @@ private void updateProviders(String profileExtensionId, List<String> allInfo) {
1284
1300
removedProvider = true ;
1285
1301
break ;
1286
1302
}
1303
+ profileCheckProviderNames .remove (property );
1287
1304
}
1288
1305
}
1289
1306
@@ -1311,6 +1328,7 @@ private void updateProviders(String profileExtensionId, List<String> allInfo) {
1311
1328
allInfo .add (property + "=" + providerInfo );
1312
1329
1313
1330
parseProvider (providerInfo , i , false );
1331
+ profileCheckProviderNames .remove (property );
1314
1332
}
1315
1333
}
1316
1334
@@ -1634,6 +1652,7 @@ private boolean setProperty(String property, String propertyKey, List<String> al
1634
1652
newValue = value ;
1635
1653
}
1636
1654
profileProperties .put (property , newValue );
1655
+ profileCheckPropertyNames .remove (propertyKey );
1637
1656
return true ;
1638
1657
}
1639
1658
if (debug != null ) {
@@ -1706,6 +1725,39 @@ private static void checkProviderFormat(String providerInfo, boolean update) {
1706
1725
printStackTraceAndExit ("Provider format is incorrect: " + providerInfo );
1707
1726
}
1708
1727
}
1728
+
1729
+ private void loadProfileCheck (String profileID ) {
1730
+ Enumeration <?> pNames = securityProps .propertyNames ();
1731
+ String profileDot = profileID + '.' ;
1732
+ while (pNames .hasMoreElements ()) {
1733
+ String name = (String ) pNames .nextElement ();
1734
+ if (name .startsWith (profileDot )) {
1735
+ if (name .contains (".jce.provider." )) {
1736
+ profileCheckProviderNames .add (name );
1737
+ } else {
1738
+ profileCheckPropertyNames .add (name );
1739
+ }
1740
+ }
1741
+ }
1742
+ }
1743
+
1744
+ private void checkProfileCheck (String profileID ) {
1745
+ if (!profileCheckProviderNames .isEmpty ()) {
1746
+ printStackTraceAndExit (
1747
+ "The order numbers of providers in profile " + profileID
1748
+ + " (or a base profile) are not consecutive." );
1749
+ }
1750
+ if (!profileCheckPropertyNames .isEmpty ()) {
1751
+ printStackTraceAndExit (
1752
+ "The property names: "
1753
+ + profileCheckPropertyNames
1754
+ .stream ()
1755
+ .sorted ()
1756
+ .collect (Collectors .joining (", " ))
1757
+ + " in profile " + profileID
1758
+ + " (or a base profile) are not recognized." );
1759
+ }
1760
+ }
1709
1761
}
1710
1762
1711
1763
/**
0 commit comments