Beispiel #1
0
// Get the last OpenSSL error and convert it to a human-readable string
func getErrString() string {
	e := C.ERR_get_error()

	buf := [120]byte{} // max length specified in OpenSSL doc
	bufp := (*_Ctype_char)(unsafe.Pointer(&buf[0]))
	C.ERR_error_string_n(e, bufp, C.size_t(len(buf)))

	return string(buf[:C.strlen(bufp)])
}
Beispiel #2
0
func lastError() string {
	buf := C.malloc(1024)
	e := C.ERR_get_error() // a C.ulong
	C.ERR_load_crypto_strings()
	defer C.ERR_free_strings()
	C.ERR_error_string_n(e, (*C.char)(buf), 1024)
	defer C.free(buf)
	return C.GoString((*C.char)(buf))
}
Beispiel #3
0
func get_error() string {
	packed_error := C.ERR_get_error()
	str_buf := make([]byte, C.ERR_ERROR_STRING_BUF_LEN)
	C.ERR_error_string_n(packed_error, (*C.char)(unsafe.Pointer(&str_buf[0])), C.ERR_ERROR_STRING_BUF_LEN)
	n := bytes.IndexByte(str_buf, 0)
	if n > 0 {
		return string(str_buf[:n])
	} else {
		return fmt.Sprintf("error:%x", packed_error)
	}
}
Beispiel #4
0
func SSLErrorMessage() SSLError {
	msg := ""
	for {
		errCode := C.ERR_get_error()
		if errCode == 0 {
			break
		}
		msg += getErrorString(errCode)
	}
	C.ERR_clear_error()
	return SSLError{msg: msg}
}
Beispiel #5
0
// errorFromErrorQueue needs to run in the same OS thread as the operation
// that caused the possible error
func errorFromErrorQueue() error {
	var errs []string
	for {
		err := C.ERR_get_error()
		if err == 0 {
			break
		}
		errs = append(errs, fmt.Sprintf("%s:%s:%s",
			C.GoString(C.ERR_lib_error_string(err)),
			C.GoString(C.ERR_func_error_string(err)),
			C.GoString(C.ERR_reason_error_string(err))))
	}
	return errors.New(fmt.Sprintf("SSL errors: %s", strings.Join(errs, "\n")))
}