summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore27
-rw-r--r--AUTHORS3
-rw-r--r--COPYING502
-rw-r--r--Makefile.am12
-rw-r--r--NEWS22
-rw-r--r--README65
-rwxr-xr-xautogen.sh15
-rw-r--r--configure.ac80
-rw-r--r--include/Makefile.am1
-rw-r--r--include/libideviceactivation.h95
-rw-r--r--libideviceactivation-1.0.pc.in12
-rw-r--r--src/Makefile.am10
-rw-r--r--src/activation.c1076
-rw-r--r--tools/Makefile.am11
-rw-r--r--tools/ideviceactivation.c297
15 files changed, 2228 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..31ffebd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+.*.swp
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache
+compile
+config.guess
+config.h
+config.h.in
+config.log
+config.status
+config.sub
+configure
+depcomp
+install-sh
+libideviceactivation-1.0.pc
+libtool
+ltmain.sh
+m4
+missing
+src/.deps
+src/.libs
+src/*.o
+src/*.lo
+src/*.la
+stamp-h1
+
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..7ddf33e
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,3 @@
+Konstantin Sokolov
+Martin Szulecki
+Nikias Bassen
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..732811e
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,502 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..7a25fc0
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,12 @@
+AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I m4
+SUBDIRS = src include tools
+
+DISTCHECK_CONFIGURE_FLAGS =
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libideviceactivation-1.0.pc
+
+indent:
+ indent -kr -ut -ts4 -l120 src/*.c src/*.h dev/*.c
+
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..042ef6e
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,22 @@
+Version 0.9.0
+~~~~~~~~~~~~~
+
+* Changes:
+ - Refactor interface to allow handling forms
+ - BuddyML and HTML parsing support
+ - Minor fixes
+
+Version 0.5.0
+~~~~~~~~~~~~~
+
+* Changes:
+ - Add debug level setter to enable verbose curl debugging
+ - Minor fixes
+
+Version 0.1.0
+~~~~~~~~~~~~~
+
+* Changes:
+ - Implement basic API to interact with activation webservice
+ - Add basic ideviceactivation tool
+ - Setup build system \ No newline at end of file
diff --git a/README b/README
new file mode 100644
index 0000000..1b53e3f
--- /dev/null
+++ b/README
@@ -0,0 +1,65 @@
+About
+=====
+
+A library to manage the activation process of Apple iOS devices.
+
+Requirements
+============
+
+Development Packages of:
+ libcurl
+ libxml2
+ libplist
+ libimobiledevice
+
+Software:
+ usbmuxd
+ make
+ autoheader
+ automake
+ autoconf
+ libtool
+ pkg-config
+ gcc
+
+Installation
+============
+
+To compile run:
+ ./autogen.sh
+ make
+ sudo make install
+
+Who/What/Where?
+===============
+
+Home:
+ http://www.libimobiledevice.org/
+
+Code:
+ git clone http://git.sukimashita.com/libideviceactivation.git
+
+Code (Mirror):
+ git clone https://github.com/libimobiledevice/libideviceactivation.git
+
+Tickets:
+ http://github.com/libimobiledevice/libideviceactivation/issues
+
+Mailing List:
+ http://lists.libimobiledevice.org/mailman/listinfo/libimobiledevice-devel
+
+IRC:
+ irc://irc.freenode.net#libimobiledevice
+
+Credits
+=======
+
+Inspired by the activation utility from Joshua Hill (p0sixninja):
+https://github.com/posixninja/ideviceactivate/
+
+Apple, iPhone, iPod, and iPod Touch are trademarks of Apple Inc.
+libimobiledevice is an independent software library and has not been
+authorized, sponsored, or otherwise approved by Apple Inc.
+
+README Updated on:
+ 2014-06-05
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..3292973
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+gprefix=`which glibtoolize 2>&1 >/dev/null`
+if [ $? -eq 0 ]; then
+ glibtoolize --force
+else
+ libtoolize --force
+fi
+aclocal -I m4
+autoheader
+automake --add-missing
+autoconf
+
+if [ -z "$NOCONFIGURE" ]; then
+ ./configure "$@"
+fi
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..973d06c
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,80 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.61)
+AC_INIT(libideviceactivation, 0.9.0, info@libimobiledevice.org)
+AM_INIT_AUTOMAKE([dist-bzip2 no-dist-gzip])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
+AC_CONFIG_SRCDIR([src/])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_MACRO_DIR([m4])
+
+dnl libtool versioning
+# +1 : 0 : +1 == adds new functions to the interface
+# +1 : 0 : 0 == changes or removes functions (changes include both
+# changes to the signature and the semantic)
+# ? :+1 : ? == just internal changes
+# CURRENT : REVISION : AGE
+LIBIDEVICEACTIVATION_SO_VERSION=2:0:0
+
+dnl Minimum package versions
+LIBIMOBILEDEVICE_VERSION=1.1.4
+LIBPLIST_VERSION=1.11
+LIBCURL_VERSION=7.20
+LIBXML2_VERSION=2.9
+
+AC_SUBST(LIBIDEVICEACTIVATION_SO_VERSION)
+AC_SUBST(LIBIMOBILEDEVICE_VERSION)
+AC_SUBST(LIBPLIST_VERSION)
+AC_SUBST(LIBCURL_VERSION)
+AC_SUBST(LIBXML2_VERSION)
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_CXX
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
+
+# Checks for libraries.
+PKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= $LIBIMOBILEDEVICE_VERSION)
+PKG_CHECK_MODULES(libplist, libplist >= $LIBPLIST_VERSION)
+PKG_CHECK_MODULES(libcurl, libcurl >= $LIBCURL_VERSION)
+PKG_CHECK_MODULES(libxml2, libxml-2.0 >= $LIBXML2_VERSION)
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([stdint.h stdlib.h string.h sys/socket.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+AC_TYPE_UINT16_T
+AC_TYPE_UINT32_T
+AC_TYPE_UINT8_T
+
+# Checks for library functions.
+AC_CHECK_FUNCS([strcasecmp strdup strerror strndup])
+
+AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter")
+AC_SUBST(GLOBAL_CFLAGS)
+
+m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
+
+AC_OUTPUT([
+Makefile
+src/Makefile
+include/Makefile
+tools/Makefile
+libideviceactivation-1.0.pc
+])
+
+echo "
+Configuration for $PACKAGE $VERSION:
+-------------------------------------------
+
+ Install prefix: .........: $prefix
+
+ Now type 'make' to build $PACKAGE $VERSION,
+ and then 'make install' for installation.
+"
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..ae0895a
--- /dev/null
+++ b/include/Makefile.am
@@ -0,0 +1 @@
+nobase_include_HEADERS = libideviceactivation.h
diff --git a/include/libideviceactivation.h b/include/libideviceactivation.h
new file mode 100644
index 0000000..53607c9
--- /dev/null
+++ b/include/libideviceactivation.h
@@ -0,0 +1,95 @@
+/**
+ * @file libideviceactivation.h
+ * @brief Manage device activation process.
+ *
+ * Copyright (c) 2011-2014 Mirell Development, All Rights Reserved.
+ *
+ * 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 LIBIDEVICEACTIVATION_H
+#define LIBIDEVICEACTIVATION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <libimobiledevice/lockdown.h>
+#include <plist/plist.h>
+
+typedef enum {
+ IDEVICE_ACTIVATION_E_SUCCESS = 0,
+ IDEVICE_ACTIVATION_E_INCOMPLETE_INFO = -1,
+ IDEVICE_ACTIVATION_E_OUT_OF_MEMORY = -2,
+ IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE = -3,
+ IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR = -4,
+ IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR = -5,
+ IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR = -6,
+ IDEVICE_ACTIVATION_E_UNSUPPORTED_FIELD_TYPE = -7,
+ IDEVICE_ACTIVATION_E_INTERNAL_ERROR = -255
+} idevice_activation_error_t;
+
+typedef enum {
+ IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION,
+ IDEVICE_ACTIVATION_CLIENT_ITUNES
+} idevice_activation_client_type_t;
+
+typedef struct idevice_activation_request_private idevice_activation_request;
+typedef idevice_activation_request* idevice_activation_request_t;
+typedef struct idevice_activation_response_private idevice_activation_response;
+typedef idevice_activation_response* idevice_activation_response_t;
+
+/* Interface */
+
+void idevice_activation_set_debug_level(int level);
+
+idevice_activation_error_t idevice_activation_request_new(idevice_activation_client_type_t activation_type, idevice_activation_request_t* request);
+idevice_activation_error_t idevice_activation_request_new_from_lockdownd(idevice_activation_client_type_t activation_type, lockdownd_client_t lockdown, idevice_activation_request_t* request);
+void idevice_activation_request_free(idevice_activation_request_t request);
+
+void idevice_activation_request_get_fields(idevice_activation_request_t request, plist_t* fields);
+void idevice_activation_request_set_fields(idevice_activation_request_t request, plist_t fields);
+void idevice_activation_request_set_fields_from_response(idevice_activation_request_t request, const idevice_activation_response_t response);
+void idevice_activation_request_set_field(idevice_activation_request_t request, const char* key, const char* value);
+void idevice_activation_request_get_field(idevice_activation_request_t request, const char* key, char** value);
+
+void idevice_activation_request_get_url(idevice_activation_request_t request, const char** url);
+void idevice_activation_request_set_url(idevice_activation_request_t request, const char* url);
+
+idevice_activation_error_t idevice_activation_response_new(idevice_activation_response_t* response);
+idevice_activation_error_t idevice_activation_response_new_from_html(const char* content, idevice_activation_response_t* response);
+idevice_activation_error_t idevice_activation_response_to_buffer(idevice_activation_response_t response, char** buffer, size_t* size);
+void idevice_activation_response_free(idevice_activation_response_t response);
+
+void idevice_activation_response_get_field(idevice_activation_response_t response, const char* key, char** value);
+void idevice_activation_response_get_fields(idevice_activation_response_t response, plist_t* fields);
+void idevice_activation_response_get_label(idevice_activation_response_t response, const char* key, char** value);
+
+void idevice_activation_response_get_title(idevice_activation_response_t response, const char** title);
+void idevice_activation_response_get_description(idevice_activation_response_t response, const char** description);
+void idevice_activation_response_get_activation_record(idevice_activation_response_t response, plist_t* activation_record);
+
+int idevice_activation_response_is_activation_acknowledged(idevice_activation_response_t response);
+int idevice_activation_response_is_authentication_required(idevice_activation_response_t response);
+int idevice_activation_response_field_requires_input(idevice_activation_response_t response, const char* key);
+int idevice_activation_response_has_errors(idevice_activation_response_t response);
+
+idevice_activation_error_t idevice_activation_send_request(idevice_activation_request_t request, idevice_activation_response_t* response);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libideviceactivation-1.0.pc.in b/libideviceactivation-1.0.pc.in
new file mode 100644
index 0000000..09f087d
--- /dev/null
+++ b/libideviceactivation-1.0.pc.in
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libideviceactivation
+Description: A library to handle activation of iDevices.
+Version: @VERSION@
+Requires: libplist >= @LIBPLIST_VERSION@ libimobiledevice-1.0 >= @LIBIMOBILEDEVICE_VERSION@ libcurl >= @LIBCURL_VERSION@ libxml-2.0 >= @LIBXML2_VERSION@
+Libs: -L${libdir} -lideviceactivation
+Cflags: -I${includedir}
+
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..0f0d807
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,10 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS) $(libcurl_CFLAGS) $(libxml2_CFLAGS)
+AM_LDFLAGS = $(GLOBAL_LIBS) $(libimobiledevice_LIBS) $(libplist_LIBS) $(libcurl_LIBS) $(libxml2_LIBS)
+
+lib_LTLIBRARIES = libideviceactivation.la
+libideviceactivation_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIDEVICEACTIVATION_SO_VERSION) -no-undefined
+libideviceactivation_la_SOURCES = \
+ activation.c
+
diff --git a/src/activation.c b/src/activation.c
new file mode 100644
index 0000000..40f423f
--- /dev/null
+++ b/src/activation.c
@@ -0,0 +1,1076 @@
+/**
+ * @file activation.c
+ *
+ * Copyright (c) 2011-2014 Mirell Development, All Rights Reserved.
+ *
+ * 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
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <libxml/HTMLtree.h>
+#include <curl/curl.h>
+
+#include <libideviceactivation.h>
+
+#define IDEVICE_ACTIVATION_USER_AGENT_IOS "iOS Device Activator (MobileActivation-20 built on Jan 15 2012 at 19:07:28)"
+#define IDEVICE_ACTIVATION_USER_AGENT_ITUNES "iTunes/11.1.4 (Macintosh; OS X 10.9.1) AppleWebKit/537.73.11"
+#define IDEVICE_ACTIVATION_DEFAULT_URL "https://albert.apple.com/deviceservices/deviceActivation"
+
+typedef enum {
+ IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED,
+ IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA,
+ IDEVICE_ACTIVATION_CONTENT_TYPE_HTML,
+ IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML,
+ IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST,
+ IDEVICE_ACTIVATION_CONTENT_TYPE_UNKNOWN
+} idevice_activation_content_type_t;
+
+struct idevice_activation_request_private {
+ idevice_activation_client_type_t client_type;
+ idevice_activation_content_type_t content_type;
+ char* url;
+ plist_t fields;
+};
+
+struct idevice_activation_response_private {
+ char* raw_content;
+ size_t raw_content_size;
+ idevice_activation_content_type_t content_type;
+ char* title;
+ char* description;
+ plist_t activation_record;
+ plist_t fields;
+ plist_t fields_require_input;
+ plist_t labels;
+ int is_activation_ack;
+ int is_auth_required;
+ int has_errors;
+};
+
+int debug_level = 0;
+
+void idevice_activation_set_debug_level(int level) {
+ debug_level = level;
+}
+
+static idevice_activation_error_t idevice_activation_activation_node_from_plist_xml(const char* plist_xml, size_t size, plist_t* activation_node)
+{
+ plist_t activation_ticket = NULL;
+
+ plist_from_xml(plist_xml, size, &activation_ticket);
+ if (activation_ticket == NULL) {
+ return IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;
+ }
+
+ plist_t activation_node_tmp = plist_dict_get_item(activation_ticket, "iphone-activation");
+ if (!activation_node_tmp) {
+ activation_node_tmp = plist_dict_get_item(activation_ticket, "device-activation");
+ if (!activation_node_tmp) {
+ plist_free(activation_ticket);
+ return IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;
+ }
+ }
+
+ *activation_node = plist_copy(activation_node_tmp);
+ plist_free(activation_ticket);
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+static idevice_activation_error_t idevice_activation_activation_record_from_activation_node(plist_t activation_node, plist_t* activation_record)
+{
+ plist_t record = plist_dict_get_item(activation_node, "activation-record");
+ if (!record) {
+ return IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;
+ }
+
+ *activation_record = plist_copy(record);
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+static void idevice_activation_response_add_field(idevice_activation_response_t response, const char* key, const char* value, int required_input)
+{
+ plist_dict_set_item(response->fields, key, plist_new_string(value));
+ if (required_input) {
+ plist_dict_set_item(response->fields_require_input, key, plist_new_bool(1));
+ }
+}
+
+static idevice_activation_error_t idevice_activation_parse_buddyml_response(idevice_activation_response_t response)
+{
+ idevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;
+ xmlDocPtr doc = NULL;
+ xmlXPathContextPtr context = NULL;
+ xmlXPathObjectPtr xpath_result = NULL;
+ int i = 0;
+
+ if (!response->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML)
+ return IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE;
+
+ doc = xmlReadMemory(response->raw_content, response->raw_content_size, "ideviceactivation.xml", NULL, XML_PARSE_NOERROR);
+ if (!doc) {
+ result = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;
+ goto cleanup;
+ }
+
+ context = xmlXPathNewContext(doc);
+ if (!context) {
+ result = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;
+ goto cleanup;
+ }
+
+ // check for an error
+ // <navigationBar> appears directly under <xmlui> only in case of an error
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/navigationBar/@title", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {
+ xmlChar* content = xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
+ if (content) {
+ response->title = strdup((const char*) content);
+ xmlFree(content);
+ }
+
+ response->has_errors = 1;
+ goto cleanup;
+ }
+
+ // check for activation ack
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/clientInfo[@ack-received='true']", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {
+ // existing activation_acknowledged
+ response->is_activation_ack = 1;
+ goto cleanup;
+ }
+
+ // retrieve response title
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/alert/@title", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {
+ // incorrect credentials
+ // <alert> exists only in case of incorrect credentials
+ xmlChar* content = xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
+ if (content) {
+ response->title = strdup((const char*) content);
+ xmlFree(content);
+ }
+ } else {
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/page/navigationBar/@title", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (!xpath_result->nodesetval) {
+ result = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;
+ goto cleanup;
+ }
+ xmlChar* content = xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
+ if (content) {
+ response->title = strdup((const char*) content);
+ xmlFree(content);
+ }
+ }
+
+ // retrieve response description
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/page/tableView/section[@footer and not(@footerLinkURL)]/@footer", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval) {
+ char* response_description = (char*) malloc(sizeof(char));
+ response_description[0] = '\0';
+
+ for(i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
+ xmlChar* content = xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
+ if (content) {
+ const size_t len = strlen(response_description);
+ response_description = (char*) realloc(response_description, len + xmlStrlen(content) + 2);
+ sprintf(&response_description[len], "%s\n", (const char*) content);
+ xmlFree(content);
+ }
+ }
+
+ if (strlen(response_description) > 0) {
+ // remove the last '\n'
+ response_description[strlen(response_description) - 1] = '\0';
+ response->description = response_description;
+ } else {
+ free(response_description);
+ }
+ }
+
+ // retrieve input fields
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/page//editableTextRow", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval) {
+ for(i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
+ xmlChar* id = xmlGetProp(xpath_result->nodesetval->nodeTab[i], (const xmlChar*) "id");
+ if (!id) {
+ result = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;
+ goto cleanup;
+ }
+
+ idevice_activation_response_add_field(response, (const char*) id, "", 1);
+
+ xmlChar* label = xmlGetProp(xpath_result->nodesetval->nodeTab[i], (const xmlChar*) "label");
+ if (label) {
+ plist_dict_set_item(response->labels, (const char*)id, plist_new_string((const char*) label));
+ xmlFree(label);
+ }
+
+ xmlFree(id);
+ }
+ }
+
+ // retrieve server info fields
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "/xmlui/serverInfo/@*", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval) {
+ for(i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
+ xmlChar* content = xmlNodeGetContent(xpath_result->nodesetval->nodeTab[i]);
+ if (content) {
+ if (!xmlStrcmp(xpath_result->nodesetval->nodeTab[i]->name, (const xmlChar*) "isAuthRequired")) {
+ response->is_auth_required = 1;
+ }
+
+ idevice_activation_response_add_field(response,
+ (const char*) xpath_result->nodesetval->nodeTab[i]->name, (const char*) content, 0);
+ xmlFree(content);
+ }
+ }
+ }
+
+ if (plist_dict_get_size(response->fields) == 0) {
+ response->has_errors = 1;
+ }
+
+cleanup:
+ if (xpath_result)
+ xmlXPathFreeObject(xpath_result);
+ if (context)
+ xmlXPathFreeContext(context);
+ if (doc)
+ xmlFreeDoc(doc);
+
+ return result;
+}
+
+static idevice_activation_error_t idevice_activation_parse_html_response(idevice_activation_response_t response)
+{
+ idevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;
+ xmlDocPtr doc = NULL;
+ xmlXPathContextPtr context = NULL;
+ xmlXPathObjectPtr xpath_result = NULL;
+
+ if (!response->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_HTML)
+ return IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE;
+
+ doc = xmlReadMemory(response->raw_content, response->raw_content_size, "ideviceactivation.xml", NULL, XML_PARSE_RECOVER | XML_PARSE_NOERROR);
+ if (!doc) {
+ result = IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR;
+ goto cleanup;
+ }
+
+ context = xmlXPathNewContext(doc);
+ if (!context) {
+ result = IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR;
+ goto cleanup;
+ }
+
+ // check for authentication required
+ if (xpath_result) {
+ xmlXPathFreeObject(xpath_result);
+ xpath_result = NULL;
+ }
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "//input[@name='isAuthRequired' and @value='true']", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {
+ response->is_auth_required = 1;
+ goto cleanup;
+ }
+
+ // check for plist content
+ xpath_result = xmlXPathEvalExpression((const xmlChar*) "//script[@type='text/x-apple-plist']/plist", context);
+ if (!xpath_result) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {
+ plist_t activation_node = NULL;
+ xmlBufferPtr plistNodeBuffer = xmlBufferCreate();
+ if (htmlNodeDump(plistNodeBuffer, doc, xpath_result->nodesetval->nodeTab[0]) == -1) {
+ result = IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR;
+ goto local_cleanup;
+ }
+
+ result = idevice_activation_activation_node_from_plist_xml(
+ (const char*) plistNodeBuffer->content, plistNodeBuffer->use, &activation_node);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ response->has_errors = 1;
+ result = IDEVICE_ACTIVATION_E_SUCCESS;
+ goto local_cleanup;
+ }
+
+ // check for ack-received
+ plist_t ack_received = plist_dict_get_item(activation_node, "ack-received");
+ if (ack_received) {
+ uint8_t val = 0;
+ plist_get_bool_val(ack_received, &val);
+ if (val) {
+ response->is_activation_ack = 1;
+ } else {
+ result = IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;
+ }
+
+ goto local_cleanup;
+ }
+
+ // try to retrieve the activation record
+ result = idevice_activation_activation_record_from_activation_node(activation_node, &response->activation_record);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ goto local_cleanup;
+ }
+
+ local_cleanup:
+ if (plistNodeBuffer)
+ xmlBufferFree(plistNodeBuffer);
+ if (activation_node)
+ plist_free(activation_node);
+ goto cleanup;
+ }
+
+ response->has_errors = 1;
+
+cleanup:
+ if (xpath_result)
+ xmlXPathFreeObject(xpath_result);
+ if (context)
+ xmlXPathFreeContext(context);
+ if (doc)
+ xmlFreeDoc(doc);
+
+ return result;
+}
+
+static idevice_activation_error_t idevice_activation_parse_raw_response(idevice_activation_response_t response)
+{
+ switch(response->content_type)
+ {
+ case IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST:
+ {
+ plist_t activation_node = NULL;
+ idevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;
+
+ result = idevice_activation_activation_node_from_plist_xml(response->raw_content, response->raw_content_size, &activation_node);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ return result;
+ }
+
+ result = idevice_activation_activation_record_from_activation_node(activation_node, &response->activation_record);
+ plist_free(activation_node);
+ return result;
+ }
+ case IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML:
+ return idevice_activation_parse_buddyml_response(response);
+ case IDEVICE_ACTIVATION_CONTENT_TYPE_HTML:
+ return idevice_activation_parse_html_response(response);
+ default:
+ return IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE;
+ }
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+static size_t idevice_activation_write_callback(char* data, size_t size, size_t nmemb, void* userdata)
+{
+ idevice_activation_response_t response = (idevice_activation_response_t)userdata;
+ const size_t total = size * nmemb;
+
+ if (total != 0) {
+ response->raw_content = realloc(response->raw_content, response->raw_content_size + total);
+ memcpy(response->raw_content + response->raw_content_size, data, total);
+ response->raw_content_size += total;
+ }
+
+ return total;
+}
+
+static size_t idevice_activation_header_callback(void *data, size_t size, size_t nmemb, void *userdata)
+{
+ idevice_activation_response_t response = (idevice_activation_response_t)userdata;
+ const size_t total = size * nmemb;
+ if (total != 0) {
+ if (strstr(data, "Content-Type: text/xml") != NULL) {
+ response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST;
+ } else if (strstr(data, "Content-Type: application/x-buddyml") != NULL) {
+ response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML;
+ } else if (strstr(data, "Content-Type: text/html") != NULL) {
+ response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_HTML;
+ }
+ }
+ return total;
+}
+
+static char* urlencode(const char* buf)
+{
+ static const signed char conv_table[256] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
+ };
+
+ unsigned int i;
+ int count = 0;
+ for (i = 0; i < strlen(buf); i++) {
+ if (conv_table[(int)buf[i]]) {
+ count++;
+ }
+ }
+ int newsize = strlen(buf) + count*2 + 1;
+ char* res = malloc(newsize);
+ int o = 0;
+ for (i = 0; i < strlen(buf); i++) {
+ if (conv_table[(int)buf[i]]) {
+ sprintf(&res[o], "%%%02X", (unsigned char)buf[i]);
+ o+=3;
+ } else {
+ res[o] = buf[i];
+ o++;
+ }
+ }
+ res[o] = '\0';
+
+ return res;
+}
+
+static int plist_strip_xml(char** xmlplist)
+{
+ uint32_t size = 0;
+
+ if (!xmlplist && !*xmlplist)
+ return -1;
+
+ char* start = strstr(*xmlplist, "<plist version=\"1.0\">\n");
+ if (start == NULL) {
+ return -1;
+ }
+
+ char* stop = strstr(*xmlplist, "\n</plist>");
+ if (stop == NULL) {
+ return -1;
+ }
+
+ start += strlen("<plist version=\"1.0\">\n");
+ size = stop - start;
+ char* stripped = malloc(size + 1);
+ memset(stripped, '\0', size + 1);
+ memcpy(stripped, start, size);
+ free(*xmlplist);
+ *xmlplist = stripped;
+ stripped = NULL;
+
+ return 0;
+}
+
+idevice_activation_error_t idevice_activation_request_new(idevice_activation_client_type_t client_type, idevice_activation_request_t* request)
+{
+ idevice_activation_request_t tmp_request = (idevice_activation_request_t) malloc(sizeof(idevice_activation_request));
+
+ if (!tmp_request) {
+ return IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;
+ }
+
+ tmp_request->client_type = client_type;
+ tmp_request->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED;
+ tmp_request->url = strdup(IDEVICE_ACTIVATION_DEFAULT_URL);
+ tmp_request->fields = plist_new_dict();
+ *request = tmp_request;
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+idevice_activation_error_t idevice_activation_request_new_from_lockdownd(idevice_activation_client_type_t client_type, lockdownd_client_t lockdown, idevice_activation_request** request)
+{
+ // check arguments
+ if (!lockdown) {
+ return IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ }
+
+ plist_t node = NULL;
+ plist_t fields = plist_new_dict();
+
+ // add InStoreActivation
+ plist_dict_set_item(fields, "InStoreActivation", plist_new_string("false"));
+
+ // add AppleSerialNumber
+ if ((lockdownd_get_value(lockdown, NULL, "SerialNumber", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
+ fprintf(stderr, "%s: Unable to get SerialNumber from lockdownd\n", __func__);
+ plist_free(fields);
+ return IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;
+ } else {
+ plist_dict_set_item(fields, "AppleSerialNumber", plist_copy(node));
+ }
+ if (node) {
+ plist_free(node);
+ node = NULL;
+ }
+
+ // add IMEI
+ if ((lockdownd_get_value(lockdown, NULL, "InternationalMobileEquipmentIdentity", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
+ fprintf(stderr, "%s: Unable to get IMEI from lockdownd\n", __func__);
+ } else {
+ plist_dict_set_item(fields, "IMEI", plist_copy(node));
+ }
+ if (node) {
+ plist_free(node);
+ node = NULL;
+ }
+
+ // add MEID
+ if ((lockdownd_get_value(lockdown, NULL, "MobileEquipmentIdentifier", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
+ fprintf(stderr, "%s: Unable to get MEID from lockdownd\n", __func__);
+ } else {
+ plist_dict_set_item(fields, "MEID", plist_copy(node));
+ }
+ if (node) {
+ plist_free(node);
+ node = NULL;
+ }
+
+ // add IMSI
+ if ((lockdownd_get_value(lockdown, NULL, "InternationalMobileSubscriberIdentity", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
+ fprintf(stderr, "%s: Unable to get IMSI from lockdownd\n", __func__);
+ } else {
+ plist_dict_set_item(fields, "IMSI", plist_copy(node));
+ }
+ if (node) {
+ plist_free(node);
+ node = NULL;
+ }
+
+ // add ICCID
+ if ((lockdownd_get_value(lockdown, NULL, "IntegratedCircuitCardIdentity", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
+ fprintf(stderr, "%s: Unable to get ICCID from lockdownd\n", __func__);
+ } else {
+ plist_dict_set_item(fields, "ICCID", plist_copy(node));
+ }
+ if (node) {
+ plist_free(node);
+ node = NULL;
+ }
+
+ // add activation-info
+ if ((lockdownd_get_value(lockdown, NULL, "ActivationInfo", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_DICT)) {
+ fprintf(stderr, "%s: Unable to get ActivationInfo from lockdownd\n", __func__);
+ plist_free(fields);
+ return IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;
+ }
+ plist_dict_set_item(fields, "activation-info", plist_copy(node));
+ plist_free(node);
+ node = NULL;
+
+ idevice_activation_request* tmp_request = (idevice_activation_request*) malloc(sizeof(idevice_activation_request));
+
+ if (!tmp_request) {
+ plist_free(fields);
+ return IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;
+ }
+
+ tmp_request->client_type = client_type;
+ tmp_request->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA;
+ tmp_request->url = strdup(IDEVICE_ACTIVATION_DEFAULT_URL);
+ tmp_request->fields = fields;
+ *request = tmp_request;
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+void idevice_activation_request_free(idevice_activation_request_t request)
+{
+ if (!request)
+ return;
+
+ if (request->fields)
+ plist_free(request->fields);
+
+ free(request);
+}
+
+void idevice_activation_request_get_fields(idevice_activation_request_t request, plist_t* fields)
+{
+ *fields = plist_copy(request->fields);
+}
+
+void idevice_activation_request_set_fields(idevice_activation_request_t request, plist_t fields)
+{
+ if (!fields)
+ return;
+
+ if (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED) {
+ // if at least one of the new fields has a different type than string, we have to change the type
+ plist_dict_iter iter = NULL;
+ plist_dict_new_iter(fields, &iter);
+ plist_t item = NULL;
+ do {
+ plist_dict_next_item(fields, iter, NULL, &item);
+ if (item && plist_get_node_type(item) != PLIST_STRING) {
+ request->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA;
+ break;
+ }
+ } while(item);
+ }
+
+ plist_dict_merge(&request->fields, fields);
+}
+
+void idevice_activation_request_set_fields_from_response(idevice_activation_request_t request, const idevice_activation_response_t response)
+{
+ plist_t response_fields = NULL;
+ idevice_activation_response_get_fields(response, &response_fields);
+ if (response_fields) {
+ idevice_activation_request_set_fields(request, response_fields);
+ free(response_fields);
+ }
+}
+
+void idevice_activation_request_set_field(idevice_activation_request_t request, const char* key, const char* value)
+{
+ plist_dict_set_item(request->fields, key, plist_new_string(value));
+}
+
+void idevice_activation_request_get_field(idevice_activation_request_t request, const char* key, char** value)
+{
+ char* tmp_value = NULL;
+
+ plist_t item = plist_dict_get_item(request->fields, key);
+
+ if (item && plist_get_node_type(item) == PLIST_STRING) {
+ plist_get_string_val(item, &tmp_value);
+ } else {
+ uint32_t data_size = 0;
+ plist_to_xml(item, &tmp_value, &data_size);
+ plist_strip_xml(&tmp_value);
+ }
+
+ *value = tmp_value;
+}
+
+void idevice_activation_request_get_url(idevice_activation_request_t request, const char** url)
+{
+ *url = request->url;
+}
+
+void idevice_activation_request_set_url(idevice_activation_request_t request, const char* url)
+{
+ if (request->url) {
+ free(request->url);
+ }
+
+ request->url = strdup(url);
+}
+
+idevice_activation_error_t idevice_activation_response_new(idevice_activation_response_t* response)
+{
+ idevice_activation_response_t tmp_response = (idevice_activation_response_t) malloc(sizeof(idevice_activation_response));
+
+ if (!tmp_response) {
+ return IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;
+ }
+
+ tmp_response->raw_content = NULL;
+ tmp_response->raw_content_size = 0;
+ tmp_response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_UNKNOWN;
+ tmp_response->title = NULL;
+ tmp_response->description = NULL;
+ tmp_response->activation_record = NULL;
+ tmp_response->fields = plist_new_dict();
+ tmp_response->fields_require_input = plist_new_dict();
+ tmp_response->labels = plist_new_dict();
+ tmp_response->is_activation_ack = 0;
+ tmp_response->is_auth_required = 0;
+ tmp_response->has_errors = 0;
+ *response = tmp_response;
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+idevice_activation_error_t idevice_activation_response_new_from_html(const char* content, idevice_activation_response_t* response)
+{
+ idevice_activation_response_t tmp_response = NULL;
+ idevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;
+
+ result = idevice_activation_response_new(&tmp_response);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ return result;
+ }
+
+ const size_t tmp_size = strlen(content);
+ char* tmp_content = (char*) malloc(sizeof(char) * tmp_size);
+
+ if (!tmp_content) {
+ idevice_activation_response_free(tmp_response);
+ return IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;
+ }
+
+ memcpy(tmp_content, content, tmp_size);
+
+ tmp_response->raw_content = tmp_content;
+ tmp_response->raw_content_size = tmp_size;
+ tmp_response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_HTML;
+
+ result = idevice_activation_parse_html_response(tmp_response);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ idevice_activation_response_free(tmp_response);
+ return result;
+ }
+
+ *response = tmp_response;
+
+ return result;
+}
+
+idevice_activation_error_t idevice_activation_response_to_buffer(idevice_activation_response_t response, char** buffer, size_t* size)
+{
+ char* tmp_buffer = (char*) malloc(sizeof(char) * response->raw_content_size);
+ if (!tmp_buffer) {
+ return IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;
+ }
+
+ memcpy(tmp_buffer, response->raw_content, response->raw_content_size);
+
+ *buffer = tmp_buffer;
+ *size = response->raw_content_size;
+
+ return IDEVICE_ACTIVATION_E_SUCCESS;
+}
+
+void idevice_activation_response_free(idevice_activation_response_t response)
+{
+ if (response->raw_content)
+ free(response->raw_content);
+ if (response->title)
+ free(response->title);
+ if (response->description)
+ free(response->description);
+ if (response->activation_record)
+ plist_free(response->activation_record);
+ if (response->fields)
+ plist_free(response->fields);
+ if (response->fields_require_input)
+ plist_free(response->fields_require_input);
+ if (response->labels)
+ plist_free(response->labels);
+ free(response);
+}
+
+void idevice_activation_response_get_field(idevice_activation_response_t response, const char* key, char** value)
+{
+ *value = NULL;
+ plist_t item = plist_dict_get_item(response->fields, key);
+
+ if (item && plist_get_node_type(item) == PLIST_STRING) {
+ plist_get_string_val(item, value);
+ }
+}
+
+void idevice_activation_response_get_fields(idevice_activation_response_t response, plist_t* fields)
+{
+ *fields = plist_copy(response->fields);
+}
+
+void idevice_activation_response_get_label(idevice_activation_response_t response, const char* key, char** value)
+{
+ *value = NULL;
+ plist_t item = plist_dict_get_item(response->labels, key);
+ if (item) {
+ plist_get_string_val(item, value);
+ }
+}
+
+void idevice_activation_response_get_title(idevice_activation_response_t response, const char** title)
+{
+ *title = response->title;
+}
+
+void idevice_activation_response_get_description(idevice_activation_response_t response, const char** description)
+{
+ *description = response->description;
+}
+
+void idevice_activation_response_get_activation_record(idevice_activation_response_t response, plist_t* activation_record)
+{
+ if (response->activation_record) {
+ *activation_record = plist_copy(response->activation_record);
+ } else {
+ *activation_record = NULL;
+ }
+}
+
+int idevice_activation_response_is_activation_acknowledged(idevice_activation_response_t response)
+{
+ return response->is_activation_ack;
+}
+
+int idevice_activation_response_is_authentication_required(idevice_activation_response_t response)
+{
+ return response->is_auth_required;
+}
+
+int idevice_activation_response_field_requires_input(idevice_activation_response_t response, const char* key)
+{
+ if (plist_dict_get_item(response->fields_require_input, key)) {
+ return 1;
+ }
+ return 0;
+}
+
+int idevice_activation_response_has_errors(idevice_activation_response_t response)
+{
+ return response->has_errors;
+}
+
+idevice_activation_error_t idevice_activation_send_request(idevice_activation_request_t request, idevice_activation_response_t* response)
+{
+ idevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;
+
+ // check arguments
+ if (!request) {
+ return IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ }
+
+ plist_dict_iter iter = NULL;
+ plist_dict_new_iter(request->fields, &iter);
+ if (!iter) {
+ return IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ curl_global_init(CURL_GLOBAL_ALL);
+ CURL* handle = curl_easy_init();
+ struct curl_httppost* form = NULL;
+
+ if (!handle) {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ switch (request->client_type) {
+ case IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION:
+ curl_easy_setopt(handle, CURLOPT_USERAGENT, IDEVICE_ACTIVATION_USER_AGENT_IOS);
+ break;
+ case IDEVICE_ACTIVATION_CLIENT_ITUNES:
+ curl_easy_setopt(handle, CURLOPT_USERAGENT, IDEVICE_ACTIVATION_USER_AGENT_ITUNES);
+ break;
+ default:
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ char* key = NULL;
+ char* svalue = NULL;
+ plist_t value_node = NULL;
+
+ if (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA) {
+ struct curl_httppost* last = NULL;
+ do {
+ plist_dict_next_item(request->fields, iter, &key, &value_node);
+ if (key != NULL) {
+ if (value_node != NULL) {
+ // serialize plist node as field value
+ if (plist_get_node_type(value_node) == PLIST_STRING) {
+ plist_get_string_val(value_node, &svalue);
+ } else {
+ uint32_t data_size = 0;
+ plist_to_xml(value_node, &svalue, &data_size);
+ plist_strip_xml(&svalue);
+ }
+
+ curl_formadd(&form, &last, CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, svalue, CURLFORM_END);
+
+ if (svalue)
+ free(svalue);
+ svalue = NULL;
+ }
+ }
+ } while(value_node != NULL);
+ curl_easy_setopt(handle, CURLOPT_HTTPPOST, form);
+
+ } else if (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED) {
+ char* postdata = (char*) malloc(sizeof(char));
+ postdata[0] = '\0';
+ do {
+ plist_dict_next_item(request->fields, iter, &key, &value_node);
+ if (key != NULL) {
+ if (value_node != NULL) {
+ // serialize plist node as field value
+ if (plist_get_node_type(value_node) == PLIST_STRING) {
+ plist_get_string_val(value_node, &svalue);
+ } else {
+ // only strings supported
+ if (postdata)
+ free(postdata);
+ result = IDEVICE_ACTIVATION_E_UNSUPPORTED_FIELD_TYPE;
+ goto cleanup;
+ }
+
+ char* value_encoded = urlencode(svalue);
+ if (value_encoded) {
+ const size_t new_size = strlen(postdata) + strlen(key) + strlen(value_encoded) + 3;
+ postdata = (char*) realloc(postdata, new_size);
+ sprintf(&postdata[strlen(postdata)], "%s=%s&", key, value_encoded);
+ free(value_encoded);
+ }
+
+ if (svalue)
+ free(svalue);
+ svalue = NULL;
+ }
+ }
+ } while(value_node != NULL);
+
+ // remove the last '&'
+ const size_t postdata_len = strlen(postdata);
+ if (postdata_len > 0)
+ postdata[postdata_len - 1] = '\0';
+
+ curl_easy_setopt(handle, CURLOPT_POST, 1);
+ curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postdata);
+ curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, strlen(postdata));
+ }
+ else {
+ result = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ idevice_activation_response_t tmp_response = NULL;
+ result = idevice_activation_response_new(&tmp_response);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ goto cleanup;
+ }
+
+ curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt(handle, CURLOPT_WRITEDATA, tmp_response);
+ curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &idevice_activation_write_callback);
+ curl_easy_setopt(handle, CURLOPT_HEADERDATA, tmp_response);
+ curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, &idevice_activation_header_callback);
+ curl_easy_setopt(handle, CURLOPT_URL, request->url);
+
+ // enable communication debugging
+ if (debug_level > 0) {
+ curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
+ }
+
+ curl_easy_perform(handle);
+
+ if (debug_level > 0) {
+ fprintf(stderr, "%*s\n", (int)tmp_response->raw_content_size, tmp_response->raw_content);
+ }
+
+ result = idevice_activation_parse_raw_response(tmp_response);
+ if (result != IDEVICE_ACTIVATION_E_SUCCESS) {
+ goto cleanup;
+ }
+
+ *response = tmp_response;
+
+ result = IDEVICE_ACTIVATION_E_SUCCESS;
+
+cleanup:
+ if (iter)
+ free(iter);
+ if (form)
+ curl_formfree(form);
+ if (handle)
+ curl_easy_cleanup(handle);
+
+ curl_global_cleanup();
+
+ return result;
+}
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644
index 0000000..4eb9a7d
--- /dev/null
+++ b/tools/Makefile.am
@@ -0,0 +1,11 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS)
+AM_LDFLAGS = $(GLOBAL_LIBS) $(libimobiledevice_LIBS) $(libplist_LIBS)
+
+bin_PROGRAMS = ideviceactivation
+
+ideviceactivation_SOURCES = ideviceactivation.c
+ideviceactivation_CFLAGS = $(AM_CFLAGS)
+ideviceactivation_LDFLAGS = $(AM_LDFLAGS)
+ideviceactivation_LDADD = $(top_builddir)/src/libideviceactivation.la
diff --git a/tools/ideviceactivation.c b/tools/ideviceactivation.c
new file mode 100644
index 0000000..8fd5098
--- /dev/null
+++ b/tools/ideviceactivation.c
@@ -0,0 +1,297 @@
+/**
+ * @file ideviceactivate.h
+ * @brief A command line tool to handle the activation process.
+ *
+ * Copyright (c) 2011-2014 Mirell Development, All Rights Reserved.
+ *
+ * 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
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <plist/plist.h>
+#include <libimobiledevice/lockdown.h>
+#include <libimobiledevice/libimobiledevice.h>
+#include <libideviceactivation.h>
+
+static void print_usage(int argc, char **argv)
+{
+ char *name = NULL;
+
+ name = strrchr(argv[0], '/');
+ printf("Usage: %s COMMAND [OPTIONS]\n", (name ? name + 1: argv[0]));
+ printf("Activate or deactivate a device.\n\n");
+ printf("Where COMMAND is one of:\n");
+ printf(" activate\t\tattempt to activate the device\n");
+ printf(" deactivate\t\tdeactivate the device\n");
+ printf("\nThe following OPTIONS are accepted:\n");
+ printf(" -d, --debug\t\tenable communication debugging\n");
+ printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n");
+ printf(" -h, --help\t\tprints usage information\n");
+ printf("\n");
+}
+
+int main(int argc, char *argv[])
+{
+ idevice_t device = NULL;
+ idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
+ lockdownd_client_t lockdown = NULL;
+ idevice_activation_request_t request = NULL;
+ idevice_activation_response_t response = NULL;
+ const char* response_title = NULL;
+ const char* response_description = NULL;
+ char* field_key = NULL;
+ char* field_label = NULL;
+ char input[1024];
+ plist_t fields = NULL;
+ plist_dict_iter iter = NULL;
+ plist_t record = NULL;
+ char *udid = NULL;
+ int i;
+ int result = EXIT_FAILURE;
+
+ typedef enum {
+ OP_NONE = 0, OP_ACTIVATE, OP_DEACTIVATE
+ } op_t;
+ op_t op = OP_NONE;
+
+ /* parse cmdline args */
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
+ idevice_set_debug_level(1);
+ idevice_activation_set_debug_level(1);
+ continue;
+ }
+ else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) {
+ i++;
+ if (!argv[i] || (strlen(argv[i]) != 40)) {
+ print_usage(argc, argv);
+ return EXIT_FAILURE;
+ }
+ udid = argv[i];
+ continue;
+ }
+ else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
+ print_usage(argc, argv);
+ return EXIT_SUCCESS;
+ }
+ else if (!strcmp(argv[i], "activate")) {
+ op = OP_ACTIVATE;
+ continue;
+ }
+ else if (!strcmp(argv[i], "deactivate")) {
+ op = OP_DEACTIVATE;
+ continue;
+ }
+ else {
+ print_usage(argc, argv);
+ return EXIT_SUCCESS;
+ }
+ }
+
+ if (op == OP_NONE) {
+ print_usage(argc, argv);
+ return EXIT_FAILURE;
+ }
+
+ if (udid) {
+ ret = idevice_new(&device, udid);
+ if (ret != IDEVICE_E_SUCCESS) {
+ printf("No device found with UDID %s, is it plugged in?\n", udid);
+ return EXIT_FAILURE;
+ }
+ }
+ else
+ {
+ ret = idevice_new(&device, NULL);
+ if (ret != IDEVICE_E_SUCCESS) {
+ printf("No device found, is it plugged in?\n");
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown, "ideviceactivation")) {
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ switch (op) {
+ case OP_DEACTIVATE:
+ // deactivate device using lockdown
+ if (LOCKDOWN_E_SUCCESS != lockdownd_deactivate(lockdown)) {
+ fprintf(stderr, "Failed to deactivate device.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ result = EXIT_SUCCESS;
+ printf("Successfully deactivated device.\n");
+ break;
+ case OP_ACTIVATE:
+ default:
+ // create activation request
+ if (idevice_activation_request_new_from_lockdownd(
+ IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION, lockdown, &request) != IDEVICE_ACTIVATION_E_SUCCESS) {
+ fprintf(stderr, "Failed to create activation request.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ while(1) {
+ if (idevice_activation_send_request(request, &response) != IDEVICE_ACTIVATION_E_SUCCESS) {
+ fprintf(stderr, "Failed to send request or retrieve response.\n");
+ // Here response might have some content that could't be correctly interpreted (parsed)
+ // by the library. Printing out the content could help to identify the cause of the error.
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ if (idevice_activation_response_is_activation_acknowledged(response)) {
+ printf("Activation server reports that device is already activated.\n");
+ result = EXIT_SUCCESS;
+ goto cleanup;
+ }
+
+ if (idevice_activation_response_has_errors(response)) {
+ fprintf(stderr, "Activation server repors errors.\n");
+
+ idevice_activation_response_get_title(response, &response_title);
+ if (response_title) {
+ fprintf(stderr, "\t%s\n", response_title);
+ }
+
+ idevice_activation_response_get_description(response, &response_description);
+ if (response_description) {
+ fprintf(stderr, "\t%s\n", response_description);
+ }
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ idevice_activation_response_get_activation_record(response, &record);
+
+ if (record) {
+ // activate device using lockdown
+ if (LOCKDOWN_E_SUCCESS != lockdownd_activate(lockdown, record)) {
+ fprintf(stderr, "Failed to activate device with record.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ // set ActivationStateAcknowledged if we succeeded
+ if (LOCKDOWN_E_SUCCESS != lockdownd_set_value(lockdown, NULL, "ActivationStateAcknowledged", plist_new_bool(1))) {
+ fprintf(stderr, "Failed to set ActivationStateAcknowledged on device.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+ break;
+ } else {
+ idevice_activation_response_get_title(response, &response_title);
+ if (response_title) {
+ fprintf(stderr, "Server reports:\n%s\n", response_title);
+ }
+
+ idevice_activation_response_get_description(response, &response_description);
+ if (response_description) {
+ fprintf(stderr, "Server reports:\n%s\n", response_description);
+ }
+
+ idevice_activation_response_get_fields(response, &fields);
+ if (!fields || plist_dict_get_size(fields) == 0) {
+ // we have no activation record, no reported erros, no acknowledgment and no fields to send
+ fprintf(stderr, "Unknown error.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ plist_dict_new_iter(fields, &iter);
+ if (!iter) {
+ fprintf(stderr, "Unknown error.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ idevice_activation_request_free(request);
+ request = NULL;
+ if (idevice_activation_request_new(
+ IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION, &request) != IDEVICE_ACTIVATION_E_SUCCESS) {
+ fprintf(stderr, "Could not create new request.\n");
+ result = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ idevice_activation_request_set_fields_from_response(request, response);
+
+ do {
+ field_key = NULL;
+ plist_dict_next_item(fields, iter, &field_key, NULL);
+ if (field_key) {
+ if (idevice_activation_response_field_requires_input(response, field_key)) {
+ idevice_activation_response_get_label(response, field_key, &field_label);
+ printf("input %s: ", field_label ? field_label : field_key);
+ fflush(stdin);
+ scanf("%1023s", input);
+ idevice_activation_request_set_field(request, field_key, input);
+ if (field_label) {
+ free(field_label);
+ field_label = NULL;
+ }
+ }
+ }
+ } while(field_key);
+
+ free(iter);
+ iter = NULL;
+ idevice_activation_response_free(response);
+ response = NULL;
+ }
+
+ }
+
+ result = EXIT_SUCCESS;
+ printf("Successfully activated device.\n");
+ break;
+ }
+
+cleanup:
+ if (request)
+ idevice_activation_request_free(request);
+
+ if (response)
+ idevice_activation_response_free(response);
+
+ if (fields)
+ plist_free(fields);
+
+ if (field_label)
+ free(field_label);
+
+ if (iter)
+ free(iter);
+
+ if (record)
+ plist_free(record);
+
+ if (lockdown)
+ lockdownd_client_free(lockdown);
+
+ if (device)
+ idevice_free(device);
+
+ return result;
+}