Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UT: Get supervision state through ideviceprofile binary #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ tools/idevice*
cython/.libs/*
cython/*.c
doxygen.cfg
dependencies
test-driver
.DS_Store

# Build

build/
scripts/__pycache__/
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Petr Uzel
Todd Zullinger
Zach C
Zoltan Balaton
Ethan Carlson
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ to:
* Mount filesystem images
* Forward device notifications
* Manage device provisioning
* Manage device configuration profiles
* Take screenshots from the device screen (requires mounted developer image)
* Simulate changed geolocation of the device (requires mounted developer image)
* Relay the syslog of the device
Expand Down Expand Up @@ -113,6 +114,12 @@ MbedTLS headers and `mbedtls_LIBDIR` to set the library path. Optionally,
./autogen.sh --with-mbedtls mbedtls_INCLUDES=/opt/local/include mbedtls_LIBDIR=/opt/local/lib
```

### MAC

- Using brew run: `brew install make automake autoconf libtool pkg-config gcc`.
- Then run: `install-libimobiledevice.sh`.
- You will find all the binaries in: `dependencies/bin` path.

## Usage

Documentation about using the library in your application is not available yet.
Expand Down Expand Up @@ -141,6 +148,7 @@ The library bundles the following command-line utilities in the tools directory:
| `idevicenotificationproxy` | Post or observe notifications on a device |
| `idevicepair` | Manage host pairings with devices and usbmuxd |
| `ideviceprovision` | Manage provisioning profiles on a device |
| `ideviceprofile` | Manage configuration profiles on a device |
| `idevicescreenshot` | Gets a screenshot from the connected device |
| `idevicesetlocation` | Simulate location on device |
| `idevicesyslog` | Relay syslog of a connected device |
Expand Down
205 changes: 205 additions & 0 deletions include/libimobiledevice/mcinstall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/**
* @file libimobiledevice/mcinstall.h
* @brief Manage mobileconfig profiles.
* \internal
*
* Copyright (c) 2020 Ethan Carlson All Rights Reserved.
* Uses base code from mcinstall.h Copyright Nikias Bassen and Martin Szulecki
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef IMCINSTALL_H
#define IMCINSTALL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>

#define MCINSTALL_SERVICE_NAME "com.apple.MCInstall"

/** Error Codes */
typedef enum {
MCINSTALL_E_SUCCESS = 0,
MCINSTALL_E_INVALID_ARG = -1,
MCINSTALL_E_PLIST_ERROR = -2,
MCINSTALL_E_CONN_FAILED = -3,
MCINSTALL_E_REQUEST_FAILED = -4,
MCINSTALL_E_UNKNOWN_ERROR = -256
} mcinstall_error_t;

typedef struct mcinstall_client_private mcinstall_client_private;
typedef mcinstall_client_private *mcinstall_client_t; /**< The client handle. */

/* Interface */

/**
* Connects to the mcinstall service on the specified device.
*
* @param device The device to connect to.
* @param service The service descriptor returned by lockdownd_start_service.
* @param client Pointer that will point to a newly allocated
* mcinstall_client_t upon successful return.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is NULL, or an MCINSTALL_E_* error code otherwise.
*/
mcinstall_error_t mcinstall_client_new(idevice_t device, lockdownd_service_descriptor_t service, mcinstall_client_t *client);

/**
* Starts a new mcinstall service on the specified device and connects to it.
*
* @param device The device to connect to.
* @param client Pointer that will point to a newly allocated
* mcinstall_client_t upon successful return. Must be freed using
* mcinstall_client_free() after use.
* @param label The label to use for communication. Usually the program name.
* Pass NULL to disable sending the label in requests to lockdownd.
*
* @return MCINSTALL_E_SUCCESS on success, or an MCINSTALL_E_* error
* code otherwise.
*/
mcinstall_error_t mcinstall_client_start_service(idevice_t device, mcinstall_client_t* client, const char* label);

/**
* Disconnects an mcinstall client from the device and frees up the
* mcinstall client data.
*
* @param client The mcinstall client to disconnect and free.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is NULL, or an MCINSTALL_E_* error code otherwise.
*/
mcinstall_error_t mcinstall_client_free(mcinstall_client_t client);

/**
* Retrieves all installed mobileconfig profiles
*
* @param client The connected mcinstall to use.
* @param profiles Pointer to a plist_t that will be set to a PLIST_ARRAY
* if the function is successful.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is invalid, or an MCINSTALL_E_* error code otherwise.
*
*
* @note If no mobileconfig profiles are installed on the device, this function
* still returns MCINSTALL_E_SUCCESS and profiles will just point to an
* empty array.
*/
mcinstall_error_t mcinstall_copy(mcinstall_client_t client, plist_t* profiles);


/**
* Installs the given mobileconfig profile. Only works with valid profiles.
*
* @param client The connected mcinstall to use for installation
* @param profile The valid mobileconfig profile to install. This has to be
* passed as a PLIST_DATA, otherwise the function will fail.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is invalid, or an MCINSTALL_E_* error code otherwise.
*/
mcinstall_error_t mcinstall_install(mcinstall_client_t client, plist_t profile);


/**
* Installs the given DEP Enrollment CloudCOnfig Data. Use this carfully, you only get one shot before an erase is neccesary. Only works with valid profiles.
*
* @param client The connected mcinstall to use for installation
* @param profile The valid mobileconfig profile to install. This has to be
* passed as a PLIST_DATA, otherwise the function will fail.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is invalid, or an MCINSTALL_E_* error code otherwise.
*/
mcinstall_error_t mcinstall_install_cloud_config(mcinstall_client_t client, plist_t profile);


/**
* Retrieves DEP Enrollment Information
*
* @param client The connected mcinstall to use.
* @param profiles Pointer to a plist_t that will be set to a PLIST_ARRAY
* if the function is successful.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is invalid, or an MCINSTALL_E_* error code otherwise.
*
*
* @note If no mobileconfig profiles are installed on the device, this function
* still returns MCINSTALL_E_SUCCESS and profiles will just point to an
* empty array.
*/
mcinstall_error_t mcinstall_get_cloud_config(mcinstall_client_t client, plist_t* profiles);


/**
* Requests that device download a DEP Enrollment Profile from the server
*
* @param client The connected mcinstall to use.
* @param profiles Pointer to a plist_t that will be set to a PLIST_ARRAY
* if the function is successful.
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is invalid, or an MCINSTALL_E_* error code otherwise.
*
*
* @note If no mobileconfig profiles are installed on the device, this function
* still returns MCINSTALL_E_SUCCESS and profiles will just point to an
* empty array.
*/
mcinstall_error_t mcinstall_download_cloud_config(mcinstall_client_t client, plist_t* profiles);



/**
* Removes a specified mobileconfig from the device
*
* @param client The connected mcinstall to use.
* @param profile Pointer to a plist_t DICT that is recived from mcinstall_copy for the ID Specified
* if the function is successful.
*
* @param profileID The Key that was used to access the DICS passed as profile, it is the pofiles identifier
*
* @return MCINSTALL_E_SUCCESS on success, MCINSTALL_E_INVALID_ARG when
* client is invalid, or an MCINSTALL_E_* error code otherwise.
*
*
* @note If no mobileconfig profiles are installed on the device, this function
* still returns MCINSTALL_E_SUCCESS and profiles will just point to an
* empty array.
*/
mcinstall_error_t mcinstall_remove(mcinstall_client_t client, plist_t profile, const char* profileID);



/**
* Retrieves the status code from the last operation.
*
* @param client The mcinstall to use.
*
* @return -1 if client is invalid, or the status code from the last operation
*/
int mcinstall_get_status_code(mcinstall_client_t client);

#ifdef __cplusplus
}
#endif

#endif
136 changes: 136 additions & 0 deletions install-libimobiledevice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/sh

export root_path=$PWD
export install_dir="$root_path/dependencies"
export tmp_dir="tmp"
export tmp_path="$root_path/$tmp_dir"

export openssl_url="https://www.openssl.org/source/openssl-1.1.1k.tar.gz"
export openssl_file="openssl-1.1.1k.tar.gz"
export openssl_dir="openssl-1.1.1k"
export openssl_check_file="${install_dir}/include/openssl/opensslv.h"
export libplist_url="https://github.com/libimobiledevice/libplist.git"
export libplist_dir="libplist"
export libplist_check_file="${install_dir}/lib/libplist.la"
export libusbmuxd_url="https://github.com/libimobiledevice/libusbmuxd.git"
export libusbmuxd_dir="libusbmuxd"
export libusbmuxd_check_file="${install_dir}/lib/libusbmuxd.la"
export libimobiledevice_url="https://github.com/libimobiledevice/libimobiledevice.git"
export libimobiledevice_dir="libimobiledevice"
export libimobiledevice_check_file="${install_dir}/lib/libimobiledevice.la"
BRANCH="master"

mkdir $tmp_dir
cd $tmp_path

## openssl
#if is not installed, install it
if [ ! -f $openssl_check_file ]; then
echo "\n\n"
echo "Install openssl"
echo "-------------------------------------------\n\n"
# download sources
curl -OL $openssl_url
tar xvzf $openssl_file
# compile it
cd $openssl_dir
if [[ "$(uname -m)" == "x86_64" ]]; then
echo "\n\n ------- Compiling Openssl with Darwin Intel ------- \n\n"
./Configure --prefix=$install_dir --openssldir=$install_dir/openssl darwin64-x86_64-cc
elif [[ "$(uname -m)" == "arm64" ]]; then
echo "\n\n ------- Compiling Openssl with Darwin Apple Silicon ------- \n\n"
./Configure --prefix=$install_dir shared enable-rc5 zlib darwin64-arm64-cc no-asm
elif [[ "$(uname -s)" == *"CYGWIN"* ]]; then
dos2unix ./*
./Configure --prefix=$install_dir --openssldir=$install_dir/openssl Cygwin-x86_64
else
echo "\n\n ------- No suitable compiler has been found ------- \n\n"
fi
make
make install_sw
fi

## lipplist
# if is not installed, install it
if [ ! -f $libplist_check_file ]; then
echo "\n\n"
echo "Install libplist"
echo "-------------------------------------------\n\n"
# download sources
cd $tmp_path
git clone $libplist_url
# compile it
cd $libplist_dir
git checkout $BRANCH
# for some reason the first time it set the libtool folter to ../.. instead of .
# so running a second time the issue its fixed
if [[ "$(uname -s)" == *"CYGWIN"* ]]; then
dos2unix ./*
fi
./autogen.sh
./autogen.sh
./configure --prefix=$install_dir
make
make install
# this file was created the first time autogen.sh runs (in the wrong directory)
rm ../../ltmain.sh
fi

## libusbmuxd
# if is not installed, install it
if [ ! -f $libusbmuxd_check_file ]; then
echo "\n\n"
echo "Install libusbmuxd"
echo "-------------------------------------------\n\n"
# download sources
cd $tmp_path
git clone $libusbmuxd_url
# compile it
cd $libusbmuxd_dir
git checkout $BRANCH
export PKG_CONFIG_PATH=$install_dir/lib/pkgconfig
# for some reason the first time it set the libtool folter to ../.. instead of .
# so running a second time the issue its fixed
if [[ "$(uname -s)" == *"CYGWIN"* ]]; then
dos2unix ./*
fi
./autogen.sh
./autogen.sh
./configure --prefix=$install_dir
make
make install
# this file was created the first time autogen.sh runs (in the wrong directory)
rm ../../ltmain.sh
fi

## libimobiledevice
# if is not installed, install it
if [ ! -f $libimobiledevice_check_file ]; then
echo "\n\n"
echo "Install libimobiledevice"
echo "-------------------------------------------\n\n"
cd $root_path
# download sources
# compile it
export PKG_CONFIG_PATH=$install_dir/lib/pkgconfig
export LD_LIBRARY_PATH=$install_dir/lib:$LD_LIBRARY_PATH
export CPATH=$install_dir/include/openssl:$CPATH
# for some reason the first time it set the libtool folter to ../.. instead of .
# so running a second time the issue its fixed
if [[ "$(uname -s)" == *"CYGWIN"* ]]; then
dos2unix ./*
fi
./autogen.sh
./autogen.sh
./configure --prefix=$install_dir
make
make install
rm ltmain.sh
# this file was created the first time autogen.sh runs (in the wrong directory)
fi

# clean
cd $root_path
rm -rf $tmp_dir
# remove binaries, we don't need them

Loading