Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@ If you wish to know how to build this repository, follow [these instructions](BU

iOS WebKit Debug Proxy works on Linux, MacOS & Windows.

On a MacOS, it's easiest to install with [homebrew](http://brew.sh/):
### MacOS

It's easiest to install with [homebrew](http://brew.sh/):

```console
brew install ios-webkit-debug-proxy
```

On Windows, it's easiest to install with [scoop](http://scoop.sh/):
### Windows
It's easiest to install with [scoop](http://scoop.sh/):
```
scoop bucket add extras
scoop install ios-webkit-debug-proxy
```
Note: you also need the latest version of [iTunes](https://www.apple.com/il/itunes/download/) installed.

On Linux:
### Linux

Install dependencies available in apt repository:
```console
sudo apt-get install autoconf automake libusb-dev libusb-1.0-0-dev libplist-dev libtool libssl-dev
```

Build and install dependencies that require more recent versions:
- [libmobiledevice](https://github.com/libimobiledevice/libimobiledevice)
- [libimobiledevice](https://github.com/libimobiledevice/libimobiledevice)
- [libusbmuxd](https://github.com/libimobiledevice/libusbmuxd)
- [usbmuxd](https://github.com/libimobiledevice/usbmuxd)
- [libplist](https://github.com/libimobiledevice/libplist)
Expand Down Expand Up @@ -84,12 +87,10 @@ ios_webkit_debug_proxy can be used with many tools such as Chrome DevTools and S

#### Chrome Devtools

To use Chrome DevTools it's the recommendation to use the [RemoteDebug/remotedebug-ios-webkit-adapter](https://github.com/RemoteDebug/remotedebug-ios-webkit-adapter) project, which has instructions on how to setup Chrome to remote debug iOS devices, much similar to Android debugging.

The reason is that in recent versions of Chrome and Safari there're major discrepancies between [Chrome Remote Debugging Protocol](https://developer.chrome.com/devtools/docs/debugger-protocol) and [Webkit Inspector Protocol](https://github.com/WebKit/webkit/tree/master/Source/JavaScriptCore/inspector/protocol), which means that newer versions of Chrome DevTools aren't compatible with Safari.
In recent versions of Chrome and Safari there're major discrepancies between [Chrome Remote Debugging Protocol](https://developer.chrome.com/devtools/docs/debugger-protocol) and [Webkit Inspector Protocol](https://github.com/WebKit/webkit/tree/master/Source/JavaScriptCore/inspector/protocol), which means that newer versions of Chrome DevTools aren't compatible with Safari.

#### Safari Web Inspector
You can use Safari Web Inspector extracted from Webkit sources, e.g. [artygus/webkit-webinspector](https://github.com/artygus/webkit-webinspector).
You can use Safari Web Inspector extracted from Webkit sources, e.g. [artygus/webkit-webinspector](https://github.com/artygus/webkit-webinspector) or [HimbeersaftLP/ios-safari-remote-debug-kit](https://github.com/HimbeersaftLP/ios-safari-remote-debug-kit).

#### Firefox DevTools via Valence
Another option is [mozilla/valence](https://github.com/mozilla/valence) which enables Firefox DevTools to be used with iOS.
Expand Down Expand Up @@ -211,6 +212,15 @@ Make sure you're using latest version of ios-webkit-debug-proxy
- Check that webinspector switch is enabled (Settings -> Safari -> Advanced -> Web Inspector)
- Most likely simulator's web inspector daemon listens on ipv6 interface, check that you have `::1 localhost` line in `/etc/hosts`

##### Building under Rosetta (OS X)

libimobildevice formulae [depends on](https://github.com/Homebrew/homebrew-core/blob/d6c416caf0622f2aac47742bca679c3510d0b1d9/Formula/libimobiledevice.rb#L30) [email protected], which is key-only and requires the following env paths for the build

```console
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
```

##### If no luck so far...
Lastly, always try replugging in the USB cable.
Expand Down
12 changes: 10 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT([ios_webkit_debug_proxy], [1.8.8], [https://github.com/google/ios-webkit-debug-proxy/issues])
AC_INIT([ios_webkit_debug_proxy], [1.9.0], [https://github.com/google/ios-webkit-debug-proxy/issues])
AM_INIT_AUTOMAKE([1.10 no-define])
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([config.h])
Expand All @@ -18,7 +18,8 @@ PKG_PROG_PKG_CONFIG
# Checks for libraries.
PKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= 1.3.0)
PKG_CHECK_MODULES(libplist, libplist-2.0 >= 2.2.0)
PKG_CHECK_MODULES(openssl, openssl >= 0.9.8)
PKG_CHECK_MODULES(libusbmuxd, libusbmuxd-2.0 >= 2.0.0)
PKG_CHECK_MODULES(openssl, openssl >= 1.1.0)
AC_CHECK_LIB([plist-2.0], [plist_to_xml],
[ ], [AC_MSG_FAILURE([*** Unable to link with libplist])],
[$libplist_LIBS])
Expand All @@ -31,9 +32,16 @@ LT_INIT
# Defines versions of required modules
libimobiledevice_version=`$PKG_CONFIG --modversion libimobiledevice-1.0`
libplist_version=`$PKG_CONFIG --modversion libplist-2.0`
libusbmuxd_version=`$PKG_CONFIG --modversion libusbmuxd-2.0`

AC_DEFINE_UNQUOTED([LIBIMOBILEDEVICE_VERSION], ["$libimobiledevice_version"], [ ])
AC_DEFINE_UNQUOTED([LIBPLIST_VERSION], ["$libplist_version"], [ ])
AC_DEFINE_UNQUOTED([LIBUSBMUXD_VERSION], ["$libusbmuxd_version"], [ ])

[libplist_version_major=`expr "$libplist_version" : '\([0-9]*\)'`]
[libplist_version_minor=`expr "$libplist_version" : '[0-9]*\.\([0-9]*\)'`]
AC_DEFINE_UNQUOTED([LIBPLIST_VERSION_MAJOR], [$libplist_version_major], [ ])
AC_DEFINE_UNQUOTED([LIBPLIST_VERSION_MINOR], [$libplist_version_minor], [ ])

# Checks for header files.
AC_HEADER_STDC
Expand Down
2 changes: 1 addition & 1 deletion design.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Copyright 2012 Google Inc. <[email protected]>
iOS WebKit Debug Proxy Design
=============================

See the [README.md](README) for an overview.
See the [README.md](README.md) for an overview.

Source
------
Expand Down
6 changes: 4 additions & 2 deletions examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src

AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS) $(openssl_CFLAGS)
AM_LDFLAGS = $(libimobiledevice_LIBS) $(libplist_LIBS) $(openssl_LIBS)
AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS) $(libusbmuxd_CFLAGS) $(openssl_CFLAGS)
AM_LDFLAGS = $(libimobiledevice_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(openssl_LIBS)

noinst_PROGRAMS = ws_echo1 ws_echo2 wi_client dl_client

Expand Down Expand Up @@ -34,10 +34,12 @@ wi_client_SOURCES = \
wi_client.c \
char_buffer.h \
rpc.h \
idevice_ext.h \
webinspector.h
wi_client_LDADD = \
../src/char_buffer.o \
../src/rpc.o \
../src/idevice_ext.o \
../src/webinspector.o

dl_client_SOURCES = \
Expand Down
24 changes: 24 additions & 0 deletions include/ios-webkit-debug-proxy/idevice_ext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Google BSD license https://developers.google.com/google-bsd-license
// Copyright 2012 Google Inc. [email protected]

//
// libimobildevice extensions
//

#ifndef IDEVICE_EXT_H
#define IDEVICE_EXT_H

#ifdef __cplusplus
extern "C" {
#endif

#include <openssl/ssl.h>
#include <libimobiledevice/libimobiledevice.h>

int idevice_ext_connection_enable_ssl(const char *device_id, int fd, SSL **to_session);

#ifdef __cplusplus
}
#endif

#endif /* IDEVICE_EXT_H */
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/include/ios-webkit-debug-proxy

AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS) $(libpcreposix_CFLAGS) $(openssl_CFLAGS)
AM_LDFLAGS = $(libimobiledevice_LIBS) $(libplist_LIBS) $(libpcreposix_LIBS) $(openssl_LIBS)
AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS) $(libusbmuxd_CFLAGS) $(libpcreposix_CFLAGS) $(openssl_CFLAGS)
AM_LDFLAGS = $(libimobiledevice_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libpcreposix_LIBS) $(openssl_LIBS)

lib_LTLIBRARIES = libios_webkit_debug_proxy.la
libios_webkit_debug_proxy_la_LIBADD =
Expand All @@ -20,6 +20,7 @@ libios_webkit_debug_proxy_la_SOURCES = ios_webkit_debug_proxy_main.c \
sha1.c sha1.h \
socket_manager.c socket_manager.h \
validate_utf8.h \
idevice_ext.c idevice_ext.h \
webinspector.c webinspector.h \
websocket.c websocket.h

Expand All @@ -35,6 +36,7 @@ ios_webkit_debug_proxy_SOURCES = ios_webkit_debug_proxy_main.c \
sha1.c sha1.h \
socket_manager.c socket_manager.h \
validate_utf8.h \
idevice_ext.c idevice_ext.h \
webinspector.c webinspector.h \
websocket.c websocket.h
ios_webkit_debug_proxy_CFLAGS = $(AM_CFLAGS)
Expand Down
149 changes: 149 additions & 0 deletions src/idevice_ext.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Google BSD license https://developers.google.com/google-bsd-license
// Copyright 2012 Google Inc. [email protected]

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <time.h>
#ifdef WIN32
#include <windows.h>
#endif

#include <usbmuxd.h>

#include "idevice_ext.h"

typedef struct {
unsigned char *data;
unsigned int size;
} key_data_t;

int read_pair_record(const char *udid, plist_t *pair_record) {
char* record_data = NULL;
uint32_t record_size = 0;

int res = usbmuxd_read_pair_record(udid, &record_data, &record_size);
if (res < 0) {
free(record_data);
return -1;
}

*pair_record = NULL;
#if LIBPLIST_VERSION_MAJOR >= 2 && LIBPLIST_VERSION_MINOR >= 3
plist_from_memory(record_data, record_size, pair_record, NULL);
#else
plist_from_memory(record_data, record_size, pair_record);
#endif
free(record_data);

if (!*pair_record) {
return -1;
}

return 0;
}

int pair_record_get_item_as_key_data(plist_t pair_record, const char* name, key_data_t *value) {
char* buffer = NULL;
uint64_t length = 0;
plist_t node = plist_dict_get_item(pair_record, name);

if (node && plist_get_node_type(node) == PLIST_DATA) {
plist_get_data_val(node, &buffer, &length);
value->data = (unsigned char*)malloc(length+1);
memcpy(value->data, buffer, length);
value->data[length] = '\0';
value->size = length+1;
free(buffer);
return 0;
}

return -1;
}

int idevice_ext_connection_enable_ssl(const char *device_id, int fd, SSL **to_session) {
plist_t pair_record = NULL;
if (read_pair_record(device_id, &pair_record)) {
fprintf(stderr, "Failed to read pair record\n");
return -1;
}

key_data_t root_cert = { NULL, 0 };
key_data_t root_privkey = { NULL, 0 };
pair_record_get_item_as_key_data(pair_record, "RootCertificate", &root_cert);
pair_record_get_item_as_key_data(pair_record, "RootPrivateKey", &root_privkey);
plist_free(pair_record);

BIO *ssl_bio = BIO_new(BIO_s_socket());
if (!ssl_bio) {
fprintf(stderr, "Could not create SSL bio\n");
return -1;
}

BIO_set_fd(ssl_bio, fd, BIO_NOCLOSE);
SSL_CTX *ssl_ctx = SSL_CTX_new(TLS_method());
if (ssl_ctx == NULL) {
fprintf(stderr, "Could not create SSL context\n");
BIO_free(ssl_bio);
}

SSL_CTX_set_security_level(ssl_ctx, 0);
SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION);

BIO* membp;
X509* rootCert = NULL;
membp = BIO_new_mem_buf(root_cert.data, root_cert.size);
PEM_read_bio_X509(membp, &rootCert, NULL, NULL);
BIO_free(membp);
SSL_CTX_use_certificate(ssl_ctx, rootCert);
X509_free(rootCert);
free(root_cert.data);

EVP_PKEY* rootPrivKey = NULL;
membp = BIO_new_mem_buf(root_privkey.data, root_privkey.size);
PEM_read_bio_PrivateKey(membp, &rootPrivKey, NULL, NULL);
BIO_free(membp);
SSL_CTX_use_PrivateKey(ssl_ctx, rootPrivKey);
EVP_PKEY_free(rootPrivKey);

free(root_privkey.data);

SSL *ssl = SSL_new(ssl_ctx);
if (!ssl) {
fprintf(stderr, "Could not create SSL object\n");
BIO_free(ssl_bio);
SSL_CTX_free(ssl_ctx);
return -1;
}

SSL_set_connect_state(ssl);
SSL_set_verify(ssl, 0, NULL);
SSL_set_bio(ssl, ssl_bio, ssl_bio);

int ssl_error = 0;
while (1) {
ssl_error = SSL_get_error(ssl, SSL_do_handshake(ssl));
if (ssl_error == 0 || ssl_error != SSL_ERROR_WANT_READ) {
break;
}
#ifdef WIN32
Sleep(100);
#else
struct timespec ts = { 0, 100000000 };
nanosleep(&ts, NULL);
#endif
}

if (ssl_error != 0) {
SSL_free(ssl);
SSL_CTX_free(ssl_ctx);
return ssl_error;
}

*to_session = ssl;
return 0;
}
7 changes: 5 additions & 2 deletions src/ios_webkit_debug_proxy_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <winsock2.h>
#endif

#include <openssl/opensslv.h>

#include "device_listener.h"
#include "hash_table.h"
#include "ios_webkit_debug_proxy.h"
Expand Down Expand Up @@ -261,8 +263,9 @@ int iwdpm_configure(iwdpm_t self, int argc, char **argv) {
case 'V':
printf(
"%s\n"
"Built with libimobiledevice v%s, libplist v%s\n",
PACKAGE_STRING, LIBIMOBILEDEVICE_VERSION, LIBPLIST_VERSION);
"Built with libimobiledevice v%s, libplist v%s, libusbmuxd v%s, %s\n",
PACKAGE_STRING, LIBIMOBILEDEVICE_VERSION, LIBPLIST_VERSION,
LIBUSBMUXD_VERSION, OPENSSL_VERSION_TEXT);
ret = -2;
break;
case 'u':
Expand Down
6 changes: 5 additions & 1 deletion src/socket_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ sm_status sm_remove_fd(sm_t self, int fd) {
if (!FD_ISSET(fd, my->all_fds)) {
return SM_ERROR;
}
ht_put(my->fd_to_ssl, HT_KEY(fd), NULL);
SSL *ssl_session = (SSL *)ht_put(my->fd_to_ssl, HT_KEY(fd), NULL);
if (ssl_session) {
SSL_shutdown(ssl_session);
SSL_free(ssl_session);
}
void *value = ht_put(my->fd_to_value, HT_KEY(fd), NULL);
bool is_server = FD_ISSET(fd, my->server_fds);
sm_on_debug(self, "ss.remove%s_fd(%d)", (is_server ? "_server" : ""), fd);
Expand Down
Loading