kopia lustrzana https://github.com/ge0rg/aprsdroid
ssl: implement import of .bks files
rodzic
6f0227359e
commit
a6f9803b51
|
@ -68,6 +68,17 @@
|
|||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".KeyfileImportActivity" android:label="@string/ssl_import_activity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="file" />
|
||||
<data android:mimeType="*/*" />
|
||||
<data android:pathPattern=".*\\.bks" />
|
||||
<data android:host="*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".AprsService" android:label="@string/aprsservice">
|
||||
<intent-filter>
|
||||
<action android:name="org.aprsdroid.app.SERVICE" />
|
||||
|
|
|
@ -350,4 +350,10 @@
|
|||
<!-- TCP/IP TNC settings -->
|
||||
<string name="p_tcptnc_server_summary">KISS TCP server to contact</string>
|
||||
<string name="p_tcptnc_entry">Enter the KISS server hostname</string>
|
||||
|
||||
<!-- SSL strings -->
|
||||
<string name="ssl_import_activity">Import keyfile into APRSdroid</string>
|
||||
<string name="ssl_no_keyfile">No keyfile for %s! Using plaintext.</string>
|
||||
<string name="ssl_import_ok">Imported keyfile for %s.</string>
|
||||
<string name="ssl_import_error">Error importing keyfile: %s!</string>
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package org.aprsdroid.app
|
||||
|
||||
import _root_.android.app.Activity
|
||||
import _root_.android.content.Context
|
||||
import _root_.android.os.Bundle
|
||||
import _root_.android.preference.PreferenceManager
|
||||
import _root_.android.util.Log
|
||||
import _root_.android.widget.Toast
|
||||
|
||||
import _root_.java.io.File
|
||||
import _root_.java.io.FileOutputStream
|
||||
import _root_.java.security.KeyStore
|
||||
import _root_.java.security.cert.X509Certificate
|
||||
|
||||
import scala.collection.JavaConversions._ // for enumeration of keystore aliases
|
||||
|
||||
class KeyfileImportActivity extends Activity {
|
||||
val TAG = "APRSdroid.KeyImport"
|
||||
val KEYSTORE_PASS = "APRS-IS".toCharArray()
|
||||
val KEYSTORE_DIR = "keystore"
|
||||
|
||||
val CALL_RE = ".*CALLSIGN=([0-9A-Za-z]+).*".r
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Log.d(TAG, "created: " + getIntent())
|
||||
try {
|
||||
val ks = KeyStore.getInstance("BKS")
|
||||
ks.load(getContentResolver().openInputStream(getIntent.getData()), KEYSTORE_PASS)
|
||||
var callsign : String = null
|
||||
for (alias <- ks.aliases()) {
|
||||
if (ks.isKeyEntry(alias)) {
|
||||
val c = ks.getCertificate(alias).asInstanceOf[X509Certificate]
|
||||
// work around missing X500Principal.getName(String, Map<String, String) on SDK<9:
|
||||
val dn = c.getSubjectX500Principal().toString()
|
||||
.replace("OID.1.3.6.1.4.1.12348.1.1=", "CALLSIGN=")
|
||||
Log.d(TAG, "Loaded key: " + dn)
|
||||
dn match {
|
||||
case CALL_RE(call) => callsign = call
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callsign != null) {
|
||||
val dir = getApplicationContext().getDir(KEYSTORE_DIR, Context.MODE_PRIVATE)
|
||||
val keyStoreFile = new File(dir + File.separator + callsign + ".bks")
|
||||
ks.store(new FileOutputStream(keyStoreFile), KEYSTORE_PASS)
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.edit().putString("callsign", callsign).commit()
|
||||
|
||||
Toast.makeText(this, getString(R.string.ssl_import_ok, callsign), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} catch {
|
||||
case e : Exception =>
|
||||
Toast.makeText(this, getString(R.string.ssl_import_error, e.getMessage()), Toast.LENGTH_SHORT).show()
|
||||
e.printStackTrace()
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
|
@ -100,7 +100,7 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsBacke
|
|||
} catch {
|
||||
case e : java.io.FileNotFoundException =>
|
||||
service.postAddPost(StorageDatabase.Post.TYPE_INFO, R.string.post_info,
|
||||
"No keyfile for '%s'! Using plaintext.".format(prefs.getCallsign()))
|
||||
service.getString(R.string.ssl_no_keyfile, prefs.getCallsign()))
|
||||
return null
|
||||
case e : Exception =>
|
||||
e.printStackTrace()
|
||||
|
|
Ładowanie…
Reference in New Issue