Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
24ff8841
Commit
24ff8841
authored
7 years ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#61
: add certification script.
parent
9d106d4b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cert.py
+89
-0
89 additions, 0 deletions
src/cert.py
src/wot.py
+16
-0
16 additions, 0 deletions
src/wot.py
with
105 additions
and
0 deletions
src/cert.py
0 → 100644
+
89
−
0
View file @
24ff8841
import
webbrowser
import
urllib
from
sys
import
exit
from
pydoc
import
pager
from
tabulate
import
tabulate
from
auth
import
auth_method
from
tools
import
get_publickey_from_seed
,
message_exit
,
get_current_block
,
\
sign_document_from_seed
from
network_tools
import
get_request
,
get_current_block
,
post_request
from
constants
import
NO_MATCHING_ID
from
wot
import
is_member
,
get_pubkey_from_id
,
get_pubkeys_from_id
,
\
get_uid_from_pubkey
def
send_certification
(
ep
,
cli_args
):
current_blk
=
get_current_block
(
ep
)
certified_uid
=
cli_args
.
subsubcmd
certified_pubkey
=
get_pubkey_from_id
(
ep
,
certified_uid
)
# Check that the id is present on the network
if
(
certified_pubkey
is
NO_MATCHING_ID
):
message_exit
(
NO_MATCHING_ID
)
# Display license and ask for confirmation
license_approval
(
current_blk
[
"
currency
"
])
# Authentication
seed
=
auth_method
(
cli_args
)
# Check whether current user is member
issuer_pubkey
=
get_publickey_from_seed
(
seed
)
issuer_id
=
get_uid_from_pubkey
(
ep
,
issuer_pubkey
)
if
not
is_member
(
ep
,
issuer_pubkey
,
issuer_id
):
message_exit
(
"
Current identity is not member.
"
)
# Check if this certification is already present on the network
id_lookup
=
get_pubkeys_from_id
(
ep
,
certified_uid
)[
0
]
for
certifiers
in
id_lookup
[
"
uids
"
][
0
][
"
others
"
]:
if
certifiers
[
"
pubkey
"
]
==
issuer_pubkey
:
message_exit
(
"
Identity already certified by
"
+
issuer_id
)
# Certification confirmation
if
not
certification_confirmation
(
issuer_id
,
issuer_pubkey
,
certified_uid
,
certified_pubkey
):
return
cert_doc
=
generate_certification_document
(
id_lookup
,
current_blk
,
issuer_pubkey
,
certified_uid
)
cert_doc
+=
sign_document_from_seed
(
cert_doc
,
seed
)
+
"
\n
"
# Send certification document
post_request
(
ep
,
"
wot/certify
"
,
"
cert=
"
+
urllib
.
parse
.
quote_plus
(
cert_doc
))
print
(
"
Certification successfully sent.
"
)
def
license_approval
(
currency
):
if
currency
!=
"
g1
"
:
return
language
=
input
(
"
In which language would you like to display Ğ1 license [en/fr]?
"
)
if
(
language
==
"
en
"
):
if
not
webbrowser
.
open
(
"
https://duniter.org/en/get-g1/
"
):
pager
(
open
(
"
licence-G1/license/license_g1-en.rst
"
).
read
())
else
:
if
not
webbrowser
.
open
(
"
https://duniter.org/fr/wiki/licence-g1/
"
):
pager
(
open
(
"
licence-G1/license/license_g1-fr-FR.rst
"
).
read
())
if
(
input
(
"
Do you approve Ğ1 license [yes/no]?
"
)
!=
"
yes
"
):
exit
(
1
)
def
certification_confirmation
(
issuer_id
,
issuer_pubkey
,
certified_uid
,
certified_pubkey
):
cert
=
list
()
cert
.
append
([
"
Cert
"
,
"
From
"
,
"
–>
"
,
"
To
"
])
cert
.
append
([
"
ID
"
,
issuer_id
,
"
–>
"
,
certified_uid
])
cert
.
append
([
"
Pubkey
"
,
issuer_pubkey
,
"
–>
"
,
certified_pubkey
])
if
input
(
tabulate
(
cert
,
tablefmt
=
"
fancy_grid
"
)
+
"
\n
Do you confirm sending this certification? [yes/no]:
"
)
==
"
yes
"
:
return
True
def
generate_certification_document
(
id_lookup
,
current_blk
,
issuer_pubkey
,
certified_uid
):
return
"
Version: 10
\n\
Type: Certification
\n\
Currency:
"
+
current_blk
[
"
currency
"
]
+
"
\n\
Issuer:
"
+
issuer_pubkey
+
"
\n\
IdtyIssuer:
"
+
id_lookup
[
"
pubkey
"
]
+
"
\n\
IdtyUniqueID:
"
+
certified_uid
+
"
\n\
IdtyTimestamp:
"
+
id_lookup
[
"
uids
"
][
0
][
"
meta
"
][
"
timestamp
"
]
+
"
\n\
IdtySignature:
"
+
id_lookup
[
"
uids
"
][
0
][
"
self
"
]
+
"
\n\
CertTimestamp:
"
+
str
(
current_blk
[
"
number
"
])
+
"
-
"
+
current_blk
[
"
hash
"
]
+
"
\n
"
This diff is collapsed.
Click to expand it.
src/wot.py
+
16
−
0
View file @
24ff8841
...
@@ -79,3 +79,19 @@ def get_pubkeys_from_id(ep, uid):
...
@@ -79,3 +79,19 @@ def get_pubkeys_from_id(ep, uid):
except
:
except
:
return
NO_MATCHING_ID
return
NO_MATCHING_ID
return
results
[
"
results
"
]
return
results
[
"
results
"
]
def
is_member
(
ep
,
pubkey
,
uid
):
members
=
get_request
(
ep
,
"
wot/members
"
)[
"
results
"
]
for
member
in
members
:
if
(
pubkey
in
member
[
"
pubkey
"
]
and
uid
in
member
[
"
uid
"
]):
return
(
True
)
return
(
False
)
def
get_pubkey_from_id
(
ep
,
uid
):
members
=
get_request
(
ep
,
"
wot/members
"
)[
"
results
"
]
for
member
in
members
:
if
(
uid
in
member
[
"
uid
"
]):
return
(
member
[
"
pubkey
"
])
return
(
NO_MATCHING_ID
)
This diff is collapsed.
Click to expand it.
Moul
@moul
mentioned in commit
92a03636
·
7 years ago
mentioned in commit
92a03636
mentioned in commit 92a03636e67c15deb9fcdd830091c8de9eee8385
Toggle commit list
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