Esempio n. 1
0
    def __init__(self, root_dir, cert_globals, fqdn):
        ca_globals = {}
        ca_globals['verbose'] = cert_globals['verbose']

        self.ca = CA(root_dir, ca_globals, True)

        if not root_dir:
            if os.path.isdir(os.path.abspath(self.default_root_dir)):
                root_dir = os.path.abspath(self.default_root_dir)
            else:
                try:
                    self.ca.CheckForPopulatedCAdirectory()

                    root_dir = self.ca.getIntermediateDirectory()
                except FileNotFoundError as e:
                    root_dir = Certificate.default_root_dir

        for key, value in self.subdirs.items():
            value['path'] = "{}/{}".format(root_dir, value['path'])

        Path(self.getPrivatePath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCertsPath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCSRPath()).mkdir(parents=True, exist_ok=True)

        self.fqdn = fqdn
Esempio n. 2
0
def ca_create_root_certificate():
    """
      Create the root certificate for the CA.
    """
    try:
        ca = CA(rootDir, ca_globals)
        ca.createRootCertificate()
    except FileNotFoundError as e:
        print(e)
Esempio n. 3
0
def create_intermediate_certificate():
    """
      Create a signed intermediate crtificate.
    """
    try:
        ca = CA(rootDir, ca_globals)
        ca.createIntermediateCertificate()
    except FileNotFoundError as e:
        print(e)
Esempio n. 4
0
def create_intermediate_certificate():
    """
      Create a signed intermediate crtificate.
    """
    try:
        ca = CA(rootDir, ca_globals)
        ca.createIntermediateCertificate()
    except FileNotFoundError as e:
        print(e)
Esempio n. 5
0
def ca_create_intermediate_key():
    """
      Create a private key for the usage of the CA.
    """
    try:
        ca = CA(rootDir, ca_globals)
        ca.createIntermediateKey()
    except FileExistsError as e:
        print(e)
Esempio n. 6
0
def ca_create_intermediate_key():
    """
      Create a private key for the usage of the CA.
    """
    try:
        ca = CA(rootDir, ca_globals)
        ca.createIntermediateKey()
    except FileExistsError as e:
        print(e)
Esempio n. 7
0
def ca_create_root_certificate():
    """
      Create the root certificate for the CA.
    """
    try:
        ca = CA(rootDir, ca_globals)
        ca.createRootCertificate()
    except FileNotFoundError as e:
        print(e)
Esempio n. 8
0
def ca_init(serial_number, root_config_file, intermediate_config_file):
    """
      Create a root directory if it does not exist and populate it. The
      init command requires one parameter:\n

      Args:\n
          CONFIG_FILE: path to the the configuration file of the root CA.
    """
    try:
        ca = CA(rootDir, ca_globals, missing_ca_dir_okay=True)
        ca.init(root_config_file, intermediate_config_file, serial_number)
    except FileNotFoundError as e:
        print (e)
Esempio n. 9
0
def ca_init(serial_number, root_config_file, intermediate_config_file):
    """
      Create a root directory if it does not exist and populate it. The
      init command requires one parameter:\n

      Args:\n
          CONFIG_FILE: path to the the configuration file of the root CA.
    """
    try:
        ca = CA(rootDir, ca_globals, missing_ca_dir_okay=True)
        ca.init(root_config_file, intermediate_config_file, serial_number)
    except FileNotFoundError as e:
        print(e)
Esempio n. 10
0
    def __init__(self, root_dir, cert_globals, fqdn):
        ca_globals = {}
        ca_globals['verbose'] = cert_globals['verbose']

        self.ca = CA(root_dir, ca_globals, True)

        if not root_dir:
            if os.path.isdir(os.path.abspath(self.default_root_dir)):
                root_dir = os.path.abspath(self.default_root_dir)
            else:
                try:
                    self.ca.CheckForPopulatedCAdirectory()

                    root_dir = self.ca.getIntermediateDirectory()
                except FileNotFoundError as e:
                    root_dir = Certificate.default_root_dir

        for key, value in self.subdirs.items():
            value['path'] = "{}/{}".format(root_dir, value['path'])

        Path(self.getPrivatePath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCertsPath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCSRPath()).mkdir(parents=True, exist_ok=True)

        self.fqdn = fqdn
Esempio n. 11
0
def sign_csr(fqdn):
    try:
        ca = CA(rootDir, ca_globals, fqdn)

        config = ca.getIntermediateConfigName()
        csr = ca.getCSRName()
        certificate = ca.getCertificateName()

        ca.signCSR(config, csr, certificate)
    except FileNotFoundError as e:
        print(e)
Esempio n. 12
0
def sign_csr(fqdn):
    try:
        ca = CA(rootDir, ca_globals, fqdn)

        config      = ca.getIntermediateConfigName()
        csr         = ca.getCSRName()
        certificate = ca.getCertificateName()

        ca.signCSR(config, csr, certificate)
    except FileNotFoundError as e:
        print(e)
