Skip to content
Merged
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: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ install:
- docker build -t $TRAVIS_BUILD_NUMBER $TRAVIS_BUILD_DIR/

script:
- docker run -d -p 8069:8069 --name openssl-exec-$TRAVIS_BUILD_NUMBER -t $TRAVIS_BUILD_NUMBER
- sleep 10
- curl --fail http://localhost:8080/
- docker run -t $TRAVIS_BUILD_NUMBER openssl version
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM laslabs/clouder-python-exec:latest
MAINTAINER Dave Lasley <[email protected]>

RUN apk add --no-cache libffi-dev \
openssl \
openssl-dev \
python3-dev

RUN pip install cryptography

RUN apk del build-base \
libffi-dev \
openssl-dev \
python3-dev

COPY ./bin/* /usr/bin/
COPY ./docker-entrypoint.sh /

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["openssl"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pleasure:
Known Issues / Roadmap
======================

*
* Add a test for `parse_cfssl`

Bug Tracker
===========
Expand Down
62 changes: 62 additions & 0 deletions bin/parse_cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from __future__ import print_function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own edification, apart from 3.x compat, what's the value add of importing the 3.x print function?

Copy link
Member Author

@lasley lasley Jan 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2/3.x compat


import argparse
import pickle

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives import hashes
from cryptography import x509


def parse_cert(self, cert):
""" It parses a PEM encoded certificate and returns the attrs. """
cert = x509.load_pem_x509_certificate(
cert,
default_backend(),
)
enc_pem = Encoding('PEM')
extensions = {}
for extension in cert.extensions:
public_props = (
n for n in dir(extension.value) if not n.startswith('_')
)
extensions[extension.oid._name] = {
'oid': extension.oid.dotted_string,
}
for prop in public_props:
if prop == 'oid':
continue
try:
value = getattr(extension.value, prop)
except ValueError:
continue
if callable(value):
continue
extensions[extension.oid._name][prop] = value
return {
'serial': cert.serial,
'fingerprint': cert.fingerprint(hashes.SHA256()),
'public_key': cert.public_bytes(enc_pem),
'not_valid_before': cert.not_valid_before,
'not_valid_after': cert.not_valid_after,
'extensions': extensions,
}


if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Cert Parse CLI')
parser.add_argument('cert',
help='PEM encoded certificate string to parse',
)
args = parser.parse_args()
cert_info = parse_cert(args.cert)
print(
pickle.dumps(cert_info.encode('base64')),
)
15 changes: 15 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/ash
# Copyright 2016 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

set -e

# Add openssl as command if needed
if [ "${1:0:1}" = '-' ]; then
set -- openssl "$@"
fi

# As argument is not related to openssl,
# then assume that user wants to run their own process,
# for example a `bash` shell to explore this image
exec "$@"