Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
c4d46d20
Commit
c4d46d20
authored
Feb 20, 2022
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the galene-link utility.
parent
37ef768a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
8 deletions
+123
-8
galene-link/galene-link.go
galene-link/galene-link.go
+115
-0
token/token.go
token/token.go
+2
-2
token/token_test.go
token/token_test.go
+6
-6
No files found.
galene-link/galene-link.go
0 → 100644
View file @
c4d46d20
package
main
import
(
"flag"
"fmt"
"log"
"net/url"
"path"
"time"
"github.com/golang-jwt/jwt/v4"
"github.com/jech/galene/group"
"github.com/jech/galene/token"
)
func
main
()
{
var
username
,
kid
,
server
string
var
valid
int
var
tokenOnly
bool
flag
.
StringVar
(
&
group
.
Directory
,
"groups"
,
"./groups/"
,
"group description `directory`"
)
flag
.
StringVar
(
&
username
,
"user"
,
""
,
"username"
)
flag
.
StringVar
(
&
kid
,
"kid"
,
""
,
"`id` of key to use"
)
flag
.
IntVar
(
&
valid
,
"valid"
,
86400
,
"`seconds` validity"
)
flag
.
StringVar
(
&
server
,
"server"
,
"https://galene.org:8443"
,
"server `url`"
)
flag
.
BoolVar
(
&
tokenOnly
,
"token"
,
false
,
"generate token only"
)
flag
.
Parse
()
if
flag
.
NArg
()
!=
1
{
log
.
Fatal
(
"One argument (the group URL) required"
)
}
groupname
:=
flag
.
Arg
(
0
)
desc
,
err
:=
group
.
GetDescription
(
groupname
)
if
err
!=
nil
{
log
.
Fatal
(
"Get group description: "
,
err
)
}
serverURL
,
err
:=
url
.
Parse
(
server
)
if
err
!=
nil
{
log
.
Fatal
(
"Couldn't parse server URL"
)
}
pth
:=
path
.
Join
(
path
.
Join
(
serverURL
.
Path
,
"group"
),
groupname
)
+
"/"
groupURL
:=
&
url
.
URL
{
Scheme
:
serverURL
.
Scheme
,
Host
:
serverURL
.
Host
,
Path
:
pth
,
}
keys
:=
desc
.
AuthKeys
var
key
map
[
string
]
interface
{}
for
_
,
k
:=
range
keys
{
kid2
,
_
:=
k
[
"kid"
]
.
(
string
)
if
kid
==
""
||
kid
==
kid2
{
key
=
k
break
}
}
if
key
==
nil
{
log
.
Fatal
(
"Couldn't find key"
)
}
alg
,
ok
:=
key
[
"alg"
]
.
(
string
)
var
method
jwt
.
SigningMethod
if
ok
{
method
=
jwt
.
GetSigningMethod
(
alg
)
}
if
method
==
nil
{
log
.
Fatal
(
"Couldn't determine key signing method"
)
}
kstring
,
err
:=
token
.
ParseKey
(
key
)
if
err
!=
nil
{
log
.
Fatal
(
"Couldn't parse key"
)
}
now
:=
time
.
Now
()
end
:=
now
.
Add
(
time
.
Second
*
time
.
Duration
(
valid
))
token
:=
jwt
.
NewWithClaims
(
method
,
&
jwt
.
MapClaims
{
"sub"
:
username
,
"aud"
:
groupURL
.
String
(),
"exp"
:
&
jwt
.
NumericDate
{
end
},
"nbf"
:
&
jwt
.
NumericDate
{
now
},
"iat"
:
&
jwt
.
NumericDate
{
now
},
"permissions"
:
[]
string
{
"present"
},
},
)
s
,
err
:=
token
.
SignedString
(
kstring
)
if
err
!=
nil
{
log
.
Fatal
(
"Couldn't sign token: "
,
err
)
}
if
tokenOnly
{
fmt
.
Println
(
s
)
}
else
{
query
:=
url
.
Values
{}
if
username
!=
""
{
query
.
Add
(
"username"
,
username
)
}
query
.
Add
(
"token"
,
s
)
outURL
:=
&
url
.
URL
{
Scheme
:
groupURL
.
Scheme
,
Host
:
groupURL
.
Host
,
Path
:
groupURL
.
Path
,
RawQuery
:
query
.
Encode
(),
}
fmt
.
Println
(
outURL
.
String
())
}
}
token/token.go
View file @
c4d46d20
...
...
@@ -24,7 +24,7 @@ func parseBase64(k string, d map[string]interface{}) ([]byte, error) {
return
vv
,
nil
}
func
p
arseKey
(
key
map
[
string
]
interface
{})
(
interface
{},
error
)
{
func
P
arseKey
(
key
map
[
string
]
interface
{})
(
interface
{},
error
)
{
kty
,
ok
:=
key
[
"kty"
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"kty not found"
)
...
...
@@ -99,7 +99,7 @@ func getKey(header map[string]interface{}, keys []map[string]interface{}) (inter
kid2
,
_
:=
k
[
"kid"
]
.
(
string
)
alg2
,
_
:=
k
[
"alg"
]
.
(
string
)
if
(
kid
==
""
||
kid
==
kid2
)
&&
alg
==
alg2
{
return
p
arseKey
(
k
)
return
P
arseKey
(
k
)
}
}
return
nil
,
errors
.
New
(
"key not found"
)
...
...
token/token_test.go
View file @
c4d46d20
...
...
@@ -21,13 +21,13 @@ func TestHS256(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %v"
,
err
)
}
k
,
err
:=
p
arseKey
(
j
)
k
,
err
:=
P
arseKey
(
j
)
if
err
!=
nil
{
t
.
Fatalf
(
"
p
arseKey: %v"
,
err
)
t
.
Fatalf
(
"
P
arseKey: %v"
,
err
)
}
kk
,
ok
:=
k
.
([]
byte
)
if
!
ok
||
len
(
kk
)
!=
32
{
t
.
Errorf
(
"
p
arseKey: got %v"
,
kk
)
t
.
Errorf
(
"
P
arseKey: got %v"
,
kk
)
}
}
...
...
@@ -44,13 +44,13 @@ func TestES256(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %v"
,
err
)
}
k
,
err
:=
p
arseKey
(
j
)
k
,
err
:=
P
arseKey
(
j
)
if
err
!=
nil
{
t
.
Fatalf
(
"
p
arseKey: %v"
,
err
)
t
.
Fatalf
(
"
P
arseKey: %v"
,
err
)
}
kk
,
ok
:=
k
.
(
*
ecdsa
.
PublicKey
)
if
!
ok
||
kk
.
Params
()
.
Name
!=
"P-256"
{
t
.
Errorf
(
"
p
arseKey: got %v"
,
kk
)
t
.
Errorf
(
"
P
arseKey: got %v"
,
kk
)
}
if
!
kk
.
IsOnCurve
(
kk
.
X
,
kk
.
Y
)
{
t
.
Errorf
(
"point is not on curve"
)
...
...
Write
Preview
Markdown
is supported
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