src/share/classes/sun/security/tools/jarsigner/Main.java
Print this page
*** 55,65 ****
import java.util.Map.Entry;
import sun.security.tools.KeyStoreUtil;
import sun.security.tools.PathList;
import sun.security.x509.*;
import sun.security.util.*;
! import sun.misc.BASE64Encoder;
/**
* <p>The jarsigner utility.
*
--- 55,65 ----
import java.util.Map.Entry;
import sun.security.tools.KeyStoreUtil;
import sun.security.tools.PathList;
import sun.security.x509.*;
import sun.security.util.*;
! import java.util.Base64;
/**
* <p>The jarsigner utility.
*
*** 1118,1128 ****
* - if entry is contained in manifest, calculate its hash and
* compare it with the one in the manifest; if they are
* different, replace the hash in the manifest with the newly
* generated one. (This may invalidate existing signatures!)
*/
- BASE64Encoder encoder = new JarBASE64Encoder();
Vector<ZipEntry> mfFiles = new Vector<>();
boolean wasSigned = false;
for (Enumeration<? extends ZipEntry> enum_=zipFile.entries();
--- 1118,1127 ----
*** 1146,1164 ****
}
if (manifest.getAttributes(ze.getName()) != null) {
// jar entry is contained in manifest, check and
// possibly update its digest attributes
! if (updateDigests(ze, zipFile, digests, encoder,
manifest) == true) {
mfModified = true;
}
} else if (!ze.isDirectory()) {
// Add entry to manifest
Attributes attrs = getDigestAttributes(ze, zipFile,
! digests,
! encoder);
mfEntries.put(ze.getName(), attrs);
mfModified = true;
}
}
--- 1145,1162 ----
}
if (manifest.getAttributes(ze.getName()) != null) {
// jar entry is contained in manifest, check and
// possibly update its digest attributes
! if (updateDigests(ze, zipFile, digests,
manifest) == true) {
mfModified = true;
}
} else if (!ze.isDirectory()) {
// Add entry to manifest
Attributes attrs = getDigestAttributes(ze, zipFile,
! digests);
mfEntries.put(ze.getName(), attrs);
mfModified = true;
}
}
*** 1953,1964 ****
/*
* Computes the digests of a zip entry, and returns them as an array
* of base64-encoded strings.
*/
private synchronized String[] getDigests(ZipEntry ze, ZipFile zf,
! MessageDigest[] digests,
! BASE64Encoder encoder)
throws IOException {
int n, i;
InputStream is = null;
try {
--- 1951,1961 ----
/*
* Computes the digests of a zip entry, and returns them as an array
* of base64-encoded strings.
*/
private synchronized String[] getDigests(ZipEntry ze, ZipFile zf,
! MessageDigest[] digests)
throws IOException {
int n, i;
InputStream is = null;
try {
*** 1978,2002 ****
}
// complete the digests
String[] base64Digests = new String[digests.length];
for (i=0; i<digests.length; i++) {
! base64Digests[i] = encoder.encode(digests[i].digest());
}
return base64Digests;
}
/*
* Computes the digests of a zip entry, and returns them as a list of
* attributes
*/
private Attributes getDigestAttributes(ZipEntry ze, ZipFile zf,
! MessageDigest[] digests,
! BASE64Encoder encoder)
throws IOException {
! String[] base64Digests = getDigests(ze, zf, digests, encoder);
Attributes attrs = new Attributes();
for (int i=0; i<digests.length; i++) {
attrs.putValue(digests[i].getAlgorithm()+"-Digest",
base64Digests[i]);
--- 1975,1998 ----
}
// complete the digests
String[] base64Digests = new String[digests.length];
for (i=0; i<digests.length; i++) {
! base64Digests[i] = Base64.getEncoder().encodeToString(digests[i].digest());
}
return base64Digests;
}
/*
* Computes the digests of a zip entry, and returns them as a list of
* attributes
*/
private Attributes getDigestAttributes(ZipEntry ze, ZipFile zf,
! MessageDigest[] digests)
throws IOException {
! String[] base64Digests = getDigests(ze, zf, digests);
Attributes attrs = new Attributes();
for (int i=0; i<digests.length; i++) {
attrs.putValue(digests[i].getAlgorithm()+"-Digest",
base64Digests[i]);
*** 2014,2029 ****
* Returns true if the manifest entry has been changed, and false
* otherwise.
*/
private boolean updateDigests(ZipEntry ze, ZipFile zf,
MessageDigest[] digests,
- BASE64Encoder encoder,
Manifest mf) throws IOException {
boolean update = false;
Attributes attrs = mf.getAttributes(ze.getName());
! String[] base64Digests = getDigests(ze, zf, digests, encoder);
for (int i=0; i<digests.length; i++) {
// The entry name to be written into attrs
String name = null;
try {
--- 2010,2024 ----
* Returns true if the manifest entry has been changed, and false
* otherwise.
*/
private boolean updateDigests(ZipEntry ze, ZipFile zf,
MessageDigest[] digests,
Manifest mf) throws IOException {
boolean update = false;
Attributes attrs = mf.getAttributes(ze.getName());
! String[] base64Digests = getDigests(ze, zf, digests);
for (int i=0; i<digests.length; i++) {
// The entry name to be written into attrs
String name = null;
try {
*** 2092,2114 ****
}
return (ContentSigner)signer;
}
}
- /**
- * This is a BASE64Encoder that does not insert a default newline at the end of
- * every output line. This is necessary because java.util.jar does its own
- * line management (see Manifest.make72Safe()). Inserting additional new lines
- * can cause line-wrapping problems (see CR 6219522).
- */
- class JarBASE64Encoder extends BASE64Encoder {
- /**
- * Encode the suffix that ends every output line.
- */
- protected void encodeLineSuffix(OutputStream aStream) throws IOException { }
- }
-
class SignatureFile {
/** SignatureFile */
Manifest sf;
--- 2087,2096 ----
*** 2127,2146 ****
String version = System.getProperty("java.version");
String javaVendor = System.getProperty("java.vendor");
sf = new Manifest();
Attributes mattr = sf.getMainAttributes();
- BASE64Encoder encoder = new JarBASE64Encoder();
mattr.putValue(Attributes.Name.SIGNATURE_VERSION.toString(), "1.0");
mattr.putValue("Created-By", version + " (" + javaVendor + ")");
if (signManifest) {
// sign the whole manifest
for (int i=0; i < digests.length; i++) {
mattr.putValue(digests[i].getAlgorithm()+"-Digest-Manifest",
! encoder.encode(md.manifestDigest(digests[i])));
}
}
// create digest of the manifest main attributes
ManifestDigester.Entry mde =
--- 2109,2127 ----
String version = System.getProperty("java.version");
String javaVendor = System.getProperty("java.vendor");
sf = new Manifest();
Attributes mattr = sf.getMainAttributes();
mattr.putValue(Attributes.Name.SIGNATURE_VERSION.toString(), "1.0");
mattr.putValue("Created-By", version + " (" + javaVendor + ")");
if (signManifest) {
// sign the whole manifest
for (int i=0; i < digests.length; i++) {
mattr.putValue(digests[i].getAlgorithm()+"-Digest-Manifest",
! Base64.getEncoder().encodeToString(md.manifestDigest(digests[i])));
}
}
// create digest of the manifest main attributes
ManifestDigester.Entry mde =
*** 2147,2157 ****
md.get(ManifestDigester.MF_MAIN_ATTRS, false);
if (mde != null) {
for (int i=0; i < digests.length; i++) {
mattr.putValue(digests[i].getAlgorithm() +
"-Digest-" + ManifestDigester.MF_MAIN_ATTRS,
! encoder.encode(mde.digest(digests[i])));
}
} else {
throw new IllegalStateException
("ManifestDigester failed to create " +
"Manifest-Main-Attribute entry");
--- 2128,2138 ----
md.get(ManifestDigester.MF_MAIN_ATTRS, false);
if (mde != null) {
for (int i=0; i < digests.length; i++) {
mattr.putValue(digests[i].getAlgorithm() +
"-Digest-" + ManifestDigester.MF_MAIN_ATTRS,
! Base64.getEncoder().encodeToString(mde.digest(digests[i])));
}
} else {
throw new IllegalStateException
("ManifestDigester failed to create " +
"Manifest-Main-Attribute entry");
*** 2168,2178 ****
mde = md.get(name, false);
if (mde != null) {
Attributes attr = new Attributes();
for (int i=0; i < digests.length; i++) {
attr.putValue(digests[i].getAlgorithm()+"-Digest",
! encoder.encode(mde.digest(digests[i])));
}
entries.put(name, attr);
}
}
}
--- 2149,2159 ----
mde = md.get(name, false);
if (mde != null) {
Attributes attr = new Attributes();
for (int i=0; i < digests.length; i++) {
attr.putValue(digests[i].getAlgorithm()+"-Digest",
! Base64.getEncoder().encodeToString(mde.digest(digests[i])));
}
entries.put(name, attr);
}
}
}