From: Tobias Brunner Date: Mon, 13 Aug 2012 16:41:34 +0000 (+0200) Subject: Added class to store trusted certificate entries for lists X-Git-Tag: 5.0.1~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dc89984191807ea1c859f7cd8dfc333fd078e15;p=thirdparty%2Fstrongswan.git Added class to store trusted certificate entries for lists --- diff --git a/src/frontends/android/src/org/strongswan/android/data/TrustedCertificateEntry.java b/src/frontends/android/src/org/strongswan/android/data/TrustedCertificateEntry.java new file mode 100644 index 0000000000..bedf06f744 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/data/TrustedCertificateEntry.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2012 Tobias Brunner + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package org.strongswan.android.data; + +import java.security.cert.X509Certificate; + +import android.net.http.SslCertificate; + +public class TrustedCertificateEntry implements Comparable +{ + private final X509Certificate mCert; + private final String mAlias; + private String mSubjectPrimary; + private String mSubjectSecondary = ""; + private String mString; + + /** + * Create an entry for certificate lists. + * + * @param alias alias of the certificate (as used in the KeyStore) + * @param cert certificate associated with that alias + */ + public TrustedCertificateEntry(String alias, X509Certificate cert) + { + mCert = cert; + mAlias = alias; + + SslCertificate ssl = new SslCertificate(mCert); + String o = ssl.getIssuedTo().getOName(); + String ou = ssl.getIssuedTo().getUName(); + String cn = ssl.getIssuedTo().getCName(); + if (!o.isEmpty()) + { + mSubjectPrimary = o; + if (!cn.isEmpty()) + { + mSubjectSecondary = cn; + } + else if (!ou.isEmpty()) + { + mSubjectSecondary = ou; + } + } + else if (!cn.isEmpty()) + { + mSubjectPrimary = cn; + } + else + { + mSubjectPrimary = ssl.getIssuedTo().getDName(); + } + } + + /** + * The main subject of this certificate (O, CN or the complete DN, whatever + * is found first). + * + * @return the main subject + */ + public String getSubjectPrimary() + { + return mSubjectPrimary; + } + + /** + * Get the secondary subject of this certificate (either CN or OU if primary + * subject is O, empty otherwise) + * + * @return the secondary subject + */ + public String getSubjectSecondary() + { + return mSubjectSecondary; + } + + /** + * The alias associated with this certificate. + * + * @return KeyStore alias of this certificate + */ + public String getAlias() + { + return mAlias; + } + + /** + * The certificate. + * + * @return certificate + */ + public X509Certificate getCertificate() + { + return mCert; + } + + @Override + public int compareTo(TrustedCertificateEntry another) + { + int diff = mSubjectPrimary.compareToIgnoreCase(another.mSubjectPrimary); + if (diff == 0) + { + diff = mSubjectSecondary.compareToIgnoreCase(another.mSubjectSecondary); + } + return diff; + } +}