<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"
<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>
<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>
<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>
<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>
<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>
--- /dev/null
+/*
+ * 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();
+ }
+}