16505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom/*
26505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  Licensed to the Apache Software Foundation (ASF) under one or more
36505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  contributor license agreements.  See the NOTICE file distributed with
46505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  this work for additional information regarding copyright ownership.
56505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  The ASF licenses this file to You under the Apache License, Version 2.0
66505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  (the "License"); you may not use this file except in compliance with
76505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  the License.  You may obtain a copy of the License at
86505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *
96505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *     http://www.apache.org/licenses/LICENSE-2.0
106505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *
116505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  Unless required by applicable law or agreed to in writing, software
126505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  distributed under the License is distributed on an "AS IS" BASIS,
136505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
146505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  See the License for the specific language governing permissions and
156505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom *  limitations under the License.
166505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom */
176505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom
186505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrompackage android.net.http;
196505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom
206505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstromimport android.net.http.SslCertificate;
216505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstromimport android.test.suitebuilder.annotation.LargeTest;
226505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstromimport java.io.ByteArrayInputStream;
236505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstromimport java.security.cert.CertificateFactory;
246505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstromimport java.security.cert.X509Certificate;
256505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstromimport junit.framework.TestCase;
266505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom
276505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrompublic class SslCertificateTest extends TestCase {
286505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom
296505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom    /**
306505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom     * Problematic certificate from Issue 1597
316505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom     * http://code.google.com/p/android/issues/detail?id=1597
326505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom     */
336505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom    private static final String Issue1597Certificate =
346505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "-----BEGIN CERTIFICATE-----\n"+
356505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "MIIBnjCCAQegAwIBAgIFAKvN774wDQYJKoZIhvcNAQEFBQAwADAeFw0yNzA5MjQw\n"+
366505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "MDAwMDFaFw0zNzA5MjQwMDAwMDFaMAAwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ\n"+
376505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "AoGBAMNAaUSKw3stg6UHx6bWHNn0T5WR39UB43EZqdhhM0hnfpzwAzNs1T3jOAzF\n"+
386505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "OtgcX/XVt2Exc1vnwwuiJfvtPtBtQVsNu7wfk45cTUF45axBr4v8oFq7DOHCvs2C\n"+
396505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "pBDnw/v9PoOihuBamOjzRPL+oVhVfzEqEOILnZD1qEeVJn4RAgMBAAGjJDAiMCAG\n"+
406505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "A1UdEQQZMBeGD2h0dHBzOi8vMS4xLjEuMYcEAQEBATANBgkqhkiG9w0BAQUFAAOB\n"+
416505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "gQA7CMJylEjCR9CjztZUMLOutLe64RNhMq9iKgbDfJwYrcgvUNOxjrCdFW66lE9N\n"+
426505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "TDscc4zS2kpV41vcVYiGwabCNUPi2P6zfFSpYmGqwwu1NoEayqGPdDMrgCnMXVYV\n"+
436505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "X7HoVif4IdGvjFQrYcyU2VWSWBq6IGMVCR6RkC2YWnnNhw==\n"+
446505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        "-----END CERTIFICATE-----\n";
456505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom
466505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom    @LargeTest
476505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom    public void testSslCertificateWithEmptyIssuer() throws Exception {
486505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
496505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        X509Certificate x509Certificate = (X509Certificate)
506505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom            certificateFactory.generateCertificate(new ByteArrayInputStream(Issue1597Certificate.getBytes()));
516505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        assertEquals(x509Certificate.getIssuerDN().getName(), "");
526505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        SslCertificate sslCertificate = new SslCertificate(x509Certificate);
536505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom        assertEquals(sslCertificate.getIssuedBy().getDName(), "");
546505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom    }
556505122dfe96322bdeac4210d313b3f043c6a29aBrian Carlstrom}
56