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// The class structure for the #GTlsConnection type.
17type TlsConnectionClass struct {
18 _ structs.HostLayout
19
20 ParentClass IOStreamClass
21
22 xAcceptCertificate uintptr
23
24 xHandshake uintptr
25
26 xHandshakeAsync uintptr
27
28 xHandshakeFinish uintptr
29
30 xGetBindingData uintptr
31
32 xGetNegotiatedProtocol uintptr
33
34 Padding [6]uintptr
35}
36
37func (x *TlsConnectionClass) GoPointer() uintptr {
38 return uintptr(unsafe.Pointer(x))
39}
40
41// OverrideAcceptCertificate sets the "accept_certificate" callback function.
42// Check whether to accept a certificate.
43func (x *TlsConnectionClass) OverrideAcceptCertificate(cb func(*TlsConnection, *TlsCertificate, TlsCertificateFlags) bool) {
44 if cb == nil {
45 x.xAcceptCertificate = 0
46 } else {
47 x.xAcceptCertificate = purego.NewCallback(func(ConnectionVarp uintptr, PeerCertVarp uintptr, ErrorsVarp TlsCertificateFlags) bool {
48 return cb(TlsConnectionNewFromInternalPtr(ConnectionVarp), TlsCertificateNewFromInternalPtr(PeerCertVarp), ErrorsVarp)
49 })
50 }
51}
52
53// GetAcceptCertificate gets the "accept_certificate" callback function.
54// Check whether to accept a certificate.
55func (x *TlsConnectionClass) GetAcceptCertificate() func(*TlsConnection, *TlsCertificate, TlsCertificateFlags) bool {
56 if x.xAcceptCertificate == 0 {
57 return nil
58 }
59 var rawCallback func(ConnectionVarp uintptr, PeerCertVarp uintptr, ErrorsVarp TlsCertificateFlags) bool
60 purego.RegisterFunc(&rawCallback, x.xAcceptCertificate)
61 return func(ConnectionVar *TlsConnection, PeerCertVar *TlsCertificate, ErrorsVar TlsCertificateFlags) bool {
62 return rawCallback(ConnectionVar.GoPointer(), PeerCertVar.GoPointer(), ErrorsVar)
63 }
64}
65
66// OverrideHandshake sets the "handshake" callback function.
67// Perform a handshake operation.
68func (x *TlsConnectionClass) OverrideHandshake(cb func(*TlsConnection, *Cancellable) bool) {
69 if cb == nil {
70 x.xHandshake = 0
71 } else {
72 x.xHandshake = purego.NewCallback(func(ConnVarp uintptr, CancellableVarp uintptr) bool {
73 return cb(TlsConnectionNewFromInternalPtr(ConnVarp), CancellableNewFromInternalPtr(CancellableVarp))
74 })
75 }
76}
77
78// GetHandshake gets the "handshake" callback function.
79// Perform a handshake operation.
80func (x *TlsConnectionClass) GetHandshake() func(*TlsConnection, *Cancellable) bool {
81 if x.xHandshake == 0 {
82 return nil
83 }
84 var rawCallback func(ConnVarp uintptr, CancellableVarp uintptr) bool
85 purego.RegisterFunc(&rawCallback, x.xHandshake)
86 return func(ConnVar *TlsConnection, CancellableVar *Cancellable) bool {
87 return rawCallback(ConnVar.GoPointer(), CancellableVar.GoPointer())
88 }
89}
90
91// OverrideHandshakeAsync sets the "handshake_async" callback function.
92// Start an asynchronous handshake operation.
93func (x *TlsConnectionClass) OverrideHandshakeAsync(cb func(*TlsConnection, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
94 if cb == nil {
95 x.xHandshakeAsync = 0
96 } else {
97 x.xHandshakeAsync = purego.NewCallback(func(ConnVarp uintptr, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
98 cb(TlsConnectionNewFromInternalPtr(ConnVarp), IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
99 })
100 }
101}
102
103// GetHandshakeAsync gets the "handshake_async" callback function.
104// Start an asynchronous handshake operation.
105func (x *TlsConnectionClass) GetHandshakeAsync() func(*TlsConnection, int, *Cancellable, *AsyncReadyCallback, uintptr) {
106 if x.xHandshakeAsync == 0 {
107 return nil
108 }
109 var rawCallback func(ConnVarp uintptr, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
110 purego.RegisterFunc(&rawCallback, x.xHandshakeAsync)
111 return func(ConnVar *TlsConnection, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
112 rawCallback(ConnVar.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
113 }
114}
115
116// OverrideHandshakeFinish sets the "handshake_finish" callback function.
117// Finish an asynchronous handshake operation.
118func (x *TlsConnectionClass) OverrideHandshakeFinish(cb func(*TlsConnection, AsyncResult) bool) {
119 if cb == nil {
120 x.xHandshakeFinish = 0
121 } else {
122 x.xHandshakeFinish = purego.NewCallback(func(ConnVarp uintptr, ResultVarp uintptr) bool {
123 return cb(TlsConnectionNewFromInternalPtr(ConnVarp), &AsyncResultBase{Ptr: ResultVarp})
124 })
125 }
126}
127
128// GetHandshakeFinish gets the "handshake_finish" callback function.
129// Finish an asynchronous handshake operation.
130func (x *TlsConnectionClass) GetHandshakeFinish() func(*TlsConnection, AsyncResult) bool {
131 if x.xHandshakeFinish == 0 {
132 return nil
133 }
134 var rawCallback func(ConnVarp uintptr, ResultVarp uintptr) bool
135 purego.RegisterFunc(&rawCallback, x.xHandshakeFinish)
136 return func(ConnVar *TlsConnection, ResultVar AsyncResult) bool {
137 return rawCallback(ConnVar.GoPointer(), ResultVar.GoPointer())
138 }
139}
140
141// OverrideGetBindingData sets the "get_binding_data" callback function.
142// Retrieve TLS channel binding data (Since: 2.66)
143func (x *TlsConnectionClass) OverrideGetBindingData(cb func(*TlsConnection, TlsChannelBindingType, []byte) bool) {
144 if cb == nil {
145 x.xGetBindingData = 0
146 } else {
147 x.xGetBindingData = purego.NewCallback(func(ConnVarp uintptr, TypeVarp TlsChannelBindingType, DataVarp []byte) bool {
148 return cb(TlsConnectionNewFromInternalPtr(ConnVarp), TypeVarp, DataVarp)
149 })
150 }
151}
152
153// GetGetBindingData gets the "get_binding_data" callback function.
154// Retrieve TLS channel binding data (Since: 2.66)
155func (x *TlsConnectionClass) GetGetBindingData() func(*TlsConnection, TlsChannelBindingType, []byte) bool {
156 if x.xGetBindingData == 0 {
157 return nil
158 }
159 var rawCallback func(ConnVarp uintptr, TypeVarp TlsChannelBindingType, DataVarp []byte) bool
160 purego.RegisterFunc(&rawCallback, x.xGetBindingData)
161 return func(ConnVar *TlsConnection, TypeVar TlsChannelBindingType, DataVar []byte) bool {
162 return rawCallback(ConnVar.GoPointer(), TypeVar, DataVar)
163 }
164}
165
166// OverrideGetNegotiatedProtocol sets the "get_negotiated_protocol" callback function.
167// Get ALPN-negotiated protocol (Since: 2.70)
168func (x *TlsConnectionClass) OverrideGetNegotiatedProtocol(cb func(*TlsConnection) string) {
169 if cb == nil {
170 x.xGetNegotiatedProtocol = 0
171 } else {
172 x.xGetNegotiatedProtocol = purego.NewCallback(func(ConnVarp uintptr) string {
173 return cb(TlsConnectionNewFromInternalPtr(ConnVarp))
174 })
175 }
176}
177
178// GetGetNegotiatedProtocol gets the "get_negotiated_protocol" callback function.
179// Get ALPN-negotiated protocol (Since: 2.70)
180func (x *TlsConnectionClass) GetGetNegotiatedProtocol() func(*TlsConnection) string {
181 if x.xGetNegotiatedProtocol == 0 {
182 return nil
183 }
184 var rawCallback func(ConnVarp uintptr) string
185 purego.RegisterFunc(&rawCallback, x.xGetNegotiatedProtocol)
186 return func(ConnVar *TlsConnection) string {
187 return rawCallback(ConnVar.GoPointer())
188 }
189}
190
191type TlsConnectionPrivate struct {
192 _ structs.HostLayout
193}
194
195func (x *TlsConnectionPrivate) GoPointer() uintptr {
196 return uintptr(unsafe.Pointer(x))
197}
198
199var xTlsChannelBindingErrorQuark func() glib.Quark
200
201// Gets the TLS channel binding error quark.
202func TlsChannelBindingErrorQuark() glib.Quark {
203
204 cret := xTlsChannelBindingErrorQuark()
205 return cret
206}
207
208var xTlsErrorQuark func() glib.Quark
209
210// Gets the TLS error quark.
211func TlsErrorQuark() glib.Quark {
212
213 cret := xTlsErrorQuark()
214 return cret
215}
216
217// `GTlsConnection` is the base TLS connection class type, which wraps
218// a [class@Gio.IOStream] and provides TLS encryption on top of it. Its
219// subclasses, [iface@Gio.TlsClientConnection] and
220// [iface@Gio.TlsServerConnection], implement client-side and server-side TLS,
221// respectively.
222//
223// For DTLS (Datagram TLS) support, see [iface@Gio.DtlsConnection].
224type TlsConnection struct {
225 IOStream
226}
227
228var xTlsConnectionGLibType func() types.GType
229
230func TlsConnectionGLibType() types.GType {
231 return xTlsConnectionGLibType()
232}
233
234func TlsConnectionNewFromInternalPtr(ptr uintptr) *TlsConnection {
235 cls := &TlsConnection{}
236 cls.Ptr = ptr
237 return cls
238}
239
240var xTlsConnectionEmitAcceptCertificate func(uintptr, uintptr, TlsCertificateFlags) bool
241
242// Used by #GTlsConnection implementations to emit the
243// #GTlsConnection::accept-certificate signal.
244func (x *TlsConnection) EmitAcceptCertificate(PeerCertVar *TlsCertificate, ErrorsVar TlsCertificateFlags) bool {
245
246 cret := xTlsConnectionEmitAcceptCertificate(x.GoPointer(), PeerCertVar.GoPointer(), ErrorsVar)
247 return cret
248}
249
250var xTlsConnectionGetCertificate func(uintptr) uintptr
251
252// Gets @conn's certificate, as set by
253// g_tls_connection_set_certificate().
254func (x *TlsConnection) GetCertificate() *TlsCertificate {
255 var cls *TlsCertificate
256
257 cret := xTlsConnectionGetCertificate(x.GoPointer())
258
259 if cret == 0 {
260 return nil
261 }
262 gobject.IncreaseRef(cret)
263 cls = &TlsCertificate{}
264 cls.Ptr = cret
265 return cls
266}
267
268var xTlsConnectionGetChannelBindingData func(uintptr, TlsChannelBindingType, *[]byte, **glib.Error) bool
269
270// Query the TLS backend for TLS channel binding data of @type for @conn.
271//
272// This call retrieves TLS channel binding data as specified in RFC
273// [5056](https://tools.ietf.org/html/rfc5056), RFC
274// [5929](https://tools.ietf.org/html/rfc5929), and related RFCs. The
275// binding data is returned in @data. The @data is resized by the callee
276// using #GByteArray buffer management and will be freed when the @data
277// is destroyed by g_byte_array_unref(). If @data is %NULL, it will only
278// check whether TLS backend is able to fetch the data (e.g. whether @type
279// is supported by the TLS backend). It does not guarantee that the data
280// will be available though. That could happen if TLS connection does not
281// support @type or the binding data is not available yet due to additional
282// negotiation or input required.
283func (x *TlsConnection) GetChannelBindingData(TypeVar TlsChannelBindingType, DataVar *[]byte) (bool, error) {
284 var cerr *glib.Error
285
286 cret := xTlsConnectionGetChannelBindingData(x.GoPointer(), TypeVar, DataVar, &cerr)
287 if cerr == nil {
288 return cret, nil
289 }
290 return cret, cerr
291
292}
293
294var xTlsConnectionGetCiphersuiteName func(uintptr) string
295
296// Returns the name of the current TLS ciphersuite, or %NULL if the
297// connection has not handshaked or has been closed. Beware that the TLS
298// backend may use any of multiple different naming conventions, because
299// OpenSSL and GnuTLS have their own ciphersuite naming conventions that
300// are different from each other and different from the standard, IANA-
301// registered ciphersuite names. The ciphersuite name is intended to be
302// displayed to the user for informative purposes only, and parsing it
303// is not recommended.
304func (x *TlsConnection) GetCiphersuiteName() string {
305
306 cret := xTlsConnectionGetCiphersuiteName(x.GoPointer())
307 return cret
308}
309
310var xTlsConnectionGetDatabase func(uintptr) uintptr
311
312// Gets the certificate database that @conn uses to verify
313// peer certificates. See g_tls_connection_set_database().
314func (x *TlsConnection) GetDatabase() *TlsDatabase {
315 var cls *TlsDatabase
316
317 cret := xTlsConnectionGetDatabase(x.GoPointer())
318
319 if cret == 0 {
320 return nil
321 }
322 gobject.IncreaseRef(cret)
323 cls = &TlsDatabase{}
324 cls.Ptr = cret
325 return cls
326}
327
328var xTlsConnectionGetInteraction func(uintptr) uintptr
329
330// Get the object that will be used to interact with the user. It will be used
331// for things like prompting the user for passwords. If %NULL is returned, then
332// no user interaction will occur for this connection.
333func (x *TlsConnection) GetInteraction() *TlsInteraction {
334 var cls *TlsInteraction
335
336 cret := xTlsConnectionGetInteraction(x.GoPointer())
337
338 if cret == 0 {
339 return nil
340 }
341 gobject.IncreaseRef(cret)
342 cls = &TlsInteraction{}
343 cls.Ptr = cret
344 return cls
345}
346
347var xTlsConnectionGetNegotiatedProtocol func(uintptr) string
348
349// Gets the name of the application-layer protocol negotiated during
350// the handshake.
351//
352// If the peer did not use the ALPN extension, or did not advertise a
353// protocol that matched one of @conn's protocols, or the TLS backend
354// does not support ALPN, then this will be %NULL. See
355// g_tls_connection_set_advertised_protocols().
356func (x *TlsConnection) GetNegotiatedProtocol() string {
357
358 cret := xTlsConnectionGetNegotiatedProtocol(x.GoPointer())
359 return cret
360}
361
362var xTlsConnectionGetPeerCertificate func(uintptr) uintptr
363
364// Gets @conn's peer's certificate after the handshake has completed
365// or failed. (It is not set during the emission of
366// #GTlsConnection::accept-certificate.)
367func (x *TlsConnection) GetPeerCertificate() *TlsCertificate {
368 var cls *TlsCertificate
369
370 cret := xTlsConnectionGetPeerCertificate(x.GoPointer())
371
372 if cret == 0 {
373 return nil
374 }
375 gobject.IncreaseRef(cret)
376 cls = &TlsCertificate{}
377 cls.Ptr = cret
378 return cls
379}
380
381var xTlsConnectionGetPeerCertificateErrors func(uintptr) TlsCertificateFlags
382
383// Gets the errors associated with validating @conn's peer's
384// certificate, after the handshake has completed or failed. (It is
385// not set during the emission of #GTlsConnection::accept-certificate.)
386//
387// See #GTlsConnection:peer-certificate-errors for more information.
388func (x *TlsConnection) GetPeerCertificateErrors() TlsCertificateFlags {
389
390 cret := xTlsConnectionGetPeerCertificateErrors(x.GoPointer())
391 return cret
392}
393
394var xTlsConnectionGetProtocolVersion func(uintptr) TlsProtocolVersion
395
396// Returns the current TLS protocol version, which may be
397// %G_TLS_PROTOCOL_VERSION_UNKNOWN if the connection has not handshaked, or
398// has been closed, or if the TLS backend has implemented a protocol version
399// that is not a recognized #GTlsProtocolVersion.
400func (x *TlsConnection) GetProtocolVersion() TlsProtocolVersion {
401
402 cret := xTlsConnectionGetProtocolVersion(x.GoPointer())
403 return cret
404}
405
406var xTlsConnectionGetRehandshakeMode func(uintptr) TlsRehandshakeMode
407
408// Gets @conn rehandshaking mode. See
409// g_tls_connection_set_rehandshake_mode() for details.
410func (x *TlsConnection) GetRehandshakeMode() TlsRehandshakeMode {
411
412 cret := xTlsConnectionGetRehandshakeMode(x.GoPointer())
413 return cret
414}
415
416var xTlsConnectionGetRequireCloseNotify func(uintptr) bool
417
418// Tests whether or not @conn expects a proper TLS close notification
419// when the connection is closed. See
420// g_tls_connection_set_require_close_notify() for details.
421func (x *TlsConnection) GetRequireCloseNotify() bool {
422
423 cret := xTlsConnectionGetRequireCloseNotify(x.GoPointer())
424 return cret
425}
426
427var xTlsConnectionGetUseSystemCertdb func(uintptr) bool
428
429// Gets whether @conn uses the system certificate database to verify
430// peer certificates. See g_tls_connection_set_use_system_certdb().
431func (x *TlsConnection) GetUseSystemCertdb() bool {
432
433 cret := xTlsConnectionGetUseSystemCertdb(x.GoPointer())
434 return cret
435}
436
437var xTlsConnectionHandshake func(uintptr, uintptr, **glib.Error) bool
438
439// Attempts a TLS handshake on @conn.
440//
441// On the client side, it is never necessary to call this method;
442// although the connection needs to perform a handshake after
443// connecting (or after sending a "STARTTLS"-type command),
444// #GTlsConnection will handle this for you automatically when you try
445// to send or receive data on the connection. You can call
446// g_tls_connection_handshake() manually if you want to know whether
447// the initial handshake succeeded or failed (as opposed to just
448// immediately trying to use @conn to read or write, in which case,
449// if it fails, it may not be possible to tell if it failed before or
450// after completing the handshake), but beware that servers may reject
451// client authentication after the handshake has completed, so a
452// successful handshake does not indicate the connection will be usable.
453//
454// Likewise, on the server side, although a handshake is necessary at
455// the beginning of the communication, you do not need to call this
456// function explicitly unless you want clearer error reporting.
457//
458// Previously, calling g_tls_connection_handshake() after the initial
459// handshake would trigger a rehandshake; however, this usage was
460// deprecated in GLib 2.60 because rehandshaking was removed from the
461// TLS protocol in TLS 1.3. Since GLib 2.64, calling this function after
462// the initial handshake will no longer do anything.
463//
464// When using a #GTlsConnection created by #GSocketClient, the
465// #GSocketClient performs the initial handshake, so calling this
466// function manually is not recommended.
467//
468// #GTlsConnection::accept_certificate may be emitted during the
469// handshake.
470func (x *TlsConnection) Handshake(CancellableVar *Cancellable) (bool, error) {
471 var cerr *glib.Error
472
473 cret := xTlsConnectionHandshake(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
474 if cerr == nil {
475 return cret, nil
476 }
477 return cret, cerr
478
479}
480
481var xTlsConnectionHandshakeAsync func(uintptr, int, uintptr, uintptr, uintptr)
482
483// Asynchronously performs a TLS handshake on @conn. See
484// g_tls_connection_handshake() for more information.
485func (x *TlsConnection) HandshakeAsync(IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
486
487 var CallbackVarRef uintptr
488 if CallbackVar != nil {
489 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
490 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
491 CallbackVarRef = cbRefPtr
492 } else {
493 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
494 cbFn := *CallbackVar
495 cbFn(arg0, arg1, arg2)
496 }
497 CallbackVarRef = purego.NewCallback(fcb)
498 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
499 }
500 }
501
502 xTlsConnectionHandshakeAsync(x.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
503
504}
505
506var xTlsConnectionHandshakeFinish func(uintptr, uintptr, **glib.Error) bool
507
508// Finish an asynchronous TLS handshake operation. See
509// g_tls_connection_handshake() for more information.
510func (x *TlsConnection) HandshakeFinish(ResultVar AsyncResult) (bool, error) {
511 var cerr *glib.Error
512
513 cret := xTlsConnectionHandshakeFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
514 if cerr == nil {
515 return cret, nil
516 }
517 return cret, cerr
518
519}
520
521var xTlsConnectionSetAdvertisedProtocols func(uintptr, []string)
522
523// Sets the list of application-layer protocols to advertise that the
524// caller is willing to speak on this connection. The
525// Application-Layer Protocol Negotiation (ALPN) extension will be
526// used to negotiate a compatible protocol with the peer; use
527// g_tls_connection_get_negotiated_protocol() to find the negotiated
528// protocol after the handshake. Specifying %NULL for the the value
529// of @protocols will disable ALPN negotiation.
530//
531// See [IANA TLS ALPN Protocol IDs](https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)
532// for a list of registered protocol IDs.
533func (x *TlsConnection) SetAdvertisedProtocols(ProtocolsVar []string) {
534
535 xTlsConnectionSetAdvertisedProtocols(x.GoPointer(), ProtocolsVar)
536
537}
538
539var xTlsConnectionSetCertificate func(uintptr, uintptr)
540
541// This sets the certificate that @conn will present to its peer
542// during the TLS handshake. For a #GTlsServerConnection, it is
543// mandatory to set this, and that will normally be done at construct
544// time.
545//
546// For a #GTlsClientConnection, this is optional. If a handshake fails
547// with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
548// requires a certificate, and if you try connecting again, you should
549// call this method first. You can call
550// g_tls_client_connection_get_accepted_cas() on the failed connection
551// to get a list of Certificate Authorities that the server will
552// accept certificates from.
553//
554// (It is also possible that a server will allow the connection with
555// or without a certificate; in that case, if you don't provide a
556// certificate, you can tell that the server requested one by the fact
557// that g_tls_client_connection_get_accepted_cas() will return
558// non-%NULL.)
559func (x *TlsConnection) SetCertificate(CertificateVar *TlsCertificate) {
560
561 xTlsConnectionSetCertificate(x.GoPointer(), CertificateVar.GoPointer())
562
563}
564
565var xTlsConnectionSetDatabase func(uintptr, uintptr)
566
567// Sets the certificate database that is used to verify peer certificates.
568// This is set to the default database by default. See
569// g_tls_backend_get_default_database(). If set to %NULL, then
570// peer certificate validation will always set the
571// %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
572// #GTlsConnection::accept-certificate will always be emitted on
573// client-side connections, unless that bit is not set in
574// #GTlsClientConnection:validation-flags).
575//
576// There are nonintuitive security implications when using a non-default
577// database. See #GTlsConnection:database for details.
578func (x *TlsConnection) SetDatabase(DatabaseVar *TlsDatabase) {
579
580 xTlsConnectionSetDatabase(x.GoPointer(), DatabaseVar.GoPointer())
581
582}
583
584var xTlsConnectionSetInteraction func(uintptr, uintptr)
585
586// Set the object that will be used to interact with the user. It will be used
587// for things like prompting the user for passwords.
588//
589// The @interaction argument will normally be a derived subclass of
590// #GTlsInteraction. %NULL can also be provided if no user interaction
591// should occur for this connection.
592func (x *TlsConnection) SetInteraction(InteractionVar *TlsInteraction) {
593
594 xTlsConnectionSetInteraction(x.GoPointer(), InteractionVar.GoPointer())
595
596}
597
598var xTlsConnectionSetRehandshakeMode func(uintptr, TlsRehandshakeMode)
599
600// Since GLib 2.64, changing the rehandshake mode is no longer supported
601// and will have no effect. With TLS 1.3, rehandshaking has been removed from
602// the TLS protocol, replaced by separate post-handshake authentication and
603// rekey operations.
604func (x *TlsConnection) SetRehandshakeMode(ModeVar TlsRehandshakeMode) {
605
606 xTlsConnectionSetRehandshakeMode(x.GoPointer(), ModeVar)
607
608}
609
610var xTlsConnectionSetRequireCloseNotify func(uintptr, bool)
611
612// Sets whether or not @conn expects a proper TLS close notification
613// before the connection is closed. If this is %TRUE (the default),
614// then @conn will expect to receive a TLS close notification from its
615// peer before the connection is closed, and will return a
616// %G_TLS_ERROR_EOF error if the connection is closed without proper
617// notification (since this may indicate a network error, or
618// man-in-the-middle attack).
619//
620// In some protocols, the application will know whether or not the
621// connection was closed cleanly based on application-level data
622// (because the application-level data includes a length field, or is
623// somehow self-delimiting); in this case, the close notify is
624// redundant and sometimes omitted. (TLS 1.1 explicitly allows this;
625// in TLS 1.0 it is technically an error, but often done anyway.) You
626// can use g_tls_connection_set_require_close_notify() to tell @conn
627// to allow an "unannounced" connection close, in which case the close
628// will show up as a 0-length read, as in a non-TLS
629// #GSocketConnection, and it is up to the application to check that
630// the data has been fully received.
631//
632// Note that this only affects the behavior when the peer closes the
633// connection; when the application calls g_io_stream_close() itself
634// on @conn, this will send a close notification regardless of the
635// setting of this property. If you explicitly want to do an unclean
636// close, you can close @conn's #GTlsConnection:base-io-stream rather
637// than closing @conn itself, but note that this may only be done when no other
638// operations are pending on @conn or the base I/O stream.
639func (x *TlsConnection) SetRequireCloseNotify(RequireCloseNotifyVar bool) {
640
641 xTlsConnectionSetRequireCloseNotify(x.GoPointer(), RequireCloseNotifyVar)
642
643}
644
645var xTlsConnectionSetUseSystemCertdb func(uintptr, bool)
646
647// Sets whether @conn uses the system certificate database to verify
648// peer certificates. This is %TRUE by default. If set to %FALSE, then
649// peer certificate validation will always set the
650// %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
651// #GTlsConnection::accept-certificate will always be emitted on
652// client-side connections, unless that bit is not set in
653// #GTlsClientConnection:validation-flags).
654func (x *TlsConnection) SetUseSystemCertdb(UseSystemCertdbVar bool) {
655
656 xTlsConnectionSetUseSystemCertdb(x.GoPointer(), UseSystemCertdbVar)
657
658}
659
660func (c *TlsConnection) GoPointer() uintptr {
661 if c == nil {
662 return 0
663 }
664 return c.Ptr
665}
666
667func (c *TlsConnection) SetGoPointer(ptr uintptr) {
668 c.Ptr = ptr
669}
670
671// SetPropertyAdvertisedProtocols sets the "advertised-protocols" property.
672// The list of application-layer protocols that the connection
673// advertises that it is willing to speak. See
674// g_tls_connection_set_advertised_protocols().
675func (x *TlsConnection) SetPropertyAdvertisedProtocols(value []string) {
676 var v gobject.Value
677 v.Init(glib.StrvGetType())
678 v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))
679 x.SetProperty("advertised-protocols", &v)
680}
681
682// GetPropertyAdvertisedProtocols gets the "advertised-protocols" property.
683// The list of application-layer protocols that the connection
684// advertises that it is willing to speak. See
685// g_tls_connection_set_advertised_protocols().
686func (x *TlsConnection) GetPropertyAdvertisedProtocols() []string {
687 var v gobject.Value
688 x.GetProperty("advertised-protocols", &v)
689 return core.GoStringSlice(v.GetBoxed())
690}
691
692// GetPropertyCiphersuiteName gets the "ciphersuite-name" property.
693// The name of the TLS ciphersuite in use. See g_tls_connection_get_ciphersuite_name().
694func (x *TlsConnection) GetPropertyCiphersuiteName() string {
695 var v gobject.Value
696 x.GetProperty("ciphersuite-name", &v)
697 return v.GetString()
698}
699
700// GetPropertyNegotiatedProtocol gets the "negotiated-protocol" property.
701// The application-layer protocol negotiated during the TLS
702// handshake. See g_tls_connection_get_negotiated_protocol().
703func (x *TlsConnection) GetPropertyNegotiatedProtocol() string {
704 var v gobject.Value
705 x.GetProperty("negotiated-protocol", &v)
706 return v.GetString()
707}
708
709// SetPropertyRequireCloseNotify sets the "require-close-notify" property.
710// Whether or not proper TLS close notification is required.
711// See g_tls_connection_set_require_close_notify().
712func (x *TlsConnection) SetPropertyRequireCloseNotify(value bool) {
713 var v gobject.Value
714 v.Init(gobject.TypeBooleanVal)
715 v.SetBoolean(value)
716 x.SetProperty("require-close-notify", &v)
717}
718
719// GetPropertyRequireCloseNotify gets the "require-close-notify" property.
720// Whether or not proper TLS close notification is required.
721// See g_tls_connection_set_require_close_notify().
722func (x *TlsConnection) GetPropertyRequireCloseNotify() bool {
723 var v gobject.Value
724 x.GetProperty("require-close-notify", &v)
725 return v.GetBoolean()
726}
727
728// SetPropertyUseSystemCertdb sets the "use-system-certdb" property.
729// Whether or not the system certificate database will be used to
730// verify peer certificates. See
731// g_tls_connection_set_use_system_certdb().
732func (x *TlsConnection) SetPropertyUseSystemCertdb(value bool) {
733 var v gobject.Value
734 v.Init(gobject.TypeBooleanVal)
735 v.SetBoolean(value)
736 x.SetProperty("use-system-certdb", &v)
737}
738
739// GetPropertyUseSystemCertdb gets the "use-system-certdb" property.
740// Whether or not the system certificate database will be used to
741// verify peer certificates. See
742// g_tls_connection_set_use_system_certdb().
743func (x *TlsConnection) GetPropertyUseSystemCertdb() bool {
744 var v gobject.Value
745 x.GetProperty("use-system-certdb", &v)
746 return v.GetBoolean()
747}
748
749// Emitted during the TLS handshake after the peer certificate has
750// been received. You can examine @peer_cert's certification path by
751// calling g_tls_certificate_get_issuer() on it.
752//
753// For a client-side connection, @peer_cert is the server's
754// certificate, and the signal will only be emitted if the
755// certificate was not acceptable according to @conn's
756// #GTlsClientConnection:validation_flags. If you would like the
757// certificate to be accepted despite @errors, return %TRUE from the
758// signal handler. Otherwise, if no handler accepts the certificate,
759// the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
760//
761// GLib guarantees that if certificate verification fails, this signal
762// will be emitted with at least one error will be set in @errors, but
763// it does not guarantee that all possible errors will be set.
764// Accordingly, you may not safely decide to ignore any particular
765// type of error. For example, it would be incorrect to ignore
766// %G_TLS_CERTIFICATE_EXPIRED if you want to allow expired
767// certificates, because this could potentially be the only error flag
768// set even if other problems exist with the certificate.
769//
770// For a server-side connection, @peer_cert is the certificate
771// presented by the client, if this was requested via the server's
772// #GTlsServerConnection:authentication_mode. On the server side,
773// the signal is always emitted when the client presents a
774// certificate, and the certificate will only be accepted if a
775// handler returns %TRUE.
776//
777// Note that if this signal is emitted as part of asynchronous I/O
778// in the main thread, then you should not attempt to interact with
779// the user before returning from the signal handler. If you want to
780// let the user decide whether or not to accept the certificate, you
781// would have to return %FALSE from the signal handler on the first
782// attempt, and then after the connection attempt returns a
783// %G_TLS_ERROR_BAD_CERTIFICATE, you can interact with the user, and
784// if the user decides to accept the certificate, remember that fact,
785// create a new connection, and return %TRUE from the signal handler
786// the next time.
787//
788// If you are doing I/O in another thread, you do not
789// need to worry about this, and can simply block in the signal
790// handler until the UI thread returns an answer.
791func (x *TlsConnection) ConnectAcceptCertificate(cb *func(TlsConnection, uintptr, TlsCertificateFlags) bool) uint {
792 cbPtr := uintptr(unsafe.Pointer(cb))
793 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
794 handlerID := gobject.SignalConnect(x.GoPointer(), "accept-certificate", cbRefPtr)
795 glib.SaveHandlerMapping(handlerID, cbPtr)
796 return handlerID
797 }
798
799 fcb := func(clsPtr uintptr, PeerCertVarp uintptr, ErrorsVarp TlsCertificateFlags) bool {
800 fa := TlsConnection{}
801 fa.Ptr = clsPtr
802 cbFn := *cb
803
804 return cbFn(fa, PeerCertVarp, ErrorsVarp)
805
806 }
807 cbRefPtr := purego.NewCallback(fcb)
808 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
809 handlerID := gobject.SignalConnect(x.GoPointer(), "accept-certificate", cbRefPtr)
810 glib.SaveHandlerMapping(handlerID, cbPtr)
811 return handlerID
812}
813
814func init() {
815 core.SetPackageName("GIO", "gio-2.0")
816 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
817 var libs []uintptr
818 for _, libPath := range core.GetPaths("GIO") {
819 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
820 if err != nil {
821 panic(err)
822 }
823 libs = append(libs, lib)
824 }
825
826 core.PuregoSafeRegister(&xTlsChannelBindingErrorQuark, libs, "g_tls_channel_binding_error_quark")
827 core.PuregoSafeRegister(&xTlsErrorQuark, libs, "g_tls_error_quark")
828
829 core.PuregoSafeRegister(&xTlsConnectionGLibType, libs, "g_tls_connection_get_type")
830
831 core.PuregoSafeRegister(&xTlsConnectionEmitAcceptCertificate, libs, "g_tls_connection_emit_accept_certificate")
832 core.PuregoSafeRegister(&xTlsConnectionGetCertificate, libs, "g_tls_connection_get_certificate")
833 core.PuregoSafeRegister(&xTlsConnectionGetChannelBindingData, libs, "g_tls_connection_get_channel_binding_data")
834 core.PuregoSafeRegister(&xTlsConnectionGetCiphersuiteName, libs, "g_tls_connection_get_ciphersuite_name")
835 core.PuregoSafeRegister(&xTlsConnectionGetDatabase, libs, "g_tls_connection_get_database")
836 core.PuregoSafeRegister(&xTlsConnectionGetInteraction, libs, "g_tls_connection_get_interaction")
837 core.PuregoSafeRegister(&xTlsConnectionGetNegotiatedProtocol, libs, "g_tls_connection_get_negotiated_protocol")
838 core.PuregoSafeRegister(&xTlsConnectionGetPeerCertificate, libs, "g_tls_connection_get_peer_certificate")
839 core.PuregoSafeRegister(&xTlsConnectionGetPeerCertificateErrors, libs, "g_tls_connection_get_peer_certificate_errors")
840 core.PuregoSafeRegister(&xTlsConnectionGetProtocolVersion, libs, "g_tls_connection_get_protocol_version")
841 core.PuregoSafeRegister(&xTlsConnectionGetRehandshakeMode, libs, "g_tls_connection_get_rehandshake_mode")
842 core.PuregoSafeRegister(&xTlsConnectionGetRequireCloseNotify, libs, "g_tls_connection_get_require_close_notify")
843 core.PuregoSafeRegister(&xTlsConnectionGetUseSystemCertdb, libs, "g_tls_connection_get_use_system_certdb")
844 core.PuregoSafeRegister(&xTlsConnectionHandshake, libs, "g_tls_connection_handshake")
845 core.PuregoSafeRegister(&xTlsConnectionHandshakeAsync, libs, "g_tls_connection_handshake_async")
846 core.PuregoSafeRegister(&xTlsConnectionHandshakeFinish, libs, "g_tls_connection_handshake_finish")
847 core.PuregoSafeRegister(&xTlsConnectionSetAdvertisedProtocols, libs, "g_tls_connection_set_advertised_protocols")
848 core.PuregoSafeRegister(&xTlsConnectionSetCertificate, libs, "g_tls_connection_set_certificate")
849 core.PuregoSafeRegister(&xTlsConnectionSetDatabase, libs, "g_tls_connection_set_database")
850 core.PuregoSafeRegister(&xTlsConnectionSetInteraction, libs, "g_tls_connection_set_interaction")
851 core.PuregoSafeRegister(&xTlsConnectionSetRehandshakeMode, libs, "g_tls_connection_set_rehandshake_mode")
852 core.PuregoSafeRegister(&xTlsConnectionSetRequireCloseNotify, libs, "g_tls_connection_set_require_close_notify")
853 core.PuregoSafeRegister(&xTlsConnectionSetUseSystemCertdb, libs, "g_tls_connection_set_use_system_certdb")
854
855}