def normalize_certificate(rawcert): """ Incoming certificates should be DER-encoded. If not it is converted to DER-format. Note that this can't be a normalizer on a Param because only unicode variables are normalized. """ if not rawcert: return None rawcert = strip_header(rawcert) if util.isvalid_base64(rawcert): try: dercert = base64.b64decode(rawcert) except Exception as e: raise errors.Base64DecodeError(reason=str(e)) else: dercert = rawcert # At this point we should have a DER certificate. # Attempt to decode it. validate_certificate(dercert, datatype=DER) return dercert
def normalize_certificate(rawcert): """ Incoming certificates should be DER-encoded. If not it is converted to DER-format. Note that this can't be a normalizer on a Param because only unicode variables are normalized. """ if not rawcert: return None rawcert = strip_header(rawcert) if util.isvalid_base64(rawcert): try: dercert = base64.b64decode(rawcert) except Exception as e: raise errors.Base64DecodeError(reason=str(e)) else: dercert = rawcert # At this point we should have a certificate, either because the data # was base64-encoded and now its not or it came in as DER format. # Let's decode it and see. Fetching the serial number will pass the # certificate through the NSS DER parser. validate_certificate(dercert, datatype=DER) return dercert
def validate_certificate(ugettext, cert): """ For now just verify that it is properly base64-encoded. """ if cert and util.isvalid_base64(cert): try: base64.b64decode(cert) except Exception, e: raise errors.Base64DecodeError(reason=str(e))
def validate_csr(ugettext, csr): """ Ensure the CSR is base64-encoded and can be decoded by our PKCS#10 parser. """ if api.env.context == 'cli': # If we are passed in a pointer to a valid file on the client side # escape and let the load_files() handle things if csr and os.path.exists(csr): return try: request = pkcs10.load_certificate_request(csr) except TypeError, e: raise errors.Base64DecodeError(reason=str(e))
def validate_csr(ugettext, csr): """ Ensure the CSR is base64-encoded and can be decoded by our PKCS#10 parser. """ if api.env.context == 'cli': # If we are passed in a pointer to a valid file on the client side # escape and let the load_files() handle things if csr and os.path.exists(csr): return try: pkcs10.load_certificate_request(csr) except (TypeError, binascii.Error) as e: raise errors.Base64DecodeError(reason=str(e)) except Exception as e: raise errors.CertificateOperationError( error=_('Failure decoding Certificate Signing Request: %s') % e)
def normalize_certificate(rawcert): """ Incoming certificates should be DER-encoded. If not it is converted to DER-format. Note that this can't be a normalizer on a Param because only unicode variables are normalized. """ if not rawcert: return None rawcert = strip_header(rawcert) if util.isvalid_base64(rawcert): try: dercert = base64.b64decode(rawcert) except Exception, e: raise errors.Base64DecodeError(reason=str(e))