Skip to content

Commit

Permalink
Generate local token using a word list rather than a random hash
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Apr 5, 2024
1 parent 08c746c commit 6071956
Show file tree
Hide file tree
Showing 2 changed files with 1,312 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.text.TextUtils;

import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
Expand All @@ -19,10 +20,11 @@
import java.io.InputStreamReader;
import java.security.SecureRandom;

import aosp.libcore.util.HexEncoding;
import io.github.muntashirakon.AppManager.BuildConfig;
import io.github.muntashirakon.AppManager.R;
import io.github.muntashirakon.AppManager.server.common.ConfigParams;
import io.github.muntashirakon.AppManager.server.common.Constants;
import io.github.muntashirakon.AppManager.utils.ContextUtils;
import io.github.muntashirakon.AppManager.utils.FileUtils;
import io.github.muntashirakon.io.IoUtils;

Expand Down Expand Up @@ -108,9 +110,13 @@ static void writeScript(@NonNull Context context) throws IOException {
@AnyThread
@NonNull
static String generateToken() {
Context context = ContextUtils.getContext();
String[] wordList = context.getResources().getStringArray(R.array.word_list);
SecureRandom secureRandom = new SecureRandom();
byte[] bytes = new byte[16];
secureRandom.nextBytes(bytes);
return HexEncoding.encodeToString(bytes, false /* lowercase */);
String[] tokenItems = new String[3 + secureRandom.nextInt(3)];
for (int i = 0; i < tokenItems.length; ++i) {
tokenItems[i] = wordList[secureRandom.nextInt(wordList.length)];
}
return TextUtils.join("-", tokenItems);
}
}
Loading

0 comments on commit 6071956

Please sign in to comment.