Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/pkcs/pkcs9/UnknownAttribute.java
41155 views
1
/*
2
* Copyright (c) 2013, 2020, 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 8011867 8242151
27
* @summary Accept unknown PKCS #9 attributes
28
* @library /test/lib
29
* @modules java.base/sun.security.pkcs
30
* java.base/sun.security.util
31
*/
32
33
import java.io.*;
34
import java.util.Arrays;
35
36
import sun.security.pkcs.PKCS9Attribute;
37
import sun.security.util.DerValue;
38
import sun.security.util.ObjectIdentifier;
39
import jdk.test.lib.hexdump.HexPrinter;
40
41
public class UnknownAttribute {
42
43
public static void main(String[] args) throws Exception {
44
// Unknown attr
45
PKCS9Attribute p1 = new PKCS9Attribute(
46
PKCS9Attribute.CHALLENGE_PASSWORD_OID, "t0p5ecr3t");
47
if (!p1.isKnown()) {
48
throw new Exception();
49
}
50
// Unknown attr from DER
51
byte[] data = {
52
0x30, 0x08, // SEQUENCE OF
53
0x06, 0x02, 0x2A, 0x03, // OID 1.2.3 and
54
0x31, 0x02, 0x05, 0x00 // an empty SET
55
};
56
PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
57
if (p2.isKnown()) {
58
throw new Exception();
59
}
60
ByteArrayOutputStream bout = new ByteArrayOutputStream();
61
p2.derEncode(bout);
62
HexPrinter.simple().dest(System.err).format(bout.toByteArray());
63
if (!Arrays.equals(data, bout.toByteArray())) {
64
throw new Exception();
65
}
66
// Unknown attr from value
67
try {
68
new PKCS9Attribute(ObjectIdentifier.of("1.2.3"), "hello");
69
throw new Exception();
70
} catch (IllegalArgumentException iae) {
71
// Good. Unknown attr must have byte[] value type
72
}
73
PKCS9Attribute p3 = new PKCS9Attribute(
74
ObjectIdentifier.of("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
75
if (p3.isKnown()) {
76
throw new Exception();
77
}
78
bout = new ByteArrayOutputStream();
79
p3.derEncode(bout);
80
if (!Arrays.equals(data, bout.toByteArray())) {
81
throw new Exception();
82
}
83
}
84
}
85
86