Skip to content

realityone/libtrust-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libtrust-py

Integrate docker/libtrust with python.

Build Status

However libtrust has been deprecated, sign/verify manifest with docker distribution in python still cause great suffering.

Works for both Python 2.7.* and Python 3.*.

Usage

Install

You can install from PyPi.

$ pip install libtrust-py

Or install from GitHub for latest version.

$ pip install https://github.com/realityone/libtrust-py/archive/master.zip

Sign & Verify

from libtrust import jsonsign
from libtrust import rsa_key

pem_data = b"""-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAwq1mCmgn460MC6MnCqranQNTgmKuKPl7bNH7Qc6hBDGHlnIj
U6q/h2KXF37TC5Y9tsKvQ4b8jd0Sf0dXFHml8qunSvNnqsSvoD8tSPUKqXS6jrlb
GSQXhya7BL1RPGccD5K1xrV73QlI6uFPd3APRQYij5EOB8IOWEQujJk/8Mjc0EC9
zvk5TUJb59hkOUPZ3CkvSBNLNS8wpQI98FRnIzHjuaNicqve8054oxmDKifHWy0n
nF135cXW8zkH3Zto1q89zD2g+zcVxLcRP84Uhe0nSQyg7vEYl4Wl74Eo6/89qL2y
E0mEiQN245ACA5B8WFV/t3j/OD3ydOCaAOg28vQtzcZ1gh2Ev4RxeR7bKq58g+R0
+MMwl7nnW29mbCkcgdVVR4YPmglP7Vb6w7/NbqFhnxx4E3A05AeevHdMdYCrtgQw
ogvIhdOHLcVQxJgwy1d2Lg/mv9rovhCJ7d3XaNEYym6CplCHPMtfnU1LCVkA6b44
pFaOVjsAQ8FviFtGXQAToRtwoszSarzslHKYdPoSGFOsgNJgW67iViOYqGPD97rg
JA0VPm0POMNHGw/R6o+08KhDF/OI1EDckmjXhUggY/WCqWDxD77Ezd/wr9Zlbv/u
SIEL9ifvBLq06lLcXMLrQbJrwMbDrngMZMAcUkTzThmtxNs4uwu45R+zfKcCAwEA
AQKCAgEAtu9aQ808LqYd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GmRAoCtcFvrthaWFnQlhdQMnk
iMe3oAE5n8HaRwzxfXm40p3npvSjYazz3NDF5mEfvnDwFYYLb06uCFfsd9pA1FiU
DelU4L8FphYy+5a8Yqt9P08mKKYtqaop5xURrjI/IFg0Yv2JjsK4ouPbepprXmEu
PEfB+fQ6ms1alyDDHNpyFLfS2bOUBs6aGJMgbDHQiBZiVeZhxXgsVQ+kuft67w/3
wkogkU/eGEG2HR5CkJ59yaVJp6SMK2gcTSRK40bPj0UwMzEgLbPopv2wgF0=
-----END RSA PRIVATE KEY-----
"""

# Sign Content
# Content may be is the manifest
content = {
    'hello': '123456'
}
js = jsonsign.JSONSignature.from_map(content)
rsa_private_key = rsa_key.RSAPrivateKey.from_pem(pem_data)
js.sign(rsa_private_key, timestamp=1478423072)

# Get jws
jws = js.jws()

# Parse from jws
js2 = jsonsign.JSONSignature.parse_jws(jws)
jws2 = js2.jws()

print(jws, jws2, jws == jws2)

# Verify jws
print(js.verify() == js2.verify())

Reference

About

Integrate docker/libtrust with python.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages