1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package android.net.http; 19 20import android.net.http.SslCertificate; 21import android.test.suitebuilder.annotation.LargeTest; 22import java.io.ByteArrayInputStream; 23import java.security.cert.CertificateFactory; 24import java.security.cert.X509Certificate; 25import junit.framework.TestCase; 26 27public class SslCertificateTest extends TestCase { 28 29 /** 30 * Problematic certificate from Issue 1597 31 * http://code.google.com/p/android/issues/detail?id=1597 32 */ 33 private static final String Issue1597Certificate = 34 "-----BEGIN CERTIFICATE-----\n"+ 35 "MIIBnjCCAQegAwIBAgIFAKvN774wDQYJKoZIhvcNAQEFBQAwADAeFw0yNzA5MjQw\n"+ 36 "MDAwMDFaFw0zNzA5MjQwMDAwMDFaMAAwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ\n"+ 37 "AoGBAMNAaUSKw3stg6UHx6bWHNn0T5WR39UB43EZqdhhM0hnfpzwAzNs1T3jOAzF\n"+ 38 "OtgcX/XVt2Exc1vnwwuiJfvtPtBtQVsNu7wfk45cTUF45axBr4v8oFq7DOHCvs2C\n"+ 39 "pBDnw/v9PoOihuBamOjzRPL+oVhVfzEqEOILnZD1qEeVJn4RAgMBAAGjJDAiMCAG\n"+ 40 "A1UdEQQZMBeGD2h0dHBzOi8vMS4xLjEuMYcEAQEBATANBgkqhkiG9w0BAQUFAAOB\n"+ 41 "gQA7CMJylEjCR9CjztZUMLOutLe64RNhMq9iKgbDfJwYrcgvUNOxjrCdFW66lE9N\n"+ 42 "TDscc4zS2kpV41vcVYiGwabCNUPi2P6zfFSpYmGqwwu1NoEayqGPdDMrgCnMXVYV\n"+ 43 "X7HoVif4IdGvjFQrYcyU2VWSWBq6IGMVCR6RkC2YWnnNhw==\n"+ 44 "-----END CERTIFICATE-----\n"; 45 46 @LargeTest 47 public void testSslCertificateWithEmptyIssuer() throws Exception { 48 CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); 49 X509Certificate x509Certificate = (X509Certificate) 50 certificateFactory.generateCertificate(new ByteArrayInputStream(Issue1597Certificate.getBytes())); 51 assertEquals(x509Certificate.getIssuerDN().getName(), ""); 52 SslCertificate sslCertificate = new SslCertificate(x509Certificate); 53 assertEquals(sslCertificate.getIssuedBy().getDName(), ""); 54 } 55} 56