Exemple #1
0
// GetSerialNumberHex returns the certificate's serial number in hex format
func (c *Certificate) GetSerialNumberHex() (serial string) {
	asn1_i := C.X509_get_serialNumber(c.x)
	bignum := C.ASN1_INTEGER_to_BN(asn1_i, nil)
	hex := C.BN_bn2hex(bignum)
	serial = C.GoString(hex)
	C.BN_free(bignum)
	C.OPENSSL_free_not_a_macro(unsafe.Pointer(hex))
	return
}
Exemple #2
0
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
}
Exemple #3
0
// SetSerial sets the serial of a certificate.
func (c *Certificate) SetSerial(serial int) error {
	if C.ASN1_INTEGER_set(C.X509_get_serialNumber(c.x), C.long(serial)) != 1 {
		return errors.New("failed to set serial")
	}
	return nil
}