8321274: Rename ZipEntry.extraAttributes to ZipEntry.externalFileAttributes

Reviewed-by: lancea, jpai
This commit is contained in:
Eirik Bjørsnøs 2024-07-03 04:36:32 +00:00 committed by Jaikiran Pai
parent fac74b118f
commit d51141e5fc
12 changed files with 52 additions and 56 deletions

View File

@ -59,7 +59,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
int flag = 0; // general purpose flag
byte[] extra; // optional extra field data for entry
String comment; // optional comment string for entry
int extraAttributes = -1; // e.g. POSIX permissions, sym links.
int externalFileAttributes = -1; // File type, setuid, setgid, sticky, POSIX permissions
/**
* Compression method for uncompressed entries.
*/
@ -134,7 +134,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
flag = e.flag;
extra = e.extra;
comment = e.comment;
extraAttributes = e.extraAttributes;
externalFileAttributes = e.externalFileAttributes;
}
/**

View File

@ -697,7 +697,7 @@ public class ZipFile implements ZipConstants, Closeable {
e.method = CENHOW(cen, pos);
if (CENVEM_FA(cen, pos) == FILE_ATTRIBUTES_UNIX) {
// read all bits in this field, including sym link attributes
e.extraAttributes = CENATX_PERMS(cen, pos) & 0xFFFF;
e.externalFileAttributes = CENATX_PERMS(cen, pos) & 0xFFFF;
}
if (elen != 0) {
@ -1165,12 +1165,12 @@ public class ZipFile implements ZipConstants, Closeable {
return zip.entryNameStream();
}
@Override
public int getExtraAttributes(ZipEntry ze) {
return ze.extraAttributes;
public int getExternalFileAttributes(ZipEntry ze) {
return ze.externalFileAttributes;
}
@Override
public void setExtraAttributes(ZipEntry ze, int extraAttrs) {
ze.extraAttributes = extraAttrs;
public void setExternalFileAttributes(ZipEntry ze, int externalFileAttributes) {
ze.externalFileAttributes = externalFileAttributes;
}
}

View File

@ -541,7 +541,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
* to a version value.
*/
private int versionMadeBy(ZipEntry e, int version) {
return (e.extraAttributes < 0) ? version :
return (e.externalFileAttributes < 0) ? version :
VERSION_MADE_BY_BASE_UNIX | (version & 0xff);
}
@ -637,7 +637,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
writeShort(0); // starting disk number
writeShort(0); // internal file attributes (unused)
// extra file attributes, used for storing posix permissions etc.
writeInt(e.extraAttributes > 0 ? e.extraAttributes << 16 : 0);
writeInt(e.externalFileAttributes > 0 ? e.externalFileAttributes << 16 : 0);
writeInt(offset); // relative offset of local header
writeBytes(nameBytes, 0, nameBytes.length);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -42,7 +42,7 @@ public interface JavaUtilZipFileAccess {
public Enumeration<JarEntry> entries(ZipFile zip);
public Stream<JarEntry> stream(ZipFile zip);
public Stream<String> entryNameStream(ZipFile zip);
public void setExtraAttributes(ZipEntry ze, int extraAttrs);
public int getExtraAttributes(ZipEntry ze);
public void setExternalFileAttributes(ZipEntry ze, int externalFileAttributes);
public int getExternalFileAttributes(ZipEntry ze);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,7 +31,6 @@ import sun.security.pkcs.PKCS7;
import sun.security.pkcs.PKCS9Attribute;
import sun.security.pkcs.PKCS9Attributes;
import sun.security.timestamp.HttpTimestamper;
import sun.security.tools.PathList;
import sun.security.util.Event;
import sun.security.util.ManifestDigester;
import sun.security.util.SignatureFileVerifier;
@ -39,11 +38,8 @@ import sun.security.util.SignatureUtil;
import sun.security.x509.AlgorithmId;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.*;
import java.security.cert.CertPath;
import java.security.cert.Certificate;
@ -492,7 +488,7 @@ public final class JarSigner {
private final String tSADigestAlg;
private final boolean sectionsonly; // do not "sign" the whole manifest
private final boolean internalsf; // include the .SF inside the PKCS7 block
private boolean extraAttrsDetected;
private boolean externalFileAttributesDetected;
private JarSigner(JarSigner.Builder builder) {
@ -936,12 +932,12 @@ public final class JarSigner {
ze2.setTime(ze.getTime());
ze2.setComment(ze.getComment());
ze2.setExtra(ze.getExtra());
int extraAttrs = JUZFA.getExtraAttributes(ze);
if (!extraAttrsDetected && extraAttrs != -1) {
extraAttrsDetected = true;
int externalFileAttributes = JUZFA.getExternalFileAttributes(ze);
if (!externalFileAttributesDetected && externalFileAttributes != -1) {
externalFileAttributesDetected = true;
Event.report(Event.ReporterCategory.ZIPFILEATTRS, "detected");
}
JUZFA.setExtraAttributes(ze2, extraAttrs);
JUZFA.setExternalFileAttributes(ze2, externalFileAttributes);
if (ze.getMethod() == ZipEntry.STORED) {
ze2.setSize(ze.getSize());
ze2.setCrc(ze.getCrc());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -118,7 +118,7 @@ public class Main {
private static final Set<CryptoPrimitive> SIG_PRIMITIVE_SET = Collections
.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE));
private static boolean extraAttrsDetected;
private static boolean externalFileAttributesDetected;
static final String VERSION = "1.0";
@ -823,8 +823,8 @@ public class Main {
JarEntry je = e.nextElement();
String name = je.getName();
if (!extraAttrsDetected && JUZFA.getExtraAttributes(je) != -1) {
extraAttrsDetected = true;
if (!externalFileAttributesDetected && JUZFA.getExternalFileAttributes(je) != -1) {
externalFileAttributesDetected = true;
}
hasSignature |= signatureRelated(name) && SignatureFileVerifier.isBlockOrSF(name);
@ -1311,8 +1311,8 @@ public class Main {
}
}
if (extraAttrsDetected) {
warnings.add(rb.getString("extra.attributes.detected"));
if (externalFileAttributesDetected) {
warnings.add(rb.getString("external.file.attributes.detected"));
}
if ((strict) && (!errors.isEmpty())) {
@ -1946,7 +1946,7 @@ public class Main {
try {
Event.setReportListener(Event.ReporterCategory.ZIPFILEATTRS,
(t, o) -> extraAttrsDetected = true);
(t, o) -> externalFileAttributesDetected = true);
builder.build().sign(zipFile, fos);
} catch (JarSignerException e) {
failedCause = e.getCause();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -178,7 +178,7 @@ public class Resources extends java.util.ListResourceBundle {
{"key.bit.disabled", "%d-bit key (disabled)"},
{"key.bit.eccurve.disabled", "%1$d-bit %2$s key (disabled)"},
{"unknown.size", "unknown size"},
{"extra.attributes.detected", "POSIX file permission and/or symlink attributes detected. These attributes are ignored when signing and are not protected by the signature."},
{"external.file.attributes.detected", "POSIX file permission and/or symlink attributes detected. These attributes are ignored when signing and are not protected by the signature."},
{"jarsigner.", "jarsigner: "},
{"signature.filename.must.consist.of.the.following.characters.A.Z.0.9.or.",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -178,7 +178,7 @@ public class Resources_de extends java.util.ListResourceBundle {
{"key.bit.disabled", "%d-Bit-Schl\u00FCssel (deaktiviert)"},
{"key.bit.eccurve.disabled", "%1$d-Bit-%2$s-Schl\u00FCssel (deaktiviert)"},
{"unknown.size", "unbekannte Gr\u00F6\u00DFe"},
{"extra.attributes.detected", "POSIX-Dateiberechtigung und/oder Symlink-Attribute erkannt. Diese Attribute werden bei der Signatur ignoriert und sind nicht durch die Signatur gesch\u00FCtzt."},
{"external.file.attributes.detected", "POSIX-Dateiberechtigung und/oder Symlink-Attribute erkannt. Diese Attribute werden bei der Signatur ignoriert und sind nicht durch die Signatur gesch\u00FCtzt."},
{"jarsigner.", "jarsigner: "},
{"signature.filename.must.consist.of.the.following.characters.A.Z.0.9.or.",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -178,7 +178,7 @@ public class Resources_ja extends java.util.ListResourceBundle {
{"key.bit.disabled", "%d\u30D3\u30C3\u30C8\u30FB\u30AD\u30FC (\u7121\u52B9)"},
{"key.bit.eccurve.disabled", "%1$d\u30D3\u30C3\u30C8%2$s\u30AD\u30FC(\u7121\u52B9)"},
{"unknown.size", "\u4E0D\u660E\u30B5\u30A4\u30BA"},
{"extra.attributes.detected", "POSIX\u30D5\u30A1\u30A4\u30EB\u6A29\u9650\u307E\u305F\u306Fsymlink(\u3042\u308B\u3044\u306F\u305D\u306E\u4E21\u65B9)\u306E\u5C5E\u6027\u304C\u691C\u51FA\u3055\u308C\u307E\u3057\u305F\u3002\u7F72\u540D\u4E2D\u306F\u3053\u308C\u3089\u306E\u5C5E\u6027\u306F\u7121\u8996\u3055\u308C\u3001\u7F72\u540D\u306B\u3088\u3063\u3066\u4FDD\u8B77\u3055\u308C\u307E\u305B\u3093\u3002"},
{"external.file.attributes.detected", "POSIX\u30D5\u30A1\u30A4\u30EB\u6A29\u9650\u307E\u305F\u306Fsymlink(\u3042\u308B\u3044\u306F\u305D\u306E\u4E21\u65B9)\u306E\u5C5E\u6027\u304C\u691C\u51FA\u3055\u308C\u307E\u3057\u305F\u3002\u7F72\u540D\u4E2D\u306F\u3053\u308C\u3089\u306E\u5C5E\u6027\u306F\u7121\u8996\u3055\u308C\u3001\u7F72\u540D\u306B\u3088\u3063\u3066\u4FDD\u8B77\u3055\u308C\u307E\u305B\u3093\u3002"},
{"jarsigner.", "jarsigner: "},
{"signature.filename.must.consist.of.the.following.characters.A.Z.0.9.or.",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -178,7 +178,7 @@ public class Resources_zh_CN extends java.util.ListResourceBundle {
{"key.bit.disabled", "%d \u4F4D\u5BC6\u94A5\uFF08\u7981\u7528\uFF09"},
{"key.bit.eccurve.disabled", "%1$d \u4F4D %2$s \u5BC6\u94A5\uFF08\u7981\u7528\uFF09"},
{"unknown.size", "\u672A\u77E5\u5927\u5C0F"},
{"extra.attributes.detected", "\u68C0\u6D4B\u5230 POSIX \u6587\u4EF6\u6743\u9650\u548C/\u6216 symlink \u5C5E\u6027\u3002\u8FD9\u4E9B\u5C5E\u6027\u5728\u8FDB\u884C\u7B7E\u540D\u65F6\u4F1A\u88AB\u5FFD\u7565\uFF0C\u4E0D\u53D7\u8BE5\u7B7E\u540D\u7684\u4FDD\u62A4\u3002"},
{"external.file.attributes.detected", "\u68C0\u6D4B\u5230 POSIX \u6587\u4EF6\u6743\u9650\u548C/\u6216 symlink \u5C5E\u6027\u3002\u8FD9\u4E9B\u5C5E\u6027\u5728\u8FDB\u884C\u7B7E\u540D\u65F6\u4F1A\u88AB\u5FFD\u7565\uFF0C\u4E0D\u53D7\u8BE5\u7B7E\u540D\u7684\u4FDD\u62A4\u3002"},
{"jarsigner.", "jarsigner: "},
{"signature.filename.must.consist.of.the.following.characters.A.Z.0.9.or.",

View File

@ -645,12 +645,12 @@ class ZipFileSystem extends FileSystem {
e.type = Entry.COPY; // copy e
}
if (perms == null) {
e.posixPerms = -1;
} else if (e.posixPerms == -1) {
e.posixPerms = ZipUtils.permsToFlags(perms);
e.externalFileAttributes = -1;
} else if (e.externalFileAttributes == -1) {
e.externalFileAttributes = ZipUtils.permsToFlags(perms);
} else {
e.posixPerms = ZipUtils.permsToFlags(perms) |
(e.posixPerms & 0xFE00); // Preserve unrelated bits
e.externalFileAttributes = ZipUtils.permsToFlags(perms) |
(e.externalFileAttributes & 0xFE00); // Preserve unrelated bits
}
update(e);
} finally {
@ -2887,7 +2887,7 @@ class ZipFileSystem extends FileSystem {
// entry attributes
int version;
int flag;
int posixPerms = -1; // posix permissions
int externalFileAttributes = -1; // file type, setuid, setgid, sticky, posix permissions
int method = -1; // compression method
long mtime = -1; // last modification time (in DOS time)
long atime = -1; // last access time
@ -2923,7 +2923,7 @@ class ZipFileSystem extends FileSystem {
for (FileAttribute<?> attr : attrs) {
String attrName = attr.name();
if (attrName.equals("posix:permissions")) {
posixPerms = ZipUtils.permsToFlags((Set<PosixFilePermission>)attr.value());
externalFileAttributes = ZipUtils.permsToFlags((Set<PosixFilePermission>)attr.value());
}
}
}
@ -2958,7 +2958,7 @@ class ZipFileSystem extends FileSystem {
*/
this.locoff = e.locoff;
this.comment = e.comment;
this.posixPerms = e.posixPerms;
this.externalFileAttributes = e.externalFileAttributes;
this.type = type;
}
@ -2988,7 +2988,7 @@ class ZipFileSystem extends FileSystem {
* to a version value.
*/
private int versionMadeBy(int version) {
return (posixPerms < 0) ? version :
return (externalFileAttributes < 0) ? version :
VERSION_MADE_BY_BASE_UNIX | (version & 0xff);
}
@ -3015,7 +3015,7 @@ class ZipFileSystem extends FileSystem {
attrsEx = CENATX(cen, pos);
*/
if (CENVEM_FA(cen, pos) == FILE_ATTRIBUTES_UNIX) {
posixPerms = (CENATX_PERMS(cen, pos) & 0xFFFF); // 16 bits for file type, setuid, setgid, sticky + perms
externalFileAttributes = (CENATX_PERMS(cen, pos) & 0xFFFF); // 16 bits for file type, setuid, setgid, sticky + perms
}
locoff = CENOFF(cen, pos);
pos += CENHDR;
@ -3105,7 +3105,7 @@ class ZipFileSystem extends FileSystem {
}
writeShort(os, 0); // starting disk number
writeShort(os, 0); // internal file attributes (unused)
writeInt(os, posixPerms > 0 ? posixPerms << 16 : 0); // external file
writeInt(os, externalFileAttributes > 0 ? externalFileAttributes << 16 : 0); // external file
// attributes, used for storing posix
// permissions
writeInt(os, locoff0); // relative offset of local header
@ -3528,10 +3528,10 @@ class ZipFileSystem extends FileSystem {
@Override
public Optional<Set<PosixFilePermission>> storedPermissions() {
Set<PosixFilePermission> perms = null;
if (posixPerms != -1) {
if (externalFileAttributes != -1) {
perms = HashSet.newHashSet(PosixFilePermission.values().length);
for (PosixFilePermission perm : PosixFilePermission.values()) {
if ((posixPerms & ZipUtils.permToFlag(perm)) != 0) {
if ((externalFileAttributes & ZipUtils.permToFlag(perm)) != 0) {
perms.add(perm);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -57,7 +57,7 @@ public class SymLinkTest {
Files.write(Path.of(ZIPFILENAME), ZIPBYTES);
// check attributes before signing
verifyExtraAttrs(ZIPFILENAME);
verifyExternalFileAttributes(ZIPFILENAME);
// generate key for signing
SecurityTools.keytool(
@ -82,7 +82,7 @@ public class SymLinkTest {
.shouldContain(WARNING_MSG);
// recheck attributes after signing
verifyExtraAttrs(ZIPFILENAME);
verifyExternalFileAttributes(ZIPFILENAME);
// verify zip file - expect warning
SecurityTools.jarsigner(
@ -95,8 +95,8 @@ public class SymLinkTest {
.shouldContain(WARNING_MSG);
}
private static void verifyExtraAttrs(String zipFileName) throws IOException {
// the 16 bit extra attributes value should equal 0xa1ff - look for that pattern.
private static void verifyExternalFileAttributes(String zipFileName) throws IOException {
// the 16 bit 'external file attributes' value should equal 0xa1ff - look for that pattern.
// Such values can be read from zip file via 'unzip -Z -l -v <zipfile>'
try (FileInputStream fis = new FileInputStream(ZIPFILENAME)) {
byte[] b = fis.readAllBytes();
@ -107,7 +107,7 @@ public class SymLinkTest {
return;
}
}
throw new RuntimeException("extra attribute value not detected");
throw new RuntimeException("external file attribute value not detected");
}
}