Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
normandy
pleroma
Commits
1a8bc26e
Commit
1a8bc26e
authored
6 years ago
by
Moon Man
Browse files
Options
Downloads
Patches
Plain Diff
auth against sha512-crypt password hashes, upgrade to pbkdf2
parent
8143251f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/pleroma/plugs/authentication_plug.ex
+22
-1
22 additions, 1 deletion
lib/pleroma/plugs/authentication_plug.ex
mix.exs
+2
-1
2 additions, 1 deletion
mix.exs
test/plugs/authentication_plug_test.exs
+28
-0
28 additions, 0 deletions
test/plugs/authentication_plug_test.exs
with
52 additions
and
2 deletions
lib/pleroma/plugs/authentication_plug.ex
+
22
−
1
View file @
1a8bc26e
...
...
@@ -14,7 +14,17 @@ defmodule Pleroma.Plugs.AuthenticationPlug do
{
:ok
,
user
}
<-
opts
[
:fetcher
]
.
(
username
),
false
<-
!!user
.
info
[
"deactivated"
],
saved_user_id
<-
get_session
(
conn
,
:user_id
),
legacy_password
<-
String
.
starts_with?
(
user
.
password_hash
,
"$6$"
),
update_legacy_password
<-
!
(
Map
.
has_key?
(
opts
,
:update_legacy_password
)
&&
opts
[
:update_legacy_password
]
==
false
),
{
:ok
,
verified_user
}
<-
verify
(
user
,
password
,
saved_user_id
)
do
if
legacy_password
and
update_legacy_password
do
User
.
reset_password
(
verified_user
,
%{
:password
=>
password
,
:password_confirmation
=>
password
})
end
conn
|>
assign
(
:user
,
verified_user
)
|>
put_session
(
:user_id
,
verified_user
.
id
)
...
...
@@ -34,7 +44,18 @@ defmodule Pleroma.Plugs.AuthenticationPlug do
end
defp
verify
(
user
,
password
,
_user_id
)
do
if
Pbkdf2
.
checkpw
(
password
,
user
.
password_hash
)
do
is_legacy
=
String
.
starts_with?
(
user
.
password_hash
,
"$6$"
)
valid
=
cond
do
is_legacy
->
:crypt
.
crypt
(
password
,
user
.
password_hash
)
==
user
.
password_hash
true
->
Pbkdf2
.
checkpw
(
password
,
user
.
password_hash
)
end
if
valid
do
{
:ok
,
user
}
else
:error
...
...
This diff is collapsed.
Click to expand it.
mix.exs
+
2
−
1
View file @
1a8bc26e
...
...
@@ -50,7 +50,8 @@ defmodule Pleroma.Mixfile do
{
:ex_aws_s3
,
"~> 2.0"
},
{
:ex_machina
,
"~> 2.2"
,
only:
:test
},
{
:credo
,
"~> 0.9.3"
,
only:
[
:dev
,
:test
]},
{
:mock
,
"~> 0.3.1"
,
only:
:test
}
{
:mock
,
"~> 0.3.1"
,
only:
:test
},
{
:crypt
,
git:
"https://github.com/msantos/crypt"
}
]
end
...
...
This diff is collapsed.
Click to expand it.
test/plugs/authentication_plug_test.exs
+
28
−
0
View file @
1a8bc26e
...
...
@@ -21,6 +21,13 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
info:
%{
"deactivated"
=>
true
}
}
@legacy
%
User
{
id:
1
,
name:
"dude"
,
password_hash:
"$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1"
}
@session_opts
[
store:
:cookie
,
key:
"_test"
,
...
...
@@ -139,6 +146,27 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
assert
get_session
(
conn
,
:user_id
)
==
@user
.
id
assert
conn
.
halted
==
false
end
test
"it assigns legacy user"
,
%{
conn:
conn
}
do
opts
=
%{
optional:
true
,
fetcher:
fn
_
->
{
:ok
,
@legacy
}
end
,
update_legacy_password:
false
}
header
=
basic_auth_enc
(
"dude"
,
"password"
)
conn
=
conn
|>
Plug
.
Session
.
call
(
Plug
.
Session
.
init
(
@session_opts
))
|>
fetch_session
|>
put_req_header
(
"authorization"
,
header
)
|>
AuthenticationPlug
.
call
(
opts
)
assert
%{
user:
@legacy
}
==
conn
.
assigns
assert
get_session
(
conn
,
:user_id
)
==
@legacy
.
id
assert
conn
.
halted
==
false
end
end
describe
"with a correct authorization header for an deactiviated user"
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment