Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wkd
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
tools
wkd
Commits
ff2091ae
Commit
ff2091ae
authored
3 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Support hosting multiple domains more easily
parent
a1c18acb
Branches
Branches containing commit
Tags
v0.0.1
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
build-static-bundle.sh
+1
-1
1 addition, 1 deletion
build-static-bundle.sh
ldap.go
+13
-6
13 additions, 6 deletions
ldap.go
server.go
+2
-2
2 additions, 2 deletions
server.go
static.go
+4
-2
4 additions, 2 deletions
static.go
with
20 additions
and
11 deletions
build-static-bundle.sh
+
1
−
1
View file @
ff2091ae
...
...
@@ -20,7 +20,7 @@ gpg --homedir $tmpdir --list-options show-only-fpr-mbox -k '*' \
hash
=
$(
echo
$mbox
| /usr/lib/gnupg/gpg-wks-client
--print-wkd-hash
|
awk
'{print $1}'
)
domain
=
${
mbox
##*@
}
key
=
$(
base64
-w0
<
${
tmpdir
}
/openpgpkeys/
${
domain
}
/hu/
${
hash
}
)
echo
"
${
comma
}
\"
${
hash
}
\"
: {
\"
Addr
\"
:
\"
${
mbox
}
\"
,
\"
Data
\"
:
\"
${
key
}
\"
}"
echo
"
${
comma
}
\"
${
hash
}
@
${
domain
}
\"
: {
\"
Addr
\"
:
\"
${
mbox
}
\"
,
\"
Data
\"
:
\"
${
key
}
\"
}"
comma
=
,
done
)
echo
'}'
...
...
This diff is collapsed.
Click to expand it.
ldap.go
+
13
−
6
View file @
ff2091ae
...
...
@@ -37,10 +37,10 @@ func NewLDAPStorage(uri, bindDN, bindPw, baseDN, filter string) (Storage, error)
}
if
filter
==
""
{
filter
=
fmt
.
Sprintf
(
"(%s=%%
s
)"
,
hashLDAPAttr
)
filter
=
fmt
.
Sprintf
(
"(%s=%%
h@%%d
)"
,
hashLDAPAttr
)
}
if
!
strings
.
Contains
(
filter
,
"%
s
"
)
{
return
nil
,
errors
.
New
(
"filter expression does not contain literal '%
s
' token"
)
if
!
strings
.
Contains
(
filter
,
"%
h
"
)
{
return
nil
,
errors
.
New
(
"filter expression does not contain literal '%
h
' token"
)
}
return
&
ldapStorage
{
...
...
@@ -50,8 +50,15 @@ func NewLDAPStorage(uri, bindDN, bindPw, baseDN, filter string) (Storage, error)
},
nil
}
func
(
s
*
ldapStorage
)
Lookup
(
ctx
context
.
Context
,
hash
string
)
(
*
Key
,
error
)
{
filter
:=
fmt
.
Sprintf
(
s
.
filter
,
ldap
.
EscapeFilter
(
hash
))
// Replace '%h' (for hash) and '%d' (for domain) tokens in the
// configured LDAP filter string, and return the result.
func
(
s
*
ldapStorage
)
filterExpr
(
hash
,
domain
string
)
string
{
// This is only safe because domain can't contain %h.
f
:=
strings
.
Replace
(
s
.
filter
,
"%d"
,
ldap
.
EscapeFilter
(
domain
),
-
1
)
return
strings
.
Replace
(
f
,
"%h"
,
ldap
.
EscapeFilter
(
hash
),
-
1
)
}
func
(
s
*
ldapStorage
)
Lookup
(
ctx
context
.
Context
,
hash
,
domain
string
)
(
*
Key
,
error
)
{
req
:=
ldap
.
NewSearchRequest
(
s
.
baseDN
,
ldap
.
ScopeWholeSubtree
,
...
...
@@ -59,7 +66,7 @@ func (s *ldapStorage) Lookup(ctx context.Context, hash string) (*Key, error) {
0
,
0
,
false
,
filter
,
s
.
filter
Expr
(
hash
,
domain
)
,
[]
string
{
mailLDAPAttr
,
keyLDAPAttr
},
nil
,
)
...
...
This diff is collapsed.
Click to expand it.
server.go
+
2
−
2
View file @
ff2091ae
...
...
@@ -84,7 +84,7 @@ type Storage interface {
// information. The special ErrNotFound error can be used to
// indicate that no key was found, as opposed to a generic
// backend error.
Lookup
(
context
.
Context
,
string
)
(
*
Key
,
error
)
Lookup
(
context
.
Context
,
string
,
string
)
(
*
Key
,
error
)
}
// Server for the WKD protocol.
...
...
@@ -138,7 +138,7 @@ func (s *Server) serveDiscovery(w http.ResponseWriter, r *http.Request, request
// Go through available storages until one returns a valid key.
for
_
,
storage
:=
range
s
.
storages
{
key
,
err
=
storage
.
Lookup
(
r
.
Context
(),
request
.
Hash
)
key
,
err
=
storage
.
Lookup
(
r
.
Context
(),
request
.
Hash
,
request
.
Domain
)
if
err
==
nil
{
break
}
...
...
This diff is collapsed.
Click to expand it.
static.go
+
4
−
2
View file @
ff2091ae
...
...
@@ -3,6 +3,7 @@ package wkd
import
(
"context"
"encoding/json"
"fmt"
"os"
)
...
...
@@ -30,8 +31,9 @@ func NewStaticStorage(path string) (Storage, error) {
return
&
staticStorage
{
keys
:
keys
},
nil
}
func
(
s
*
staticStorage
)
Lookup
(
ctx
context
.
Context
,
hash
string
)
(
*
Key
,
error
)
{
if
key
,
ok
:=
s
.
keys
[
hash
];
ok
{
func
(
s
*
staticStorage
)
Lookup
(
ctx
context
.
Context
,
hash
,
domain
string
)
(
*
Key
,
error
)
{
hashAddr
:=
fmt
.
Sprintf
(
"%s@%s"
,
hash
,
domain
)
if
key
,
ok
:=
s
.
keys
[
hashAddr
];
ok
{
return
key
,
nil
}
return
nil
,
ErrNotFound
...
...
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