From: Tobias Brunner Date: Fri, 30 May 2014 18:16:57 +0000 (+0200) Subject: android: Add activity to import certificate files X-Git-Tag: 5.2.1dr1~117^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94cc8f6a720ed034f6c6561a03c20257df3b2260;p=thirdparty%2Fstrongswan.git android: Add activity to import certificate files Such files can e.g. be opened from the Download view, if they are associated with one of the supported mime-types. --- diff --git a/src/frontends/android/AndroidManifest.xml b/src/frontends/android/AndroidManifest.xml index e2d25e4acc..887063faaa 100644 --- a/src/frontends/android/AndroidManifest.xml +++ b/src/frontends/android/AndroidManifest.xml @@ -67,6 +67,18 @@ + + + + + + + + + + Importiert Zertifikat löschen? Das Zertifikat wird permanent entfernt! + Zertifikat importieren + Zertifikat erfolgreich importiert + Zertifikat-Import fehlgeschlagen Status: diff --git a/src/frontends/android/res/values-pl/strings.xml b/src/frontends/android/res/values-pl/strings.xml index 5bde18c60a..d0cfa48f19 100644 --- a/src/frontends/android/res/values-pl/strings.xml +++ b/src/frontends/android/res/values-pl/strings.xml @@ -81,6 +81,9 @@ Imported Delete certificate? The certificate will be permanently removed! + Import certificate + Certificate successfully imported + Failed to import certificate Status: diff --git a/src/frontends/android/res/values-ru/strings.xml b/src/frontends/android/res/values-ru/strings.xml index f61b251fee..eb69183db5 100644 --- a/src/frontends/android/res/values-ru/strings.xml +++ b/src/frontends/android/res/values-ru/strings.xml @@ -78,6 +78,9 @@ Imported Delete certificate? The certificate will be permanently removed! + Import certificate + Certificate successfully imported + Failed to import certificate Статус: diff --git a/src/frontends/android/res/values-ua/strings.xml b/src/frontends/android/res/values-ua/strings.xml index bff97ecb1a..e23b9b9b27 100644 --- a/src/frontends/android/res/values-ua/strings.xml +++ b/src/frontends/android/res/values-ua/strings.xml @@ -79,6 +79,9 @@ Imported Delete certificate? The certificate will be permanently removed! + Import certificate + Certificate successfully imported + Failed to import certificate Статус: diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml index f03d3e4285..933a80aff1 100644 --- a/src/frontends/android/res/values/strings.xml +++ b/src/frontends/android/res/values/strings.xml @@ -81,6 +81,9 @@ Imported Delete certificate? The certificate will be permanently removed! + Import certificate + Certificate successfully imported + Failed to import certificate Status: diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateImportActivity.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateImportActivity.java new file mode 100644 index 0000000000..663c414e2e --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateImportActivity.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2014 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.ui; + +import java.io.InputStream; +import java.security.KeyStore; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; + +import org.strongswan.android.R; +import org.strongswan.android.logic.TrustedCertificateManager; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.widget.Toast; + +public class TrustedCertificateImportActivity extends Activity +{ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + Intent intent = getIntent(); + String action = intent.getAction(); + if (Intent.ACTION_VIEW.equals(action)) + { + try + { + CertificateFactory factory = CertificateFactory.getInstance("X.509"); + InputStream in = getContentResolver().openInputStream(intent.getData()); + X509Certificate certificate = (X509Certificate)factory.generateCertificate(in); + /* we don't check whether it's actually a CA certificate or not */ + KeyStore store = KeyStore.getInstance("LocalCertificateStore"); + store.load(null, null); + store.setCertificateEntry(null, certificate); + TrustedCertificateManager.getInstance().reset(); + Toast.makeText(this, R.string.cert_imported_successfully, Toast.LENGTH_LONG).show(); + } + catch (Exception e) + { + Toast.makeText(this, R.string.cert_import_failed, Toast.LENGTH_LONG).show(); + e.printStackTrace(); + } + } + finish(); + } +}