Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/x509/AVA/EmailAddressEncoding.java
41153 views
1
/*
2
* Copyright (c) 2002, 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 4702543
27
* @summary incorrect ASN1 DER encoding of EmailAddress Attribute
28
* @modules java.base/sun.security.pkcs
29
* java.base/sun.security.util
30
*/
31
32
import java.io.*;
33
import javax.security.auth.x500.*;
34
import sun.security.util.*;
35
import sun.security.pkcs.*;
36
37
public class EmailAddressEncoding {
38
39
public static void main(String[] args) throws Exception {
40
X500Principal p = new X500Principal
41
("c=us, emailaddress=foo@bar, cn=foobar");
42
byte[] encoded = p.getEncoded();
43
44
// name is a sequence of RDN's
45
DerInputStream dis = new DerInputStream(encoded);
46
DerValue[] nameseq = dis.getSequence(3);
47
48
boolean passed = false;
49
for (int i = 0; i < nameseq.length; i++) {
50
51
// each RDN is a set of AttributeTypeAndValue
52
DerInputStream is = new DerInputStream(nameseq[i].toByteArray());
53
DerValue[] ava = is.getSet(3);
54
55
for (int j = 0; j < ava.length; j++) {
56
57
ObjectIdentifier oid = ava[j].data.getOID();
58
59
if (oid.equals(PKCS9Attribute.EMAIL_ADDRESS_OID)) {
60
DerValue value = ava[j].data.getDerValue();
61
if (value.getTag() == DerValue.tag_IA5String) {
62
passed = true;
63
break;
64
} else {
65
throw new SecurityException
66
("Test failed, expected EMAIL_ADDRESS tag '" +
67
DerValue.tag_IA5String +
68
"', got '" +
69
value.getTag() + "'");
70
}
71
}
72
}
73
74
if (passed) {
75
break;
76
}
77
}
78
79
if (passed) {
80
System.out.println("Test passed");
81
} else {
82
throw new SecurityException("Test failed");
83
}
84
}
85
}
86
87