Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Indienet
Site
Commits
5e840488
Verified
Commit
5e840488
authored
Apr 25, 2018
by
Aral Balkan
Browse files
Await sodium library initialisation before using it. Fixes
#40
parent
c83ebb2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/index.js
View file @
5e840488
...
...
@@ -23,9 +23,10 @@ function startFeathersServer () {
})
}
//
On first run of the server only
, create a server secret. This
//
If it doesn’t already exist
, create a server secret. This
// server secret is used to sign the JSON Web Tokens that we use
// for stateless authentication.
// for stateless authentication. (This should only happen on first run of
// an instance unless the server secret is manually deleted on the server.)
async
function
createAndPersitServerSecretIfItDoesntAlreadyExist
()
{
if
(
!
app
.
get
(
'
serverSecretFileExists
'
))
{
//
...
...
@@ -34,17 +35,14 @@ async function createAndPersitServerSecretIfItDoesntAlreadyExist () {
//
logger
.
info
(
'
Server secret does not exist, creating this one time.
'
)
try
{
// Create a server secret as the owner of the site is registering. This is
// the secret that we will use to sign JSON Web Tokens (JWTs).
const
serverSecret
=
sodium
.
randombytes_buf
(
sodium
.
crypto_pwhash_SALTBYTES
)
const
serverSecretInHex
=
sodium
.
to_hex
(
serverSecret
)
const
serverSecretObject
=
{
serverSecret
:
serverSecretInHex
}
}
catch
(
error
)
{
const
message
=
`Error trying to use sodium.
${
error
}
`
logger
.
error
(
message
)
throw
new
Error
(
message
)
}
// Sodium’s initialisation is asynchronous. Wait for it complete before using it.
await
sodium
.
ready
// Create a server secret as the owner of the site is registering. This is
// the secret that we will use to sign JSON Web Tokens (JWTs).
const
serverSecret
=
sodium
.
randombytes_buf
(
sodium
.
crypto_pwhash_SALTBYTES
)
const
serverSecretInHex
=
sodium
.
to_hex
(
serverSecret
)
const
serverSecretObject
=
{
serverSecret
:
serverSecretInHex
}
try
{
// Write the keys file to a data file in a directory for this spike that
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment