~ubuntu-branches/ubuntu/wily/libimobiledevice/wily

« back to all changes in this revision

Viewing changes to src/idevice.c

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki, Matthias Niess, Timo Jyrinki
  • Date: 2014-03-14 08:44:15 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20140314084415-twglhjx6bqzmir8v
Tags: 1.1.5+git20140313.bafe6a9e-0ubuntu1
[ Matthias Niess ]
* Replace a duplicate 'backup' util man page with the one for 'crashreport'

[ Timo Jyrinki ]
* New upstream snapshot. (LP: #1207812)
* Drop patches include in the upstream snapshot:
  - debian/patches/CVE-2013-2142.patch
  - debian/patches/git_explicitly_cast_ssl_enabled.patch
* Drop the python patch, new upstream method seems to work:
  - debian/patches/09_use_python_config.patch
* Refreshed remaining patches:
  - debian/patches/01-libs.private.patch
  - debian/patches/02-fix-link-errors.patch
* Drop libimobiledevice-doc, the git does not include html documentation
* Updated libimobiledevice4.symbols 
* Add missing man page for the 'idevicename' util

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <gnutls/gnutls.h>
36
36
#endif
37
37
#include "idevice.h"
38
 
#include "userpref.h"
39
 
#include "debug.h"
 
38
#include "common/userpref.h"
 
39
#include "common/debug.h"
40
40
 
41
41
#ifdef HAVE_OPENSSL
42
42
static int openssl_init_done = 0;
71
71
{
72
72
        event_cb = callback;
73
73
        int res = usbmuxd_subscribe(usbmux_event_cb, user_data);
74
 
        if (res != 0) {
 
74
        if (res != 0) {
75
75
                event_cb = NULL;
76
76
                debug_info("Error %d when subscribing usbmux event callback!", res);
77
77
                return IDEVICE_E_UNKNOWN_ERROR;
113
113
        *count = 0;
114
114
 
115
115
        if (usbmuxd_get_device_list(&dev_list) < 0) {
116
 
                debug_info("ERROR: usbmuxd is not running!\n", __func__);
 
116
                debug_info("ERROR: usbmuxd is not running!", __func__);
117
117
                return IDEVICE_E_NO_DEVICE;
118
118
        }
119
119
 
238
238
                new_connection->type = CONNECTION_USBMUXD;
239
239
                new_connection->data = (void*)(long)sfd;
240
240
                new_connection->ssl_data = NULL;
 
241
                idevice_get_udid(device, &new_connection->udid);
241
242
                *connection = new_connection;
242
243
                return IDEVICE_E_SUCCESS;
243
244
        } else {
266
267
        idevice_error_t result = IDEVICE_E_UNKNOWN_ERROR;
267
268
        if (connection->type == CONNECTION_USBMUXD) {
268
269
                usbmuxd_disconnect((int)(long)connection->data);
 
270
                connection->data = NULL;
269
271
                result = IDEVICE_E_SUCCESS;
270
272
        } else {
271
273
                debug_info("Unknown connection type %d", connection->type);
272
274
        }
 
275
 
 
276
        if (connection->udid)
 
277
                free(connection->udid);
 
278
 
273
279
        free(connection);
 
280
        connection = NULL;
 
281
 
274
282
        return result;
275
283
}
276
284
 
377
385
 
378
386
        if (connection->ssl_data) {
379
387
#ifdef HAVE_OPENSSL
380
 
                int received = SSL_read(connection->ssl_data->session, (void*)data, (int)len);
 
388
                uint32_t received = 0;
 
389
                while (received < len) {
 
390
                        int r = SSL_read(connection->ssl_data->session, (void*)((char*)(data+received)), (int)len-received);
 
391
                        if (r > 0) {
 
392
                                received += r;
 
393
                        } else {
 
394
                                break;
 
395
                        }
 
396
                }
381
397
                debug_info("SSL_read %d, received %d", len, received);
382
398
#else
383
399
                ssize_t received = gnutls_record_recv(connection->ssl_data->session, (void*)data, (size_t)len);
591
607
#ifndef STRIP_DEBUG_CODE
592
608
static const char *errorstring(int e)
593
609
{
594
 
    switch(e) {
595
 
        case SSL_ERROR_NONE:
596
 
            return "SSL_ERROR_NONE";
597
 
        case SSL_ERROR_SSL:
598
 
            return "SSL_ERROR_SSL";
599
 
        case SSL_ERROR_WANT_READ:
600
 
            return "SSL_ERROR_WANT_READ";
601
 
        case SSL_ERROR_WANT_WRITE:
602
 
            return "SSL_ERROR_WANT_WRITE";
603
 
        case SSL_ERROR_WANT_X509_LOOKUP:
604
 
            return "SSL_ERROR_WANT_X509_LOOKUP";
605
 
        case SSL_ERROR_SYSCALL:
606
 
            return "SSL_ERROR_SYSCALL";
607
 
        case SSL_ERROR_ZERO_RETURN:
608
 
            return "SSL_ERROR_ZERO_RETURN";
609
 
        case SSL_ERROR_WANT_CONNECT:
610
 
            return "SSL_ERROR_WANT_CONNECT";
611
 
        case SSL_ERROR_WANT_ACCEPT:
612
 
            return "SSL_ERROR_WANT_ACCEPT";
613
 
        default:
614
 
            return "UNKOWN_ERROR_VALUE";
615
 
    }
 
610
        switch(e) {
 
611
                case SSL_ERROR_NONE:
 
612
                        return "SSL_ERROR_NONE";
 
613
                case SSL_ERROR_SSL:
 
614
                        return "SSL_ERROR_SSL";
 
615
                case SSL_ERROR_WANT_READ:
 
616
                        return "SSL_ERROR_WANT_READ";
 
617
                case SSL_ERROR_WANT_WRITE:
 
618
                        return "SSL_ERROR_WANT_WRITE";
 
619
                case SSL_ERROR_WANT_X509_LOOKUP:
 
620
                        return "SSL_ERROR_WANT_X509_LOOKUP";
 
621
                case SSL_ERROR_SYSCALL:
 
622
                        return "SSL_ERROR_SYSCALL";
 
623
                case SSL_ERROR_ZERO_RETURN:
 
624
                        return "SSL_ERROR_ZERO_RETURN";
 
625
                case SSL_ERROR_WANT_CONNECT:
 
626
                        return "SSL_ERROR_WANT_CONNECT";
 
627
                case SSL_ERROR_WANT_ACCEPT:
 
628
                        return "SSL_ERROR_WANT_ACCEPT";
 
629
                default:
 
630
                        return "UNKOWN_ERROR_VALUE";
 
631
        }
616
632
}
617
633
#endif
618
634
#endif
662
678
        key_data_t root_cert = { NULL, 0 };
663
679
        key_data_t root_privkey = { NULL, 0 };
664
680
 
665
 
        userpref_error_t uerr = userpref_get_keys_and_certs(&root_privkey, &root_cert, NULL, NULL);
 
681
        userpref_error_t uerr = userpref_device_record_get_keys_and_certs(connection->udid, &root_privkey, &root_cert, NULL, NULL);
666
682
        if (uerr != USERPREF_E_SUCCESS) {
667
683
                debug_info("Error %d when loading keys and certificates! %d", uerr);
668
684
        }
720
736
        SSL_set_bio(ssl, ssl_bio, ssl_bio);
721
737
 
722
738
        return_me = SSL_do_handshake(ssl);
723
 
        if (return_me != 1) {
 
739
        if (return_me != 1) {
724
740
                debug_info("ERROR in SSL_do_handshake: %s", errorstring(SSL_get_error(ssl, return_me)));
725
 
                BIO_free(ssl_bio);
 
741
                SSL_free(ssl);
726
742
                SSL_CTX_free(ssl_ctx);
727
743
        } else {
728
744
                ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private));
729
745
                ssl_data_loc->session = ssl;
730
746
                ssl_data_loc->ctx = ssl_ctx;
731
 
                ssl_data_loc->bio = ssl_bio;
732
747
                connection->ssl_data = ssl_data_loc;
733
748
                ret = IDEVICE_E_SUCCESS;
734
749
                debug_info("SSL mode enabled, cipher: %s", SSL_get_cipher(ssl));
752
767
        gnutls_x509_privkey_init(&ssl_data_loc->root_privkey);
753
768
        gnutls_x509_privkey_init(&ssl_data_loc->host_privkey);
754
769
 
755
 
        userpref_error_t uerr = userpref_get_keys_and_certs(ssl_data_loc->root_privkey, ssl_data_loc->root_cert, ssl_data_loc->host_privkey, ssl_data_loc->host_cert);
 
770
        userpref_error_t uerr = userpref_device_record_get_keys_and_certs(connection->udid, ssl_data_loc->root_privkey, ssl_data_loc->root_cert, ssl_data_loc->host_privkey, ssl_data_loc->host_cert);
756
771
        if (uerr != USERPREF_E_SUCCESS) {
757
772
                debug_info("Error %d when loading keys and certificates! %d", uerr);
758
773
        }
805
820
 
806
821
#ifdef HAVE_OPENSSL
807
822
        if (connection->ssl_data->session) {
808
 
                SSL_shutdown(connection->ssl_data->session);
 
823
                /* see: https://www.openssl.org/docs/ssl/SSL_shutdown.html#RETURN_VALUES */
 
824
                if (SSL_shutdown(connection->ssl_data->session) == 0) {
 
825
                        SSL_shutdown(connection->ssl_data->session);
 
826
                }
809
827
        }
810
828
#else
811
829
        if (connection->ssl_data->session) {