author | weijun |
Fri, 15 Nov 2019 09:06:58 +0800 | |
changeset 59104 | 046e4024e55a |
parent 58902 | 197238c30630 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
26 |
package sun.security.tools.keytool; |
2 | 27 |
|
28 |
import java.io.*; |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
29 |
import java.nio.file.Files; |
49285
4d2e3f5abb48
8194746: (fs) Add equivalents of Paths.get to Path interface
bpb
parents:
48608
diff
changeset
|
30 |
import java.nio.file.Path; |
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
31 |
import java.security.AlgorithmParameters; |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
32 |
import java.security.CodeSigner; |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
33 |
import java.security.CryptoPrimitive; |
2 | 34 |
import java.security.KeyStore; |
35 |
import java.security.KeyStoreException; |
|
36 |
import java.security.MessageDigest; |
|
37 |
import java.security.Key; |
|
38 |
import java.security.PublicKey; |
|
39 |
import java.security.PrivateKey; |
|
54346
b7ebff3e4e69
8221257: Improve serial number generation mechanism for keytool -gencert
weijun
parents:
53740
diff
changeset
|
40 |
import java.security.SecureRandom; |
2 | 41 |
import java.security.Signature; |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
42 |
import java.security.Timestamp; |
2 | 43 |
import java.security.UnrecoverableEntryException; |
44 |
import java.security.UnrecoverableKeyException; |
|
45 |
import java.security.Principal; |
|
46 |
import java.security.cert.Certificate; |
|
47 |
import java.security.cert.CertificateFactory; |
|
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
48 |
import java.security.cert.CertStoreException; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
49 |
import java.security.cert.CRL; |
2 | 50 |
import java.security.cert.X509Certificate; |
51 |
import java.security.cert.CertificateException; |
|
30506
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
52 |
import java.security.cert.URICertStoreParameters; |
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
53 |
|
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
54 |
|
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
55 |
import java.security.interfaces.ECKey; |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
56 |
import java.security.spec.AlgorithmParameterSpec; |
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
57 |
import java.security.spec.ECParameterSpec; |
2 | 58 |
import java.text.Collator; |
59 |
import java.text.MessageFormat; |
|
60 |
import java.util.*; |
|
58902
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
61 |
import java.util.function.BiFunction; |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
62 |
import java.util.jar.JarEntry; |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
63 |
import java.util.jar.JarFile; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
64 |
import java.math.BigInteger; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
65 |
import java.net.URI; |
2 | 66 |
import java.net.URL; |
67 |
import java.net.URLClassLoader; |
|
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
68 |
import java.security.cert.CertStore; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
69 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
70 |
import java.security.cert.X509CRL; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
71 |
import java.security.cert.X509CRLEntry; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
72 |
import java.security.cert.X509CRLSelector; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
73 |
import javax.security.auth.x500.X500Principal; |
16020
b57c48f16179
8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents:
14421
diff
changeset
|
74 |
import java.util.Base64; |
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
75 |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
76 |
import sun.security.pkcs12.PKCS12KeyStore; |
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
77 |
import sun.security.util.ECKeySizeParameterSpec; |
27038
64cb6608f8a6
8029659: Keytool, print key algorithm of certificate or key entry
weijun
parents:
25859
diff
changeset
|
78 |
import sun.security.util.KeyUtil; |
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
79 |
import sun.security.util.NamedCurve; |
2 | 80 |
import sun.security.util.ObjectIdentifier; |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
81 |
import sun.security.pkcs10.PKCS10; |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
82 |
import sun.security.pkcs10.PKCS10Attribute; |
2 | 83 |
import sun.security.provider.X509Factory; |
30506
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
84 |
import sun.security.provider.certpath.ssl.SSLServerCertStore; |
2 | 85 |
import sun.security.util.Password; |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
86 |
import sun.security.util.SecurityProperties; |
47421
f9e03aef3a49
8181048: Refactor existing providers to refer to the same constants for default values for key length
valeriep
parents:
47420
diff
changeset
|
87 |
import sun.security.util.SecurityProviderConstants; |
54483
ac20c3bdc55d
8216039: TLS with BC and RSASSA-PSS breaks ECDHServerKeyExchange
valeriep
parents:
54421
diff
changeset
|
88 |
import sun.security.util.SignatureUtil; |
2 | 89 |
import javax.crypto.KeyGenerator; |
90 |
import javax.crypto.SecretKey; |
|
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
91 |
import javax.crypto.SecretKeyFactory; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
92 |
import javax.crypto.spec.PBEKeySpec; |
2 | 93 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
94 |
import sun.security.pkcs.PKCS9Attribute; |
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
95 |
import sun.security.tools.KeyStoreUtil; |
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
96 |
import sun.security.tools.PathList; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
97 |
import sun.security.util.DerValue; |
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
98 |
import sun.security.util.Pem; |
2 | 99 |
import sun.security.x509.*; |
100 |
||
101 |
import static java.security.KeyStore.*; |
|
41960
916bb3d29d7b
8168882: keytool doesn't print certificate info if disabled algorithm was used for signing a jar
asmotrak
parents:
40393
diff
changeset
|
102 |
import java.security.Security; |
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
103 |
import static sun.security.tools.keytool.Main.Command.*; |
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
104 |
import static sun.security.tools.keytool.Main.Option.*; |
41960
916bb3d29d7b
8168882: keytool doesn't print certificate info if disabled algorithm was used for signing a jar
asmotrak
parents:
40393
diff
changeset
|
105 |
import sun.security.util.DisabledAlgorithmConstraints; |
2 | 106 |
|
107 |
/** |
|
108 |
* This tool manages keystores. |
|
109 |
* |
|
110 |
* @author Jan Luehe |
|
111 |
* |
|
112 |
* |
|
113 |
* @see java.security.KeyStore |
|
114 |
* @see sun.security.provider.KeyProtector |
|
115 |
* @see sun.security.provider.JavaKeyStore |
|
116 |
* |
|
117 |
* @since 1.2 |
|
118 |
*/ |
|
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
119 |
public final class Main { |
2 | 120 |
|
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
121 |
private static final byte[] CRLF = new byte[] {'\r', '\n'}; |
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
122 |
|
2 | 123 |
private boolean debug = false; |
3948 | 124 |
private Command command = null; |
2 | 125 |
private String sigAlgName = null; |
126 |
private String keyAlgName = null; |
|
127 |
private boolean verbose = false; |
|
128 |
private int keysize = -1; |
|
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
129 |
private String groupName = null; |
2 | 130 |
private boolean rfc = false; |
131 |
private long validity = (long)90; |
|
132 |
private String alias = null; |
|
133 |
private String dname = null; |
|
134 |
private String dest = null; |
|
135 |
private String filename = null; |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
136 |
private String infilename = null; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
137 |
private String outfilename = null; |
2 | 138 |
private String srcksfname = null; |
139 |
||
140 |
// User-specified providers are added before any command is called. |
|
141 |
// However, they are not removed before the end of the main() method. |
|
142 |
// If you're calling KeyTool.main() directly in your own Java program, |
|
143 |
// please programtically add any providers you need and do not specify |
|
144 |
// them through the command line. |
|
145 |
||
146 |
private Set<Pair <String, String>> providers = null; |
|
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
147 |
private Set<Pair <String, String>> providerClasses = null; |
2 | 148 |
private String storetype = null; |
149 |
private String srcProviderName = null; |
|
150 |
private String providerName = null; |
|
151 |
private String pathlist = null; |
|
152 |
private char[] storePass = null; |
|
153 |
private char[] storePassNew = null; |
|
154 |
private char[] keyPass = null; |
|
155 |
private char[] keyPassNew = null; |
|
156 |
private char[] newPass = null; |
|
157 |
private char[] destKeyPass = null; |
|
158 |
private char[] srckeyPass = null; |
|
159 |
private String ksfname = null; |
|
160 |
private File ksfile = null; |
|
161 |
private InputStream ksStream = null; // keystore stream |
|
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
162 |
private String sslserver = null; |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
163 |
private String jarfile = null; |
2 | 164 |
private KeyStore keyStore = null; |
165 |
private boolean token = false; |
|
166 |
private boolean nullStream = false; |
|
167 |
private boolean kssave = false; |
|
168 |
private boolean noprompt = false; |
|
169 |
private boolean trustcacerts = false; |
|
170 |
private boolean protectedPath = false; |
|
171 |
private boolean srcprotectedPath = false; |
|
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
172 |
private boolean cacerts = false; |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
173 |
private boolean nowarn = false; |
2 | 174 |
private KeyStore caks = null; // "cacerts" keystore |
175 |
private char[] srcstorePass = null; |
|
176 |
private String srcstoretype = null; |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
177 |
private Set<char[]> passwords = new HashSet<>(); |
2 | 178 |
private String startDate = null; |
179 |
||
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
180 |
private boolean tlsInfo = false; |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
181 |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
182 |
private List<String> ids = new ArrayList<>(); // used in GENCRL |
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
183 |
private List<String> v3ext = new ArrayList<>(); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
184 |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
185 |
// In-place importkeystore is special. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
186 |
// A backup is needed, and no need to prompt for deststorepass. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
187 |
private boolean inplaceImport = false; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
188 |
private String inplaceBackupName = null; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
189 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
190 |
// Warnings on weak algorithms etc |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
191 |
private List<String> weakWarnings = new ArrayList<>(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
192 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
193 |
private static final DisabledAlgorithmConstraints DISABLED_CHECK = |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
194 |
new DisabledAlgorithmConstraints( |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
195 |
DisabledAlgorithmConstraints.PROPERTY_CERTPATH_DISABLED_ALGS); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
196 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
197 |
private static final Set<CryptoPrimitive> SIG_PRIMITIVE_SET = Collections |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
198 |
.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE)); |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
199 |
private boolean isPasswordlessKeyStore = false; |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
200 |
|
3948 | 201 |
enum Command { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
202 |
CERTREQ("Generates.a.certificate.request", |
4918
13ed75166139
6925639: keytool -genkeypair -help missing dname option
weijun
parents:
4819
diff
changeset
|
203 |
ALIAS, SIGALG, FILEOUT, KEYPASS, KEYSTORE, DNAME, |
45475
19aefb1b6fc6
8181501: KeyTool help does not show -ext for -certreq
weijun
parents:
44597
diff
changeset
|
204 |
EXT, STOREPASS, STORETYPE, PROVIDERNAME, ADDPROVIDER, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
205 |
PROVIDERCLASS, PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
206 |
CHANGEALIAS("Changes.an.entry.s.alias", |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
207 |
ALIAS, DESTALIAS, KEYPASS, KEYSTORE, CACERTS, STOREPASS, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
208 |
STORETYPE, PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
209 |
PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
210 |
DELETE("Deletes.an.entry", |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
211 |
ALIAS, KEYSTORE, CACERTS, STOREPASS, STORETYPE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
212 |
PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
213 |
PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
214 |
EXPORTCERT("Exports.certificate", |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
215 |
RFC, ALIAS, FILEOUT, KEYSTORE, CACERTS, STOREPASS, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
216 |
STORETYPE, PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
217 |
PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
218 |
GENKEYPAIR("Generates.a.key.pair", |
53740
54a8b7673afc
8218888: keytool -genkeypair should not have the -destalias option
weijun
parents:
53398
diff
changeset
|
219 |
ALIAS, KEYALG, KEYSIZE, CURVENAME, SIGALG, DNAME, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
220 |
STARTDATE, EXT, VALIDITY, KEYPASS, KEYSTORE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
221 |
STOREPASS, STORETYPE, PROVIDERNAME, ADDPROVIDER, |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
222 |
PROVIDERCLASS, PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
223 |
GENSECKEY("Generates.a.secret.key", |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
224 |
ALIAS, KEYPASS, KEYALG, KEYSIZE, KEYSTORE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
225 |
STOREPASS, STORETYPE, PROVIDERNAME, ADDPROVIDER, |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
226 |
PROVIDERCLASS, PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
227 |
GENCERT("Generates.certificate.from.a.certificate.request", |
4918
13ed75166139
6925639: keytool -genkeypair -help missing dname option
weijun
parents:
4819
diff
changeset
|
228 |
RFC, INFILE, OUTFILE, ALIAS, SIGALG, DNAME, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
229 |
STARTDATE, EXT, VALIDITY, KEYPASS, KEYSTORE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
230 |
STOREPASS, STORETYPE, PROVIDERNAME, ADDPROVIDER, |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
231 |
PROVIDERCLASS, PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
232 |
IMPORTCERT("Imports.a.certificate.or.a.certificate.chain", |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
233 |
NOPROMPT, TRUSTCACERTS, PROTECTED, ALIAS, FILEIN, |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
234 |
KEYPASS, KEYSTORE, CACERTS, STOREPASS, STORETYPE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
235 |
PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
236 |
PROVIDERPATH, V), |
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
237 |
IMPORTPASS("Imports.a.password", |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
238 |
ALIAS, KEYPASS, KEYALG, KEYSIZE, KEYSTORE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
239 |
STOREPASS, STORETYPE, PROVIDERNAME, ADDPROVIDER, |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
240 |
PROVIDERCLASS, PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
241 |
IMPORTKEYSTORE("Imports.one.or.all.entries.from.another.keystore", |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
242 |
SRCKEYSTORE, DESTKEYSTORE, SRCSTORETYPE, |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
243 |
DESTSTORETYPE, SRCSTOREPASS, DESTSTOREPASS, |
38855
4e587173e37e
8151836: keytool -importkeystore -help does not list option -destprotected
weijun
parents:
38439
diff
changeset
|
244 |
SRCPROTECTED, DESTPROTECTED, SRCPROVIDERNAME, DESTPROVIDERNAME, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
245 |
SRCALIAS, DESTALIAS, SRCKEYPASS, DESTKEYPASS, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
246 |
NOPROMPT, ADDPROVIDER, PROVIDERCLASS, PROVIDERPATH, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
247 |
V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
248 |
KEYPASSWD("Changes.the.key.password.of.an.entry", |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
249 |
ALIAS, KEYPASS, NEW, KEYSTORE, STOREPASS, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
250 |
STORETYPE, PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
251 |
PROVIDERPATH, V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
252 |
LIST("Lists.entries.in.a.keystore", |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
253 |
RFC, ALIAS, KEYSTORE, CACERTS, STOREPASS, STORETYPE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
254 |
PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
255 |
PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
256 |
PRINTCERT("Prints.the.content.of.a.certificate", |
51373
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
257 |
RFC, FILEIN, SSLSERVER, JARFILE, |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
258 |
PROVIDERNAME, ADDPROVIDER, PROVIDERCLASS, |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
259 |
PROVIDERPATH, V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
260 |
PRINTCERTREQ("Prints.the.content.of.a.certificate.request", |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
261 |
FILEIN, V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
262 |
PRINTCRL("Prints.the.content.of.a.CRL.file", |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
263 |
FILEIN, V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
264 |
STOREPASSWD("Changes.the.store.password.of.a.keystore", |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
265 |
NEW, KEYSTORE, CACERTS, STOREPASS, STORETYPE, PROVIDERNAME, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
266 |
ADDPROVIDER, PROVIDERCLASS, PROVIDERPATH, V), |
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
267 |
SHOWINFO("showinfo.command.help", |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
268 |
TLS, V), |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
269 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
270 |
// Undocumented start here, KEYCLONE is used a marker in -help; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
271 |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
272 |
KEYCLONE("Clones.a.key.entry", |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
273 |
ALIAS, DESTALIAS, KEYPASS, NEW, STORETYPE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
274 |
KEYSTORE, STOREPASS, PROVIDERNAME, ADDPROVIDER, |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
275 |
PROVIDERCLASS, PROVIDERPATH, V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
276 |
SELFCERT("Generates.a.self.signed.certificate", |
45475
19aefb1b6fc6
8181501: KeyTool help does not show -ext for -certreq
weijun
parents:
44597
diff
changeset
|
277 |
ALIAS, SIGALG, DNAME, STARTDATE, EXT, VALIDITY, KEYPASS, |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
278 |
STORETYPE, KEYSTORE, STOREPASS, PROVIDERNAME, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
279 |
ADDPROVIDER, PROVIDERCLASS, PROVIDERPATH, V), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
280 |
GENCRL("Generates.CRL", |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
281 |
RFC, FILEOUT, ID, |
45475
19aefb1b6fc6
8181501: KeyTool help does not show -ext for -certreq
weijun
parents:
44597
diff
changeset
|
282 |
ALIAS, SIGALG, KEYPASS, KEYSTORE, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
283 |
STOREPASS, STORETYPE, PROVIDERNAME, ADDPROVIDER, |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
284 |
PROVIDERCLASS, PROVIDERPATH, V, PROTECTED), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
285 |
IDENTITYDB("Imports.entries.from.a.JDK.1.1.x.style.identity.database", |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
286 |
FILEIN, STORETYPE, KEYSTORE, STOREPASS, PROVIDERNAME, |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
287 |
ADDPROVIDER, PROVIDERCLASS, PROVIDERPATH, V); |
3948 | 288 |
|
289 |
final String description; |
|
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
290 |
final Option[] options; |
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
291 |
final String name; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
292 |
|
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
293 |
String altName; // "genkey" is altName for "genkeypair" |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
294 |
|
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
295 |
Command(String d, Option... o) { |
3948 | 296 |
description = d; |
297 |
options = o; |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
298 |
name = "-" + name().toLowerCase(Locale.ENGLISH); |
3948 | 299 |
} |
300 |
@Override |
|
301 |
public String toString() { |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
302 |
return name; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
303 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
304 |
public String getAltName() { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
305 |
return altName; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
306 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
307 |
public void setAltName(String altName) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
308 |
this.altName = altName; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
309 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
310 |
public static Command getCommand(String cmd) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
311 |
for (Command c: Command.values()) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
312 |
if (collator.compare(cmd, c.name) == 0 |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
313 |
|| (c.altName != null |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
314 |
&& collator.compare(cmd, c.altName) == 0)) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
315 |
return c; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
316 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
317 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
318 |
return null; |
3948 | 319 |
} |
320 |
}; |
|
321 |
||
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
322 |
static { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
323 |
Command.GENKEYPAIR.setAltName("-genkey"); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
324 |
Command.IMPORTCERT.setAltName("-import"); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
325 |
Command.EXPORTCERT.setAltName("-export"); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
326 |
Command.IMPORTPASS.setAltName("-importpassword"); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
327 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
328 |
|
45839
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
329 |
// If an option is allowed multiple times, remember to record it |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
330 |
// in the optionsSet.contains() block in parseArgs(). |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
331 |
enum Option { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
332 |
ALIAS("alias", "<alias>", "alias.name.of.the.entry.to.process"), |
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
333 |
CURVENAME("groupname", "<name>", "groupname.option.help"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
334 |
DESTALIAS("destalias", "<alias>", "destination.alias"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
335 |
DESTKEYPASS("destkeypass", "<arg>", "destination.key.password"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
336 |
DESTKEYSTORE("destkeystore", "<keystore>", "destination.keystore.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
337 |
DESTPROTECTED("destprotected", null, "destination.keystore.password.protected"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
338 |
DESTPROVIDERNAME("destprovidername", "<name>", "destination.keystore.provider.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
339 |
DESTSTOREPASS("deststorepass", "<arg>", "destination.keystore.password"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
340 |
DESTSTORETYPE("deststoretype", "<type>", "destination.keystore.type"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
341 |
DNAME("dname", "<name>", "distinguished.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
342 |
EXT("ext", "<value>", "X.509.extension"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
343 |
FILEOUT("file", "<file>", "output.file.name"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
344 |
FILEIN("file", "<file>", "input.file.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
345 |
ID("id", "<id:reason>", "Serial.ID.of.cert.to.revoke"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
346 |
INFILE("infile", "<file>", "input.file.name"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
347 |
KEYALG("keyalg", "<alg>", "key.algorithm.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
348 |
KEYPASS("keypass", "<arg>", "key.password"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
349 |
KEYSIZE("keysize", "<size>", "key.bit.size"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
350 |
KEYSTORE("keystore", "<keystore>", "keystore.name"), |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
351 |
CACERTS("cacerts", null, "access.the.cacerts.keystore"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
352 |
NEW("new", "<arg>", "new.password"), |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
353 |
NOPROMPT("noprompt", null, "do.not.prompt"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
354 |
OUTFILE("outfile", "<file>", "output.file.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
355 |
PROTECTED("protected", null, "password.through.protected.mechanism"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
356 |
PROVIDERCLASS("providerclass", "<class>\n[-providerarg <arg>]", "provider.class.option"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
357 |
ADDPROVIDER("addprovider", "<name>\n[-providerarg <arg>]", "addprovider.option"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
358 |
PROVIDERNAME("providername", "<name>", "provider.name"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
359 |
PROVIDERPATH("providerpath", "<list>", "provider.classpath"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
360 |
RFC("rfc", null, "output.in.RFC.style"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
361 |
SIGALG("sigalg", "<alg>", "signature.algorithm.name"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
362 |
SRCALIAS("srcalias", "<alias>", "source.alias"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
363 |
SRCKEYPASS("srckeypass", "<arg>", "source.key.password"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
364 |
SRCKEYSTORE("srckeystore", "<keystore>", "source.keystore.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
365 |
SRCPROTECTED("srcprotected", null, "source.keystore.password.protected"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
366 |
SRCPROVIDERNAME("srcprovidername", "<name>", "source.keystore.provider.name"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
367 |
SRCSTOREPASS("srcstorepass", "<arg>", "source.keystore.password"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
368 |
SRCSTORETYPE("srcstoretype", "<type>", "source.keystore.type"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
369 |
SSLSERVER("sslserver", "<server[:port]>", "SSL.server.host.and.port"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
370 |
JARFILE("jarfile", "<file>", "signed.jar.file"), |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
371 |
STARTDATE("startdate", "<date>", "certificate.validity.start.date.time"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
372 |
STOREPASS("storepass", "<arg>", "keystore.password"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
373 |
STORETYPE("storetype", "<type>", "keystore.type"), |
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
374 |
TLS("tls", null, "tls.option.help"), |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
375 |
TRUSTCACERTS("trustcacerts", null, "trust.certificates.from.cacerts"), |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
376 |
V("v", null, "verbose.output"), |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
377 |
VALIDITY("validity", "<days>", "validity.number.of.days"); |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
378 |
|
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
379 |
final String name, arg, description; |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
380 |
Option(String name, String arg, String description) { |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
381 |
this.name = name; |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
382 |
this.arg = arg; |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
383 |
this.description = description; |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
384 |
} |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
385 |
@Override |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
386 |
public String toString() { |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
387 |
return "-" + name; |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
388 |
} |
3948 | 389 |
}; |
2 | 390 |
|
391 |
private static final String NONE = "NONE"; |
|
392 |
private static final String P11KEYSTORE = "PKCS11"; |
|
393 |
private static final String P12KEYSTORE = "PKCS12"; |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
394 |
private static final String keyAlias = "mykey"; |
2 | 395 |
|
396 |
// for i18n |
|
397 |
private static final java.util.ResourceBundle rb = |
|
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
398 |
java.util.ResourceBundle.getBundle( |
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
399 |
"sun.security.tools.keytool.Resources"); |
2 | 400 |
private static final Collator collator = Collator.getInstance(); |
401 |
static { |
|
402 |
// this is for case insensitive string comparisons |
|
403 |
collator.setStrength(Collator.PRIMARY); |
|
404 |
}; |
|
405 |
||
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
406 |
private Main() { } |
2 | 407 |
|
408 |
public static void main(String[] args) throws Exception { |
|
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
409 |
Main kt = new Main(); |
2 | 410 |
kt.run(args, System.out); |
411 |
} |
|
412 |
||
413 |
private void run(String[] args, PrintStream out) throws Exception { |
|
414 |
try { |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
415 |
args = parseArgs(args); |
3948 | 416 |
if (command != null) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
417 |
doCommands(out); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
418 |
} |
2 | 419 |
} catch (Exception e) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
420 |
System.out.println(rb.getString("keytool.error.") + e); |
2 | 421 |
if (verbose) { |
422 |
e.printStackTrace(System.out); |
|
423 |
} |
|
424 |
if (!debug) { |
|
425 |
System.exit(1); |
|
426 |
} else { |
|
427 |
throw e; |
|
428 |
} |
|
429 |
} finally { |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
430 |
printWeakWarnings(false); |
2 | 431 |
for (char[] pass : passwords) { |
432 |
if (pass != null) { |
|
433 |
Arrays.fill(pass, ' '); |
|
434 |
pass = null; |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
if (ksStream != null) { |
|
439 |
ksStream.close(); |
|
440 |
} |
|
441 |
} |
|
442 |
} |
|
443 |
||
444 |
/** |
|
445 |
* Parse command line arguments. |
|
446 |
*/ |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
447 |
String[] parseArgs(String[] args) throws Exception { |
2 | 448 |
|
449 |
int i=0; |
|
3948 | 450 |
boolean help = args.length == 0; |
2 | 451 |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
452 |
String confFile = null; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
453 |
|
45839
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
454 |
// Records all commands and options set. Used to check dups. |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
455 |
Set<String> optionsSet = new HashSet<>(); |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
456 |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
457 |
for (i=0; i < args.length; i++) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
458 |
String flags = args[i]; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
459 |
if (flags.startsWith("-")) { |
45839
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
460 |
String lowerFlags = flags.toLowerCase(Locale.ROOT); |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
461 |
if (optionsSet.contains(lowerFlags)) { |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
462 |
switch (lowerFlags) { |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
463 |
case "-ext": |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
464 |
case "-id": |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
465 |
case "-provider": |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
466 |
case "-addprovider": |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
467 |
case "-providerclass": |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
468 |
case "-providerarg": |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
469 |
// These options are allowed multiple times |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
470 |
break; |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
471 |
default: |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
472 |
weakWarnings.add(String.format( |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
473 |
rb.getString("option.1.set.twice"), |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
474 |
lowerFlags)); |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
475 |
} |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
476 |
} else { |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
477 |
optionsSet.add(lowerFlags); |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
478 |
} |
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
479 |
if (collator.compare(flags, "-conf") == 0) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
480 |
if (i == args.length - 1) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
481 |
errorNeedArgument(flags); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
482 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
483 |
confFile = args[++i]; |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
484 |
} else { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
485 |
Command c = Command.getCommand(flags); |
45839
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
486 |
if (c != null) { |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
487 |
if (command == null) { |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
488 |
command = c; |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
489 |
} else { |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
490 |
throw new Exception(String.format( |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
491 |
rb.getString("multiple.commands.1.2"), |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
492 |
command.name, c.name)); |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
493 |
} |
6df5e24443fc
8183509: keytool should not allow multiple commands
weijun
parents:
45475
diff
changeset
|
494 |
} |
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
495 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
496 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
497 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
498 |
|
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
499 |
if (confFile != null && command != null) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
500 |
args = KeyStoreUtil.expandArgs("keytool", confFile, |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
501 |
command.toString(), |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
502 |
command.getAltName(), args); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
503 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
504 |
|
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
505 |
debug = Arrays.stream(args).anyMatch( |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
506 |
x -> collator.compare(x, "-debug") == 0); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
507 |
|
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
508 |
if (debug) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
509 |
// No need to localize debug output |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
510 |
System.out.println("Command line args: " + |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
511 |
Arrays.toString(args)); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
512 |
} |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
513 |
|
2 | 514 |
for (i=0; (i < args.length) && args[i].startsWith("-"); i++) { |
515 |
||
516 |
String flags = args[i]; |
|
3948 | 517 |
|
518 |
// Check if the last option needs an arg |
|
519 |
if (i == args.length - 1) { |
|
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
520 |
for (Option option: Option.values()) { |
3948 | 521 |
// Only options with an arg need to be checked |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
522 |
if (collator.compare(flags, option.toString()) == 0) { |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
523 |
if (option.arg != null) errorNeedArgument(flags); |
3948 | 524 |
break; |
525 |
} |
|
526 |
} |
|
527 |
} |
|
528 |
||
2 | 529 |
/* |
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
530 |
* Check modifiers |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
531 |
*/ |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
532 |
String modifier = null; |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
533 |
int pos = flags.indexOf(':'); |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
534 |
if (pos > 0) { |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
535 |
modifier = flags.substring(pos+1); |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
536 |
flags = flags.substring(0, pos); |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
537 |
} |
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
538 |
|
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
539 |
/* |
2 | 540 |
* command modes |
541 |
*/ |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
542 |
Command c = Command.getCommand(flags); |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
543 |
|
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
544 |
if (c != null) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
545 |
command = c; |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
546 |
} else if (collator.compare(flags, "--help") == 0 || |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
547 |
collator.compare(flags, "-h") == 0 || |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
548 |
collator.compare(flags, "-?") == 0 || |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
549 |
// -help: legacy. |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
550 |
collator.compare(flags, "-help") == 0) { |
3948 | 551 |
help = true; |
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
552 |
} else if (collator.compare(flags, "-conf") == 0) { |
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
553 |
i++; |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
554 |
} else if (collator.compare(flags, "-nowarn") == 0) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
555 |
nowarn = true; |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
556 |
} else if (collator.compare(flags, "-keystore") == 0) { |
3948 | 557 |
ksfname = args[++i]; |
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
558 |
if (new File(ksfname).getCanonicalPath().equals( |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
559 |
new File(KeyStoreUtil.getCacerts()).getCanonicalPath())) { |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
560 |
System.err.println(rb.getString("warning.cacerts.option")); |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
561 |
} |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
562 |
} else if (collator.compare(flags, "-destkeystore") == 0) { |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
563 |
ksfname = args[++i]; |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
564 |
} else if (collator.compare(flags, "-cacerts") == 0) { |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
565 |
cacerts = true; |
2 | 566 |
} else if (collator.compare(flags, "-storepass") == 0 || |
567 |
collator.compare(flags, "-deststorepass") == 0) { |
|
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
568 |
storePass = getPass(modifier, args[++i]); |
2 | 569 |
passwords.add(storePass); |
570 |
} else if (collator.compare(flags, "-storetype") == 0 || |
|
571 |
collator.compare(flags, "-deststoretype") == 0) { |
|
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
572 |
storetype = KeyStoreUtil.niceStoreTypeName(args[++i]); |
2 | 573 |
} else if (collator.compare(flags, "-srcstorepass") == 0) { |
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
574 |
srcstorePass = getPass(modifier, args[++i]); |
2 | 575 |
passwords.add(srcstorePass); |
576 |
} else if (collator.compare(flags, "-srcstoretype") == 0) { |
|
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
577 |
srcstoretype = KeyStoreUtil.niceStoreTypeName(args[++i]); |
2 | 578 |
} else if (collator.compare(flags, "-srckeypass") == 0) { |
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
579 |
srckeyPass = getPass(modifier, args[++i]); |
2 | 580 |
passwords.add(srckeyPass); |
581 |
} else if (collator.compare(flags, "-srcprovidername") == 0) { |
|
3948 | 582 |
srcProviderName = args[++i]; |
2 | 583 |
} else if (collator.compare(flags, "-providername") == 0 || |
584 |
collator.compare(flags, "-destprovidername") == 0) { |
|
3948 | 585 |
providerName = args[++i]; |
2 | 586 |
} else if (collator.compare(flags, "-providerpath") == 0) { |
3948 | 587 |
pathlist = args[++i]; |
2 | 588 |
} else if (collator.compare(flags, "-keypass") == 0) { |
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
589 |
keyPass = getPass(modifier, args[++i]); |
2 | 590 |
passwords.add(keyPass); |
591 |
} else if (collator.compare(flags, "-new") == 0) { |
|
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
592 |
newPass = getPass(modifier, args[++i]); |
2 | 593 |
passwords.add(newPass); |
594 |
} else if (collator.compare(flags, "-destkeypass") == 0) { |
|
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
595 |
destKeyPass = getPass(modifier, args[++i]); |
2 | 596 |
passwords.add(destKeyPass); |
597 |
} else if (collator.compare(flags, "-alias") == 0 || |
|
598 |
collator.compare(flags, "-srcalias") == 0) { |
|
3948 | 599 |
alias = args[++i]; |
2 | 600 |
} else if (collator.compare(flags, "-dest") == 0 || |
601 |
collator.compare(flags, "-destalias") == 0) { |
|
3948 | 602 |
dest = args[++i]; |
2 | 603 |
} else if (collator.compare(flags, "-dname") == 0) { |
3948 | 604 |
dname = args[++i]; |
2 | 605 |
} else if (collator.compare(flags, "-keysize") == 0) { |
3948 | 606 |
keysize = Integer.parseInt(args[++i]); |
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
607 |
} else if (collator.compare(flags, "-groupname") == 0) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
608 |
groupName = args[++i]; |
2 | 609 |
} else if (collator.compare(flags, "-keyalg") == 0) { |
3948 | 610 |
keyAlgName = args[++i]; |
2 | 611 |
} else if (collator.compare(flags, "-sigalg") == 0) { |
3948 | 612 |
sigAlgName = args[++i]; |
2 | 613 |
} else if (collator.compare(flags, "-startdate") == 0) { |
3948 | 614 |
startDate = args[++i]; |
2 | 615 |
} else if (collator.compare(flags, "-validity") == 0) { |
3948 | 616 |
validity = Long.parseLong(args[++i]); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
617 |
} else if (collator.compare(flags, "-ext") == 0) { |
3948 | 618 |
v3ext.add(args[++i]); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
619 |
} else if (collator.compare(flags, "-id") == 0) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
620 |
ids.add(args[++i]); |
2 | 621 |
} else if (collator.compare(flags, "-file") == 0) { |
3948 | 622 |
filename = args[++i]; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
623 |
} else if (collator.compare(flags, "-infile") == 0) { |
3948 | 624 |
infilename = args[++i]; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
625 |
} else if (collator.compare(flags, "-outfile") == 0) { |
3948 | 626 |
outfilename = args[++i]; |
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
627 |
} else if (collator.compare(flags, "-sslserver") == 0) { |
3948 | 628 |
sslserver = args[++i]; |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
629 |
} else if (collator.compare(flags, "-jarfile") == 0) { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
630 |
jarfile = args[++i]; |
2 | 631 |
} else if (collator.compare(flags, "-srckeystore") == 0) { |
3948 | 632 |
srcksfname = args[++i]; |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
633 |
} else if (collator.compare(flags, "-provider") == 0 || |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
634 |
collator.compare(flags, "-providerclass") == 0) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
635 |
if (providerClasses == null) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
636 |
providerClasses = new HashSet<Pair <String, String>> (3); |
2 | 637 |
} |
3948 | 638 |
String providerClass = args[++i]; |
2 | 639 |
String providerArg = null; |
640 |
||
641 |
if (args.length > (i+1)) { |
|
642 |
flags = args[i+1]; |
|
643 |
if (collator.compare(flags, "-providerarg") == 0) { |
|
644 |
if (args.length == (i+2)) errorNeedArgument(flags); |
|
645 |
providerArg = args[i+2]; |
|
646 |
i += 2; |
|
647 |
} |
|
648 |
} |
|
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
649 |
providerClasses.add( |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
650 |
Pair.of(providerClass, providerArg)); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
651 |
} else if (collator.compare(flags, "-addprovider") == 0) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
652 |
if (providers == null) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
653 |
providers = new HashSet<Pair <String, String>> (3); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
654 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
655 |
String provider = args[++i]; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
656 |
String providerArg = null; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
657 |
|
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
658 |
if (args.length > (i+1)) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
659 |
flags = args[i+1]; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
660 |
if (collator.compare(flags, "-providerarg") == 0) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
661 |
if (args.length == (i+2)) errorNeedArgument(flags); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
662 |
providerArg = args[i+2]; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
663 |
i += 2; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
664 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
665 |
} |
2 | 666 |
providers.add( |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
667 |
Pair.of(provider, providerArg)); |
2 | 668 |
} |
669 |
||
670 |
/* |
|
671 |
* options |
|
672 |
*/ |
|
673 |
else if (collator.compare(flags, "-v") == 0) { |
|
674 |
verbose = true; |
|
675 |
} else if (collator.compare(flags, "-debug") == 0) { |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
676 |
// Already processed |
2 | 677 |
} else if (collator.compare(flags, "-rfc") == 0) { |
678 |
rfc = true; |
|
679 |
} else if (collator.compare(flags, "-noprompt") == 0) { |
|
680 |
noprompt = true; |
|
681 |
} else if (collator.compare(flags, "-trustcacerts") == 0) { |
|
682 |
trustcacerts = true; |
|
683 |
} else if (collator.compare(flags, "-protected") == 0 || |
|
684 |
collator.compare(flags, "-destprotected") == 0) { |
|
685 |
protectedPath = true; |
|
686 |
} else if (collator.compare(flags, "-srcprotected") == 0) { |
|
687 |
srcprotectedPath = true; |
|
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
688 |
} else if (collator.compare(flags, "-tls") == 0) { |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
689 |
tlsInfo = true; |
2 | 690 |
} else { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
691 |
System.err.println(rb.getString("Illegal.option.") + flags); |
2 | 692 |
tinyHelp(); |
693 |
} |
|
694 |
} |
|
695 |
||
696 |
if (i<args.length) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
697 |
System.err.println(rb.getString("Illegal.option.") + args[i]); |
2 | 698 |
tinyHelp(); |
699 |
} |
|
3948 | 700 |
|
701 |
if (command == null) { |
|
702 |
if (help) { |
|
703 |
usage(); |
|
704 |
} else { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
705 |
System.err.println(rb.getString("Usage.error.no.command.provided")); |
3948 | 706 |
tinyHelp(); |
707 |
} |
|
708 |
} else if (help) { |
|
709 |
usage(); |
|
710 |
command = null; |
|
711 |
} |
|
24868
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
712 |
|
89d9bd9eba96
8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
20754
diff
changeset
|
713 |
return args; |
2 | 714 |
} |
715 |
||
3948 | 716 |
boolean isKeyStoreRelated(Command cmd) { |
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
717 |
return cmd != PRINTCERT && cmd != PRINTCERTREQ && cmd != SHOWINFO; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
718 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
719 |
|
2 | 720 |
/** |
721 |
* Execute the commands. |
|
722 |
*/ |
|
723 |
void doCommands(PrintStream out) throws Exception { |
|
40253
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
724 |
|
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
725 |
if (cacerts) { |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
726 |
if (ksfname != null || storetype != null) { |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
727 |
throw new IllegalArgumentException(rb.getString |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
728 |
("the.keystore.or.storetype.option.cannot.be.used.with.the.cacerts.option")); |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
729 |
} |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
730 |
ksfname = KeyStoreUtil.getCacerts(); |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
731 |
} |
08809866c0bc
8162739: Create new keytool option to access cacerts file
weijun
parents:
39886
diff
changeset
|
732 |
|
2 | 733 |
if (P11KEYSTORE.equalsIgnoreCase(storetype) || |
734 |
KeyStoreUtil.isWindowsKeyStore(storetype)) { |
|
735 |
token = true; |
|
736 |
if (ksfname == null) { |
|
737 |
ksfname = NONE; |
|
738 |
} |
|
739 |
} |
|
740 |
if (NONE.equals(ksfname)) { |
|
741 |
nullStream = true; |
|
742 |
} |
|
743 |
||
744 |
if (token && !nullStream) { |
|
745 |
System.err.println(MessageFormat.format(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
746 |
(".keystore.must.be.NONE.if.storetype.is.{0}"), storetype)); |
2 | 747 |
System.err.println(); |
748 |
tinyHelp(); |
|
749 |
} |
|
750 |
||
751 |
if (token && |
|
752 |
(command == KEYPASSWD || command == STOREPASSWD)) { |
|
753 |
throw new UnsupportedOperationException(MessageFormat.format(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
754 |
(".storepasswd.and.keypasswd.commands.not.supported.if.storetype.is.{0}"), storetype)); |
2 | 755 |
} |
756 |
||
757 |
if (token && (keyPass != null || newPass != null || destKeyPass != null)) { |
|
758 |
throw new IllegalArgumentException(MessageFormat.format(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
759 |
(".keypass.and.new.can.not.be.specified.if.storetype.is.{0}"), storetype)); |
2 | 760 |
} |
761 |
||
762 |
if (protectedPath) { |
|
763 |
if (storePass != null || keyPass != null || |
|
764 |
newPass != null || destKeyPass != null) { |
|
765 |
throw new IllegalArgumentException(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
766 |
("if.protected.is.specified.then.storepass.keypass.and.new.must.not.be.specified")); |
2 | 767 |
} |
768 |
} |
|
769 |
||
770 |
if (srcprotectedPath) { |
|
771 |
if (srcstorePass != null || srckeyPass != null) { |
|
772 |
throw new IllegalArgumentException(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
773 |
("if.srcprotected.is.specified.then.srcstorepass.and.srckeypass.must.not.be.specified")); |
2 | 774 |
} |
775 |
} |
|
776 |
||
777 |
if (KeyStoreUtil.isWindowsKeyStore(storetype)) { |
|
778 |
if (storePass != null || keyPass != null || |
|
779 |
newPass != null || destKeyPass != null) { |
|
780 |
throw new IllegalArgumentException(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
781 |
("if.keystore.is.not.password.protected.then.storepass.keypass.and.new.must.not.be.specified")); |
2 | 782 |
} |
783 |
} |
|
784 |
||
785 |
if (KeyStoreUtil.isWindowsKeyStore(srcstoretype)) { |
|
786 |
if (srcstorePass != null || srckeyPass != null) { |
|
787 |
throw new IllegalArgumentException(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
788 |
("if.source.keystore.is.not.password.protected.then.srcstorepass.and.srckeypass.must.not.be.specified")); |
2 | 789 |
} |
790 |
} |
|
791 |
||
792 |
if (validity <= (long)0) { |
|
793 |
throw new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
794 |
(rb.getString("Validity.must.be.greater.than.zero")); |
2 | 795 |
} |
796 |
||
797 |
// Try to load and install specified provider |
|
798 |
if (providers != null) { |
|
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
799 |
for (Pair<String, String> provider : providers) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
800 |
try { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
801 |
KeyStoreUtil.loadProviderByName( |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
802 |
provider.fst, provider.snd); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
803 |
if (debug) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
804 |
System.out.println("loadProviderByName: " + provider.fst); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
805 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
806 |
} catch (IllegalArgumentException e) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
807 |
throw new Exception(String.format(rb.getString( |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
808 |
"provider.name.not.found"), provider.fst)); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
809 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
810 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
811 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
812 |
if (providerClasses != null) { |
2 | 813 |
ClassLoader cl = null; |
814 |
if (pathlist != null) { |
|
815 |
String path = null; |
|
816 |
path = PathList.appendPath( |
|
817 |
path, System.getProperty("java.class.path")); |
|
818 |
path = PathList.appendPath( |
|
819 |
path, System.getProperty("env.class.path")); |
|
820 |
path = PathList.appendPath(path, pathlist); |
|
821 |
||
822 |
URL[] urls = PathList.pathToURLs(path); |
|
823 |
cl = new URLClassLoader(urls); |
|
824 |
} else { |
|
825 |
cl = ClassLoader.getSystemClassLoader(); |
|
826 |
} |
|
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
827 |
for (Pair<String, String> provider : providerClasses) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
828 |
try { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
829 |
KeyStoreUtil.loadProviderByClass( |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
830 |
provider.fst, provider.snd, cl); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
831 |
if (debug) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
832 |
System.out.println("loadProviderByClass: " + provider.fst); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
833 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
834 |
} catch (ClassCastException cce) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
835 |
throw new Exception(String.format(rb.getString( |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
836 |
"provclass.not.a.provider"), provider.fst)); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
837 |
} catch (IllegalArgumentException e) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
838 |
throw new Exception(String.format(rb.getString( |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
839 |
"provider.class.not.found"), provider.fst), e.getCause()); |
2 | 840 |
} |
841 |
} |
|
842 |
} |
|
843 |
||
844 |
if (command == LIST && verbose && rfc) { |
|
845 |
System.err.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
846 |
("Must.not.specify.both.v.and.rfc.with.list.command")); |
2 | 847 |
tinyHelp(); |
848 |
} |
|
849 |
||
850 |
// Make sure provided passwords are at least 6 characters long |
|
851 |
if (command == GENKEYPAIR && keyPass!=null && keyPass.length < 6) { |
|
852 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
853 |
("Key.password.must.be.at.least.6.characters")); |
2 | 854 |
} |
855 |
if (newPass != null && newPass.length < 6) { |
|
856 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
857 |
("New.password.must.be.at.least.6.characters")); |
2 | 858 |
} |
859 |
if (destKeyPass != null && destKeyPass.length < 6) { |
|
860 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
861 |
("New.password.must.be.at.least.6.characters")); |
2 | 862 |
} |
863 |
||
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
864 |
// Set this before inplaceImport check so we can compare name. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
865 |
if (ksfname == null) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
866 |
ksfname = System.getProperty("user.home") + File.separator |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
867 |
+ ".keystore"; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
868 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
869 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
870 |
KeyStore srcKeyStore = null; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
871 |
if (command == IMPORTKEYSTORE) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
872 |
inplaceImport = inplaceImportCheck(); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
873 |
if (inplaceImport) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
874 |
// We load srckeystore first so we have srcstorePass that |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
875 |
// can be assigned to storePass |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
876 |
srcKeyStore = loadSourceKeyStore(); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
877 |
if (storePass == null) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
878 |
storePass = srcstorePass; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
879 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
880 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
881 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
882 |
|
2 | 883 |
// Check if keystore exists. |
884 |
// If no keystore has been specified at the command line, try to use |
|
885 |
// the default, which is located in $HOME/.keystore. |
|
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
886 |
// No need to check if isKeyStoreRelated(command) is false. |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
887 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
888 |
// DO NOT open the existing keystore if this is an in-place import. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
889 |
// The keystore should be created as brand new. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
890 |
if (isKeyStoreRelated(command) && !nullStream && !inplaceImport) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
891 |
try { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
892 |
ksfile = new File(ksfname); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
893 |
// Check if keystore file is empty |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
894 |
if (ksfile.exists() && ksfile.length() == 0) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
895 |
throw new Exception(rb.getString |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
896 |
("Keystore.file.exists.but.is.empty.") + ksfname); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
897 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
898 |
ksStream = new FileInputStream(ksfile); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
899 |
} catch (FileNotFoundException e) { |
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
900 |
// These commands do not need the keystore to be existing. |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
901 |
// Either it will create a new one or the keystore is |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
902 |
// optional (i.e. PRINTCRL). |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
903 |
if (command != GENKEYPAIR && |
2 | 904 |
command != GENSECKEY && |
905 |
command != IDENTITYDB && |
|
906 |
command != IMPORTCERT && |
|
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
907 |
command != IMPORTPASS && |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
908 |
command != IMPORTKEYSTORE && |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
909 |
command != PRINTCRL) { |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
910 |
throw new Exception(rb.getString |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
911 |
("Keystore.file.does.not.exist.") + ksfname); |
2 | 912 |
} |
913 |
} |
|
914 |
} |
|
915 |
||
916 |
if ((command == KEYCLONE || command == CHANGEALIAS) |
|
917 |
&& dest == null) { |
|
918 |
dest = getAlias("destination"); |
|
919 |
if ("".equals(dest)) { |
|
920 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
921 |
("Must.specify.destination.alias")); |
2 | 922 |
} |
923 |
} |
|
924 |
||
925 |
if (command == DELETE && alias == null) { |
|
926 |
alias = getAlias(null); |
|
927 |
if ("".equals(alias)) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
928 |
throw new Exception(rb.getString("Must.specify.alias")); |
2 | 929 |
} |
930 |
} |
|
931 |
||
932 |
// Create new keystore |
|
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
933 |
// Probe for keystore type when filename is available |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
934 |
if (ksfile != null && ksStream != null && providerName == null && |
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
935 |
storetype == null && !inplaceImport) { |
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
936 |
keyStore = KeyStore.getInstance(ksfile, storePass); |
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
937 |
storetype = keyStore.getType(); |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
938 |
if (storetype.equalsIgnoreCase("pkcs12")) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
939 |
isPasswordlessKeyStore = PKCS12KeyStore.isPasswordless(ksfile); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
940 |
} |
2 | 941 |
} else { |
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
942 |
if (storetype == null) { |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
943 |
storetype = KeyStore.getDefaultType(); |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
944 |
} |
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
945 |
if (providerName == null) { |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
946 |
keyStore = KeyStore.getInstance(storetype); |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
947 |
} else { |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
948 |
keyStore = KeyStore.getInstance(storetype, providerName); |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
949 |
} |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
950 |
// When creating a new pkcs12 file, Do not prompt for storepass |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
951 |
// if certProtectionAlgorithm and macAlgorithm are both NONE. |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
952 |
if (storetype.equalsIgnoreCase("pkcs12")) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
953 |
isPasswordlessKeyStore = |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
954 |
"NONE".equals(SecurityProperties.privilegedGetOverridable( |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
955 |
"keystore.pkcs12.certProtectionAlgorithm")) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
956 |
&& "NONE".equals(SecurityProperties.privilegedGetOverridable( |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
957 |
"keystore.pkcs12.macAlgorithm")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
958 |
} |
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
959 |
|
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
960 |
/* |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
961 |
* Load the keystore data. |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
962 |
* |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
963 |
* At this point, it's OK if no keystore password has been provided. |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
964 |
* We want to make sure that we can load the keystore data, i.e., |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
965 |
* the keystore data has the right format. If we cannot load the |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
966 |
* keystore, why bother asking the user for his or her password? |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
967 |
* Only if we were able to load the keystore, and no keystore |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
968 |
* password has been provided, will we prompt the user for the |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
969 |
* keystore password to verify the keystore integrity. |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
970 |
* This means that the keystore is loaded twice: first load operation |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
971 |
* checks the keystore format, second load operation verifies the |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
972 |
* keystore integrity. |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
973 |
* |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
974 |
* If the keystore password has already been provided (at the |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
975 |
* command line), however, the keystore is loaded only once, and the |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
976 |
* keystore format and integrity are checked "at the same time". |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
977 |
* |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
978 |
* Null stream keystores are loaded later. |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
979 |
*/ |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
980 |
if (!nullStream) { |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
981 |
if (inplaceImport) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
982 |
keyStore.load(null, storePass); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
983 |
} else { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
984 |
keyStore.load(ksStream, storePass); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
985 |
} |
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
986 |
if (ksStream != null) { |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
987 |
ksStream.close(); |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
988 |
} |
2 | 989 |
} |
990 |
} |
|
991 |
||
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
992 |
if (P12KEYSTORE.equalsIgnoreCase(storetype) && command == KEYPASSWD) { |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
993 |
throw new UnsupportedOperationException(rb.getString |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
994 |
(".keypasswd.commands.not.supported.if.storetype.is.PKCS12")); |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
995 |
} |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
996 |
|
2 | 997 |
// All commands that create or modify the keystore require a keystore |
998 |
// password. |
|
999 |
||
1000 |
if (nullStream && storePass != null) { |
|
1001 |
keyStore.load(null, storePass); |
|
1002 |
} else if (!nullStream && storePass != null) { |
|
1003 |
// If we are creating a new non nullStream-based keystore, |
|
1004 |
// insist that the password be at least 6 characters |
|
1005 |
if (ksStream == null && storePass.length < 6) { |
|
1006 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1007 |
("Keystore.password.must.be.at.least.6.characters")); |
2 | 1008 |
} |
1009 |
} else if (storePass == null) { |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1010 |
if (!protectedPath && !KeyStoreUtil.isWindowsKeyStore(storetype) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1011 |
&& isKeyStoreRelated(command) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1012 |
&& !isPasswordlessKeyStore) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1013 |
if (command == CERTREQ || |
2 | 1014 |
command == DELETE || |
1015 |
command == GENKEYPAIR || |
|
1016 |
command == GENSECKEY || |
|
1017 |
command == IMPORTCERT || |
|
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1018 |
command == IMPORTPASS || |
2 | 1019 |
command == IMPORTKEYSTORE || |
1020 |
command == KEYCLONE || |
|
1021 |
command == CHANGEALIAS || |
|
1022 |
command == SELFCERT || |
|
1023 |
command == STOREPASSWD || |
|
1024 |
command == KEYPASSWD || |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1025 |
command == IDENTITYDB) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1026 |
int count = 0; |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1027 |
do { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1028 |
if (command == IMPORTKEYSTORE) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1029 |
System.err.print |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1030 |
(rb.getString("Enter.destination.keystore.password.")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1031 |
} else { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1032 |
System.err.print |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1033 |
(rb.getString("Enter.keystore.password.")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1034 |
} |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1035 |
System.err.flush(); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1036 |
storePass = Password.readPassword(System.in); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1037 |
passwords.add(storePass); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1038 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1039 |
// If we are creating a new non nullStream-based keystore, |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1040 |
// insist that the password be at least 6 characters |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1041 |
if (!nullStream && (storePass == null || storePass.length < 6)) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1042 |
System.err.println(rb.getString |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1043 |
("Keystore.password.is.too.short.must.be.at.least.6.characters")); |
2 | 1044 |
storePass = null; |
1045 |
} |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1046 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1047 |
// If the keystore file does not exist and needs to be |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1048 |
// created, the storepass should be prompted twice. |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1049 |
if (storePass != null && !nullStream && ksStream == null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1050 |
System.err.print(rb.getString("Re.enter.new.password.")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1051 |
char[] storePassAgain = Password.readPassword(System.in); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1052 |
passwords.add(storePassAgain); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1053 |
if (!Arrays.equals(storePass, storePassAgain)) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1054 |
System.err.println |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1055 |
(rb.getString("They.don.t.match.Try.again")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1056 |
storePass = null; |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1057 |
} |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1058 |
} |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1059 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1060 |
count++; |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1061 |
} while ((storePass == null) && count < 3); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1062 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1063 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1064 |
if (storePass == null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1065 |
System.err.println |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1066 |
(rb.getString("Too.many.failures.try.later")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1067 |
return; |
2 | 1068 |
} |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1069 |
} else { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1070 |
// here we have EXPORTCERT and LIST (info valid until STOREPASSWD) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1071 |
if (command != PRINTCRL) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1072 |
System.err.print(rb.getString("Enter.keystore.password.")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1073 |
System.err.flush(); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1074 |
storePass = Password.readPassword(System.in); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1075 |
passwords.add(storePass); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1076 |
} |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1077 |
} |
2 | 1078 |
} |
1079 |
||
1080 |
// Now load a nullStream-based keystore, |
|
1081 |
// or verify the integrity of an input stream-based keystore |
|
1082 |
if (nullStream) { |
|
1083 |
keyStore.load(null, storePass); |
|
1084 |
} else if (ksStream != null) { |
|
1085 |
ksStream = new FileInputStream(ksfile); |
|
1086 |
keyStore.load(ksStream, storePass); |
|
1087 |
ksStream.close(); |
|
1088 |
} |
|
1089 |
} |
|
1090 |
||
1091 |
if (storePass != null && P12KEYSTORE.equalsIgnoreCase(storetype)) { |
|
1092 |
MessageFormat form = new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1093 |
"Warning.Different.store.and.key.passwords.not.supported.for.PKCS12.KeyStores.Ignoring.user.specified.command.value.")); |
2 | 1094 |
if (keyPass != null && !Arrays.equals(storePass, keyPass)) { |
1095 |
Object[] source = {"-keypass"}; |
|
1096 |
System.err.println(form.format(source)); |
|
1097 |
keyPass = storePass; |
|
1098 |
} |
|
1099 |
if (destKeyPass != null && !Arrays.equals(storePass, destKeyPass)) { |
|
1100 |
Object[] source = {"-destkeypass"}; |
|
1101 |
System.err.println(form.format(source)); |
|
1102 |
destKeyPass = storePass; |
|
1103 |
} |
|
1104 |
} |
|
1105 |
||
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1106 |
// -trustcacerts can only be specified on -importcert. |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1107 |
// Reset it so that warnings on CA cert will remain for |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1108 |
// -printcert, etc. |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1109 |
if (command != IMPORTCERT) { |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1110 |
trustcacerts = false; |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1111 |
} |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1112 |
|
2 | 1113 |
if (trustcacerts) { |
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
1114 |
caks = KeyStoreUtil.getCacertsKeyStore(); |
2 | 1115 |
} |
1116 |
||
1117 |
// Perform the specified command |
|
1118 |
if (command == CERTREQ) { |
|
1119 |
if (filename != null) { |
|
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1120 |
try (PrintStream ps = new PrintStream(new FileOutputStream |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1121 |
(filename))) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1122 |
doCertReq(alias, sigAlgName, ps); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1123 |
} |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1124 |
} else { |
2 | 1125 |
doCertReq(alias, sigAlgName, out); |
1126 |
} |
|
1127 |
if (verbose && filename != null) { |
|
1128 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1129 |
("Certification.request.stored.in.file.filename.")); |
2 | 1130 |
Object[] source = {filename}; |
1131 |
System.err.println(form.format(source)); |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1132 |
System.err.println(rb.getString("Submit.this.to.your.CA")); |
2 | 1133 |
} |
1134 |
} else if (command == DELETE) { |
|
1135 |
doDeleteEntry(alias); |
|
1136 |
kssave = true; |
|
1137 |
} else if (command == EXPORTCERT) { |
|
1138 |
if (filename != null) { |
|
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1139 |
try (PrintStream ps = new PrintStream(new FileOutputStream |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1140 |
(filename))) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1141 |
doExportCert(alias, ps); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1142 |
} |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1143 |
} else { |
2 | 1144 |
doExportCert(alias, out); |
1145 |
} |
|
1146 |
if (filename != null) { |
|
1147 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1148 |
("Certificate.stored.in.file.filename.")); |
2 | 1149 |
Object[] source = {filename}; |
1150 |
System.err.println(form.format(source)); |
|
1151 |
} |
|
1152 |
} else if (command == GENKEYPAIR) { |
|
1153 |
if (keyAlgName == null) { |
|
59104 | 1154 |
throw new Exception(rb.getString( |
1155 |
"keyalg.option.missing.error")); |
|
2 | 1156 |
} |
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1157 |
doGenKeyPair(alias, dname, keyAlgName, keysize, groupName, sigAlgName); |
2 | 1158 |
kssave = true; |
1159 |
} else if (command == GENSECKEY) { |
|
1160 |
if (keyAlgName == null) { |
|
59104 | 1161 |
throw new Exception(rb.getString( |
1162 |
"keyalg.option.missing.error")); |
|
2 | 1163 |
} |
1164 |
doGenSecretKey(alias, keyAlgName, keysize); |
|
1165 |
kssave = true; |
|
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1166 |
} else if (command == IMPORTPASS) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1167 |
if (keyAlgName == null) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1168 |
keyAlgName = "PBE"; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1169 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1170 |
// password is stored as a secret key |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1171 |
doGenSecretKey(alias, keyAlgName, keysize); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1172 |
kssave = true; |
2 | 1173 |
} else if (command == IDENTITYDB) { |
1174 |
if (filename != null) { |
|
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1175 |
try (InputStream inStream = new FileInputStream(filename)) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1176 |
doImportIdentityDatabase(inStream); |
2 | 1177 |
} |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1178 |
} else { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1179 |
doImportIdentityDatabase(System.in); |
2 | 1180 |
} |
1181 |
} else if (command == IMPORTCERT) { |
|
1182 |
InputStream inStream = System.in; |
|
1183 |
if (filename != null) { |
|
1184 |
inStream = new FileInputStream(filename); |
|
1185 |
} |
|
5164
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1186 |
String importAlias = (alias!=null)?alias:keyAlias; |
2 | 1187 |
try { |
5164
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1188 |
if (keyStore.entryInstanceOf( |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1189 |
importAlias, KeyStore.PrivateKeyEntry.class)) { |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1190 |
kssave = installReply(importAlias, inStream); |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1191 |
if (kssave) { |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1192 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1193 |
("Certificate.reply.was.installed.in.keystore")); |
5164
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1194 |
} else { |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1195 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1196 |
("Certificate.reply.was.not.installed.in.keystore")); |
5164
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1197 |
} |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1198 |
} else if (!keyStore.containsAlias(importAlias) || |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1199 |
keyStore.entryInstanceOf(importAlias, |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1200 |
KeyStore.TrustedCertificateEntry.class)) { |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1201 |
kssave = addTrustedCert(importAlias, inStream); |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1202 |
if (kssave) { |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1203 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1204 |
("Certificate.was.added.to.keystore")); |
5164
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1205 |
} else { |
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1206 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1207 |
("Certificate.was.not.added.to.keystore")); |
5164
337ae296b6d6
6813340: X509Factory should not depend on is.available()==0
weijun
parents:
4918
diff
changeset
|
1208 |
} |
2 | 1209 |
} |
1210 |
} finally { |
|
1211 |
if (inStream != System.in) { |
|
1212 |
inStream.close(); |
|
1213 |
} |
|
1214 |
} |
|
1215 |
} else if (command == IMPORTKEYSTORE) { |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1216 |
// When not in-place import, srcKeyStore is not loaded yet. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1217 |
if (srcKeyStore == null) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1218 |
srcKeyStore = loadSourceKeyStore(); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1219 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1220 |
doImportKeyStore(srcKeyStore); |
2 | 1221 |
kssave = true; |
1222 |
} else if (command == KEYCLONE) { |
|
1223 |
keyPassNew = newPass; |
|
1224 |
||
1225 |
// added to make sure only key can go thru |
|
1226 |
if (alias == null) { |
|
1227 |
alias = keyAlias; |
|
1228 |
} |
|
1229 |
if (keyStore.containsAlias(alias) == false) { |
|
1230 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1231 |
(rb.getString("Alias.alias.does.not.exist")); |
2 | 1232 |
Object[] source = {alias}; |
1233 |
throw new Exception(form.format(source)); |
|
1234 |
} |
|
1235 |
if (!keyStore.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { |
|
1236 |
MessageFormat form = new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1237 |
"Alias.alias.references.an.entry.type.that.is.not.a.private.key.entry.The.keyclone.command.only.supports.cloning.of.private.key")); |
2 | 1238 |
Object[] source = {alias}; |
1239 |
throw new Exception(form.format(source)); |
|
1240 |
} |
|
1241 |
||
1242 |
doCloneEntry(alias, dest, true); // Now everything can be cloned |
|
1243 |
kssave = true; |
|
1244 |
} else if (command == CHANGEALIAS) { |
|
1245 |
if (alias == null) { |
|
1246 |
alias = keyAlias; |
|
1247 |
} |
|
1248 |
doCloneEntry(alias, dest, false); |
|
1249 |
// in PKCS11, clone a PrivateKeyEntry will delete the old one |
|
1250 |
if (keyStore.containsAlias(alias)) { |
|
1251 |
doDeleteEntry(alias); |
|
1252 |
} |
|
1253 |
kssave = true; |
|
1254 |
} else if (command == KEYPASSWD) { |
|
1255 |
keyPassNew = newPass; |
|
1256 |
doChangeKeyPasswd(alias); |
|
1257 |
kssave = true; |
|
1258 |
} else if (command == LIST) { |
|
27038
64cb6608f8a6
8029659: Keytool, print key algorithm of certificate or key entry
weijun
parents:
25859
diff
changeset
|
1259 |
if (storePass == null |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1260 |
&& !KeyStoreUtil.isWindowsKeyStore(storetype) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1261 |
&& !isPasswordlessKeyStore) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1262 |
printNoIntegrityWarning(); |
27038
64cb6608f8a6
8029659: Keytool, print key algorithm of certificate or key entry
weijun
parents:
25859
diff
changeset
|
1263 |
} |
64cb6608f8a6
8029659: Keytool, print key algorithm of certificate or key entry
weijun
parents:
25859
diff
changeset
|
1264 |
|
2 | 1265 |
if (alias != null) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1266 |
doPrintEntry(rb.getString("the.certificate"), alias, out); |
2 | 1267 |
} else { |
1268 |
doPrintEntries(out); |
|
1269 |
} |
|
1270 |
} else if (command == PRINTCERT) { |
|
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
1271 |
doPrintCert(out); |
2 | 1272 |
} else if (command == SELFCERT) { |
1273 |
doSelfCert(alias, dname, sigAlgName); |
|
1274 |
kssave = true; |
|
1275 |
} else if (command == STOREPASSWD) { |
|
48333
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
1276 |
doChangeStorePasswd(); |
2 | 1277 |
kssave = true; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1278 |
} else if (command == GENCERT) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1279 |
if (alias == null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1280 |
alias = keyAlias; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1281 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1282 |
InputStream inStream = System.in; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1283 |
if (infilename != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1284 |
inStream = new FileInputStream(infilename); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1285 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1286 |
PrintStream ps = null; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1287 |
if (outfilename != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1288 |
ps = new PrintStream(new FileOutputStream(outfilename)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1289 |
out = ps; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1290 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1291 |
try { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1292 |
doGenCert(alias, sigAlgName, inStream, out); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1293 |
} finally { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1294 |
if (inStream != System.in) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1295 |
inStream.close(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1296 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1297 |
if (ps != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1298 |
ps.close(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1299 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1300 |
} |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1301 |
} else if (command == GENCRL) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1302 |
if (alias == null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1303 |
alias = keyAlias; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1304 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1305 |
if (filename != null) { |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1306 |
try (PrintStream ps = |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1307 |
new PrintStream(new FileOutputStream(filename))) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1308 |
doGenCRL(ps); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1309 |
} |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1310 |
} else { |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1311 |
doGenCRL(out); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1312 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1313 |
} else if (command == PRINTCERTREQ) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1314 |
if (filename != null) { |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1315 |
try (InputStream inStream = new FileInputStream(filename)) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1316 |
doPrintCertReq(inStream, out); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1317 |
} |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1318 |
} else { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
1319 |
doPrintCertReq(System.in, out); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1320 |
} |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1321 |
} else if (command == PRINTCRL) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1322 |
doPrintCRL(filename, out); |
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
1323 |
} else if (command == SHOWINFO) { |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
1324 |
doShowInfo(); |
2 | 1325 |
} |
1326 |
||
1327 |
// If we need to save the keystore, do so. |
|
1328 |
if (kssave) { |
|
1329 |
if (verbose) { |
|
1330 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1331 |
(rb.getString(".Storing.ksfname.")); |
2 | 1332 |
Object[] source = {nullStream ? "keystore" : ksfname}; |
1333 |
System.err.println(form.format(source)); |
|
1334 |
} |
|
1335 |
||
1336 |
if (token) { |
|
1337 |
keyStore.store(null, null); |
|
1338 |
} else { |
|
10436 | 1339 |
char[] pass = (storePassNew!=null) ? storePassNew : storePass; |
1340 |
if (nullStream) { |
|
1341 |
keyStore.store(null, pass); |
|
1342 |
} else { |
|
1343 |
ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
|
1344 |
keyStore.store(bout, pass); |
|
1345 |
try (FileOutputStream fout = new FileOutputStream(ksfname)) { |
|
1346 |
fout.write(bout.toByteArray()); |
|
2 | 1347 |
} |
1348 |
} |
|
1349 |
} |
|
1350 |
} |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1351 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1352 |
if (isKeyStoreRelated(command) |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1353 |
&& !token && !nullStream && ksfname != null) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1354 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1355 |
// JKS storetype warning on the final result keystore |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1356 |
File f = new File(ksfname); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1357 |
char[] pass = (storePassNew!=null) ? storePassNew : storePass; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1358 |
if (f.exists()) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1359 |
// Probe for real type. A JKS can be loaded as PKCS12 because |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1360 |
// DualFormat support, vice versa. |
52689
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1361 |
String realType = storetype; |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1362 |
try { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1363 |
keyStore = KeyStore.getInstance(f, pass); |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1364 |
realType = keyStore.getType(); |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1365 |
if (realType.equalsIgnoreCase("JKS") |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1366 |
|| realType.equalsIgnoreCase("JCEKS")) { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1367 |
boolean allCerts = true; |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1368 |
for (String a : Collections.list(keyStore.aliases())) { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1369 |
if (!keyStore.entryInstanceOf( |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1370 |
a, TrustedCertificateEntry.class)) { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1371 |
allCerts = false; |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1372 |
break; |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1373 |
} |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1374 |
} |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1375 |
// Don't warn for "cacerts" style keystore. |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1376 |
if (!allCerts) { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1377 |
weakWarnings.add(String.format( |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1378 |
rb.getString("jks.storetype.warning"), |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1379 |
realType, ksfname)); |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1380 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1381 |
} |
52689
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1382 |
} catch (KeyStoreException e) { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1383 |
// Probing not supported, therefore cannot be JKS or JCEKS. |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1384 |
// Skip the legacy type warning at all. |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1385 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1386 |
if (inplaceImport) { |
52689
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1387 |
String realSourceStoreType = srcstoretype; |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1388 |
try { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1389 |
realSourceStoreType = KeyStore.getInstance( |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1390 |
new File(inplaceBackupName), srcstorePass).getType(); |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1391 |
} catch (KeyStoreException e) { |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1392 |
// Probing not supported. Assuming srcstoretype. |
7084dae775f2
8214100: use of keystore probing results in unnecessary exception thrown
weijun
parents:
52598
diff
changeset
|
1393 |
} |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1394 |
String format = |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1395 |
realType.equalsIgnoreCase(realSourceStoreType) ? |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1396 |
rb.getString("backup.keystore.warning") : |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1397 |
rb.getString("migrate.keystore.warning"); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1398 |
weakWarnings.add( |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1399 |
String.format(format, |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1400 |
srcksfname, |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1401 |
realSourceStoreType, |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1402 |
inplaceBackupName, |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1403 |
realType)); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1404 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1405 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
1406 |
} |
2 | 1407 |
} |
1408 |
||
1409 |
/** |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1410 |
* Generate a certificate: Read PKCS10 request from in, and print |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1411 |
* certificate to out. Use alias as CA, sigAlgName as the signature |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1412 |
* type. |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1413 |
*/ |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1414 |
private void doGenCert(String alias, String sigAlgName, InputStream in, PrintStream out) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1415 |
throws Exception { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1416 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1417 |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1418 |
if (keyStore.containsAlias(alias) == false) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1419 |
MessageFormat form = new MessageFormat |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1420 |
(rb.getString("Alias.alias.does.not.exist")); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1421 |
Object[] source = {alias}; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1422 |
throw new Exception(form.format(source)); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1423 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1424 |
Certificate signerCert = keyStore.getCertificate(alias); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1425 |
byte[] encoded = signerCert.getEncoded(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1426 |
X509CertImpl signerCertImpl = new X509CertImpl(encoded); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1427 |
X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get( |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1428 |
X509CertImpl.NAME + "." + X509CertImpl.INFO); |
3316
32d30c561c5a
6847026: keytool should be able to generate certreq and cert without subject name
weijun
parents:
2437
diff
changeset
|
1429 |
X500Name issuer = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "." + |
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
1430 |
X509CertInfo.DN_NAME); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1431 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1432 |
Date firstDate = getStartDate(startDate); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1433 |
Date lastDate = new Date(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1434 |
lastDate.setTime(firstDate.getTime() + validity*1000L*24L*60L*60L); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1435 |
CertificateValidity interval = new CertificateValidity(firstDate, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1436 |
lastDate); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1437 |
|
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1438 |
PrivateKey privateKey = |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1439 |
(PrivateKey)recoverKey(alias, storePass, keyPass).fst; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1440 |
if (sigAlgName == null) { |
38439 | 1441 |
sigAlgName = getCompatibleSigAlgName(privateKey); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1442 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1443 |
Signature signature = Signature.getInstance(sigAlgName); |
54483
ac20c3bdc55d
8216039: TLS with BC and RSASSA-PSS breaks ECDHServerKeyExchange
valeriep
parents:
54421
diff
changeset
|
1444 |
AlgorithmParameterSpec params = AlgorithmId |
ac20c3bdc55d
8216039: TLS with BC and RSASSA-PSS breaks ECDHServerKeyExchange
valeriep
parents:
54421
diff
changeset
|
1445 |
.getDefaultAlgorithmParameterSpec(sigAlgName, privateKey); |
ac20c3bdc55d
8216039: TLS with BC and RSASSA-PSS breaks ECDHServerKeyExchange
valeriep
parents:
54421
diff
changeset
|
1446 |
|
ac20c3bdc55d
8216039: TLS with BC and RSASSA-PSS breaks ECDHServerKeyExchange
valeriep
parents:
54421
diff
changeset
|
1447 |
SignatureUtil.initSignWithParam(signature, privateKey, params, null); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1448 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1449 |
X509CertInfo info = new X509CertInfo(); |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
1450 |
AlgorithmId algID = AlgorithmId.getWithParameterSpec(sigAlgName, params); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1451 |
info.set(X509CertInfo.VALIDITY, interval); |
54346
b7ebff3e4e69
8221257: Improve serial number generation mechanism for keytool -gencert
weijun
parents:
53740
diff
changeset
|
1452 |
info.set(X509CertInfo.SERIAL_NUMBER, |
b7ebff3e4e69
8221257: Improve serial number generation mechanism for keytool -gencert
weijun
parents:
53740
diff
changeset
|
1453 |
CertificateSerialNumber.newRandom64bit(new SecureRandom())); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1454 |
info.set(X509CertInfo.VERSION, |
4350
2a593a20d962
6876158: Remove dependencies on Signer, Certificate, Identity, IdentityScope classes from java.security pkg
vinnie
parents:
4169
diff
changeset
|
1455 |
new CertificateVersion(CertificateVersion.V3)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1456 |
info.set(X509CertInfo.ALGORITHM_ID, |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
1457 |
new CertificateAlgorithmId(algID)); |
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
1458 |
info.set(X509CertInfo.ISSUER, issuer); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1459 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1460 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1461 |
boolean canRead = false; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1462 |
StringBuffer sb = new StringBuffer(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1463 |
while (true) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1464 |
String s = reader.readLine(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1465 |
if (s == null) break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1466 |
// OpenSSL does not use NEW |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1467 |
//if (s.startsWith("-----BEGIN NEW CERTIFICATE REQUEST-----")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1468 |
if (s.startsWith("-----BEGIN") && s.indexOf("REQUEST") >= 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1469 |
canRead = true; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1470 |
//} else if (s.startsWith("-----END NEW CERTIFICATE REQUEST-----")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1471 |
} else if (s.startsWith("-----END") && s.indexOf("REQUEST") >= 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1472 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1473 |
} else if (canRead) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1474 |
sb.append(s); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1475 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1476 |
} |
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
1477 |
byte[] rawReq = Pem.decode(new String(sb)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1478 |
PKCS10 req = new PKCS10(rawReq); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1479 |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1480 |
checkWeak(rb.getString("the.certificate.request"), req); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1481 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1482 |
info.set(X509CertInfo.KEY, new CertificateX509Key(req.getSubjectPublicKeyInfo())); |
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
1483 |
info.set(X509CertInfo.SUBJECT, |
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
1484 |
dname==null?req.getSubjectName():new X500Name(dname)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1485 |
CertificateExtensions reqex = null; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1486 |
Iterator<PKCS10Attribute> attrs = req.getAttributes().getAttributes().iterator(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1487 |
while (attrs.hasNext()) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1488 |
PKCS10Attribute attr = attrs.next(); |
31426
9cd672654f97
8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents:
31270
diff
changeset
|
1489 |
if (attr.getAttributeId().equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1490 |
reqex = (CertificateExtensions)attr.getAttributeValue(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1491 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1492 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1493 |
CertificateExtensions ext = createV3Extensions( |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1494 |
reqex, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1495 |
null, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1496 |
v3ext, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1497 |
req.getSubjectPublicKeyInfo(), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1498 |
signerCert.getPublicKey()); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1499 |
info.set(X509CertInfo.EXTENSIONS, ext); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1500 |
X509CertImpl cert = new X509CertImpl(info); |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
1501 |
cert.sign(privateKey, params, sigAlgName, null); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1502 |
dumpCert(cert, out); |
5296 | 1503 |
for (Certificate ca: keyStore.getCertificateChain(alias)) { |
1504 |
if (ca instanceof X509Certificate) { |
|
1505 |
X509Certificate xca = (X509Certificate)ca; |
|
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
34381
diff
changeset
|
1506 |
if (!KeyStoreUtil.isSelfSigned(xca)) { |
5296 | 1507 |
dumpCert(xca, out); |
1508 |
} |
|
1509 |
} |
|
1510 |
} |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1511 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1512 |
checkWeak(rb.getString("the.issuer"), keyStore.getCertificateChain(alias)); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1513 |
checkWeak(rb.getString("the.generated.certificate"), cert); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1514 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1515 |
|
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1516 |
private void doGenCRL(PrintStream out) |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1517 |
throws Exception { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1518 |
if (ids == null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1519 |
throw new Exception("Must provide -id when -gencrl"); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1520 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1521 |
Certificate signerCert = keyStore.getCertificate(alias); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1522 |
byte[] encoded = signerCert.getEncoded(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1523 |
X509CertImpl signerCertImpl = new X509CertImpl(encoded); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1524 |
X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get( |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1525 |
X509CertImpl.NAME + "." + X509CertImpl.INFO); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1526 |
X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "." + |
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
1527 |
X509CertInfo.DN_NAME); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1528 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1529 |
Date firstDate = getStartDate(startDate); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1530 |
Date lastDate = (Date) firstDate.clone(); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
10051
diff
changeset
|
1531 |
lastDate.setTime(lastDate.getTime() + validity*1000*24*60*60); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1532 |
CertificateValidity interval = new CertificateValidity(firstDate, |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1533 |
lastDate); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1534 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1535 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1536 |
PrivateKey privateKey = |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1537 |
(PrivateKey)recoverKey(alias, storePass, keyPass).fst; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1538 |
if (sigAlgName == null) { |
38439 | 1539 |
sigAlgName = getCompatibleSigAlgName(privateKey); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1540 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1541 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1542 |
X509CRLEntry[] badCerts = new X509CRLEntry[ids.size()]; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1543 |
for (int i=0; i<ids.size(); i++) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1544 |
String id = ids.get(i); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1545 |
int d = id.indexOf(':'); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1546 |
if (d >= 0) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1547 |
CRLExtensions ext = new CRLExtensions(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1548 |
ext.set("Reason", new CRLReasonCodeExtension(Integer.parseInt(id.substring(d+1)))); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1549 |
badCerts[i] = new X509CRLEntryImpl(new BigInteger(id.substring(0, d)), |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1550 |
firstDate, ext); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1551 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1552 |
badCerts[i] = new X509CRLEntryImpl(new BigInteger(ids.get(i)), firstDate); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1553 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1554 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1555 |
X509CRLImpl crl = new X509CRLImpl(owner, firstDate, lastDate, badCerts); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1556 |
crl.sign(privateKey, sigAlgName); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1557 |
if (rfc) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1558 |
out.println("-----BEGIN X509 CRL-----"); |
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
1559 |
out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(crl.getEncodedInternal())); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1560 |
out.println("-----END X509 CRL-----"); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1561 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1562 |
out.write(crl.getEncodedInternal()); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1563 |
} |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1564 |
checkWeak(rb.getString("the.generated.crl"), crl, privateKey); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1565 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
1566 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1567 |
/** |
2 | 1568 |
* Creates a PKCS#10 cert signing request, corresponding to the |
1569 |
* keys (and name) associated with a given alias. |
|
1570 |
*/ |
|
1571 |
private void doCertReq(String alias, String sigAlgName, PrintStream out) |
|
1572 |
throws Exception |
|
1573 |
{ |
|
1574 |
if (alias == null) { |
|
1575 |
alias = keyAlias; |
|
1576 |
} |
|
1577 |
||
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1578 |
Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1579 |
PrivateKey privKey = (PrivateKey)objs.fst; |
2 | 1580 |
if (keyPass == null) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1581 |
keyPass = objs.snd; |
2 | 1582 |
} |
1583 |
||
1584 |
Certificate cert = keyStore.getCertificate(alias); |
|
1585 |
if (cert == null) { |
|
1586 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1587 |
(rb.getString("alias.has.no.public.key.certificate.")); |
2 | 1588 |
Object[] source = {alias}; |
1589 |
throw new Exception(form.format(source)); |
|
1590 |
} |
|
1591 |
PKCS10 request = new PKCS10(cert.getPublicKey()); |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1592 |
CertificateExtensions ext = createV3Extensions(null, null, v3ext, cert.getPublicKey(), null); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1593 |
// Attribute name is not significant |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1594 |
request.getAttributes().setAttribute(X509CertInfo.EXTENSIONS, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1595 |
new PKCS10Attribute(PKCS9Attribute.EXTENSION_REQUEST_OID, ext)); |
2 | 1596 |
|
4350
2a593a20d962
6876158: Remove dependencies on Signer, Certificate, Identity, IdentityScope classes from java.security pkg
vinnie
parents:
4169
diff
changeset
|
1597 |
// Construct a Signature object, so that we can sign the request |
2 | 1598 |
if (sigAlgName == null) { |
38439 | 1599 |
sigAlgName = getCompatibleSigAlgName(privKey); |
2 | 1600 |
} |
1601 |
||
1602 |
Signature signature = Signature.getInstance(sigAlgName); |
|
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
1603 |
AlgorithmParameterSpec params = AlgorithmId |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
1604 |
.getDefaultAlgorithmParameterSpec(sigAlgName, privKey); |
54483
ac20c3bdc55d
8216039: TLS with BC and RSASSA-PSS breaks ECDHServerKeyExchange
valeriep
parents:
54421
diff
changeset
|
1605 |
SignatureUtil.initSignWithParam(signature, privKey, params, null); |
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
1606 |
|
3316
32d30c561c5a
6847026: keytool should be able to generate certreq and cert without subject name
weijun
parents:
2437
diff
changeset
|
1607 |
X500Name subject = dname == null? |
32d30c561c5a
6847026: keytool should be able to generate certreq and cert without subject name
weijun
parents:
2437
diff
changeset
|
1608 |
new X500Name(((X509Certificate)cert).getSubjectDN().toString()): |
32d30c561c5a
6847026: keytool should be able to generate certreq and cert without subject name
weijun
parents:
2437
diff
changeset
|
1609 |
new X500Name(dname); |
2 | 1610 |
|
1611 |
// Sign the request and base-64 encode it |
|
4350
2a593a20d962
6876158: Remove dependencies on Signer, Certificate, Identity, IdentityScope classes from java.security pkg
vinnie
parents:
4169
diff
changeset
|
1612 |
request.encodeAndSign(subject, signature); |
2 | 1613 |
request.print(out); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1614 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1615 |
checkWeak(rb.getString("the.generated.certificate.request"), request); |
2 | 1616 |
} |
1617 |
||
1618 |
/** |
|
1619 |
* Deletes an entry from the keystore. |
|
1620 |
*/ |
|
1621 |
private void doDeleteEntry(String alias) throws Exception { |
|
1622 |
if (keyStore.containsAlias(alias) == false) { |
|
1623 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1624 |
(rb.getString("Alias.alias.does.not.exist")); |
2 | 1625 |
Object[] source = {alias}; |
1626 |
throw new Exception(form.format(source)); |
|
1627 |
} |
|
1628 |
keyStore.deleteEntry(alias); |
|
1629 |
} |
|
1630 |
||
1631 |
/** |
|
1632 |
* Exports a certificate from the keystore. |
|
1633 |
*/ |
|
1634 |
private void doExportCert(String alias, PrintStream out) |
|
1635 |
throws Exception |
|
1636 |
{ |
|
1637 |
if (storePass == null |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1638 |
&& !KeyStoreUtil.isWindowsKeyStore(storetype) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1639 |
&& !isPasswordlessKeyStore) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1640 |
printNoIntegrityWarning(); |
2 | 1641 |
} |
1642 |
if (alias == null) { |
|
1643 |
alias = keyAlias; |
|
1644 |
} |
|
1645 |
if (keyStore.containsAlias(alias) == false) { |
|
1646 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1647 |
(rb.getString("Alias.alias.does.not.exist")); |
2 | 1648 |
Object[] source = {alias}; |
1649 |
throw new Exception(form.format(source)); |
|
1650 |
} |
|
1651 |
||
1652 |
X509Certificate cert = (X509Certificate)keyStore.getCertificate(alias); |
|
1653 |
if (cert == null) { |
|
1654 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1655 |
(rb.getString("Alias.alias.has.no.certificate")); |
2 | 1656 |
Object[] source = {alias}; |
1657 |
throw new Exception(form.format(source)); |
|
1658 |
} |
|
1659 |
dumpCert(cert, out); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
1660 |
checkWeak(rb.getString("the.certificate"), cert); |
2 | 1661 |
} |
1662 |
||
1663 |
/** |
|
1664 |
* Prompt the user for a keypass when generating a key entry. |
|
1665 |
* @param alias the entry we will set password for |
|
1666 |
* @param orig the original entry of doing a dup, null if generate new |
|
1667 |
* @param origPass the password to copy from if user press ENTER |
|
1668 |
*/ |
|
1669 |
private char[] promptForKeyPass(String alias, String orig, char[] origPass) throws Exception{ |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1670 |
if (origPass != null && P12KEYSTORE.equalsIgnoreCase(storetype)) { |
2 | 1671 |
return origPass; |
10436 | 1672 |
} else if (!token && !protectedPath) { |
2 | 1673 |
// Prompt for key password |
1674 |
int count; |
|
1675 |
for (count = 0; count < 3; count++) { |
|
1676 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1677 |
("Enter.key.password.for.alias.")); |
2 | 1678 |
Object[] source = {alias}; |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1679 |
System.err.print(form.format(source)); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1680 |
if (origPass != null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1681 |
System.err.println(); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1682 |
if (orig == null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1683 |
System.err.print(rb.getString |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1684 |
(".RETURN.if.same.as.keystore.password.")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1685 |
} else { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1686 |
form = new MessageFormat(rb.getString |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1687 |
(".RETURN.if.same.as.for.otherAlias.")); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1688 |
Object[] src = {orig}; |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1689 |
System.err.print(form.format(src)); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1690 |
} |
2 | 1691 |
} |
1692 |
System.err.flush(); |
|
1693 |
char[] entered = Password.readPassword(System.in); |
|
1694 |
passwords.add(entered); |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1695 |
if (entered == null && origPass != null) { |
2 | 1696 |
return origPass; |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
1697 |
} else if (entered != null && entered.length >= 6) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1698 |
System.err.print(rb.getString("Re.enter.new.password.")); |
2 | 1699 |
char[] passAgain = Password.readPassword(System.in); |
1700 |
passwords.add(passAgain); |
|
1701 |
if (!Arrays.equals(entered, passAgain)) { |
|
1702 |
System.err.println |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1703 |
(rb.getString("They.don.t.match.Try.again")); |
2 | 1704 |
continue; |
1705 |
} |
|
1706 |
return entered; |
|
1707 |
} else { |
|
1708 |
System.err.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1709 |
("Key.password.is.too.short.must.be.at.least.6.characters")); |
2 | 1710 |
} |
1711 |
} |
|
1712 |
if (count == 3) { |
|
1713 |
if (command == KEYCLONE) { |
|
1714 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1715 |
("Too.many.failures.Key.entry.not.cloned")); |
2 | 1716 |
} else { |
1717 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1718 |
("Too.many.failures.key.not.added.to.keystore")); |
2 | 1719 |
} |
1720 |
} |
|
1721 |
} |
|
10436 | 1722 |
return null; // PKCS11, MSCAPI, or -protected |
2 | 1723 |
} |
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1724 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1725 |
/* |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1726 |
* Prompt the user for the password credential to be stored. |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1727 |
*/ |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1728 |
private char[] promptForCredential() throws Exception { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1729 |
// Handle password supplied via stdin |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1730 |
if (System.console() == null) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1731 |
char[] importPass = Password.readPassword(System.in); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1732 |
passwords.add(importPass); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1733 |
return importPass; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1734 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1735 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1736 |
int count; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1737 |
for (count = 0; count < 3; count++) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1738 |
System.err.print( |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1739 |
rb.getString("Enter.the.password.to.be.stored.")); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1740 |
System.err.flush(); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1741 |
char[] entered = Password.readPassword(System.in); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1742 |
passwords.add(entered); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1743 |
System.err.print(rb.getString("Re.enter.password.")); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1744 |
char[] passAgain = Password.readPassword(System.in); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1745 |
passwords.add(passAgain); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1746 |
if (!Arrays.equals(entered, passAgain)) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1747 |
System.err.println(rb.getString("They.don.t.match.Try.again")); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1748 |
continue; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1749 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1750 |
return entered; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1751 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1752 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1753 |
if (count == 3) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1754 |
throw new Exception(rb.getString |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1755 |
("Too.many.failures.key.not.added.to.keystore")); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1756 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1757 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1758 |
return null; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1759 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1760 |
|
2 | 1761 |
/** |
1762 |
* Creates a new secret key. |
|
1763 |
*/ |
|
1764 |
private void doGenSecretKey(String alias, String keyAlgName, |
|
1765 |
int keysize) |
|
1766 |
throws Exception |
|
1767 |
{ |
|
1768 |
if (alias == null) { |
|
1769 |
alias = keyAlias; |
|
1770 |
} |
|
1771 |
if (keyStore.containsAlias(alias)) { |
|
1772 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1773 |
("Secret.key.not.generated.alias.alias.already.exists")); |
2 | 1774 |
Object[] source = {alias}; |
1775 |
throw new Exception(form.format(source)); |
|
1776 |
} |
|
1777 |
||
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1778 |
// Use the keystore's default PBE algorithm for entry protection |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1779 |
boolean useDefaultPBEAlgorithm = true; |
2 | 1780 |
SecretKey secKey = null; |
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1781 |
|
25402
0c24d9aa8fb9
7065233: To interpret case-insensitive string locale independently
juh
parents:
25186
diff
changeset
|
1782 |
if (keyAlgName.toUpperCase(Locale.ENGLISH).startsWith("PBE")) { |
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1783 |
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE"); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1784 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1785 |
// User is prompted for PBE credential |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1786 |
secKey = |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1787 |
factory.generateSecret(new PBEKeySpec(promptForCredential())); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1788 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1789 |
// Check whether a specific PBE algorithm was specified |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1790 |
if (!"PBE".equalsIgnoreCase(keyAlgName)) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1791 |
useDefaultPBEAlgorithm = false; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1792 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1793 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1794 |
if (verbose) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1795 |
MessageFormat form = new MessageFormat(rb.getString( |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1796 |
"Generated.keyAlgName.secret.key")); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1797 |
Object[] source = |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1798 |
{useDefaultPBEAlgorithm ? "PBE" : secKey.getAlgorithm()}; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1799 |
System.err.println(form.format(source)); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1800 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1801 |
} else { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1802 |
KeyGenerator keygen = KeyGenerator.getInstance(keyAlgName); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1803 |
if (keysize == -1) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1804 |
if ("DES".equalsIgnoreCase(keyAlgName)) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1805 |
keysize = 56; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1806 |
} else if ("DESede".equalsIgnoreCase(keyAlgName)) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1807 |
keysize = 168; |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1808 |
} else { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1809 |
throw new Exception(rb.getString |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1810 |
("Please.provide.keysize.for.secret.key.generation")); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1811 |
} |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1812 |
} |
2 | 1813 |
keygen.init(keysize); |
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1814 |
secKey = keygen.generateKey(); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1815 |
|
52598
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1816 |
MessageFormat form = new MessageFormat(rb.getString |
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1817 |
("Generated.keysize.bit.keyAlgName.secret.key")); |
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1818 |
Object[] source = {keysize, |
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1819 |
secKey.getAlgorithm()}; |
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1820 |
System.err.println(form.format(source)); |
2 | 1821 |
} |
1822 |
||
1823 |
if (keyPass == null) { |
|
1824 |
keyPass = promptForKeyPass(alias, null, storePass); |
|
1825 |
} |
|
20516
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1826 |
|
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1827 |
if (useDefaultPBEAlgorithm) { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1828 |
keyStore.setKeyEntry(alias, secKey, keyPass, null); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1829 |
} else { |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1830 |
keyStore.setEntry(alias, new KeyStore.SecretKeyEntry(secKey), |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1831 |
new KeyStore.PasswordProtection(keyPass, keyAlgName, null)); |
fa2edce67c48
8008296: keytool utility doesn't support '-importpassword' command
vinnie
parents:
19043
diff
changeset
|
1832 |
} |
2 | 1833 |
} |
1834 |
||
1835 |
/** |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1836 |
* If no signature algorithm was specified at the command line, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1837 |
* we choose one that is compatible with the selected private key |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1838 |
*/ |
38439 | 1839 |
private static String getCompatibleSigAlgName(PrivateKey key) |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1840 |
throws Exception { |
38439 | 1841 |
String result = AlgorithmId.getDefaultSigAlgForKey(key); |
1842 |
if (result != null) { |
|
1843 |
return result; |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1844 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1845 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1846 |
("Cannot.derive.signature.algorithm")); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1847 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1848 |
} |
38439 | 1849 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1850 |
/** |
2 | 1851 |
* Creates a new key pair and self-signed certificate. |
1852 |
*/ |
|
1853 |
private void doGenKeyPair(String alias, String dname, String keyAlgName, |
|
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1854 |
int keysize, String groupName, String sigAlgName) |
2 | 1855 |
throws Exception |
1856 |
{ |
|
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1857 |
if (groupName != null) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1858 |
if (keysize != -1) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1859 |
throw new Exception(rb.getString("groupname.keysize.coexist")); |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1860 |
} |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1861 |
} else { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1862 |
if (keysize == -1) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1863 |
if ("EC".equalsIgnoreCase(keyAlgName)) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1864 |
keysize = SecurityProviderConstants.DEF_EC_KEY_SIZE; |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1865 |
} else if ("RSA".equalsIgnoreCase(keyAlgName)) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1866 |
keysize = SecurityProviderConstants.DEF_RSA_KEY_SIZE; |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1867 |
} else if ("DSA".equalsIgnoreCase(keyAlgName)) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1868 |
keysize = SecurityProviderConstants.DEF_DSA_KEY_SIZE; |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1869 |
} |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1870 |
} else { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1871 |
if ("EC".equalsIgnoreCase(keyAlgName)) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1872 |
weakWarnings.add(String.format( |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1873 |
rb.getString("deprecate.keysize.for.ec"), |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1874 |
ecGroupNameForSize(keysize))); |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1875 |
} |
2 | 1876 |
} |
1877 |
} |
|
1878 |
||
1879 |
if (alias == null) { |
|
1880 |
alias = keyAlias; |
|
1881 |
} |
|
1882 |
||
1883 |
if (keyStore.containsAlias(alias)) { |
|
1884 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1885 |
("Key.pair.not.generated.alias.alias.already.exists")); |
2 | 1886 |
Object[] source = {alias}; |
1887 |
throw new Exception(form.format(source)); |
|
1888 |
} |
|
1889 |
||
1890 |
CertAndKeyGen keypair = |
|
1891 |
new CertAndKeyGen(keyAlgName, sigAlgName, providerName); |
|
1892 |
||
1893 |
||
1894 |
// If DN is provided, parse it. Otherwise, prompt the user for it. |
|
1895 |
X500Name x500Name; |
|
1896 |
if (dname == null) { |
|
52598
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1897 |
printWeakWarnings(true); |
2 | 1898 |
x500Name = getX500Name(); |
1899 |
} else { |
|
1900 |
x500Name = new X500Name(dname); |
|
1901 |
} |
|
1902 |
||
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1903 |
if (groupName != null) { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1904 |
keypair.generate(groupName); |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1905 |
} else { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1906 |
// This covers keysize both specified and unspecified |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1907 |
keypair.generate(keysize); |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1908 |
} |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1909 |
|
2 | 1910 |
PrivateKey privKey = keypair.getPrivateKey(); |
1911 |
||
11012
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1912 |
CertificateExtensions ext = createV3Extensions( |
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1913 |
null, |
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1914 |
null, |
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1915 |
v3ext, |
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1916 |
keypair.getPublicKeyAnyway(), |
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1917 |
null); |
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1918 |
|
2 | 1919 |
X509Certificate[] chain = new X509Certificate[1]; |
1920 |
chain[0] = keypair.getSelfCertificate( |
|
11012
13ee761ef120
7109096: keytool -genkeypair needn't call -selfcert
weijun
parents:
10782
diff
changeset
|
1921 |
x500Name, getStartDate(startDate), validity*24L*60L*60L, ext); |
2 | 1922 |
|
52598
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1923 |
MessageFormat form = new MessageFormat(rb.getString |
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1924 |
("Generating.keysize.bit.keyAlgName.key.pair.and.self.signed.certificate.sigAlgName.with.a.validity.of.validality.days.for")); |
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
1925 |
Object[] source = { |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
1926 |
groupName == null ? keysize : KeyUtil.getKeySize(privKey), |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
1927 |
fullDisplayAlgName(privKey), |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
1928 |
chain[0].getSigAlgName(), |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
1929 |
validity, |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
1930 |
x500Name}; |
52598
0379b618ec46
8212003: Deprecating the default keytool -keyalg option
weijun
parents:
52511
diff
changeset
|
1931 |
System.err.println(form.format(source)); |
2 | 1932 |
|
1933 |
if (keyPass == null) { |
|
1934 |
keyPass = promptForKeyPass(alias, null, storePass); |
|
1935 |
} |
|
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
1936 |
checkWeak(rb.getString("the.generated.certificate"), chain[0]); |
2 | 1937 |
keyStore.setKeyEntry(alias, privKey, keyPass, chain); |
1938 |
} |
|
1939 |
||
52511
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1940 |
private String ecGroupNameForSize(int size) throws Exception { |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1941 |
AlgorithmParameters ap = AlgorithmParameters.getInstance("EC"); |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1942 |
ap.init(new ECKeySizeParameterSpec(size)); |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1943 |
// The following line assumes the toString value is "name (oid)" |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1944 |
return ap.toString().split(" ")[0]; |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1945 |
} |
ddcbc20e8c6a
8213400: Support choosing group name in keytool keypair generation
weijun
parents:
51373
diff
changeset
|
1946 |
|
2 | 1947 |
/** |
1948 |
* Clones an entry |
|
1949 |
* @param orig original alias |
|
1950 |
* @param dest destination alias |
|
1951 |
* @changePassword if the password can be changed |
|
1952 |
*/ |
|
1953 |
private void doCloneEntry(String orig, String dest, boolean changePassword) |
|
1954 |
throws Exception |
|
1955 |
{ |
|
1956 |
if (orig == null) { |
|
1957 |
orig = keyAlias; |
|
1958 |
} |
|
1959 |
||
1960 |
if (keyStore.containsAlias(dest)) { |
|
1961 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
1962 |
(rb.getString("Destination.alias.dest.already.exists")); |
2 | 1963 |
Object[] source = {dest}; |
1964 |
throw new Exception(form.format(source)); |
|
1965 |
} |
|
1966 |
||
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1967 |
Pair<Entry,char[]> objs = recoverEntry(keyStore, orig, storePass, keyPass); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1968 |
Entry entry = objs.fst; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1969 |
keyPass = objs.snd; |
2 | 1970 |
|
1971 |
PasswordProtection pp = null; |
|
1972 |
||
1973 |
if (keyPass != null) { // protected |
|
1974 |
if (!changePassword || P12KEYSTORE.equalsIgnoreCase(storetype)) { |
|
1975 |
keyPassNew = keyPass; |
|
1976 |
} else { |
|
1977 |
if (keyPassNew == null) { |
|
1978 |
keyPassNew = promptForKeyPass(dest, orig, keyPass); |
|
1979 |
} |
|
1980 |
} |
|
1981 |
pp = new PasswordProtection(keyPassNew); |
|
1982 |
} |
|
1983 |
keyStore.setEntry(dest, entry, pp); |
|
1984 |
} |
|
1985 |
||
1986 |
/** |
|
1987 |
* Changes a key password. |
|
1988 |
*/ |
|
1989 |
private void doChangeKeyPasswd(String alias) throws Exception |
|
1990 |
{ |
|
1991 |
||
1992 |
if (alias == null) { |
|
1993 |
alias = keyAlias; |
|
1994 |
} |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1995 |
Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1996 |
Key privKey = objs.fst; |
2 | 1997 |
if (keyPass == null) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
1998 |
keyPass = objs.snd; |
2 | 1999 |
} |
2000 |
||
2001 |
if (keyPassNew == null) { |
|
2002 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2003 |
(rb.getString("key.password.for.alias.")); |
2 | 2004 |
Object[] source = {alias}; |
2005 |
keyPassNew = getNewPasswd(form.format(source), keyPass); |
|
2006 |
} |
|
2007 |
keyStore.setKeyEntry(alias, privKey, keyPassNew, |
|
2008 |
keyStore.getCertificateChain(alias)); |
|
2009 |
} |
|
2010 |
||
2011 |
/** |
|
2012 |
* Imports a JDK 1.1-style identity database. We can only store one |
|
2013 |
* certificate per identity, because we use the identity's name as the |
|
2014 |
* alias (which references a keystore entry), and aliases must be unique. |
|
2015 |
*/ |
|
2016 |
private void doImportIdentityDatabase(InputStream in) |
|
2017 |
throws Exception |
|
2018 |
{ |
|
4350
2a593a20d962
6876158: Remove dependencies on Signer, Certificate, Identity, IdentityScope classes from java.security pkg
vinnie
parents:
4169
diff
changeset
|
2019 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2020 |
("No.entries.from.identity.database.added")); |
2 | 2021 |
} |
2022 |
||
2023 |
/** |
|
2024 |
* Prints a single keystore entry. |
|
2025 |
*/ |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2026 |
private void doPrintEntry(String label, String alias, PrintStream out) |
2 | 2027 |
throws Exception |
2028 |
{ |
|
2029 |
if (keyStore.containsAlias(alias) == false) { |
|
2030 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2031 |
(rb.getString("Alias.alias.does.not.exist")); |
2 | 2032 |
Object[] source = {alias}; |
2033 |
throw new Exception(form.format(source)); |
|
2034 |
} |
|
2035 |
||
2036 |
if (verbose || rfc || debug) { |
|
2037 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2038 |
(rb.getString("Alias.name.alias")); |
2 | 2039 |
Object[] source = {alias}; |
2040 |
out.println(form.format(source)); |
|
2041 |
||
2042 |
if (!token) { |
|
2043 |
form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2044 |
("Creation.date.keyStore.getCreationDate.alias.")); |
2 | 2045 |
Object[] src = {keyStore.getCreationDate(alias)}; |
2046 |
out.println(form.format(src)); |
|
2047 |
} |
|
2048 |
} else { |
|
2049 |
if (!token) { |
|
2050 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2051 |
(rb.getString("alias.keyStore.getCreationDate.alias.")); |
2 | 2052 |
Object[] source = {alias, keyStore.getCreationDate(alias)}; |
2053 |
out.print(form.format(source)); |
|
2054 |
} else { |
|
2055 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2056 |
(rb.getString("alias.")); |
2 | 2057 |
Object[] source = {alias}; |
2058 |
out.print(form.format(source)); |
|
2059 |
} |
|
2060 |
} |
|
2061 |
||
2062 |
if (keyStore.entryInstanceOf(alias, KeyStore.SecretKeyEntry.class)) { |
|
2063 |
if (verbose || rfc || debug) { |
|
2064 |
Object[] source = {"SecretKeyEntry"}; |
|
2065 |
out.println(new MessageFormat( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2066 |
rb.getString("Entry.type.type.")).format(source)); |
2 | 2067 |
} else { |
2068 |
out.println("SecretKeyEntry, "); |
|
2069 |
} |
|
2070 |
} else if (keyStore.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { |
|
2071 |
if (verbose || rfc || debug) { |
|
2072 |
Object[] source = {"PrivateKeyEntry"}; |
|
2073 |
out.println(new MessageFormat( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2074 |
rb.getString("Entry.type.type.")).format(source)); |
2 | 2075 |
} else { |
2076 |
out.println("PrivateKeyEntry, "); |
|
2077 |
} |
|
2078 |
||
2079 |
// Get the chain |
|
2080 |
Certificate[] chain = keyStore.getCertificateChain(alias); |
|
2081 |
if (chain != null) { |
|
2082 |
if (verbose || rfc || debug) { |
|
2083 |
out.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2084 |
("Certificate.chain.length.") + chain.length); |
2 | 2085 |
for (int i = 0; i < chain.length; i ++) { |
2086 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2087 |
(rb.getString("Certificate.i.1.")); |
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
25402
diff
changeset
|
2088 |
Object[] source = {(i + 1)}; |
2 | 2089 |
out.println(form.format(source)); |
2090 |
if (verbose && (chain[i] instanceof X509Certificate)) { |
|
2091 |
printX509Cert((X509Certificate)(chain[i]), out); |
|
2092 |
} else if (debug) { |
|
2093 |
out.println(chain[i].toString()); |
|
2094 |
} else { |
|
2095 |
dumpCert(chain[i], out); |
|
2096 |
} |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2097 |
checkWeak(label, chain[i]); |
2 | 2098 |
} |
2099 |
} else { |
|
2100 |
// Print the digest of the user cert only |
|
2101 |
out.println |
|
34381
be5600f6a4da
8141457: keytool default cert fingerprint algorithm should be SHA-256
weijun
parents:
31426
diff
changeset
|
2102 |
(rb.getString("Certificate.fingerprint.SHA.256.") + |
be5600f6a4da
8141457: keytool default cert fingerprint algorithm should be SHA-256
weijun
parents:
31426
diff
changeset
|
2103 |
getCertFingerPrint("SHA-256", chain[0])); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2104 |
checkWeak(label, chain); |
2 | 2105 |
} |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2106 |
} else { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2107 |
out.println(rb.getString |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2108 |
("Certificate.chain.length.") + 0); |
2 | 2109 |
} |
2110 |
} else if (keyStore.entryInstanceOf(alias, |
|
2111 |
KeyStore.TrustedCertificateEntry.class)) { |
|
2112 |
// We have a trusted certificate entry |
|
2113 |
Certificate cert = keyStore.getCertificate(alias); |
|
9011
c08eb9697ee4
7019937: Translatability bug - Remove Unused String - String ID , read end of file
mullan
parents:
8556
diff
changeset
|
2114 |
Object[] source = {"trustedCertEntry"}; |
c08eb9697ee4
7019937: Translatability bug - Remove Unused String - String ID , read end of file
mullan
parents:
8556
diff
changeset
|
2115 |
String mf = new MessageFormat( |
c08eb9697ee4
7019937: Translatability bug - Remove Unused String - String ID , read end of file
mullan
parents:
8556
diff
changeset
|
2116 |
rb.getString("Entry.type.type.")).format(source) + "\n"; |
2 | 2117 |
if (verbose && (cert instanceof X509Certificate)) { |
9011
c08eb9697ee4
7019937: Translatability bug - Remove Unused String - String ID , read end of file
mullan
parents:
8556
diff
changeset
|
2118 |
out.println(mf); |
2 | 2119 |
printX509Cert((X509Certificate)cert, out); |
2120 |
} else if (rfc) { |
|
9011
c08eb9697ee4
7019937: Translatability bug - Remove Unused String - String ID , read end of file
mullan
parents:
8556
diff
changeset
|
2121 |
out.println(mf); |
2 | 2122 |
dumpCert(cert, out); |
2123 |
} else if (debug) { |
|
2124 |
out.println(cert.toString()); |
|
2125 |
} else { |
|
9011
c08eb9697ee4
7019937: Translatability bug - Remove Unused String - String ID , read end of file
mullan
parents:
8556
diff
changeset
|
2126 |
out.println("trustedCertEntry, "); |
34381
be5600f6a4da
8141457: keytool default cert fingerprint algorithm should be SHA-256
weijun
parents:
31426
diff
changeset
|
2127 |
out.println(rb.getString("Certificate.fingerprint.SHA.256.") |
be5600f6a4da
8141457: keytool default cert fingerprint algorithm should be SHA-256
weijun
parents:
31426
diff
changeset
|
2128 |
+ getCertFingerPrint("SHA-256", cert)); |
2 | 2129 |
} |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2130 |
checkWeak(label, cert); |
2 | 2131 |
} else { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2132 |
out.println(rb.getString("Unknown.Entry.Type")); |
2 | 2133 |
} |
2134 |
} |
|
2135 |
||
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2136 |
boolean inplaceImportCheck() throws Exception { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2137 |
if (P11KEYSTORE.equalsIgnoreCase(srcstoretype) || |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2138 |
KeyStoreUtil.isWindowsKeyStore(srcstoretype)) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2139 |
return false; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2140 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2141 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2142 |
if (srcksfname != null) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2143 |
File srcksfile = new File(srcksfname); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2144 |
if (srcksfile.exists() && srcksfile.length() == 0) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2145 |
throw new Exception(rb.getString |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2146 |
("Source.keystore.file.exists.but.is.empty.") + |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2147 |
srcksfname); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2148 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2149 |
if (srcksfile.getCanonicalFile() |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2150 |
.equals(new File(ksfname).getCanonicalFile())) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2151 |
return true; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2152 |
} else { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2153 |
// Informational, especially if destkeystore is not |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2154 |
// provided, which default to ~/.keystore. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2155 |
System.err.println(String.format(rb.getString( |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2156 |
"importing.keystore.status"), srcksfname, ksfname)); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2157 |
return false; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2158 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2159 |
} else { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2160 |
throw new Exception(rb.getString |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2161 |
("Please.specify.srckeystore")); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2162 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2163 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2164 |
|
2 | 2165 |
/** |
2166 |
* Load the srckeystore from a stream, used in -importkeystore |
|
30374 | 2167 |
* @return the src KeyStore |
2 | 2168 |
*/ |
2169 |
KeyStore loadSourceKeyStore() throws Exception { |
|
2170 |
||
2171 |
InputStream is = null; |
|
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2172 |
File srcksfile = null; |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2173 |
boolean srcIsPasswordless = false; |
2 | 2174 |
|
2175 |
if (P11KEYSTORE.equalsIgnoreCase(srcstoretype) || |
|
2176 |
KeyStoreUtil.isWindowsKeyStore(srcstoretype)) { |
|
2177 |
if (!NONE.equals(srcksfname)) { |
|
2178 |
System.err.println(MessageFormat.format(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2179 |
(".keystore.must.be.NONE.if.storetype.is.{0}"), srcstoretype)); |
2 | 2180 |
System.err.println(); |
2181 |
tinyHelp(); |
|
2182 |
} |
|
2183 |
} else { |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2184 |
srcksfile = new File(srcksfname); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2185 |
is = new FileInputStream(srcksfile); |
2 | 2186 |
} |
2187 |
||
2188 |
KeyStore store; |
|
2189 |
try { |
|
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2190 |
// Probe for keystore type when filename is available |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2191 |
if (srcksfile != null && is != null && srcProviderName == null && |
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
2192 |
srcstoretype == null) { |
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2193 |
store = KeyStore.getInstance(srcksfile, srcstorePass); |
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
2194 |
srcstoretype = store.getType(); |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2195 |
if (srcstoretype.equalsIgnoreCase("pkcs12")) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2196 |
srcIsPasswordless = PKCS12KeyStore.isPasswordless(srcksfile); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2197 |
} |
2 | 2198 |
} else { |
48216
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
2199 |
if (srcstoretype == null) { |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
2200 |
srcstoretype = KeyStore.getDefaultType(); |
e3b6cb90d7ce
8192987: keytool should remember real storetype if it is not provided
weijun
parents:
48050
diff
changeset
|
2201 |
} |
28243
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2202 |
if (srcProviderName == null) { |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2203 |
store = KeyStore.getInstance(srcstoretype); |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2204 |
} else { |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2205 |
store = KeyStore.getInstance(srcstoretype, srcProviderName); |
47080f9ae750
8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents:
27344
diff
changeset
|
2206 |
} |
2 | 2207 |
} |
2208 |
||
2209 |
if (srcstorePass == null |
|
2210 |
&& !srcprotectedPath |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2211 |
&& !KeyStoreUtil.isWindowsKeyStore(srcstoretype) |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2212 |
&& !srcIsPasswordless) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2213 |
System.err.print(rb.getString("Enter.source.keystore.password.")); |
2 | 2214 |
System.err.flush(); |
2215 |
srcstorePass = Password.readPassword(System.in); |
|
2216 |
passwords.add(srcstorePass); |
|
2217 |
} |
|
2218 |
||
2219 |
// always let keypass be storepass when using pkcs12 |
|
2220 |
if (P12KEYSTORE.equalsIgnoreCase(srcstoretype)) { |
|
2221 |
if (srckeyPass != null && srcstorePass != null && |
|
2222 |
!Arrays.equals(srcstorePass, srckeyPass)) { |
|
2223 |
MessageFormat form = new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2224 |
"Warning.Different.store.and.key.passwords.not.supported.for.PKCS12.KeyStores.Ignoring.user.specified.command.value.")); |
2 | 2225 |
Object[] source = {"-srckeypass"}; |
2226 |
System.err.println(form.format(source)); |
|
2227 |
srckeyPass = srcstorePass; |
|
2228 |
} |
|
2229 |
} |
|
2230 |
||
2231 |
store.load(is, srcstorePass); // "is" already null in PKCS11 |
|
2232 |
} finally { |
|
2233 |
if (is != null) { |
|
2234 |
is.close(); |
|
2235 |
} |
|
2236 |
} |
|
2237 |
||
2238 |
if (srcstorePass == null |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
2239 |
&& !srcIsPasswordless |
2 | 2240 |
&& !KeyStoreUtil.isWindowsKeyStore(srcstoretype)) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2241 |
// anti refactoring, copied from printNoIntegrityWarning(), |
2 | 2242 |
// but change 2 lines |
2243 |
System.err.println(); |
|
2244 |
System.err.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2245 |
(".WARNING.WARNING.WARNING.")); |
2 | 2246 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2247 |
(".The.integrity.of.the.information.stored.in.the.srckeystore.")); |
2 | 2248 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2249 |
(".WARNING.WARNING.WARNING.")); |
2 | 2250 |
System.err.println(); |
2251 |
} |
|
2252 |
||
2253 |
return store; |
|
2254 |
} |
|
2255 |
||
2256 |
/** |
|
2257 |
* import all keys and certs from importkeystore. |
|
2258 |
* keep alias unchanged if no name conflict, otherwise, prompt. |
|
2259 |
* keep keypass unchanged for keys |
|
2260 |
*/ |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2261 |
private void doImportKeyStore(KeyStore srcKS) throws Exception { |
2 | 2262 |
|
2263 |
if (alias != null) { |
|
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2264 |
doImportKeyStoreSingle(srcKS, alias); |
2 | 2265 |
} else { |
16720
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2266 |
if (dest != null || srckeyPass != null) { |
2 | 2267 |
throw new Exception(rb.getString( |
16720
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2268 |
"if.alias.not.specified.destalias.and.srckeypass.must.not.be.specified")); |
2 | 2269 |
} |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2270 |
doImportKeyStoreAll(srcKS); |
2 | 2271 |
} |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2272 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2273 |
if (inplaceImport) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2274 |
// Backup to file.old or file.old2... |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2275 |
// The keystore is not rewritten yet now. |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2276 |
for (int n = 1; /* forever */; n++) { |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2277 |
inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2278 |
File bkFile = new File(inplaceBackupName); |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2279 |
if (!bkFile.exists()) { |
49285
4d2e3f5abb48
8194746: (fs) Add equivalents of Paths.get to Path interface
bpb
parents:
48608
diff
changeset
|
2280 |
Files.copy(Path.of(srcksfname), bkFile.toPath()); |
47420
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2281 |
break; |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2282 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2283 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2284 |
|
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2285 |
} |
a2bf68a0365f
8182879: Add warnings to keytool when using JKS and JCEKS
weijun
parents:
47216
diff
changeset
|
2286 |
|
2 | 2287 |
/* |
2288 |
* Information display rule of -importkeystore |
|
2289 |
* 1. inside single, shows failure |
|
2290 |
* 2. inside all, shows sucess |
|
2291 |
* 3. inside all where there is a failure, prompt for continue |
|
2292 |
* 4. at the final of all, shows summary |
|
2293 |
*/ |
|
2294 |
} |
|
2295 |
||
2296 |
/** |
|
2297 |
* Import a single entry named alias from srckeystore |
|
30374 | 2298 |
* @return 1 if the import action succeed |
2 | 2299 |
* 0 if user choose to ignore an alias-dumplicated entry |
2300 |
* 2 if setEntry throws Exception |
|
2301 |
*/ |
|
2302 |
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias) |
|
2303 |
throws Exception { |
|
2304 |
||
2305 |
String newAlias = (dest==null) ? alias : dest; |
|
2306 |
||
2307 |
if (keyStore.containsAlias(newAlias)) { |
|
2308 |
Object[] source = {alias}; |
|
2309 |
if (noprompt) { |
|
2310 |
System.err.println(new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2311 |
"Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source)); |
2 | 2312 |
} else { |
2313 |
String reply = getYesNoReply(new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2314 |
"Existing.entry.alias.alias.exists.overwrite.no.")).format(source)); |
2 | 2315 |
if ("NO".equals(reply)) { |
2316 |
newAlias = inputStringFromStdin(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2317 |
("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry.")); |
2 | 2318 |
if ("".equals(newAlias)) { |
2319 |
System.err.println(new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2320 |
"Entry.for.alias.alias.not.imported.")).format( |
2 | 2321 |
source)); |
2322 |
return 0; |
|
2323 |
} |
|
2324 |
} |
|
2325 |
} |
|
2326 |
} |
|
2327 |
||
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2328 |
Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2329 |
Entry entry = objs.fst; |
2 | 2330 |
|
2331 |
PasswordProtection pp = null; |
|
2332 |
||
2333 |
// According to keytool.html, "The destination entry will be protected |
|
2334 |
// using destkeypass. If destkeypass is not provided, the destination |
|
2335 |
// entry will be protected with the source entry password." |
|
2336 |
// so always try to protect with destKeyPass. |
|
16720
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2337 |
char[] newPass = null; |
2 | 2338 |
if (destKeyPass != null) { |
16720
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2339 |
newPass = destKeyPass; |
2 | 2340 |
pp = new PasswordProtection(destKeyPass); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2341 |
} else if (objs.snd != null) { |
48333
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2342 |
newPass = P12KEYSTORE.equalsIgnoreCase(storetype) ? |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2343 |
storePass : objs.snd; |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2344 |
pp = new PasswordProtection(newPass); |
2 | 2345 |
} |
2346 |
||
2347 |
try { |
|
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
2348 |
Certificate c = srckeystore.getCertificate(alias); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
2349 |
if (c != null) { |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
2350 |
checkWeak("<" + newAlias + ">", c); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
2351 |
} |
2 | 2352 |
keyStore.setEntry(newAlias, entry, pp); |
16720
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2353 |
// Place the check so that only successful imports are blocked. |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2354 |
// For example, we don't block a failed SecretEntry import. |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2355 |
if (P12KEYSTORE.equalsIgnoreCase(storetype)) { |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2356 |
if (newPass != null && !Arrays.equals(newPass, storePass)) { |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2357 |
throw new Exception(rb.getString( |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2358 |
"The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified.")); |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2359 |
} |
0e7e9e6ed98a
8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
16020
diff
changeset
|
2360 |
} |
2 | 2361 |
return 1; |
2362 |
} catch (KeyStoreException kse) { |
|
2363 |
Object[] source2 = {alias, kse.toString()}; |
|
2364 |
MessageFormat form = new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2365 |
"Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported.")); |
2 | 2366 |
System.err.println(form.format(source2)); |
2367 |
return 2; |
|
2368 |
} |
|
2369 |
} |
|
2370 |
||
2371 |
private void doImportKeyStoreAll(KeyStore srckeystore) throws Exception { |
|
2372 |
||
2373 |
int ok = 0; |
|
2374 |
int count = srckeystore.size(); |
|
2375 |
for (Enumeration<String> e = srckeystore.aliases(); |
|
2376 |
e.hasMoreElements(); ) { |
|
2377 |
String alias = e.nextElement(); |
|
2378 |
int result = doImportKeyStoreSingle(srckeystore, alias); |
|
2379 |
if (result == 1) { |
|
2380 |
ok++; |
|
2381 |
Object[] source = {alias}; |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2382 |
MessageFormat form = new MessageFormat(rb.getString("Entry.for.alias.alias.successfully.imported.")); |
2 | 2383 |
System.err.println(form.format(source)); |
2384 |
} else if (result == 2) { |
|
2385 |
if (!noprompt) { |
|
2386 |
String reply = getYesNoReply("Do you want to quit the import process? [no]: "); |
|
2387 |
if ("YES".equals(reply)) { |
|
2388 |
break; |
|
2389 |
} |
|
2390 |
} |
|
2391 |
} |
|
2392 |
} |
|
2393 |
Object[] source = {ok, count-ok}; |
|
2394 |
MessageFormat form = new MessageFormat(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2395 |
"Import.command.completed.ok.entries.successfully.imported.fail.entries.failed.or.cancelled")); |
2 | 2396 |
System.err.println(form.format(source)); |
2397 |
} |
|
2398 |
||
2399 |
/** |
|
2400 |
* Prints all keystore entries. |
|
2401 |
*/ |
|
2402 |
private void doPrintEntries(PrintStream out) |
|
2403 |
throws Exception |
|
2404 |
{ |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2405 |
out.println(rb.getString("Keystore.type.") + keyStore.getType()); |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2406 |
out.println(rb.getString("Keystore.provider.") + |
2 | 2407 |
keyStore.getProvider().getName()); |
2408 |
out.println(); |
|
2409 |
||
2410 |
MessageFormat form; |
|
2411 |
form = (keyStore.size() == 1) ? |
|
2412 |
new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2413 |
("Your.keystore.contains.keyStore.size.entry")) : |
2 | 2414 |
new MessageFormat(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2415 |
("Your.keystore.contains.keyStore.size.entries")); |
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
25402
diff
changeset
|
2416 |
Object[] source = {keyStore.size()}; |
2 | 2417 |
out.println(form.format(source)); |
2418 |
out.println(); |
|
2419 |
||
55412
55a79ffab804
8225392: Comparison builds are failing due to cacerts file
weijun
parents:
54827
diff
changeset
|
2420 |
List<String> aliases = Collections.list(keyStore.aliases()); |
55a79ffab804
8225392: Comparison builds are failing due to cacerts file
weijun
parents:
54827
diff
changeset
|
2421 |
aliases.sort(String::compareTo); |
55a79ffab804
8225392: Comparison builds are failing due to cacerts file
weijun
parents:
54827
diff
changeset
|
2422 |
for (String alias : aliases) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2423 |
doPrintEntry("<" + alias + ">", alias, out); |
2 | 2424 |
if (verbose || rfc) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2425 |
out.println(rb.getString("NEWLINE")); |
2 | 2426 |
out.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2427 |
("STAR")); |
2 | 2428 |
out.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2429 |
("STARNN")); |
2 | 2430 |
} |
2431 |
} |
|
2432 |
} |
|
2433 |
||
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2434 |
private static <T> Iterable<T> e2i(final Enumeration<T> e) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2435 |
return new Iterable<T>() { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2436 |
@Override |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2437 |
public Iterator<T> iterator() { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2438 |
return new Iterator<T>() { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2439 |
@Override |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2440 |
public boolean hasNext() { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2441 |
return e.hasMoreElements(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2442 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2443 |
@Override |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2444 |
public T next() { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2445 |
return e.nextElement(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2446 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2447 |
public void remove() { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2448 |
throw new UnsupportedOperationException("Not supported yet."); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2449 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2450 |
}; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2451 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2452 |
}; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2453 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2454 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2455 |
/** |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2456 |
* Loads CRLs from a source. This method is also called in JarSigner. |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2457 |
* @param src the source, which means System.in if null, or a URI, |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2458 |
* or a bare file path name |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2459 |
*/ |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2460 |
public static Collection<? extends CRL> loadCRLs(String src) throws Exception { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2461 |
InputStream in = null; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2462 |
URI uri = null; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2463 |
if (src == null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2464 |
in = System.in; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2465 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2466 |
try { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2467 |
uri = new URI(src); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2468 |
if (uri.getScheme().equals("ldap")) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2469 |
// No input stream for LDAP |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2470 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2471 |
in = uri.toURL().openStream(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2472 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2473 |
} catch (Exception e) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2474 |
try { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2475 |
in = new FileInputStream(src); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2476 |
} catch (Exception e2) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2477 |
if (uri == null || uri.getScheme() == null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2478 |
throw e2; // More likely a bare file path |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2479 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2480 |
throw e; // More likely a protocol or network problem |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2481 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2482 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2483 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2484 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2485 |
if (in != null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2486 |
try { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2487 |
// Read the full stream before feeding to X509Factory, |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2488 |
// otherwise, keytool -gencrl | keytool -printcrl |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2489 |
// might not work properly, since -gencrl is slow |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2490 |
// and there's no data in the pipe at the beginning. |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2491 |
ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2492 |
byte[] b = new byte[4096]; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2493 |
while (true) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2494 |
int len = in.read(b); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2495 |
if (len < 0) break; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2496 |
bout.write(b, 0, len); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2497 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2498 |
return CertificateFactory.getInstance("X509").generateCRLs( |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2499 |
new ByteArrayInputStream(bout.toByteArray())); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2500 |
} finally { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2501 |
if (in != System.in) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2502 |
in.close(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2503 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2504 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2505 |
} else { // must be LDAP, and uri is not null |
30506
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
2506 |
URICertStoreParameters params = |
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
2507 |
new URICertStoreParameters(uri); |
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
2508 |
CertStore s = CertStore.getInstance("LDAP", params); |
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
2509 |
return s.getCRLs(new X509CRLSelector()); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2510 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2511 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2512 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2513 |
/** |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2514 |
* Returns CRLs described in a X509Certificate's CRLDistributionPoints |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2515 |
* Extension. Only those containing a general name of type URI are read. |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2516 |
*/ |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2517 |
public static List<CRL> readCRLsFromCert(X509Certificate cert) |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2518 |
throws Exception { |
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
2519 |
List<CRL> crls = new ArrayList<>(); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2520 |
CRLDistributionPointsExtension ext = |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2521 |
X509CertImpl.toImpl(cert).getCRLDistributionPointsExtension(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2522 |
if (ext == null) return crls; |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
10051
diff
changeset
|
2523 |
List<DistributionPoint> distPoints = |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
10051
diff
changeset
|
2524 |
ext.get(CRLDistributionPointsExtension.POINTS); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
10051
diff
changeset
|
2525 |
for (DistributionPoint o: distPoints) { |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2526 |
GeneralNames names = o.getFullName(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2527 |
if (names != null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2528 |
for (GeneralName name: names.names()) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2529 |
if (name.getType() == GeneralNameInterface.NAME_URI) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2530 |
URIName uriName = (URIName)name.getName(); |
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
2531 |
for (CRL crl: loadCRLs(uriName.getName())) { |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2532 |
if (crl instanceof X509CRL) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2533 |
crls.add((X509CRL)crl); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2534 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2535 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2536 |
break; // Different name should point to same CRL |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2537 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2538 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2539 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2540 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2541 |
return crls; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2542 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2543 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2544 |
private static String verifyCRL(KeyStore ks, CRL crl) |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2545 |
throws Exception { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2546 |
X509CRLImpl xcrl = (X509CRLImpl)crl; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2547 |
X500Principal issuer = xcrl.getIssuerX500Principal(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2548 |
for (String s: e2i(ks.aliases())) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2549 |
Certificate cert = ks.getCertificate(s); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2550 |
if (cert instanceof X509Certificate) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2551 |
X509Certificate xcert = (X509Certificate)cert; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2552 |
if (xcert.getSubjectX500Principal().equals(issuer)) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2553 |
try { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2554 |
((X509CRLImpl)crl).verify(cert.getPublicKey()); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2555 |
return s; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2556 |
} catch (Exception e) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2557 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2558 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2559 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2560 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2561 |
return null; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2562 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2563 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2564 |
private void doPrintCRL(String src, PrintStream out) |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2565 |
throws Exception { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2566 |
for (CRL crl: loadCRLs(src)) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2567 |
printCRL(crl, out); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2568 |
String issuer = null; |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2569 |
Certificate signer = null; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2570 |
if (caks != null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2571 |
issuer = verifyCRL(caks, crl); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2572 |
if (issuer != null) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2573 |
signer = caks.getCertificate(issuer); |
11912
49b066b32693
7147336: clarification on warning of keytool -printcrl
weijun
parents:
11012
diff
changeset
|
2574 |
out.printf(rb.getString( |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2575 |
"verified.by.s.in.s.weak"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2576 |
issuer, |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2577 |
"cacerts", |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2578 |
withWeak(signer.getPublicKey())); |
11912
49b066b32693
7147336: clarification on warning of keytool -printcrl
weijun
parents:
11012
diff
changeset
|
2579 |
out.println(); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2580 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2581 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2582 |
if (issuer == null && keyStore != null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2583 |
issuer = verifyCRL(keyStore, crl); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2584 |
if (issuer != null) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2585 |
signer = keyStore.getCertificate(issuer); |
11912
49b066b32693
7147336: clarification on warning of keytool -printcrl
weijun
parents:
11012
diff
changeset
|
2586 |
out.printf(rb.getString( |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2587 |
"verified.by.s.in.s.weak"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2588 |
issuer, |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2589 |
"keystore", |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2590 |
withWeak(signer.getPublicKey())); |
11912
49b066b32693
7147336: clarification on warning of keytool -printcrl
weijun
parents:
11012
diff
changeset
|
2591 |
out.println(); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2592 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2593 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2594 |
if (issuer == null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2595 |
out.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2596 |
("STAR")); |
11912
49b066b32693
7147336: clarification on warning of keytool -printcrl
weijun
parents:
11012
diff
changeset
|
2597 |
out.println(rb.getString |
49b066b32693
7147336: clarification on warning of keytool -printcrl
weijun
parents:
11012
diff
changeset
|
2598 |
("warning.not.verified.make.sure.keystore.is.correct")); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2599 |
out.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2600 |
("STARNN")); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2601 |
} |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2602 |
checkWeak(rb.getString("the.crl"), crl, signer == null ? null : signer.getPublicKey()); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2603 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2604 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2605 |
|
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2606 |
private void printCRL(CRL crl, PrintStream out) |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2607 |
throws Exception { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2608 |
X509CRL xcrl = (X509CRL)crl; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2609 |
if (rfc) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2610 |
out.println("-----BEGIN X509 CRL-----"); |
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
2611 |
out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(xcrl.getEncoded())); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2612 |
out.println("-----END X509 CRL-----"); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2613 |
} else { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2614 |
String s; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2615 |
if (crl instanceof X509CRLImpl) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2616 |
X509CRLImpl x509crl = (X509CRLImpl) crl; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2617 |
s = x509crl.toStringWithAlgName(withWeak("" + x509crl.getSigAlgId())); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2618 |
} else { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2619 |
s = crl.toString(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2620 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2621 |
out.println(s); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2622 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2623 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
2624 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2625 |
private void doPrintCertReq(InputStream in, PrintStream out) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2626 |
throws Exception { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2627 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2628 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2629 |
StringBuffer sb = new StringBuffer(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2630 |
boolean started = false; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2631 |
while (true) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2632 |
String s = reader.readLine(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2633 |
if (s == null) break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2634 |
if (!started) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2635 |
if (s.startsWith("-----")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2636 |
started = true; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2637 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2638 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2639 |
if (s.startsWith("-----")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2640 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2641 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2642 |
sb.append(s); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2643 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2644 |
} |
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
2645 |
PKCS10 req = new PKCS10(Pem.decode(new String(sb))); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2646 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2647 |
PublicKey pkey = req.getSubjectPublicKeyInfo(); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2648 |
out.printf(rb.getString("PKCS.10.with.weak"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2649 |
req.getSubjectName(), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2650 |
pkey.getFormat(), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2651 |
withWeak(pkey), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2652 |
withWeak(req.getSigAlg())); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2653 |
for (PKCS10Attribute attr: req.getAttributes().getAttributes()) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2654 |
ObjectIdentifier oid = attr.getAttributeId(); |
31426
9cd672654f97
8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents:
31270
diff
changeset
|
2655 |
if (oid.equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2656 |
CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue(); |
2179
e172c13ca87a
6813402: keytool cannot -printcert entries without extensions
weijun
parents:
2067
diff
changeset
|
2657 |
if (exts != null) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2658 |
printExtensions(rb.getString("Extension.Request."), exts, out); |
2179
e172c13ca87a
6813402: keytool cannot -printcert entries without extensions
weijun
parents:
2067
diff
changeset
|
2659 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2660 |
} else { |
19043
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2661 |
out.println("Attribute: " + attr.getAttributeId()); |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2662 |
PKCS9Attribute pkcs9Attr = |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2663 |
new PKCS9Attribute(attr.getAttributeId(), |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2664 |
attr.getAttributeValue()); |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2665 |
out.print(pkcs9Attr.getName() + ": "); |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2666 |
Object attrVal = attr.getAttributeValue(); |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2667 |
out.println(attrVal instanceof String[] ? |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2668 |
Arrays.toString((String[]) attrVal) : |
42407be709a3
8016916: UnstructuredName should support DirectoryString
juh
parents:
16720
diff
changeset
|
2669 |
attrVal); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2670 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2671 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2672 |
if (debug) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2673 |
out.println(req); // Just to see more, say, public key length... |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2674 |
} |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2675 |
checkWeak(rb.getString("the.certificate.request"), req); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2676 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2677 |
|
2 | 2678 |
/** |
2679 |
* Reads a certificate (or certificate chain) and prints its contents in |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2680 |
* a human readable format. |
2 | 2681 |
*/ |
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2682 |
private void printCertFromStream(InputStream in, PrintStream out) |
2 | 2683 |
throws Exception |
2684 |
{ |
|
2685 |
Collection<? extends Certificate> c = null; |
|
2686 |
try { |
|
51373
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2687 |
c = generateCertificates(in); |
2 | 2688 |
} catch (CertificateException ce) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2689 |
throw new Exception(rb.getString("Failed.to.parse.input"), ce); |
2 | 2690 |
} |
2691 |
if (c.isEmpty()) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2692 |
throw new Exception(rb.getString("Empty.input")); |
2 | 2693 |
} |
2694 |
Certificate[] certs = c.toArray(new Certificate[c.size()]); |
|
2695 |
for (int i=0; i<certs.length; i++) { |
|
2696 |
X509Certificate x509Cert = null; |
|
2697 |
try { |
|
2698 |
x509Cert = (X509Certificate)certs[i]; |
|
2699 |
} catch (ClassCastException cce) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2700 |
throw new Exception(rb.getString("Not.X.509.certificate")); |
2 | 2701 |
} |
2702 |
if (certs.length > 1) { |
|
2703 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2704 |
(rb.getString("Certificate.i.1.")); |
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
25402
diff
changeset
|
2705 |
Object[] source = {i + 1}; |
2 | 2706 |
out.println(form.format(source)); |
2707 |
} |
|
16020
b57c48f16179
8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents:
14421
diff
changeset
|
2708 |
if (rfc) |
b57c48f16179
8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents:
14421
diff
changeset
|
2709 |
dumpCert(x509Cert, out); |
b57c48f16179
8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents:
14421
diff
changeset
|
2710 |
else |
b57c48f16179
8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents:
14421
diff
changeset
|
2711 |
printX509Cert(x509Cert, out); |
2 | 2712 |
if (i < (certs.length-1)) { |
2713 |
out.println(); |
|
2714 |
} |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2715 |
checkWeak(oneInMany(rb.getString("the.certificate"), i, certs.length), x509Cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2716 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2717 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2718 |
|
54421
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2719 |
private void doShowInfo() throws Exception { |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2720 |
if (tlsInfo) { |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2721 |
ShowInfo.tls(verbose); |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2722 |
} else { |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2723 |
System.out.println(rb.getString("showinfo.no.option")); |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2724 |
} |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2725 |
} |
a7df0de0835a
8219861: Add new keytool -showinfo -tls command for displaying TLS configuration information
weijun
parents:
54346
diff
changeset
|
2726 |
|
51373
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2727 |
private Collection<? extends Certificate> generateCertificates(InputStream in) |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2728 |
throws CertificateException, IOException { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2729 |
byte[] data = in.readAllBytes(); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2730 |
try { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2731 |
return CertificateFactory.getInstance("X.509") |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2732 |
.generateCertificates(new ByteArrayInputStream(data)); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2733 |
} catch (CertificateException e) { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2734 |
if (providerName != null) { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2735 |
try { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2736 |
return CertificateFactory.getInstance("X.509", providerName) |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2737 |
.generateCertificates(new ByteArrayInputStream(data)); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2738 |
} catch (Exception e2) { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2739 |
e.addSuppressed(e2); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2740 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2741 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2742 |
throw e; |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2743 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2744 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2745 |
|
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2746 |
private Certificate generateCertificate(InputStream in) |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2747 |
throws CertificateException, IOException { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2748 |
byte[] data = in.readAllBytes(); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2749 |
try { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2750 |
return CertificateFactory.getInstance("X.509") |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2751 |
.generateCertificate(new ByteArrayInputStream(data)); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2752 |
} catch (CertificateException e) { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2753 |
if (providerName != null) { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2754 |
try { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2755 |
return CertificateFactory.getInstance("X.509", providerName) |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2756 |
.generateCertificate(new ByteArrayInputStream(data)); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2757 |
} catch (Exception e2) { |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2758 |
e.addSuppressed(e2); |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2759 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2760 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2761 |
throw e; |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2762 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2763 |
} |
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
2764 |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2765 |
private static String oneInMany(String label, int i, int num) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2766 |
if (num == 1) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2767 |
return label; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2768 |
} else { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2769 |
return String.format(rb.getString("one.in.many"), label, i+1, num); |
2 | 2770 |
} |
2771 |
} |
|
2772 |
||
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2773 |
private void doPrintCert(final PrintStream out) throws Exception { |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2774 |
if (jarfile != null) { |
41960
916bb3d29d7b
8168882: keytool doesn't print certificate info if disabled algorithm was used for signing a jar
asmotrak
parents:
40393
diff
changeset
|
2775 |
// reset "jdk.certpath.disabledAlgorithms" security property |
916bb3d29d7b
8168882: keytool doesn't print certificate info if disabled algorithm was used for signing a jar
asmotrak
parents:
40393
diff
changeset
|
2776 |
// to be able to read jars which were signed with weak algorithms |
916bb3d29d7b
8168882: keytool doesn't print certificate info if disabled algorithm was used for signing a jar
asmotrak
parents:
40393
diff
changeset
|
2777 |
Security.setProperty(DisabledAlgorithmConstraints.PROPERTY_JAR_DISABLED_ALGS, ""); |
916bb3d29d7b
8168882: keytool doesn't print certificate info if disabled algorithm was used for signing a jar
asmotrak
parents:
40393
diff
changeset
|
2778 |
|
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2779 |
JarFile jf = new JarFile(jarfile, true); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2780 |
Enumeration<JarEntry> entries = jf.entries(); |
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
2781 |
Set<CodeSigner> ss = new HashSet<>(); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2782 |
byte[] buffer = new byte[8192]; |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2783 |
int pos = 0; |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2784 |
while (entries.hasMoreElements()) { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2785 |
JarEntry je = entries.nextElement(); |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2786 |
try (InputStream is = jf.getInputStream(je)) { |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2787 |
while (is.read(buffer) != -1) { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2788 |
// we just read. this will throw a SecurityException |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2789 |
// if a signature/digest check fails. This also |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2790 |
// populate the signers |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2791 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2792 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2793 |
CodeSigner[] signers = je.getCodeSigners(); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2794 |
if (signers != null) { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2795 |
for (CodeSigner signer: signers) { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2796 |
if (!ss.contains(signer)) { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2797 |
ss.add(signer); |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2798 |
out.printf(rb.getString("Signer.d."), ++pos); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2799 |
out.println(); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2800 |
out.println(); |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2801 |
out.println(rb.getString("Signature.")); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2802 |
out.println(); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2803 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2804 |
List<? extends Certificate> certs |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2805 |
= signer.getSignerCertPath().getCertificates(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2806 |
int cc = 0; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2807 |
for (Certificate cert: certs) { |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2808 |
X509Certificate x = (X509Certificate)cert; |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2809 |
if (rfc) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2810 |
out.println(rb.getString("Certificate.owner.") + x.getSubjectDN() + "\n"); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2811 |
dumpCert(x, out); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2812 |
} else { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2813 |
printX509Cert(x, out); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2814 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2815 |
out.println(); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2816 |
checkWeak(oneInMany(rb.getString("the.certificate"), cc++, certs.size()), x); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2817 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2818 |
Timestamp ts = signer.getTimestamp(); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2819 |
if (ts != null) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2820 |
out.println(rb.getString("Timestamp.")); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2821 |
out.println(); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2822 |
certs = ts.getSignerCertPath().getCertificates(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2823 |
cc = 0; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2824 |
for (Certificate cert: certs) { |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2825 |
X509Certificate x = (X509Certificate)cert; |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2826 |
if (rfc) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2827 |
out.println(rb.getString("Certificate.owner.") + x.getSubjectDN() + "\n"); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2828 |
dumpCert(x, out); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2829 |
} else { |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2830 |
printX509Cert(x, out); |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2831 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2832 |
out.println(); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
2833 |
checkWeak(oneInMany(rb.getString("the.tsa.certificate"), cc++, certs.size()), x); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2834 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2835 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2836 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2837 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2838 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2839 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2840 |
jf.close(); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
10051
diff
changeset
|
2841 |
if (ss.isEmpty()) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2842 |
out.println(rb.getString("Not.a.signed.jar.file")); |
4169
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2843 |
} |
0ca7e3e74ba4
6890872: keytool -printcert to recognize signed jar files
weijun
parents:
4152
diff
changeset
|
2844 |
} else if (sslserver != null) { |
30506
1998a5644f50
8038084: CertStore needs a way to add new CertStore types
valeriep
parents:
30374
diff
changeset
|
2845 |
CertStore cs = SSLServerCertStore.getInstance(new URI("https://" + sslserver)); |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2846 |
Collection<? extends Certificate> chain; |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2847 |
try { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2848 |
chain = cs.getCertificates(null); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2849 |
if (chain.isEmpty()) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2850 |
// If the certs are not retrieved, we consider it an error |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2851 |
// even if the URL connection is successful. |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2852 |
throw new Exception(rb.getString( |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2853 |
"No.certificate.from.the.SSL.server")); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2854 |
} |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2855 |
} catch (CertStoreException cse) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2856 |
if (cse.getCause() instanceof IOException) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2857 |
throw new Exception(rb.getString( |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2858 |
"No.certificate.from.the.SSL.server"), |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2859 |
cse.getCause()); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2860 |
} else { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2861 |
throw cse; |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2862 |
} |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2863 |
} |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2864 |
|
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2865 |
int i = 0; |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2866 |
for (Certificate cert : chain) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2867 |
try { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2868 |
if (rfc) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2869 |
dumpCert(cert, out); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2870 |
} else { |
48050
b1993e334da1
8187985: Broken certificate number in debug output
igerasim
parents:
47421
diff
changeset
|
2871 |
out.println("Certificate #" + i); |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2872 |
out.println("===================================="); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2873 |
printX509Cert((X509Certificate)cert, out); |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2874 |
out.println(); |
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2875 |
} |
48050
b1993e334da1
8187985: Broken certificate number in debug output
igerasim
parents:
47421
diff
changeset
|
2876 |
checkWeak(oneInMany(rb.getString("the.certificate"), i++, chain.size()), cert); |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2877 |
} catch (Exception e) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2878 |
if (debug) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2879 |
e.printStackTrace(); |
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2880 |
} |
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2881 |
} |
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2882 |
} |
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2883 |
} else { |
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2884 |
if (filename != null) { |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2885 |
try (FileInputStream inStream = new FileInputStream(filename)) { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2886 |
printCertFromStream(inStream, out); |
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2887 |
} |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2888 |
} else { |
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
2889 |
printCertFromStream(System.in, out); |
904
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2890 |
} |
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2891 |
} |
eadc9fa4b700
6480981: keytool should be able to import certificates from remote SSL servers
weijun
parents:
2
diff
changeset
|
2892 |
} |
48333
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2893 |
|
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2894 |
private void doChangeStorePasswd() throws Exception { |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2895 |
storePassNew = newPass; |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2896 |
if (storePassNew == null) { |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2897 |
storePassNew = getNewPasswd("keystore password", storePass); |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2898 |
} |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2899 |
if (P12KEYSTORE.equalsIgnoreCase(storetype)) { |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2900 |
// When storetype is PKCS12, we need to change all keypass as well |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2901 |
for (String alias : Collections.list(keyStore.aliases())) { |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2902 |
if (!keyStore.isCertificateEntry(alias)) { |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2903 |
// keyPass should be either null or same with storePass, |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2904 |
// but keep it in case one day we want to "normalize" |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2905 |
// a PKCS12 keystore having different passwords. |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2906 |
Pair<Entry, char[]> objs |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2907 |
= recoverEntry(keyStore, alias, storePass, keyPass); |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2908 |
keyStore.setEntry(alias, objs.fst, |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2909 |
new PasswordProtection(storePassNew)); |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2910 |
} |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2911 |
} |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2912 |
} |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2913 |
} |
f47c18852172
8192988: keytool should support -storepasswd for pkcs12 keystores
weijun
parents:
48216
diff
changeset
|
2914 |
|
2 | 2915 |
/** |
2916 |
* Creates a self-signed certificate, and stores it as a single-element |
|
2917 |
* certificate chain. |
|
2918 |
*/ |
|
2919 |
private void doSelfCert(String alias, String dname, String sigAlgName) |
|
2920 |
throws Exception |
|
2921 |
{ |
|
2922 |
if (alias == null) { |
|
2923 |
alias = keyAlias; |
|
2924 |
} |
|
2925 |
||
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2926 |
Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2927 |
PrivateKey privKey = (PrivateKey)objs.fst; |
2 | 2928 |
if (keyPass == null) |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
2929 |
keyPass = objs.snd; |
2 | 2930 |
|
2931 |
// Determine the signature algorithm |
|
2932 |
if (sigAlgName == null) { |
|
38439 | 2933 |
sigAlgName = getCompatibleSigAlgName(privKey); |
2 | 2934 |
} |
2935 |
||
2936 |
// Get the old certificate |
|
2937 |
Certificate oldCert = keyStore.getCertificate(alias); |
|
2938 |
if (oldCert == null) { |
|
2939 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2940 |
(rb.getString("alias.has.no.public.key")); |
2 | 2941 |
Object[] source = {alias}; |
2942 |
throw new Exception(form.format(source)); |
|
2943 |
} |
|
2944 |
if (!(oldCert instanceof X509Certificate)) { |
|
2945 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
2946 |
(rb.getString("alias.has.no.X.509.certificate")); |
2 | 2947 |
Object[] source = {alias}; |
2948 |
throw new Exception(form.format(source)); |
|
2949 |
} |
|
2950 |
||
2951 |
// convert to X509CertImpl, so that we can modify selected fields |
|
2952 |
// (no public APIs available yet) |
|
2953 |
byte[] encoded = oldCert.getEncoded(); |
|
2954 |
X509CertImpl certImpl = new X509CertImpl(encoded); |
|
2955 |
X509CertInfo certInfo = (X509CertInfo)certImpl.get(X509CertImpl.NAME |
|
2956 |
+ "." + |
|
2957 |
X509CertImpl.INFO); |
|
2958 |
||
2959 |
// Extend its validity |
|
2960 |
Date firstDate = getStartDate(startDate); |
|
2961 |
Date lastDate = new Date(); |
|
2962 |
lastDate.setTime(firstDate.getTime() + validity*1000L*24L*60L*60L); |
|
2963 |
CertificateValidity interval = new CertificateValidity(firstDate, |
|
2964 |
lastDate); |
|
2965 |
certInfo.set(X509CertInfo.VALIDITY, interval); |
|
2966 |
||
2967 |
// Make new serial number |
|
54346
b7ebff3e4e69
8221257: Improve serial number generation mechanism for keytool -gencert
weijun
parents:
53740
diff
changeset
|
2968 |
certInfo.set(X509CertInfo.SERIAL_NUMBER, |
b7ebff3e4e69
8221257: Improve serial number generation mechanism for keytool -gencert
weijun
parents:
53740
diff
changeset
|
2969 |
CertificateSerialNumber.newRandom64bit(new SecureRandom())); |
2 | 2970 |
|
2971 |
// Set owner and issuer fields |
|
2972 |
X500Name owner; |
|
2973 |
if (dname == null) { |
|
2974 |
// Get the owner name from the certificate |
|
2975 |
owner = (X500Name)certInfo.get(X509CertInfo.SUBJECT + "." + |
|
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
2976 |
X509CertInfo.DN_NAME); |
2 | 2977 |
} else { |
2978 |
// Use the owner name specified at the command line |
|
2979 |
owner = new X500Name(dname); |
|
2980 |
certInfo.set(X509CertInfo.SUBJECT + "." + |
|
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
2981 |
X509CertInfo.DN_NAME, owner); |
2 | 2982 |
} |
2983 |
// Make issuer same as owner (self-signed!) |
|
2984 |
certInfo.set(X509CertInfo.ISSUER + "." + |
|
14421
a64b2cc9d429
7198416: CertificateIssuerName and CertificateSubjectName are redundant
mullan
parents:
14182
diff
changeset
|
2985 |
X509CertInfo.DN_NAME, owner); |
2 | 2986 |
|
2987 |
// The inner and outer signature algorithms have to match. |
|
2988 |
// The way we achieve that is really ugly, but there seems to be no |
|
2989 |
// other solution: We first sign the cert, then retrieve the |
|
2990 |
// outer sigalg and use it to set the inner sigalg |
|
2991 |
X509CertImpl newCert = new X509CertImpl(certInfo); |
|
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
2992 |
AlgorithmParameterSpec params = AlgorithmId |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
2993 |
.getDefaultAlgorithmParameterSpec(sigAlgName, privKey); |
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
2994 |
newCert.sign(privKey, params, sigAlgName, null); |
2 | 2995 |
AlgorithmId sigAlgid = (AlgorithmId)newCert.get(X509CertImpl.SIG_ALG); |
2996 |
certInfo.set(CertificateAlgorithmId.NAME + "." + |
|
2997 |
CertificateAlgorithmId.ALGORITHM, sigAlgid); |
|
2998 |
||
2999 |
certInfo.set(X509CertInfo.VERSION, |
|
3000 |
new CertificateVersion(CertificateVersion.V3)); |
|
3001 |
||
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3002 |
CertificateExtensions ext = createV3Extensions( |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3003 |
null, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3004 |
(CertificateExtensions)certInfo.get(X509CertInfo.EXTENSIONS), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3005 |
v3ext, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3006 |
oldCert.getPublicKey(), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3007 |
null); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3008 |
certInfo.set(X509CertInfo.EXTENSIONS, ext); |
2 | 3009 |
// Sign the new certificate |
3010 |
newCert = new X509CertImpl(certInfo); |
|
53351
bdb29aa5fd31
8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
52996
diff
changeset
|
3011 |
newCert.sign(privKey, params, sigAlgName, null); |
2 | 3012 |
|
3013 |
// Store the new certificate as a single-element certificate chain |
|
3014 |
keyStore.setKeyEntry(alias, privKey, |
|
3015 |
(keyPass != null) ? keyPass : storePass, |
|
3016 |
new Certificate[] { newCert } ); |
|
3017 |
||
3018 |
if (verbose) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3019 |
System.err.println(rb.getString("New.certificate.self.signed.")); |
2 | 3020 |
System.err.print(newCert.toString()); |
3021 |
System.err.println(); |
|
3022 |
} |
|
3023 |
} |
|
3024 |
||
3025 |
/** |
|
3026 |
* Processes a certificate reply from a certificate authority. |
|
3027 |
* |
|
3028 |
* <p>Builds a certificate chain on top of the certificate reply, |
|
3029 |
* using trusted certificates from the keystore. The chain is complete |
|
3030 |
* after a self-signed certificate has been encountered. The self-signed |
|
3031 |
* certificate is considered a root certificate authority, and is stored |
|
3032 |
* at the end of the chain. |
|
3033 |
* |
|
3034 |
* <p>The newly generated chain replaces the old chain associated with the |
|
3035 |
* key entry. |
|
3036 |
* |
|
3037 |
* @return true if the certificate reply was installed, otherwise false. |
|
3038 |
*/ |
|
3039 |
private boolean installReply(String alias, InputStream in) |
|
3040 |
throws Exception |
|
3041 |
{ |
|
3042 |
if (alias == null) { |
|
3043 |
alias = keyAlias; |
|
3044 |
} |
|
3045 |
||
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3046 |
Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3047 |
PrivateKey privKey = (PrivateKey)objs.fst; |
2 | 3048 |
if (keyPass == null) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3049 |
keyPass = objs.snd; |
2 | 3050 |
} |
3051 |
||
3052 |
Certificate userCert = keyStore.getCertificate(alias); |
|
3053 |
if (userCert == null) { |
|
3054 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3055 |
(rb.getString("alias.has.no.public.key.certificate.")); |
2 | 3056 |
Object[] source = {alias}; |
3057 |
throw new Exception(form.format(source)); |
|
3058 |
} |
|
3059 |
||
3060 |
// Read the certificates in the reply |
|
51373
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
3061 |
Collection<? extends Certificate> c = generateCertificates(in); |
2 | 3062 |
if (c.isEmpty()) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3063 |
throw new Exception(rb.getString("Reply.has.no.certificates")); |
2 | 3064 |
} |
3065 |
Certificate[] replyCerts = c.toArray(new Certificate[c.size()]); |
|
3066 |
Certificate[] newChain; |
|
3067 |
if (replyCerts.length == 1) { |
|
3068 |
// single-cert reply |
|
3069 |
newChain = establishCertChain(userCert, replyCerts[0]); |
|
3070 |
} else { |
|
3071 |
// cert-chain reply (e.g., PKCS#7) |
|
3072 |
newChain = validateReply(alias, userCert, replyCerts); |
|
3073 |
} |
|
3074 |
||
3075 |
// Now store the newly established chain in the keystore. The new |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3076 |
// chain replaces the old one. The chain can be null if user chooses no. |
2 | 3077 |
if (newChain != null) { |
3078 |
keyStore.setKeyEntry(alias, privKey, |
|
3079 |
(keyPass != null) ? keyPass : storePass, |
|
3080 |
newChain); |
|
3081 |
return true; |
|
3082 |
} else { |
|
3083 |
return false; |
|
3084 |
} |
|
3085 |
} |
|
3086 |
||
3087 |
/** |
|
3088 |
* Imports a certificate and adds it to the list of trusted certificates. |
|
3089 |
* |
|
3090 |
* @return true if the certificate was added, otherwise false. |
|
3091 |
*/ |
|
3092 |
private boolean addTrustedCert(String alias, InputStream in) |
|
3093 |
throws Exception |
|
3094 |
{ |
|
3095 |
if (alias == null) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3096 |
throw new Exception(rb.getString("Must.specify.alias")); |
2 | 3097 |
} |
3098 |
if (keyStore.containsAlias(alias)) { |
|
3099 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3100 |
("Certificate.not.imported.alias.alias.already.exists")); |
2 | 3101 |
Object[] source = {alias}; |
3102 |
throw new Exception(form.format(source)); |
|
3103 |
} |
|
3104 |
||
3105 |
// Read the certificate |
|
3106 |
X509Certificate cert = null; |
|
3107 |
try { |
|
51373
514035618c1d
8201290: keytool importcert fails with CertificateParsingException if unknown certificate algorithms should be imported
weijun
parents:
49285
diff
changeset
|
3108 |
cert = (X509Certificate)generateCertificate(in); |
10782
01689c7b34ac
6953295: Move few sun.security.{util, x509, pkcs} classes used by keytool/jarsigner to another package
mullan
parents:
10436
diff
changeset
|
3109 |
} catch (ClassCastException | CertificateException ce) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3110 |
throw new Exception(rb.getString("Input.not.an.X.509.certificate")); |
2 | 3111 |
} |
3112 |
||
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3113 |
if (noprompt) { |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3114 |
checkWeak(rb.getString("the.input"), cert); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3115 |
keyStore.setCertificateEntry(alias, cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3116 |
return true; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3117 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3118 |
|
2 | 3119 |
// if certificate is self-signed, make sure it verifies |
3120 |
boolean selfSigned = false; |
|
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
34381
diff
changeset
|
3121 |
if (KeyStoreUtil.isSelfSigned(cert)) { |
2 | 3122 |
cert.verify(cert.getPublicKey()); |
3123 |
selfSigned = true; |
|
3124 |
} |
|
3125 |
||
3126 |
// check if cert already exists in keystore |
|
3127 |
String reply = null; |
|
3128 |
String trustalias = keyStore.getCertificateAlias(cert); |
|
3129 |
if (trustalias != null) { |
|
3130 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3131 |
("Certificate.already.exists.in.keystore.under.alias.trustalias.")); |
2 | 3132 |
Object[] source = {trustalias}; |
3133 |
System.err.println(form.format(source)); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3134 |
checkWeak(rb.getString("the.input"), cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3135 |
printWeakWarnings(true); |
2 | 3136 |
reply = getYesNoReply |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3137 |
(rb.getString("Do.you.still.want.to.add.it.no.")); |
2 | 3138 |
} else if (selfSigned) { |
3139 |
if (trustcacerts && (caks != null) && |
|
3140 |
((trustalias=caks.getCertificateAlias(cert)) != null)) { |
|
3141 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3142 |
("Certificate.already.exists.in.system.wide.CA.keystore.under.alias.trustalias.")); |
2 | 3143 |
Object[] source = {trustalias}; |
3144 |
System.err.println(form.format(source)); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3145 |
checkWeak(rb.getString("the.input"), cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3146 |
printWeakWarnings(true); |
2 | 3147 |
reply = getYesNoReply |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3148 |
(rb.getString("Do.you.still.want.to.add.it.to.your.own.keystore.no.")); |
2 | 3149 |
} |
3150 |
if (trustalias == null) { |
|
3151 |
// Print the cert and ask user if they really want to add |
|
3152 |
// it to their keystore |
|
3153 |
printX509Cert(cert, System.out); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3154 |
checkWeak(rb.getString("the.input"), cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3155 |
printWeakWarnings(true); |
2 | 3156 |
reply = getYesNoReply |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3157 |
(rb.getString("Trust.this.certificate.no.")); |
2 | 3158 |
} |
3159 |
} |
|
3160 |
if (reply != null) { |
|
3161 |
if ("YES".equals(reply)) { |
|
3162 |
keyStore.setCertificateEntry(alias, cert); |
|
3163 |
return true; |
|
3164 |
} else { |
|
3165 |
return false; |
|
3166 |
} |
|
3167 |
} |
|
3168 |
||
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3169 |
// Not found in this keystore and not self-signed |
2 | 3170 |
// Try to establish trust chain |
3171 |
try { |
|
3172 |
Certificate[] chain = establishCertChain(null, cert); |
|
3173 |
if (chain != null) { |
|
3174 |
keyStore.setCertificateEntry(alias, cert); |
|
3175 |
return true; |
|
3176 |
} |
|
3177 |
} catch (Exception e) { |
|
3178 |
// Print the cert and ask user if they really want to add it to |
|
3179 |
// their keystore |
|
3180 |
printX509Cert(cert, System.out); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3181 |
checkWeak(rb.getString("the.input"), cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3182 |
printWeakWarnings(true); |
2 | 3183 |
reply = getYesNoReply |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3184 |
(rb.getString("Trust.this.certificate.no.")); |
2 | 3185 |
if ("YES".equals(reply)) { |
3186 |
keyStore.setCertificateEntry(alias, cert); |
|
3187 |
return true; |
|
3188 |
} else { |
|
3189 |
return false; |
|
3190 |
} |
|
3191 |
} |
|
3192 |
||
3193 |
return false; |
|
3194 |
} |
|
3195 |
||
3196 |
/** |
|
3197 |
* Prompts user for new password. New password must be different from |
|
3198 |
* old one. |
|
3199 |
* |
|
3200 |
* @param prompt the message that gets prompted on the screen |
|
3201 |
* @param oldPasswd the current (i.e., old) password |
|
3202 |
*/ |
|
3203 |
private char[] getNewPasswd(String prompt, char[] oldPasswd) |
|
3204 |
throws Exception |
|
3205 |
{ |
|
3206 |
char[] entered = null; |
|
3207 |
char[] reentered = null; |
|
3208 |
||
3209 |
for (int count = 0; count < 3; count++) { |
|
3210 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3211 |
(rb.getString("New.prompt.")); |
2 | 3212 |
Object[] source = {prompt}; |
3213 |
System.err.print(form.format(source)); |
|
3214 |
entered = Password.readPassword(System.in); |
|
3215 |
passwords.add(entered); |
|
3216 |
if (entered == null || entered.length < 6) { |
|
3217 |
System.err.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3218 |
("Password.is.too.short.must.be.at.least.6.characters")); |
2 | 3219 |
} else if (Arrays.equals(entered, oldPasswd)) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3220 |
System.err.println(rb.getString("Passwords.must.differ")); |
2 | 3221 |
} else { |
3222 |
form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3223 |
(rb.getString("Re.enter.new.prompt.")); |
2 | 3224 |
Object[] src = {prompt}; |
3225 |
System.err.print(form.format(src)); |
|
3226 |
reentered = Password.readPassword(System.in); |
|
3227 |
passwords.add(reentered); |
|
3228 |
if (!Arrays.equals(entered, reentered)) { |
|
3229 |
System.err.println |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3230 |
(rb.getString("They.don.t.match.Try.again")); |
2 | 3231 |
} else { |
3232 |
Arrays.fill(reentered, ' '); |
|
3233 |
return entered; |
|
3234 |
} |
|
3235 |
} |
|
3236 |
if (entered != null) { |
|
3237 |
Arrays.fill(entered, ' '); |
|
3238 |
entered = null; |
|
3239 |
} |
|
3240 |
if (reentered != null) { |
|
3241 |
Arrays.fill(reentered, ' '); |
|
3242 |
reentered = null; |
|
3243 |
} |
|
3244 |
} |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3245 |
throw new Exception(rb.getString("Too.many.failures.try.later")); |
2 | 3246 |
} |
3247 |
||
3248 |
/** |
|
3249 |
* Prompts user for alias name. |
|
3250 |
* @param prompt the {0} of "Enter {0} alias name: " in prompt line |
|
30374 | 3251 |
* @return the string entered by the user, without the \n at the end |
2 | 3252 |
*/ |
3253 |
private String getAlias(String prompt) throws Exception { |
|
3254 |
if (prompt != null) { |
|
3255 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3256 |
(rb.getString("Enter.prompt.alias.name.")); |
2 | 3257 |
Object[] source = {prompt}; |
3258 |
System.err.print(form.format(source)); |
|
3259 |
} else { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3260 |
System.err.print(rb.getString("Enter.alias.name.")); |
2 | 3261 |
} |
3262 |
return (new BufferedReader(new InputStreamReader( |
|
3263 |
System.in))).readLine(); |
|
3264 |
} |
|
3265 |
||
3266 |
/** |
|
3267 |
* Prompts user for an input string from the command line (System.in) |
|
3268 |
* @prompt the prompt string printed |
|
30374 | 3269 |
* @return the string entered by the user, without the \n at the end |
2 | 3270 |
*/ |
3271 |
private String inputStringFromStdin(String prompt) throws Exception { |
|
3272 |
System.err.print(prompt); |
|
3273 |
return (new BufferedReader(new InputStreamReader( |
|
3274 |
System.in))).readLine(); |
|
3275 |
} |
|
3276 |
||
3277 |
/** |
|
3278 |
* Prompts user for key password. User may select to choose the same |
|
3279 |
* password (<code>otherKeyPass</code>) as for <code>otherAlias</code>. |
|
3280 |
*/ |
|
3281 |
private char[] getKeyPasswd(String alias, String otherAlias, |
|
3282 |
char[] otherKeyPass) |
|
3283 |
throws Exception |
|
3284 |
{ |
|
3285 |
int count = 0; |
|
3286 |
char[] keyPass = null; |
|
3287 |
||
3288 |
do { |
|
3289 |
if (otherKeyPass != null) { |
|
3290 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3291 |
("Enter.key.password.for.alias.")); |
2 | 3292 |
Object[] source = {alias}; |
3293 |
System.err.println(form.format(source)); |
|
3294 |
||
3295 |
form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3296 |
(".RETURN.if.same.as.for.otherAlias.")); |
2 | 3297 |
Object[] src = {otherAlias}; |
3298 |
System.err.print(form.format(src)); |
|
3299 |
} else { |
|
3300 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3301 |
("Enter.key.password.for.alias.")); |
2 | 3302 |
Object[] source = {alias}; |
3303 |
System.err.print(form.format(source)); |
|
3304 |
} |
|
3305 |
System.err.flush(); |
|
3306 |
keyPass = Password.readPassword(System.in); |
|
3307 |
passwords.add(keyPass); |
|
3308 |
if (keyPass == null) { |
|
3309 |
keyPass = otherKeyPass; |
|
3310 |
} |
|
3311 |
count++; |
|
3312 |
} while ((keyPass == null) && count < 3); |
|
3313 |
||
3314 |
if (keyPass == null) { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3315 |
throw new Exception(rb.getString("Too.many.failures.try.later")); |
2 | 3316 |
} |
3317 |
||
3318 |
return keyPass; |
|
3319 |
} |
|
3320 |
||
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3321 |
private String withWeak(String alg) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3322 |
if (DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, alg, null)) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3323 |
return alg; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3324 |
} else { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3325 |
return String.format(rb.getString("with.weak"), alg); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3326 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3327 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3328 |
|
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3329 |
private String fullDisplayAlgName(Key key) { |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3330 |
String result = key.getAlgorithm(); |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3331 |
if (key instanceof ECKey) { |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3332 |
ECParameterSpec paramSpec = ((ECKey) key).getParams(); |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3333 |
if (paramSpec instanceof NamedCurve) { |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3334 |
result += " (" + paramSpec.toString().split(" ")[0] + ")"; |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3335 |
} |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3336 |
} |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3337 |
return result; |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3338 |
} |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3339 |
|
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3340 |
private String withWeak(Key key) { |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3341 |
int kLen = KeyUtil.getKeySize(key); |
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3342 |
String displayAlg = fullDisplayAlgName(key); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3343 |
if (DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, key)) { |
46139
5196af754957
8185934: keytool shows "Signature algorithm: SHA1withECDSA, -1-bit key"
weijun
parents:
45839
diff
changeset
|
3344 |
if (kLen >= 0) { |
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3345 |
return String.format(rb.getString("key.bit"), kLen, displayAlg); |
46139
5196af754957
8185934: keytool shows "Signature algorithm: SHA1withECDSA, -1-bit key"
weijun
parents:
45839
diff
changeset
|
3346 |
} else { |
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3347 |
return String.format(rb.getString("unknown.size.1"), displayAlg); |
46139
5196af754957
8185934: keytool shows "Signature algorithm: SHA1withECDSA, -1-bit key"
weijun
parents:
45839
diff
changeset
|
3348 |
} |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3349 |
} else { |
52791
a6ede2dabe20
8214179: Add groupname info into keytool -list and -genkeypair output
weijun
parents:
52689
diff
changeset
|
3350 |
return String.format(rb.getString("key.bit.weak"), kLen, displayAlg); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3351 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3352 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3353 |
|
2 | 3354 |
/** |
3355 |
* Prints a certificate in a human readable format. |
|
3356 |
*/ |
|
3357 |
private void printX509Cert(X509Certificate cert, PrintStream out) |
|
3358 |
throws Exception |
|
3359 |
{ |
|
3360 |
||
3361 |
MessageFormat form = new MessageFormat |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3362 |
(rb.getString(".PATTERN.printX509Cert.with.weak")); |
27038
64cb6608f8a6
8029659: Keytool, print key algorithm of certificate or key entry
weijun
parents:
25859
diff
changeset
|
3363 |
PublicKey pkey = cert.getPublicKey(); |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3364 |
String sigName = cert.getSigAlgName(); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3365 |
// No need to warn about sigalg of a trust anchor |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3366 |
if (!isTrustedCert(cert)) { |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3367 |
sigName = withWeak(sigName); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3368 |
} |
2 | 3369 |
Object[] source = {cert.getSubjectDN().toString(), |
3370 |
cert.getIssuerDN().toString(), |
|
3371 |
cert.getSerialNumber().toString(16), |
|
3372 |
cert.getNotBefore().toString(), |
|
3373 |
cert.getNotAfter().toString(), |
|
34381
be5600f6a4da
8141457: keytool default cert fingerprint algorithm should be SHA-256
weijun
parents:
31426
diff
changeset
|
3374 |
getCertFingerPrint("SHA-1", cert), |
3318
dade78e63c92
6561126: keytool should use larger default keysize for keypairs
weijun
parents:
3316
diff
changeset
|
3375 |
getCertFingerPrint("SHA-256", cert), |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3376 |
sigName, |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3377 |
withWeak(pkey), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3378 |
cert.getVersion() |
2 | 3379 |
}; |
3380 |
out.println(form.format(source)); |
|
3381 |
||
3382 |
if (cert instanceof X509CertImpl) { |
|
3383 |
X509CertImpl impl = (X509CertImpl)cert; |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3384 |
X509CertInfo certInfo = (X509CertInfo)impl.get(X509CertImpl.NAME |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3385 |
+ "." + |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3386 |
X509CertImpl.INFO); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3387 |
CertificateExtensions exts = (CertificateExtensions) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3388 |
certInfo.get(X509CertInfo.EXTENSIONS); |
2179
e172c13ca87a
6813402: keytool cannot -printcert entries without extensions
weijun
parents:
2067
diff
changeset
|
3389 |
if (exts != null) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3390 |
printExtensions(rb.getString("Extensions."), exts, out); |
2179
e172c13ca87a
6813402: keytool cannot -printcert entries without extensions
weijun
parents:
2067
diff
changeset
|
3391 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3392 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3393 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3394 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3395 |
private static void printExtensions(String title, CertificateExtensions exts, PrintStream out) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3396 |
throws Exception { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3397 |
int extnum = 0; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3398 |
Iterator<Extension> i1 = exts.getAllExtensions().iterator(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3399 |
Iterator<Extension> i2 = exts.getUnparseableExtensions().values().iterator(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3400 |
while (i1.hasNext() || i2.hasNext()) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3401 |
Extension ext = i1.hasNext()?i1.next():i2.next(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3402 |
if (extnum == 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3403 |
out.println(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3404 |
out.println(title); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3405 |
out.println(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3406 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3407 |
out.print("#"+(++extnum)+": "+ ext); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3408 |
if (ext.getClass() == Extension.class) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3409 |
byte[] v = ext.getExtensionValue(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3410 |
if (v.length == 0) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3411 |
out.println(rb.getString(".Empty.value.")); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3412 |
} else { |
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
34382
diff
changeset
|
3413 |
new sun.security.util.HexDumpEncoder().encodeBuffer(ext.getExtensionValue(), out); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3414 |
out.println(); |
2 | 3415 |
} |
3416 |
} |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3417 |
out.println(); |
2 | 3418 |
} |
3419 |
} |
|
3420 |
||
3421 |
/** |
|
5296 | 3422 |
* Locates a signer for a given certificate from a given keystore and |
3423 |
* returns the signer's certificate. |
|
3424 |
* @param cert the certificate whose signer is searched, not null |
|
3425 |
* @param ks the keystore to search with, not null |
|
3426 |
* @return <code>cert</code> itself if it's already inside <code>ks</code>, |
|
3427 |
* or a certificate inside <code>ks</code> who signs <code>cert</code>, |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3428 |
* or null otherwise. A label is added. |
2 | 3429 |
*/ |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3430 |
private static Pair<String,Certificate> |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3431 |
getSigner(Certificate cert, KeyStore ks) throws Exception { |
5296 | 3432 |
if (ks.getCertificateAlias(cert) != null) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3433 |
return new Pair<>("", cert); |
2 | 3434 |
} |
5296 | 3435 |
for (Enumeration<String> aliases = ks.aliases(); |
3436 |
aliases.hasMoreElements(); ) { |
|
3437 |
String name = aliases.nextElement(); |
|
3438 |
Certificate trustedCert = ks.getCertificate(name); |
|
3439 |
if (trustedCert != null) { |
|
3440 |
try { |
|
3441 |
cert.verify(trustedCert.getPublicKey()); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3442 |
return new Pair<>(name, trustedCert); |
5296 | 3443 |
} catch (Exception e) { |
3444 |
// Not verified, skip to the next one |
|
3445 |
} |
|
3446 |
} |
|
2 | 3447 |
} |
5296 | 3448 |
return null; |
2 | 3449 |
} |
3450 |
||
3451 |
/** |
|
3452 |
* Gets an X.500 name suitable for inclusion in a certification request. |
|
3453 |
*/ |
|
3454 |
private X500Name getX500Name() throws IOException { |
|
3455 |
BufferedReader in; |
|
3456 |
in = new BufferedReader(new InputStreamReader(System.in)); |
|
3457 |
String commonName = "Unknown"; |
|
3458 |
String organizationalUnit = "Unknown"; |
|
3459 |
String organization = "Unknown"; |
|
3460 |
String city = "Unknown"; |
|
3461 |
String state = "Unknown"; |
|
3462 |
String country = "Unknown"; |
|
3463 |
X500Name name; |
|
3464 |
String userInput = null; |
|
3465 |
||
3466 |
int maxRetry = 20; |
|
3467 |
do { |
|
3468 |
if (maxRetry-- < 0) { |
|
3469 |
throw new RuntimeException(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3470 |
"Too.many.retries.program.terminated")); |
2 | 3471 |
} |
3472 |
commonName = inputString(in, |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3473 |
rb.getString("What.is.your.first.and.last.name."), |
2 | 3474 |
commonName); |
3475 |
organizationalUnit = inputString(in, |
|
3476 |
rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3477 |
("What.is.the.name.of.your.organizational.unit."), |
2 | 3478 |
organizationalUnit); |
3479 |
organization = inputString(in, |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3480 |
rb.getString("What.is.the.name.of.your.organization."), |
2 | 3481 |
organization); |
3482 |
city = inputString(in, |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3483 |
rb.getString("What.is.the.name.of.your.City.or.Locality."), |
2 | 3484 |
city); |
3485 |
state = inputString(in, |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3486 |
rb.getString("What.is.the.name.of.your.State.or.Province."), |
2 | 3487 |
state); |
3488 |
country = inputString(in, |
|
3489 |
rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3490 |
("What.is.the.two.letter.country.code.for.this.unit."), |
2 | 3491 |
country); |
3492 |
name = new X500Name(commonName, organizationalUnit, organization, |
|
3493 |
city, state, country); |
|
3494 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3495 |
(rb.getString("Is.name.correct.")); |
2 | 3496 |
Object[] source = {name}; |
3497 |
userInput = inputString |
|
3498 |
(in, form.format(source), rb.getString("no")); |
|
3499 |
} while (collator.compare(userInput, rb.getString("yes")) != 0 && |
|
3500 |
collator.compare(userInput, rb.getString("y")) != 0); |
|
3501 |
||
3502 |
System.err.println(); |
|
3503 |
return name; |
|
3504 |
} |
|
3505 |
||
3506 |
private String inputString(BufferedReader in, String prompt, |
|
3507 |
String defaultValue) |
|
3508 |
throws IOException |
|
3509 |
{ |
|
3510 |
System.err.println(prompt); |
|
3511 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3512 |
(rb.getString(".defaultValue.")); |
2 | 3513 |
Object[] source = {defaultValue}; |
3514 |
System.err.print(form.format(source)); |
|
3515 |
System.err.flush(); |
|
3516 |
||
3517 |
String value = in.readLine(); |
|
3518 |
if (value == null || collator.compare(value, "") == 0) { |
|
3519 |
value = defaultValue; |
|
3520 |
} |
|
3521 |
return value; |
|
3522 |
} |
|
3523 |
||
3524 |
/** |
|
3525 |
* Writes an X.509 certificate in base64 or binary encoding to an output |
|
3526 |
* stream. |
|
3527 |
*/ |
|
3528 |
private void dumpCert(Certificate cert, PrintStream out) |
|
3529 |
throws IOException, CertificateException |
|
3530 |
{ |
|
3531 |
if (rfc) { |
|
3532 |
out.println(X509Factory.BEGIN_CERT); |
|
29596
70399c7a7f5a
8074935: jdk8 keytool doesn't validate pem files for RFC 1421 correctness, as jdk7 did
weijun
parents:
29225
diff
changeset
|
3533 |
out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(cert.getEncoded())); |
2 | 3534 |
out.println(X509Factory.END_CERT); |
3535 |
} else { |
|
3536 |
out.write(cert.getEncoded()); // binary |
|
3537 |
} |
|
3538 |
} |
|
3539 |
||
3540 |
/** |
|
3541 |
* Converts a byte to hex digit and writes to the supplied buffer |
|
3542 |
*/ |
|
3543 |
private void byte2hex(byte b, StringBuffer buf) { |
|
3544 |
char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', |
|
3545 |
'9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
|
3546 |
int high = ((b & 0xf0) >> 4); |
|
3547 |
int low = (b & 0x0f); |
|
3548 |
buf.append(hexChars[high]); |
|
3549 |
buf.append(hexChars[low]); |
|
3550 |
} |
|
3551 |
||
3552 |
/** |
|
3553 |
* Converts a byte array to hex string |
|
3554 |
*/ |
|
3555 |
private String toHexString(byte[] block) { |
|
3556 |
StringBuffer buf = new StringBuffer(); |
|
3557 |
int len = block.length; |
|
3558 |
for (int i = 0; i < len; i++) { |
|
3559 |
byte2hex(block[i], buf); |
|
3560 |
if (i < len-1) { |
|
3561 |
buf.append(":"); |
|
3562 |
} |
|
3563 |
} |
|
3564 |
return buf.toString(); |
|
3565 |
} |
|
3566 |
||
3567 |
/** |
|
3568 |
* Recovers (private) key associated with given alias. |
|
3569 |
* |
|
3570 |
* @return an array of objects, where the 1st element in the array is the |
|
3571 |
* recovered private key, and the 2nd element is the password used to |
|
3572 |
* recover it. |
|
3573 |
*/ |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3574 |
private Pair<Key,char[]> recoverKey(String alias, char[] storePass, |
2 | 3575 |
char[] keyPass) |
3576 |
throws Exception |
|
3577 |
{ |
|
3578 |
Key key = null; |
|
3579 |
||
54827 | 3580 |
if (KeyStoreUtil.isWindowsKeyStore(storetype)) { |
3581 |
key = keyStore.getKey(alias, null); |
|
3582 |
return Pair.of(key, null); |
|
3583 |
} |
|
3584 |
||
2 | 3585 |
if (keyStore.containsAlias(alias) == false) { |
3586 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3587 |
(rb.getString("Alias.alias.does.not.exist")); |
2 | 3588 |
Object[] source = {alias}; |
3589 |
throw new Exception(form.format(source)); |
|
3590 |
} |
|
3591 |
if (!keyStore.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class) && |
|
3592 |
!keyStore.entryInstanceOf(alias, KeyStore.SecretKeyEntry.class)) { |
|
3593 |
MessageFormat form = new MessageFormat |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3594 |
(rb.getString("Alias.alias.has.no.key")); |
2 | 3595 |
Object[] source = {alias}; |
3596 |
throw new Exception(form.format(source)); |
|
3597 |
} |
|
3598 |
||
3599 |
if (keyPass == null) { |
|
3600 |
// Try to recover the key using the keystore password |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3601 |
if (storePass != null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3602 |
try { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3603 |
key = keyStore.getKey(alias, storePass); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3604 |
passwords.add(storePass); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3605 |
return Pair.of(key, storePass); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3606 |
} catch (UnrecoverableKeyException e) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3607 |
if (token) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3608 |
throw e; |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3609 |
} |
2 | 3610 |
} |
3611 |
} |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3612 |
// prompt user for key password |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3613 |
keyPass = getKeyPasswd(alias, null, null); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3614 |
key = keyStore.getKey(alias, keyPass); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3615 |
return Pair.of(key, keyPass); |
2 | 3616 |
} else { |
3617 |
key = keyStore.getKey(alias, keyPass); |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3618 |
return Pair.of(key, keyPass); |
2 | 3619 |
} |
3620 |
} |
|
3621 |
||
3622 |
/** |
|
3623 |
* Recovers entry associated with given alias. |
|
3624 |
* |
|
3625 |
* @return an array of objects, where the 1st element in the array is the |
|
3626 |
* recovered entry, and the 2nd element is the password used to |
|
3627 |
* recover it (null if no password). |
|
3628 |
*/ |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3629 |
private Pair<Entry,char[]> recoverEntry(KeyStore ks, |
2 | 3630 |
String alias, |
3631 |
char[] pstore, |
|
3632 |
char[] pkey) throws Exception { |
|
3633 |
||
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3634 |
if (!ks.containsAlias(alias)) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3635 |
MessageFormat form = new MessageFormat( |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3636 |
rb.getString("Alias.alias.does.not.exist")); |
2 | 3637 |
Object[] source = {alias}; |
3638 |
throw new Exception(form.format(source)); |
|
3639 |
} |
|
3640 |
||
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3641 |
// Step 1: First attempt to access entry without key password |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3642 |
// (PKCS11 entry or trusted certificate entry, for example). |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3643 |
// If fail, go next. |
2 | 3644 |
try { |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3645 |
Entry entry = ks.getEntry(alias, null); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3646 |
return Pair.of(entry, null); |
2 | 3647 |
} catch (UnrecoverableEntryException une) { |
3648 |
if(P11KEYSTORE.equalsIgnoreCase(ks.getType()) || |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3649 |
KeyStoreUtil.isWindowsKeyStore(ks.getType())) { |
2 | 3650 |
// should not happen, but a possibility |
3651 |
throw une; |
|
3652 |
} |
|
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3653 |
} |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3654 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3655 |
// entry is protected |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3656 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3657 |
// Step 2: try pkey if not null. If fail, fail. |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3658 |
if (pkey != null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3659 |
PasswordProtection pp = new PasswordProtection(pkey); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3660 |
Entry entry = ks.getEntry(alias, pp); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3661 |
return Pair.of(entry, pkey); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3662 |
} |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3663 |
|
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3664 |
// Step 3: try pstore if not null. If fail, go next. |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3665 |
if (pstore != null) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3666 |
try { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3667 |
PasswordProtection pp = new PasswordProtection(pstore); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3668 |
Entry entry = ks.getEntry(alias, pp); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3669 |
return Pair.of(entry, pstore); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3670 |
} catch (UnrecoverableEntryException une) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3671 |
if (P12KEYSTORE.equalsIgnoreCase(ks.getType())) { |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3672 |
// P12 keystore currently does not support separate |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3673 |
// store and entry passwords. We will not prompt for |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3674 |
// entry password. |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3675 |
throw une; |
2 | 3676 |
} |
3677 |
} |
|
3678 |
} |
|
3679 |
||
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3680 |
// Step 4: prompt for entry password |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3681 |
pkey = getKeyPasswd(alias, null, null); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3682 |
PasswordProtection pp = new PasswordProtection(pkey); |
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3683 |
Entry entry = ks.getEntry(alias, pp); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
3684 |
return Pair.of(entry, pkey); |
2 | 3685 |
} |
52996
2457d862a646
8076190: Customizing the generation of a PKCS12 keystore
weijun
parents:
52791
diff
changeset
|
3686 |
|
2 | 3687 |
/** |
3688 |
* Gets the requested finger print of the certificate. |
|
3689 |
*/ |
|
3690 |
private String getCertFingerPrint(String mdAlg, Certificate cert) |
|
3691 |
throws Exception |
|
3692 |
{ |
|
3693 |
byte[] encCertInfo = cert.getEncoded(); |
|
3694 |
MessageDigest md = MessageDigest.getInstance(mdAlg); |
|
3695 |
byte[] digest = md.digest(encCertInfo); |
|
3696 |
return toHexString(digest); |
|
3697 |
} |
|
3698 |
||
3699 |
/** |
|
3700 |
* Prints warning about missing integrity check. |
|
3701 |
*/ |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3702 |
private void printNoIntegrityWarning() { |
2 | 3703 |
System.err.println(); |
3704 |
System.err.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3705 |
(".WARNING.WARNING.WARNING.")); |
2 | 3706 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3707 |
(".The.integrity.of.the.information.stored.in.your.keystore.")); |
2 | 3708 |
System.err.println(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3709 |
(".WARNING.WARNING.WARNING.")); |
2 | 3710 |
System.err.println(); |
3711 |
} |
|
3712 |
||
3713 |
/** |
|
3714 |
* Validates chain in certification reply, and returns the ordered |
|
3715 |
* elements of the chain (with user certificate first, and root |
|
3716 |
* certificate last in the array). |
|
3717 |
* |
|
3718 |
* @param alias the alias name |
|
3719 |
* @param userCert the user certificate of the alias |
|
3720 |
* @param replyCerts the chain provided in the reply |
|
3721 |
*/ |
|
3722 |
private Certificate[] validateReply(String alias, |
|
3723 |
Certificate userCert, |
|
3724 |
Certificate[] replyCerts) |
|
3725 |
throws Exception |
|
3726 |
{ |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3727 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3728 |
checkWeak(rb.getString("reply"), replyCerts); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3729 |
|
2 | 3730 |
// order the certs in the reply (bottom-up). |
3731 |
// we know that all certs in the reply are of type X.509, because |
|
3732 |
// we parsed them using an X.509 certificate factory |
|
3733 |
int i; |
|
3734 |
PublicKey userPubKey = userCert.getPublicKey(); |
|
39046
db1dddd32a8f
6968542: keytool -importcert cannot deal with duplicate certs
weijun
parents:
38855
diff
changeset
|
3735 |
|
db1dddd32a8f
6968542: keytool -importcert cannot deal with duplicate certs
weijun
parents:
38855
diff
changeset
|
3736 |
// Remove duplicated certificates. |
db1dddd32a8f
6968542: keytool -importcert cannot deal with duplicate certs
weijun
parents:
38855
diff
changeset
|
3737 |
HashSet<Certificate> nodup = new HashSet<>(Arrays.asList(replyCerts)); |
db1dddd32a8f
6968542: keytool -importcert cannot deal with duplicate certs
weijun
parents:
38855
diff
changeset
|
3738 |
replyCerts = nodup.toArray(new Certificate[nodup.size()]); |
db1dddd32a8f
6968542: keytool -importcert cannot deal with duplicate certs
weijun
parents:
38855
diff
changeset
|
3739 |
|
2 | 3740 |
for (i=0; i<replyCerts.length; i++) { |
3741 |
if (userPubKey.equals(replyCerts[i].getPublicKey())) { |
|
3742 |
break; |
|
3743 |
} |
|
3744 |
} |
|
3745 |
if (i == replyCerts.length) { |
|
3746 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3747 |
("Certificate.reply.does.not.contain.public.key.for.alias.")); |
2 | 3748 |
Object[] source = {alias}; |
3749 |
throw new Exception(form.format(source)); |
|
3750 |
} |
|
3751 |
||
3752 |
Certificate tmpCert = replyCerts[0]; |
|
3753 |
replyCerts[0] = replyCerts[i]; |
|
3754 |
replyCerts[i] = tmpCert; |
|
2437
098db6faaf66
6825352: support self-issued certificate in keytool
weijun
parents:
2432
diff
changeset
|
3755 |
|
098db6faaf66
6825352: support self-issued certificate in keytool
weijun
parents:
2432
diff
changeset
|
3756 |
X509Certificate thisCert = (X509Certificate)replyCerts[0]; |
2 | 3757 |
|
3758 |
for (i=1; i < replyCerts.length-1; i++) { |
|
2437
098db6faaf66
6825352: support self-issued certificate in keytool
weijun
parents:
2432
diff
changeset
|
3759 |
// find a cert in the reply who signs thisCert |
2 | 3760 |
int j; |
3761 |
for (j=i; j<replyCerts.length; j++) { |
|
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
34381
diff
changeset
|
3762 |
if (KeyStoreUtil.signedBy(thisCert, (X509Certificate)replyCerts[j])) { |
2 | 3763 |
tmpCert = replyCerts[i]; |
3764 |
replyCerts[i] = replyCerts[j]; |
|
3765 |
replyCerts[j] = tmpCert; |
|
2437
098db6faaf66
6825352: support self-issued certificate in keytool
weijun
parents:
2432
diff
changeset
|
3766 |
thisCert = (X509Certificate)replyCerts[i]; |
2 | 3767 |
break; |
3768 |
} |
|
3769 |
} |
|
3770 |
if (j == replyCerts.length) { |
|
3771 |
throw new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3772 |
(rb.getString("Incomplete.certificate.chain.in.reply")); |
2 | 3773 |
} |
3774 |
} |
|
3775 |
||
3776 |
if (noprompt) { |
|
3777 |
return replyCerts; |
|
3778 |
} |
|
3779 |
||
5296 | 3780 |
// do we trust the cert at the top? |
2 | 3781 |
Certificate topCert = replyCerts[replyCerts.length-1]; |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3782 |
boolean fromKeyStore = true; |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3783 |
Pair<String,Certificate> root = getSigner(topCert, keyStore); |
5296 | 3784 |
if (root == null && trustcacerts && caks != null) { |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
3785 |
root = getSigner(topCert, caks); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3786 |
fromKeyStore = false; |
5296 | 3787 |
} |
3788 |
if (root == null) { |
|
3789 |
System.err.println(); |
|
3790 |
System.err.println |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3791 |
(rb.getString("Top.level.certificate.in.reply.")); |
5296 | 3792 |
printX509Cert((X509Certificate)topCert, System.out); |
3793 |
System.err.println(); |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3794 |
System.err.print(rb.getString(".is.not.trusted.")); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3795 |
printWeakWarnings(true); |
5296 | 3796 |
String reply = getYesNoReply |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3797 |
(rb.getString("Install.reply.anyway.no.")); |
5296 | 3798 |
if ("NO".equals(reply)) { |
3799 |
return null; |
|
2 | 3800 |
} |
5296 | 3801 |
} else { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3802 |
if (root.snd != topCert) { |
5296 | 3803 |
// append the root CA cert to the chain |
3804 |
Certificate[] tmpCerts = |
|
3805 |
new Certificate[replyCerts.length+1]; |
|
3806 |
System.arraycopy(replyCerts, 0, tmpCerts, 0, |
|
3807 |
replyCerts.length); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3808 |
tmpCerts[tmpCerts.length-1] = root.snd; |
5296 | 3809 |
replyCerts = tmpCerts; |
53398
dd1be616c95e
8215937: Check usages of security-related Resources files
weijun
parents:
53351
diff
changeset
|
3810 |
checkWeak(String.format(fromKeyStore |
dd1be616c95e
8215937: Check usages of security-related Resources files
weijun
parents:
53351
diff
changeset
|
3811 |
? rb.getString("alias.in.keystore") |
dd1be616c95e
8215937: Check usages of security-related Resources files
weijun
parents:
53351
diff
changeset
|
3812 |
: rb.getString("alias.in.cacerts"), |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3813 |
root.fst), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3814 |
root.snd); |
2 | 3815 |
} |
3816 |
} |
|
3817 |
return replyCerts; |
|
3818 |
} |
|
3819 |
||
3820 |
/** |
|
3821 |
* Establishes a certificate chain (using trusted certificates in the |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3822 |
* keystore and cacerts), starting with the reply (certToVerify) |
2 | 3823 |
* and ending at a self-signed certificate found in the keystore. |
3824 |
* |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3825 |
* @param userCert optional existing certificate, mostly likely be the |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3826 |
* original self-signed cert created by -genkeypair. |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3827 |
* It must have the same public key as certToVerify |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3828 |
* but cannot be the same cert. |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3829 |
* @param certToVerify the starting certificate to build the chain |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3830 |
* @returns the established chain, might be null if user decides not |
2 | 3831 |
*/ |
3832 |
private Certificate[] establishCertChain(Certificate userCert, |
|
3833 |
Certificate certToVerify) |
|
3834 |
throws Exception |
|
3835 |
{ |
|
3836 |
if (userCert != null) { |
|
3837 |
// Make sure that the public key of the certificate reply matches |
|
3838 |
// the original public key in the keystore |
|
3839 |
PublicKey origPubKey = userCert.getPublicKey(); |
|
3840 |
PublicKey replyPubKey = certToVerify.getPublicKey(); |
|
3841 |
if (!origPubKey.equals(replyPubKey)) { |
|
3842 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3843 |
("Public.keys.in.reply.and.keystore.don.t.match")); |
2 | 3844 |
} |
3845 |
||
3846 |
// If the two certs are identical, we're done: no need to import |
|
3847 |
// anything |
|
3848 |
if (certToVerify.equals(userCert)) { |
|
3849 |
throw new Exception(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3850 |
("Certificate.reply.and.certificate.in.keystore.are.identical")); |
2 | 3851 |
} |
3852 |
} |
|
3853 |
||
3854 |
// Build a hash table of all certificates in the keystore. |
|
3855 |
// Use the subject distinguished name as the key into the hash table. |
|
3856 |
// All certificates associated with the same subject distinguished |
|
3857 |
// name are stored in the same hash table entry as a vector. |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3858 |
Hashtable<Principal, Vector<Pair<String,X509Certificate>>> certs = null; |
2 | 3859 |
if (keyStore.size() > 0) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3860 |
certs = new Hashtable<>(11); |
2 | 3861 |
keystorecerts2Hashtable(keyStore, certs); |
3862 |
} |
|
3863 |
if (trustcacerts) { |
|
3864 |
if (caks!=null && caks.size()>0) { |
|
3865 |
if (certs == null) { |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3866 |
certs = new Hashtable<>(11); |
2 | 3867 |
} |
3868 |
keystorecerts2Hashtable(caks, certs); |
|
3869 |
} |
|
3870 |
} |
|
3871 |
||
3872 |
// start building chain |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3873 |
Vector<Pair<String,X509Certificate>> chain = new Vector<>(2); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3874 |
if (buildChain( |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3875 |
new Pair<>(rb.getString("the.input"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3876 |
(X509Certificate) certToVerify), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3877 |
chain, certs)) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3878 |
for (Pair<String,X509Certificate> p : chain) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3879 |
checkWeak(p.fst, p.snd); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3880 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3881 |
Certificate[] newChain = |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3882 |
new Certificate[chain.size()]; |
2 | 3883 |
// buildChain() returns chain with self-signed root-cert first and |
3884 |
// user-cert last, so we need to invert the chain before we store |
|
3885 |
// it |
|
3886 |
int j=0; |
|
3887 |
for (int i=chain.size()-1; i>=0; i--) { |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3888 |
newChain[j] = chain.elementAt(i).snd; |
2 | 3889 |
j++; |
3890 |
} |
|
3891 |
return newChain; |
|
3892 |
} else { |
|
3893 |
throw new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3894 |
(rb.getString("Failed.to.establish.chain.from.reply")); |
2 | 3895 |
} |
3896 |
} |
|
3897 |
||
3898 |
/** |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3899 |
* Recursively tries to establish chain from pool of certs starting from |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3900 |
* certToVerify until a self-signed cert is found, and fill the certs found |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3901 |
* into chain. Each cert in the chain signs the next one. |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3902 |
* |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3903 |
* This method is able to recover from an error, say, if certToVerify |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3904 |
* is signed by certA but certA has no issuer in certs and itself is not |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3905 |
* self-signed, the method can try another certB that also signs |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3906 |
* certToVerify and look for signer of certB, etc, etc. |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3907 |
* |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3908 |
* Each cert in chain comes with a label showing its origin. The label is |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3909 |
* used in the warning message when the cert is considered a risk. |
2 | 3910 |
* |
3911 |
* @param certToVerify the cert that needs to be verified. |
|
3912 |
* @param chain the chain that's being built. |
|
3913 |
* @param certs the pool of trusted certs |
|
3914 |
* |
|
3915 |
* @return true if successful, false otherwise. |
|
3916 |
*/ |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3917 |
private boolean buildChain(Pair<String,X509Certificate> certToVerify, |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3918 |
Vector<Pair<String,X509Certificate>> chain, |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3919 |
Hashtable<Principal, Vector<Pair<String,X509Certificate>>> certs) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3920 |
if (KeyStoreUtil.isSelfSigned(certToVerify.snd)) { |
2 | 3921 |
// reached self-signed root cert; |
3922 |
// no verification needed because it's trusted. |
|
3923 |
chain.addElement(certToVerify); |
|
3924 |
return true; |
|
3925 |
} |
|
3926 |
||
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3927 |
Principal issuer = certToVerify.snd.getIssuerDN(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3928 |
|
2 | 3929 |
// Get the issuer's certificate(s) |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3930 |
Vector<Pair<String,X509Certificate>> vec = certs.get(issuer); |
2 | 3931 |
if (vec == null) { |
3932 |
return false; |
|
3933 |
} |
|
3934 |
||
3935 |
// Try out each certificate in the vector, until we find one |
|
3936 |
// whose public key verifies the signature of the certificate |
|
3937 |
// in question. |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3938 |
for (Enumeration<Pair<String,X509Certificate>> issuerCerts = vec.elements(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3939 |
issuerCerts.hasMoreElements(); ) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3940 |
Pair<String,X509Certificate> issuerCert = issuerCerts.nextElement(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3941 |
PublicKey issuerPubKey = issuerCert.snd.getPublicKey(); |
2 | 3942 |
try { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3943 |
certToVerify.snd.verify(issuerPubKey); |
2 | 3944 |
} catch (Exception e) { |
3945 |
continue; |
|
3946 |
} |
|
3947 |
if (buildChain(issuerCert, chain, certs)) { |
|
3948 |
chain.addElement(certToVerify); |
|
3949 |
return true; |
|
3950 |
} |
|
3951 |
} |
|
3952 |
return false; |
|
3953 |
} |
|
3954 |
||
3955 |
/** |
|
3956 |
* Prompts user for yes/no decision. |
|
3957 |
* |
|
3958 |
* @return the user's decision, can only be "YES" or "NO" |
|
3959 |
*/ |
|
3960 |
private String getYesNoReply(String prompt) |
|
3961 |
throws IOException |
|
3962 |
{ |
|
3963 |
String reply = null; |
|
3964 |
int maxRetry = 20; |
|
3965 |
do { |
|
3966 |
if (maxRetry-- < 0) { |
|
3967 |
throw new RuntimeException(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3968 |
"Too.many.retries.program.terminated")); |
2 | 3969 |
} |
3970 |
System.err.print(prompt); |
|
3971 |
System.err.flush(); |
|
3972 |
reply = (new BufferedReader(new InputStreamReader |
|
3973 |
(System.in))).readLine(); |
|
43238
60b2aa915d98
8172975: SecurityTools.keytool() needs to accept user input
weijun
parents:
41960
diff
changeset
|
3974 |
if (reply == null || |
60b2aa915d98
8172975: SecurityTools.keytool() needs to accept user input
weijun
parents:
41960
diff
changeset
|
3975 |
collator.compare(reply, "") == 0 || |
2 | 3976 |
collator.compare(reply, rb.getString("n")) == 0 || |
3977 |
collator.compare(reply, rb.getString("no")) == 0) { |
|
3978 |
reply = "NO"; |
|
3979 |
} else if (collator.compare(reply, rb.getString("y")) == 0 || |
|
3980 |
collator.compare(reply, rb.getString("yes")) == 0) { |
|
3981 |
reply = "YES"; |
|
3982 |
} else { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
3983 |
System.err.println(rb.getString("Wrong.answer.try.again")); |
2 | 3984 |
reply = null; |
3985 |
} |
|
3986 |
} while (reply == null); |
|
3987 |
return reply; |
|
3988 |
} |
|
3989 |
||
3990 |
/** |
|
3991 |
* Stores the (leaf) certificates of a keystore in a hashtable. |
|
3992 |
* All certs belonging to the same CA are stored in a vector that |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3993 |
* in turn is stored in the hashtable, keyed by the CA's subject DN. |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3994 |
* Each cert comes with a string label that shows its origin and alias. |
2 | 3995 |
*/ |
3996 |
private void keystorecerts2Hashtable(KeyStore ks, |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
3997 |
Hashtable<Principal, Vector<Pair<String,X509Certificate>>> hash) |
2 | 3998 |
throws Exception { |
3999 |
||
4000 |
for (Enumeration<String> aliases = ks.aliases(); |
|
4001 |
aliases.hasMoreElements(); ) { |
|
4002 |
String alias = aliases.nextElement(); |
|
4003 |
Certificate cert = ks.getCertificate(alias); |
|
4004 |
if (cert != null) { |
|
4005 |
Principal subjectDN = ((X509Certificate)cert).getSubjectDN(); |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4006 |
Pair<String,X509Certificate> pair = new Pair<>( |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4007 |
String.format( |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4008 |
rb.getString(ks == caks ? |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4009 |
"alias.in.cacerts" : |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4010 |
"alias.in.keystore"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4011 |
alias), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4012 |
(X509Certificate)cert); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4013 |
Vector<Pair<String,X509Certificate>> vec = hash.get(subjectDN); |
2 | 4014 |
if (vec == null) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4015 |
vec = new Vector<>(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4016 |
vec.addElement(pair); |
2 | 4017 |
} else { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4018 |
if (!vec.contains(pair)) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4019 |
vec.addElement(pair); |
2 | 4020 |
} |
4021 |
} |
|
4022 |
hash.put(subjectDN, vec); |
|
4023 |
} |
|
4024 |
} |
|
4025 |
} |
|
4026 |
||
4027 |
/** |
|
4028 |
* Returns the issue time that's specified the -startdate option |
|
4029 |
* @param s the value of -startdate option |
|
4030 |
*/ |
|
4031 |
private static Date getStartDate(String s) throws IOException { |
|
4032 |
Calendar c = new GregorianCalendar(); |
|
4033 |
if (s != null) { |
|
4034 |
IOException ioe = new IOException( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4035 |
rb.getString("Illegal.startdate.value")); |
2 | 4036 |
int len = s.length(); |
4037 |
if (len == 0) { |
|
4038 |
throw ioe; |
|
4039 |
} |
|
4040 |
if (s.charAt(0) == '-' || s.charAt(0) == '+') { |
|
4041 |
// Form 1: ([+-]nnn[ymdHMS])+ |
|
4042 |
int start = 0; |
|
4043 |
while (start < len) { |
|
4044 |
int sign = 0; |
|
4045 |
switch (s.charAt(start)) { |
|
4046 |
case '+': sign = 1; break; |
|
4047 |
case '-': sign = -1; break; |
|
4048 |
default: throw ioe; |
|
4049 |
} |
|
4050 |
int i = start+1; |
|
4051 |
for (; i<len; i++) { |
|
4052 |
char ch = s.charAt(i); |
|
4053 |
if (ch < '0' || ch > '9') break; |
|
4054 |
} |
|
4055 |
if (i == start+1) throw ioe; |
|
4056 |
int number = Integer.parseInt(s.substring(start+1, i)); |
|
4057 |
if (i >= len) throw ioe; |
|
4058 |
int unit = 0; |
|
4059 |
switch (s.charAt(i)) { |
|
4060 |
case 'y': unit = Calendar.YEAR; break; |
|
4061 |
case 'm': unit = Calendar.MONTH; break; |
|
4062 |
case 'd': unit = Calendar.DATE; break; |
|
4063 |
case 'H': unit = Calendar.HOUR; break; |
|
4064 |
case 'M': unit = Calendar.MINUTE; break; |
|
4065 |
case 'S': unit = Calendar.SECOND; break; |
|
4066 |
default: throw ioe; |
|
4067 |
} |
|
4068 |
c.add(unit, sign * number); |
|
4069 |
start = i + 1; |
|
4070 |
} |
|
4071 |
} else { |
|
4072 |
// Form 2: [yyyy/mm/dd] [HH:MM:SS] |
|
4073 |
String date = null, time = null; |
|
4074 |
if (len == 19) { |
|
4075 |
date = s.substring(0, 10); |
|
4076 |
time = s.substring(11); |
|
4077 |
if (s.charAt(10) != ' ') |
|
4078 |
throw ioe; |
|
4079 |
} else if (len == 10) { |
|
4080 |
date = s; |
|
4081 |
} else if (len == 8) { |
|
4082 |
time = s; |
|
4083 |
} else { |
|
4084 |
throw ioe; |
|
4085 |
} |
|
4086 |
if (date != null) { |
|
4087 |
if (date.matches("\\d\\d\\d\\d\\/\\d\\d\\/\\d\\d")) { |
|
4088 |
c.set(Integer.valueOf(date.substring(0, 4)), |
|
4089 |
Integer.valueOf(date.substring(5, 7))-1, |
|
4090 |
Integer.valueOf(date.substring(8, 10))); |
|
4091 |
} else { |
|
4092 |
throw ioe; |
|
4093 |
} |
|
4094 |
} |
|
4095 |
if (time != null) { |
|
4096 |
if (time.matches("\\d\\d:\\d\\d:\\d\\d")) { |
|
4097 |
c.set(Calendar.HOUR_OF_DAY, Integer.valueOf(time.substring(0, 2))); |
|
40393
cb883ad42653
8141411: keytool can wrongly parse the start date value given by the -startdate option
weijun
parents:
40253
diff
changeset
|
4098 |
c.set(Calendar.MINUTE, Integer.valueOf(time.substring(3, 5))); |
cb883ad42653
8141411: keytool can wrongly parse the start date value given by the -startdate option
weijun
parents:
40253
diff
changeset
|
4099 |
c.set(Calendar.SECOND, Integer.valueOf(time.substring(6, 8))); |
2 | 4100 |
c.set(Calendar.MILLISECOND, 0); |
4101 |
} else { |
|
4102 |
throw ioe; |
|
4103 |
} |
|
4104 |
} |
|
4105 |
} |
|
4106 |
} |
|
4107 |
return c.getTime(); |
|
4108 |
} |
|
4109 |
||
4110 |
/** |
|
58902
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4111 |
* Match a command with a command set. The match can be exact, or |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4112 |
* partial, or case-insensitive. |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4113 |
* |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4114 |
* @param s the command provided by user |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4115 |
* @param list the legal command set. If there is a null, commands after it |
58902
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4116 |
* are regarded experimental, which means they are supported but their |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4117 |
* existence should not be revealed to user. |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4118 |
* @return the position of a single match, or -1 if none matched |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4119 |
* @throws Exception if s is ambiguous |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4120 |
*/ |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4121 |
private static int oneOf(String s, String... list) throws Exception { |
58902
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4122 |
|
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4123 |
// First, if there is an exact match, returns it. |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4124 |
int res = oneOfMatch((a,b) -> a.equals(b), s, list); |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4125 |
if (res >= 0) { |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4126 |
return res; |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4127 |
} |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4128 |
|
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4129 |
// Second, if there is one single camelCase or prefix match, returns it. |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4130 |
// This regex substitution removes all lowercase letters not at the |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4131 |
// beginning, so "keyCertSign" becomes "kCS". |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4132 |
res = oneOfMatch((a,b) -> a.equals(b.replaceAll("(?<!^)[a-z]", "")) |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4133 |
|| b.startsWith(a), s, list); |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4134 |
if (res >= 0) { |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4135 |
return res; |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4136 |
} |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4137 |
|
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4138 |
// Finally, retry the 2nd step ignoring case |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4139 |
return oneOfMatch((a,b) -> a.equalsIgnoreCase(b.replaceAll("(?<!^)[a-z]", "")) |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4140 |
|| b.toUpperCase(Locale.ROOT).startsWith(a.toUpperCase(Locale.ROOT)), |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4141 |
s, list); |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4142 |
} |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4143 |
|
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4144 |
/** |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4145 |
* Match a command with a command set. |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4146 |
* |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4147 |
* @param matcher a BiFunction which returns {@code true} if the 1st |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4148 |
* argument (user input) matches the 2nd one (full command) |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4149 |
* @param s the command provided by user |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4150 |
* @param list the legal command set |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4151 |
* @return the position of a single match, or -1 if none matched |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4152 |
* @throws Exception if s is ambiguous |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4153 |
*/ |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4154 |
private static int oneOfMatch(BiFunction<String,String,Boolean> matcher, |
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4155 |
String s, String... list) throws Exception { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4156 |
int[] match = new int[list.length]; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4157 |
int nmatch = 0; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4158 |
int experiment = Integer.MAX_VALUE; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4159 |
for (int i = 0; i<list.length; i++) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4160 |
String one = list[i]; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4161 |
if (one == null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4162 |
experiment = i; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4163 |
continue; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4164 |
} |
58902
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4165 |
if (matcher.apply(s, one)) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4166 |
match[nmatch++] = i; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4167 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4168 |
} |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4169 |
if (nmatch == 0) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4170 |
return -1; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4171 |
} else if (nmatch == 1) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4172 |
return match[0]; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4173 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4174 |
// If multiple matches is in experimental commands, ignore them |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4175 |
if (match[1] > experiment) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4176 |
return match[0]; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4177 |
} |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
24868
diff
changeset
|
4178 |
StringBuilder sb = new StringBuilder(); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4179 |
MessageFormat form = new MessageFormat(rb.getString |
58902
197238c30630
8231950: keytool -ext camel-case shorthand not working
weijun
parents:
55412
diff
changeset
|
4180 |
("command.{0}.is.ambiguous.")); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4181 |
Object[] source = {s}; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4182 |
sb.append(form.format(source)); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4183 |
sb.append("\n "); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4184 |
for (int i=0; i<nmatch && match[i]<experiment; i++) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4185 |
sb.append(' '); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4186 |
sb.append(list[match[i]]); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4187 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4188 |
throw new Exception(sb.toString()); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4189 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4190 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4191 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4192 |
/** |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4193 |
* Create a GeneralName object from known types |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4194 |
* @param t one of 5 known types |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4195 |
* @param v value |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4196 |
* @return which one |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4197 |
*/ |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4198 |
private GeneralName createGeneralName(String t, String v) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4199 |
throws Exception { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4200 |
GeneralNameInterface gn; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4201 |
int p = oneOf(t, "EMAIL", "URI", "DNS", "IP", "OID"); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4202 |
if (p < 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4203 |
throw new Exception(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4204 |
"Unrecognized.GeneralName.type.") + t); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4205 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4206 |
switch (p) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4207 |
case 0: gn = new RFC822Name(v); break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4208 |
case 1: gn = new URIName(v); break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4209 |
case 2: gn = new DNSName(v); break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4210 |
case 3: gn = new IPAddressName(v); break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4211 |
default: gn = new OIDName(v); break; //4 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4212 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4213 |
return new GeneralName(gn); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4214 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4215 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4216 |
private static final String[] extSupported = { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4217 |
"BasicConstraints", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4218 |
"KeyUsage", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4219 |
"ExtendedKeyUsage", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4220 |
"SubjectAlternativeName", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4221 |
"IssuerAlternativeName", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4222 |
"SubjectInfoAccess", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4223 |
"AuthorityInfoAccess", |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4224 |
null, |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4225 |
"CRLDistributionPoints", |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4226 |
}; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4227 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4228 |
private ObjectIdentifier findOidForExtName(String type) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4229 |
throws Exception { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4230 |
switch (oneOf(type, extSupported)) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4231 |
case 0: return PKIXExtensions.BasicConstraints_Id; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4232 |
case 1: return PKIXExtensions.KeyUsage_Id; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4233 |
case 2: return PKIXExtensions.ExtendedKeyUsage_Id; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4234 |
case 3: return PKIXExtensions.SubjectAlternativeName_Id; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4235 |
case 4: return PKIXExtensions.IssuerAlternativeName_Id; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4236 |
case 5: return PKIXExtensions.SubjectInfoAccess_Id; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4237 |
case 6: return PKIXExtensions.AuthInfoAccess_Id; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4238 |
case 8: return PKIXExtensions.CRLDistributionPoints_Id; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4239 |
default: return new ObjectIdentifier(type); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4240 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4241 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4242 |
|
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4243 |
// Add an extension into a CertificateExtensions, always using OID as key |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4244 |
private static void setExt(CertificateExtensions result, Extension ex) |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4245 |
throws IOException { |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4246 |
result.set(ex.getId(), ex); |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4247 |
} |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4248 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4249 |
/** |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4250 |
* Create X509v3 extensions from a string representation. Note that the |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4251 |
* SubjectKeyIdentifierExtension will always be created non-critical besides |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4252 |
* the extension requested in the <code>extstr</code> argument. |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4253 |
* |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4254 |
* @param requestedEx the requested extensions, can be null, used for -gencert |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4255 |
* @param existingEx the original extensions, can be null, used for -selfcert |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4256 |
* @param extstrs -ext values, Read keytool doc |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4257 |
* @param pkey the public key for the certificate |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4258 |
* @param akey the public key for the authority (issuer) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4259 |
* @return the created CertificateExtensions |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4260 |
*/ |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4261 |
private CertificateExtensions createV3Extensions( |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4262 |
CertificateExtensions requestedEx, |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4263 |
CertificateExtensions existingEx, |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4264 |
List <String> extstrs, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4265 |
PublicKey pkey, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4266 |
PublicKey akey) throws Exception { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4267 |
|
29225
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4268 |
// By design, inside a CertificateExtensions object, all known |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4269 |
// extensions uses name (say, "BasicConstraints") as key and |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4270 |
// a child Extension type (say, "BasicConstraintsExtension") |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4271 |
// as value, unknown extensions uses OID as key and bare |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4272 |
// Extension object as value. This works fine inside JDK. |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4273 |
// |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4274 |
// However, in keytool, there is no way to prevent people |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4275 |
// using OID in -ext, either as a new extension, or in a |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4276 |
// honored value. Thus here we (ab)use CertificateExtensions |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4277 |
// by always using OID as key and value can be of any type. |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4278 |
|
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4279 |
if (existingEx != null && requestedEx != null) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4280 |
// This should not happen |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4281 |
throw new Exception("One of request and original should be null."); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4282 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4283 |
// A new extensions always using OID as key |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4284 |
CertificateExtensions result = new CertificateExtensions(); |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4285 |
if (existingEx != null) { |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4286 |
for (Extension ex: existingEx.getAllExtensions()) { |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4287 |
setExt(result, ex); |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4288 |
} |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4289 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4290 |
try { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4291 |
// name{:critical}{=value} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4292 |
// Honoring requested extensions |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4293 |
if (requestedEx != null) { |
29225
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4294 |
// The existing requestedEx might use names as keys, |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4295 |
// translate to all-OID first. |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4296 |
CertificateExtensions request2 = new CertificateExtensions(); |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4297 |
for (sun.security.x509.Extension ex: requestedEx.getAllExtensions()) { |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4298 |
request2.set(ex.getId(), ex); |
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4299 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4300 |
for(String extstr: extstrs) { |
3948 | 4301 |
if (extstr.toLowerCase(Locale.ENGLISH).startsWith("honored=")) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4302 |
List<String> list = Arrays.asList( |
3948 | 4303 |
extstr.toLowerCase(Locale.ENGLISH).substring(8).split(",")); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4304 |
// First check existence of "all" |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4305 |
if (list.contains("all")) { |
29225
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4306 |
for (Extension ex: request2.getAllExtensions()) { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4307 |
setExt(result, ex); |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4308 |
} |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4309 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4310 |
// one by one for others |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4311 |
for (String item: list) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4312 |
if (item.equals("all")) continue; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4313 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4314 |
// add or remove |
29110
ea89fdd8a5d5
8073181: keytool -ext honored not working correctly
weijun
parents:
28243
diff
changeset
|
4315 |
boolean add; |
ea89fdd8a5d5
8073181: keytool -ext honored not working correctly
weijun
parents:
28243
diff
changeset
|
4316 |
// -1, unchanged, 0 critical, 1 non-critical |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4317 |
int action = -1; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4318 |
String type = null; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4319 |
if (item.startsWith("-")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4320 |
add = false; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4321 |
type = item.substring(1); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4322 |
} else { |
29110
ea89fdd8a5d5
8073181: keytool -ext honored not working correctly
weijun
parents:
28243
diff
changeset
|
4323 |
add = true; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4324 |
int colonpos = item.indexOf(':'); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4325 |
if (colonpos >= 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4326 |
type = item.substring(0, colonpos); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4327 |
action = oneOf(item.substring(colonpos+1), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4328 |
"critical", "non-critical"); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4329 |
if (action == -1) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4330 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4331 |
("Illegal.value.") + item); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4332 |
} |
29110
ea89fdd8a5d5
8073181: keytool -ext honored not working correctly
weijun
parents:
28243
diff
changeset
|
4333 |
} else { |
ea89fdd8a5d5
8073181: keytool -ext honored not working correctly
weijun
parents:
28243
diff
changeset
|
4334 |
type = item; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4335 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4336 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4337 |
String n = findOidForExtName(type).toString(); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4338 |
if (add) { |
29225
fb5b4b9d12f5
8074018: Named extension not recognized in keytool -ext honored after 8073182
weijun
parents:
29111
diff
changeset
|
4339 |
Extension e = request2.get(n); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4340 |
if (!e.isCritical() && action == 0 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4341 |
|| e.isCritical() && action == 1) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4342 |
e = Extension.newExtension( |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4343 |
e.getExtensionId(), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4344 |
!e.isCritical(), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4345 |
e.getExtensionValue()); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4346 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4347 |
setExt(result, e); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4348 |
} else { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4349 |
result.delete(n); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4350 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4351 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4352 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4353 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4354 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4355 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4356 |
for(String extstr: extstrs) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4357 |
String name, value; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4358 |
boolean isCritical = false; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4359 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4360 |
int eqpos = extstr.indexOf('='); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4361 |
if (eqpos >= 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4362 |
name = extstr.substring(0, eqpos); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4363 |
value = extstr.substring(eqpos+1); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4364 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4365 |
name = extstr; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4366 |
value = null; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4367 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4368 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4369 |
int colonpos = name.indexOf(':'); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4370 |
if (colonpos >= 0) { |
3316
32d30c561c5a
6847026: keytool should be able to generate certreq and cert without subject name
weijun
parents:
2437
diff
changeset
|
4371 |
if (oneOf(name.substring(colonpos+1), "critical") == 0) { |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4372 |
isCritical = true; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4373 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4374 |
name = name.substring(0, colonpos); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4375 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4376 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4377 |
if (name.equalsIgnoreCase("honored")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4378 |
continue; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4379 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4380 |
int exttype = oneOf(name, extSupported); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4381 |
switch (exttype) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4382 |
case 0: // BC |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4383 |
int pathLen = -1; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4384 |
boolean isCA = false; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4385 |
if (value == null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4386 |
isCA = true; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4387 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4388 |
try { // the abbr format |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4389 |
pathLen = Integer.parseInt(value); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4390 |
isCA = true; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4391 |
} catch (NumberFormatException ufe) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4392 |
// ca:true,pathlen:1 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4393 |
for (String part: value.split(",")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4394 |
String[] nv = part.split(":"); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4395 |
if (nv.length != 2) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4396 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4397 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4398 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4399 |
if (nv[0].equalsIgnoreCase("ca")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4400 |
isCA = Boolean.parseBoolean(nv[1]); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4401 |
} else if (nv[0].equalsIgnoreCase("pathlen")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4402 |
pathLen = Integer.parseInt(nv[1]); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4403 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4404 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4405 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4406 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4407 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4408 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4409 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4410 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4411 |
setExt(result, new BasicConstraintsExtension(isCritical, isCA, |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4412 |
pathLen)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4413 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4414 |
case 1: // KU |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4415 |
if(value != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4416 |
boolean[] ok = new boolean[9]; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4417 |
for (String s: value.split(",")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4418 |
int p = oneOf(s, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4419 |
"digitalSignature", // (0), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4420 |
"nonRepudiation", // (1) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4421 |
"keyEncipherment", // (2), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4422 |
"dataEncipherment", // (3), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4423 |
"keyAgreement", // (4), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4424 |
"keyCertSign", // (5), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4425 |
"cRLSign", // (6), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4426 |
"encipherOnly", // (7), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4427 |
"decipherOnly", // (8) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4428 |
"contentCommitment" // also (1) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4429 |
); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4430 |
if (p < 0) { |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4431 |
throw new Exception(rb.getString("Unknown.keyUsage.type.") + s); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4432 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4433 |
if (p == 9) p = 1; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4434 |
ok[p] = true; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4435 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4436 |
KeyUsageExtension kue = new KeyUsageExtension(ok); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4437 |
// The above KeyUsageExtension constructor does not |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4438 |
// allow isCritical value, so... |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4439 |
setExt(result, Extension.newExtension( |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4440 |
kue.getExtensionId(), |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4441 |
isCritical, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4442 |
kue.getExtensionValue())); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4443 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4444 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4445 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4446 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4447 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4448 |
case 2: // EKU |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4449 |
if(value != null) { |
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
4450 |
Vector<ObjectIdentifier> v = new Vector<>(); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4451 |
for (String s: value.split(",")) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4452 |
int p = oneOf(s, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4453 |
"anyExtendedKeyUsage", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4454 |
"serverAuth", //1 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4455 |
"clientAuth", //2 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4456 |
"codeSigning", //3 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4457 |
"emailProtection", //4 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4458 |
"", //5 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4459 |
"", //6 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4460 |
"", //7 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4461 |
"timeStamping", //8 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4462 |
"OCSPSigning" //9 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4463 |
); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4464 |
if (p < 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4465 |
try { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4466 |
v.add(new ObjectIdentifier(s)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4467 |
} catch (Exception e) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4468 |
throw new Exception(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4469 |
"Unknown.extendedkeyUsage.type.") + s); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4470 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4471 |
} else if (p == 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4472 |
v.add(new ObjectIdentifier("2.5.29.37.0")); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4473 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4474 |
v.add(new ObjectIdentifier("1.3.6.1.5.5.7.3." + p)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4475 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4476 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4477 |
setExt(result, new ExtendedKeyUsageExtension(isCritical, v)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4478 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4479 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4480 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4481 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4482 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4483 |
case 3: // SAN |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4484 |
case 4: // IAN |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4485 |
if(value != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4486 |
String[] ps = value.split(","); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4487 |
GeneralNames gnames = new GeneralNames(); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4488 |
for(String item: ps) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4489 |
colonpos = item.indexOf(':'); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4490 |
if (colonpos < 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4491 |
throw new Exception("Illegal item " + item + " in " + extstr); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4492 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4493 |
String t = item.substring(0, colonpos); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4494 |
String v = item.substring(colonpos+1); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4495 |
gnames.add(createGeneralName(t, v)); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4496 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4497 |
if (exttype == 3) { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4498 |
setExt(result, new SubjectAlternativeNameExtension( |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4499 |
isCritical, gnames)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4500 |
} else { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4501 |
setExt(result, new IssuerAlternativeNameExtension( |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4502 |
isCritical, gnames)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4503 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4504 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4505 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4506 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4507 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4508 |
break; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4509 |
case 5: // SIA, always non-critical |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4510 |
case 6: // AIA, always non-critical |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4511 |
if (isCritical) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4512 |
throw new Exception(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4513 |
"This.extension.cannot.be.marked.as.critical.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4514 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4515 |
if(value != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4516 |
List<AccessDescription> accessDescriptions = |
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
4517 |
new ArrayList<>(); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4518 |
String[] ps = value.split(","); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4519 |
for(String item: ps) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4520 |
colonpos = item.indexOf(':'); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4521 |
int colonpos2 = item.indexOf(':', colonpos+1); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4522 |
if (colonpos < 0 || colonpos2 < 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4523 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4524 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4525 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4526 |
String m = item.substring(0, colonpos); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4527 |
String t = item.substring(colonpos+1, colonpos2); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4528 |
String v = item.substring(colonpos2+1); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4529 |
int p = oneOf(m, |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4530 |
"", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4531 |
"ocsp", //1 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4532 |
"caIssuers", //2 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4533 |
"timeStamping", //3 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4534 |
"", |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4535 |
"caRepository" //5 |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4536 |
); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4537 |
ObjectIdentifier oid; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4538 |
if (p < 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4539 |
try { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4540 |
oid = new ObjectIdentifier(m); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4541 |
} catch (Exception e) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4542 |
throw new Exception(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4543 |
"Unknown.AccessDescription.type.") + m); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4544 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4545 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4546 |
oid = new ObjectIdentifier("1.3.6.1.5.5.7.48." + p); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4547 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4548 |
accessDescriptions.add(new AccessDescription( |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4549 |
oid, createGeneralName(t, v))); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4550 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4551 |
if (exttype == 5) { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4552 |
setExt(result, new SubjectInfoAccessExtension(accessDescriptions)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4553 |
} else { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4554 |
setExt(result, new AuthorityInfoAccessExtension(accessDescriptions)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4555 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4556 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4557 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4558 |
("Illegal.value.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4559 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4560 |
break; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4561 |
case 8: // CRL, experimental, only support 1 distributionpoint |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4562 |
if(value != null) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4563 |
String[] ps = value.split(","); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4564 |
GeneralNames gnames = new GeneralNames(); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4565 |
for(String item: ps) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4566 |
colonpos = item.indexOf(':'); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4567 |
if (colonpos < 0) { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4568 |
throw new Exception("Illegal item " + item + " in " + extstr); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4569 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4570 |
String t = item.substring(0, colonpos); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4571 |
String v = item.substring(colonpos+1); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4572 |
gnames.add(createGeneralName(t, v)); |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4573 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4574 |
setExt(result, new CRLDistributionPointsExtension( |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4575 |
isCritical, Collections.singletonList( |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4576 |
new DistributionPoint(gnames, null, null)))); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4577 |
} else { |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4578 |
throw new Exception(rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4579 |
("Illegal.value.") + extstr); |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4580 |
} |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4581 |
break; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4582 |
case -1: |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4583 |
ObjectIdentifier oid = new ObjectIdentifier(name); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4584 |
byte[] data = null; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4585 |
if (value != null) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4586 |
data = new byte[value.length() / 2 + 1]; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4587 |
int pos = 0; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4588 |
for (char c: value.toCharArray()) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4589 |
int hex; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4590 |
if (c >= '0' && c <= '9') { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4591 |
hex = c - '0' ; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4592 |
} else if (c >= 'A' && c <= 'F') { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4593 |
hex = c - 'A' + 10; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4594 |
} else if (c >= 'a' && c <= 'f') { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4595 |
hex = c - 'a' + 10; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4596 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4597 |
continue; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4598 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4599 |
if (pos % 2 == 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4600 |
data[pos/2] = (byte)(hex << 4); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4601 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4602 |
data[pos/2] += hex; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4603 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4604 |
pos++; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4605 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4606 |
if (pos % 2 != 0) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4607 |
throw new Exception(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4608 |
"Odd.number.of.hex.digits.found.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4609 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4610 |
data = Arrays.copyOf(data, pos/2); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4611 |
} else { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4612 |
data = new byte[0]; |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4613 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4614 |
setExt(result, new Extension(oid, isCritical, |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4615 |
new DerValue(DerValue.tag_OctetString, data) |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4616 |
.toByteArray())); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4617 |
break; |
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4618 |
default: |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4619 |
throw new Exception(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4620 |
"Unknown.extension.type.") + extstr); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4621 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4622 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4623 |
// always non-critical |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4624 |
setExt(result, new SubjectKeyIdentifierExtension( |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4625 |
new KeyIdentifier(pkey).getIdentifier())); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4626 |
if (akey != null && !pkey.equals(akey)) { |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4627 |
setExt(result, new AuthorityKeyIdentifierExtension( |
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4628 |
new KeyIdentifier(akey), null, null)); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4629 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4630 |
} catch(IOException e) { |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4631 |
throw new RuntimeException(e); |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4632 |
} |
29111
e9103f166a4a
8073182: keytool may generate duplicate extensions
weijun
parents:
29110
diff
changeset
|
4633 |
return result; |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4634 |
} |
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4635 |
|
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4636 |
private boolean isTrustedCert(Certificate cert) throws KeyStoreException { |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4637 |
if (caks != null && caks.getCertificateAlias(cert) != null) { |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4638 |
return true; |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4639 |
} else { |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4640 |
String inKS = keyStore.getCertificateAlias(cert); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4641 |
return inKS != null && keyStore.isCertificateEntry(inKS); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4642 |
} |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4643 |
} |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4644 |
|
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4645 |
private void checkWeak(String label, String sigAlg, Key key) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4646 |
|
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4647 |
if (sigAlg != null && !DISABLED_CHECK.permits( |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4648 |
SIG_PRIMITIVE_SET, sigAlg, null)) { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4649 |
weakWarnings.add(String.format( |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4650 |
rb.getString("whose.sigalg.risk"), label, sigAlg)); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4651 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4652 |
if (key != null && !DISABLED_CHECK.permits(SIG_PRIMITIVE_SET, key)) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4653 |
weakWarnings.add(String.format( |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4654 |
rb.getString("whose.key.risk"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4655 |
label, |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4656 |
String.format(rb.getString("key.bit"), |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4657 |
KeyUtil.getKeySize(key), key.getAlgorithm()))); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4658 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4659 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4660 |
|
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4661 |
private void checkWeak(String label, Certificate[] certs) |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4662 |
throws KeyStoreException { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4663 |
for (int i = 0; i < certs.length; i++) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4664 |
Certificate cert = certs[i]; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4665 |
if (cert instanceof X509Certificate) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4666 |
X509Certificate xc = (X509Certificate)cert; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4667 |
String fullLabel = label; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4668 |
if (certs.length > 1) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4669 |
fullLabel = oneInMany(label, i, certs.length); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4670 |
} |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4671 |
checkWeak(fullLabel, xc); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4672 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4673 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4674 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4675 |
|
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4676 |
private void checkWeak(String label, Certificate cert) |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4677 |
throws KeyStoreException { |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4678 |
if (cert instanceof X509Certificate) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4679 |
X509Certificate xc = (X509Certificate)cert; |
44419
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4680 |
// No need to check the sigalg of a trust anchor |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4681 |
String sigAlg = isTrustedCert(cert) ? null : xc.getSigAlgName(); |
c29f26282ba0
8177569: keytool should not warn if signature algorithm used in cacerts is weak
weijun
parents:
44046
diff
changeset
|
4682 |
checkWeak(label, sigAlg, xc.getPublicKey()); |
44046
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4683 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4684 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4685 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4686 |
private void checkWeak(String label, PKCS10 p10) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4687 |
checkWeak(label, p10.getSigAlg(), p10.getSubjectPublicKeyInfo()); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4688 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4689 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4690 |
private void checkWeak(String label, CRL crl, Key key) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4691 |
if (crl instanceof X509CRLImpl) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4692 |
X509CRLImpl impl = (X509CRLImpl)crl; |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4693 |
checkWeak(label, impl.getSigAlgName(), key); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4694 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4695 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4696 |
|
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4697 |
private void printWeakWarnings(boolean newLine) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4698 |
if (!weakWarnings.isEmpty() && !nowarn) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4699 |
System.err.println("\nWarning:"); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4700 |
for (String warning : weakWarnings) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4701 |
System.err.println(warning); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4702 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4703 |
if (newLine) { |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4704 |
// When calling before a yes/no prompt, add a new line |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4705 |
System.err.println(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4706 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4707 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4708 |
weakWarnings.clear(); |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4709 |
} |
762e807bfac1
8171319: keytool should print out warnings when reading or generating cert/cert req using weak algorithms
weijun
parents:
43238
diff
changeset
|
4710 |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4711 |
/** |
2 | 4712 |
* Prints the usage of this tool. |
4713 |
*/ |
|
4714 |
private void usage() { |
|
3948 | 4715 |
if (command != null) { |
4716 |
System.err.println("keytool " + command + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4717 |
rb.getString(".OPTION.")); |
3948 | 4718 |
System.err.println(); |
4719 |
System.err.println(rb.getString(command.description)); |
|
4720 |
System.err.println(); |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4721 |
System.err.println(rb.getString("Options.")); |
3948 | 4722 |
System.err.println(); |
4723 |
||
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4724 |
// Left and right sides of the options list. Both might |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4725 |
// contain "\n" and span multiple lines |
3948 | 4726 |
String[] left = new String[command.options.length]; |
4727 |
String[] right = new String[command.options.length]; |
|
4728 |
||
4729 |
// Length of left side of options list |
|
4730 |
int lenLeft = 0; |
|
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4731 |
|
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4732 |
for (int j = 0; j < command.options.length; j++) { |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
4733 |
Option opt = command.options[j]; |
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
4734 |
left[j] = opt.toString(); |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4735 |
if (opt.arg != null) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4736 |
left[j] += " " + opt.arg; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4737 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4738 |
String[] lefts = left[j].split("\n"); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4739 |
for (String s : lefts) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4740 |
if (s.length() > lenLeft) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4741 |
lenLeft = s.length(); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4742 |
} |
3948 | 4743 |
} |
4819
c1661a223e19
6922482: keytool's help on -file always shows 'output file'
weijun
parents:
4350
diff
changeset
|
4744 |
right[j] = rb.getString(opt.description); |
3948 | 4745 |
} |
39633
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4746 |
for (int j = 0; j < left.length; j++) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4747 |
String[] lefts = left[j].split("\n"); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4748 |
String[] rights = right[j].split("\n"); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4749 |
for (int i = 0; i < lefts.length && i < rights.length; i++) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4750 |
String s1 = i < lefts.length ? lefts[i] : ""; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4751 |
String s2 = i < rights.length ? rights[i] : ""; |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4752 |
if (i == 0) { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4753 |
System.err.printf(" %-" + lenLeft + "s %s\n", s1, s2); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4754 |
} else { |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4755 |
System.err.printf(" %-" + lenLeft + "s %s\n", s1, s2); |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4756 |
} |
9dc7586be5f0
8130302: jarsigner and keytool -providerClass needs be re-examined for modules
weijun
parents:
39046
diff
changeset
|
4757 |
} |
3948 | 4758 |
} |
4759 |
System.err.println(); |
|
4760 |
System.err.println(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4761 |
"Use.keytool.help.for.all.available.commands")); |
3948 | 4762 |
} else { |
4763 |
System.err.println(rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4764 |
"Key.and.Certificate.Management.Tool")); |
3948 | 4765 |
System.err.println(); |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4766 |
System.err.println(rb.getString("Commands.")); |
3948 | 4767 |
System.err.println(); |
4768 |
for (Command c: Command.values()) { |
|
5462
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4769 |
if (c == KEYCLONE) break; |
cb614e59f7f9
6890876: jarsigner can add CRL info into signed jar
weijun
parents:
5457
diff
changeset
|
4770 |
System.err.printf(" %-20s%s\n", c, rb.getString(c.description)); |
3948 | 4771 |
} |
4772 |
System.err.println(); |
|
4773 |
System.err.println(rb.getString( |
|
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
4774 |
"Use.keytool.help.for.all.available.commands")); |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48333
diff
changeset
|
4775 |
System.err.println(rb.getString( |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4776 |
"Use.keytool.command.name.help.for.usage.of.command.name")); |
3948 | 4777 |
} |
2 | 4778 |
} |
4779 |
||
4780 |
private void tinyHelp() { |
|
3948 | 4781 |
usage(); |
2 | 4782 |
if (debug) { |
4783 |
throw new RuntimeException("NO BIG ERROR, SORRY"); |
|
4784 |
} else { |
|
4785 |
System.exit(1); |
|
4786 |
} |
|
4787 |
} |
|
4788 |
||
4789 |
private void errorNeedArgument(String flag) { |
|
4790 |
Object[] source = {flag}; |
|
4791 |
System.err.println(new MessageFormat( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6688
diff
changeset
|
4792 |
rb.getString("Command.option.flag.needs.an.argument.")).format(source)); |
2 | 4793 |
tinyHelp(); |
4794 |
} |
|
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4795 |
|
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4796 |
private char[] getPass(String modifier, String arg) { |
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
11912
diff
changeset
|
4797 |
char[] output = KeyStoreUtil.getPassWithModifier(modifier, arg, rb); |
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4798 |
if (output != null) return output; |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4799 |
tinyHelp(); |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4800 |
return null; // Useless, tinyHelp() already exits. |
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4801 |
} |
2 | 4802 |
} |
4803 |
||
4804 |
// This class is exactly the same as com.sun.tools.javac.util.Pair, |
|
4805 |
// it's copied here since the original one is not included in JRE. |
|
4806 |
class Pair<A, B> { |
|
4807 |
||
4808 |
public final A fst; |
|
4809 |
public final B snd; |
|
4810 |
||
4811 |
public Pair(A fst, B snd) { |
|
4812 |
this.fst = fst; |
|
4813 |
this.snd = snd; |
|
4814 |
} |
|
4815 |
||
4816 |
public String toString() { |
|
4817 |
return "Pair[" + fst + "," + snd + "]"; |
|
4818 |
} |
|
4819 |
||
4820 |
public boolean equals(Object other) { |
|
4821 |
return |
|
4822 |
other instanceof Pair && |
|
10051 | 4823 |
Objects.equals(fst, ((Pair)other).fst) && |
4824 |
Objects.equals(snd, ((Pair)other).snd); |
|
2 | 4825 |
} |
4826 |
||
4827 |
public int hashCode() { |
|
4828 |
if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1; |
|
4829 |
else if (snd == null) return fst.hashCode() + 2; |
|
4830 |
else return fst.hashCode() * 17 + snd.hashCode(); |
|
4831 |
} |
|
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4832 |
|
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4833 |
public static <A,B> Pair<A,B> of(A a, B b) { |
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7179
diff
changeset
|
4834 |
return new Pair<>(a,b); |
2067
6f9db5f305cd
6780416: New keytool commands/options: -gencert, -printcertreq, -ext
weijun
parents:
909
diff
changeset
|
4835 |
} |
2 | 4836 |
} |
3951
e821908c953e
6868579: RFE: jarsigner to support reading password from environment variable
weijun
parents:
3948
diff
changeset
|
4837 |