Implemented HTTPS support with libgit2 using OpenSSL.

Might fix issue #68.
This commit is contained in:
WrinklyNinja
2013-09-27 13:04:02 +01:00
parent 43f3d8af15
commit e08363180f
3 changed files with 33 additions and 15 deletions
+13 -2
View File
@@ -68,6 +68,7 @@ ENDIF ()
# MinGW settings.
IF (MINGW)
link_directories("${PROJECT_LIBS_DIR}/openssl")
set (CMAKE_C_FLAGS "-m${PROJECT_ARCH} -O3")
set (CMAKE_CXX_FLAGS "-m${PROJECT_ARCH} -O3")
set (CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static-libgcc -Wl,--subsystem,windows")
@@ -81,9 +82,9 @@ IF (MSVC)
set (BOOST_SUFFIX "-vc110-mt-1_52")
ENDIF ()
set (BOSS_LIBS version
set (BOSS_LIBS ${BOSS_LIBS}
version
git2
ws2_32
zlibstatic
loadorder${PROJECT_ARCH}
yaml-cpp
@@ -97,6 +98,16 @@ set (BOSS_LIBS version
boost_system${BOOST_SUFFIX}
boost_regex${BOOST_SUFFIX})
IF (MINGW)
set (BOSS_LIBS ${BOSS_LIBS}
ssl
crypto
ws2_32)
ELSE ()
set (BOSS_LIBS ${BOSS_LIBS}
ws2_32)
ENDIF ()
set (BOSS_GUI_LIBS ${BOSS_LIBS}
wx_mswu_webview-2.9-${COMPILER_PREFIX}
wx_mswu_core-2.9-${COMPILER_PREFIX}
+14 -1
View File
@@ -32,6 +32,7 @@ BOSS requires the following libraries:
* [Libespm](http://github.com/WrinklyNinja/libespm)
* [Libgit2](https://github.com/libgit2) v0.19.0.
* [Libloadorder](http://github.com/WrinklyNinja/libloadorder)
* [OpenSSL](https://www.openssl.org) - only if HTTPS support in libgit2 is required using compilers other than MSVC.
* [PugiXML](http://code.google.com/p/pugixml/) v1.2 or later.
* [wxWidgets](http://www.wxwidgets.org) v2.9.5 or later.
* [yaml-cpp](http://code.google.com/p/yaml-cpp/) v0.5.1 or later.
@@ -107,17 +108,29 @@ cp zconf.h ../zconf.h
cmake . -DCMAKE_C_FLAGS=-m32 -DPROJECT_ARCH=32 -DCMAKE_TOOLCHAIN_FILE=../BOSSv3/mingw-toolchain.cmake -DBOOST_ROOT=../boost
```
### Libespm
Follow the instructions in libespm's README.md to build it as a static library.
### Libloadorder
Follow the instructions in libloadorder's README.md to build it as a static library.
### OpenSSL
```
./Configure --cross-compile-prefix=i686-w64-mingw32- mingw
make
```
### Libgit2
```
mkdir build && cd build
cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-m32 -DPROJECT_ARCH=32 -DCMAKE_TOOLCHAIN_FILE=../BOSSv3/mingw-toolchain.cmake
make
```
If building with SSL support using OpenSSL, also pass `-DOPENSSL_ROOT_DIR=../openssl`.
### BOSS
+6 -12
View File
@@ -123,15 +123,6 @@ namespace boss {
*/
pointers_struct ptrs;
const git_transfer_progress * stats = NULL;
std::string httpURL;
//If the URL is a HTTPS URL, convert it to a HTTP URL, because the build of libgit2 BOSS uses doesn't support HTTPS.
BOOST_LOG_TRIVIAL(trace) << "Checking URL type.";
httpURL = game.URL();
if (boost::istarts_with(httpURL, "https")) {
BOOST_LOG_TRIVIAL(info) << "HTTPS URL found. Converting to a HTTP URL.";
httpURL.erase(4, 1);
}
BOOST_LOG_TRIVIAL(trace) << "Checking for a Git repository.";
@@ -154,10 +145,10 @@ namespace boss {
BOOST_LOG_TRIVIAL(trace) << "Checking to see if remote URL matches URL in settings.";
//Check if the URLs match.
if (url != httpURL) {
if (url != game.URL()) {
BOOST_LOG_TRIVIAL(trace) << "URLs do not match, setting repository URL to URL in settings.";
//The URLs don't match. Change the remote URL to match the one BOSS has.
handle_error(git_remote_set_url(ptrs.remote, httpURL.c_str()), ptrs);
handle_error(git_remote_set_url(ptrs.remote, game.URL().c_str()), ptrs);
//Now save change.
handle_error(git_remote_save(ptrs.remote), ptrs);
@@ -170,7 +161,10 @@ namespace boss {
BOOST_LOG_TRIVIAL(trace) << "Setting the new repository's remote.";
//Now set the repository's remote.
handle_error(git_remote_create(&ptrs.remote, ptrs.repo, "origin", httpURL.c_str()), ptrs);
handle_error(git_remote_create(&ptrs.remote, ptrs.repo, "origin", game.URL().c_str()), ptrs);
//WARNING: This is generally a very bad idea, since it makes HTTPS a little bit pointless, but in this case because we're only reading data and not really concerned about its integrity, it's acceptable. A better solution would be to figure out why GitHub's certificate appears to be invalid to OpenSSL.
git_remote_check_cert(ptrs.remote, 0);
BOOST_LOG_TRIVIAL(trace) << "Getting the repository config.";