コード例 #1
0
ファイル: signing_request.py プロジェクト: viraptor/anchor
    def from_buffer(self, data, password=None):
        """Create this CSR from a buffer

        :param data: The data buffer
        :param password: decryption password, if needed
        """
        bio = backend._bytes_to_bio(data.encode('ascii'))
        ptr = self._ffi.new("X509_REQ **")
        ptr[0] = self._csrObj
        ret = self._lib.PEM_read_bio_X509_REQ(bio[0], ptr,
                                              self._ffi.NULL,
                                              self._ffi.NULL)
        if ret == self._ffi.NULL:
            raise X509CsrError("Could not read X509 CSR from PEM data.")
コード例 #2
0
    def from_buffer(self, data, password=None):
        """Create this CSR from a buffer

        :param data: The data buffer
        :param password: decryption password, if needed
        """
        if type(data) != bytes:
            data = data.encode('ascii')
        bio = backend._bytes_to_bio(data)
        ptr = self._ffi.new("X509_REQ **")
        ptr[0] = self._csrObj
        ret = self._lib.PEM_read_bio_X509_REQ(bio[0], ptr, self._ffi.NULL,
                                              self._ffi.NULL)
        if ret == self._ffi.NULL:
            raise X509CsrError("Could not read X509 CSR from PEM data.")
コード例 #3
0
ファイル: certificate.py プロジェクト: viraptor/anchor
    def from_buffer(self, data):
        """Build this X509 object from a data buffer in memory.

        :param data: A data buffer
        """
        bio = backend._bytes_to_bio(data.encode('ascii'))

        # NOTE(tkelsey): some versions of OpenSSL dont re-use the cert object
        # properly, so free it and use the new one
        #
        certObj = self._lib.PEM_read_bio_X509(bio[0],
                                              self._ffi.NULL,
                                              self._ffi.NULL,
                                              self._ffi.NULL)
        if certObj == self._ffi.NULL:
            raise X509CertificateError("Could not read X509 certificate from "
                                       "PEM data.")

        self._lib.X509_free(self._certObj)
        self._certObj = certObj
コード例 #4
0
    def from_buffer(self, data):
        """Build this X509 object from a data buffer in memory.

        :param data: A data buffer
        """
        if type(data) != bytes:
            data = data.encode('ascii')
        bio = backend._bytes_to_bio(data)

        # NOTE(tkelsey): some versions of OpenSSL dont re-use the cert object
        # properly, so free it and use the new one
        #
        certObj = self._lib.PEM_read_bio_X509(bio[0], self._ffi.NULL,
                                              self._ffi.NULL, self._ffi.NULL)
        if certObj == self._ffi.NULL:
            raise X509CertificateError("Could not read X509 certificate from "
                                       "PEM data.")

        self._lib.X509_free(self._certObj)
        self._certObj = certObj
コード例 #5
0
ファイル: utils.py プロジェクト: viraptor/anchor
def load_pem_private_key(key_data, passwd=None):
    """Load and return an OpenSSL EVP_PKEY public key object from a data buffer

    :param key_data: The data buffer
    :param passwd: Decryption password if neded (not used for now)
    :return: an OpenSSL EVP_PKEY public key object
    """
    # TODO(tkelsey): look at using backend.read_private_key
    #

    lib = backend._lib
    ffi = backend._ffi
    data = backend._bytes_to_bio(key_data)

    evp_pkey = lib.EVP_PKEY_new()
    evp_pkey_ptr = ffi.new("EVP_PKEY**")
    evp_pkey_ptr[0] = evp_pkey
    evp_pkey = lib.PEM_read_bio_PrivateKey(data[0], evp_pkey_ptr,
                                           ffi.NULL, ffi.NULL)

    evp_pkey = ffi.gc(evp_pkey, lib.EVP_PKEY_free)
    return evp_pkey
コード例 #6
0
ファイル: utils.py プロジェクト: Daviey/anchor
def load_pem_private_key(key_data, passwd=None):
    """Load and return an OpenSSL EVP_PKEY public key object from a data buffer

    :param key_data: The data buffer
    :param passwd: Decryption password if neded (not used for now)
    :return: an OpenSSL EVP_PKEY public key object
    """
    # TODO(tkelsey): look at using backend.read_private_key
    #

    if type(key_data) != bytes:
        key_data = key_data.encode('ascii')
    lib = backend._lib
    ffi = backend._ffi
    data = backend._bytes_to_bio(key_data)

    evp_pkey = lib.EVP_PKEY_new()
    evp_pkey_ptr = ffi.new("EVP_PKEY**")
    evp_pkey_ptr[0] = evp_pkey
    evp_pkey = lib.PEM_read_bio_PrivateKey(data[0], evp_pkey_ptr, ffi.NULL,
                                           ffi.NULL)

    evp_pkey = ffi.gc(evp_pkey, lib.EVP_PKEY_free)
    return evp_pkey