Kaynağa Gözat

use SecureRandom instead of Random

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 6 yıl önce
ebeveyn
işleme
213f2c597e

+ 2 - 1
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -127,6 +127,7 @@ import com.owncloud.android.utils.PermissionUtil;
 
 import java.io.InputStream;
 import java.net.URLDecoder;
+import java.security.SecureRandom;
 import java.security.cert.X509Certificate;
 import java.util.HashMap;
 import java.util.Locale;
@@ -1939,7 +1940,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             username = webViewUser;
         }
         if (isOAuth) {
-            username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
+            username = "OAuth_user" + new SecureRandom().nextLong();
         }
 
         String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username);

+ 2 - 2
src/main/java/com/owncloud/android/jobs/NotificationJob.java

@@ -56,7 +56,7 @@ import java.io.IOException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
-import java.util.Random;
+import java.security.SecureRandom;
 
 import javax.crypto.Cipher;
 import javax.crypto.NoSuchPaddingException;
@@ -74,7 +74,7 @@ public class NotificationJob extends Job {
     private static final String PUSH_NOTIFICATION_ID = "PUSH_NOTIFICATION_ID";
     private static final String NUMERIC_NOTIFICATION_ID = "NUMERIC_NOTIFICATION_ID";
 
-    private Random randomId = new Random();
+    private SecureRandom randomId = new SecureRandom();
 
     @NonNull
     @Override

+ 6 - 9
src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   Copyright (C) 2015 ownCloud Inc.
@@ -27,7 +27,7 @@ import android.os.Process;
 
 import com.owncloud.android.utils.ThemeUtils;
 
-import java.util.Random;
+import java.security.SecureRandom;
 
 import androidx.core.app.NotificationCompat;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -70,16 +70,13 @@ public final class NotificationUtils {
                                        long delayInMillis) {
 
         HandlerThread thread = new HandlerThread(
-                "NotificationDelayerThread_" + (new Random(System.currentTimeMillis())).nextInt(),
-                Process.THREAD_PRIORITY_BACKGROUND);
+            "NotificationDelayerThread_" + new SecureRandom().nextInt(), Process.THREAD_PRIORITY_BACKGROUND);
         thread.start();
 
         Handler handler = new Handler(thread.getLooper());
-        handler.postDelayed(new Runnable() {
-            public void run() {
-                 notificationManager.cancel(notificationId);
-                 ((HandlerThread)Thread.currentThread()).getLooper().quit();
-            }
+        handler.postDelayed(() -> {
+            notificationManager.cancel(notificationId);
+            ((HandlerThread) Thread.currentThread()).getLooper().quit();
         }, delayInMillis);
     }
 }