mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 18:05:50 +01:00
Use SecureRandom to generate access tokens.
scala.util.Random uses java.util.Random which only provides 64 bits of randomness.
This commit is contained in:
@@ -5,13 +5,13 @@ import gitbucket.core.model.Profile.profile.blockingApi._
|
|||||||
import gitbucket.core.model.{AccessToken, Account}
|
import gitbucket.core.model.{AccessToken, Account}
|
||||||
import gitbucket.core.util.StringUtil
|
import gitbucket.core.util.StringUtil
|
||||||
|
|
||||||
import scala.util.Random
|
import java.security.SecureRandom
|
||||||
|
|
||||||
trait AccessTokenService {
|
trait AccessTokenService {
|
||||||
|
|
||||||
def makeAccessTokenString: String = {
|
def makeAccessTokenString: String = {
|
||||||
val bytes = new Array[Byte](20)
|
val bytes = new Array[Byte](20)
|
||||||
Random.nextBytes(bytes)
|
AccessTokenService.secureRandom.nextBytes(bytes)
|
||||||
bytes.map("%02x".format(_)).mkString
|
bytes.map("%02x".format(_)).mkString
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,4 +55,6 @@ trait AccessTokenService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object AccessTokenService extends AccessTokenService
|
object AccessTokenService extends AccessTokenService {
|
||||||
|
private val secureRandom = new SecureRandom()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user