Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/x509/AVA/EmailAddressEncoding.java
38854 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 470254326* @summary incorrect ASN1 DER encoding of EmailAddress Attribute27*/2829import java.io.*;30import javax.security.auth.x500.*;31import sun.security.util.*;32import sun.security.pkcs.*;33import sun.security.x509.*;3435public class EmailAddressEncoding {3637public static void main(String[] args) throws Exception {38X500Principal p = new X500Principal39("c=us, emailaddress=foo@bar, cn=foobar");40byte[] encoded = p.getEncoded();4142// name is a sequence of RDN's43DerInputStream dis = new DerInputStream(encoded);44DerValue[] nameseq = dis.getSequence(3);4546boolean passed = false;47for (int i = 0; i < nameseq.length; i++) {4849// each RDN is a set of AttributeTypeAndValue50DerInputStream is = new DerInputStream(nameseq[i].toByteArray());51DerValue[] ava = is.getSet(3);5253for (int j = 0; j < ava.length; j++) {5455ObjectIdentifier oid = ava[j].data.getOID();5657if (oid.equals(PKCS9Attribute.EMAIL_ADDRESS_OID)) {58DerValue value = ava[j].data.getDerValue();59if (value.getTag() == DerValue.tag_IA5String) {60passed = true;61break;62} else {63throw new SecurityException64("Test failed, expected EMAIL_ADDRESS tag '" +65DerValue.tag_IA5String +66"', got '" +67value.getTag() + "'");68}69}70}7172if (passed) {73break;74}75}7677if (passed) {78System.out.println("Test passed");79} else {80throw new SecurityException("Test failed");81}82}83}848586