Merge pull request #467 from shocknet/feature/allow-locked-lnd
allow locked lnd
This commit is contained in:
commit
f162407043
3 changed files with 55 additions and 9 deletions
|
|
@ -18,3 +18,5 @@ TORRENT_SEED_URL=https://webtorrent.shock.network
|
||||||
TORRENT_SEED_TOKEN=jibberish
|
TORRENT_SEED_TOKEN=jibberish
|
||||||
# "default" or "hosting"
|
# "default" or "hosting"
|
||||||
DEPLOYMENT_TYPE=hosting
|
DEPLOYMENT_TYPE=hosting
|
||||||
|
# allow to create a user with unlocked lnd
|
||||||
|
ALLOW_UNLOCKED_LND="true"
|
||||||
|
|
@ -611,7 +611,7 @@ module.exports = async (
|
||||||
// If we're connected to lnd, unlock the wallet using the password supplied
|
// If we're connected to lnd, unlock the wallet using the password supplied
|
||||||
// and generate an auth token if that operation was successful.
|
// and generate an auth token if that operation was successful.
|
||||||
if (health.LNDStatus.success && walletInitialized) {
|
if (health.LNDStatus.success && walletInitialized) {
|
||||||
const { alias, password, invite } = req.body
|
const { alias, password, invite, accessSecret } = req.body
|
||||||
|
|
||||||
await recreateLnServices()
|
await recreateLnServices()
|
||||||
|
|
||||||
|
|
@ -647,8 +647,18 @@ module.exports = async (
|
||||||
if (!walletUnlocked) {
|
if (!walletUnlocked) {
|
||||||
await unlockWallet(password)
|
await unlockWallet(password)
|
||||||
}
|
}
|
||||||
|
let secretUsed = null
|
||||||
if (walletUnlocked && !authorization && !isKeyTrusted) {
|
if (accessSecret) {
|
||||||
|
secretUsed = await Storage.get(
|
||||||
|
`UnlockedAccessSecrets/${accessSecret}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
walletUnlocked &&
|
||||||
|
!authorization &&
|
||||||
|
!isKeyTrusted &&
|
||||||
|
(process.env.ALLOW_UNLOCKED_LND !== 'true' || secretUsed !== false)
|
||||||
|
) {
|
||||||
res.status(401).json({
|
res.status(401).json({
|
||||||
field: 'alias',
|
field: 'alias',
|
||||||
errorMessage:
|
errorMessage:
|
||||||
|
|
@ -658,7 +668,11 @@ module.exports = async (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (walletUnlocked && !isKeyTrusted) {
|
if (
|
||||||
|
walletUnlocked &&
|
||||||
|
!isKeyTrusted &&
|
||||||
|
(process.env.ALLOW_UNLOCKED_LND !== 'true' || secretUsed !== false)
|
||||||
|
) {
|
||||||
const validatedToken = await validateToken(
|
const validatedToken = await validateToken(
|
||||||
authorization.replace('Bearer ', '')
|
authorization.replace('Bearer ', '')
|
||||||
)
|
)
|
||||||
|
|
@ -674,6 +688,10 @@ module.exports = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (secretUsed === false) {
|
||||||
|
await Storage.setItem(`UnlockedAccessSecrets/${accessSecret}`, true)
|
||||||
|
}
|
||||||
|
|
||||||
if (!isKeyTrusted) {
|
if (!isKeyTrusted) {
|
||||||
await Storage.set('trustedPKs', [...(trustedKeys || []), publicKey])
|
await Storage.set('trustedPKs', [...(trustedKeys || []), publicKey])
|
||||||
}
|
}
|
||||||
|
|
@ -1003,7 +1021,7 @@ module.exports = async (
|
||||||
|
|
||||||
app.post('/api/lnd/wallet/existing', async (req, res) => {
|
app.post('/api/lnd/wallet/existing', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { password, alias, invite } = req.body
|
const { password, alias, invite, accessSecret } = req.body
|
||||||
const healthResponse = await checkHealth()
|
const healthResponse = await checkHealth()
|
||||||
const exists = await walletExists()
|
const exists = await walletExists()
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
|
|
@ -1034,17 +1052,30 @@ module.exports = async (
|
||||||
"Please specify a password that's longer than 8 characters"
|
"Please specify a password that's longer than 8 characters"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
let secretUsed = null
|
||||||
if (healthResponse.LNDStatus.service !== 'walletUnlocker') {
|
if (accessSecret) {
|
||||||
|
secretUsed = await Storage.get(
|
||||||
|
`UnlockedAccessSecrets/${accessSecret}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
healthResponse.LNDStatus.service !== 'walletUnlocker' &&
|
||||||
|
(process.env.ALLOW_UNLOCKED_LND !== 'true' || secretUsed !== false)
|
||||||
|
) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
field: 'wallet',
|
field: 'wallet',
|
||||||
errorMessage:
|
errorMessage:
|
||||||
'Wallet is already unlocked. Please restart your LND instance and try again.'
|
'Wallet is already unlocked. Please restart your LND instance and try again.'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (secretUsed === false) {
|
||||||
|
await Storage.setItem(`UnlockedAccessSecrets/${accessSecret}`, true)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (healthResponse.LNDStatus.service === 'walletUnlocker') {
|
||||||
await unlockWallet(password)
|
await unlockWallet(password)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(401).json({
|
return res.status(401).json({
|
||||||
field: 'wallet',
|
field: 'wallet',
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
const { generateRandomString } = require('../utils/encryptionStore')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
|
|
@ -437,6 +439,17 @@ const server = program => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(process.env.ALLOW_UNLOCKED_LND === 'true'){
|
||||||
|
const codes = await Storage.valuesWithKeyMatch(/^UnlockedAccessSecrets\//u)
|
||||||
|
if(codes.length === 0){
|
||||||
|
const code = generateRandomString(12)
|
||||||
|
await Storage.setItem(`UnlockedAccessSecrets/${code}`, false)
|
||||||
|
logger.info("the access code is:"+code)
|
||||||
|
} else if(codes.length === 1 || codes[0] === false){
|
||||||
|
logger.info("the access code is:"+codes[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
serverInstance.listen(serverPort, serverHost)
|
serverInstance.listen(serverPort, serverHost)
|
||||||
logger.info('App listening on ' + serverHost + ' port ' + serverPort)
|
logger.info('App listening on ' + serverHost + ' port ' + serverPort)
|
||||||
module.server = serverInstance
|
module.server = serverInstance
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue