Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alternate-mdx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Trust and Identity Incubator
alternate-mdx
Commits
f12bb4b0
Commit
f12bb4b0
authored
3 years ago
by
Martin van Es
Browse files
Options
Downloads
Patches
Plain Diff
Make key_spec and cert_spec configurable
parent
b3e4d8c0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mdsigner.yaml.example
+7
-2
7 additions, 2 deletions
mdsigner.yaml.example
signers.py
+30
-22
30 additions, 22 deletions
signers.py
utils.py
+2
-2
2 additions, 2 deletions
utils.py
with
39 additions
and
26 deletions
mdsigner.yaml.example
+
7
−
2
View file @
f12bb4b0
---
test:
signer: test_signer
signer:
name: test_signer
key_spec: meta.key
cert_spec: meta.crt
metadir: metadata/test
foobar:
signer: foobar_signer
signer:
name: hsm_signer
key_spec: pkcs11:///usr/lib/softhsm/libsofthsm2.so/test?pin=secret
metadir: metadata/foobar
This diff is collapsed.
Click to expand it.
signers.py
+
30
−
22
View file @
f12bb4b0
import
xmlsec
cert
=
"
meta.crt
"
key
=
"
meta.key
"
def
_normal_signer
(
xml
,
key_spec
,
cert_spec
):
print
(
f
"
Normal signer
{
key_spec
}
{
cert_spec
}
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key_spec
,
cert_spec
=
cert_spec
)
def
Signers
(
signer
):
def
_normal_signer
(
xml
):
print
(
"
Normal signer
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key
,
cert_spec
=
cert
)
def
_test_signer
(
xml
):
print
(
"
Test signer
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key
,
cert_spec
=
cert
)
def
_test_signer
(
xml
,
key_spec
,
cert_spec
):
print
(
f
"
Test signer
{
key_spec
}
{
cert_spec
}
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key
_spec
,
cert_spec
=
cert
_spec
)
def
_foobar_signer
(
xml
):
print
(
"
Foobar signer
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key
,
cert_spec
=
cert
)
def
_
hsm
_signer
(
xml
):
print
(
"
HSM signer
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
"
pkcs11:///usr/lib/softhsm/libsofthsm2.so/test?pin=secret
"
)
def
_
foobar
_signer
(
xml
,
key_spec
,
cert_spec
):
print
(
f
"
Foobar signer
{
key_spec
}
{
cert_spec
}
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key_spec
,
cert_spec
=
cert_spec
)
signers
=
{
'
normal_signer
'
:
_normal_signer
,
'
test_signer
'
:
_test_signer
,
'
foobar_signer
'
:
_foobar_signer
,
'
hsm_signer
'
:
_hsm_signer
}
return
signers
[
signer
]
def
_hsm_signer
(
xml
,
key_spec
,
cert_spec
):
print
(
f
"
HSM signer
{
key_spec
}
{
cert_spec
}
"
)
return
xmlsec
.
sign
(
xml
,
key_spec
=
key_spec
,
cert_spec
=
cert_spec
)
_signers
=
{
'
normal_signer
'
:
_normal_signer
,
'
test_signer
'
:
_test_signer
,
'
foobar_signer
'
:
_foobar_signer
,
'
hsm_signer
'
:
_hsm_signer
}
class
Signers
():
def
__init__
(
self
,
signer
):
self
.
name
=
signer
[
'
name
'
]
self
.
key_spec
=
signer
[
'
key_spec
'
]
self
.
cert_spec
=
signer
.
get
(
'
cert_spec
'
,
None
)
def
sign
(
self
,
xml
):
return
_signers
[
self
.
name
](
xml
,
self
.
key_spec
,
self
.
cert_spec
)
This diff is collapsed.
Click to expand it.
utils.py
+
2
−
2
View file @
f12bb4b0
...
...
@@ -163,7 +163,7 @@ class Realm:
print
(
f
"
sign
{
sha1
}
"
)
valid_until
=
self
.
idps
[
sha1
].
valid_until
if
valid_until
>
datetime
.
now
(
tz
.
tzutc
()):
signed_element
=
self
.
signer
(
self
.
idps
[
sha1
].
md
)
signed_element
=
self
.
signer
.
sign
(
self
.
idps
[
sha1
].
md
)
signed_xml
=
ET
.
tostring
(
signed_element
,
pretty_print
=
True
).
decode
()
signed_entity
=
Entity
()
...
...
@@ -208,7 +208,7 @@ class Realm:
root
.
set
(
'
cacheDuration
'
,
duration_isoformat
(
cache_duration
))
last_modified
=
datetime
.
now
(
tz
.
tzutc
())
signed_root
=
self
.
signer
(
root
)
signed_root
=
self
.
signer
.
sign
(
root
)
data
.
md
=
ET
.
tostring
(
signed_root
,
pretty_print
=
True
)
data
.
valid_until
=
valid_until
data
.
last_modified
=
last_modified
...
...
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