Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
6c6371aa
Commit
6c6371aa
authored
May 19, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SECURITY] implemeting password hash
parent
aa2add79
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
33 deletions
+101
-33
package.yaml
package.yaml
+1
-1
Auth.hs
src/Gargantext/Core/Auth.hs
+58
-0
Individu.hs
src/Gargantext/Core/Types/Individu.hs
+18
-0
User.hs
src/Gargantext/Database/Query/Table/User.hs
+19
-11
User.hs
src/Gargantext/Database/Schema/User.hs
+2
-1
Utils.hs
src/Gargantext/Prelude/Utils.hs
+0
-19
stack.yaml
stack.yaml
+3
-1
No files found.
package.yaml
View file @
6c6371aa
...
@@ -87,7 +87,7 @@ library:
...
@@ -87,7 +87,7 @@ library:
-
aeson
-
aeson
-
aeson-lens
-
aeson-lens
-
aeson-pretty
-
aeson-pretty
-
argon2
-
password
-
array
-
array
-
async
-
async
-
attoparsec
-
attoparsec
...
...
src/Gargantext/Core/Auth.hs
0 → 100644
View file @
6c6371aa
{-|
Module : Gargantext.API.Admin.Auth.Check
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module
Gargantext.Core.Auth
(
createPasswordHash
,
checkPassword
,
module
Data
.
Password
.
Argon2
)
where
import
Control.Monad.IO.Class
(
MonadIO
)
import
Data.Text
(
Text
)
import
Data.Password.Argon2
hiding
(
checkPassword
)
import
qualified
Data.Password.Argon2
as
A
createPasswordHash
::
MonadIO
m
=>
Text
->
m
(
PasswordHash
Argon2
)
createPasswordHash
x
=
hashPassword
(
mkPassword
x
)
checkPassword
::
Password
->
PasswordHash
Argon2
->
PasswordCheck
checkPassword
=
A
.
checkPassword
{-
-- Notes to implement Raw Password with argon2 lib
-- (now using password library, which does not use salt anymore)
-- import Crypto.Argon2 as Crypto
-- import Data.ByteString.Base64.URL as URL
-- import Data.Either
-- import Data.ByteString (ByteString)
secret_key :: ByteString
secret_key = "WRV5ymit8s~ge6%08dLR7Q!gBcpb1MY%7e67db2206"
type SecretKey = ByteString
hashNode :: SecretKey -> NodeToHash -> ByteString
hashNode sk (NodeToHash nt ni) = case hashResult of
Left e -> panic (cs $ show e)
Right h -> URL.encode h
where
hashResult = Crypto.hash Crypto.defaultHashOptions
sk
(cs $ show nt <> show ni)
-}
src/Gargantext/Core/Types/Individu.hs
View file @
6c6371aa
...
@@ -18,9 +18,11 @@ Individu defintions
...
@@ -18,9 +18,11 @@ Individu defintions
module
Gargantext.Core.Types.Individu
module
Gargantext.Core.Types.Individu
where
where
import
Control.Monad.IO.Class
(
MonadIO
)
import
Data.Text
(
Text
,
pack
,
reverse
)
import
Data.Text
(
Text
,
pack
,
reverse
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
,
UserId
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
,
UserId
)
import
Gargantext.Prelude
hiding
(
reverse
)
import
Gargantext.Prelude
hiding
(
reverse
)
import
qualified
Gargantext.Core.Auth
as
Auth
-- FIXME UserName used twice
-- FIXME UserName used twice
data
User
=
UserDBId
UserId
|
UserName
Text
|
RootId
NodeId
data
User
=
UserDBId
UserId
|
UserName
Text
|
RootId
NodeId
...
@@ -28,6 +30,7 @@ data User = UserDBId UserId | UserName Text | RootId NodeId
...
@@ -28,6 +30,7 @@ data User = UserDBId UserId | UserName Text | RootId NodeId
type
Username
=
Text
type
Username
=
Text
type
Password
=
Text
type
Password
=
Text
type
Email
=
Text
type
UsernameMaster
=
Username
type
UsernameMaster
=
Username
type
UsernameSimple
=
Username
type
UsernameSimple
=
Username
...
@@ -42,4 +45,19 @@ arbitraryUsername = ["gargantua"] <> users
...
@@ -42,4 +45,19 @@ arbitraryUsername = ["gargantua"] <> users
arbitraryPassword
::
[
Password
]
arbitraryPassword
::
[
Password
]
arbitraryPassword
=
map
reverse
arbitraryUsername
arbitraryPassword
=
map
reverse
arbitraryUsername
-----------------------------------------------------------
arbitraryUsersHash
::
MonadIO
m
=>
m
[(
Username
,
Email
,
Auth
.
PasswordHash
Auth
.
Argon2
)]
arbitraryUsersHash
=
mapM
userHash
arbitraryUsers
userHash
::
MonadIO
m
=>
(
Username
,
Email
,
Password
)
->
m
(
Username
,
Email
,
Auth
.
PasswordHash
Auth
.
Argon2
)
userHash
(
u
,
m
,
p
)
=
do
h
<-
Auth
.
createPasswordHash
p
pure
(
u
,
m
,
h
)
arbitraryUsers
::
[(
Username
,
Email
,
Password
)]
arbitraryUsers
=
map
(
\
u
->
(
u
,
u
<>
"@gargantext.org"
,
reverse
u
))
arbitraryUsername
src/Gargantext/Database/Query/Table/User.hs
View file @
6c6371aa
...
@@ -27,9 +27,9 @@ module Gargantext.Database.Query.Table.User
...
@@ -27,9 +27,9 @@ module Gargantext.Database.Query.Table.User
(
insertUsers
(
insertUsers
,
queryUserTable
,
queryUserTable
,
getUser
,
getUser
,
garg
antextUser
,
garg
UserWith
,
insertUsersDemo
,
insertUsersDemo
,
selectUsersLight
,
selectUsersLight
With
,
userWithUsername
,
userWithUsername
,
userWithId
,
userWithId
,
userLightWithId
,
userLightWithId
...
@@ -44,35 +44,43 @@ import Data.Maybe (Maybe)
...
@@ -44,35 +44,43 @@ import Data.Maybe (Maybe)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Data.Time
(
UTCTime
)
import
Data.Time
(
UTCTime
)
import
Gargantext.Core.Types.Individu
import
Gargantext.Core.Types.Individu
import
qualified
Gargantext.Core.Auth
as
Auth
import
Gargantext.Database.Schema.User
import
Gargantext.Database.Schema.User
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Opaleye
import
Opaleye
------------------------------------------------------------------------
------------------------------------------------------------------------
-- TODO: on conflict, nice message
-- TODO: on conflict, nice message
insertUsers
::
[
UserWrite
]
->
Cmd
err
Int64
insertUsers
::
[
UserWrite
]
->
Cmd
err
Int64
insertUsers
us
=
mkCmd
$
\
c
->
runInsert_
c
insert
insertUsers
us
=
mkCmd
$
\
c
->
runInsert_
c
insert
where
where
insert
=
Insert
userTable
us
rCount
Nothing
insert
=
Insert
userTable
us
rCount
Nothing
gargantextUser
::
Username
->
UserWrite
insertUsersDemo
::
Cmd
err
Int64
gargantextUser
u
=
UserDB
(
Nothing
)
(
pgStrictText
"password"
)
insertUsersDemo
=
do
users
<-
liftBase
arbitraryUsersHash
insertUsers
$
map
(
\
(
u
,
m
,
h
)
->
gargUserWith
u
m
h
)
users
-----------------------------------------------------------------------
gargUserWith
::
Username
->
Email
->
Auth
.
PasswordHash
Auth
.
Argon2
->
UserWrite
gargUserWith
u
m
(
Auth
.
PasswordHash
p
)
=
UserDB
(
Nothing
)
(
pgStrictText
p
)
(
Nothing
)
(
pgBool
True
)
(
pgStrictText
u
)
(
Nothing
)
(
pgBool
True
)
(
pgStrictText
u
)
(
pgStrictText
"first_name"
)
(
pgStrictText
"first_name"
)
(
pgStrictText
"last_name"
)
(
pgStrictText
"last_name"
)
(
pgStrictText
"e@mail"
)
(
pgStrictText
m
)
(
pgBool
True
)
(
pgBool
True
)
(
Nothing
)
(
pgBool
True
)
(
pgBool
True
)
Nothing
insertUsersDemo
::
Cmd
err
Int64
insertUsersDemo
=
insertUsers
$
map
(
\
u
->
gargantextUser
u
)
arbitraryUsername
------------------------------------------------------------------
------------------------------------------------------------------
queryUserTable
::
Query
UserRead
queryUserTable
::
Query
UserRead
queryUserTable
=
queryTable
userTable
queryUserTable
=
queryTable
userTable
selectUsersLight
::
Query
UserRead
selectUsersLight
With
::
Query
UserRead
selectUsersLight
=
proc
()
->
do
selectUsersLight
With
=
proc
()
->
do
row
@
(
UserDB
i
_p
_ll
_is
_un
_fn
_ln
_m
_iff
_ive
_dj
)
<-
queryUserTable
-<
()
row
@
(
UserDB
i
_p
_ll
_is
_un
_fn
_ln
_m
_iff
_ive
_dj
)
<-
queryUserTable
-<
()
restrict
-<
i
.==
1
restrict
-<
i
.==
1
--returnA -< User i p ll is un fn ln m iff ive dj
--returnA -< User i p ll is un fn ln m iff ive dj
...
...
src/Gargantext/Database/Schema/User.hs
View file @
6c6371aa
...
@@ -43,10 +43,11 @@ import Opaleye
...
@@ -43,10 +43,11 @@ import Opaleye
data
UserLight
=
UserLight
{
userLight_id
::
!
Int
data
UserLight
=
UserLight
{
userLight_id
::
!
Int
,
userLight_username
::
!
Text
,
userLight_username
::
!
Text
,
userLight_email
::
!
Text
,
userLight_email
::
!
Text
,
userLigth_password
::
!
Text
}
deriving
(
Show
)
}
deriving
(
Show
)
toUserLight
::
UserDB
->
UserLight
toUserLight
::
UserDB
->
UserLight
toUserLight
(
UserDB
id
_
_
_
u
_
_
e
_
_
_
)
=
UserLight
id
u
e
toUserLight
(
UserDB
id
p
_
_
u
_
_
e
_
_
_
)
=
UserLight
id
u
e
p
data
UserPoly
id
pass
llogin
suser
data
UserPoly
id
pass
llogin
suser
uname
fname
lname
uname
fname
lname
...
...
src/Gargantext/Prelude/Utils.hs
View file @
6c6371aa
...
@@ -20,10 +20,6 @@ import Control.Lens (view)
...
@@ -20,10 +20,6 @@ import Control.Lens (view)
import
Control.Monad.Random.Class
(
MonadRandom
)
import
Control.Monad.Random.Class
(
MonadRandom
)
import
Control.Monad.Reader
(
MonadReader
)
import
Control.Monad.Reader
(
MonadReader
)
import
Control.Monad.Reader
(
ask
)
import
Control.Monad.Reader
(
ask
)
import
Crypto.Argon2
as
Crypto
import
Data.ByteString
(
ByteString
)
import
Data.ByteString.Base64.URL
as
URL
import
Data.Either
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
GHC.IO
(
FilePath
)
import
GHC.IO
(
FilePath
)
import
Gargantext.API.Admin.Settings
import
Gargantext.API.Admin.Settings
...
@@ -53,24 +49,9 @@ data NodeToHash = NodeToHash { nodeType :: NodeType
...
@@ -53,24 +49,9 @@ data NodeToHash = NodeToHash { nodeType :: NodeType
,
nodeId
::
NodeId
,
nodeId
::
NodeId
}
}
secret_key
::
ByteString
secret_key
=
"WRV5ymit8s~ge6%08dLR7Q!gBcpb1MY%7e67db2206"
type
SecretKey
=
ByteString
type
FolderPath
=
FilePath
type
FolderPath
=
FilePath
type
FileName
=
FilePath
type
FileName
=
FilePath
hashNode
::
SecretKey
->
NodeToHash
->
ByteString
hashNode
sk
(
NodeToHash
nt
ni
)
=
case
hashResult
of
Left
e
->
panic
(
cs
$
show
e
)
Right
h
->
URL
.
encode
h
where
hashResult
=
Crypto
.
hash
Crypto
.
defaultHashOptions
sk
(
cs
$
show
nt
<>
show
ni
)
toPath
::
Int
->
Text
->
(
FolderPath
,
FileName
)
toPath
::
Int
->
Text
->
(
FolderPath
,
FileName
)
toPath
n
x
=
(
Text
.
unpack
$
Text
.
intercalate
"/"
[
x1
,
x2
],
Text
.
unpack
xs
)
toPath
n
x
=
(
Text
.
unpack
$
Text
.
intercalate
"/"
[
x1
,
x2
],
Text
.
unpack
xs
)
where
where
...
...
stack.yaml
View file @
6c6371aa
...
@@ -81,4 +81,6 @@ extra-deps:
...
@@ -81,4 +81,6 @@ extra-deps:
-
validity-0.9.0.0
# patches-{map,class}
-
validity-0.9.0.0
# patches-{map,class}
-
directory-1.3.1.5
-
directory-1.3.1.5
-
process-1.6.5.1@sha256:77a9afeb676357f67fe5cf1ad79aca0745fb6f7fb96b786d510af08f622643f6,2468
-
process-1.6.5.1@sha256:77a9afeb676357f67fe5cf1ad79aca0745fb6f7fb96b786d510af08f622643f6,2468
-
argon2-1.3.0.1@sha256:e7771caf255929453c7cebfed0809617c51428d1c1b22f207c80b8711b792d78,4592
-
password-2.0.1.1
-
base64-0.4.2@sha256:e9523e18bdadc3cab9dc32dfe3ac09c718fe792076326d6d353437b8b255cb5b,2888
-
ghc-byteorder-4.11.0.0.10@sha256:5ee4a907279bfec27b0f9de7b8fba4cecfd34395a0235a7784494de70ad4e98f,1535
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