- Added possibility to configure baresip a TLS certificate and
CA certificates.
This commit is contained in:
@ -642,7 +642,11 @@ class BaresipService: Service() {
|
||||
fun stopped(error: String) {
|
||||
Log.d(LOG_TAG, "'stopped' from baresip with error $error")
|
||||
isServiceRunning = false
|
||||
if (error == "ua_init") Config.remove("sip_listen")
|
||||
if (error == "ua_init") {
|
||||
Config.remove("sip_listen")
|
||||
Config.remove("sip_certificate")
|
||||
Config.remove("sip_cafile")
|
||||
}
|
||||
val intent = Intent("service event")
|
||||
intent.putExtra("event", "stopped")
|
||||
intent.putExtra("params", arrayListOf(error))
|
||||
|
||||
@ -6,18 +6,23 @@ import android.content.Intent
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
import java.io.File
|
||||
|
||||
class ConfigActivity : AppCompatActivity() {
|
||||
|
||||
internal lateinit var autoStart: CheckBox
|
||||
internal lateinit var listenAddr: EditText
|
||||
internal lateinit var preferIPv6: CheckBox
|
||||
internal lateinit var dnsServers: EditText
|
||||
internal lateinit var certificateFile: CheckBox
|
||||
internal lateinit var caFile: CheckBox
|
||||
internal lateinit var aec: CheckBox
|
||||
internal lateinit var opusBitRate: EditText
|
||||
internal lateinit var iceLite: CheckBox
|
||||
@ -28,6 +33,8 @@ class ConfigActivity : AppCompatActivity() {
|
||||
private var oldListenAddr = ""
|
||||
private var oldPreferIPv6 = ""
|
||||
private var oldDnsServers = ""
|
||||
private var oldCertificateFile = false
|
||||
private var oldCAFile = false
|
||||
private var oldAec = false
|
||||
private var oldOpusBitrate = ""
|
||||
private var oldIceMode = ""
|
||||
@ -35,6 +42,8 @@ class ConfigActivity : AppCompatActivity() {
|
||||
private var callVolume = BaresipService.callVolume
|
||||
private var save = false
|
||||
private var restart = false
|
||||
private var downloadsDir =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
@ -68,6 +77,14 @@ class ConfigActivity : AppCompatActivity() {
|
||||
}
|
||||
dnsServers.setText(oldDnsServers)
|
||||
|
||||
certificateFile = findViewById(R.id.CertificateFile) as CheckBox
|
||||
oldCertificateFile = Config.variable("sip_certificate").isNotEmpty()
|
||||
certificateFile.isChecked = oldCertificateFile
|
||||
|
||||
caFile = findViewById(R.id.CAFile) as CheckBox
|
||||
oldCAFile = Config.variable("sip_cafile").isNotEmpty()
|
||||
caFile.isChecked = oldCAFile
|
||||
|
||||
aec = findViewById(R.id.Aec) as CheckBox
|
||||
val aecCv = Config.variable("module")
|
||||
oldAec = aecCv.contains("webrtc_aec.so")
|
||||
@ -190,6 +207,56 @@ class ConfigActivity : AppCompatActivity() {
|
||||
save = true
|
||||
}
|
||||
|
||||
if (certificateFile.isChecked != oldCertificateFile) {
|
||||
if (certificateFile.isChecked) {
|
||||
if (!Utils.checkPermission(applicationContext,
|
||||
android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
getString(R.string.no_storage_space_permission))
|
||||
return false
|
||||
}
|
||||
val content = Utils.getFileContents(File(downloadsDir, "cert.pem"))
|
||||
if (content == "Failed") {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
getString(R.string.read_cert_error))
|
||||
return false
|
||||
}
|
||||
Utils.putFileContents(File(BaresipService.filesPath + "/cert.pem"),
|
||||
content)
|
||||
Config.remove("sip_certificate")
|
||||
Config.add("sip_certificate", BaresipService.filesPath + "/cert.pem")
|
||||
} else {
|
||||
Config.remove("sip_certificate")
|
||||
}
|
||||
save = true
|
||||
restart = true
|
||||
}
|
||||
|
||||
if (caFile.isChecked != oldCAFile) {
|
||||
if (caFile.isChecked) {
|
||||
if (!Utils.checkPermission(applicationContext,
|
||||
android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
getString(R.string.no_storage_space_permission))
|
||||
return false
|
||||
}
|
||||
val content = Utils.getFileContents(File(downloadsDir, "ca_certs.crt"))
|
||||
if (content == "Failed") {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
getString(R.string.read_ca_certs_error))
|
||||
return false
|
||||
}
|
||||
Utils.putFileContents(File(BaresipService.filesPath + "/ca_certs.crt"),
|
||||
content)
|
||||
Config.remove("sip_cafile")
|
||||
Config.add("sip_cafile", BaresipService.filesPath + "/ca_certs.crt")
|
||||
} else {
|
||||
Config.remove("sip_cafile")
|
||||
}
|
||||
save = true
|
||||
restart = true
|
||||
}
|
||||
|
||||
if (aec.isChecked != oldAec) {
|
||||
Config.remove("module webrtc_aec.so")
|
||||
if (aec.isChecked) {
|
||||
@ -280,6 +347,14 @@ class ConfigActivity : AppCompatActivity() {
|
||||
Utils.alertView(this, getString(R.string.dns_servers),
|
||||
getString(R.string.dns_servers_help))
|
||||
}
|
||||
findViewById(R.id.CertificateFileTitle) as TextView -> {
|
||||
Utils.alertView(this, getString(R.string.tls_certificate_file),
|
||||
getString(R.string.tls_certificate_file_help))
|
||||
}
|
||||
findViewById(R.id.CAFileTitle) as TextView -> {
|
||||
Utils.alertView(this, getString(R.string.tls_ca_file),
|
||||
getString(R.string.tls_ca_file_help))
|
||||
}
|
||||
findViewById(R.id.AecTitle) as TextView-> {
|
||||
Utils.alertView(this, getString(R.string.aec),
|
||||
getString(R.string.aec_help))
|
||||
|
||||
@ -50,7 +50,6 @@ object Utils {
|
||||
e.toString())
|
||||
return "Failed"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,6 +320,10 @@ object Utils {
|
||||
}
|
||||
}
|
||||
|
||||
fun checkPermission(ctx: Context, permission: String) : Boolean {
|
||||
return ContextCompat.checkSelfPermission(ctx, permission) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
fun requestPermission(ctx: Context, permission: String) : Boolean {
|
||||
if (ContextCompat.checkSelfPermission(ctx, permission) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.w("Baresip", "Baresip does not have $permission permission")
|
||||
|
||||
@ -112,6 +112,62 @@
|
||||
android:importantForAutofill="no" >
|
||||
</EditText>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:orientation="horizontal" >
|
||||
<TextView
|
||||
android:id="@+id/CertificateFileTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toStartOf="@id/CertificateFile"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:onClick="onClick"
|
||||
android:text="@string/tls_certificate_file" >
|
||||
</TextView>
|
||||
<CheckBox
|
||||
android:id="@+id/CertificateFile"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="end"
|
||||
android:checked="false" >
|
||||
</CheckBox>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:orientation="horizontal" >
|
||||
<TextView
|
||||
android:id="@+id/CAFileTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toStartOf="@id/CAFile"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:onClick="onClick"
|
||||
android:text="@string/tls_ca_file" >
|
||||
</TextView>
|
||||
<CheckBox
|
||||
android:id="@+id/CAFile"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="end"
|
||||
android:checked="false" >
|
||||
</CheckBox>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@ -206,6 +206,8 @@
|
||||
<string name="reset_config_help">Jos merkitty, oletuskonfiguraatio palautetaan, kun
|
||||
baresip seuraavan kerran käynnistetään.
|
||||
</string>
|
||||
<string name="read_cert_error">Tiedoston \'cert.pem\' luku Download-kansiosta epäonnistui.</string>
|
||||
<string name="read_ca_certs_error">Tiedoston \'ca_certs.crt\' luku Download-kansiosta epäonnistui.</string>
|
||||
<!-- Contact Activity -->
|
||||
<string name="contact">Kontakti</string>
|
||||
<string name="new_contact">Uusi kontakti</string>
|
||||
@ -286,7 +288,8 @@
|
||||
<string name="dialpad">Numeronäppäimistö</string>
|
||||
<string name="call_already_active">Sinulla on jo puhelu käynnissä.</string>
|
||||
<string name="start_failed">Sovelluksen käynnistäminen
|
||||
epäonnistui. Kuunteluosoiteen oletusarvo palautettu. Käynnistä
|
||||
epäonnistui. Tämä voi johtua virheellisestä kuunteluosoitteesta tai
|
||||
TLS sertifikaattitiedostosta. Niiden oletusarvot on palautettu. Käynnistä
|
||||
baresip uudelleen.
|
||||
</string>
|
||||
<string name="registering_failed">Tilin \'%1$s\' rekisteröinti
|
||||
@ -312,4 +315,9 @@
|
||||
<string name="call_is_secure">Tämä pulelu on turvallinen ja kohde on
|
||||
todennettu! Haluatko poistaa todennuksen?</string>
|
||||
<string name="unverify">Poista todennus</string>
|
||||
<string name="no_storage_space_permission">Et ole antanut käyttölupaa tallennustilaan. Tarkista Sovellukset → baresip → Käyttöluvat → Tallennustila.</string>
|
||||
<string name="tls_ca_file">TLS CA-tiedosto</string>
|
||||
<string name="tls_ca_file_help">Jos merkitty, tiedosto \'ca_certs.crt\', joka sisältää todennusauktoriteettien TLS-sertifikaatit, on ladattu tai ladataan Download-kansiosta.</string>
|
||||
<string name="tls_certificate_file">TLS sertifikaattitiedosto</string>
|
||||
<string name="tls_certificate_file_help">"Jos merkitty, tiedosto \'cert.pem\', joka sisältää tämän baresip-sovelluksen TLS-sertifikaatin ja yksityisen avaimen, on ladattu tai ladataan Download-kansiosta."</string>
|
||||
</resources>
|
||||
|
||||
@ -144,6 +144,10 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
|
||||
add peer to contacts?</string>
|
||||
<string name="short_chat_question">Do you want to delete chat with \'%1$s\'?</string>
|
||||
|
||||
<!-- Common -->
|
||||
<string name="no_storage_space_permission">You have not granted storage space permission.
|
||||
Check Apps → baresip → Permissions → Storage.</string>
|
||||
|
||||
<!-- Config Activity -->
|
||||
<string name="configuration">Configuration</string>
|
||||
<string name="start_automatically">Start Automatically</string>
|
||||
@ -165,6 +169,13 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
|
||||
also port is given, ip must
|
||||
be written inside brackets []. As an example, list \'8.8.8.8:53,[2001:4860:4860::8888]:53\'
|
||||
points to IPv4 and IPv6 addresses of public Google DNS servers.</string>
|
||||
<string name="tls_certificate_file">TLS Certificate File</string>
|
||||
<string name="tls_certificate_file_help">If checked, file \'cert.pem\' containing
|
||||
TLS certificate and private key of this baresip instance has been or will be loaded from
|
||||
Download directory. For security reasons, delete the file after loading.</string>
|
||||
<string name="tls_ca_file">TLS CA File</string>
|
||||
<string name="tls_ca_file_help">If checked, file \'ca_certs.crt\' containing TLS certificates
|
||||
of Certificate Authorities has been or will be loaded from Download directory.</string>
|
||||
<string name="aec">Acoustic Echo Cancellation</string>
|
||||
<string name="aec_help">If checked, echo cancellation is attempted on call audio.</string>
|
||||
<string name="opus_bit_rate">Opus Bit Rate</string>
|
||||
@ -179,7 +190,9 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
|
||||
<string name="debug_help">Provides debug and info level log message availability in Logcat.</string>
|
||||
<string name="reset_config">Reset to Factory Defaults</string>
|
||||
<string name="reset_config_help">If checked, configuration is reset
|
||||
to factory default values.</string>
|
||||
to factory default values.</string>
|
||||
<string name="read_cert_error">Failed to read file \'cert.pem\' from Download directory.</string>
|
||||
<string name="read_ca_certs_error">Failed to read file \'ca_certs.crt\' from Download directory.</string>
|
||||
|
||||
<!-- Contact Activity -->
|
||||
<string name="contact">Contact</string>
|
||||
@ -255,8 +268,8 @@ Check Apps → baresip → Permissions → Storage and that file \'contacts.bs\'
|
||||
<string name="messages">Messages</string>
|
||||
<string name="dialpad">Dialpad</string>
|
||||
<string name="call_already_active">You already have an active call.</string>
|
||||
<string name="start_failed">Baresip failed to start. Listen Address was reset.
|
||||
Restart baresip.</string>
|
||||
<string name="start_failed">Baresip failed to start. This may be due to invalid Listen Address
|
||||
or TLS file. They have been reset. Restart baresip.</string>
|
||||
<string name="registering_failed">Registering of \`%1$s\` failed.</string>
|
||||
<string name="no_microphone_permission">You have not granted microphone permission.</string>
|
||||
<string name="verify">Verify</string>
|
||||
|
||||
Reference in New Issue
Block a user