Skip to content

Commit

Permalink
Change secret file permission to 600
Browse files Browse the repository at this point in the history
  • Loading branch information
polarker committed Sep 21, 2022
1 parent 6e622c6 commit 6fac5a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 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,11 @@ class WalletApp(config: WalletConfig)(implicit
}
}
}

object WalletApp {
def checkSecretFilePermission(walletDir: Path): Unit = {
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 = {
require(file.setReadable(false, false))
require(file.setReadable(true, true))
require(file.setWritable(false, false))
require(file.setWritable(true, true))
}
}

0 comments on commit 6fac5a5

Please sign in to comment.