Skip to content

Commit

Permalink
Updated project structure to run demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Solana authored and Albert Solana committed Jul 19, 2019
1 parent 4e34e44 commit 998b0e0
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 47 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 8 additions & 5 deletions demo/eidas_demo.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# eidas_demo.py
""" EIDAS LIBRARY DEMO TO TEST ALL API FUNCTIONS """
import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)

import time, json, threading
from eidas_bridge.eidas_bridge import eidas_link_did, \
eidas_get_service_endpoint, eidas_sign_credential, eidas_verify_credential, \
EIDASNotSupportedException
from eidas_bridge.utils.crypto import InvalidSignatureException, x509_load_certificate_from_data_bytes, \
PKCS1v15_PADDING, PSS_PADDING, rsa_verify
from tests.data.common_data import eidas_link_inputs, service_endpoints, credentials, paddings, \
from data.common_data import eidas_link_inputs, service_endpoints, credentials, paddings, \
did_documents
from tests.util import bcolors, print_object, LocalServer
from tests.crypto import create_selfsigned_x509_certificate, store_rsa_key_and_x509cert_to_disk, \
from util.util import bcolors, print_object, LocalServer
from util.crypto import create_selfsigned_x509_certificate, store_rsa_key_and_x509cert_to_disk, \
print_rsa_pub_key, print_x509cert, eidas_crypto_hash_byte, eidas_crypto_hash_str, \
eidas_crypto_hash_hex, rsa_load_private_key_from_file, x509_load_certificate_from_file, \
x509_get_PEM_certificate_from_obj, print_rsa_priv_key, rsa_sign, load_pkcs12_file
Expand Down Expand Up @@ -295,7 +299,6 @@ def main_tests():
input("Press Enter to continue...")
basic_demo()

"""
print(bcolors.HEADER + "\n--- INIT CRYPTO HASH TEST SUITE ---\n\r" + bcolors.ENDC)
input("Press Enter to continue...")
test_crypto_hash_suite()
Expand All @@ -314,7 +317,7 @@ def main_tests():
paddings,
True
)
"""