Esempio n. 13
0
class Certificate:
    default_root_dir = os.path.abspath("client-certificates")

    subdirs = {
        'private': {
            'path': "/private",
            'mode': 0o700
        },
        'certificates': {
            'path': "/certs",
            'mode': 0o755
        },
        'csr': {
            'path': "/csr",
            'mode': 0o755
        },
        'config': {
            'path': "/config",
            'mode': 0o755
        }
    }

    fqdn = None

    def __init__(self, root_dir, cert_globals, fqdn):
        ca_globals = {}
        ca_globals['verbose'] = cert_globals['verbose']

        self.ca = CA(root_dir, ca_globals, True)

        if not root_dir:
            if os.path.isdir(os.path.abspath(self.default_root_dir)):
                root_dir = os.path.abspath(self.default_root_dir)
            else:
                try:
                    self.ca.CheckForPopulatedCAdirectory()

                    root_dir = self.ca.getIntermediateDirectory()
                except FileNotFoundError as e:
                    root_dir = Certificate.default_root_dir

        for key, value in self.subdirs.items():
            value['path'] = "{}/{}".format(root_dir, value['path'])

        Path(self.getPrivatePath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCertsPath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCSRPath()).mkdir(parents=True, exist_ok=True)

        self.fqdn = fqdn

    def getPrivatePath(self):
        return self.subdirs['private']['path']

    def getCertsPath(self):
        return self.subdirs['certificates']['path']

    def getCSRPath(self):
        return self.subdirs['csr']['path']

    def getConfigName(self):
        """
          return the config name
        """
        return "{}/{}.config".format(self.subdirs['config']['path'], self.fqdn)

    def getKeyName(self):
        """
          return the key name
        """
        return "{}/{}.key".format(self.subdirs['private']['path'], self.fqdn)

    def getCSRName(self):
        """
          return the csr name
        """
        return "{}/{}.csr".format(self.subdirs['csr']['path'], self.fqdn)

    def createKey(self, key, keyLength, usePassPhrase):
        self.ca.createKey(key, keyLength, usePassPhrase)

    def createCSR(self, config, key, csr):
        self.ca.createCSR(config, key, csr)
Esempio n. 14
0
def create_domain_key(fqdn):
    try:
        ca = CA(rootDir, ca_globals)
        ca.createDomainKey(fqdn)
    except FileNotFoundError as e:
        print(e)
Esempio n. 15
0
def create_domain_key(fqdn):
    try:
        ca = CA(rootDir, ca_globals)
        ca.createDomainKey(fqdn)
    except FileNotFoundError as e:
        print(e)
Esempio n. 16
0
class Certificate:
    default_root_dir = os.path.abspath("client-certificates")

    subdirs = {
        'private':      { 'path': "/private", 'mode': 0o700 },
        'certificates': { 'path': "/certs",   'mode': 0o755 },
        'csr':          { 'path': "/csr",     'mode': 0o755 },
        'config':       { 'path': "/config",  'mode': 0o755 }
    }

    fqdn = None

    def __init__(self, root_dir, cert_globals, fqdn):
        ca_globals = {}
        ca_globals['verbose'] = cert_globals['verbose']

        self.ca = CA(root_dir, ca_globals, True)

        if not root_dir:
            if os.path.isdir(os.path.abspath(self.default_root_dir)):
                root_dir = os.path.abspath(self.default_root_dir)
            else:
                try:
                    self.ca.CheckForPopulatedCAdirectory()

                    root_dir = self.ca.getIntermediateDirectory()
                except FileNotFoundError as e:
                    root_dir = Certificate.default_root_dir

        for key, value in self.subdirs.items():
            value['path'] = "{}/{}".format(root_dir, value['path'])

        Path(self.getPrivatePath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCertsPath()).mkdir(parents=True, exist_ok=True)
        Path(self.getCSRPath()).mkdir(parents=True, exist_ok=True)

        self.fqdn = fqdn


    def getPrivatePath(self):
        return  self.subdirs['private']['path']


    def getCertsPath(self):
        return self.subdirs['certificates']['path']


    def getCSRPath(self):
        return self.subdirs['csr']['path']


    def getConfigName(self):
        """
          return the config name
        """
        return "{}/{}.config".format(self.subdirs['config']['path'], self.fqdn)


    def getKeyName(self):
        """
          return the key name
        """
        return "{}/{}.key".format(self.subdirs['private']['path'], self.fqdn)


    def getCSRName(self):
        """
          return the csr name
        """
        return "{}/{}.csr".format(self.subdirs['csr']['path'], self.fqdn)


    def createKey(self, key, keyLength, usePassPhrase):
        self.ca.createKey(key, keyLength, usePassPhrase)


    def createCSR(self, config, key, csr):
        self.ca.createCSR(config, key, csr)