1
1
/*
2
- * Copyright (c) 1997, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1997, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -81,6 +81,8 @@ public class SignatureFileVerifier {
81
81
/** ConstraintsParameters for checking disabled algorithms */
82
82
private JarConstraintsParameters params ;
83
83
84
+ private static final String META_INF = "META-INF/" ;
85
+
84
86
/**
85
87
* Create the named SignatureFileVerifier.
86
88
*
@@ -141,6 +143,18 @@ public void setSignatureFile(byte[] sfBytes)
141
143
this .sfBytes = sfBytes ;
142
144
}
143
145
146
+ /**
147
+ * Utility method used by JarVerifier and JarSigner
148
+ * to determine if a path is located directly in the
149
+ * META-INF/ directory
150
+ *
151
+ * @param name the path name to check
152
+ * @return true if the path resides in META-INF directly, ignoring case
153
+ */
154
+ public static boolean isInMetaInf (String name ) {
155
+ return name .regionMatches (true , 0 , META_INF , 0 , META_INF .length ())
156
+ && name .lastIndexOf ('/' ) < META_INF .length ();
157
+ }
144
158
/**
145
159
* Utility method used by JarVerifier and JarSigner
146
160
* to determine the signature file names and PKCS7 block
@@ -153,7 +167,7 @@ public void setSignatureFile(byte[] sfBytes)
153
167
*/
154
168
public static boolean isBlockOrSF (String s ) {
155
169
// Note: keep this in sync with j.u.z.ZipFile.Source#isSignatureRelated
156
- // we currently only support DSA and RSA PKCS7 blocks
170
+ // we currently only support DSA, RSA or EC PKCS7 blocks
157
171
return s .endsWith (".SF" )
158
172
|| s .endsWith (".DSA" )
159
173
|| s .endsWith (".RSA" )
@@ -191,19 +205,15 @@ public static String getBlockExtension(PrivateKey key) {
191
205
* @return true if the input file name is signature related
192
206
*/
193
207
public static boolean isSigningRelated (String name ) {
194
- name = name .toUpperCase (Locale .ENGLISH );
195
- if (!name .startsWith ("META-INF/" )) {
208
+ if (!isInMetaInf (name )) {
196
209
return false ;
197
210
}
198
- name = name .substring (9 );
199
- if (name .indexOf ('/' ) != -1 ) {
200
- return false ;
201
- }
202
- if (isBlockOrSF (name ) || name .equals ("MANIFEST.MF" )) {
211
+ name = name .toUpperCase (Locale .ENGLISH );
212
+ if (isBlockOrSF (name ) || name .equals ("META-INF/MANIFEST.MF" )) {
203
213
return true ;
204
- } else if (name .startsWith ("SIG-" )) {
214
+ } else if (name .startsWith ("SIG-" , META_INF . length () )) {
205
215
// check filename extension
206
- // see http ://docs.oracle.com/javase/7 /docs/technotes/guides/ jar/jar.html#Digital_Signatures
216
+ // see https ://docs.oracle.com/en/java/ javase/19 /docs/specs/ jar/jar.html#digital-signatures
207
217
// for what filename extensions are legal
208
218
int extIndex = name .lastIndexOf ('.' );
209
219
if (extIndex != -1 ) {
0 commit comments