Giter Site home page Giter Site logo

pykmssig's Introduction

pykmssig

A python library inspired by https://github.com/codahale/kmssig

Why pykmssig?

Sometimes you need to validate a message passing multiple AWS accounts and services has not been tampered with in transit.

Let's say we have three AWS accounts Account A, Account B, and Account C.

Account A wants to publish messages to a Kinesis stream in Account B. Account B runs the Kinesis stream and some light data validation but does not modify the data.

Account C is a high security account and only allows Account B put access to a single dynamo table. In the event account B is compromised how does account C guarantee the integrity of the messages in transit?

Answer : pykmssig

pykmssig allows the owners of Account A to sign and encrypt a signature against a KMS key let's call it kms-key-alpha in order to do this kms-key-alpha needs to allow Account owner A the ability to encrypt messages. This encrypts the signature data. A second key kms-key-beta can be used to provide data at rest protection. Account A, B, and C can all be allowed decrypt for kms-key-beta but only Account C should be allowed to decrypt using kms-key-alpha to verify the message was not tampered with in transit.

Installing

git clone https://github.com/andrewkrug/pykmssig
pip install -r requirements.txt
python setup.py install

Setting up your environment

This looks for the environment variable SIGNING_KEY_ALIAS this should be a precreated alias for the KMS key you'd like to use to sign. If you've used the provided cloudformation stack template you need not change this.

Usage

# Signing a payload
from pykmssig import crypto

o = crypto.Operation()

result = o.sign(plaintext={'foo': 'bar'})

# The result of this operation will be ciphertext.

Verifying the payload:

# Verification

from pykmssig import crypto

o = crypto.Operation()

result = o.verify(
    ciphertext=ciphertext,
    plaintext={'foo': 'bar'}
)

"""Result returns a dictionary that looks as follows.""""
{
    'status': 'valid',
    'sig_b': b'U05jVK2Ewp286h3Ksr6Cc2GWMQT+9dG3Pxt0Wb5VEoPWGzTPfcNWxGFb5LHa9zyDs4rqUDc7kgzbXPKrRXCgmQ==',
    'sig_a': b'U05jVK2Ewp286h3Ksr6Cc2GWMQT+9dG3Pxt0Wb5VEoPWGzTPfcNWxGFb5LHa9zyDs4rqUDc7kgzbXPKrRXCgmQ=='
}

pykmssig's People

Contributors

andrewkrug avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.