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
ai3
accountserver
Commits
5806a8b8
Commit
5806a8b8
authored
Nov 17, 2018
by
ale
Browse files
Move u2f encoding code along with the other composite values
parent
fa4ce752
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/composite_values.go
View file @
5806a8b8
...
...
@@ -6,6 +6,7 @@ import (
"strings"
as
"git.autistici.org/ai3/accountserver"
"github.com/tstranex/u2f"
)
// Extend the AppSpecificPasswordInfo type, which only contains public
...
...
@@ -89,3 +90,35 @@ func encodeUserEncryptionKeys(keys []*as.UserEncryptionKey) []string {
}
return
out
}
func
decodeU2FRegistration
(
enc
string
)
(
*
as
.
U2FRegistration
,
error
)
{
var
reg
u2f
.
Registration
if
err
:=
reg
.
UnmarshalBinary
([]
byte
(
enc
));
err
!=
nil
{
return
nil
,
err
}
return
&
as
.
U2FRegistration
{
Registration
:
&
reg
},
nil
}
func
encodeU2FRegistration
(
r
*
as
.
U2FRegistration
)
string
{
// MarshalBinary can't fail, ignore error.
b
,
_
:=
r
.
MarshalBinary
()
// nolint
return
string
(
b
)
}
func
decodeU2FRegistrations
(
encRegs
[]
string
)
[]
*
as
.
U2FRegistration
{
var
out
[]
*
as
.
U2FRegistration
for
_
,
enc
:=
range
encRegs
{
if
r
,
err
:=
decodeU2FRegistration
(
enc
);
err
==
nil
{
out
=
append
(
out
,
r
)
}
}
return
out
}
func
encodeU2FRegistrations
(
regs
[]
*
as
.
U2FRegistration
)
[]
string
{
var
out
[]
string
for
_
,
r
:=
range
regs
{
out
=
append
(
out
,
encodeU2FRegistration
(
r
))
}
return
out
}
backend/model.go
View file @
5806a8b8
...
...
@@ -9,7 +9,6 @@ import (
"time"
ldaputil
"git.autistici.org/ai3/go-common/ldap"
"github.com/tstranex/u2f"
"gopkg.in/ldap.v2"
as
"git.autistici.org/ai3/accountserver"
...
...
@@ -152,54 +151,22 @@ func userToLDAP(user *as.User) (attrs []ldap.PartialAttribute) {
{
Type
:
"uid"
,
Vals
:
s2l
(
user
.
Name
)},
{
Type
:
"cn"
,
Vals
:
s2l
(
user
.
Name
)},
{
Type
:
uidNumberLDAPAttr
,
Vals
:
s2l
(
strconv
.
Itoa
(
user
.
UID
))},
{
Type
:
"givenName"
,
Vals
:
[]
string
{
"Private"
}
},
{
Type
:
"sn"
,
Vals
:
[]
string
{
"Private"
}
},
{
Type
:
"givenName"
,
Vals
:
s2l
(
"Private"
)
},
{
Type
:
"sn"
,
Vals
:
s2l
(
"Private"
)
},
{
Type
:
"gecos"
,
Vals
:
s2l
(
user
.
Name
)},
{
Type
:
"loginShell"
,
Vals
:
[]
string
{
"/bin/false"
}
},
{
Type
:
"homeDirectory"
,
Vals
:
[]
string
{
"/var/empty"
}
},
{
Type
:
passwordLastChangeLDAPAttr
,
Vals
:
[]
string
{
"12345"
}
},
{
Type
:
"status"
,
Vals
:
[]
string
{
user
.
Status
}
},
{
Type
:
"host"
,
Vals
:
[]
string
{
user
.
Shard
}
},
{
Type
:
"shadowWarning"
,
Vals
:
[]
string
{
"7"
}
},
{
Type
:
"shadowMax"
,
Vals
:
[]
string
{
"99999"
}
},
{
Type
:
"loginShell"
,
Vals
:
s2l
(
"/bin/false"
)
},
{
Type
:
"homeDirectory"
,
Vals
:
s2l
(
"/var/empty"
)
},
{
Type
:
passwordLastChangeLDAPAttr
,
Vals
:
s2l
(
"12345"
)
},
{
Type
:
"status"
,
Vals
:
s2l
(
user
.
Status
)
},
{
Type
:
"host"
,
Vals
:
s2l
(
user
.
Shard
)
},
{
Type
:
"shadowWarning"
,
Vals
:
s2l
(
"7"
)
},
{
Type
:
"shadowMax"
,
Vals
:
s2l
(
"99999"
)
},
{
Type
:
preferredLanguageLDAPAttr
,
Vals
:
s2l
(
user
.
Lang
)},
{
Type
:
u2fRegistrationsLDAPAttr
,
Vals
:
encodeU2FRegistrations
(
user
.
U2FRegistrations
)},
}
...
)
return
}
func
decodeU2FRegistration
(
enc
string
)
(
*
as
.
U2FRegistration
,
error
)
{
var
reg
u2f
.
Registration
if
err
:=
reg
.
UnmarshalBinary
([]
byte
(
enc
));
err
!=
nil
{
return
nil
,
err
}
return
&
as
.
U2FRegistration
{
Registration
:
&
reg
},
nil
}
func
encodeU2FRegistration
(
r
*
as
.
U2FRegistration
)
string
{
// MarshalBinary can't fail, ignore error.
b
,
_
:=
r
.
MarshalBinary
()
// nolint
return
string
(
b
)
}
func
decodeU2FRegistrations
(
encRegs
[]
string
)
[]
*
as
.
U2FRegistration
{
var
out
[]
*
as
.
U2FRegistration
for
_
,
enc
:=
range
encRegs
{
if
r
,
err
:=
decodeU2FRegistration
(
enc
);
err
==
nil
{
out
=
append
(
out
,
r
)
}
}
return
out
}
func
encodeU2FRegistrations
(
regs
[]
*
as
.
U2FRegistration
)
[]
string
{
var
out
[]
string
for
_
,
r
:=
range
regs
{
out
=
append
(
out
,
encodeU2FRegistration
(
r
))
}
return
out
}
func
(
tx
*
backendTX
)
getUserDN
(
user
*
as
.
User
)
string
{
return
getUserDN
(
user
,
tx
.
backend
.
baseDN
)
}
...
...
backend/resources.go
View file @
5806a8b8
...
...
@@ -14,7 +14,6 @@ import (
// Generic resource handler interface. One for each resource type,
// mapping to exactly one LDAP object type.
type
resourceHandler
interface
{
//GetDN(as.ResourceID) (string, error)
MakeDN
(
*
as
.
User
,
*
as
.
Resource
)
(
string
,
error
)
GetOwner
(
*
as
.
Resource
)
string
ToLDAP
(
*
as
.
Resource
)
[]
ldap
.
PartialAttribute
...
...
Write
Preview
Supports
Markdown
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