Skip to main content

Python interface for accessing RACF Keyrings and key databases on z/OS

Project description

Python-Zcrypto

This Python package provides API's to access Certificate Management Services (CMS). The APIs in this module can be used to create/manage your own key database files, and extract certificates stored in the key database file or RACF key ring. The helper package is installed alongside python zcrypto, and is only used to bundle together functionality.

Setup

It's best practice to install in a clean virtual environment with --system-site-packages to get access to other needed dependencies (cffi, cryptography, six, pycparser) required by pyOpenSSL.

A C compiler is required to install this package from source. See this page for supported compilers and required environment variables to use them.

# Install from PyPI
python3 -m venv venv --system-site-packages
source venv/bin/activate
pip3 install py_zcrypto
# Install from local
python3 -m venv venv --system-site-packages
source venv/bin/activate
pip3 install ./py-zcrypto

Usage

The get_keypair method shows how to get a public/private keypair using zcrypto.

import py_zcrypto
from helper import export_keypair
from py_zcrypto import zcrypto

def get_keypair(ring_name, cert_name, key_name, password, keypair_name):
    '''
    Export keypair method will export the public/private keypair
    from your RACF keyring and convert the encoding to pem.
    Parameters:
         zcrypto_object (zcrypto) : A zcrypto object
         cert_name (string) : String name for the certificate file
         key_name (String) : String name for the key file
         password (String) : String password for the keyfile
         keypair_name (String) : String name for the public/private
                                 keypair from RACF
    Returns:
         Nothing. If successful will create 4 files;
         cert and key files (pem and der encoded)
    '''
    py_zcrypto_obj = zcrypto()
    try:
        py_zcrypto_obj.open_key_ring(ring_name)
    except py_zcrypto.GSKError as e:
        print(str(e))
        return

    export_keypair(py_zcrypto_obj, cert_name, key_name, password, keypair_name, "output.pem")

    py_zcrypto_obj.close_database()
    

The get_certificate_fromRACF method shows how to export a CA certificate.

import sys
import py_zcrypto
from helper import convert_der_cert_to_pem

def get_certificate_fromRACF():
    '''
    Export a CA certificate from a RACF keyring and convert
    encoding to pem.
    Returns:
        return 0 if successful along with a der and pem encoded CA certificate.
    '''
    
    py_zcrypto_obj = py_zcrypto.zcrypto()
    try:
        py_zcrypto_obj.open_key_ring("ring_name")
    except py_zcrypto.GSKError as e:
        print(str(e))
        return

    try:
        py_zcrypto_obj.export_cert_to_file("public_key_file.der",
                                            "CACert_name")
    except py_zcrypto.GSKError as e:
        print(str(e))
        return

    convert_der_cert_to_pem("public_key_file.der")
    return

Notes

  • Error codes are Certificate Management Services (CMS) status codes in decimal format. These codes can be found in the header gskcms.h.

  • Additional details about the Certificate Management Services (CMS) API can be found here

  • Only use the pem encoded versions of certificates/public/private keys for python purposes.

Docstrings

To view a function docstring, type the method name followed by .doc

print(Pythonzcrypto.__doc__)

To view all methods available, read the package docstring:

python3 -c "import py_zcrypto; print(help(py_zcrypto))"
python3 -c "import helper; print(help(helper.helper))"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_zcrypto-1.0.2.tar.gz (11.2 kB view details)

Uploaded Source

File details

Details for the file py_zcrypto-1.0.2.tar.gz.

File metadata

  • Download URL: py_zcrypto-1.0.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for py_zcrypto-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c4f8791b63b78abb07119baef784b98ecee93f8661ff1a3ea41a365e8bdc84db
MD5 8f554a9437ade5fe5f3c9d00c592c2b6
BLAKE2b-256 a5afacc4bdabb57b87399cf5c55ecf0c62eef501dd6997c6aff275a04ad90dc8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page