Skip to content

Commit a756320

Browse files
committed
8255536: Remove the directsign property and option
Reviewed-by: mullan
1 parent f77a658 commit a756320

File tree

7 files changed

+22
-170
lines changed

7 files changed

+22
-170
lines changed

src/java.base/share/classes/sun/security/pkcs/PKCS7.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import java.io.*;
2929
import java.math.BigInteger;
3030
import java.net.URI;
31-
import java.security.interfaces.EdECPrivateKey;
32-
import java.security.spec.InvalidParameterSpecException;
33-
import java.security.spec.PSSParameterSpec;
3431
import java.util.*;
3532
import java.security.cert.X509Certificate;
3633
import java.security.cert.CertificateException;

src/jdk.jartool/share/classes/jdk/security/jarsigner/JarSigner.java

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import sun.security.pkcs.PKCS9Attributes;
3535
import sun.security.timestamp.HttpTimestamper;
3636
import sun.security.tools.PathList;
37-
import sun.security.tools.jarsigner.TimestampedSigner;
3837
import sun.security.util.Event;
3938
import sun.security.util.ManifestDigester;
4039
import sun.security.util.SignatureFileVerifier;
@@ -122,7 +121,6 @@ public static class Builder {
122121
String tSADigestAlg;
123122
boolean sectionsonly = false;
124123
boolean internalsf = false;
125-
boolean directsign = false;
126124
String altSignerPath;
127125
String altSigner;
128126

@@ -358,10 +356,6 @@ public Builder eventHandler(BiConsumer<String,String> handler) {
358356
* <li>"sectionsonly": "true" if the .SF file only contains the hash
359357
* value for each section of the manifest and not for the whole
360358
* manifest, "false" otherwise. Default "false".
361-
* <li>"directsign": "true" if the signature is calculated on the
362-
* content directly, "false" if it's calculated on signed attributes
363-
* which itself is calculated from the content and stored in the
364-
* signer's SignerInfo. Default "false".
365359
* </ul>
366360
* All property names are case-insensitive.
367361
*
@@ -395,9 +389,6 @@ public Builder setProperty(String key, String value) {
395389
case "sectionsonly":
396390
this.sectionsonly = parseBoolean("sectionsonly", value);
397391
break;
398-
case "directsign":
399-
this.directsign = parseBoolean("directsign", value);
400-
break;
401392
case "altsignerpath":
402393
altSignerPath = value;
403394
break;
@@ -510,7 +501,6 @@ public JarSigner build() {
510501
private final String tSADigestAlg;
511502
private final boolean sectionsonly; // do not "sign" the whole manifest
512503
private final boolean internalsf; // include the .SF inside the PKCS7 block
513-
private final boolean directsign;
514504

515505
@Deprecated(since="16", forRemoval=true)
516506
private final String altSignerPath;
@@ -561,9 +551,12 @@ private JarSigner(JarSigner.Builder builder) {
561551
this.altSigner = builder.altSigner;
562552
this.altSignerPath = builder.altSignerPath;
563553

564-
this.directsign = this.altSigner != null
565-
? true
566-
: builder.directsign;
554+
// altSigner cannot support modern algorithms like RSASSA-PSS and EdDSA
555+
if (altSigner != null
556+
&& !sigalg.toUpperCase(Locale.ENGLISH).contains("WITH")) {
557+
throw new IllegalArgumentException(
558+
"Customized ContentSigner is not supported for " + sigalg);
559+
}
567560
}
568561

569562
/**
@@ -666,8 +659,6 @@ public String getProperty(String key) {
666659
return Boolean.toString(sectionsonly);
667660
case "altsignerpath":
668661
return altSignerPath;
669-
case "directsign":
670-
return Boolean.toString(directsign);
671662
case "altsigner":
672663
return altSigner;
673664
default:
@@ -855,20 +846,7 @@ private void sign0(ZipFile zipFile, OutputStream os)
855846
sf.write(baos);
856847
byte[] content = baos.toByteArray();
857848

858-
// Use new method if directSign is false or it's a modern
859-
// algorithm not supported by existing ContentSigner.
860-
// Make this always true after we remove ContentSigner.
861-
boolean useNewMethod = !directsign
862-
|| !sigalg.toUpperCase(Locale.ENGLISH).contains("WITH");
863-
864-
// For newer sigalg without "with", always use the new PKCS7
865-
// generateToken method. Otherwise, use deprecated ContentSigner.
866-
if (useNewMethod) {
867-
if (altSigner != null) {
868-
throw new IllegalArgumentException(directsign
869-
? ("Customized ContentSigner is not supported for " + sigalg)
870-
: "Customized ContentSigner does not support authenticated attributes");
871-
}
849+
if (altSigner == null) {
872850
Function<byte[], PKCS9Attributes> timestamper = null;
873851
if (tsaUrl != null) {
874852
timestamper = s -> {
@@ -889,7 +867,7 @@ private void sign0(ZipFile zipFile, OutputStream os)
889867
}
890868
// We now create authAttrs in block data, so "direct == false".
891869
block = PKCS7.generateNewSignedData(sigalg, sigProvider, privateKey, certChain,
892-
content, internalsf, directsign, timestamper);
870+
content, internalsf, false, timestamper);
893871
} else {
894872
Signature signer = SignatureUtil.fromKey(sigalg, privateKey, sigProvider);
895873
signer.update(content);
@@ -901,9 +879,7 @@ private void sign0(ZipFile zipFile, OutputStream os)
901879
tSADigestAlg, signature,
902880
signer.getAlgorithm(), certChain, content, zipFile);
903881
@SuppressWarnings("removal")
904-
ContentSigner signingMechanism = (altSigner != null)
905-
? loadSigningMechanism(altSigner, altSignerPath)
906-
: new TimestampedSigner();
882+
ContentSigner signingMechanism = loadSigningMechanism(altSigner, altSignerPath);
907883
block = signingMechanism.generateSignedData(
908884
params,
909885
!internalsf,

src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ public static void main(String args[]) throws Exception {
163163
boolean debug = false; // debug
164164
boolean signManifest = true; // "sign" the whole manifest
165165
boolean externalSF = true; // leave the .SF out of the PKCS7 block
166-
boolean directSign = false; // sign SF directly or thru signedAttrs
167166
boolean strict = false; // treat warnings as error
168167
boolean revocationCheck = false; // Revocation check flag
169168

@@ -473,8 +472,6 @@ String[] parseArgs(String args[]) throws Exception {
473472
signManifest = false;
474473
} else if (collator.compare(flags, "-internalsf") ==0) {
475474
externalSF = false;
476-
} else if (collator.compare(flags, "-directsign") ==0) {
477-
directSign = true;
478475
} else if (collator.compare(flags, "-verify") ==0) {
479476
verify = true;
480477
} else if (collator.compare(flags, "-verbose") ==0) {
@@ -663,9 +660,6 @@ static void fullusage() {
663660
System.out.println(rb.getString
664661
(".internalsf.include.the.SF.file.inside.the.signature.block"));
665662
System.out.println();
666-
System.out.println(rb.getString
667-
(".directsign.sign.the.SF.file.directly.no.signerinfo.signedattributes"));
668-
System.out.println();
669663
System.out.println(rb.getString
670664
(".sectionsonly.don.t.compute.hash.of.entire.manifest"));
671665
System.out.println();
@@ -1773,7 +1767,6 @@ void signJar(String jarName, String alias)
17731767

17741768
builder.setProperty("sectionsOnly", Boolean.toString(!signManifest));
17751769
builder.setProperty("internalSF", Boolean.toString(!externalSF));
1776-
builder.setProperty("directsign", Boolean.toString(directSign));
17771770

17781771
FileOutputStream fos = null;
17791772
try {

src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ public class Resources extends java.util.ListResourceBundle {
101101
" (This option is deprecated and will be removed in a future release.)"},
102102
{".internalsf.include.the.SF.file.inside.the.signature.block",
103103
"[-internalsf] include the .SF file inside the signature block"},
104-
{".directsign.sign.the.SF.file.directly.no.signerinfo.signedattributes",
105-
"[-directsign] sign the .SF file directly (no SignerInfo signedAttributes)"},
106104
{".sectionsonly.don.t.compute.hash.of.entire.manifest",
107105
"[-sectionsonly] don't compute hash of entire manifest"},
108106
{".protected.keystore.has.protected.authentication.path",

src/jdk.jartool/share/classes/sun/security/tools/jarsigner/TimestampedSigner.java

Lines changed: 0 additions & 113 deletions
This file was deleted.

test/jdk/jdk/security/jarsigner/Properties.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,10 @@ public static void main(String[] args) throws Exception {
7575
Asserts.assertTrue(sf.startsWith("Signature-Version"));
7676

7777
// There is a SignedAttributes
78-
byte[] d0 = sign(jsb.setProperty("directsign", "false"));
78+
byte[] d0 = sign(jsb);
7979
Asserts.assertTrue(DerUtils.innerDerValue(d0, "10403")
8080
.isContextSpecific((byte)0));
8181

82-
// There is no SignedAttributes
83-
byte[] d1 = sign(jsb.setProperty("directsign", "true"));
84-
Asserts.assertFalse(DerUtils.innerDerValue(d1, "10403")
85-
.isContextSpecific((byte)0));
86-
8782
// Has a hash for the whole manifest
8883
byte[] s0 = sign(jsb.setProperty("sectionsonly", "false"));
8984
sf = new String(DerUtils.innerDerValue(s0, "10210").getOctetString());

test/jdk/jdk/security/jarsigner/Spec.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* @test
26-
* @bug 8056174 8242068
26+
* @bug 8056174 8242068 8255536
2727
* @summary Make sure JarSigner impl conforms to spec
2828
* @library /test/lib
2929
* @modules java.base/sun.security.tools.keytool
@@ -70,6 +70,9 @@ public static void main(String[] args) throws Exception {
7070
sun.security.tools.keytool.Main.main(
7171
("-keystore ks -storepass changeit -keypass changeit -dname" +
7272
" CN=DSA -alias d -genkeypair -keyalg dsa").split(" "));
73+
sun.security.tools.keytool.Main.main(
74+
("-keystore ks -storepass changeit -keypass changeit -dname" +
75+
" CN=Ed25519 -alias e -genkeypair -keyalg Ed25519").split(" "));
7376

7477
char[] pass = "changeit".toCharArray();
7578

@@ -127,8 +130,6 @@ public static void main(String[] args) throws Exception {
127130
iae(()->b1.setProperty("sectionsonly", "OK"));
128131
npe(()->b1.setProperty("sectionsonly", null));
129132
npe(()->b1.setProperty("altsigner", null));
130-
iae(()->b1.setProperty("directsign", "OK"));
131-
npe(()->b1.setProperty("directsign", null));
132133
npe(()->b1.eventHandler(null));
133134

134135
// default values
@@ -146,7 +147,6 @@ public static void main(String[] args) throws Exception {
146147
assertTrue(js2.getProperty("tsapolicyid") == null);
147148
assertTrue(js2.getProperty("internalsf").equals("false"));
148149
assertTrue(js2.getProperty("sectionsonly").equals("false"));
149-
assertTrue(js2.getProperty("directsign").equals("false"));
150150
assertTrue(js2.getProperty("altsigner") == null);
151151
uoe(()->js2.getProperty("invalid"));
152152

@@ -163,7 +163,6 @@ public static void main(String[] args) throws Exception {
163163
.setProperty("tsapolicyid", "1.2.3.4")
164164
.setProperty("internalsf", "true")
165165
.setProperty("sectionsonly", "true")
166-
.setProperty("directsign", "true")
167166
.setProperty("altsigner", "MyContentSigner")
168167
.eventHandler(myeh);
169168
JarSigner js3 = b3.build();
@@ -176,7 +175,6 @@ public static void main(String[] args) throws Exception {
176175
assertTrue(js3.getProperty("tsapolicyid").equals("1.2.3.4"));
177176
assertTrue(js3.getProperty("internalsf").equals("true"));
178177
assertTrue(js3.getProperty("sectionsonly").equals("true"));
179-
assertTrue(js3.getProperty("directsign").equals("true"));
180178
assertTrue(js3.getProperty("altsigner").equals("MyContentSigner"));
181179
assertTrue(js3.getProperty("altsignerpath") == null);
182180

@@ -208,6 +206,14 @@ public static void main(String[] args) throws Exception {
208206
assertTrue(JarSigner.Builder
209207
.getDefaultSignatureAlgorithm(kpg.generateKeyPair().getPrivate())
210208
.equals("SHA512withECDSA"));
209+
210+
// altsigner does not support modern algorithms
211+
JarSigner.Builder b4 = new JarSigner.Builder(
212+
(PrivateKey)ks.getKey("e", pass),
213+
CertificateFactory.getInstance("X.509")
214+
.generateCertPath(Arrays.asList(ks.getCertificateChain("e"))));
215+
b4.setProperty("altsigner", "MyContentSigner");
216+
iae(() -> b4.build());
211217
}
212218

213219
interface RunnableWithException {

0 commit comments

Comments
 (0)