Increase version, more settings

pull/29/head
sh123 2021-10-14 15:52:27 +03:00
rodzic ab4bbeba9c
commit 1a42f6a8fc
6 zmienionych plików z 29 dodań i 10 usunięć

Wyświetl plik

@ -11,7 +11,7 @@ android {
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.7"
versionName "1.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Wyświetl plik

@ -1,8 +1,12 @@
package com.radio.codec2talkie.protocol;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import com.radio.codec2talkie.MainActivity;
import com.radio.codec2talkie.settings.PreferenceKeys;
import com.radio.codec2talkie.tools.ScramblingTools;
import com.radio.codec2talkie.transport.Transport;
@ -20,10 +24,12 @@ public class ScramblerPipe implements Protocol {
private static final String TAG = MainActivity.class.getSimpleName();
Context _context;
private Context _context;
final Protocol _childProtocol;
final String _scramblingKey;
private final Protocol _childProtocol;
private final String _scramblingKey;
private int _iterationsCount;
public ScramblerPipe(Protocol childProtocol, String scramblingKey) {
_childProtocol = childProtocol;
@ -33,6 +39,8 @@ public class ScramblerPipe implements Protocol {
@Override
public void initialize(Transport transport, Context context) throws IOException {
_context = context;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(_context);
_iterationsCount = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_SCRAMBLER_ITERATIONS, "1000"));
_childProtocol.initialize(transport, context);
}
@ -40,7 +48,7 @@ public class ScramblerPipe implements Protocol {
public void send(byte[] audioFrame) throws IOException {
ScramblingTools.ScrambledData data = null;
try {
data = ScramblingTools.scramble(_scramblingKey, audioFrame);
data = ScramblingTools.scramble(_scramblingKey, audioFrame, _iterationsCount);
} catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeySpecException |
InvalidKeyException | BadPaddingException | IllegalBlockSizeException |
InvalidAlgorithmParameterException e) {
@ -76,7 +84,7 @@ public class ScramblerPipe implements Protocol {
byte[] audioFrame = null;
try {
audioFrame = ScramblingTools.unscramble(_scramblingKey, data);
audioFrame = ScramblingTools.unscramble(_scramblingKey, data, _iterationsCount);
} catch (NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException |
InvalidKeyException | BadPaddingException | IllegalBlockSizeException |
InvalidAlgorithmParameterException e) {

Wyświetl plik

@ -23,6 +23,7 @@ public final class PreferenceKeys {
public static String KISS_BASIC_TX_TAIL = "kiss_basic_tx_tail";
public static String KISS_SCRAMBLING_ENABLED = "kiss_enable_scrambler";
public static String KISS_SCRAMBLER_KEY = "kiss_scrambler_key";
public static String KISS_SCRAMBLER_ITERATIONS = "kiss_scrambler_iterations";
public static String KISS_EXTENSIONS_ENABLED = "kiss_extensions_enable";
public static String KISS_EXTENSIONS_RADIO_FREQUENCY = "kiss_extension_radio_frequency";

Wyświetl plik

@ -24,7 +24,7 @@ public class ScramblingTools {
private static final String SCRAMBLING_ALGORITHM = "AES/CBC/PKCS5Padding";
private static final String PBE_ALGORITHM = "PBEwithSHA256and128BITAES-CBC-BC";
public static ScrambledData scramble(String masterKey, byte[] rawData)
public static ScrambledData scramble(String masterKey, byte[] rawData, int iterations)
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeySpecException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {
@ -37,7 +37,7 @@ public class ScramblingTools {
rnd.nextBytes(encData.salt);
rnd.nextBytes(encData.iv);
PBEKeySpec keySpec = new PBEKeySpec(masterKey.toCharArray(), encData.salt, PBK_ITERATIONS);
PBEKeySpec keySpec = new PBEKeySpec(masterKey.toCharArray(), encData.salt, iterations);
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(PBE_ALGORITHM);
Key key = secretKeyFactory.generateSecret(keySpec);
@ -51,11 +51,11 @@ public class ScramblingTools {
return encData;
}
public static byte[] unscramble(String masterKey, ScrambledData scrambledData)
public static byte[] unscramble(String masterKey, ScrambledData scrambledData, int iterations)
throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {
PBEKeySpec keySpec = new PBEKeySpec(masterKey.toCharArray(), scrambledData.salt, PBK_ITERATIONS);
PBEKeySpec keySpec = new PBEKeySpec(masterKey.toCharArray(), scrambledData.salt, iterations);
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(PBE_ALGORITHM);
Key key = secretKeyFactory.generateSecret(keySpec);

Wyświetl plik

@ -162,4 +162,6 @@
<string name="kiss_toast_modem_reboot">Modem reboot requested</string>
<string name="app_audio_output_speaker_title">Play audio through the speaker</string>
<string name="app_audio_output_speaker_summary">Output incoming audio through the speaker</string>
<string name="kiss_scrambler_iterations_title">(Experimental) Number of iterations preformed</string>
<string name="kiss_scrambler_iterations_summary">Change to lower value on slow devices, >1000 recommended, should match on all devices</string>
</resources>

Wyświetl plik

@ -56,5 +56,13 @@ s
app:defaultValue="0">
</EditTextPreference>
<EditTextPreference
android:key="kiss_scrambler_iterations"
android:title="@string/kiss_scrambler_iterations_title"
android:summary="@string/kiss_scrambler_iterations_summary"
app:dependency="kiss_enable_scrambler"
app:defaultValue="1000">
</EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>