'Verifies if a certificate is valid and signed by a given certificate.
:param signing_cert_str: This certificate will be used to verify the
signature. Must be a string representation
of the certificate. If you only have a file
use the method read_str_from_file to
get a string representation.
:param cert_str:         This certificate will be verified if it is
correct. Must be a string representation
of the certificate. If you only have a file
use the method read_str_from_file to
get a string representation.
:return:                 Valid, Message
Valid = True if the certificate is valid,
otherwise false.
Message = Why the validation failed.'

def verify(self, signing_cert_str, cert_str):

    try:
        ca_cert = crypto.load_certificate(crypto.FILETYPE_PEM, signing_cert_str)
        cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_str)
        if self.certificate_not_valid_yet(ca_cert):
            return (False, 'CA    certificate    is    not    valid    yet.')
        if (ca_cert.has_expired() == 1):
            return (False, 'CA    certificate    is    expired.')
        if (cert.has_expired() == 1):
            return (False, 'The    signed    certificate    is    expired.')
        if self.certificate_not_valid_yet(cert):
            return (False, 'The    signed    certificate    is    not    valid    yet.')
        if (ca_cert.get_subject().CN == cert.get_subject().CN):
            return (False, 'CN    may    not    be    equal    for    CA    certificate    and    the    signed    certificate.')
        cert_algorithm = cert.get_signature_algorithm()
        cert_asn1 = crypto.dump_certificate(crypto.FILETYPE_ASN1, cert)
        der_seq = asn1.DerSequence()
        der_seq.decode(cert_asn1)
        cert_certificate = der_seq[0]
        cert_signature = der_seq[2]
        cert_signature_decoded = asn1.DerObject()
        cert_signature_decoded.decode(cert_signature)
        signature_payload = cert_signature_decoded.payload
        if (signature_payload[0] != '\x00'):
            return (False, 'The    certificate    should    not    contain    any    unused    bits.')
        signature = signature_payload[1:]
        try:
            crypto.verify(ca_cert, signature, cert_certificate, cert_algorithm)
            return (True, 'Signed    certificate    is    valid    and    correctly    signed    by    CA    certificate.')
        except crypto.Error as e:
            return (False, 'Certificate    is    incorrectly    signed.')
    except Exception as e:
        return (False, 'Certificate    is    not    valid    for    an    unknown    reason.')
