Skip to content

Pip package #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Contributors
============
* James Kizer
* Alan Viars
93 changes: 93 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from distutils.core import setup
from distutils.command.install_data import install_data
from distutils.command.install import INSTALL_SCHEMES
import os
import sys


class osx_install_data(install_data):
# On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
# which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
# for this in distutils.command.install_data#306. It fixes install_lib but not
# install_data, which is why we roll our own install_data class.

def finalize_options(self):
# By the time finalize_options is called, install.install_lib is set to the
# fixed directory, so we set the installdir to install_lib. The
# install_data class uses ('install_data', 'install_dir') instead.
self.set_undefined_options('install', ('install_lib', 'install_dir'))
install_data.finalize_options(self)

if sys.platform == "darwin":
cmdclasses = {'install_data': osx_install_data}
else:
cmdclasses = {'install_data': install_data}


def fullsplit(path, result=None):
"""
Split a pathname into components (the opposite of os.path.join) in a
platform-neutral way.
"""
if result is None:
result = []
head, tail = os.path.split(path)
if head == '':
return [tail] + result
if head == path:
return result
return fullsplit(head, [tail] + result)

# Tell distutils to put the data_files in platform-specific installation
# locations. See here for an explanation:
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
for scheme in INSTALL_SCHEMES.values():
scheme['data'] = scheme['purelib']

# Compile the list of packages available, because distutils doesn't have
# an easy way to do this.
packages, data_files = [], []
root_dir = os.path.dirname(__file__)
if root_dir != '':
os.chdir(root_dir)
shc_dir = ''

for dirpath, dirnames, filenames in os.walk(shc_dir):
# Ignore dirnames that start with '.'
for i, dirname in enumerate(dirnames):
if dirname.startswith('.'):
del dirnames[i]
if '__init__.py' in filenames:
packages.append('.'.join(fullsplit(dirpath)))
elif filenames:
data_files.append([dirpath, [os.path.join(dirpath, f)
for f in filenames]])

# Small hack for working with bdist_wininst.
# See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
for file_info in data_files:
file_info[0] = '\\PURELIB\\%s' % file_info[0]


setup(
name="shc",
version="0.0.4",
description="SMART Health Card Tools",
long_description="""A collection of scripts and utilites for working with SMART Health Cards on the command line and in Python.""",
author="James Kizer, Alan Viars",
author_email="[email protected]",
url="https://github.com/TransparentHealth/healthcards_python_sample_scripts",
download_url="https://github.com/TransparentHealth/healthcards_python_sample_scripts/tarball/master",
install_requires=[
'jwcrypto', 'canonicaljson', 'requests', 'py-multihash', 'PyLD', 'python-jose[cryptography]', 'qrcode[pil]'
],
packages=['shc',],
scripts=[
'shc/decode_resource.py',
'shc/decode_resource_local.py',
'shc/encode_resource.py',
'shc/generate_random_jwks.py',
'shc/encode_resource_in_qr_code.py',
'shc/encode_resource_file_in_qr_code.py',
])
Empty file added shc/__init__.py
Empty file.
11 changes: 7 additions & 4 deletions decode_inline.py → shc/decode_inline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python
import json
import argparse
import base64
import utils
import shc.utils


def main():
parser = argparse.ArgumentParser(description='Decodes a vc')
Expand All @@ -11,13 +13,14 @@ def main():
try:
jws_raw = base64.standard_b64decode(args.input).decode(encoding='utf-8')
print("Base 64 decoding succeeded")
except:
print("Base 64 decoding failed, assuming input is JWS")
except Exception as e:
print("Base 64 decoding failed, assuming input is JWS", e)
jws_raw = args.input

payload_dict = utils.decode_vc(jws_raw)

print(json.dumps(payload_dict, indent=4))


if __name__ == "__main__":
main()
main()
7 changes: 5 additions & 2 deletions decode_resource.py → shc/decode_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import json
import argparse
import utils
import shc.utils


def main():
parser = argparse.ArgumentParser(description='Decodes a vc')
Expand All @@ -13,5 +15,6 @@ def main():

print(json.dumps(payload_dict, indent=4))


if __name__ == "__main__":
main()
main()
7 changes: 5 additions & 2 deletions decode_resource_local.py → shc/decode_resource_local.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import json
import argparse
import utils
import shc.utils


def main():
parser = argparse.ArgumentParser(description='Decodes a vc')
Expand All @@ -14,5 +16,6 @@ def main():

print(json.dumps(payload_dict, indent=4))


if __name__ == "__main__":
main()
main()
13 changes: 8 additions & 5 deletions encode_resource.py → shc/encode_resource.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
import argparse
import json
import time
import secrets
import utils
import shc.utils


def main():
parser = argparse.ArgumentParser(description='Encodes a vc')
Expand All @@ -21,19 +23,20 @@ def main():
with open(args.input_file, 'r') as input_file:
payload = json.load(input_file)

##since we're using a static file to form the payload
## it needs to be modified a bit
# since we're using a static file to form the payload
# it needs to be modified a bit
now = int(time.time())
payload['iss'] = args.issuer
payload['iat'] = now
vc_jws = utils.encode_vc(payload, private_signing_key, kid)

## this is the general format for a FHIR backed vc file, this is subject to change
# this is the general format for a FHIR backed vc file, this is subject to change
with open(args.output_file, 'w') as outfile:
output_dict = {
'verifiableCredential': [vc_jws]
}
json.dump(output_dict, outfile)


if __name__ == "__main__":
main()
main()
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
import argparse
import json
import time
import secrets
import utils
import shc.utils


def main():
Expand All @@ -20,5 +21,6 @@ def main():
with open(args.output_file, 'wb') as outfile:
qr_img.save(outfile)


if __name__ == "__main__":
main()
main()
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
import argparse
import json
import time
import secrets
import utils
import shc.utils


def main():
Expand All @@ -23,8 +24,8 @@ def main():
with open(args.input_file, 'r') as input_file:
payload = json.load(input_file)

##since we're using a static file to form the payload
## it needs to be modified a bit
# since we're using a static file to form the payload
# it needs to be modified a bit
now = int(time.time())
payload['iss'] = args.issuer
payload['iat'] = now
Expand All @@ -35,5 +36,6 @@ def main():
with open(args.output_file, 'wb') as outfile:
qr_img.save(outfile)


if __name__ == "__main__":
main()
main()
10 changes: 8 additions & 2 deletions generate_random_jwks.py → shc/generate_random_jwks.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#!/usr/bin/env python
from jwcrypto import jwk
import argparse
import json


def generate_signing_key():
key = jwk.JWK.generate(kty='EC', crv='P-256', alg='ES256', use='sig')
key._params['kid'] = key.thumbprint()
key.setdefault("kid",key.thumbprint())
return key


def generate_encryption_key():
key = jwk.JWK.generate(kty='EC', crv='P-256', alg='ECDH-ES', use='enc')
key._params['kid'] = key.thumbprint()
key.setdefault("kid",key.thumbprint())
return key


def generate_keyset(keys):
keyset = jwk.JWKSet()
for key in keys:
keyset.add(key)
return keyset


def main():

parser = argparse.ArgumentParser(description='Generates a random JWK set')
Expand All @@ -35,5 +40,6 @@ def main():
with open(args.public_file, 'w', newline='') as public_file:
json.dump(keyset.export(private_keys=False, as_dict=True), public_file, indent=4)


if __name__ == "__main__":
main()
Loading