37
37
import java .io .IOException ;
38
38
import java .io .InputStream ;
39
39
import java .lang .ref .SoftReference ;
40
- import java .net .URL ;
41
40
import java .security .CodeSigner ;
42
- import java .security .CodeSource ;
43
41
import java .security .cert .Certificate ;
44
- import java .util .ArrayList ;
45
- import java .util .Collections ;
46
42
import java .util .Enumeration ;
47
43
import java .util .List ;
48
- import java .util .NoSuchElementException ;
49
44
import java .util .Objects ;
50
45
import java .util .stream .Stream ;
51
46
import java .util .zip .ZipEntry ;
@@ -658,7 +653,7 @@ public Certificate[] getCertificates() {
658
653
throw new RuntimeException (e );
659
654
}
660
655
if (certs == null && jv != null ) {
661
- certs = jv .getCerts (JarFile . this , realEntry ());
656
+ certs = jv .getCerts (realEntry ());
662
657
}
663
658
return certs == null ? null : certs .clone ();
664
659
}
@@ -671,7 +666,7 @@ public CodeSigner[] getCodeSigners() {
671
666
throw new RuntimeException (e );
672
667
}
673
668
if (signers == null && jv != null ) {
674
- signers = jv .getCodeSigners (JarFile . this , realEntry ());
669
+ signers = jv .getCodeSigners (realEntry ());
675
670
}
676
671
return signers == null ? null : signers .clone ();
677
672
}
@@ -1073,195 +1068,4 @@ synchronized void ensureInitialization() {
1073
1068
static boolean isInitializing () {
1074
1069
return ThreadTrackHolder .TRACKER .contains (Thread .currentThread ());
1075
1070
}
1076
-
1077
- /*
1078
- * Returns a versioned {@code JarFileEntry} for the given entry,
1079
- * if there is one. Otherwise returns the original entry. This
1080
- * is invoked by the {@code entries2} for verifier.
1081
- */
1082
- JarEntry newEntry (JarEntry je ) {
1083
- if (isMultiRelease ()) {
1084
- return getVersionedEntry (je .getName (), je );
1085
- }
1086
- return je ;
1087
- }
1088
-
1089
- /*
1090
- * Returns a versioned {@code JarFileEntry} for the given entry
1091
- * name, if there is one. Otherwise returns a {@code JarFileEntry}
1092
- * with the given name. It is invoked from JarVerifier's entries2
1093
- * for {@code singers}.
1094
- */
1095
- JarEntry newEntry (String name ) {
1096
- if (isMultiRelease ()) {
1097
- JarEntry vje = getVersionedEntry (name , null );
1098
- if (vje != null ) {
1099
- return vje ;
1100
- }
1101
- }
1102
- return new JarFileEntry (name );
1103
- }
1104
-
1105
- Enumeration <String > entryNames (CodeSource [] cs ) {
1106
- ensureInitialization ();
1107
- if (jv != null ) {
1108
- return jv .entryNames (this , cs );
1109
- }
1110
-
1111
- /*
1112
- * JAR file has no signed content. Is there a non-signing
1113
- * code source?
1114
- */
1115
- boolean includeUnsigned = false ;
1116
- for (CodeSource c : cs ) {
1117
- if (c .getCodeSigners () == null ) {
1118
- includeUnsigned = true ;
1119
- break ;
1120
- }
1121
- }
1122
- if (includeUnsigned ) {
1123
- return unsignedEntryNames ();
1124
- } else {
1125
- return Collections .emptyEnumeration ();
1126
- }
1127
- }
1128
-
1129
- /**
1130
- * Returns an enumeration of the zip file entries
1131
- * excluding internal JAR mechanism entries and including
1132
- * signed entries missing from the ZIP directory.
1133
- */
1134
- Enumeration <JarEntry > entries2 () {
1135
- ensureInitialization ();
1136
- if (jv != null ) {
1137
- return jv .entries2 (this , JUZFA .entries (JarFile .this ));
1138
- }
1139
-
1140
- // screen out entries which are never signed
1141
- final var unfilteredEntries = JUZFA .entries (JarFile .this );
1142
-
1143
- return new Enumeration <>() {
1144
-
1145
- JarEntry entry ;
1146
-
1147
- public boolean hasMoreElements () {
1148
- if (entry != null ) {
1149
- return true ;
1150
- }
1151
- while (unfilteredEntries .hasMoreElements ()) {
1152
- JarEntry je = unfilteredEntries .nextElement ();
1153
- if (JarVerifier .isSigningRelated (je .getName ())) {
1154
- continue ;
1155
- }
1156
- entry = je ;
1157
- return true ;
1158
- }
1159
- return false ;
1160
- }
1161
-
1162
- public JarEntry nextElement () {
1163
- if (hasMoreElements ()) {
1164
- JarEntry je = entry ;
1165
- entry = null ;
1166
- return newEntry (je );
1167
- }
1168
- throw new NoSuchElementException ();
1169
- }
1170
- };
1171
- }
1172
-
1173
- CodeSource [] getCodeSources (URL url ) {
1174
- ensureInitialization ();
1175
- if (jv != null ) {
1176
- return jv .getCodeSources (this , url );
1177
- }
1178
-
1179
- /*
1180
- * JAR file has no signed content. Is there a non-signing
1181
- * code source?
1182
- */
1183
- Enumeration <String > unsigned = unsignedEntryNames ();
1184
- if (unsigned .hasMoreElements ()) {
1185
- return new CodeSource []{JarVerifier .getUnsignedCS (url )};
1186
- } else {
1187
- return null ;
1188
- }
1189
- }
1190
-
1191
- private Enumeration <String > unsignedEntryNames () {
1192
- final Enumeration <JarEntry > entries = entries ();
1193
- return new Enumeration <>() {
1194
-
1195
- String name ;
1196
-
1197
- /*
1198
- * Grab entries from ZIP directory but screen out
1199
- * metadata.
1200
- */
1201
- public boolean hasMoreElements () {
1202
- if (name != null ) {
1203
- return true ;
1204
- }
1205
- while (entries .hasMoreElements ()) {
1206
- String value ;
1207
- ZipEntry e = entries .nextElement ();
1208
- value = e .getName ();
1209
- if (e .isDirectory () || JarVerifier .isSigningRelated (value )) {
1210
- continue ;
1211
- }
1212
- name = value ;
1213
- return true ;
1214
- }
1215
- return false ;
1216
- }
1217
-
1218
- public String nextElement () {
1219
- if (hasMoreElements ()) {
1220
- String value = name ;
1221
- name = null ;
1222
- return value ;
1223
- }
1224
- throw new NoSuchElementException ();
1225
- }
1226
- };
1227
- }
1228
-
1229
- CodeSource getCodeSource (URL url , String name ) {
1230
- ensureInitialization ();
1231
- if (jv != null ) {
1232
- if (jv .eagerValidation ) {
1233
- CodeSource cs ;
1234
- JarEntry je = getJarEntry (name );
1235
- if (je != null ) {
1236
- cs = jv .getCodeSource (url , this , je );
1237
- } else {
1238
- cs = jv .getCodeSource (url , name );
1239
- }
1240
- return cs ;
1241
- } else {
1242
- return jv .getCodeSource (url , name );
1243
- }
1244
- }
1245
-
1246
- return JarVerifier .getUnsignedCS (url );
1247
- }
1248
-
1249
- void setEagerValidation (boolean eager ) {
1250
- try {
1251
- maybeInstantiateVerifier ();
1252
- } catch (IOException e ) {
1253
- throw new RuntimeException (e );
1254
- }
1255
- if (jv != null ) {
1256
- jv .setEagerValidation (eager );
1257
- }
1258
- }
1259
-
1260
- List <Object > getManifestDigests () {
1261
- ensureInitialization ();
1262
- if (jv != null ) {
1263
- return jv .getManifestDigests ();
1264
- }
1265
- return new ArrayList <>();
1266
- }
1267
1071
}
0 commit comments