Mercurial > pidgin
comparison libpurple/plugins/ssl/ssl-gnutls.c @ 18963:146907cd3b07
- Add subject_name (AKA Common Name) functions to GnuTLS x509 scheme
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Wed, 27 Jun 2007 03:51:36 +0000 |
parents | fa138dbacff5 |
children | 31bdbb82de7e |
comparison
equal
deleted
inserted
replaced
18962:fcd05c39803e | 18963:146907cd3b07 |
---|---|
541 /* TODO: Change this error checking? */ | 541 /* TODO: Change this error checking? */ |
542 g_return_val_if_fail(crt, FALSE); | 542 g_return_val_if_fail(crt, FALSE); |
543 g_return_val_if_fail(issuer, FALSE); | 543 g_return_val_if_fail(issuer, FALSE); |
544 | 544 |
545 /* Verify that both certs are the correct scheme */ | 545 /* Verify that both certs are the correct scheme */ |
546 g_return_val_if_fail(crt->scheme != &x509_gnutls, FALSE); | 546 g_return_val_if_fail(crt->scheme == &x509_gnutls, FALSE); |
547 g_return_val_if_fail(issuer->scheme != &x509_gnutls, FALSE); | 547 g_return_val_if_fail(issuer->scheme == &x509_gnutls, FALSE); |
548 | 548 |
549 /* TODO: check for more nullness? */ | 549 /* TODO: check for more nullness? */ |
550 | 550 |
551 crt_dat = *((gnutls_x509_crt_t *) crt->data); | 551 crt_dat = *((gnutls_x509_crt_t *) crt->data); |
552 issuer_dat = *((gnutls_x509_crt_t *) issuer->data); | 552 issuer_dat = *((gnutls_x509_crt_t *) issuer->data); |
612 /* Okay, now create and fill hash array */ | 612 /* Okay, now create and fill hash array */ |
613 hash = g_byte_array_new(); | 613 hash = g_byte_array_new(); |
614 g_byte_array_append(hash, hashbuf, hashlen); | 614 g_byte_array_append(hash, hashbuf, hashlen); |
615 | 615 |
616 return hash; | 616 return hash; |
617 } | |
618 | |
619 static gchar * | |
620 x509_common_name (PurpleCertificate *crt) | |
621 { | |
622 gnutls_x509_crt_t cert_dat; | |
623 gchar *cn = NULL; | |
624 size_t cn_size; | |
625 | |
626 g_return_val_if_fail(crt, NULL); | |
627 g_return_val_if_fail(crt->scheme == &x509_gnutls, NULL); | |
628 | |
629 cert_dat = *( (gnutls_x509_crt_t *) crt->data ); | |
630 | |
631 /* TODO: Not return values? */ | |
632 | |
633 /* Figure out the length of the Common Name */ | |
634 /* Claim that the buffer is size 0 so GnuTLS just tells us how much | |
635 space it needs */ | |
636 cn_size = 0; | |
637 gnutls_x509_crt_get_dn_by_oid(cert_dat, | |
638 GNUTLS_OID_X520_COMMON_NAME, | |
639 0, /* First CN found, please */ | |
640 0, /* Not in raw mode */ | |
641 cn, &cn_size); | |
642 | |
643 /* Now allocate and get the Common Name */ | |
644 cn = g_new0(gchar, cn_size); | |
645 gnutls_x509_crt_get_dn_by_oid(cert_dat, | |
646 GNUTLS_OID_X520_COMMON_NAME, | |
647 0, /* First CN found, please */ | |
648 0, /* Not in raw mode */ | |
649 cn, &cn_size); | |
650 | |
651 return cn; | |
617 } | 652 } |
618 | 653 |
619 /* X.509 certificate operations provided by this plugin */ | 654 /* X.509 certificate operations provided by this plugin */ |
620 /* TODO: Flesh this out! */ | 655 /* TODO: Flesh this out! */ |
621 static PurpleCertificateScheme x509_gnutls = { | 656 static PurpleCertificateScheme x509_gnutls = { |
624 x509_import_from_file, /* Certificate import function */ | 659 x509_import_from_file, /* Certificate import function */ |
625 x509_destroy_certificate, /* Destroy cert */ | 660 x509_destroy_certificate, /* Destroy cert */ |
626 x509_sha1sum, /* SHA1 fingerprint */ | 661 x509_sha1sum, /* SHA1 fingerprint */ |
627 NULL, /* Subject */ | 662 NULL, /* Subject */ |
628 NULL, /* Unique ID */ | 663 NULL, /* Unique ID */ |
629 NULL /* Issuer Unique ID */ | 664 NULL, /* Issuer Unique ID */ |
665 x509_common_name /* Subject name */ | |
630 }; | 666 }; |
631 | 667 |
632 static PurpleSslOps ssl_ops = | 668 static PurpleSslOps ssl_ops = |
633 { | 669 { |
634 ssl_gnutls_init, | 670 ssl_gnutls_init, |