Path: blob/master/test/jdk/java/security/cert/CertificateFactory/GenerateCertificatesEmptyCollection.java
41153 views
/*1* Copyright (c) 2000, 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 437180126* @summary check that generateCertificates() returns an empty27* Collection when the input stream contains an encoded28* PKCS #7 SignedData object with no certificates.29*/3031import java.io.ByteArrayInputStream;32import java.security.cert.CertificateFactory;33import java.util.Collection;3435public class GenerateCertificatesEmptyCollection {3637public static void main(String[] args) throws Exception {38/*39* create an empty SignedData content type in ASN.140* as defined in PKCS#741*/42byte[] b = { 0x30, 0x23,43/* contentInfo ::= signedData */440x06, 0x09, 0x2A, (byte)0x86, 0x48,45(byte)0x86, (byte)0xF7, 0x0D,460x01, 0x07, 0x02,470x00, 0x16,480x30, 0x14, /* SignedData */490x02, 0x01, 0x01, /* version */500x31, 0x00, /* digestAlgorithms */510x30, 0x0B, /* contentInfo ::= data */520x06, 0x09, 0x2A, (byte)0x86, 0x48,53(byte)0x86, (byte)0xF7, 0x0D,540x01, 0x07, 0x01,55/* certificates are absent */560x31, 0x00 /* signerInfos */57};5859CertificateFactory cf = CertificateFactory.getInstance( "X509", "SUN");60Collection c = cf.generateCertificates( new ByteArrayInputStream(b));61if (!c.isEmpty())62throw new Exception("CertificateFactory.generateCertificates() "63+ "did not return an empty Collection");64}65}666768