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
43ec42fd
Commit
43ec42fd
authored
3 years ago
by
Martin van Es
Browse files
Options
Downloads
Patches
Plain Diff
Reuse some code in utils.py
parent
f8ed9aac
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
mdproxy.py
+4
-14
4 additions, 14 deletions
mdproxy.py
mdserver.py
+4
-22
4 additions, 22 deletions
mdserver.py
mdsigner.py
+6
-8
6 additions, 8 deletions
mdsigner.py
utils.py
+18
-0
18 additions, 0 deletions
utils.py
with
33 additions
and
44 deletions
.gitignore
+
1
−
0
View file @
43ec42fd
...
...
@@ -2,6 +2,7 @@
bin/
lib/
pyvenv.cfg
__pycache__
meta.crt
meta.key
*.xml
This diff is collapsed.
Click to expand it.
mdproxy.py
+
4
−
14
View file @
43ec42fd
...
...
@@ -8,24 +8,14 @@ from urllib.parse import unquote
from
dateutil
import
parser
,
tz
from
datetime
import
datetime
from
utils
import
hasher
,
Entity
app
=
Flask
(
__name__
)
# Find all IdP's in edugain metadata
cached
=
{}
signer
=
'
http://localhost:5001/sign
'
class
Entity
(
object
):
md
=
None
valid_until
=
0
def
hasher
(
entity_id
):
sha1
=
hashlib
.
sha1
()
sha1
.
update
(
entity_id
.
encode
())
sha1_digest
=
sha1
.
hexdigest
()
sha1_identifier
=
sha1_digest
return
sha1_identifier
signer_url
=
'
http://localhost:5001/sign
'
@app.route
(
'
/cache/<path:eid>
'
,
methods
=
[
'
GET
'
])
...
...
@@ -43,7 +33,7 @@ def cache(eid):
return
cached
[
entityID
].
md
else
:
print
(
f
"
request
{
entityID
}
"
)
result
=
requests
.
get
(
f
"
{
signer
}
/{{sha1}}
{
entityID
}
"
).
text
result
=
requests
.
get
(
f
"
{
signer
_url
}
/{{sha1}}
{
entityID
}
"
).
text
parsed
=
ET
.
fromstring
(
result
)
validUntil
=
parsed
.
get
(
'
validUntil
'
)
# cacheDuration = parsed.get('cacheDuration')
...
...
This diff is collapsed.
Click to expand it.
mdserver.py
+
4
−
22
View file @
43ec42fd
#!/usr/bin/env python
import
sys
import
copy
import
hashlib
from
lxml
import
etree
as
ET
from
signxml
import
XMLSigner
from
flask
import
Flask
from
urllib.parse
import
unquote
from
dateutil
import
parser
,
tz
from
datetime
import
datetime
import
traceback
from
utils
import
hasher
,
signer
,
Entity
app
=
Flask
(
__name__
)
...
...
@@ -24,27 +24,9 @@ cert = open("meta.crt").read()
key
=
open
(
"
meta.key
"
).
read
()
class
Entity
(
object
):
md
=
None
valid_until
=
0
def
hasher
(
entity_id
):
sha1
=
hashlib
.
sha1
()
sha1
.
update
(
entity_id
.
encode
())
sha1_digest
=
sha1
.
hexdigest
()
return
sha1_digest
def
signer
(
xml
):
global
cert
,
key
print
(
xml
)
return
XMLSigner
().
sign
(
xml
,
key
=
key
,
cert
=
cert
)
@app.route
(
'
/sign/<path:eid>
'
,
methods
=
[
'
GET
'
])
def
sign
(
eid
):
global
idps
,
signed
global
idps
,
signed
,
cert
,
key
entityID
=
unquote
(
eid
)
if
entityID
[:
6
]
==
"
{sha1}
"
:
entityID
=
entityID
[
6
:]
...
...
@@ -60,7 +42,7 @@ def sign(eid):
if
entityID
in
idps
:
try
:
print
(
f
"
sign
{
entityID
}
"
)
signed_element
=
signer
(
idps
[
entityID
].
md
)
signed_element
=
signer
(
idps
[
entityID
].
md
,
cert
,
key
)
signed_xml
=
ET
.
tostring
(
signed_element
,
pretty_print
=
True
).
decode
()
signed_entity
=
Entity
()
signed_entity
.
md
=
signed_xml
...
...
This diff is collapsed.
Click to expand it.
mdsigner.py
+
6
−
8
View file @
43ec42fd
...
...
@@ -4,10 +4,10 @@ import copy
from
concurrent.futures
import
ThreadPoolExecutor
from
lxml
import
etree
as
ET
from
signxml
import
XMLSigner
,
XMLVerifier
import
hashlib
# import traceback
from
.utils
import
hasher
,
signer
# Find all IdP's in edugain metadata
idps
=
[]
...
...
@@ -20,16 +20,14 @@ key = open("meta.key").read()
def
sign
(
xml
,
name
):
global
success
,
failed
,
cert
global
success
,
failed
,
cert
,
key
# print("Signer")
try
:
sha1
=
hashlib
.
sha1
()
sha1
.
update
(
name
.
encode
(
'
utf-8
'
))
sha1d
=
sha1
.
hexdigest
()
signed
=
XMLSigner
().
sign
(
xml
,
key
=
key
,
cert
=
cert
)
sha1
=
hasher
(
name
)
signed
=
signer
(
xml
,
cert
,
key
)
out
=
ET
.
tostring
(
signed
,
pretty_print
=
True
).
decode
()
# XMLVerifier().verify(out, x509_cert=cert)
with
open
(
f
'
output/
{
sha1
d
}
.xml
'
,
'
w
'
)
as
f
:
with
open
(
f
'
output/
{
sha1
}
.xml
'
,
'
w
'
)
as
f
:
f
.
write
(
out
)
success
+=
1
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
utils.py
0 → 100644
+
18
−
0
View file @
43ec42fd
import
hashlib
from
signxml
import
XMLSigner
class
Entity
(
object
):
md
=
None
valid_until
=
0
def
hasher
(
entity_id
):
sha1
=
hashlib
.
sha1
()
sha1
.
update
(
entity_id
.
encode
())
sha1_digest
=
sha1
.
hexdigest
()
return
sha1_digest
def
signer
(
xml
,
cert
,
key
):
return
XMLSigner
().
sign
(
xml
,
key
=
key
,
cert
=
cert
)
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