示例#1
0
func (c *Certificate) GetSubjectName() (*Name, error) {
	n := C.X509_get_subject_name(c.x)
	if n == nil {
		return nil, errors.New("failed to get subject name")
	}
	return &Name{name: n}, nil
}
示例#2
0
文件: cert.go 项目: Machyne/mongo
func (c *Certificate) X509NamePrintEx() (out []byte, err error) {
	bio := C.BIO_new(C.BIO_s_mem())
	if bio == nil {
		return nil, errors.New("failed to allocate memory BIO")
	}
	defer C.BIO_free(bio)
	name := C.X509_get_subject_name(c.x)
	// TODO, pass in flags instead of using this hardcoded one
	if int(C.X509_NAME_print_ex(bio, name, 0, C.XN_FLAG_RFC2253)) < 0 {
		return nil, errors.New("failed formatting subject")
	}
	return ioutil.ReadAll(asAnyBio(bio))
}
示例#3
0
文件: x509.go 项目: runcom/gossl
func getCertificate(asn1Data []byte, x509 *C.X509) (*Certificate, error) {
	cert := &Certificate{}
	cert.x509 = x509
	// certificate raw data
	cert.Raw = asn1Data
	// certificate version (zero indexed)
	cert.Version = int(C.X509_get_version_no_macro(cert.x509)) + 1
	// certificate serial number
	cert.SerialNumber = big.NewInt(int64(C.ASN1_INTEGER_get(C.X509_get_serialNumber(cert.x509))))
	// TODO(runcom): store in pkix.Name
	// certificate subject
	cert.Subject = C.GoString(C.X509_NAME_oneline(C.X509_get_subject_name(cert.x509), nil, 0))
	// TODO(runcom): store in pkix.Name
	// certificate issuer
	cert.Issuer = C.GoString(C.X509_NAME_oneline(C.X509_get_issuer_name(cert.x509), nil, 0))
	return cert, nil
}