1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
use crate::InetAddress;
use crate::SocketConnectable;
use crate::TlsCertificateFlags;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
use glib::object::Cast;
use glib::object::IsA;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
use glib::signal::connect_raw;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
use std::boxed::Box as Box_;
use std::fmt;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
use std::mem::transmute;
use std::ptr;
glib::wrapper! {
/// A certificate used for TLS authentication and encryption.
/// This can represent either a certificate only (eg, the certificate
/// received by a client from a server), or the combination of
/// a certificate and a private key (which is needed when acting as a
/// [`TlsServerConnection`][crate::TlsServerConnection]).
///
/// This is an Abstract Base Class, you cannot instantiate it.
///
/// # Implements
///
/// [`TlsCertificateExt`][trait@crate::prelude::TlsCertificateExt], [`trait@glib::ObjectExt`]
#[doc(alias = "GTlsCertificate")]
pub struct TlsCertificate(Object<ffi::GTlsCertificate, ffi::GTlsCertificateClass>);
match fn {
type_ => || ffi::g_tls_certificate_get_type(),
}
}
impl TlsCertificate {
pub const NONE: Option<&'static TlsCertificate> = None;
/// Creates a [`TlsCertificate`][crate::TlsCertificate] from the data in `file`.
///
/// As of 2.72, if the filename ends in `.p12` or `.pfx` the data is loaded by
/// [`from_pkcs12()`][Self::from_pkcs12()] otherwise it is loaded by
/// [`from_pem()`][Self::from_pem()]. See those functions for
/// exact details.
///
/// If `file` cannot be read or parsed, the function will return [`None`] and
/// set `error`.
/// ## `file`
/// file containing a certificate to import
///
/// # Returns
///
/// the new certificate, or [`None`] on error
#[doc(alias = "g_tls_certificate_new_from_file")]
#[doc(alias = "new_from_file")]
pub fn from_file(file: impl AsRef<std::path::Path>) -> Result<TlsCertificate, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret =
ffi::g_tls_certificate_new_from_file(file.as_ref().to_glib_none().0, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Creates a [`TlsCertificate`][crate::TlsCertificate] from the data in `file`.
///
/// If `file` cannot be read or parsed, the function will return [`None`] and
/// set `error`.
///
/// Any unknown file types will error with [`IOErrorEnum::NotSupported`][crate::IOErrorEnum::NotSupported].
/// Currently only `.p12` and `.pfx` files are supported.
/// See [`from_pkcs12()`][Self::from_pkcs12()] for more details.
/// ## `file`
/// file containing a certificate to import
/// ## `password`
/// password for PKCS `12` files
///
/// # Returns
///
/// the new certificate, or [`None`] on error
#[cfg(any(feature = "v2_72", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_72")))]
#[doc(alias = "g_tls_certificate_new_from_file_with_password")]
#[doc(alias = "new_from_file_with_password")]
pub fn from_file_with_password(
file: impl AsRef<std::path::Path>,
password: &str,
) -> Result<TlsCertificate, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_tls_certificate_new_from_file_with_password(
file.as_ref().to_glib_none().0,
password.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Creates a [`TlsCertificate`][crate::TlsCertificate] from the PEM-encoded data in `cert_file`
/// and `key_file`. The returned certificate will be the first certificate
/// found in `cert_file`. As of GLib 2.44, if `cert_file` contains more
/// certificates it will try to load a certificate chain. All
/// certificates will be verified in the order found (top-level
/// certificate should be the last one in the file) and the
/// `property::TlsCertificate::issuer` property of each certificate will be set
/// accordingly if the verification succeeds. If any certificate in the
/// chain cannot be verified, the first certificate in the file will
/// still be returned.
///
/// If either file cannot be read or parsed, the function will return
/// [`None`] and set `error`. Otherwise, this behaves like
/// [`from_pem()`][Self::from_pem()].
/// ## `cert_file`
/// file containing one or more PEM-encoded
/// certificates to import
/// ## `key_file`
/// file containing a PEM-encoded private key
/// to import
///
/// # Returns
///
/// the new certificate, or [`None`] on error
#[doc(alias = "g_tls_certificate_new_from_files")]
#[doc(alias = "new_from_files")]
pub fn from_files(
cert_file: impl AsRef<std::path::Path>,
key_file: impl AsRef<std::path::Path>,
) -> Result<TlsCertificate, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_tls_certificate_new_from_files(
cert_file.as_ref().to_glib_none().0,
key_file.as_ref().to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Creates a [`TlsCertificate`][crate::TlsCertificate] from the PEM-encoded data in `data`. If
/// `data` includes both a certificate and a private key, then the
/// returned certificate will include the private key data as well. (See
/// the `property::TlsCertificate::private-key-pem` property for information about
/// supported formats.)
///
/// The returned certificate will be the first certificate found in
/// `data`. As of GLib 2.44, if `data` contains more certificates it will
/// try to load a certificate chain. All certificates will be verified in
/// the order found (top-level certificate should be the last one in the
/// file) and the `property::TlsCertificate::issuer` property of each certificate
/// will be set accordingly if the verification succeeds. If any
/// certificate in the chain cannot be verified, the first certificate in
/// the file will still be returned.
/// ## `data`
/// PEM-encoded certificate data
/// ## `length`
/// the length of `data`, or -1 if it's 0-terminated.
///
/// # Returns
///
/// the new certificate, or [`None`] if `data` is invalid
#[doc(alias = "g_tls_certificate_new_from_pem")]
#[doc(alias = "new_from_pem")]
pub fn from_pem(data: &str) -> Result<TlsCertificate, glib::Error> {
let length = data.len() as _;
unsafe {
let mut error = ptr::null_mut();
let ret =
ffi::g_tls_certificate_new_from_pem(data.to_glib_none().0, length, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Creates a [`TlsCertificate`][crate::TlsCertificate] from a
/// [PKCS \`11`](https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/os/pkcs11-base-v3.0-os.html) URI.
///
/// An example `pkcs11_uri` would be `pkcs11:model=Model;manufacturer=Manufacture;serial=1;token=My`20Client``20Certificate`;id=`01``
///
/// Where the token’s layout is:
///
///
/// ```text
/// Object 0:
/// URL: pkcs11:model=Model;manufacturer=Manufacture;serial=1;token=My%20Client%20Certificate;id=%01;object=private%20key;type=private
/// Type: Private key (RSA-2048)
/// ID: 01
///
/// Object 1:
/// URL: pkcs11:model=Model;manufacturer=Manufacture;serial=1;token=My%20Client%20Certificate;id=%01;object=Certificate%20for%20Authentication;type=cert
/// Type: X.509 Certificate (RSA-2048)
/// ID: 01
/// ```
///
/// In this case the certificate and private key would both be detected and used as expected.
/// `pkcs_uri` may also just reference an X.509 certificate object and then optionally
/// `private_key_pkcs11_uri` allows using a private key exposed under a different URI.
///
/// Note that the private key is not accessed until usage and may fail or require a PIN later.
/// ## `pkcs11_uri`
/// A PKCS \`11` URI
/// ## `private_key_pkcs11_uri`
/// A PKCS \`11` URI
///
/// # Returns
///
/// the new certificate, or [`None`] on error
#[cfg(any(feature = "v2_68", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_68")))]
#[doc(alias = "g_tls_certificate_new_from_pkcs11_uris")]
#[doc(alias = "new_from_pkcs11_uris")]
pub fn from_pkcs11_uris(
pkcs11_uri: &str,
private_key_pkcs11_uri: Option<&str>,
) -> Result<TlsCertificate, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_tls_certificate_new_from_pkcs11_uris(
pkcs11_uri.to_glib_none().0,
private_key_pkcs11_uri.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Creates a [`TlsCertificate`][crate::TlsCertificate] from the data in `data`. It must contain
/// a certificate and matching private key.
///
/// If extra certificates are included they will be verified as a chain
/// and the `property::TlsCertificate::issuer` property will be set.
/// All other data will be ignored.
///
/// You can pass as single password for all of the data which will be
/// used both for the PKCS `12` container as well as encrypted
/// private keys. If decryption fails it will error with
/// [`TlsError::BadCertificatePassword`][crate::TlsError::BadCertificatePassword].
///
/// This constructor requires support in the current [`TlsBackend`][crate::TlsBackend].
/// If support is missing it will error with
/// [`IOErrorEnum::NotSupported`][crate::IOErrorEnum::NotSupported].
///
/// Other parsing failures will error with [`TlsError::BadCertificate`][crate::TlsError::BadCertificate].
/// ## `data`
/// DER-encoded PKCS `12` format certificate data
/// ## `password`
/// optional password for encrypted certificate data
///
/// # Returns
///
/// the new certificate, or [`None`] if `data` is invalid
#[cfg(any(feature = "v2_72", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_72")))]
#[doc(alias = "g_tls_certificate_new_from_pkcs12")]
#[doc(alias = "new_from_pkcs12")]
pub fn from_pkcs12(data: &[u8], password: Option<&str>) -> Result<TlsCertificate, glib::Error> {
let length = data.len() as _;
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_tls_certificate_new_from_pkcs12(
data.to_glib_none().0,
length,
password.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Creates one or more `GTlsCertificates` from the PEM-encoded
/// data in `file`. If `file` cannot be read or parsed, the function will
/// return [`None`] and set `error`. If `file` does not contain any
/// PEM-encoded certificates, this will return an empty list and not
/// set `error`.
/// ## `file`
/// file containing PEM-encoded certificates to import
///
/// # Returns
///
/// a
/// `GList` containing [`TlsCertificate`][crate::TlsCertificate] objects. You must free the list
/// and its contents when you are done with it.
#[doc(alias = "g_tls_certificate_list_new_from_file")]
pub fn list_new_from_file(
file: impl AsRef<std::path::Path>,
) -> Result<Vec<TlsCertificate>, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_tls_certificate_list_new_from_file(
file.as_ref().to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(FromGlibPtrContainer::from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
}
/// Trait containing all [`struct@TlsCertificate`] methods.
///
/// # Implementors
///
/// [`TlsCertificate`][struct@crate::TlsCertificate]
pub trait TlsCertificateExt: 'static {
/// Gets the value of `property::TlsCertificate::dns-names`.
///
/// # Returns
///
/// A `GPtrArray` of
/// [`glib::Bytes`][crate::glib::Bytes] elements, or [`None`] if it's not available.
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_tls_certificate_get_dns_names")]
#[doc(alias = "get_dns_names")]
fn dns_names(&self) -> Vec<glib::Bytes>;
/// Gets the value of `property::TlsCertificate::ip-addresses`.
///
/// # Returns
///
/// A `GPtrArray`
/// of [`InetAddress`][crate::InetAddress] elements, or [`None`] if it's not available.
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_tls_certificate_get_ip_addresses")]
#[doc(alias = "get_ip_addresses")]
fn ip_addresses(&self) -> Vec<InetAddress>;
/// Gets the [`TlsCertificate`][crate::TlsCertificate] representing `self`'s issuer, if known
///
/// # Returns
///
/// The certificate of `self`'s issuer,
/// or [`None`] if `self` is self-signed or signed with an unknown
/// certificate.
#[doc(alias = "g_tls_certificate_get_issuer")]
#[doc(alias = "get_issuer")]
#[must_use]
fn issuer(&self) -> Option<TlsCertificate>;
/// Returns the issuer name from the certificate.
///
/// # Returns
///
/// The issuer name, or [`None`] if it's not available.
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_tls_certificate_get_issuer_name")]
#[doc(alias = "get_issuer_name")]
fn issuer_name(&self) -> Option<glib::GString>;
/// Returns the time at which the certificate became or will become invalid.
///
/// # Returns
///
/// The not-valid-after date, or [`None`] if it's not available.
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_tls_certificate_get_not_valid_after")]
#[doc(alias = "get_not_valid_after")]
fn not_valid_after(&self) -> Option<glib::DateTime>;
/// Returns the time at which the certificate became or will become valid.
///
/// # Returns
///
/// The not-valid-before date, or [`None`] if it's not available.
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_tls_certificate_get_not_valid_before")]
#[doc(alias = "get_not_valid_before")]
fn not_valid_before(&self) -> Option<glib::DateTime>;
/// Returns the subject name from the certificate.
///
/// # Returns
///
/// The subject name, or [`None`] if it's not available.
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "g_tls_certificate_get_subject_name")]
#[doc(alias = "get_subject_name")]
fn subject_name(&self) -> Option<glib::GString>;
/// Check if two [`TlsCertificate`][crate::TlsCertificate] objects represent the same certificate.
/// The raw DER byte data of the two certificates are checked for equality.
/// This has the effect that two certificates may compare equal even if
/// their `property::TlsCertificate::issuer`, `property::TlsCertificate::private-key`, or
/// `property::TlsCertificate::private-key-pem` properties differ.
/// ## `cert_two`
/// second certificate to compare
///
/// # Returns
///
/// whether the same or not
#[doc(alias = "g_tls_certificate_is_same")]
fn is_same(&self, cert_two: &impl IsA<TlsCertificate>) -> bool;
/// This verifies `self` and returns a set of [`TlsCertificateFlags`][crate::TlsCertificateFlags]
/// indicating any problems found with it. This can be used to verify a
/// certificate outside the context of making a connection, or to
/// check a certificate against a CA that is not part of the system
/// CA database.
///
/// If `self` is valid, `G_TLS_CERTIFICATE_NO_FLAGS` is returned.
///
/// If `identity` is not [`None`], `self`'s name(s) will be compared against
/// it, and [`TlsCertificateFlags::BAD_IDENTITY`][crate::TlsCertificateFlags::BAD_IDENTITY] will be set in the return
/// value if it does not match. If `identity` is [`None`], that bit will
/// never be set in the return value.
///
/// If `trusted_ca` is not [`None`], then `self` (or one of the certificates
/// in its chain) must be signed by it, or else
/// [`TlsCertificateFlags::UNKNOWN_CA`][crate::TlsCertificateFlags::UNKNOWN_CA] will be set in the return value. If
/// `trusted_ca` is [`None`], that bit will never be set in the return
/// value.
///
/// GLib guarantees that if certificate verification fails, at least one
/// error will be set in the return value, but it does not guarantee
/// that all possible errors will be set. Accordingly, you may not safely
/// decide to ignore any particular type of error. For example, it would
/// be incorrect to mask [`TlsCertificateFlags::EXPIRED`][crate::TlsCertificateFlags::EXPIRED] if you want to allow
/// expired certificates, because this could potentially be the only
/// error flag set even if other problems exist with the certificate.
///
/// Because TLS session context is not used, [`TlsCertificate`][crate::TlsCertificate] may not
/// perform as many checks on the certificates as [`TlsConnection`][crate::TlsConnection] would.
/// For example, certificate constraints may not be honored, and
/// revocation checks may not be performed. The best way to verify TLS
/// certificates used by a TLS connection is to let [`TlsConnection`][crate::TlsConnection]
/// handle the verification.
/// ## `identity`
/// the expected peer identity
/// ## `trusted_ca`
/// the certificate of a trusted authority
///
/// # Returns
///
/// the appropriate [`TlsCertificateFlags`][crate::TlsCertificateFlags]
#[doc(alias = "g_tls_certificate_verify")]
fn verify(
&self,
identity: Option<&impl IsA<SocketConnectable>>,
trusted_ca: Option<&impl IsA<TlsCertificate>>,
) -> TlsCertificateFlags;
/// The DER (binary) encoded representation of the certificate.
/// This property and the `property::TlsCertificate::certificate-pem` property
/// represent the same data, just in different forms.
fn certificate(&self) -> Option<glib::ByteArray>;
/// The PEM (ASCII) encoded representation of the certificate.
/// This property and the `property::TlsCertificate::certificate`
/// property represent the same data, just in different forms.
#[doc(alias = "certificate-pem")]
fn certificate_pem(&self) -> Option<glib::GString>;
/// A URI referencing the [PKCS \`11`](https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/os/pkcs11-base-v3.0-os.html)
/// objects containing an X.509 certificate and optionally a private key.
///
/// If [`None`], the certificate is either not backed by PKCS \`11` or the
/// [`TlsBackend`][crate::TlsBackend] does not support PKCS \`11`.
#[cfg(any(feature = "v2_68", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_68")))]
#[doc(alias = "pkcs11-uri")]
fn pkcs11_uri(&self) -> Option<glib::GString>;
/// The DER (binary) encoded representation of the certificate's
/// private key, in either [PKCS \`1` format](https://datatracker.ietf.org/doc/html/rfc8017)
/// or unencrypted [PKCS \`8` format.](https://datatracker.ietf.org/doc/html/rfc5208)
/// PKCS \`8` format is supported since 2.32; earlier releases only
/// support PKCS \`1`. You can use the `openssl rsa` tool to convert
/// PKCS \`8` keys to PKCS \`1`.
///
/// This property (or the `property::TlsCertificate::private-key-pem` property)
/// can be set when constructing a key (for example, from a file).
/// Since GLib 2.70, it is now also readable; however, be aware that if
/// the private key is backed by a PKCS \`11` URI – for example, if it
/// is stored on a smartcard – then this property will be [`None`]. If so,
/// the private key must be referenced via its PKCS \`11` URI,
/// `property::TlsCertificate::private-key-pkcs11-uri`. You must check both
/// properties to see if the certificate really has a private key.
/// When this property is read, the output format will be unencrypted
/// PKCS \`8`.
#[doc(alias = "private-key")]
fn private_key(&self) -> Option<glib::ByteArray>;
/// The PEM (ASCII) encoded representation of the certificate's
/// private key in either [PKCS \`1` format](https://datatracker.ietf.org/doc/html/rfc8017)
/// ("`BEGIN RSA PRIVATE KEY`") or unencrypted
/// [PKCS \`8` format](https://datatracker.ietf.org/doc/html/rfc5208)
/// ("`BEGIN PRIVATE KEY`"). PKCS \`8` format is supported since 2.32;
/// earlier releases only support PKCS \`1`. You can use the `openssl rsa`
/// tool to convert PKCS \`8` keys to PKCS \`1`.
///
/// This property (or the `property::TlsCertificate::private-key` property)
/// can be set when constructing a key (for example, from a file).
/// Since GLib 2.70, it is now also readable; however, be aware that if
/// the private key is backed by a PKCS \`11` URI - for example, if it
/// is stored on a smartcard - then this property will be [`None`]. If so,
/// the private key must be referenced via its PKCS \`11` URI,
/// `property::TlsCertificate::private-key-pkcs11-uri`. You must check both
/// properties to see if the certificate really has a private key.
/// When this property is read, the output format will be unencrypted
/// PKCS \`8`.
#[doc(alias = "private-key-pem")]
fn private_key_pem(&self) -> Option<glib::GString>;
/// A URI referencing a [PKCS \`11`](https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/os/pkcs11-base-v3.0-os.html)
/// object containing a private key.
#[cfg(any(feature = "v2_68", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_68")))]
#[doc(alias = "private-key-pkcs11-uri")]
fn private_key_pkcs11_uri(&self) -> Option<glib::GString>;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "dns-names")]
fn connect_dns_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "ip-addresses")]
fn connect_ip_addresses_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "issuer-name")]
fn connect_issuer_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "not-valid-after")]
fn connect_not_valid_after_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "not-valid-before")]
fn connect_not_valid_before_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
#[doc(alias = "subject-name")]
fn connect_subject_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<TlsCertificate>> TlsCertificateExt for O {
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn dns_names(&self) -> Vec<glib::Bytes> {
unsafe {
FromGlibPtrContainer::from_glib_container(ffi::g_tls_certificate_get_dns_names(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn ip_addresses(&self) -> Vec<InetAddress> {
unsafe {
FromGlibPtrContainer::from_glib_container(ffi::g_tls_certificate_get_ip_addresses(
self.as_ref().to_glib_none().0,
))
}
}
fn issuer(&self) -> Option<TlsCertificate> {
unsafe {
from_glib_none(ffi::g_tls_certificate_get_issuer(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn issuer_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::g_tls_certificate_get_issuer_name(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn not_valid_after(&self) -> Option<glib::DateTime> {
unsafe {
from_glib_full(ffi::g_tls_certificate_get_not_valid_after(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn not_valid_before(&self) -> Option<glib::DateTime> {
unsafe {
from_glib_full(ffi::g_tls_certificate_get_not_valid_before(
self.as_ref().to_glib_none().0,
))
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn subject_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::g_tls_certificate_get_subject_name(
self.as_ref().to_glib_none().0,
))
}
}
fn is_same(&self, cert_two: &impl IsA<TlsCertificate>) -> bool {
unsafe {
from_glib(ffi::g_tls_certificate_is_same(
self.as_ref().to_glib_none().0,
cert_two.as_ref().to_glib_none().0,
))
}
}
fn verify(
&self,
identity: Option<&impl IsA<SocketConnectable>>,
trusted_ca: Option<&impl IsA<TlsCertificate>>,
) -> TlsCertificateFlags {
unsafe {
from_glib(ffi::g_tls_certificate_verify(
self.as_ref().to_glib_none().0,
identity.map(|p| p.as_ref()).to_glib_none().0,
trusted_ca.map(|p| p.as_ref()).to_glib_none().0,
))
}
}
fn certificate(&self) -> Option<glib::ByteArray> {
glib::ObjectExt::property(self.as_ref(), "certificate")
}
fn certificate_pem(&self) -> Option<glib::GString> {
glib::ObjectExt::property(self.as_ref(), "certificate-pem")
}
#[cfg(any(feature = "v2_68", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_68")))]
fn pkcs11_uri(&self) -> Option<glib::GString> {
glib::ObjectExt::property(self.as_ref(), "pkcs11-uri")
}
fn private_key(&self) -> Option<glib::ByteArray> {
glib::ObjectExt::property(self.as_ref(), "private-key")
}
fn private_key_pem(&self) -> Option<glib::GString> {
glib::ObjectExt::property(self.as_ref(), "private-key-pem")
}
#[cfg(any(feature = "v2_68", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_68")))]
fn private_key_pkcs11_uri(&self) -> Option<glib::GString> {
glib::ObjectExt::property(self.as_ref(), "private-key-pkcs11-uri")
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn connect_dns_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_dns_names_trampoline<
P: IsA<TlsCertificate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GTlsCertificate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TlsCertificate::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::dns-names\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_dns_names_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn connect_ip_addresses_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_ip_addresses_trampoline<
P: IsA<TlsCertificate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GTlsCertificate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TlsCertificate::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::ip-addresses\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_ip_addresses_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn connect_issuer_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_issuer_name_trampoline<
P: IsA<TlsCertificate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GTlsCertificate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TlsCertificate::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::issuer-name\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_issuer_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn connect_not_valid_after_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_not_valid_after_trampoline<
P: IsA<TlsCertificate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GTlsCertificate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TlsCertificate::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::not-valid-after\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_not_valid_after_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn connect_not_valid_before_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_not_valid_before_trampoline<
P: IsA<TlsCertificate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GTlsCertificate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TlsCertificate::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::not-valid-before\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_not_valid_before_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v2_70", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
fn connect_subject_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_subject_name_trampoline<
P: IsA<TlsCertificate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GTlsCertificate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TlsCertificate::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::subject-name\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_subject_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for TlsCertificate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("TlsCertificate")
}
}