Commit 5806a8b8 authored by ale's avatar ale

Move u2f encoding code along with the other composite values

parent fa4ce752
......@@ -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
}
......@@ -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)
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment