Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN contacts
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
edugain
eduGAIN contacts
Commits
b6e93eca
Commit
b6e93eca
authored
2 years ago
by
Davide Vaghetti
Browse files
Options
Downloads
Patches
Plain Diff
Added entity_search.py script
parent
59ec0a54
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
entity_search.py
+85
-0
85 additions, 0 deletions
entity_search.py
with
85 additions
and
0 deletions
entity_search.py
0 → 100755
+
85
−
0
View file @
b6e93eca
#!/usr/bin/env python3
import
sys
import
requests
import
argparse
import
hashlib
import
base64
from
xml.etree
import
ElementTree
as
ET
# DEFINE SOME VARS
entity_id
=
None
metadata_file
=
None
root
=
None
tec_contact
=
''
sup_contact
=
''
adm_contact
=
''
# ARGPARSE
parser
=
argparse
.
ArgumentParser
(
description
=
'
Search for an entity in a metadata aggregate (default to eduGAIN metadata).
'
,
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
epilog
=
'''
Output: entityID
Examples
- Search an entity by the SHA256 hash of its certificate in the eduGAIN metadata:
\n
./entity_search.py -s SHA256HASH_STRING
\n\n
- Search an entity by the SHA256 hash of its certificate using local metadata file:
\n
./entity_details.py -s SHA256HASH_STRING -f edugain-v2.xml
'''
)
group
=
parser
.
add_mutually_exclusive_group
()
group
.
add_argument
(
'
-s
'
,
type
=
str
,
help
=
'
search entity by the sha256 hash S
'
)
parser
.
add_argument
(
'
-f
'
,
type
=
str
,
help
=
'
load metadata from file F
'
)
parser
.
add_argument
(
'
-u
'
,
type
=
str
,
default
=
'
https://mds.edugain.org/edugain-v2.xml
'
,
help
=
'
download metadata from url U (default to https://mds.edugain.org/edugain-v2.xml)
'
)
args
=
parser
.
parse_args
()
# MAIN
if
not
args
.
s
:
parser
.
parse_args
([
'
-h
'
])
exit
(
1
)
if
args
.
f
:
tree
=
ET
.
parse
(
args
.
f
)
root
=
tree
.
getroot
()
else
:
xml_req
=
requests
.
get
(
args
.
u
)
root
=
ET
.
fromstring
(
xml_req
.
content
)
orgs
=
set
()
ns
=
{
'
md
'
:
'
urn:oasis:names:tc:SAML:2.0:metadata
'
,
'
ds
'
:
'
http://www.w3.org/2000/09/xmldsig#
'
,
'
mdui
'
:
'
urn:oasis:names:tc:SAML:metadata:ui
'
,
'
shibmd
'
:
'
urn:mace:shibboleth:metadata:1.0
'
,
'
remd
'
:
'
http://refeds.org/metadata
'
,
'
icmd
'
:
'
http://id.incommon.org/metadata
'
,
'
mdrpi
'
:
'
urn:oasis:names:tc:SAML:metadata:rpi
'
,
}
entities
=
root
.
findall
(
'
./md:EntityDescriptor
'
,
ns
)
found_entities
=
set
()
for
entity
in
entities
:
certs
=
entity
.
findall
(
f
'
.//ds:X509Certificate
'
,
ns
)
for
cert
in
certs
:
if
cert
.
text
is
not
None
:
if
hashlib
.
sha256
(
base64
.
b64decode
(
cert
.
text
)).
hexdigest
().
lower
()
==
args
.
s
.
replace
(
'
:
'
,
''
).
lower
():
entity_id
=
entity
.
attrib
[
'
entityID
'
].
strip
()
found_entities
.
add
(
entity_id
)
if
len
(
found_entities
)
>
0
:
print
(
f
'
Found
{
len
(
found_entities
)
}
entities:
'
)
for
fentity
in
found_entities
:
print
(
fentity
)
else
:
print
(
'
No entities found.
'
)
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