Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/x509/AlgorithmId/NonStandardNames.java
41153 views
1
/*
2
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 7180907
27
* @summary Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
28
* @modules java.base/sun.security.pkcs
29
* java.base/sun.security.tools.keytool
30
* java.base/sun.security.util
31
* java.base/sun.security.x509
32
* @compile -XDignore.symbol.file NonStandardNames.java
33
* @run main NonStandardNames
34
*/
35
36
import java.security.MessageDigest;
37
import java.security.Signature;
38
import java.security.cert.X509Certificate;
39
import sun.security.pkcs.ContentInfo;
40
import sun.security.pkcs.PKCS7;
41
import sun.security.pkcs.PKCS9Attribute;
42
import sun.security.pkcs.PKCS9Attributes;
43
import sun.security.pkcs.SignerInfo;
44
import sun.security.tools.keytool.CertAndKeyGen;
45
import sun.security.x509.AlgorithmId;
46
import sun.security.x509.X500Name;
47
48
public class NonStandardNames {
49
50
public static void main(String[] args) throws Exception {
51
52
byte[] data = "Hello".getBytes();
53
X500Name n = new X500Name("cn=Me");
54
55
CertAndKeyGen cakg = new CertAndKeyGen("RSA", "SHA256withRSA");
56
cakg.generate(1024);
57
X509Certificate cert = cakg.getSelfCertificate(n, 1000);
58
59
MessageDigest md = MessageDigest.getInstance("SHA-256");
60
PKCS9Attributes authed = new PKCS9Attributes(new PKCS9Attribute[]{
61
new PKCS9Attribute(PKCS9Attribute.CONTENT_TYPE_OID, ContentInfo.DATA_OID),
62
new PKCS9Attribute(PKCS9Attribute.MESSAGE_DIGEST_OID, md.digest(data)),
63
});
64
65
Signature s = Signature.getInstance("SHA256withRSA");
66
s.initSign(cakg.getPrivateKey());
67
s.update(authed.getDerEncoding());
68
byte[] sig = s.sign();
69
70
SignerInfo signerInfo = new SignerInfo(
71
n,
72
cert.getSerialNumber(),
73
AlgorithmId.get("SHA-256"),
74
authed,
75
AlgorithmId.get("SHA256withRSA"),
76
sig,
77
null
78
);
79
80
PKCS7 pkcs7 = new PKCS7(
81
new AlgorithmId[] {signerInfo.getDigestAlgorithmId()},
82
new ContentInfo(data),
83
new X509Certificate[] {cert},
84
new SignerInfo[] {signerInfo});
85
86
if (pkcs7.verify(signerInfo, data) == null) {
87
throw new Exception("Not verified");
88
}
89
}
90
}
91
92