// ParseCertificateRequest takes an incoming certificate request and
// builds a certificate template from it.
ParseCertificateRequest takes an incoming certificate request and
builds a certificate template from it.
// ParseCertificateRequest takes an incoming certificate request and // builds a certificate template from it .
func ParseCertificateRequest(s Signer, p *config.SigningProfile, csrBytes []byte) (template *x509.Certificate, err error) {
	csrv, err := x509.ParseCertificateRequest(csrBytes)
	if err != nil {
		err = cferr.Wrap(cferr.CSRError, cferr.ParseFailed, err)
		return
	}
	var r pkix.RDNSequence
	_, err = asn1.Unmarshal(csrv.RawSubject, &r)
	if err != nil {
		err = cferr.Wrap(cferr.CSRError, cferr.ParseFailed, err)
		return
	}
	var subject pkix.Name
	subject.FillFromRDNSequence(&r)
	for _, v := range r {
		for _, vv := range v {
			if !isCommonAttr(vv.Type) {
				subject.ExtraNames = append(subject.ExtraNames, vv)
			}
		}
	}
	err = csrv.CheckSignature()
	if err != nil {
		err = cferr.Wrap(cferr.CSRError, cferr.KeyMismatch, err)
		return
	}
	template = &x509.Certificate{
		Subject:            subject,
		PublicKeyAlgorithm: csrv.PublicKeyAlgorithm,
		PublicKey:          csrv.PublicKey,
		SignatureAlgorithm: s.SigAlgo(),
		DNSNames:           csrv.DNSNames,
		IPAddresses:        csrv.IPAddresses,
		EmailAddresses:     csrv.EmailAddresses,
		URIs:               csrv.URIs,
		Extensions:         csrv.Extensions,
		ExtraExtensions:    []pkix.Extension{},
	}
	for _, val := range csrv.Extensions {
		if val.Id.Equal(asn1.ObjectIdentifier{2, 5, 29, 19}) {
			var constraints csr.BasicConstraints
			var rest []byte
			if rest, err = asn1.Unmarshal(val.Value, &constraints); err != nil {
				return nil, cferr.Wrap(cferr.CSRError, cferr.ParseFailed, err)
			} else if len(rest) != 0 {
				return nil, cferr.Wrap(cferr.CSRError, cferr.ParseFailed, errors.New("x509: trailing data after X.509 BasicConstraints"))
			}
			template.BasicConstraintsValid = true
			template.IsCA = constraints.IsCA
			template.MaxPathLen = constraints.MaxPathLen
			template.MaxPathLenZero = template.MaxPathLen == 0
		} else {
			if p.CopyExtensions {
				template.ExtraExtensions = append(template.ExtraExtensions, val)
			}
		}
	}
	return
}
func ParseCertificateRequest ( s Signer , p * config . SigningProfile , csrBytes [ ] byte ) ( template * x509 . Certificate , err error ) { csrv , err := x509 . ParseCertificateRequest ( csrBytes ) if err != nil { err = cferr . Wrap ( cferr . CSRError , cferr . ParseFailed , err ) return } var r pkix . RDNSequence _ , err = asn1 . Unmarshal ( csrv . RawSubject , & r ) if err != nil { err = cferr . Wrap ( cferr . CSRError , cferr . ParseFailed , err ) return } var subject pkix . Name subject . FillFromRDNSequence ( & r ) for _ , v := range r { for _ , vv := range v { if ! isCommonAttr ( vv . Type ) { subject . ExtraNames = append ( subject . ExtraNames , vv ) } } } err = csrv . CheckSignature ( ) if err != nil { err = cferr . Wrap ( cferr . CSRError , cferr . KeyMismatch , err ) return } template = & x509 . Certificate { Subject : subject , PublicKeyAlgorithm : csrv . PublicKeyAlgorithm , PublicKey : csrv . PublicKey , SignatureAlgorithm : s . SigAlgo ( ) , DNSNames : csrv . DNSNames , IPAddresses : csrv . IPAddresses , EmailAddresses : csrv . EmailAddresses , URIs : csrv . URIs , Extensions : csrv . Extensions , ExtraExtensions : [ ] pkix . Extension { } , } for _ , val := range csrv . Extensions { if val . Id . Equal ( asn1 . ObjectIdentifier { 2 , 5 , 29 , 19 } ) { var constraints csr . BasicConstraints var rest [ ] byte if rest , err = asn1 . Unmarshal ( val . Value , & constraints ) ; err != nil { return nil , cferr . Wrap ( cferr . CSRError , cferr . ParseFailed , err ) } else if len ( rest ) != 0 { return nil , cferr . Wrap ( cferr . CSRError , cferr . ParseFailed , errors . New ( " " ) ) } template . BasicConstraintsValid = true template . IsCA = constraints . IsCA template . MaxPathLen = constraints . MaxPathLen template . MaxPathLenZero = template . MaxPathLen == 0 } else { if p . CopyExtensions { template . ExtraExtensions = append ( template . ExtraExtensions , val ) } } } return }
ParseCertificateRequest takes an incoming certificate request and
builds a certificate template from it.
ParseCertificateRequest takes an incoming certificate request and builds a certificate template from it .
// Check the CSR for the X.509 BasicConstraints (RFC 5280, 4.2.1.9) // extension and append to template if necessary // If the profile has 'copy_extensions' to true then lets add it