Esempio n. 1
0
func (self *Context) UsePrivateKeyFile(file string, filetype int) error {
	ret := int(C.SSL_CTX_use_PrivateKey_file(self.Ctx,
		C.CString(file), C.int(filetype)))
	if ret != 1 {
		return errors.New(sslerr.SSLErrorMessage())
	}
	return nil

}
Esempio n. 2
0
// UsePrivateKeyFile adds the first private key found in file to the *Ctx, c. The
// formatting type of the certificate must be specified from the known types
// FiletypePEM, and FiletypeASN1
func (c *Ctx) UsePrivateKeyFile(key_file string, file_type Filetypes) error {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	var c_key_file *C.char
	if key_file != "" {
		c_key_file = C.CString(key_file)
		defer C.free(unsafe.Pointer(c_key_file))
	}
	if int(C.SSL_CTX_use_PrivateKey_file(c.ctx, c_key_file, C.int(file_type))) != 1 {
		return errorFromErrorQueue()
	}
	return nil
}
Esempio n. 3
0
func (c *Ctx) UsePrivateKeyFileWithPassword(key_file string, file_type Filetypes, password string) error {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	var c_key_file *C.char

	c_pwd := C.CString(password)
	defer C.free(unsafe.Pointer(c_pwd))
	C.SSL_CTX_set_default_passwd_cb_userdata(c.ctx, unsafe.Pointer(c_pwd))
	C.SSL_CTX_set_default_passwd_cb(c.ctx, (*C.pem_password_cb)(C.password_cb))

	if key_file != "" {
		c_key_file = C.CString(key_file)
		defer C.free(unsafe.Pointer(c_key_file))
	}
	if int(C.SSL_CTX_use_PrivateKey_file(c.ctx, c_key_file, C.int(file_type))) != 1 {
		return errorFromErrorQueue()
	}
	return nil
}