android: Add activity to import certificate files
authorTobias Brunner <tobias@strongswan.org>
Fri, 30 May 2014 18:16:57 +0000 (20:16 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 22 Jul 2014 08:41:50 +0000 (10:41 +0200)
Such files can e.g. be opened from the Download view, if they are
associated with one of the supported mime-types.

src/frontends/android/AndroidManifest.xml
src/frontends/android/res/values-de/strings.xml
src/frontends/android/res/values-pl/strings.xml
src/frontends/android/res/values-ru/strings.xml
src/frontends/android/res/values-ua/strings.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateImportActivity.java [new file with mode: 0644]

index e2d25e4..887063f 100644 (file)
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
+        <activity
+            android:name=".ui.TrustedCertificateImportActivity"
+            android:label="@string/import_certificate" >
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:mimeType="application/x-x509-ca-cert" />
+                <data android:mimeType="application/x-x509-server-cert" />
+                <data android:mimeType="application/x-pem-file" />
+                <data android:mimeType="application/pkix-cert" />
+            </intent-filter>
+        </activity>
 
         <service
             android:name=".logic.VpnStateService"
index c9b6f9d..491fe8a 100644 (file)
@@ -81,6 +81,9 @@
     <string name="local_tab">Importiert</string>
     <string name="delete_certificate_question">Zertifikat löschen?</string>
     <string name="delete_certificate">Das Zertifikat wird permanent entfernt!</string>
+    <string name="import_certificate">Zertifikat importieren</string>
+    <string name="cert_imported_successfully">Zertifikat erfolgreich importiert</string>
+    <string name="cert_import_failed">Zertifikat-Import fehlgeschlagen</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
index 5bde18c..d0cfa48 100644 (file)
@@ -81,6 +81,9 @@
     <string name="local_tab">Imported</string>
     <string name="delete_certificate_question">Delete certificate?</string>
     <string name="delete_certificate">The certificate will be permanently removed!</string>
+    <string name="import_certificate">Import certificate</string>
+    <string name="cert_imported_successfully">Certificate successfully imported</string>
+    <string name="cert_import_failed">Failed to import certificate</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
index f61b251..eb69183 100644 (file)
@@ -78,6 +78,9 @@
     <string name="local_tab">Imported</string>
     <string name="delete_certificate_question">Delete certificate?</string>
     <string name="delete_certificate">The certificate will be permanently removed!</string>
+    <string name="import_certificate">Import certificate</string>
+    <string name="cert_imported_successfully">Certificate successfully imported</string>
+    <string name="cert_import_failed">Failed to import certificate</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Статус:</string>
index bff97ec..e23b9b9 100644 (file)
@@ -79,6 +79,9 @@
     <string name="local_tab">Imported</string>
     <string name="delete_certificate_question">Delete certificate?</string>
     <string name="delete_certificate">The certificate will be permanently removed!</string>
+    <string name="import_certificate">Import certificate</string>
+    <string name="cert_imported_successfully">Certificate successfully imported</string>
+    <string name="cert_import_failed">Failed to import certificate</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Статус:</string>
index f03d3e4..933a80a 100644 (file)
@@ -81,6 +81,9 @@
     <string name="local_tab">Imported</string>
     <string name="delete_certificate_question">Delete certificate?</string>
     <string name="delete_certificate">The certificate will be permanently removed!</string>
+    <string name="import_certificate">Import certificate</string>
+    <string name="cert_imported_successfully">Certificate successfully imported</string>
+    <string name="cert_import_failed">Failed to import certificate</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
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 (file)
index 0000000..663c414
--- /dev/null
@@ -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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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();
+       }
+}