elapsed_time = time.time() - start_time
print(bcolors.BOLD + "\n--- END EIDAS MAIN DEMO TEST SUITE ---\n\r" + bcolors.ENDC)
print("--- Total time: " + bcolors.OKGREEN + str(round(elapsed_time, 2)) + " seconds " + \
Expand Down
Empty file added demo/util/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/crypto.py → demo/util/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.serialization import pkcs12
from tests.util import print_object
from .util import print_object
from eidas_bridge.utils.crypto import PKCS1v15_PADDING, PSS_PADDING, InvalidPaddingException


Expand Down
8 changes: 2 additions & 6 deletions demo/server.py → demo/util/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import re, json

class RequestHandler(BaseHTTPRequestHandler):

def do_GET(self):
if None != re.search('/*/eidas', self.path):
# read file
with open('./demo/eidas.json', 'r') as myfile:
with open('./demo/data/eidas.json', 'r') as myfile:
data=myfile.read()

# parse file
Expand All @@ -19,11 +20,6 @@ def do_GET(self):
return

def start_server():
server = HTTPServer(('localhost', 8000), RequestHandler)
print('Starting server at http://localhost:8000')
server.serve_forever()

if __name__ == '__main__':
server = HTTPServer(('localhost', 8000), RequestHandler)
print('Starting server at http://localhost:8000')
server.serve_forever()
27 changes: 2 additions & 25 deletions tests/util.py → demo/util/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# util.py
""" data and functions to better testing """

import base58, base64, threading
from demo.server import start_server
import threading
from .server import start_server

class bcolors:
HEADER = '\033[95m'
Expand All @@ -14,29 +14,6 @@ class bcolors:
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

def b64_to_bytes(val: str, urlsafe=False) -> bytes:
"""Convert a base 64 string to bytes."""
if urlsafe:
return base64.urlsafe_b64decode(val)
return base64.b64decode(val)


def bytes_to_b64(val: bytes, urlsafe=False) -> str:
"""Convert a byte string to base 64."""
if urlsafe:
return base64.urlsafe_b64encode(val).decode("ascii")
return base64.b64encode(val).decode("ascii")


def b58_to_bytes(val: str) -> bytes:
"""Convert a base 58 string to bytes."""
return base58.b58decode(val)


def bytes_to_b58(val: bytes) -> str:
"""Convert a byte string to base 58."""
return base58.b58encode(val).decode("ascii")

def print_object(input_obj):
print("{}".format(input_obj.decode()))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
""" Unit test for cryptographic functions from tests/crypto.py file for auxiliary testing purposes """

import pytest
from tests.crypto import eidas_crypto_hash_str
from tests.data.common_data import crypto_testdata
from demo.util.crypto import eidas_crypto_hash_str
from demo.data.common_data import crypto_testdata

@pytest.mark.parametrize("did, expected", crypto_testdata)
def test_eidas_crypto_hash_str(did, expected):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_did_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest, json
from eidas_bridge.did_document import DIDDocument, EIDASDIDDocNoSubjectIdException, \
EIDASServiceEndpointException, _set_eidas_service, _get_services
from tests.data.common_data import did_documents, bad_did_documents, eidas_services, \
from demo.data.common_data import did_documents, bad_did_documents, eidas_services, \
did_doc_services, did_doc_services_no_eidas
from eidas_bridge.eidas_service import EIDASService

Expand Down
4 changes: 2 additions & 2 deletions tests/test_eidas_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
eidas_get_service_endpoint, eidas_sign_credential, eidas_verify_credential, \
EIDASNotSupportedException
from eidas_bridge.utils.util import timestamp
from tests.data.common_data import all_type_dids, all_type_certificates, bad_type_proofs, \
from demo.data.common_data import all_type_dids, all_type_certificates, bad_type_proofs, \
dids, bad_type_endpoints, service_endpoints, bad_type_credentials, credentials, \
eidas_link_inputs, did_documents
from .util import start_server_thread
from demo.util.util import start_server_thread

@pytest.mark.parametrize("did", all_type_dids)
@pytest.mark.parametrize("certificate", all_type_certificates)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_eidas_bridge_utils_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from cryptography import x509
from cryptography.hazmat.primitives import serialization
from tests.data.common_data import eidas_link_inputs, bad_obj_type_paddings, paddings, bad_type_paddings, \
from demo.data.common_data import eidas_link_inputs, bad_obj_type_paddings, paddings, bad_type_paddings, \
PKCS1v15_PADDING, PSS_PADDING
from eidas_bridge.utils.crypto import x509_load_certificate_from_data_bytes, check_args_padding, \
InvalidPaddingException, InvalidSignatureException, get_public_key_from_x509cert_obj, \
Expand Down
4 changes: 2 additions & 2 deletions tests/test_eidas_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from eidas_bridge.eidas_service import EIDASService
from eidas_bridge.did_document import DIDDocument
from eidas_bridge.eidaslink import EIDASLink
from tests.data.common_data import all_type_dids, bad_type_endpoints, service_endpoints, \
from demo.data.common_data import all_type_dids, bad_type_endpoints, service_endpoints, \
eidas_services, eidas_link_and_diddocs_jsons
from eidas_bridge.utils.util import clean_did
from .util import start_server_thread
from demo.util.util import start_server_thread

@pytest.mark.parametrize("did", all_type_dids)
@pytest.mark.parametrize("service_endpoint", bad_type_endpoints)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_eidaslink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from eidas_bridge.eidaslink import EIDASLink
from tests.data.common_data import all_type_dids, all_type_certificates, bad_type_proofs, \
from demo.data.common_data import all_type_dids, all_type_certificates, bad_type_proofs, \
dids, bad_obj_type_paddings, bad_type_paddings, eidas_link_inputs
from eidas_bridge.utils.crypto import InvalidPaddingException

Expand Down
2 changes: 1 addition & 1 deletion tests/test_verifiable_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from eidas_bridge.verifiable_credential import VerifiableCredential, EIDASVerifiableCredentialNoIssuerException
from tests.data.common_data import credentials, bad_credentials
from demo.data.common_data import credentials, bad_credentials
import json

def test_verifiable_credential_class_bad_types():
Expand Down

0 comments on commit 998b0e0

Please sign in to comment.