Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
accountserver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
ai3
accountserver
Commits
547904d1
Commit
547904d1
authored
6 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Move user key encryption/decryption to the backend package
parent
e5211476
No related branches found
No related tags found
1 merge request
!1
Txn
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/composite_values.go
+26
-0
26 additions, 0 deletions
backend/composite_values.go
backend/model.go
+2
-2
2 additions, 2 deletions
backend/model.go
types.go
+0
-24
0 additions, 24 deletions
types.go
with
28 additions
and
26 deletions
backend/composite_values.go
+
26
−
0
View file @
547904d1
...
...
@@ -2,11 +2,14 @@ package backend
import
(
"errors"
"fmt"
"strings"
"git.autistici.org/ai3/accountserver"
)
// Extend the AppSpecificPasswordInfo type, which only contains public
// information, with the encrypted password.
type
appSpecificPassword
struct
{
accountserver
.
AppSpecificPasswordInfo
Password
string
...
...
@@ -63,3 +66,26 @@ func getASPInfo(asps []*appSpecificPassword) []*accountserver.AppSpecificPasswor
}
return
out
}
func
decodeUserEncryptionKeys
(
values
[]
string
)
[]
*
accountserver
.
UserEncryptionKey
{
var
out
[]
*
accountserver
.
UserEncryptionKey
for
_
,
value
:=
range
values
{
idx
:=
strings
.
IndexByte
(
value
,
':'
)
if
idx
<
0
{
continue
}
out
=
append
(
out
,
&
accountserver
.
UserEncryptionKey
{
ID
:
value
[
:
idx
],
Key
:
[]
byte
(
value
[
idx
+
1
:
]),
})
}
return
out
}
func
encodeUserEncryptionKeys
(
keys
[]
*
accountserver
.
UserEncryptionKey
)
[]
string
{
var
out
[]
string
for
_
,
key
:=
range
keys
{
out
=
append
(
out
,
fmt
.
Sprintf
(
"%s:%s"
,
key
.
ID
,
string
(
key
.
Key
)))
}
return
out
}
This diff is collapsed.
Click to expand it.
backend/model.go
+
2
−
2
View file @
547904d1
...
...
@@ -272,11 +272,11 @@ func (tx *backendTX) SetUserPassword(ctx context.Context, user *accountserver.Us
func
(
tx
*
backendTX
)
GetUserEncryptionKeys
(
ctx
context
.
Context
,
user
*
accountserver
.
User
)
([]
*
accountserver
.
UserEncryptionKey
,
error
)
{
rawKeys
:=
tx
.
readAttributeValues
(
ctx
,
getUserDN
(
user
),
"storageEncryptionKey"
)
return
accountserver
.
D
ecodeUserEncryptionKeys
(
rawKeys
),
nil
return
d
ecodeUserEncryptionKeys
(
rawKeys
),
nil
}
func
(
tx
*
backendTX
)
SetUserEncryptionKeys
(
ctx
context
.
Context
,
user
*
accountserver
.
User
,
keys
[]
*
accountserver
.
UserEncryptionKey
)
error
{
encKeys
:=
accountserver
.
E
ncodeUserEncryptionKeys
(
keys
)
encKeys
:=
e
ncodeUserEncryptionKeys
(
keys
)
tx
.
setAttr
(
getUserDN
(
user
),
"storageEncryptionKey"
,
encKeys
...
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
types.go
+
0
−
24
View file @
547904d1
...
...
@@ -3,7 +3,6 @@ package accountserver
import
(
"encoding/json"
"errors"
"fmt"
"net/url"
"path/filepath"
"strings"
...
...
@@ -84,29 +83,6 @@ type UserEncryptionKey struct {
Key
[]
byte
`json:"key"`
}
func
DecodeUserEncryptionKeys
(
values
[]
string
)
[]
*
UserEncryptionKey
{
var
out
[]
*
UserEncryptionKey
for
_
,
value
:=
range
values
{
idx
:=
strings
.
IndexByte
(
value
,
':'
)
if
idx
<
0
{
continue
}
out
=
append
(
out
,
&
UserEncryptionKey
{
ID
:
value
[
:
idx
],
Key
:
[]
byte
(
value
[
idx
+
1
:
]),
})
}
return
out
}
func
EncodeUserEncryptionKeys
(
keys
[]
*
UserEncryptionKey
)
[]
string
{
var
out
[]
string
for
_
,
key
:=
range
keys
{
out
=
append
(
out
,
fmt
.
Sprintf
(
"%s:%s"
,
key
.
ID
,
string
(
key
.
Key
)))
}
return
out
}
const
(
ResourceTypeEmail
=
"email"
ResourceTypeMailingList
=
"list"
...
...
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