1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16// Virtual method table for a #GDtlsConnection implementation.
17type DtlsConnectionInterface struct {
18 _ structs.HostLayout
19
20 GIface uintptr
21
22 xAcceptCertificate uintptr
23
24 xHandshake uintptr
25
26 xHandshakeAsync uintptr
27
28 xHandshakeFinish uintptr
29
30 xShutdown uintptr
31
32 xShutdownAsync uintptr
33
34 xShutdownFinish uintptr
35
36 xSetAdvertisedProtocols uintptr
37
38 xGetNegotiatedProtocol uintptr
39
40 xGetBindingData uintptr
41}
42
43func (x *DtlsConnectionInterface) GoPointer() uintptr {
44 return uintptr(unsafe.Pointer(x))
45}
46
47// OverrideAcceptCertificate sets the "accept_certificate" callback function.
48// Check whether to accept a certificate.
49func (x *DtlsConnectionInterface) OverrideAcceptCertificate(cb func(DtlsConnection, *TlsCertificate, TlsCertificateFlags) bool) {
50 if cb == nil {
51 x.xAcceptCertificate = 0
52 } else {
53 x.xAcceptCertificate = purego.NewCallback(func(ConnectionVarp uintptr, PeerCertVarp uintptr, ErrorsVarp TlsCertificateFlags) bool {
54 return cb(&DtlsConnectionBase{Ptr: ConnectionVarp}, TlsCertificateNewFromInternalPtr(PeerCertVarp), ErrorsVarp)
55 })
56 }
57}
58
59// GetAcceptCertificate gets the "accept_certificate" callback function.
60// Check whether to accept a certificate.
61func (x *DtlsConnectionInterface) GetAcceptCertificate() func(DtlsConnection, *TlsCertificate, TlsCertificateFlags) bool {
62 if x.xAcceptCertificate == 0 {
63 return nil
64 }
65 var rawCallback func(ConnectionVarp uintptr, PeerCertVarp uintptr, ErrorsVarp TlsCertificateFlags) bool
66 purego.RegisterFunc(&rawCallback, x.xAcceptCertificate)
67 return func(ConnectionVar DtlsConnection, PeerCertVar *TlsCertificate, ErrorsVar TlsCertificateFlags) bool {
68 return rawCallback(ConnectionVar.GoPointer(), PeerCertVar.GoPointer(), ErrorsVar)
69 }
70}
71
72// OverrideHandshake sets the "handshake" callback function.
73// Perform a handshake operation.
74func (x *DtlsConnectionInterface) OverrideHandshake(cb func(DtlsConnection, *Cancellable) bool) {
75 if cb == nil {
76 x.xHandshake = 0
77 } else {
78 x.xHandshake = purego.NewCallback(func(ConnVarp uintptr, CancellableVarp uintptr) bool {
79 return cb(&DtlsConnectionBase{Ptr: ConnVarp}, CancellableNewFromInternalPtr(CancellableVarp))
80 })
81 }
82}
83
84// GetHandshake gets the "handshake" callback function.
85// Perform a handshake operation.
86func (x *DtlsConnectionInterface) GetHandshake() func(DtlsConnection, *Cancellable) bool {
87 if x.xHandshake == 0 {
88 return nil
89 }
90 var rawCallback func(ConnVarp uintptr, CancellableVarp uintptr) bool
91 purego.RegisterFunc(&rawCallback, x.xHandshake)
92 return func(ConnVar DtlsConnection, CancellableVar *Cancellable) bool {
93 return rawCallback(ConnVar.GoPointer(), CancellableVar.GoPointer())
94 }
95}
96
97// OverrideHandshakeAsync sets the "handshake_async" callback function.
98// Start an asynchronous handshake operation.
99func (x *DtlsConnectionInterface) OverrideHandshakeAsync(cb func(DtlsConnection, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
100 if cb == nil {
101 x.xHandshakeAsync = 0
102 } else {
103 x.xHandshakeAsync = purego.NewCallback(func(ConnVarp uintptr, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
104 cb(&DtlsConnectionBase{Ptr: ConnVarp}, IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
105 })
106 }
107}
108
109// GetHandshakeAsync gets the "handshake_async" callback function.
110// Start an asynchronous handshake operation.
111func (x *DtlsConnectionInterface) GetHandshakeAsync() func(DtlsConnection, int, *Cancellable, *AsyncReadyCallback, uintptr) {
112 if x.xHandshakeAsync == 0 {
113 return nil
114 }
115 var rawCallback func(ConnVarp uintptr, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
116 purego.RegisterFunc(&rawCallback, x.xHandshakeAsync)
117 return func(ConnVar DtlsConnection, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
118 rawCallback(ConnVar.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
119 }
120}
121
122// OverrideHandshakeFinish sets the "handshake_finish" callback function.
123// Finish an asynchronous handshake operation.
124func (x *DtlsConnectionInterface) OverrideHandshakeFinish(cb func(DtlsConnection, AsyncResult) bool) {
125 if cb == nil {
126 x.xHandshakeFinish = 0
127 } else {
128 x.xHandshakeFinish = purego.NewCallback(func(ConnVarp uintptr, ResultVarp uintptr) bool {
129 return cb(&DtlsConnectionBase{Ptr: ConnVarp}, &AsyncResultBase{Ptr: ResultVarp})
130 })
131 }
132}
133
134// GetHandshakeFinish gets the "handshake_finish" callback function.
135// Finish an asynchronous handshake operation.
136func (x *DtlsConnectionInterface) GetHandshakeFinish() func(DtlsConnection, AsyncResult) bool {
137 if x.xHandshakeFinish == 0 {
138 return nil
139 }
140 var rawCallback func(ConnVarp uintptr, ResultVarp uintptr) bool
141 purego.RegisterFunc(&rawCallback, x.xHandshakeFinish)
142 return func(ConnVar DtlsConnection, ResultVar AsyncResult) bool {
143 return rawCallback(ConnVar.GoPointer(), ResultVar.GoPointer())
144 }
145}
146
147// OverrideShutdown sets the "shutdown" callback function.
148// Shut down one or both directions of the connection.
149func (x *DtlsConnectionInterface) OverrideShutdown(cb func(DtlsConnection, bool, bool, *Cancellable) bool) {
150 if cb == nil {
151 x.xShutdown = 0
152 } else {
153 x.xShutdown = purego.NewCallback(func(ConnVarp uintptr, ShutdownReadVarp bool, ShutdownWriteVarp bool, CancellableVarp uintptr) bool {
154 return cb(&DtlsConnectionBase{Ptr: ConnVarp}, ShutdownReadVarp, ShutdownWriteVarp, CancellableNewFromInternalPtr(CancellableVarp))
155 })
156 }
157}
158
159// GetShutdown gets the "shutdown" callback function.
160// Shut down one or both directions of the connection.
161func (x *DtlsConnectionInterface) GetShutdown() func(DtlsConnection, bool, bool, *Cancellable) bool {
162 if x.xShutdown == 0 {
163 return nil
164 }
165 var rawCallback func(ConnVarp uintptr, ShutdownReadVarp bool, ShutdownWriteVarp bool, CancellableVarp uintptr) bool
166 purego.RegisterFunc(&rawCallback, x.xShutdown)
167 return func(ConnVar DtlsConnection, ShutdownReadVar bool, ShutdownWriteVar bool, CancellableVar *Cancellable) bool {
168 return rawCallback(ConnVar.GoPointer(), ShutdownReadVar, ShutdownWriteVar, CancellableVar.GoPointer())
169 }
170}
171
172// OverrideShutdownAsync sets the "shutdown_async" callback function.
173// Start an asynchronous shutdown operation.
174func (x *DtlsConnectionInterface) OverrideShutdownAsync(cb func(DtlsConnection, bool, bool, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
175 if cb == nil {
176 x.xShutdownAsync = 0
177 } else {
178 x.xShutdownAsync = purego.NewCallback(func(ConnVarp uintptr, ShutdownReadVarp bool, ShutdownWriteVarp bool, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
179 cb(&DtlsConnectionBase{Ptr: ConnVarp}, ShutdownReadVarp, ShutdownWriteVarp, IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
180 })
181 }
182}
183
184// GetShutdownAsync gets the "shutdown_async" callback function.
185// Start an asynchronous shutdown operation.
186func (x *DtlsConnectionInterface) GetShutdownAsync() func(DtlsConnection, bool, bool, int, *Cancellable, *AsyncReadyCallback, uintptr) {
187 if x.xShutdownAsync == 0 {
188 return nil
189 }
190 var rawCallback func(ConnVarp uintptr, ShutdownReadVarp bool, ShutdownWriteVarp bool, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
191 purego.RegisterFunc(&rawCallback, x.xShutdownAsync)
192 return func(ConnVar DtlsConnection, ShutdownReadVar bool, ShutdownWriteVar bool, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
193 rawCallback(ConnVar.GoPointer(), ShutdownReadVar, ShutdownWriteVar, IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
194 }
195}
196
197// OverrideShutdownFinish sets the "shutdown_finish" callback function.
198// Finish an asynchronous shutdown operation.
199func (x *DtlsConnectionInterface) OverrideShutdownFinish(cb func(DtlsConnection, AsyncResult) bool) {
200 if cb == nil {
201 x.xShutdownFinish = 0
202 } else {
203 x.xShutdownFinish = purego.NewCallback(func(ConnVarp uintptr, ResultVarp uintptr) bool {
204 return cb(&DtlsConnectionBase{Ptr: ConnVarp}, &AsyncResultBase{Ptr: ResultVarp})
205 })
206 }
207}
208
209// GetShutdownFinish gets the "shutdown_finish" callback function.
210// Finish an asynchronous shutdown operation.
211func (x *DtlsConnectionInterface) GetShutdownFinish() func(DtlsConnection, AsyncResult) bool {
212 if x.xShutdownFinish == 0 {
213 return nil
214 }
215 var rawCallback func(ConnVarp uintptr, ResultVarp uintptr) bool
216 purego.RegisterFunc(&rawCallback, x.xShutdownFinish)
217 return func(ConnVar DtlsConnection, ResultVar AsyncResult) bool {
218 return rawCallback(ConnVar.GoPointer(), ResultVar.GoPointer())
219 }
220}
221
222// OverrideSetAdvertisedProtocols sets the "set_advertised_protocols" callback function.
223// Set APLN protocol list (Since: 2.60)
224func (x *DtlsConnectionInterface) OverrideSetAdvertisedProtocols(cb func(DtlsConnection, []string)) {
225 if cb == nil {
226 x.xSetAdvertisedProtocols = 0
227 } else {
228 x.xSetAdvertisedProtocols = purego.NewCallback(func(ConnVarp uintptr, ProtocolsVarp []string) {
229 cb(&DtlsConnectionBase{Ptr: ConnVarp}, ProtocolsVarp)
230 })
231 }
232}
233
234// GetSetAdvertisedProtocols gets the "set_advertised_protocols" callback function.
235// Set APLN protocol list (Since: 2.60)
236func (x *DtlsConnectionInterface) GetSetAdvertisedProtocols() func(DtlsConnection, []string) {
237 if x.xSetAdvertisedProtocols == 0 {
238 return nil
239 }
240 var rawCallback func(ConnVarp uintptr, ProtocolsVarp []string)
241 purego.RegisterFunc(&rawCallback, x.xSetAdvertisedProtocols)
242 return func(ConnVar DtlsConnection, ProtocolsVar []string) {
243 rawCallback(ConnVar.GoPointer(), ProtocolsVar)
244 }
245}
246
247// OverrideGetNegotiatedProtocol sets the "get_negotiated_protocol" callback function.
248// Get ALPN-negotiated protocol (Since: 2.60)
249func (x *DtlsConnectionInterface) OverrideGetNegotiatedProtocol(cb func(DtlsConnection) string) {
250 if cb == nil {
251 x.xGetNegotiatedProtocol = 0
252 } else {
253 x.xGetNegotiatedProtocol = purego.NewCallback(func(ConnVarp uintptr) string {
254 return cb(&DtlsConnectionBase{Ptr: ConnVarp})
255 })
256 }
257}
258
259// GetGetNegotiatedProtocol gets the "get_negotiated_protocol" callback function.
260// Get ALPN-negotiated protocol (Since: 2.60)
261func (x *DtlsConnectionInterface) GetGetNegotiatedProtocol() func(DtlsConnection) string {
262 if x.xGetNegotiatedProtocol == 0 {
263 return nil
264 }
265 var rawCallback func(ConnVarp uintptr) string
266 purego.RegisterFunc(&rawCallback, x.xGetNegotiatedProtocol)
267 return func(ConnVar DtlsConnection) string {
268 return rawCallback(ConnVar.GoPointer())
269 }
270}
271
272// OverrideGetBindingData sets the "get_binding_data" callback function.
273// Retrieve TLS channel binding data (Since: 2.66)
274func (x *DtlsConnectionInterface) OverrideGetBindingData(cb func(DtlsConnection, TlsChannelBindingType, []byte) bool) {
275 if cb == nil {
276 x.xGetBindingData = 0
277 } else {
278 x.xGetBindingData = purego.NewCallback(func(ConnVarp uintptr, TypeVarp TlsChannelBindingType, DataVarp []byte) bool {
279 return cb(&DtlsConnectionBase{Ptr: ConnVarp}, TypeVarp, DataVarp)
280 })
281 }
282}
283
284// GetGetBindingData gets the "get_binding_data" callback function.
285// Retrieve TLS channel binding data (Since: 2.66)
286func (x *DtlsConnectionInterface) GetGetBindingData() func(DtlsConnection, TlsChannelBindingType, []byte) bool {
287 if x.xGetBindingData == 0 {
288 return nil
289 }
290 var rawCallback func(ConnVarp uintptr, TypeVarp TlsChannelBindingType, DataVarp []byte) bool
291 purego.RegisterFunc(&rawCallback, x.xGetBindingData)
292 return func(ConnVar DtlsConnection, TypeVar TlsChannelBindingType, DataVar []byte) bool {
293 return rawCallback(ConnVar.GoPointer(), TypeVar, DataVar)
294 }
295}
296
297// `GDtlsConnection` is the base DTLS connection class type, which wraps
298// a [iface@Gio.DatagramBased] and provides DTLS encryption on top of it. Its
299// subclasses, [iface@Gio.DtlsClientConnection] and
300// [iface@Gio.DtlsServerConnection], implement client-side and server-side DTLS,
301// respectively.
302//
303// For TLS support, see [class@Gio.TlsConnection].
304//
305// As DTLS is datagram based, `GDtlsConnection` implements
306// [iface@Gio.DatagramBased], presenting a datagram-socket-like API for the
307// encrypted connection. This operates over a base datagram connection, which is
308// also a `GDatagramBased` ([property@Gio.DtlsConnection:base-socket]).
309//
310// To close a DTLS connection, use [method@Gio.DtlsConnection.close].
311//
312// Neither [iface@Gio.DtlsServerConnection] or [iface@Gio.DtlsClientConnection]
313// set the peer address on their base [iface@Gio.DatagramBased] if it is a
314// [class@Gio.Socket] — it is up to the caller to do that if they wish. If they
315// do not, and [method@Gio.Socket.close] is called on the base socket, the
316// `GDtlsConnection` will not raise a `G_IO_ERROR_NOT_CONNECTED` error on
317// further I/O.
318type DtlsConnection interface {
319 GoPointer() uintptr
320 SetGoPointer(uintptr)
321 Close(CancellableVar *Cancellable) (bool, error)
322 CloseAsync(IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr)
323 CloseFinish(ResultVar AsyncResult) (bool, error)
324 EmitAcceptCertificate(PeerCertVar *TlsCertificate, ErrorsVar TlsCertificateFlags) bool
325 GetCertificate() *TlsCertificate
326 GetChannelBindingData(TypeVar TlsChannelBindingType, DataVar *[]byte) (bool, error)
327 GetCiphersuiteName() string
328 GetDatabase() *TlsDatabase
329 GetInteraction() *TlsInteraction
330 GetNegotiatedProtocol() string
331 GetPeerCertificate() *TlsCertificate
332 GetPeerCertificateErrors() TlsCertificateFlags
333 GetProtocolVersion() TlsProtocolVersion
334 GetRehandshakeMode() TlsRehandshakeMode
335 GetRequireCloseNotify() bool
336 Handshake(CancellableVar *Cancellable) (bool, error)
337 HandshakeAsync(IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr)
338 HandshakeFinish(ResultVar AsyncResult) (bool, error)
339 SetAdvertisedProtocols(ProtocolsVar []string)
340 SetCertificate(CertificateVar *TlsCertificate)
341 SetDatabase(DatabaseVar *TlsDatabase)
342 SetInteraction(InteractionVar *TlsInteraction)
343 SetRehandshakeMode(ModeVar TlsRehandshakeMode)
344 SetRequireCloseNotify(RequireCloseNotifyVar bool)
345 Shutdown(ShutdownReadVar bool, ShutdownWriteVar bool, CancellableVar *Cancellable) (bool, error)
346 ShutdownAsync(ShutdownReadVar bool, ShutdownWriteVar bool, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr)
347 ShutdownFinish(ResultVar AsyncResult) (bool, error)
348}
349
350var xDtlsConnectionGLibType func() types.GType
351
352func DtlsConnectionGLibType() types.GType {
353 return xDtlsConnectionGLibType()
354}
355
356type DtlsConnectionBase struct {
357 Ptr uintptr
358}
359
360func (x *DtlsConnectionBase) GoPointer() uintptr {
361 if x == nil {
362 return 0
363 }
364 return x.Ptr
365}
366
367func (x *DtlsConnectionBase) SetGoPointer(ptr uintptr) {
368 x.Ptr = ptr
369}
370
371// Close the DTLS connection. This is equivalent to calling
372// g_dtls_connection_shutdown() to shut down both sides of the connection.
373//
374// Closing a #GDtlsConnection waits for all buffered but untransmitted data to
375// be sent before it completes. It then sends a `close_notify` DTLS alert to the
376// peer and may wait for a `close_notify` to be received from the peer. It does
377// not close the underlying #GDtlsConnection:base-socket; that must be closed
378// separately.
379//
380// Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
381// Closing a #GDtlsConnection multiple times will not return an error.
382//
383// #GDtlsConnections will be automatically closed when the last reference is
384// dropped, but you might want to call this function to make sure resources are
385// released as early as possible.
386//
387// If @cancellable is cancelled, the #GDtlsConnection may be left
388// partially-closed and any pending untransmitted data may be lost. Call
389// g_dtls_connection_close() again to complete closing the #GDtlsConnection.
390func (x *DtlsConnectionBase) Close(CancellableVar *Cancellable) (bool, error) {
391 var cerr *glib.Error
392
393 cret := XGDtlsConnectionClose(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
394 if cerr == nil {
395 return cret, nil
396 }
397 return cret, cerr
398
399}
400
401// Asynchronously close the DTLS connection. See g_dtls_connection_close() for
402// more information.
403func (x *DtlsConnectionBase) CloseAsync(IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
404
405 XGDtlsConnectionCloseAsync(x.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
406
407}
408
409// Finish an asynchronous TLS close operation. See g_dtls_connection_close()
410// for more information.
411func (x *DtlsConnectionBase) CloseFinish(ResultVar AsyncResult) (bool, error) {
412 var cerr *glib.Error
413
414 cret := XGDtlsConnectionCloseFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
415 if cerr == nil {
416 return cret, nil
417 }
418 return cret, cerr
419
420}
421
422// Used by #GDtlsConnection implementations to emit the
423// #GDtlsConnection::accept-certificate signal.
424func (x *DtlsConnectionBase) EmitAcceptCertificate(PeerCertVar *TlsCertificate, ErrorsVar TlsCertificateFlags) bool {
425
426 cret := XGDtlsConnectionEmitAcceptCertificate(x.GoPointer(), PeerCertVar.GoPointer(), ErrorsVar)
427 return cret
428}
429
430// Gets @conn's certificate, as set by
431// g_dtls_connection_set_certificate().
432func (x *DtlsConnectionBase) GetCertificate() *TlsCertificate {
433 var cls *TlsCertificate
434
435 cret := XGDtlsConnectionGetCertificate(x.GoPointer())
436
437 if cret == 0 {
438 return nil
439 }
440 gobject.IncreaseRef(cret)
441 cls = &TlsCertificate{}
442 cls.Ptr = cret
443 return cls
444}
445
446// Query the TLS backend for TLS channel binding data of @type for @conn.
447//
448// This call retrieves TLS channel binding data as specified in RFC
449// [5056](https://tools.ietf.org/html/rfc5056), RFC
450// [5929](https://tools.ietf.org/html/rfc5929), and related RFCs. The
451// binding data is returned in @data. The @data is resized by the callee
452// using #GByteArray buffer management and will be freed when the @data
453// is destroyed by g_byte_array_unref(). If @data is %NULL, it will only
454// check whether TLS backend is able to fetch the data (e.g. whether @type
455// is supported by the TLS backend). It does not guarantee that the data
456// will be available though. That could happen if TLS connection does not
457// support @type or the binding data is not available yet due to additional
458// negotiation or input required.
459func (x *DtlsConnectionBase) GetChannelBindingData(TypeVar TlsChannelBindingType, DataVar *[]byte) (bool, error) {
460 var cerr *glib.Error
461
462 cret := XGDtlsConnectionGetChannelBindingData(x.GoPointer(), TypeVar, DataVar, &cerr)
463 if cerr == nil {
464 return cret, nil
465 }
466 return cret, cerr
467
468}
469
470// Returns the name of the current DTLS ciphersuite, or %NULL if the
471// connection has not handshaked or has been closed. Beware that the TLS
472// backend may use any of multiple different naming conventions, because
473// OpenSSL and GnuTLS have their own ciphersuite naming conventions that
474// are different from each other and different from the standard, IANA-
475// registered ciphersuite names. The ciphersuite name is intended to be
476// displayed to the user for informative purposes only, and parsing it
477// is not recommended.
478func (x *DtlsConnectionBase) GetCiphersuiteName() string {
479
480 cret := XGDtlsConnectionGetCiphersuiteName(x.GoPointer())
481 return cret
482}
483
484// Gets the certificate database that @conn uses to verify
485// peer certificates. See g_dtls_connection_set_database().
486func (x *DtlsConnectionBase) GetDatabase() *TlsDatabase {
487 var cls *TlsDatabase
488
489 cret := XGDtlsConnectionGetDatabase(x.GoPointer())
490
491 if cret == 0 {
492 return nil
493 }
494 gobject.IncreaseRef(cret)
495 cls = &TlsDatabase{}
496 cls.Ptr = cret
497 return cls
498}
499
500// Get the object that will be used to interact with the user. It will be used
501// for things like prompting the user for passwords. If %NULL is returned, then
502// no user interaction will occur for this connection.
503func (x *DtlsConnectionBase) GetInteraction() *TlsInteraction {
504 var cls *TlsInteraction
505
506 cret := XGDtlsConnectionGetInteraction(x.GoPointer())
507
508 if cret == 0 {
509 return nil
510 }
511 gobject.IncreaseRef(cret)
512 cls = &TlsInteraction{}
513 cls.Ptr = cret
514 return cls
515}
516
517// Gets the name of the application-layer protocol negotiated during
518// the handshake.
519//
520// If the peer did not use the ALPN extension, or did not advertise a
521// protocol that matched one of @conn's protocols, or the TLS backend
522// does not support ALPN, then this will be %NULL. See
523// g_dtls_connection_set_advertised_protocols().
524func (x *DtlsConnectionBase) GetNegotiatedProtocol() string {
525
526 cret := XGDtlsConnectionGetNegotiatedProtocol(x.GoPointer())
527 return cret
528}
529
530// Gets @conn's peer's certificate after the handshake has completed
531// or failed. (It is not set during the emission of
532// #GDtlsConnection::accept-certificate.)
533func (x *DtlsConnectionBase) GetPeerCertificate() *TlsCertificate {
534 var cls *TlsCertificate
535
536 cret := XGDtlsConnectionGetPeerCertificate(x.GoPointer())
537
538 if cret == 0 {
539 return nil
540 }
541 gobject.IncreaseRef(cret)
542 cls = &TlsCertificate{}
543 cls.Ptr = cret
544 return cls
545}
546
547// Gets the errors associated with validating @conn's peer's
548// certificate, after the handshake has completed or failed. (It is
549// not set during the emission of #GDtlsConnection::accept-certificate.)
550func (x *DtlsConnectionBase) GetPeerCertificateErrors() TlsCertificateFlags {
551
552 cret := XGDtlsConnectionGetPeerCertificateErrors(x.GoPointer())
553 return cret
554}
555
556// Returns the current DTLS protocol version, which may be
557// %G_TLS_PROTOCOL_VERSION_UNKNOWN if the connection has not handshaked, or
558// has been closed, or if the TLS backend has implemented a protocol version
559// that is not a recognized #GTlsProtocolVersion.
560func (x *DtlsConnectionBase) GetProtocolVersion() TlsProtocolVersion {
561
562 cret := XGDtlsConnectionGetProtocolVersion(x.GoPointer())
563 return cret
564}
565
566// Gets @conn rehandshaking mode. See
567// g_dtls_connection_set_rehandshake_mode() for details.
568func (x *DtlsConnectionBase) GetRehandshakeMode() TlsRehandshakeMode {
569
570 cret := XGDtlsConnectionGetRehandshakeMode(x.GoPointer())
571 return cret
572}
573
574// Tests whether or not @conn expects a proper TLS close notification
575// when the connection is closed. See
576// g_dtls_connection_set_require_close_notify() for details.
577func (x *DtlsConnectionBase) GetRequireCloseNotify() bool {
578
579 cret := XGDtlsConnectionGetRequireCloseNotify(x.GoPointer())
580 return cret
581}
582
583// Attempts a TLS handshake on @conn.
584//
585// On the client side, it is never necessary to call this method;
586// although the connection needs to perform a handshake after
587// connecting, #GDtlsConnection will handle this for you automatically
588// when you try to send or receive data on the connection. You can call
589// g_dtls_connection_handshake() manually if you want to know whether
590// the initial handshake succeeded or failed (as opposed to just
591// immediately trying to use @conn to read or write, in which case,
592// if it fails, it may not be possible to tell if it failed before
593// or after completing the handshake), but beware that servers may reject
594// client authentication after the handshake has completed, so a
595// successful handshake does not indicate the connection will be usable.
596//
597// Likewise, on the server side, although a handshake is necessary at
598// the beginning of the communication, you do not need to call this
599// function explicitly unless you want clearer error reporting.
600//
601// Previously, calling g_dtls_connection_handshake() after the initial
602// handshake would trigger a rehandshake; however, this usage was
603// deprecated in GLib 2.60 because rehandshaking was removed from the
604// TLS protocol in TLS 1.3. Since GLib 2.64, calling this function after
605// the initial handshake will no longer do anything.
606//
607// #GDtlsConnection::accept_certificate may be emitted during the
608// handshake.
609func (x *DtlsConnectionBase) Handshake(CancellableVar *Cancellable) (bool, error) {
610 var cerr *glib.Error
611
612 cret := XGDtlsConnectionHandshake(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
613 if cerr == nil {
614 return cret, nil
615 }
616 return cret, cerr
617
618}
619
620// Asynchronously performs a TLS handshake on @conn. See
621// g_dtls_connection_handshake() for more information.
622func (x *DtlsConnectionBase) HandshakeAsync(IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
623
624 XGDtlsConnectionHandshakeAsync(x.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
625
626}
627
628// Finish an asynchronous TLS handshake operation. See
629// g_dtls_connection_handshake() for more information.
630func (x *DtlsConnectionBase) HandshakeFinish(ResultVar AsyncResult) (bool, error) {
631 var cerr *glib.Error
632
633 cret := XGDtlsConnectionHandshakeFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
634 if cerr == nil {
635 return cret, nil
636 }
637 return cret, cerr
638
639}
640
641// Sets the list of application-layer protocols to advertise that the
642// caller is willing to speak on this connection. The
643// Application-Layer Protocol Negotiation (ALPN) extension will be
644// used to negotiate a compatible protocol with the peer; use
645// g_dtls_connection_get_negotiated_protocol() to find the negotiated
646// protocol after the handshake. Specifying %NULL for the the value
647// of @protocols will disable ALPN negotiation.
648//
649// See [IANA TLS ALPN Protocol IDs](https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)
650// for a list of registered protocol IDs.
651func (x *DtlsConnectionBase) SetAdvertisedProtocols(ProtocolsVar []string) {
652
653 XGDtlsConnectionSetAdvertisedProtocols(x.GoPointer(), ProtocolsVar)
654
655}
656
657// This sets the certificate that @conn will present to its peer
658// during the TLS handshake. For a #GDtlsServerConnection, it is
659// mandatory to set this, and that will normally be done at construct
660// time.
661//
662// For a #GDtlsClientConnection, this is optional. If a handshake fails
663// with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
664// requires a certificate, and if you try connecting again, you should
665// call this method first. You can call
666// g_dtls_client_connection_get_accepted_cas() on the failed connection
667// to get a list of Certificate Authorities that the server will
668// accept certificates from.
669//
670// (It is also possible that a server will allow the connection with
671// or without a certificate; in that case, if you don't provide a
672// certificate, you can tell that the server requested one by the fact
673// that g_dtls_client_connection_get_accepted_cas() will return
674// non-%NULL.)
675func (x *DtlsConnectionBase) SetCertificate(CertificateVar *TlsCertificate) {
676
677 XGDtlsConnectionSetCertificate(x.GoPointer(), CertificateVar.GoPointer())
678
679}
680
681// Sets the certificate database that is used to verify peer certificates.
682// This is set to the default database by default. See
683// g_tls_backend_get_default_database(). If set to %NULL, then
684// peer certificate validation will always set the
685// %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
686// #GDtlsConnection::accept-certificate will always be emitted on
687// client-side connections, unless that bit is not set in
688// #GDtlsClientConnection:validation-flags).
689//
690// There are nonintuitive security implications when using a non-default
691// database. See #GDtlsConnection:database for details.
692func (x *DtlsConnectionBase) SetDatabase(DatabaseVar *TlsDatabase) {
693
694 XGDtlsConnectionSetDatabase(x.GoPointer(), DatabaseVar.GoPointer())
695
696}
697
698// Set the object that will be used to interact with the user. It will be used
699// for things like prompting the user for passwords.
700//
701// The @interaction argument will normally be a derived subclass of
702// #GTlsInteraction. %NULL can also be provided if no user interaction
703// should occur for this connection.
704func (x *DtlsConnectionBase) SetInteraction(InteractionVar *TlsInteraction) {
705
706 XGDtlsConnectionSetInteraction(x.GoPointer(), InteractionVar.GoPointer())
707
708}
709
710// Since GLib 2.64, changing the rehandshake mode is no longer supported
711// and will have no effect. With TLS 1.3, rehandshaking has been removed from
712// the TLS protocol, replaced by separate post-handshake authentication and
713// rekey operations.
714func (x *DtlsConnectionBase) SetRehandshakeMode(ModeVar TlsRehandshakeMode) {
715
716 XGDtlsConnectionSetRehandshakeMode(x.GoPointer(), ModeVar)
717
718}
719
720// Sets whether or not @conn expects a proper TLS close notification
721// before the connection is closed. If this is %TRUE (the default),
722// then @conn will expect to receive a TLS close notification from its
723// peer before the connection is closed, and will return a
724// %G_TLS_ERROR_EOF error if the connection is closed without proper
725// notification (since this may indicate a network error, or
726// man-in-the-middle attack).
727//
728// In some protocols, the application will know whether or not the
729// connection was closed cleanly based on application-level data
730// (because the application-level data includes a length field, or is
731// somehow self-delimiting); in this case, the close notify is
732// redundant and may be omitted. You
733// can use g_dtls_connection_set_require_close_notify() to tell @conn
734// to allow an "unannounced" connection close, in which case the close
735// will show up as a 0-length read, as in a non-TLS
736// #GDatagramBased, and it is up to the application to check that
737// the data has been fully received.
738//
739// Note that this only affects the behavior when the peer closes the
740// connection; when the application calls g_dtls_connection_close_async() on
741// @conn itself, this will send a close notification regardless of the
742// setting of this property. If you explicitly want to do an unclean
743// close, you can close @conn's #GDtlsConnection:base-socket rather
744// than closing @conn itself.
745func (x *DtlsConnectionBase) SetRequireCloseNotify(RequireCloseNotifyVar bool) {
746
747 XGDtlsConnectionSetRequireCloseNotify(x.GoPointer(), RequireCloseNotifyVar)
748
749}
750
751// Shut down part or all of a DTLS connection.
752//
753// If @shutdown_read is %TRUE then the receiving side of the connection is shut
754// down, and further reading is disallowed. Subsequent calls to
755// g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
756//
757// If @shutdown_write is %TRUE then the sending side of the connection is shut
758// down, and further writing is disallowed. Subsequent calls to
759// g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
760//
761// It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
762// is equivalent to calling g_dtls_connection_close().
763//
764// If @cancellable is cancelled, the #GDtlsConnection may be left
765// partially-closed and any pending untransmitted data may be lost. Call
766// g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
767func (x *DtlsConnectionBase) Shutdown(ShutdownReadVar bool, ShutdownWriteVar bool, CancellableVar *Cancellable) (bool, error) {
768 var cerr *glib.Error
769
770 cret := XGDtlsConnectionShutdown(x.GoPointer(), ShutdownReadVar, ShutdownWriteVar, CancellableVar.GoPointer(), &cerr)
771 if cerr == nil {
772 return cret, nil
773 }
774 return cret, cerr
775
776}
777
778// Asynchronously shut down part or all of the DTLS connection. See
779// g_dtls_connection_shutdown() for more information.
780func (x *DtlsConnectionBase) ShutdownAsync(ShutdownReadVar bool, ShutdownWriteVar bool, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
781
782 XGDtlsConnectionShutdownAsync(x.GoPointer(), ShutdownReadVar, ShutdownWriteVar, IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
783
784}
785
786// Finish an asynchronous TLS shutdown operation. See
787// g_dtls_connection_shutdown() for more information.
788func (x *DtlsConnectionBase) ShutdownFinish(ResultVar AsyncResult) (bool, error) {
789 var cerr *glib.Error
790
791 cret := XGDtlsConnectionShutdownFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
792 if cerr == nil {
793 return cret, nil
794 }
795 return cret, cerr
796
797}
798
799// SetPropertyAdvertisedProtocols sets the "advertised-protocols" property.
800// The list of application-layer protocols that the connection
801// advertises that it is willing to speak. See
802// g_dtls_connection_set_advertised_protocols().
803func (x *DtlsConnectionBase) SetPropertyAdvertisedProtocols(value []string) {
804 obj := gobject.Object{}
805 obj.Ptr = x.GoPointer()
806 var v gobject.Value
807 v.Init(glib.StrvGetType())
808 v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))
809 obj.SetProperty("advertised-protocols", &v)
810}
811
812// GetPropertyAdvertisedProtocols gets the "advertised-protocols" property.
813// The list of application-layer protocols that the connection
814// advertises that it is willing to speak. See
815// g_dtls_connection_set_advertised_protocols().
816func (x *DtlsConnectionBase) GetPropertyAdvertisedProtocols() []string {
817 obj := gobject.Object{}
818 obj.Ptr = x.GoPointer()
819 var v gobject.Value
820 obj.GetProperty("advertised-protocols", &v)
821 return core.GoStringSlice(v.GetBoxed())
822}
823
824// GetPropertyCiphersuiteName gets the "ciphersuite-name" property.
825// The name of the DTLS ciphersuite in use. See g_dtls_connection_get_ciphersuite_name().
826func (x *DtlsConnectionBase) GetPropertyCiphersuiteName() string {
827 obj := gobject.Object{}
828 obj.Ptr = x.GoPointer()
829 var v gobject.Value
830 obj.GetProperty("ciphersuite-name", &v)
831 return v.GetString()
832}
833
834// GetPropertyNegotiatedProtocol gets the "negotiated-protocol" property.
835// The application-layer protocol negotiated during the TLS
836// handshake. See g_dtls_connection_get_negotiated_protocol().
837func (x *DtlsConnectionBase) GetPropertyNegotiatedProtocol() string {
838 obj := gobject.Object{}
839 obj.Ptr = x.GoPointer()
840 var v gobject.Value
841 obj.GetProperty("negotiated-protocol", &v)
842 return v.GetString()
843}
844
845// SetPropertyRequireCloseNotify sets the "require-close-notify" property.
846// Whether or not proper TLS close notification is required.
847// See g_dtls_connection_set_require_close_notify().
848func (x *DtlsConnectionBase) SetPropertyRequireCloseNotify(value bool) {
849 obj := gobject.Object{}
850 obj.Ptr = x.GoPointer()
851 var v gobject.Value
852 v.Init(gobject.TypeBooleanVal)
853 v.SetBoolean(value)
854 obj.SetProperty("require-close-notify", &v)
855}
856
857// GetPropertyRequireCloseNotify gets the "require-close-notify" property.
858// Whether or not proper TLS close notification is required.
859// See g_dtls_connection_set_require_close_notify().
860func (x *DtlsConnectionBase) GetPropertyRequireCloseNotify() bool {
861 obj := gobject.Object{}
862 obj.Ptr = x.GoPointer()
863 var v gobject.Value
864 obj.GetProperty("require-close-notify", &v)
865 return v.GetBoolean()
866}
867
868var XGDtlsConnectionClose func(uintptr, uintptr, **glib.Error) bool
869var XGDtlsConnectionCloseAsync func(uintptr, int, uintptr, uintptr, uintptr)
870var XGDtlsConnectionCloseFinish func(uintptr, uintptr, **glib.Error) bool
871var XGDtlsConnectionEmitAcceptCertificate func(uintptr, uintptr, TlsCertificateFlags) bool
872var XGDtlsConnectionGetCertificate func(uintptr) uintptr
873var XGDtlsConnectionGetChannelBindingData func(uintptr, TlsChannelBindingType, *[]byte, **glib.Error) bool
874var XGDtlsConnectionGetCiphersuiteName func(uintptr) string
875var XGDtlsConnectionGetDatabase func(uintptr) uintptr
876var XGDtlsConnectionGetInteraction func(uintptr) uintptr
877var XGDtlsConnectionGetNegotiatedProtocol func(uintptr) string
878var XGDtlsConnectionGetPeerCertificate func(uintptr) uintptr
879var XGDtlsConnectionGetPeerCertificateErrors func(uintptr) TlsCertificateFlags
880var XGDtlsConnectionGetProtocolVersion func(uintptr) TlsProtocolVersion
881var XGDtlsConnectionGetRehandshakeMode func(uintptr) TlsRehandshakeMode
882var XGDtlsConnectionGetRequireCloseNotify func(uintptr) bool
883var XGDtlsConnectionHandshake func(uintptr, uintptr, **glib.Error) bool
884var XGDtlsConnectionHandshakeAsync func(uintptr, int, uintptr, uintptr, uintptr)
885var XGDtlsConnectionHandshakeFinish func(uintptr, uintptr, **glib.Error) bool
886var XGDtlsConnectionSetAdvertisedProtocols func(uintptr, []string)
887var XGDtlsConnectionSetCertificate func(uintptr, uintptr)
888var XGDtlsConnectionSetDatabase func(uintptr, uintptr)
889var XGDtlsConnectionSetInteraction func(uintptr, uintptr)
890var XGDtlsConnectionSetRehandshakeMode func(uintptr, TlsRehandshakeMode)
891var XGDtlsConnectionSetRequireCloseNotify func(uintptr, bool)
892var XGDtlsConnectionShutdown func(uintptr, bool, bool, uintptr, **glib.Error) bool
893var XGDtlsConnectionShutdownAsync func(uintptr, bool, bool, int, uintptr, uintptr, uintptr)
894var XGDtlsConnectionShutdownFinish func(uintptr, uintptr, **glib.Error) bool
895
896func init() {
897 core.SetPackageName("GIO", "gio-2.0")
898 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
899 var libs []uintptr
900 for _, libPath := range core.GetPaths("GIO") {
901 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
902 if err != nil {
903 panic(err)
904 }
905 libs = append(libs, lib)
906 }
907
908 core.PuregoSafeRegister(&xDtlsConnectionGLibType, libs, "g_dtls_connection_get_type")
909
910 core.PuregoSafeRegister(&XGDtlsConnectionClose, libs, "g_dtls_connection_close")
911 core.PuregoSafeRegister(&XGDtlsConnectionCloseAsync, libs, "g_dtls_connection_close_async")
912 core.PuregoSafeRegister(&XGDtlsConnectionCloseFinish, libs, "g_dtls_connection_close_finish")
913 core.PuregoSafeRegister(&XGDtlsConnectionEmitAcceptCertificate, libs, "g_dtls_connection_emit_accept_certificate")
914 core.PuregoSafeRegister(&XGDtlsConnectionGetCertificate, libs, "g_dtls_connection_get_certificate")
915 core.PuregoSafeRegister(&XGDtlsConnectionGetChannelBindingData, libs, "g_dtls_connection_get_channel_binding_data")
916 core.PuregoSafeRegister(&XGDtlsConnectionGetCiphersuiteName, libs, "g_dtls_connection_get_ciphersuite_name")
917 core.PuregoSafeRegister(&XGDtlsConnectionGetDatabase, libs, "g_dtls_connection_get_database")
918 core.PuregoSafeRegister(&XGDtlsConnectionGetInteraction, libs, "g_dtls_connection_get_interaction")
919 core.PuregoSafeRegister(&XGDtlsConnectionGetNegotiatedProtocol, libs, "g_dtls_connection_get_negotiated_protocol")
920 core.PuregoSafeRegister(&XGDtlsConnectionGetPeerCertificate, libs, "g_dtls_connection_get_peer_certificate")
921 core.PuregoSafeRegister(&XGDtlsConnectionGetPeerCertificateErrors, libs, "g_dtls_connection_get_peer_certificate_errors")
922 core.PuregoSafeRegister(&XGDtlsConnectionGetProtocolVersion, libs, "g_dtls_connection_get_protocol_version")
923 core.PuregoSafeRegister(&XGDtlsConnectionGetRehandshakeMode, libs, "g_dtls_connection_get_rehandshake_mode")
924 core.PuregoSafeRegister(&XGDtlsConnectionGetRequireCloseNotify, libs, "g_dtls_connection_get_require_close_notify")
925 core.PuregoSafeRegister(&XGDtlsConnectionHandshake, libs, "g_dtls_connection_handshake")
926 core.PuregoSafeRegister(&XGDtlsConnectionHandshakeAsync, libs, "g_dtls_connection_handshake_async")
927 core.PuregoSafeRegister(&XGDtlsConnectionHandshakeFinish, libs, "g_dtls_connection_handshake_finish")
928 core.PuregoSafeRegister(&XGDtlsConnectionSetAdvertisedProtocols, libs, "g_dtls_connection_set_advertised_protocols")
929 core.PuregoSafeRegister(&XGDtlsConnectionSetCertificate, libs, "g_dtls_connection_set_certificate")
930 core.PuregoSafeRegister(&XGDtlsConnectionSetDatabase, libs, "g_dtls_connection_set_database")
931 core.PuregoSafeRegister(&XGDtlsConnectionSetInteraction, libs, "g_dtls_connection_set_interaction")
932 core.PuregoSafeRegister(&XGDtlsConnectionSetRehandshakeMode, libs, "g_dtls_connection_set_rehandshake_mode")
933 core.PuregoSafeRegister(&XGDtlsConnectionSetRequireCloseNotify, libs, "g_dtls_connection_set_require_close_notify")
934 core.PuregoSafeRegister(&XGDtlsConnectionShutdown, libs, "g_dtls_connection_shutdown")
935 core.PuregoSafeRegister(&XGDtlsConnectionShutdownAsync, libs, "g_dtls_connection_shutdown_async")
936 core.PuregoSafeRegister(&XGDtlsConnectionShutdownFinish, libs, "g_dtls_connection_shutdown_finish")
937
938}