Ejemplo n.º 1
0
def load_cert_der_string(string):
    """
    Load certificate from a string.

    @type string: string
    @param string: String containing a certificate in DER format.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    bio = BIO.MemoryBuffer(string)
    cptr = m2.d2i_x509(bio._ptr())
    if cptr is None:
        raise X509Error(Err.get_error())
    return X509(cptr, _pyfree=1)
Ejemplo n.º 2
0
def load_cert_der_string(string):
    """
    Load certificate from a string.

    @type string: string
    @param string: String containing a certificate in DER format.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    bio = BIO.MemoryBuffer(string)
    cptr = m2.d2i_x509(bio._ptr())
    if cptr is None:
        raise X509Error(Err.get_error())
    return X509(cptr, _pyfree=1)
Ejemplo n.º 3
0
def load_cert_bio(bio, format=FORMAT_PEM):
    """
    Load certificate from a bio.

    @type bio: M2Crypto.BIO.BIO
    @param bio: BIO pointing at a certificate in either DER or PEM format.
    @type format: int, either FORMAT_PEM or FORMAT_DER
    @param format: Describes the format of the cert to be loaded, either PEM or DER.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    if format == FORMAT_PEM:
        cptr = m2.x509_read_pem(bio._ptr())
    elif format == FORMAT_DER:
        cptr = m2.d2i_x509(bio._ptr())
    else:
        raise ValueError("Unknown format. Must be either FORMAT_DER or FORMAT_PEM")
    if cptr is None:
        raise X509Error(Err.get_error())
    return X509(cptr, _pyfree=1)
Ejemplo n.º 4
0
def load_cert(file, format=FORMAT_PEM):
    """
    Load certificate from file.

    @type file: string
    @param file: Name of file containing certificate in either DER or PEM format.
    @type format: int, either FORMAT_PEM or FORMAT_DER
    @param format: Describes the format of the file to be loaded, either PEM or DER.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    bio = BIO.openfile(file)
    if format == FORMAT_PEM:
        return load_cert_bio(bio)
    elif format == FORMAT_DER:
        cptr = m2.d2i_x509(bio._ptr())
        if cptr is None:
            raise X509Error(Err.get_error())
        return X509(cptr, _pyfree=1)
    else:
        raise ValueError("Unknown format. Must be either FORMAT_DER or FORMAT_PEM")
Ejemplo n.º 5
0
def load_cert_bio(bio, format=FORMAT_PEM):
    """
    Load certificate from a bio.

    @type bio: M2Crypto.BIO.BIO
    @param bio: BIO pointing at a certificate in either DER or PEM format.
    @type format: int, either FORMAT_PEM or FORMAT_DER
    @param format: Describes the format of the cert to be loaded, either PEM or DER.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    if format == FORMAT_PEM:
        cptr = m2.x509_read_pem(bio._ptr())
    elif format == FORMAT_DER:
        cptr = m2.d2i_x509(bio._ptr())
    else:
        raise ValueError(
            "Unknown format. Must be either FORMAT_DER or FORMAT_PEM")
    if cptr is None:
        raise X509Error(Err.get_error())
    return X509(cptr, _pyfree=1)
Ejemplo n.º 6
0
def load_cert(file, format=FORMAT_PEM):
    """
    Load certificate from file.

    @type file: string
    @param file: Name of file containing certificate in either DER or PEM format.
    @type format: int, either FORMAT_PEM or FORMAT_DER
    @param format: Describes the format of the file to be loaded, either PEM or DER.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    bio = BIO.openfile(file)
    if format == FORMAT_PEM:
        return load_cert_bio(bio)
    elif format == FORMAT_DER:
        cptr = m2.d2i_x509(bio._ptr())
        if cptr is None:
            raise X509Error(Err.get_error())
        return X509(cptr, _pyfree=1)
    else:
        raise ValueError(
            "Unknown format. Must be either FORMAT_DER or FORMAT_PEM")