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 ( ...@@ -6,6 +6,7 @@ import (
"strings" "strings"
as "git.autistici.org/ai3/accountserver" as "git.autistici.org/ai3/accountserver"
"github.com/tstranex/u2f"
) )
// Extend the AppSpecificPasswordInfo type, which only contains public // Extend the AppSpecificPasswordInfo type, which only contains public
...@@ -89,3 +90,35 @@ func encodeUserEncryptionKeys(keys []*as.UserEncryptionKey) []string { ...@@ -89,3 +90,35 @@ func encodeUserEncryptionKeys(keys []*as.UserEncryptionKey) []string {
} }
return out 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 ( ...@@ -9,7 +9,6 @@ import (
"time" "time"
ldaputil "git.autistici.org/ai3/go-common/ldap" ldaputil "git.autistici.org/ai3/go-common/ldap"
"github.com/tstranex/u2f"
"gopkg.in/ldap.v2" "gopkg.in/ldap.v2"
as "git.autistici.org/ai3/accountserver" as "git.autistici.org/ai3/accountserver"
...@@ -152,54 +151,22 @@ func userToLDAP(user *as.User) (attrs []ldap.PartialAttribute) { ...@@ -152,54 +151,22 @@ func userToLDAP(user *as.User) (attrs []ldap.PartialAttribute) {
{Type: "uid", Vals: s2l(user.Name)}, {Type: "uid", Vals: s2l(user.Name)},
{Type: "cn", Vals: s2l(user.Name)}, {Type: "cn", Vals: s2l(user.Name)},
{Type: uidNumberLDAPAttr, Vals: s2l(strconv.Itoa(user.UID))}, {Type: uidNumberLDAPAttr, Vals: s2l(strconv.Itoa(user.UID))},
{Type: "givenName", Vals: []string{"Private"}}, {Type: "givenName", Vals: s2l("Private")},
{Type: "sn", Vals: []string{"Private"}}, {Type: "sn", Vals: s2l("Private")},
{Type: "gecos", Vals: s2l(user.Name)}, {Type: "gecos", Vals: s2l(user.Name)},
{Type: "loginShell", Vals: []string{"/bin/false"}}, {Type: "loginShell", Vals: s2l("/bin/false")},
{Type: "homeDirectory", Vals: []string{"/var/empty"}}, {Type: "homeDirectory", Vals: s2l("/var/empty")},
{Type: passwordLastChangeLDAPAttr, Vals: []string{"12345"}}, {Type: passwordLastChangeLDAPAttr, Vals: s2l("12345")},
{Type: "status", Vals: []string{user.Status}}, {Type: "status", Vals: s2l(user.Status)},
{Type: "host", Vals: []string{user.Shard}}, {Type: "host", Vals: s2l(user.Shard)},
{Type: "shadowWarning", Vals: []string{"7"}}, {Type: "shadowWarning", Vals: s2l("7")},
{Type: "shadowMax", Vals: []string{"99999"}}, {Type: "shadowMax", Vals: s2l("99999")},
{Type: preferredLanguageLDAPAttr, Vals: s2l(user.Lang)}, {Type: preferredLanguageLDAPAttr, Vals: s2l(user.Lang)},
{Type: u2fRegistrationsLDAPAttr, Vals: encodeU2FRegistrations(user.U2FRegistrations)}, {Type: u2fRegistrationsLDAPAttr, Vals: encodeU2FRegistrations(user.U2FRegistrations)},
}...) }...)
return 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 { func (tx *backendTX) getUserDN(user *as.User) string {
return getUserDN(user, tx.backend.baseDN) return getUserDN(user, tx.backend.baseDN)
} }
......
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
// Generic resource handler interface. One for each resource type, // Generic resource handler interface. One for each resource type,
// mapping to exactly one LDAP object type. // mapping to exactly one LDAP object type.
type resourceHandler interface { type resourceHandler interface {
//GetDN(as.ResourceID) (string, error)
MakeDN(*as.User, *as.Resource) (string, error) MakeDN(*as.User, *as.Resource) (string, error)
GetOwner(*as.Resource) string GetOwner(*as.Resource) string
ToLDAP(*as.Resource) []ldap.PartialAttribute 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