AndroidCertVerifyResult.java revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.net; 6 7import org.chromium.base.CalledByNative; 8import org.chromium.base.JNINamespace; 9 10import java.security.cert.CertificateEncodingException; 11import java.security.cert.X509Certificate; 12import java.util.ArrayList; 13import java.util.Collections; 14import java.util.List; 15 16/** 17 * The result of a certification verification. 18 */ 19@JNINamespace("net::android") 20public class AndroidCertVerifyResult { 21 22 /** 23 * The verification status. One of the values in CertVerifyStatusAndroid. 24 */ 25 private final int mStatus; 26 27 /** 28 * True if the root CA in the chain is in the system store. 29 */ 30 private final boolean mIsIssuedByKnownRoot; 31 32 /** 33 * The properly ordered certificate chain used for verification. 34 */ 35 private final List<X509Certificate> mCertificateChain; 36 37 public AndroidCertVerifyResult(int status, 38 boolean isIssuedByKnownRoot, 39 List<X509Certificate> certificateChain) { 40 mStatus = status; 41 mIsIssuedByKnownRoot = isIssuedByKnownRoot; 42 mCertificateChain = new ArrayList<X509Certificate>(certificateChain); 43 } 44 45 public AndroidCertVerifyResult(int status) { 46 mStatus = status; 47 mIsIssuedByKnownRoot = false; 48 mCertificateChain = Collections.<X509Certificate>emptyList(); 49 } 50 51 @CalledByNative 52 public int getStatus() { 53 return mStatus; 54 } 55 56 @CalledByNative 57 public boolean isIssuedByKnownRoot() { 58 return mIsIssuedByKnownRoot; 59 } 60 61 @CalledByNative 62 public byte[][] getCertificateChainEncoded() { 63 byte[][] verifiedChainArray = new byte[mCertificateChain.size()][]; 64 try { 65 for (int i = 0; i < mCertificateChain.size(); i++) { 66 verifiedChainArray[i] = mCertificateChain.get(i).getEncoded(); 67 } 68 } catch (CertificateEncodingException e) { 69 return new byte[0][]; 70 } 71 return verifiedChainArray; 72 } 73} 74