Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
2dbc4175
Commit
2dbc4175
authored
Nov 13, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `encrypted` strategy to persist encrypted tokens
parent
91f11727
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
app/models/concerns/token_authenticatable_strategies/encrypted.rb
...ls/concerns/token_authenticatable_strategies/encrypted.rb
+51
-0
No files found.
app/models/concerns/token_authenticatable_strategies/encrypted.rb
0 → 100644
View file @
2dbc4175
# frozen_string_literal: true
module
TokenAuthenticatableStrategies
class
Encrypted
<
Base
def
find_token_authenticatable
(
token
,
unscoped
=
false
)
return
unless
token
token_authenticatable
=
relation
(
unscoped
)
.
find_by
(
token_field_name
=>
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
))
if
@options
[
:fallback
]
token_authenticatable
||=
fallback_strategy
.
find_token_authenticatable
(
token
)
end
token_authenticatable
end
def
get_token
(
instance
)
token
=
instance
.
cleartext_tokens
.
to_h
[
@token_field
]
token
||=
fallback_strategy
.
get_token
(
instance
)
if
@options
[
:fallback
]
token
end
def
set_token
(
instance
,
token
)
return
unless
token
instance
.
cleartext_tokens
||=
{}
instance
.
cleartext_tokens
[
@token_field
]
=
token
instance
[
token_field_name
]
=
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
)
instance
[
@token_field
]
=
nil
if
@options
[
:fallback
]
# TODO this seems wrong
end
protected
def
fallback_strategy
@fallback_strategy
||=
TokenAuthenticatableStrategies
::
Insecure
.
new
(
@klass
,
@token_field
,
@options
)
end
def
token_set?
(
instance
)
token_digest
=
instance
.
read_attribute
(
token_field_name
)
token_digest
||=
instance
.
read_attribute
(
@token_field
)
if
@options
[
:fallback
]
token_digest
.
present?
end
def
token_field_name
"
#{
@token_field
}
_encrypted"
end
end
end
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