Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix audit #743

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/test/scala/org/alephium/app/RestServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ trait RestServerFixture
lazy val blocksExporter = new BlocksExporter(node.blockFlow, rootPath)
val walletConfig: WalletConfig = WalletConfig(
None,
(new java.io.File("")).toPath,
Files.tmpDir.resolve(Hash.random.shortHex),
Duration.ofMinutesUnsafe(0),
apiConfig.apiKey,
WalletConfig.BlockFlow("host", 0, 0, Duration.ofMinutesUnsafe(0), apiConfig.apiKey)
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/main/scala/org/alephium/crypto/AES.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object AES {
final case class Encrypted(encrypted: ByteString, salt: ByteString, iv: ByteString)

private val saltByteLength = 64
private val ivByteLength = 64
private val ivByteLength = 12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it means current wallet files won't be compatible anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to check, not sure so far. It's not so urgent, the risk is low.

private val authTagLength = 128
private val keyAlgorithm = "PBKDF2WithHmacSHA256"
private val iterationCount = 10000
Expand Down
14 changes: 13 additions & 1 deletion wallet/src/main/scala/org/alephium/wallet/WalletApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.alephium.wallet

import java.nio.file.Paths
import java.nio.file.{Files, Path, Paths}

import scala.collection.immutable.ArraySeq
import scala.concurrent.{ExecutionContext, Future, Promise}
Expand All @@ -33,12 +33,14 @@ import org.alephium.protocol.config.GroupConfig
import org.alephium.util.{AVector, Service}
import org.alephium.wallet.config.WalletConfig
import org.alephium.wallet.service.WalletService
import org.alephium.wallet.storage.SecretStorage
import org.alephium.wallet.web._

class WalletApp(config: WalletConfig)(implicit
val executionContext: ExecutionContext
) extends Service
with StrictLogging {
WalletApp.checkSecretFilePermission(config.secretDir)

implicit private val groupConfig = new GroupConfig {
override def groups: Int = config.blockflow.groups
Expand Down Expand Up @@ -126,3 +128,13 @@ class WalletApp(config: WalletConfig)(implicit
}
}
}

object WalletApp {
def checkSecretFilePermission(walletDir: Path): Unit = {
if (Files.exists(walletDir)) {
Files.list(walletDir).forEach { path =>
SecretStorage.setPermission600(path.toFile)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ object SecretStorage {
)
state <- stateFromFile(file, password, path, mnemonicPassphrase)
} yield {
SecretStorage.setPermission600(file)
new Impl(file, Some(state), path)
}
}
Expand Down Expand Up @@ -404,4 +405,11 @@ object SecretStorage {
.left
.map(_ => SecretFileError)
}

def setPermission600(file: File): Unit = {
file.setReadable(false, false) // This returns false on Windows CI
require(file.setReadable(true, true))
require(file.setWritable(false, false))
require(file.setWritable(true, true))
}
}