diff --git a/.gitignore b/.gitignore
index 560b024..a6578c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
*.lo
*.o
*.obj
+*.pyc
# Precompiled Headers
*.gch
@@ -43,6 +44,14 @@ bld/
ipch/
.vs/
+dist/
+.externalNativeBuild/
+.gradle/
+.classpath
+
+# cross-platform
+platform/cross-platform/out
+platform/cross-platform/vendor
# Windows
Thumbs.db
@@ -68,5 +77,8 @@ storage.json
result.epub
*.iml
+.settings/
+.project
+local.properties
-platform/android/lcp/libs/
\ No newline at end of file
+platform/android/lcp/libs/
diff --git a/README.md b/README.md
index cb11841..816287d 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,10 @@
readium-lcp-client
==================
-This repository is for the Readium Lightweight Content Protection (LCP) client side implementation work.
+This repository is for the Readium Licensed Content Protection (LCP) client side implementation work.
Created by Artem Brazhnikov, Mickaƫl Menu.
+Maintained by Cyrille Lebeaupin, Daniel Weck.
## Overview
diff --git a/platform/android/README.md b/platform/android/README.md
new file mode 100644
index 0000000..433d130
--- /dev/null
+++ b/platform/android/README.md
@@ -0,0 +1,26 @@
+# Android
+
+## Properties
+
+You can define some properties in local.properties file:
+
+* ndk.dir: Path to the Ndk
+* sdk.dir: Path to the Sdk
+* readium.ndk_skipX86: If true, skip X86 compilation
+* readium.ndk_skipARM: If true, skip ARM compilation
+* readium.ndk_clang: If true, compile with clang
+* readium.sdk_lib_dir: Path to readium sdk lib (*.so files) directory
+* readium.sdk_include_dir: Path to readium include directory
+* readium.extra_cmake: Path to an extra cmake that can modify lib compilation
+
+## Clean
+
+```
+./gradlew clean
+```
+
+## Build
+
+```
+./gradlew build
+```
diff --git a/platform/android/build.gradle b/platform/android/build.gradle
index 0685574..10e11e7 100644
--- a/platform/android/build.gradle
+++ b/platform/android/build.gradle
@@ -1,10 +1,41 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
- jcenter()
+ jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha5'
+ Properties properties = new Properties()
+ properties.load(rootProject.file('local.properties').newDataInputStream())
+
+ def ndkClang = properties.getProperty('readium.ndk_clang', "false")
+ ndkClang = (ndkClang == "true") ? true : false;
+ rootProject.ext.set('readium_ndk_clang', ndkClang)
+
+ def ndkSkipX86 = properties.getProperty('readium.ndk_skipX86', "false")
+ ndkSkipX86 = (ndkSkipX86 == "true") ? true : false;
+ rootProject.ext.set('readium_ndk_skipX86', ndkSkipX86)
+
+ def ndkSkipARM = properties.getProperty('readium.ndk_skipARM', "false")
+ ndkSkipARM = (ndkSkipARM == "true") ? true : false;
+ rootProject.ext.set('readium_ndk_skipARM', ndkSkipARM)
+
+ def extraCmake = properties.getProperty('readium.extra_cmake', null)
+ rootProject.ext.set('readium_extra_cmake', extraCmake)
+
+ def readiumSdkLibDir = properties.getProperty('readium.sdk_lib_dir', null)
+ rootProject.ext.set('readium_sdk_lib_dir', readiumSdkLibDir)
+
+ def readiumSdkIncludeDir = properties.getProperty('readium.sdk_include_dir', null)
+ rootProject.ext.set('readium_sdk_include_dir', readiumSdkIncludeDir)
+
+ if (readiumSdkLibDir != null && readiumSdkIncludeDir != null) {
+ rootProject.ext.set('readium_lcp_build_content_filter', true)
+ } else {
+ rootProject.ext.set('readium_lcp_build_content_filter', false)
+ }
+
+ //https://bintray.com/android/android-tools/com.android.tools.build.gradle/view
+ classpath "com.android.tools.build:gradle:2.3.3"
}
}
@@ -12,4 +43,4 @@ allprojects {
repositories {
jcenter()
}
-}
\ No newline at end of file
+}
diff --git a/platform/android/clean.sh b/platform/android/clean.sh
new file mode 100644
index 0000000..e155c5b
--- /dev/null
+++ b/platform/android/clean.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+rm -rf build
+
+rm -rf lib/build
+rm -rf lib/.externalNativeBuild
diff --git a/platform/android/gradle/wrapper/gradle-wrapper.properties b/platform/android/gradle/wrapper/gradle-wrapper.properties
index 60e4196..a1347d8 100644
--- a/platform/android/gradle/wrapper/gradle-wrapper.properties
+++ b/platform/android/gradle/wrapper/gradle-wrapper.properties
@@ -1,7 +1,9 @@
-#Wed Aug 17 23:29:31 BST 2016
+#Wed Apr 12 13:19:28 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#https://services.gradle.org/distributions
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
+# GRADLE EXPERIMENTAL requires 3.3
+# GRADLE STABLE works with latest (4.4)
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/platform/android/lcp/Application.mk b/platform/android/lcp/Application.mk
deleted file mode 100644
index 04fad3f..0000000
--- a/platform/android/lcp/Application.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-APP_PLATFORM := android-25
-
-ifneq ($(READIUM_SKIPARM),true)
-
-APP_ABI := armeabi-v7a
-
-ifneq ($(READIUM_SKIPX86),true)
-APP_ABI += x86
-endif
-
-else
-
-APP_ABI := x86
-
-endif
-
-ifeq ($(READIUM_CLANG),true)
-#NDK_TOOLCHAIN := clang
-NDK_TOOLCHAIN_VERSION := clang
-APP_STL := c++_shared
-else
-#NDK_TOOLCHAIN := gcc
-NDK_TOOLCHAIN_VERSION := 4.9
-APP_STL := gnustl_shared
-endif
\ No newline at end of file
diff --git a/platform/android/lcp/Experimental.mk b/platform/android/lcp/Experimental.mk
deleted file mode 100644
index 6595ff4..0000000
--- a/platform/android/lcp/Experimental.mk
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.
-#
-# This program 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.
-#
-# Licensed under Gnu Affero General Public License Version 3 (provided, notwithstanding this
-# notice, Readium Foundation reserves the right to license this material under a different
-# separate license, and if you have done so, the terms of that separate license control and
-# the following references to GPL do not apply).
-#
-# This program is free software: you can redistribute it and/or modify it under the terms
-# of the GNU Affero General Public License as published by the Free Software Foundation,
-# either version 3 of the License, or (at your option) any later version. You should have
-# received a copy of the GNU Affero General Public License along with this program. If not,
-# see .
-
-#LOCAL_PATH := $(call my-dir)
-#THIRD_PARTY_PATH := $(LOCAL_PATH)/../../../src/third-parties
-#
-###########################################################
-# cryptopp
-#include $(CLEAR_VARS)
-#LOCAL_MODULE := cryptopp
-#
-#ifeq ($(READIUM_CLANG),true)
-#LOCAL_CPPFLAGS := -std=c++11 -fpermissive
-#LOCAL_CXXFLAGS := -std=c++11 -fpermissive
-#LOCAL_CFLAGS := -std=c11
-#else
-#LOCAL_CPPFLAGS := -std=gnu++11 -fpermissive
-#LOCAL_CXXFLAGS := -std=gnu++11 -fpermissive
-#LOCAL_CFLAGS := -std=gnu11
-#endif
-#
-#LOCAL_CPP_FEATURES += exceptions rtti
-#
-#ifeq ($(TARGET_ARCH_ABI),x86)
-# LOCAL_CFLAGS += -mtune=atom -mssse3 -mfpmath=sse
-#endif
-#
-#LOCAL_C_INCLUDES := $(THIRD_PARTY_PATH)/cryptopp
-#LOCAL_SRC_FILES := $(wildcard $(THIRD_PARTY_PATH)/cryptopp/*.cpp)
-#
-#include $(BUILD_STATIC_LIBRARY)
-#
-###########################################################
-# ZipLib
-#include $(CLEAR_VARS)
-#LOCAL_MODULE := ziplib
-#
-#ifeq ($(READIUM_CLANG),true)
-#LOCAL_CPPFLAGS := -std=c++11 -fpermissive
-#LOCAL_CXXFLAGS := -std=c++11 -fpermissive
-#LOCAL_CFLAGS := -std=c11
-#else
-#LOCAL_CPPFLAGS := -std=gnu++11 -fpermissive
-#LOCAL_CXXFLAGS := -std=gnu++11 -fpermissive
-#LOCAL_CFLAGS := -std=gnu11
-#endif
-#
-#LOCAL_CPP_FEATURES += exceptions rtti
-#
-#ifeq ($(TARGET_ARCH_ABI),x86)
-# LOCAL_CFLAGS += -mtune=atom -mssse3 -mfpmath=sse
-#endif
-#
-#LOCAL_C_INCLUDES := $(THIRD_PARTY_PATH)/Source/ZipLib
-#LOCAL_SRC_FILES := \
-# $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/extlibs/zlib/*.c) \
-# $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/extlibs/lzma/unix/*.c) \
-# $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/extlibs/bzip2/*.c) \
-# $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/detail/*.cpp) \
-# $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/*.cpp)
-#
-#include $(BUILD_STATIC_LIBRARY)
-#
\ No newline at end of file
diff --git a/platform/android/lcp/Stable.mk b/platform/android/lcp/Stable.mk
deleted file mode 100644
index 4a13f05..0000000
--- a/platform/android/lcp/Stable.mk
+++ /dev/null
@@ -1,128 +0,0 @@
-# Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.
-#
-# This program 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.
-#
-# Licensed under Gnu Affero General Public License Version 3 (provided, notwithstanding this
-# notice, Readium Foundation reserves the right to license this material under a different
-# separate license, and if you have done so, the terms of that separate license control and
-# the following references to GPL do not apply).
-#
-# This program is free software: you can redistribute it and/or modify it under the terms
-# of the GNU Affero General Public License as published by the Free Software Foundation,
-# either version 3 of the License, or (at your option) any later version. You should have
-# received a copy of the GNU Affero General Public License along with this program. If not,
-# see .
-
-LOCAL_PATH := $(call my-dir)
-SRC_PATH := $(LOCAL_PATH)/../../../src
-LCP_CLIENT_LIB_PATH := $(SRC_PATH)/lcp-client-lib
-LCP_CONTENT_FILTER_PATH := $(SRC_PATH)/lcp-content-filter
-THIRD_PARTY_PATH := $(SRC_PATH)/third-parties
-
-###########################################################
-# cryptopp
-include $(CLEAR_VARS)
-LOCAL_MODULE := cryptopp
-
-ifeq ($(READIUM_CLANG),true)
-LOCAL_CPPFLAGS := -std=c++11 -fpermissive
-LOCAL_CXXFLAGS := -std=c++11 -fpermissive
-LOCAL_CFLAGS := -std=c11
-else
-LOCAL_CPPFLAGS := -std=gnu++11 -fpermissive
-LOCAL_CXXFLAGS := -std=gnu++11 -fpermissive
-LOCAL_CFLAGS := -std=gnu11
-endif
-
-LOCAL_CPP_FEATURES += exceptions rtti
-
-ifeq ($(TARGET_ARCH_ABI),x86)
- LOCAL_CFLAGS += -mtune=atom -mssse3 -mfpmath=sse
-endif
-
-LOCAL_C_INCLUDES := $(THIRD_PARTY_PATH)/cryptopp
-LOCAL_SRC_FILES := $(wildcard $(THIRD_PARTY_PATH)/cryptopp/*.cpp)
-
-include $(BUILD_STATIC_LIBRARY)
-
-###########################################################
-# ZipLib
-include $(CLEAR_VARS)
-LOCAL_MODULE := ziplib
-
-ifeq ($(READIUM_CLANG),true)
-LOCAL_CPPFLAGS := -std=c++11 -fpermissive -DZLIB_ONLY
-LOCAL_CXXFLAGS := -std=c++11 -fpermissive -DZLIB_ONLY
-LOCAL_CFLAGS := -std=c11 -DZLIB_ONLY
-else
-LOCAL_CPPFLAGS := -std=gnu++11 -fpermissive -DZLIB_ONLY
-LOCAL_CXXFLAGS := -std=gnu++11 -fpermissive -DZLIB_ONLY
-LOCAL_CFLAGS := -std=gnu11 -DZLIB_ONLY
-endif
-
-LOCAL_CPP_FEATURES += exceptions rtti
-
-ifeq ($(TARGET_ARCH_ABI),x86)
- LOCAL_CFLAGS += -mtune=atom -mssse3 -mfpmath=sse
-endif
-
-LOCAL_C_INCLUDES := $(THIRD_PARTY_PATH)/Source/ZipLib
-LOCAL_SRC_FILES := \
- $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/extlibs/zlib/*.c) \
- $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/extlibs/lzma/unix/*.c) \
- $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/extlibs/bzip2/*.c) \
- $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/detail/*.cpp) \
- $(wildcard $(THIRD_PARTY_PATH)/ziplib/Source/ZipLib/*.cpp)
-
-include $(BUILD_STATIC_LIBRARY)
-
-###########################################################
-# Epub3
-include $(CLEAR_VARS)
-LOCAL_MODULE := epub3
-
-LOCAL_SRC_FILES := $(EPUB3_PATH)/libs/$(TARGET_ARCH_ABI)/libepub3.so
-
-include $(PREBUILT_SHARED_LIBRARY)
-
-###########################################################
-# Lcp
-include $(CLEAR_VARS)
-LOCAL_MODULE := lcp
-
-ifeq ($(READIUM_CLANG),true)
-LOCAL_CPPFLAGS := -std=c++11 -fpermissive
-LOCAL_CXXFLAGS := -std=c++11 -fpermissive -DFEATURES_READIUM
-LOCAL_CFLAGS := -std=c11
-else
-LOCAL_CPPFLAGS := -std=gnu++11 -fpermissive
-LOCAL_CXXFLAGS := -std=gnu++11 -fpermissive -DFEATURES_READIUM
-LOCAL_CFLAGS := -std=gnu11
-endif
-
-LOCAL_CPP_FEATURES += exceptions rtti
-
-ifeq ($(TARGET_ARCH_ABI),x86)
- LOCAL_CFLAGS += -mtune=atom -mssse3 -mfpmath=sse
-endif
-
-LOCAL_STATIC_LIBRARIES := cryptopp ziplib
-LOCAL_SHARED_LIBRARIES := epub3
-LOCAL_LDLIBS := -lz -landroid -llog
-
-LOCAL_C_INCLUDES += \
- $(EPUB3_PATH)/include \
- $(LCP_CLIENT_LIB_PATH) \
- $(LCP_CLIENT_LIB_PATH)/public \
- $(LCP_CONTENT_FILTER_PATH) \
- $(LCP_CONTENT_FILTER_PATH)/public \
- $(THIRD_PARTY_PATH)
-
-LOCAL_SRC_FILES := \
- $(wildcard $(THIRD_PARTY_PATH)/time64/*.c) \
- $(wildcard $(LCP_CLIENT_LIB_PATH)/*.cpp) \
- $(wildcard $(LCP_CONTENT_FILTER_PATH)/*.cpp) \
- $(wildcard $(LOCAL_PATH)/src/main/jni/*.cpp)
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/platform/android/lcp/build.gradle b/platform/android/lcp/build.gradle
deleted file mode 100644
index 7faa8a2..0000000
--- a/platform/android/lcp/build.gradle
+++ /dev/null
@@ -1,53 +0,0 @@
-import org.apache.tools.ant.taskdefs.condition.Os
-
-def ndk_skipX86 = (rootProject.hasProperty("readium_ndk_skipX86") && rootProject.readium_ndk_skipX86)
-def ndk_skipARM = (rootProject.hasProperty("readium_ndk_skipARM") && rootProject.readium_ndk_skipARM)
-def ndk_clang = (rootProject.hasProperty("readium_ndk_clang") && rootProject.readium_ndk_clang)
-def ndk_experimental = (rootProject.hasProperty("readium_ndk_experimental") && rootProject.readium_ndk_experimental)
-
-if (ndk_experimental) {
- println "${project.name}: Using Gradle EXPERIMENTAL to build LCP lib"
- apply from: 'build_experimental.gradle'
-} else {
- println "${project.name}: Using Gradle STABLE to build LCP lib"
-}
-
-task buildMk(type: Exec) {
- // Retrieve ndk dir
- Properties properties = new Properties()
- properties.load(project.rootProject.file('local.properties').newDataInputStream())
- def ndkDir = properties.getProperty('ndk.dir', null)
-
- // Call ndk build
- def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
- def projectPath = file('.').absolutePath
- def buildScript = (ndk_experimental) ? "Experimental.mk" : "Stable.mk"
-
- environment 'EPUB3_PATH', project(':epub3').projectDir
-
- if (ndk_skipX86) environment 'READIUM_SKIPX86', 'true'
- if (ndk_skipARM) environment 'READIUM_SKIPARM', 'true'
- if (ndk_clang) environment 'READIUM_CLANG', 'true'
- if (ndk_experimental) environment 'READIUM_DEBUG', 'true'
-
- commandLine "$ndkDir/ndk-build${ndkBuildExt}",
- "-j", "4", //Runtime.runtime.availableProcessors()
- '-C', projectPath,
- 'NDK_APPLICATION_MK=Application.mk',
- "APP_BUILD_SCRIPT=${buildScript}",
- "NDK_PROJECT_PATH=${projectPath}",
- "NDK_DEBUG=1"
-}
-
-tasks.whenTaskAdded { task ->
- def taskName = task.name
-
- if (taskName.startsWith("compile")) {
-
- if (ndk_experimental) {
- println "${project.name} - ${taskName}: Using Gradle EXPERIMENTAL, no need to invoke external NDK / Makefile to build LCP lib"
- } else {
- task.dependsOn "buildMk"
- }
- }
-}
diff --git a/platform/android/lcp/build_experimental.gradle b/platform/android/lcp/build_experimental.gradle
deleted file mode 100644
index a726d27..0000000
--- a/platform/android/lcp/build_experimental.gradle
+++ /dev/null
@@ -1,124 +0,0 @@
-apply plugin: 'com.android.model.native'
-
-def ndk_skipX86 = (rootProject.hasProperty("readium_ndk_skipX86") && rootProject.readium_ndk_skipX86)
-def ndk_skipARM = (rootProject.hasProperty("readium_ndk_skipARM") && rootProject.readium_ndk_skipARM)
-def ndk_clang = (rootProject.hasProperty("readium_ndk_clang") && rootProject.readium_ndk_clang)
-def ndk_experimental = (rootProject.hasProperty("readium_ndk_experimental") && rootProject.readium_ndk_experimental)
-
-model {
- android {
- compileSdkVersion = 25
- sources {
- main {
- jni {
- source {
- srcDirs = [
- './src/main/jni',
- '../../../src/lcp-client-lib',
- '../../../src/lcp-content-filter',
- '../../../src/third-parties'
- ]
-
- excludes.add('curl/**/*.*')
- excludes.add('gtest/**/*.*')
- excludes.add('rapidjson/**/*.*')
- excludes.add('utf8-cpp/**/*.*')
- excludes.add('cryptopp/*test.cpp')
- excludes.add('cryptopp/TestScripts/*.*')
- excludes.add('cryptopp/bench*.cpp')
- excludes.add('cryptopp/validat*.cpp')
- excludes.add('cryptopp/adhoc.cpp')
- excludes.add('ziplib/Source/Sample/*.*')
- excludes.add('ziplib/Source/ZipLib/extlibs/lzma/*.c')
- excludes.add('ziplib/Source/ZipLib/extlibs/lzma/**/*.c')
- } //source
-
- exportedHeaders {
- srcDir "./src/main/jni"
- }
-
- dependencies {
- project ":epub3" linkage "shared"
- }
- }
- }
- } //sources
-
- ndk {
- moduleName = "lcp"
-
- //arguments "-j 4" //Runtime.runtime.availableProcessors()
-
- toolchain = ndk_clang ? "clang" : "gcc"
- toolchainVersion = ndk_clang ? "" : "4.9" //https://github.com/android-ndk/ndk/issues/229
-
- def clangWithGnuStl = false
-
- if (!ndk_clang || clangWithGnuStl)
- stl = "gnustl_shared"
- else
- stl = "c++_shared"
-
- def arrayFlags = [
- "-fexceptions",
- "-fpic",
- "-DFEATURES_READIUM",
- "-DZLIB_ONLY",
- ndk_clang ? "-D_LIBCPP_INLINE_VISIBILITY_EXCEPT_GCC49=_LIBCPP_INLINE_VISIBILITY" : "-DREADIUM_GCC",
- "-I" + project(':epub3').projectDir + "/include",
- "-I${file("../../../src/lcp-client-lib")}".toString(),
- "-I${file("../../../src/lcp-client-lib/public")}".toString(),
- "-I${file("../../../src/lcp-content-filter")}".toString(),
- "-I${file("../../../src/lcp-content-filter/public")}".toString(),
- "-I${file("../../../src/third-parties")}".toString()
- ]
-
- def arrayFlagsCPP = [
- "-fpermissive",
- "-frtti"
- ]
-
- cppFlags.addAll(arrayFlags)
- cppFlags.addAll(arrayFlagsCPP)
- cppFlags.add((!ndk_clang || clangWithGnuStl) ? "-std=gnu++11" : "-std=c++11")
-
- CFlags.addAll(arrayFlags)
- CFlags.add((!ndk_clang || clangWithGnuStl) ? "-std=gnu11" : "-std=c11")
-
- ldLibs.addAll(['z', 'android', 'log'])
- if (ndk_clang) ldLibs.addAll(['atomic'])
- } //ndk
-
- buildTypes {
- release {
-
- }
- debug {
- ndk.with {
- debuggable = true //"NDK_DEBUG=1"
- }
- }
- } //buildTypes
-
- productFlavors {
- if (!ndk_skipARM)
- create("arm") {
- ndk.with {
- abiFilters.add("armeabi-v7a")
- ldFlags.addAll([
- "-L${file("./obj/local/armeabi-v7a")}".toString()
- ])
- }
- }
- if (!ndk_skipX86)
- create("x86") {
- ndk.with {
- abiFilters.add("x86")
- ldFlags.addAll([
- "-L${file("./obj/local/x86")}".toString()
- ])
- }
- }
- } //productFlavors
- } //android
-} //model
\ No newline at end of file
diff --git a/platform/android/lib/CMakeLists.txt b/platform/android/lib/CMakeLists.txt
new file mode 100644
index 0000000..f85414c
--- /dev/null
+++ b/platform/android/lib/CMakeLists.txt
@@ -0,0 +1,74 @@
+# Global options
+cmake_minimum_required(VERSION 3.6.0)
+set(CMAKE_VERBOSE_MAKEFILE od)
+
+set(MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(PROJECT_DIR ${MODULE_DIR}/..)
+set(ROOT_DIR ${PROJECT_DIR}/../..)
+set(DISTRIBUTION_DIR ${PROJECT_DIR}/dist/${CMAKE_BUILD_TYPE}/${ANDROID_ABI})
+set("ndk-stl_DIR" "${CMAKE_CURRENT_SOURCE_DIR}")
+
+include(${PROJECT_DIR}/lib/clientlib.cmake)
+# Android Studio 2.x with CMake support does not pack stl shared libraries,
+# so app needs to pack the right shared lib into APK. This sample uses solution
+# from https://github.com/jomof/ndk-stl to find the right stl shared lib to use
+# and copy it to the right place for Android Studio to pack
+# Usage: download ndk-stl-config.cmake into app's directory hosting CMakeLists.txt
+# and just use it with the following line
+include(${PROJECT_DIR}/lib/ndk-stl-config.cmake)
+
+if("${FEATURES_READIUM}")
+ add_definitions("-DFEATURES_READIUM")
+endif()
+
+# Compiler options
+add_definitions("-DZLIB_ONLY")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -fpic -frtti -fexceptions -fpermissive -Wall")
+
+#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
+#set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS} -std=gnu11")
+#set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
+
+include_directories(
+ ${CLIENTLIB_DIR}
+ ${CLIENTLIB_DIR}/public
+ ${THIRDPARTY_DIR}
+ ${MODULE_DIR}/src/clientlib/cpp/)
+
+# Client lib JNI files
+file(GLOB CLIENTLIB_JNI_SOURCES ${MODULE_DIR}/src/clientlib/cpp/*.cpp)
+
+# LCP with content filter
+add_definitions("-DREADIUM_GCC")
+include(${PROJECT_DIR}/lib/contentfilter.cmake)
+file(GLOB CONTENTFILTER_JNI_SOURCES ${MODULE_DIR}/src/contentfilter/cpp/*.cpp)
+include_directories(
+ ${CONTENTFILTER_DIR}
+ ${CONTENTFILTER_DIR}/public
+ ${RSDK_INCLUDE_DIR}
+ ${MODULE_DIR}/src/contentfilter/cpp/)
+
+# Link libraries used by LCP shared library
+SET (
+ LCP_LINK_LIBRARIES
+ "clientlib"
+ "contentfilter"
+ "${RSDK_LIB_DIR}/${CMAKE_BUILD_TYPE}/${ANDROID_ABI}/libepub3.so"
+)
+
+# Extra cmake called before build
+if(EXISTS "${EXTRA_CMAKE}")
+ include(${EXTRA_CMAKE})
+endif()
+
+# Targets to build
+add_library("clientlib" STATIC ${CLIENTLIB_ALL_SOURCES})
+add_library("lcp-min" SHARED ${CLIENTLIB_JNI_SOURCES})
+add_library("contentfilter" STATIC ${CONTENTFILTER_SOURCES})
+add_library("lcp" SHARED
+ ${CLIENTLIB_JNI_SOURCES}
+ ${CONTENTFILTER_JNI_SOURCES})
+
+# Target links
+target_link_libraries("lcp" ${LCP_LINK_LIBRARIES})
+target_link_libraries("lcp-min" "clientlib")
diff --git a/platform/android/lib/build.gradle b/platform/android/lib/build.gradle
index b8d0fa9..02af41a 100644
--- a/platform/android/lib/build.gradle
+++ b/platform/android/lib/build.gradle
@@ -1,55 +1,244 @@
-apply plugin: 'com.android.model.library'
+apply plugin: 'com.android.library'
-model {
- android {
- compileSdkVersion = 23
- buildToolsVersion = "23.0.2"
+repositories {
+ mavenCentral()
+ jcenter()
+}
- defaultConfig.with {
- minSdkVersion.apiLevel = 19
- targetSdkVersion.apiLevel = 23
+dependencies {
+ compile 'com.android.support:support-v4:25.+'
+ compile 'commons-io:commons-io:2.4'
+ compile 'com.koushikdutta.ion:ion:2.+'
+}
+
+def ndk_skipX86 = (rootProject.hasProperty("readium_ndk_skipX86") && rootProject.readium_ndk_skipX86)
+def ndk_skipARM = (rootProject.hasProperty("readium_ndk_skipARM") && rootProject.readium_ndk_skipARM)
+def ndk_clang = (rootProject.hasProperty("readium_ndk_clang") && rootProject.readium_ndk_clang)
+def readiumSdkLibDir = null
+def readiumSdkIncludeDir = null
+def lcpBuildContentFilter = false
+def extraCmake = null
+
+if (rootProject.hasProperty("readium_extra_cmake")) {
+ extraCmake = rootProject.readium_extra_cmake
+}
+
+if (rootProject.hasProperty("readium_sdk_lib_dir")) {
+ readiumSdkLibDir = rootProject.readium_sdk_lib_dir
+}
+
+if (rootProject.hasProperty("readium_sdk_include_dir")) {
+ readiumSdkIncludeDir = rootProject.readium_sdk_include_dir
+}
+
+if (rootProject.hasProperty("readium_lcp_build_content_filter")) {
+ lcpBuildContentFilter = rootProject.readium_lcp_build_content_filter
+}
+println("extraCmake ${extraCmake}")
+def toolchain = ndk_clang ? "clang" : "gcc"
+def stl = ndk_clang ? "c++_shared" : "gnustl_shared"
+
+if (!lcpBuildContentFilter) {
+ try {
+ def epub3Dir = project(':epub3').projectDir
+ readiumSdkLibDir = "${epub3Dir}/libs"
+ readiumSdkIncludeDir = "${epub3Dir}/include"
+ lcpBuildContentFilter = true
+ println("Build with rsdk *")
+ } catch (UnknownProjectException e) {
+ // No epub3 project is defined
+ println("Build without rsdk")
+ }
+} else {
+ println("Build with rsdk")
+}
+println "${lcpBuildContentFilter}"
+println "${readiumSdkLibDir}"
+println "${readiumSdkIncludeDir}"
+android {
+ compileSdkVersion 26
+ buildToolsVersion "27.0.3"
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 26
+ versionCode 1
+ versionName "1.0"
+
+ externalNativeBuild {
+ cmake {
+ if (lcpBuildContentFilter) {
+ targets "clientlib", "contentfilter", "lcp"
+
+ arguments "-DFEATURES_READIUM=1",
+ "-DANDROID_PLATFORM=android-19",
+ "-DANDROID_TOOLCHAIN=${toolchain}",
+ "-DANDROID_STL=${stl}",
+ "-DRSDK_INCLUDE_DIR=${readiumSdkIncludeDir}",
+ "-DRSDK_LIB_DIR=${readiumSdkLibDir}",
+ "-DEXTRA_CMAKE=${extraCmake}"
+ } else {
+ targets "clientlib", "lcp-min"
+
+ arguments "-DANDROID_PLATFORM=android-19",
+ "-DANDROID_TOOLCHAIN=${toolchain}",
+ "-DANDROID_STL=${stl}",
+ "-DRSDK_INCLUDE_DIR=${readiumSdkIncludeDir}",
+ "-DRSDK_LIB_DIR=${readiumSdkLibDir}",
+ "-DEXTRA_CMAKE=${extraCmake}"
+ }
+ }
}
+ }
- sources {
+ sourceSets {
+ if (lcpBuildContentFilter) {
main {
- jniLibs {
- dependencies {
- project ":lcp"
- }
+ java {
+ srcDirs = [
+ './src/clientlib/java',
+ './src/contentfilter/java'
+ ]
}
}
+ } else {
main {
java {
- source {
- srcDirs = [
- './src/main/java'
- ]
- }
+ srcDirs = [
+ './src/clientlib/java'
+ ]
}
}
}
+ }
- buildTypes {
- debug {
- minifyEnabled = false
+ buildTypes {
+ release {
+ externalNativeBuild {
+ cmake {
+ arguments '-DCMAKE_BUILD_TYPE=RELEASE'
+ }
}
- release {
- minifyEnabled = false
- proguardFiles.add(file('proguard-rules.txt'))
+ }
+
+ debug {
+ externalNativeBuild {
+ cmake {
+ arguments '-DCMAKE_BUILD_TYPE=DEBUG'
+ }
}
}
+ }
+
+ externalNativeBuild {
+ cmake {
+ path "CMakeLists.txt"
+ }
+ }
- productFlavors {
- create ("arm") {
- ndk.with {
- abiFilters.add("armeabi-v7a")
+ productFlavors {
+ if (!ndk_skipARM) {
+ arm7 {
+ ndk {
+ abiFilter 'armeabi-v7a'
}
}
- create ("x86") {
- ndk.with {
- abiFilters.add("x86")
+ }
+ if (!ndk_skipX86) {
+ x86 {
+ ndk {
+ abiFilter 'x86'
}
}
}
+ /*arm8 {
+ ndk {
+ abiFilters 'arm64-v8a'
+ }
+ }
+ arm {
+ ndk {
+ abiFilter 'armeabi'
+ }
+ }
+ x86_64 {
+ ndk {
+ abiFilter 'x86_64'
+ }
+ }*/
+ }
+}
+
+build.doLast {
+ println("Copy libs to dist directory")
+ android.productFlavors.all { flavor ->
+ android.buildTypes.all { buildType ->
+ def abiFilter = flavor.ndk.abiFilters.first()
+ def dstDirPath = "${project.projectDir}/../dist/${buildType.name.toLowerCase()}/${abiFilter}"
+
+ // Copy static libs
+ def srcDirPath = "${project.projectDir}/.externalNativeBuild/cmake/${flavor.name}${buildType.name.capitalize()}/${abiFilter}"
+
+ copy {
+ from("${srcDirPath}") {
+ include("*.a")
+ }
+ into("${dstDirPath}")
+ }
+
+ // Copy shared libs
+ srcDirPath = "${project.projectDir}/build/intermediates/cmake/${flavor.name}/${buildType.name}/obj/${abiFilter}"
+
+ copy {
+ from("${srcDirPath}") {
+ include("*.so")
+ }
+ into("${dstDirPath}")
+ }
+
+ // Copy aar
+ srcDirPath = "${project.projectDir}/build/outputs/aar"
+ def srcFilename = "lib-${flavor.name}-${buildType.name}.aar"
+
+ copy {
+ from("${srcDirPath}") {
+ include(srcFilename)
+ }
+ into("${dstDirPath}")
+ rename(srcFilename, "liblcp.aar")
+ }
+ }
+ }
+}
+
+clean.doFirst {
+ println("Clean dist directory")
+ def dstDirPath = "${project.projectDir}/../dist/"
+ delete dstDirPath
+}
+
+task copyLibs {
+ doLast {
+ println ("Copy shared library to libs")
+ android.productFlavors.all { flavor ->
+ android.buildTypes.all { buildType ->
+ def abiFilter = flavor.ndk.abiFilters.first()
+ def srcDirPath = "${project.projectDir}/build/intermediates/cmake/${flavor.name}/${buildType.name}/obj/${abiFilter}"
+ def dstDirPath = "${project.projectDir}/libs/${abiFilter}"
+
+ copy {
+ from("${srcDirPath}") {
+ include("liblcp.so")
+ }
+ into("${dstDirPath}")
+ }
+ }
+ }
+ }
+}
+
+tasks.whenTaskAdded { task ->
+ if (task.name.startsWith('assemble')) {
+ task.dependsOn copyLibs
}
-}
\ No newline at end of file
+}
diff --git a/platform/android/lib/clientlib.cmake b/platform/android/lib/clientlib.cmake
new file mode 100644
index 0000000..6497178
--- /dev/null
+++ b/platform/android/lib/clientlib.cmake
@@ -0,0 +1,33 @@
+# Path definitions
+set(CLIENTLIB_DIR ${ROOT_DIR}/src/lcp-client-lib)
+set(THIRDPARTY_DIR ${ROOT_DIR}/src/third-parties)
+
+# CryptoPP
+file(GLOB_RECURSE CRYPTOPP_SOURCES ${THIRDPARTY_DIR}/cryptopp/*.cpp)
+list(FILTER CRYPTOPP_SOURCES EXCLUDE REGEX "TestScripts/.*\.cpp")
+list(FILTER CRYPTOPP_SOURCES EXCLUDE REGEX "bench.*\.cpp")
+list(FILTER CRYPTOPP_SOURCES EXCLUDE REGEX ".*test\.cpp")
+list(FILTER CRYPTOPP_SOURCES EXCLUDE REGEX "validat.*\.cpp")
+list(FILTER CRYPTOPP_SOURCES EXCLUDE REGEX "adhoc\.cpp")
+
+# ZipLib
+file(GLOB ZIPLIB_SOURCES
+ ${THIRDPARTY_DIR}/ziplib/Source/ZipLib/extlibs/zlib/*\.c
+ ${THIRDPARTY_DIR}/ziplib/Source/ZipLib/extlibs/lzma/unix/*\.c
+ ${THIRDPARTY_DIR}/ziplib/Source/ZipLib/extlibs/bzip2/*\.c
+ ${THIRDPARTY_DIR}/ziplib/Source/ZipLib/detail/*\.cpp
+ ${THIRDPARTY_DIR}/ziplib/Source/ZipLib//*\.cpp
+ )
+
+# Time64
+file(GLOB_RECURSE TIME64_SOURCES ${THIRDPARTY_DIR}/time64/*.c)
+
+# Client lib
+file(GLOB CLIENTLIB_SOURCES ${CLIENTLIB_DIR}/*.cpp)
+
+set(CLIENTLIB_ALL_SOURCES
+ ${CRYPTOPP_SOURCES}
+ ${ZIPLIB_SOURCES}
+ ${TIME64_SOURCES}
+ ${CLIENTLIB_SOURCES}
+)
diff --git a/platform/android/lib/contentfilter.cmake b/platform/android/lib/contentfilter.cmake
new file mode 100644
index 0000000..72c53cc
--- /dev/null
+++ b/platform/android/lib/contentfilter.cmake
@@ -0,0 +1,5 @@
+# Path definitions
+set(CONTENTFILTER_DIR ${ROOT_DIR}/src/lcp-content-filter)
+
+# Content filter
+file(GLOB CONTENTFILTER_SOURCES ${CONTENTFILTER_DIR}/*.cpp)
\ No newline at end of file
diff --git a/platform/android/lib/ndk-stl-config.cmake b/platform/android/lib/ndk-stl-config.cmake
new file mode 100644
index 0000000..3133faf
--- /dev/null
+++ b/platform/android/lib/ndk-stl-config.cmake
@@ -0,0 +1,39 @@
+# Copy shared STL files to Android Studio output directory so they can be
+# packaged in the APK.
+# Usage:
+#
+# find_package(ndk-stl REQUIRED)
+#
+# or
+#
+# find_package(ndk-stl REQUIRED PATHS ".")
+
+if(NOT ${ANDROID_STL} MATCHES "_shared")
+ return()
+endif()
+
+function(configure_shared_stl lib_path so_base)
+ message("Configuring STL ${so_base} for ${ANDROID_ABI}")
+ configure_file(
+ "${ANDROID_NDK}/sources/cxx-stl/${lib_path}/libs/${ANDROID_ABI}/lib${so_base}.so"
+ "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${so_base}.so"
+ COPYONLY)
+endfunction()
+
+if("${ANDROID_STL}" STREQUAL "libstdc++")
+ # The default minimal system C++ runtime library.
+elseif("${ANDROID_STL}" STREQUAL "gabi++_shared")
+ # The GAbi++ runtime (shared).
+ message(FATAL_ERROR "gabi++_shared was not configured by ndk-stl package")
+elseif("${ANDROID_STL}" STREQUAL "stlport_shared")
+ # The STLport runtime (shared).
+ configure_shared_stl("stlport" "stlport_shared")
+elseif("${ANDROID_STL}" STREQUAL "gnustl_shared")
+ # The GNU STL (shared).
+ configure_shared_stl("gnu-libstdc++/4.9" "gnustl_shared")
+elseif("${ANDROID_STL}" STREQUAL "c++_shared")
+ # The LLVM libc++ runtime (shared).
+ configure_shared_stl("llvm-libc++" "c++_shared")
+else()
+ message(FATAL_ERROR "STL configuration ANDROID_STL=${ANDROID_STL} is not supported")
+endif()
diff --git a/platform/android/lcp/src/main/jni/Acquisition.cpp b/platform/android/lib/src/clientlib/cpp/Acquisition.cpp
similarity index 100%
rename from platform/android/lcp/src/main/jni/Acquisition.cpp
rename to platform/android/lib/src/clientlib/cpp/Acquisition.cpp
diff --git a/platform/android/lcp/src/main/jni/Acquisition.h b/platform/android/lib/src/clientlib/cpp/Acquisition.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/Acquisition.h
rename to platform/android/lib/src/clientlib/cpp/Acquisition.h
diff --git a/platform/android/lcp/src/main/jni/AcquisitionCallback.cpp b/platform/android/lib/src/clientlib/cpp/AcquisitionCallback.cpp
similarity index 100%
rename from platform/android/lcp/src/main/jni/AcquisitionCallback.cpp
rename to platform/android/lib/src/clientlib/cpp/AcquisitionCallback.cpp
diff --git a/platform/android/lcp/src/main/jni/AcquisitionCallback.h b/platform/android/lib/src/clientlib/cpp/AcquisitionCallback.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/AcquisitionCallback.h
rename to platform/android/lib/src/clientlib/cpp/AcquisitionCallback.h
diff --git a/platform/android/lcp/src/main/jni/License.cpp b/platform/android/lib/src/clientlib/cpp/License.cpp
similarity index 94%
rename from platform/android/lcp/src/main/jni/License.cpp
rename to platform/android/lib/src/clientlib/cpp/License.cpp
index 02ba883..702cf74 100644
--- a/platform/android/lcp/src/main/jni/License.cpp
+++ b/platform/android/lib/src/clientlib/cpp/License.cpp
@@ -49,6 +49,14 @@ JNIEXPORT jstring JNICALL Java_org_readium_sdk_lcp_License_nativeGetOriginalCont
return res;
}
+JNIEXPORT jstring JNICALL Java_org_readium_sdk_lcp_License_nativeGetPassphraseHint(
+ JNIEnv *env, jobject obj, jlong licensePtr) {
+ lcp::ILicense * license = (lcp::ILicense *) licensePtr;
+ std::string hint = license->Crypto()->UserKeyHint();
+ jstring res = env->NewStringUTF(hint.c_str());
+ return res;
+}
+
JNIEXPORT jstring JNICALL Java_org_readium_sdk_lcp_License_nativeGetLinkPublication(
JNIEnv *env, jobject obj, jlong licensePtr) {
lcp::ILicense * license = (lcp::ILicense *) licensePtr;
diff --git a/platform/android/lcp/src/main/jni/License.h b/platform/android/lib/src/clientlib/cpp/License.h
similarity index 95%
rename from platform/android/lcp/src/main/jni/License.h
rename to platform/android/lib/src/clientlib/cpp/License.h
index 5faf05c..22a7ed9 100644
--- a/platform/android/lcp/src/main/jni/License.h
+++ b/platform/android/lib/src/clientlib/cpp/License.h
@@ -45,6 +45,9 @@ JNIEXPORT jboolean JNICALL Java_org_readium_sdk_lcp_License_nativeIsDecrypted(
JNIEXPORT jstring JNICALL Java_org_readium_sdk_lcp_License_nativeGetOriginalContent(
JNIEnv *env, jobject obj, jlong licensePtr);
+JNIEXPORT jstring JNICALL Java_org_readium_sdk_lcp_License_nativeGetPassphraseHint(
+ JNIEnv *env, jobject obj, jlong licensePtr);
+
JNIEXPORT jstring JNICALL Java_org_readium_sdk_lcp_License_nativeGetLinkPublication(
JNIEnv *env, jobject obj, jlong licensePtr);
diff --git a/platform/android/lcp/src/main/jni/NetProvider.cpp b/platform/android/lib/src/clientlib/cpp/NetProvider.cpp
similarity index 88%
rename from platform/android/lcp/src/main/jni/NetProvider.cpp
rename to platform/android/lib/src/clientlib/cpp/NetProvider.cpp
index 5247cf2..01887f6 100644
--- a/platform/android/lcp/src/main/jni/NetProvider.cpp
+++ b/platform/android/lib/src/clientlib/cpp/NetProvider.cpp
@@ -27,6 +27,8 @@
#if !DISABLE_NET_PROVIDER
#include "NetProvider.h"
+#include "BaseDownloadRequest.h"
+
#include "Util.h"
namespace lcp {
@@ -49,6 +51,12 @@ namespace lcp {
) {
JNIEnv * env = getJNIEnv();
jstring jUrl = env->NewStringUTF(request->Url().c_str());
+
+ if (!request->HasDestinationPath()) {
+ // TODO: write to STREAM instead!!
+ // request->DestinationStream()
+ }
+
jstring jDstPath = env->NewStringUTF(request->DestinationPath().c_str());
env->CallVoidMethod(this->jNetProvider, this->jDownloadMethodId, jUrl, jDstPath,
(jlong) request, (jlong) callback);
@@ -70,9 +78,18 @@ JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequ
}
JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequestEnded(
- JNIEnv *env, jobject obj, jlong callbackPtr, jlong requestPtr) {
+ JNIEnv *env, jobject obj, jlong callbackPtr, jlong requestPtr, jstring path) {
lcp::INetProviderCallback * callback = (lcp::INetProviderCallback *) callbackPtr;
lcp::IDownloadRequest * request = (lcp::IDownloadRequest *) requestPtr;
+
+ // This is a hack, see TODO above in StartDownloadRequest() (Java/JNI NetProvider only supports download-to-file, not memory stream!)
+ lcp::BaseDownloadRequest* request_ = dynamic_cast(request);
+ if (request_) {
+ const char *path_ = env->GetStringUTFChars(path, 0);
+ request_->SetSuggestedFileName(std::string(path_));
+ }
+
+
lcp::Status status(lcp::StatusCode::ErrorCommonSuccess);
callback->OnRequestEnded(request, status);
}
@@ -91,4 +108,4 @@ JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequ
callback->OnRequestProgressed(request, progress);
}
-#endif //!DISABLE_NET_PROVIDER
\ No newline at end of file
+#endif //!DISABLE_NET_PROVIDER
diff --git a/platform/android/lcp/src/main/jni/NetProvider.h b/platform/android/lib/src/clientlib/cpp/NetProvider.h
similarity index 99%
rename from platform/android/lcp/src/main/jni/NetProvider.h
rename to platform/android/lib/src/clientlib/cpp/NetProvider.h
index 50ad522..e9f6414 100644
--- a/platform/android/lcp/src/main/jni/NetProvider.h
+++ b/platform/android/lib/src/clientlib/cpp/NetProvider.h
@@ -61,7 +61,7 @@ namespace lcp {
JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequestStarted(
JNIEnv *env, jobject obj, jlong callbackPtr, jlong requestPtr);
JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequestEnded(
- JNIEnv *env, jobject obj, jlong callbackPtr, jlong requestPtr);
+ JNIEnv *env, jobject obj, jlong callbackPtr, jlong requestPtr, jstring path);
JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequestCanceled(
JNIEnv *env, jobject obj, jlong callbackPtr, jlong requestPtr);
JNIEXPORT void JNICALL Java_org_readium_sdk_lcp_NetProviderCallback_nativeOnRequestProgressed(
diff --git a/platform/android/lcp/src/main/jni/Service.cpp b/platform/android/lib/src/clientlib/cpp/Service.cpp
similarity index 98%
rename from platform/android/lcp/src/main/jni/Service.cpp
rename to platform/android/lib/src/clientlib/cpp/Service.cpp
index f6b625a..d49d78f 100644
--- a/platform/android/lcp/src/main/jni/Service.cpp
+++ b/platform/android/lib/src/clientlib/cpp/Service.cpp
@@ -30,10 +30,9 @@
#include
#include
-#include
-
-//#include
+#if FEATURES_READIUM
extern "C" jboolean javaEPub3_handleSdkError(JNIEnv *env, jstring message, jboolean isSevereEpubError);
+#endif
//extern "C" jstring toJstring(JNIEnv *env, const char* str, bool freeNative = false);
@@ -90,18 +89,22 @@ JNIEXPORT jobject JNICALL Java_org_readium_sdk_lcp_Service_nativeOpenLicense(
if (!lcp::Status::IsSuccess(status)) {
+#if FEATURES_READIUM
//jstring test = toJstring(env, "test", false);
jstring jmessage = env->NewStringUTF(lcp::Status::ToString(status).c_str());
jboolean b = javaEPub3_handleSdkError(env, jmessage, (jboolean)true);
env->DeleteLocalRef(jmessage);
+#endif
return nullptr;
}
} catch (lcp::StatusException &ex) {
+#if FEATURES_READIUM
jstring jmessage = env->NewStringUTF(ex.what());
jboolean b = javaEPub3_handleSdkError(env, jmessage, (jboolean)true);
env->DeleteLocalRef(jmessage);
+#endif
return nullptr;
}
diff --git a/platform/android/lcp/src/main/jni/Service.h b/platform/android/lib/src/clientlib/cpp/Service.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/Service.h
rename to platform/android/lib/src/clientlib/cpp/Service.h
diff --git a/platform/android/lcp/src/main/jni/StorageProvider.cpp b/platform/android/lib/src/clientlib/cpp/StorageProvider.cpp
similarity index 100%
rename from platform/android/lcp/src/main/jni/StorageProvider.cpp
rename to platform/android/lib/src/clientlib/cpp/StorageProvider.cpp
diff --git a/platform/android/lcp/src/main/jni/StorageProvider.h b/platform/android/lib/src/clientlib/cpp/StorageProvider.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/StorageProvider.h
rename to platform/android/lib/src/clientlib/cpp/StorageProvider.h
diff --git a/platform/android/lcp/src/main/jni/Util.cpp b/platform/android/lib/src/clientlib/cpp/Util.cpp
similarity index 100%
rename from platform/android/lcp/src/main/jni/Util.cpp
rename to platform/android/lib/src/clientlib/cpp/Util.cpp
diff --git a/platform/android/lcp/src/main/jni/Util.h b/platform/android/lib/src/clientlib/cpp/Util.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/Util.h
rename to platform/android/lib/src/clientlib/cpp/Util.h
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/Acquisition.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/Acquisition.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/Acquisition.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/Acquisition.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/DoneCallback.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/DoneCallback.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/DoneCallback.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/DoneCallback.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/Lcp.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/Lcp.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/Lcp.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/Lcp.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/License.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/License.java
similarity index 95%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/License.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/License.java
index 4588a32..8163fe0 100644
--- a/platform/android/lib/src/main/java/org/readium/sdk/lcp/License.java
+++ b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/License.java
@@ -43,6 +43,10 @@ public String getOriginalContent() {
return this.nativeGetOriginalContent(this.nativePtr);
}
+ public String getPassphraseHint() {
+ return this.nativeGetPassphraseHint(this.nativePtr);
+ }
+
public void decrypt(String passphrase) {
this.nativeDecrypt(this.nativePtr, this.servicePtr, passphrase);
}
@@ -86,6 +90,8 @@ private long getNativePtr() {
private native String nativeGetOriginalContent(long nativePtr);
+ private native String nativeGetPassphraseHint(long nativePtr);
+
private native String nativeGetLinkPublication(long nativePtr);
private native String nativeGetLinkStatus(long nativePtr);
diff --git a/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/NetProvider.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/NetProvider.java
new file mode 100644
index 0000000..94e53dd
--- /dev/null
+++ b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/NetProvider.java
@@ -0,0 +1,208 @@
+// Licensed to the Readium Foundation under one or more contributor license agreements.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or
+// other materials provided with the distribution.
+// 3. Neither the name of the organization nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+package org.readium.sdk.lcp;
+
+import android.app.Activity;
+import android.content.Context;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.util.Log;
+
+import com.koushikdutta.async.future.Future;
+import com.koushikdutta.async.future.FutureCallback;
+import com.koushikdutta.async.http.AsyncHttpRequest;
+import com.koushikdutta.async.http.Headers;
+import com.koushikdutta.ion.Ion;
+import com.koushikdutta.ion.Response;
+import com.koushikdutta.ion.loader.AsyncHttpRequestFactory;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class NetProvider {
+//#if !DISABLE_NET_PROVIDER
+
+ private Context context;
+ private Activity activity;
+ private Map>> requests;
+
+ /**
+ * Cancel request asynchronously
+ */
+ private class CancelRequest extends AsyncTask {
+ @Override
+ protected Void doInBackground(Long... requestPtrs) {
+ for (Long requestPtr: requestPtrs) {
+ Future> request = NetProvider.this.requests.get(requestPtr);
+ request.cancel();
+ }
+
+ return null;
+ }
+ }
+
+ public NetProvider(Context context, Activity activity) {
+ this.context = context;
+ this.activity = activity;
+
+ this.requests = new HashMap<>();
+ }
+
+ public void download(final String url, String dstPath, final long requestPtr, long callbackPtr) {
+
+ final NetProviderCallback callback = new NetProviderCallback(callbackPtr, requestPtr);
+
+ if (dstPath == null || dstPath.isEmpty()) {
+ File outputDir = this.context.getCacheDir();
+ File outputFile = null;
+ try {
+ outputFile = File.createTempFile("readium_TEMP_download", ".tmp", outputDir);
+ dstPath = outputFile.getAbsolutePath();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ final String destPath = dstPath;
+
+// Timer timer = new Timer();
+// timer.schedule(new TimerTask() {
+// @Override
+// public void run() {
+//
+// }
+// }, 500);
+
+// runOnUiThread(new Runnable() {
+// @Override
+// public void run() {
+//
+// new AsyncTask() {
+// @Override
+// protected Void doInBackground(Void... params) {
+
+// final AsyncHttpRequestFactory current = Ion.getDefault(context).configure().getAsyncHttpRequestFactory();
+// Ion.getDefault(context).configure().setAsyncHttpRequestFactory(new AsyncHttpRequestFactory() {
+// @Override
+// public AsyncHttpRequest createAsyncHttpRequest(Uri uri, String method, Headers headers) {
+// AsyncHttpRequest ret = current.createAsyncHttpRequest(uri, method, headers);
+// ret.setTimeout(1000);
+// return ret;
+// }
+// });
+
+// this.activity.runOnUiThread(new Runnable() {
+// @Override
+// public void run() {
+
+ Future> request = Ion.with(NetProvider.this.context)
+ .load("GET", url)
+ .setLogging("Readium Ion", Log.VERBOSE)
+
+ //.setTimeout(AsyncHttpRequest.DEFAULT_TIMEOUT) //30000
+ .setTimeout(6000)
+
+ // TODO: comment this in production! (this is only for testing a local HTTP server)
+ //.setHeader("X-Add-Delay", "2s")
+
+ .progress(callback) // not UI thread
+ //.progressHandler(callback) // UI thread
+
+ .asInputStream()
+ .withResponse()
+
+ // UI thread
+ .setCallback(new FutureCallback>() {
+ @Override
+ public void onCompleted(Exception e, Response response) {
+
+ InputStream inputStream = response != null ? response.getResult() : null;
+ int httpResponseCode = response != null ? response.getHeaders().code() : 0;
+ if (e != null || inputStream == null
+ || httpResponseCode < 200 || httpResponseCode >= 300) {
+
+ callback.onCompleted(e, null);
+ return;
+ }
+
+ File destFile = new File(destPath);
+ try {
+ FileOutputStream outputStream = new FileOutputStream(destFile);
+ //inputStream.transferTo(outputStream);
+
+ byte[] buf = new byte[4096];
+ int n;
+ int total = 0;
+ while ((n = inputStream.read(buf)) > 0) {
+ total += n;
+ outputStream.write(buf, 0, n);
+ }
+ outputStream.close();
+// inputStream.close();
+ callback.onCompleted(null, destFile);
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ callback.onCompleted(ex, null);
+ } finally {
+ try {
+ inputStream.close();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ // ignore
+ }
+ }
+ }
+ });
+
+ NetProvider.this.requests.put(requestPtr, request);
+
+//// ASYNC TASK
+// return null;
+
+// }
+// });
+ }
+
+ public void cancel(long requestPtr) {
+ // Cancel ion request
+ if (!this.requests.containsKey(requestPtr)) {
+ return;
+ }
+
+ new CancelRequest().execute(requestPtr);
+ }
+}
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/NetProviderCallback.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/NetProviderCallback.java
similarity index 98%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/NetProviderCallback.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/NetProviderCallback.java
index 6de0f6c..75ad832 100644
--- a/platform/android/lib/src/main/java/org/readium/sdk/lcp/NetProviderCallback.java
+++ b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/NetProviderCallback.java
@@ -77,7 +77,7 @@ public void onCompleted(Exception e, File result) {
// Request timeout
this.nativeOnRequestCanceled(this.nativePtr, this.requestPtr);
} else if (e == null && result != null) {
- this.nativeOnRequestEnded(this.nativePtr, this.requestPtr);
+ this.nativeOnRequestEnded(this.nativePtr, this.requestPtr, result.getAbsolutePath());
} else {
// Other errors
this.nativeOnRequestCanceled(this.nativePtr, this.requestPtr);
@@ -104,6 +104,6 @@ public void onProgress(long downloaded, long total) {
private native void nativeOnRequestStarted(long nativePtr, long requestPtr);
private native void nativeOnRequestProgressed(long nativePtr, long requestPtr,
float progress);
- private native void nativeOnRequestEnded(long nativePtr, long requestPtr);
+ private native void nativeOnRequestEnded(long nativePtr, long requestPtr, String path);
private native void nativeOnRequestCanceled(long nativePtr, long requestPtr);
}
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/Service.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/Service.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/Service.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/Service.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/StatusDocumentProcessing.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/StatusDocumentProcessing.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/StatusDocumentProcessing.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/StatusDocumentProcessing.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/StorageProvider.java b/platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/StorageProvider.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/StorageProvider.java
rename to platform/android/lib/src/clientlib/java/org/readium/sdk/lcp/StorageProvider.java
diff --git a/platform/android/lcp/src/main/jni/CredentialHandler.cpp b/platform/android/lib/src/contentfilter/cpp/CredentialHandler.cpp
similarity index 100%
rename from platform/android/lcp/src/main/jni/CredentialHandler.cpp
rename to platform/android/lib/src/contentfilter/cpp/CredentialHandler.cpp
diff --git a/platform/android/lcp/src/main/jni/CredentialHandler.h b/platform/android/lib/src/contentfilter/cpp/CredentialHandler.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/CredentialHandler.h
rename to platform/android/lib/src/contentfilter/cpp/CredentialHandler.h
diff --git a/platform/android/lcp/src/main/jni/ServiceFactory.cpp b/platform/android/lib/src/contentfilter/cpp/ServiceFactory.cpp
similarity index 99%
rename from platform/android/lcp/src/main/jni/ServiceFactory.cpp
rename to platform/android/lib/src/contentfilter/cpp/ServiceFactory.cpp
index 5999fb1..9f48b98 100644
--- a/platform/android/lcp/src/main/jni/ServiceFactory.cpp
+++ b/platform/android/lib/src/contentfilter/cpp/ServiceFactory.cpp
@@ -87,4 +87,4 @@ JNIEXPORT jobject JNICALL Java_org_readium_sdk_lcp_ServiceFactory_nativeBuild(
jclass cls = env->FindClass("org/readium/sdk/lcp/Service");
jmethodID methodId = env->GetMethodID(cls, "", "(J)V");
return env->NewObject(cls, methodId, (jlong) service);
-}
\ No newline at end of file
+}
diff --git a/platform/android/lcp/src/main/jni/ServiceFactory.h b/platform/android/lib/src/contentfilter/cpp/ServiceFactory.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/ServiceFactory.h
rename to platform/android/lib/src/contentfilter/cpp/ServiceFactory.h
diff --git a/platform/android/lcp/src/main/jni/StatusDocumentHandler.cpp b/platform/android/lib/src/contentfilter/cpp/StatusDocumentHandler.cpp
similarity index 100%
rename from platform/android/lcp/src/main/jni/StatusDocumentHandler.cpp
rename to platform/android/lib/src/contentfilter/cpp/StatusDocumentHandler.cpp
diff --git a/platform/android/lcp/src/main/jni/StatusDocumentHandler.h b/platform/android/lib/src/contentfilter/cpp/StatusDocumentHandler.h
similarity index 100%
rename from platform/android/lcp/src/main/jni/StatusDocumentHandler.h
rename to platform/android/lib/src/contentfilter/cpp/StatusDocumentHandler.h
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/CredentialHandler.java b/platform/android/lib/src/contentfilter/java/org/readium/sdk/lcp/CredentialHandler.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/CredentialHandler.java
rename to platform/android/lib/src/contentfilter/java/org/readium/sdk/lcp/CredentialHandler.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/ServiceFactory.java b/platform/android/lib/src/contentfilter/java/org/readium/sdk/lcp/ServiceFactory.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/ServiceFactory.java
rename to platform/android/lib/src/contentfilter/java/org/readium/sdk/lcp/ServiceFactory.java
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/StatusDocumentHandler.java b/platform/android/lib/src/contentfilter/java/org/readium/sdk/lcp/StatusDocumentHandler.java
similarity index 100%
rename from platform/android/lib/src/main/java/org/readium/sdk/lcp/StatusDocumentHandler.java
rename to platform/android/lib/src/contentfilter/java/org/readium/sdk/lcp/StatusDocumentHandler.java
diff --git a/platform/android/lib/src/main/AndroidManifest.xml b/platform/android/lib/src/main/AndroidManifest.xml
index a340258..156d6aa 100644
--- a/platform/android/lib/src/main/AndroidManifest.xml
+++ b/platform/android/lib/src/main/AndroidManifest.xml
@@ -20,6 +20,8 @@
android:versionCode="1"
android:versionName="0.1" >
-
+
diff --git a/platform/android/lib/src/main/java/org/readium/sdk/lcp/NetProvider.java b/platform/android/lib/src/main/java/org/readium/sdk/lcp/NetProvider.java
deleted file mode 100644
index 0e6c8c1..0000000
--- a/platform/android/lib/src/main/java/org/readium/sdk/lcp/NetProvider.java
+++ /dev/null
@@ -1,158 +0,0 @@
-// Licensed to the Readium Foundation under one or more contributor license agreements.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or
-// other materials provided with the distribution.
-// 3. Neither the name of the organization nor the names of its contributors may be
-// used to endorse or promote products derived from this software without specific
-// prior written permission
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-package org.readium.sdk.lcp;
-
-import android.content.Context;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.util.Log;
-
-import com.koushikdutta.async.future.Future;
-import com.koushikdutta.async.future.FutureCallback;
-import com.koushikdutta.async.http.AsyncHttpRequest;
-import com.koushikdutta.async.http.Headers;
-import com.koushikdutta.ion.Ion;
-import com.koushikdutta.ion.loader.AsyncHttpRequestFactory;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-public class NetProvider {
-//#if !DISABLE_NET_PROVIDER
-
- private Context context;
- private Map> requests;
-
- /**
- * Cancel request asynchronously
- */
- private class CancelRequest extends AsyncTask {
- @Override
- protected Void doInBackground(Long... requestPtrs) {
- for (Long requestPtr: requestPtrs) {
- Future request = NetProvider.this.requests.get(requestPtr);
- request.cancel();
- }
-
- return null;
- }
- }
-
- public NetProvider(Context context) {
- this.context = context;
- this.requests = new HashMap<>();
- }
-
- public void download(String url, String dstPath, long requestPtr, long callbackPtr) {
-
- final NetProviderCallback callback = new NetProviderCallback(callbackPtr, requestPtr);
- final String destPath = dstPath;
-
- if (dstPath == null || dstPath.isEmpty()) {
- File outputDir = this.context.getCacheDir();
- File outputFile = null;
- try {
- outputFile = File.createTempFile("readium_lcp_download", ".tmp", outputDir);
- dstPath = outputFile.getAbsolutePath();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-// final AsyncHttpRequestFactory current = Ion.getDefault(context).configure().getAsyncHttpRequestFactory();
-// Ion.getDefault(context).configure().setAsyncHttpRequestFactory(new AsyncHttpRequestFactory() {
-// @Override
-// public AsyncHttpRequest createAsyncHttpRequest(Uri uri, String method, Headers headers) {
-// AsyncHttpRequest ret = current.createAsyncHttpRequest(uri, method, headers);
-// ret.setTimeout(1000);
-// return ret;
-// }
-// });
-
-
- Future request = Ion.with(this.context)
- .load("GET", url)
- .setLogging("Ion", Log.VERBOSE)
- .progress(callback) // not UI thread
- //.progressHandler(callback) // UI thread
- //.setTimeout(AsyncHttpRequest.DEFAULT_TIMEOUT) //30000
- .setTimeout(6000)
- //.setHeader(name, value)
-
- // UI thread
- .asInputStream().setCallback(new FutureCallback() {
- @Override
- public void onCompleted(Exception e, InputStream inputStream) {
- if (e != null) {
- callback.onCompleted(e, null);
- return;
- }
- if (inputStream == null) {
- callback.onCompleted(null, null);
- return;
- }
- File destFile = new File(destPath);
- try {
- FileOutputStream outputStream = new FileOutputStream(destFile);
- //inputStream.transferTo(outputStream);
-
- byte[] buf = new byte[4096];
- int n;
- int total = 0;
- while((n = inputStream.read(buf))>0){
- total += n;
- outputStream.write(buf, 0, n);
- }
- outputStream.close();
- inputStream.close();
- callback.onCompleted(null, destFile);
- } catch (Exception ex) {
- ex.printStackTrace();
- callback.onCompleted(ex, null);
- }
- }
- })
-// .write(new File(dstPath))
-// .setCallback(callback)
- ;
-
- this.requests.put(requestPtr, request);
- }
-
- public void cancel(long requestPtr) {
- // Cancel ion request
- if (!this.requests.containsKey(requestPtr)) {
- return;
- }
-
- new CancelRequest().execute(requestPtr);
- }
-}
diff --git a/platform/android/settings.gradle b/platform/android/settings.gradle
new file mode 100644
index 0000000..8c2a2e0
--- /dev/null
+++ b/platform/android/settings.gradle
@@ -0,0 +1 @@
+include ':lib'
diff --git a/platform/apple/LCP Client (iOS).xcconfig b/platform/apple/LCP Client (iOS).xcconfig
index cd380af..64e6b2a 100644
--- a/platform/apple/LCP Client (iOS).xcconfig
+++ b/platform/apple/LCP Client (iOS).xcconfig
@@ -26,4 +26,4 @@
PRODUCT_NAME = LCP-client-iOS
-GCC_PREPROCESSOR_DEFINITIONS = $(inherited) ENABLE_NET_PROVIDER_ACQUISITION=1 CRYPTOPP_DISABLE_SSE2=1 CRYPTOPP_DISABLE_ASM=1
+GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DISABLE_CRL_=1 ENABLE_NET_PROVIDER_ACQUISITION=1 CRYPTOPP_DISABLE_SSE2=1 CRYPTOPP_DISABLE_ASM=1
diff --git a/platform/apple/LCP Client.xcodeproj/project.pbxproj b/platform/apple/LCP Client.xcodeproj/project.pbxproj
index 1219045..f6c011e 100644
--- a/platform/apple/LCP Client.xcodeproj/project.pbxproj
+++ b/platform/apple/LCP Client.xcodeproj/project.pbxproj
@@ -707,7 +707,7 @@
5ACE2E031BF21D7900AC0585 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 1010;
ORGANIZATIONNAME = Readium;
TargetAttributes = {
5ACE2E1A1BF21D8C00AC0585 = {
@@ -888,14 +888,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -934,14 +942,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
diff --git a/platform/apple/src/LCPError.h b/platform/apple/src/LCPError.h
index 7fd2aaf..f5ff5d4 100644
--- a/platform/apple/src/LCPError.h
+++ b/platform/apple/src/LCPError.h
@@ -34,7 +34,9 @@ extern NSString *const LCPErrorExtensionKey;
// @see LcpStatus.h for documentation
extern NSInteger const LCPErrorCommonNoNetProvider;
extern NSInteger const LCPErrorCommonNoStorageProvider;
+#if ENABLE_PROFILE_NAMES
extern NSInteger const LCPErrorCommonEncryptionProfileNotFound;
+#endif //ENABLE_PROFILE_NAMES
extern NSInteger const LCPErrorCommonAlgorithmMismatch;
extern NSInteger const LCPErrorOpeningLicenseNotValid;
extern NSInteger const LCPErrorOpeningLicenseNotStarted;
diff --git a/platform/apple/src/LCPLicense.h b/platform/apple/src/LCPLicense.h
index b5a4470..b6a7d11 100644
--- a/platform/apple/src/LCPLicense.h
+++ b/platform/apple/src/LCPLicense.h
@@ -32,15 +32,21 @@ namespace lcp {
}
#endif
-
@interface LCPLicense : NSObject
@property (readonly, nonatomic) NSString *identifier;
@property (readonly, nonatomic) NSString *linkPublication;
@property (readonly, nonatomic) BOOL isDecrypted;
+@property (readonly, nonatomic) NSString *username;
@property (readonly, nonatomic) NSString *userHint;
+- (NSString *)originalJSON;
+- (NSString *)canonicalJSON;
+
+- (NSDate *)rightsStart;
+- (NSDate *)rightsEnd;
+
#ifdef __cplusplus
@property (readonly, nonatomic) lcp::ILicense *nativeLicense;
- (instancetype)initWithLicense:(lcp::ILicense *)nativeLicense NS_DESIGNATED_INITIALIZER;
diff --git a/platform/apple/src/LCPLicense.mm b/platform/apple/src/LCPLicense.mm
index 8b218bb..a3bb0f4 100644
--- a/platform/apple/src/LCPLicense.mm
+++ b/platform/apple/src/LCPLicense.mm
@@ -25,11 +25,11 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "LCPLicense.h"
-
#import "ICrypto.h"
#import "ILicense.h"
-
#import "ILinks.h"
+#import "IRights.h"
+#import "IUser.h"
@interface LCPLicense ()
@property (nonatomic) lcp::ILicense *nativeLicense;
@@ -77,9 +77,89 @@ - (BOOL)isDecrypted
return _nativeLicense->Decrypted();
}
+- (NSString *)username
+{
+ if (_nativeLicense->User() != NULL) { // _nativeLicense->User()->Name() can be std::string.empty(), but not nil
+ return [NSString stringWithUTF8String:_nativeLicense->User()->Name().c_str()];
+ }
+ return @""; // no nil return to be consistent with the above potential missing Name() JSON value (empty std::string)
+}
+
- (NSString *)userHint
{
return [NSString stringWithUTF8String:_nativeLicense->Crypto()->UserKeyHint().c_str()];
}
+- (NSString *)originalJSON
+{
+ return [NSString stringWithUTF8String:_nativeLicense->OriginalContent().c_str()];
+}
+
+- (NSString *)canonicalJSON
+{
+ return [NSString stringWithUTF8String:_nativeLicense->CanonicalContent().c_str()];
+}
+
+- (NSDate *)rightsStart {
+ std::string start;
+ // _nativeLicense->Rights()->HasRightValue(lcp::StartRight)
+ if (_nativeLicense->Rights() != NULL && _nativeLicense->Rights()->GetRightValue(lcp::StartRight, start)) {
+ NSString *startDateString = [NSString stringWithUTF8String:start.c_str()];
+
+ NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
+ NSDate *startDate = [dateFormatter dateFromString:startDateString]; // may be nil
+ return startDate;
+ }
+ return nil;
+
+// NSData *data = [[self canonicalJSON] dataUsingEncoding:NSUTF8StringEncoding];
+//
+// NSError *error;
+// NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
+// if (!jsonDictionary) {
+// NSLog(@"Failed to parse license JSON: %@", error);
+// return nil;
+// }
+//
+// NSDictionary *rights = [jsonDictionary objectForKey:@"rights"];
+// if (rights == nil) { // no need to check for (id)[NSNull null] here (because source data is LCP license JSON)
+// return nil;
+// }
+// NSString *startDateString = [rights objectForKey:@"start"];
+// if (startDateString == nil || [startDateString length] == 0) { // early exit
+// return nil;
+// }
+}
+
+- (NSDate *)rightsEnd {
+ std::string end;
+ // _nativeLicense->Rights()->HasRightValue(lcp::StartRight)
+ if (_nativeLicense->Rights() != NULL && _nativeLicense->Rights()->GetRightValue(lcp::EndRight, end)) {
+ NSString *endDateString = [NSString stringWithUTF8String:end.c_str()];
+
+ NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
+ NSDate *endDate = [dateFormatter dateFromString:endDateString]; // may be nil
+ return endDate;
+ }
+ return nil;
+
+// NSData *data = [[self canonicalJSON] dataUsingEncoding:NSUTF8StringEncoding];
+//
+// NSError *error;
+// NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
+// if (!jsonDictionary) {
+// NSLog(@"Failed to parse license JSON: %@", error);
+// return nil;
+// }
+//
+// NSDictionary *rights = [jsonDictionary objectForKey:@"rights"];
+// if (rights == nil) { // no need to check for (id)[NSNull null] here (because source data is LCP license JSON)
+// return nil;
+// }
+// NSString *endDateString = [rights objectForKey:@"end"];
+// if (endDateString == nil || [endDateString length] == 0) { // early exit
+// return nil;
+// }
+}
+
@end
diff --git a/platform/apple/src/LCPStatusDocumentProcessing.h b/platform/apple/src/LCPStatusDocumentProcessing.h
index 669cc53..8b19b53 100644
--- a/platform/apple/src/LCPStatusDocumentProcessing.h
+++ b/platform/apple/src/LCPStatusDocumentProcessing.h
@@ -25,6 +25,25 @@
#import
+@interface StatusDocumentLink : NSObject {
+ NSString* rel;
+ NSString* href;
+ NSString* type;
+ BOOL templated;
+ NSString* title;
+ NSString* profile;
+}
+
+- (instancetype)init_:(NSString*) rel href:(NSString*) href type:(NSString*) type templated:(BOOL) templated title:(NSString*) title profile:(NSString*) profile;
+
+@property (nonatomic, readonly) NSString* rel;
+@property (nonatomic, readonly) NSString* href;
+@property (nonatomic, readonly) NSString* type;
+@property (nonatomic, readonly) BOOL templated;
+@property (nonatomic, readonly) NSString* title;
+@property (nonatomic, readonly) NSString* profile;
+
+@end
@protocol DeviceIdManager
@@ -61,11 +80,29 @@ typedef void (^DoneCallback)(bool);
-(bool)isInitialized;
-(bool)hasLicenseUpdatePending;
+
+- (NSString *)identifier;
+- (NSString *)message;
+
+-(NSString *)status;
-(bool)isActive;
--(bool)hasRenewLink;
--(bool)hasReturnLink;
+-(StatusDocumentLink *)licenseLink;
+
+-(bool)hasRegisterLink;
+-(StatusDocumentLink *)registerLink;
+
+-(bool)hasRenewLink;
+-(StatusDocumentLink *)renewLink;
-(void)doRenew:(DoneCallback)doneCallback_doRenew; //void(^)(bool)
+
+-(bool)hasReturnLink;
+-(StatusDocumentLink *)returnLink;
-(void)doReturn:(DoneCallback)doneCallback_doReturn; //void(^)(bool)
+-(NSDate *)potentialRightsEnd;
+
+- (NSDate *)statusUpdated;
+- (NSDate *)licenseUpdated;
+
@end
diff --git a/platform/apple/src/LCPStatusDocumentProcessing.mm b/platform/apple/src/LCPStatusDocumentProcessing.mm
index 3994ce0..4c26757 100644
--- a/platform/apple/src/LCPStatusDocumentProcessing.mm
+++ b/platform/apple/src/LCPStatusDocumentProcessing.mm
@@ -41,29 +41,6 @@
using namespace lcp;
-
-@interface StatusDocumentLink : NSObject {
-
- NSString* rel;
- NSString* href;
- NSString* type;
- BOOL templated;
- NSString* title;
- NSString* profile;
-}
-
-- (instancetype)init_:(NSString*) rel href:(NSString*) href type:(NSString*) type templated:(BOOL) templated title:(NSString*) title profile:(NSString*) profile;
-
-@property (nonatomic, readonly) NSString* rel;
-@property (nonatomic, readonly) NSString* href;
-@property (nonatomic, readonly) NSString* type;
-@property (nonatomic, readonly) BOOL templated;
-@property (nonatomic, readonly) NSString* title;
-@property (nonatomic, readonly) NSString* profile;
-
-@end
-
-
@interface StatusDocumentLink()
@end
@@ -111,7 +88,7 @@ @implementation LCPStatusDocumentProcessing {
id _deviceIDManager;
bool _wasCancelled;
- id _statusDocumentProcessingListener;
+ __weak id _statusDocumentProcessingListener;
NSString * _statusDocument_ID;
NSString * _statusDocument_STATUS; // ready, active, revoked, returned, cancelled, expired
@@ -354,7 +331,6 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
if ([task.taskDescription isEqualToString:TASK_DESCRIPTION_LCP_LSD_FETCH]) {
if (error) {
-
_data_TASK_DESCRIPTION_LCP_LSD_FETCH = nil;
NSLog(@"%@", [NSString stringWithFormat:@"HTTP error (TASK_DESCRIPTION_LCP_LSD_FETCH) [%@] => (%li) ... %@ [%li]", [(NSHTTPURLResponse *)task.originalRequest URL], code, error.domain, error.code]);
@@ -365,10 +341,19 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
} else if (code < 200 || code >= 300) {
+ if (_data_TASK_DESCRIPTION_LCP_LSD_FETCH != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_LSD_FETCH encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_LSD_FETCH = nil;
NSLog(@"%@", [NSString stringWithFormat:@"HTTP fail (TASK_DESCRIPTION_LCP_LSD_FETCH) [%@] => (%li)", [(NSHTTPURLResponse *)task.response URL], code]);
-
+
if (!_wasCancelled) {
[_statusDocumentProcessingListener onStatusDocumentProcessingComplete:self];
}
@@ -427,6 +412,15 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
} else if (code < 200 || code >= 300) {
+ if (_data_TASK_DESCRIPTION_LCP_LSD_REGISTER != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_LSD_REGISTER encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_LSD_REGISTER = nil;
NSLog(@"%@", [NSString stringWithFormat:@"HTTP fail (TASK_DESCRIPTION_LCP_LSD_REGISTER) [%@] => (%li)", [(NSHTTPURLResponse *)task.response URL], code]);
@@ -473,15 +467,24 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
_data_TASK_DESCRIPTION_LCP_FETCH = nil;
- NSLog(@"%@", [NSString stringWithFormat:@"HTTP error (TASK_DESCRIPTION_LCP_LSD_FETCH) [%@] => (%li) ... %@ [%li]", [(NSHTTPURLResponse *)task.originalRequest URL], code, error.domain, error.code]);
+ NSLog(@"%@", [NSString stringWithFormat:@"HTTP error (TASK_DESCRIPTION_LCP_FETCH) [%@] => (%li) ... %@ [%li]", [(NSHTTPURLResponse *)task.originalRequest URL], code, error.domain, error.code]);
_doneCallback_fetchAndInjectUpdatedLicense(false);
} else if (code < 200 || code >= 300) {
+ if (_data_TASK_DESCRIPTION_LCP_FETCH != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_FETCH encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_FETCH = nil;
- NSLog(@"%@", [NSString stringWithFormat:@"HTTP fail (TASK_DESCRIPTION_LCP_LSD_FETCH) [%@] => (%li)", [(NSHTTPURLResponse *)task.response URL], code]);
+ NSLog(@"%@", [NSString stringWithFormat:@"HTTP fail (TASK_DESCRIPTION_LCP_FETCH) [%@] => (%li)", [(NSHTTPURLResponse *)task.response URL], code]);
_doneCallback_fetchAndInjectUpdatedLicense(false);
@@ -533,6 +536,15 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
} else if (code < 200 || code >= 300) {
+ if (_data_TASK_DESCRIPTION_LCP_LSD_RENEW != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_LSD_RENEW encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_LSD_RENEW = nil;
NSLog(@"%@", [NSString stringWithFormat:@"HTTP fail (TASK_DESCRIPTION_LCP_LSD_RENEW) [%@] => (%li)", [(NSHTTPURLResponse *)task.response URL], code]);
@@ -540,8 +552,16 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
_doneCallback_doRenew(false);
} else {
-
try {
+ if (_data_TASK_DESCRIPTION_LCP_LSD_RENEW != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_LSD_RENEW encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_LSD_RENEW = nil;
// forces re-check of LSD, now with updated LCP timestamp
@@ -583,6 +603,15 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
} else if (code < 200 || code >= 300) {
+ if (_data_TASK_DESCRIPTION_LCP_LSD_RETURN != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_LSD_RETURN encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_LSD_RETURN = nil;
NSLog(@"%@", [NSString stringWithFormat:@"HTTP fail (TASK_DESCRIPTION_LCP_LSD_RETURN) [%@] => (%li)", [(NSHTTPURLResponse *)task.response URL], code]);
@@ -592,6 +621,15 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
} else {
try {
+ if (_data_TASK_DESCRIPTION_LCP_LSD_RETURN != nil) {
+ try {
+ NSString *msg = [[NSString alloc] initWithData:_data_TASK_DESCRIPTION_LCP_LSD_RETURN encoding:NSUTF8StringEncoding];
+ NSLog(@"%@", msg);
+ }
+ catch (NSException *e) {
+ NSLog(@"%@", [e reason]);
+ }
+ }
_data_TASK_DESCRIPTION_LCP_LSD_RETURN = nil;
// forces re-check of LSD, now with updated LCP timestamp
@@ -676,7 +714,6 @@ - (bool)parseStatusDocumentJson:(NSString*)json
}
NSDictionary *updatedJsonDict = [rootJsonDict valueForKey:@"updated"];
-
strTemp = [updatedJsonDict valueForKey:@"license"];
if (strTemp != nil) {
_statusDocument_UPDATED_LICENSE = strTemp;
@@ -706,7 +743,7 @@ - (bool)parseStatusDocumentJson:(NSString*)json
templated = YES;
}
} else if ([templated_ isKindOfClass:[NSNumber class]]) {
- if (((NSNumber*)templated_) > 0) {
+ if ([((NSNumber*)templated_) integerValue] > 0) {
templated = YES;
}
}
@@ -778,7 +815,7 @@ -(bool)isInitialized {
}
-(bool)hasLicenseUpdatePending {
- if (_statusDocument_UPDATED_LICENSE == nil) {
+ if (_statusDocument_UPDATED_LICENSE == nil || [_statusDocument_UPDATED_LICENSE length] == 0) {
return false;
}
@@ -961,7 +998,6 @@ -(void)fetchAndInjectUpdatedLicense:(DoneCallback)doneCallback_fetchAndInjectUpd
[task resume];
}
-
-(void)doRenew:(DoneCallback)doneCallback_doRenew //void(^)(bool)
{
if (_statusDocument_LINK_RENEW == nil) {
@@ -988,7 +1024,6 @@ -(void)doRenew:(DoneCallback)doneCallback_doRenew //void(^)(bool)
NSURL *url = [NSURL URLWithString:urlString];
-
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
NSString * locale = [[NSLocale preferredLanguages] objectAtIndex:0];
@@ -1073,18 +1108,67 @@ -(void)doReturn:(DoneCallback)doneCallback_doReturn //void(^)(bool)
[task resume];
}
+- (NSString *)identifier {
+ return _statusDocument_ID;
+}
+- (NSString *)message {
+ return _statusDocument_MESSAGE;
+}
+
+- (NSString *)status {
+ return _statusDocument_STATUS;
+}
-(bool)isActive {
return (_statusDocument_STATUS != nil && [_statusDocument_STATUS isEqualToString:@"active"]);
}
--(bool)hasRenewLink {
+- (NSDate *)statusUpdated {
+ if (_statusDocument_UPDATED_STATUS != nil && [_statusDocument_UPDATED_STATUS length] > 0) {
+ NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
+ return [dateFormatter dateFromString:_statusDocument_UPDATED_STATUS]; // can be nil
+ }
+ return nil;
+}
+- (NSDate *)licenseUpdated {
+ if (_statusDocument_UPDATED_LICENSE != nil && [_statusDocument_UPDATED_LICENSE length] > 0) {
+ NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
+ return [dateFormatter dateFromString:_statusDocument_UPDATED_LICENSE]; // can be nil
+ }
+ return nil;
+}
+- (NSDate *)potentialRightsEnd {
+ if (_statusDocument_POTENTIAL_RIGHTS_END != nil && [_statusDocument_POTENTIAL_RIGHTS_END length] > 0) {
+ NSISO8601DateFormatter *dateFormatter = [[NSISO8601DateFormatter alloc] init];
+ return [dateFormatter dateFromString:_statusDocument_POTENTIAL_RIGHTS_END]; // can be nil
+ }
+ return nil;
+}
+
+- (StatusDocumentLink *)licenseLink {
+ return _statusDocument_LINK_LICENSE;
+}
+
+- (bool)hasRegisterLink {
+ return (_statusDocument_LINK_REGISTER != nil);
+}
+- (StatusDocumentLink *)registerLink {
+ return _statusDocument_LINK_REGISTER;
+}
+
+- (bool)hasRenewLink {
return (_statusDocument_LINK_RENEW != nil);
}
+- (StatusDocumentLink *)renewLink {
+ return _statusDocument_LINK_RENEW;
+}
--(bool)hasReturnLink {
+- (bool)hasReturnLink {
return (_statusDocument_LINK_RETURN != nil);
}
+- (StatusDocumentLink *)returnLink {
+ return _statusDocument_LINK_RETURN;
+}
@end
@@ -1102,3 +1186,4 @@ -(bool)hasReturnLink {
// });
// });
+// NSLog(@"%s", __PRETTY_FUNCTION__);
diff --git a/platform/cross-platform/README.md b/platform/cross-platform/README.md
new file mode 100644
index 0000000..74de9d3
--- /dev/null
+++ b/platform/cross-platform/README.md
@@ -0,0 +1,22 @@
+# Cross platform compilation
+
+## Bootstrap
+
+```
+python bootstrap.py
+```
+
+## Compile
+
+```
+python build.py
+```
+
+This build generates static libraries in out/Default/obj directory:
+
+* liblcp_client.a
+* liblcp_content_filter.a
+* libbzip2.a
+* libzlib.a
+* libcryptopp.a
+* libtime64.a
diff --git a/platform/cross-platform/bootstrap.py b/platform/cross-platform/bootstrap.py
new file mode 100644
index 0000000..06b4ce8
--- /dev/null
+++ b/platform/cross-platform/bootstrap.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+import os
+import shutil
+import platform
+import utils
+import urllib
+import zipfile
+import tarfile
+import tempfile
+import subprocess
+
+# Other variables
+SYSTEM = platform.system().lower()
+
+if SYSTEM == "darwin":
+ SYSTEM = "mac"
+
+# Install gyp
+def install_gyp():
+ if os.path.exists(os.path.join("vendor", "gyp")):
+ return
+
+ print "Clone gyp"
+ utils.execute_command(["git", "clone", "https://chromium.googlesource.com/external/gyp.git", "vendor/gyp"])
+
+# Install ninja
+def install_ninja():
+ if not os.path.exists(os.path.join("vendor", "ninja")):
+ print "Clone ninja"
+ utils.execute_command(["git", "clone", "https://github.com/ninja-build/ninja.git", "vendor/ninja"])
+
+ # Configure and build ninja
+ if SYSTEM == "windows":
+ cmd_path = (os.path.join("vendor", "ninja", "ninja.exe"))
+ else:
+ cmd_path = (os.path.join("vendor", "ninja", "ninja"))
+
+ if not os.path.exists(cmd_path):
+ print "Build and install ninja"
+
+ # Initialize visual studio environment variables
+ cmd = ["python", "configure.py", "--bootstrap"]
+
+ if SYSTEM == "windows":
+ cmd = ["vcvarsall.bat", "&&"] + cmd
+
+ utils.execute_command(cmd, os.path.join("vendor", "ninja"))
+
+# Apply patches
+def apply_patches():
+ patch_file_path = os.path.abspath(os.path.join("patches", "%s.diff" % SYSTEM))
+
+ if not os.path.exists(patch_file_path):
+ return
+
+ print "Apply patches"
+ cmd = ["git", "apply"]
+
+ # Add options for windows to manage spaces
+ if SYSTEM == "windows":
+ cmd += ["--ignore-space-change", "--ignore-whitespace"]
+
+ cmd += [patch_file_path]
+
+ utils.execute_command(cmd, os.path.join("..", ".."))
+
+# Download and install vendors
+if not os.path.exists("vendor"):
+ os.mkdir("vendor")
+
+install_gyp()
+install_ninja()
+
+# Apply patches
+apply_patches()
+
diff --git a/platform/cross-platform/build.py b/platform/cross-platform/build.py
new file mode 100644
index 0000000..9316a49
--- /dev/null
+++ b/platform/cross-platform/build.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+import os
+import subprocess
+import platform
+import utils
+
+SYSTEM = platform.system().lower()
+
+if SYSTEM == "linux":
+ # Use clang on linux
+ # print "Use clang compiler"
+ # os.environ["CC"] = "clang"
+ # os.environ["CXX"] = "clang++"
+ # os.environ["GYP_DEFINES"] = "clang=1"
+ GYP_OS = "linux"
+elif SYSTEM == "windows":
+ # Use msvs version 2015
+ print "Use msvs version 2015"
+ os.environ["GYP_MSVS_VERSION"] = "2015"
+ GYP_OS = "win"
+elif SYSTEM == "darwin":
+ GYP_OS = "mac"
+
+# Directories variables
+PPAPI_PATH = os.path.abspath(os.getcwd())
+GYP_CMD = os.path.join(PPAPI_PATH, "vendor", "gyp", "gyp_main.py")
+NINJA_PATH = os.path.join(PPAPI_PATH, "vendor", "ninja")
+
+if SYSTEM == "windows":
+ NINJA_CMD = os.path.join(NINJA_PATH, "ninja.exe")
+else:
+ NINJA_CMD = os.path.join(NINJA_PATH, "ninja")
+
+# Create ninja build file
+print "Create ninja project"
+utils.execute_command(["python", GYP_CMD, "--depth=.", "-f", "ninja", "-DOS=%s" % GYP_OS, "lcp.gyp"])
+
+# Build ninja project
+print "Build ninja project"
+cmd = [NINJA_CMD, "-C", os.path.join("out", "Default"), "-f", "build.ninja"]
+
+if SYSTEM == "windows":
+ cmd = ["vcvarsall.bat", "&&"] + cmd
+
+utils.execute_command(cmd)
\ No newline at end of file
diff --git a/platform/cross-platform/filenames.gypi b/platform/cross-platform/filenames.gypi
new file mode 100644
index 0000000..0298447
--- /dev/null
+++ b/platform/cross-platform/filenames.gypi
@@ -0,0 +1,219 @@
+{
+ 'variables': {
+ 'root_dir': '../../src',
+ 'third_party_dir': '<(root_dir)/third-parties',
+ 'lcp_content_filter_dir': '<(root_dir)/lcp-content-filter',
+ 'lcp_client_lib_dir': '<(root_dir)/lcp-client-lib',
+ 'cryptopp_dir': '<(third_party_dir)/cryptopp',
+ 'zip_lib_dir': '<(third_party_dir)/ziplib/Source/ZipLib',
+ 'zlib_dir': '<(zip_lib_dir)/extlibs/zlib',
+ 'bzip2_dir': '<(zip_lib_dir)/extlibs/bzip2',
+ 'time64_dir': '<(third_party_dir)/time64',
+ 'zlib_sources': [
+ '<(zlib_dir)/compress.c',
+ '<(zlib_dir)/zutil.c',
+ '<(zlib_dir)/trees.c',
+ '<(zlib_dir)/inftrees.c',
+ '<(zlib_dir)/inffast.c',
+ '<(zlib_dir)/crc32.c',
+ '<(zlib_dir)/inflate.c',
+ '<(zlib_dir)/uncompr.c',
+ '<(zlib_dir)/adler32.c',
+ '<(zlib_dir)/infback.c',
+ '<(zlib_dir)/deflate.c'
+ ],
+ 'bzip2_sources': [
+ '<(bzip2_dir)/blocksort.c',
+ '<(bzip2_dir)/bzerror.c',
+ '<(bzip2_dir)/bzlib.c',
+ '<(bzip2_dir)/compress.c',
+ '<(bzip2_dir)/crctable.c',
+ '<(bzip2_dir)/decompress.c',
+ '<(bzip2_dir)/huffman.c',
+ '<(bzip2_dir)/randtable.c',
+ ],
+ 'zip_lib_sources': [
+ '<(zip_lib_dir)/detail/EndOfCentralDirectoryBlock.cpp',
+ '<(zip_lib_dir)/detail/ZipCentralDirectoryFileHeader.cpp',
+ '<(zip_lib_dir)/detail/ZipGenericExtraField.cpp',
+ '<(zip_lib_dir)/detail/ZipLocalFileHeader.cpp',
+ '<(zip_lib_dir)/ZipArchive.cpp',
+ '<(zip_lib_dir)/ZipArchiveEntry.cpp',
+ '<(zip_lib_dir)/ZipFile.cpp'
+ ],
+ 'time64_sources': [
+ '<(time64_dir)/time64.c'
+ ],
+ 'cryptopp_sources': [
+ '<(cryptopp_dir)/3way.cpp',
+ '<(cryptopp_dir)/adhoc.cpp',
+ '<(cryptopp_dir)/adler32.cpp',
+ '<(cryptopp_dir)/algebra.cpp',
+ '<(cryptopp_dir)/algparam.cpp',
+ '<(cryptopp_dir)/arc4.cpp',
+ '<(cryptopp_dir)/asn.cpp',
+ '<(cryptopp_dir)/authenc.cpp',
+ '<(cryptopp_dir)/base32.cpp',
+ '<(cryptopp_dir)/base64.cpp',
+ '<(cryptopp_dir)/basecode.cpp',
+ '<(cryptopp_dir)/bench2.cpp',
+ '<(cryptopp_dir)/bench.cpp',
+ '<(cryptopp_dir)/bfinit.cpp',
+ '<(cryptopp_dir)/blowfish.cpp',
+ '<(cryptopp_dir)/blumshub.cpp',
+ '<(cryptopp_dir)/camellia.cpp',
+ '<(cryptopp_dir)/cast.cpp',
+ '<(cryptopp_dir)/casts.cpp',
+ '<(cryptopp_dir)/cbcmac.cpp',
+ '<(cryptopp_dir)/ccm.cpp',
+ '<(cryptopp_dir)/channels.cpp',
+ '<(cryptopp_dir)/cmac.cpp',
+ '<(cryptopp_dir)/cpu.cpp',
+ '<(cryptopp_dir)/crc.cpp',
+ '<(cryptopp_dir)/cryptlib_bds.cpp',
+ '<(cryptopp_dir)/cryptlib.cpp',
+ '<(cryptopp_dir)/datatest.cpp',
+ '<(cryptopp_dir)/default.cpp',
+ '<(cryptopp_dir)/des.cpp',
+ '<(cryptopp_dir)/dessp.cpp',
+ '<(cryptopp_dir)/dh2.cpp',
+ '<(cryptopp_dir)/dh.cpp',
+ '<(cryptopp_dir)/dll.cpp',
+ '<(cryptopp_dir)/dlltest.cpp',
+ '<(cryptopp_dir)/dsa.cpp',
+ '<(cryptopp_dir)/eax.cpp',
+ '<(cryptopp_dir)/ec2n.cpp',
+ '<(cryptopp_dir)/eccrypto.cpp',
+ '<(cryptopp_dir)/ecp.cpp',
+ '<(cryptopp_dir)/elgamal.cpp',
+ '<(cryptopp_dir)/emsa2.cpp',
+ '<(cryptopp_dir)/eprecomp.cpp',
+ '<(cryptopp_dir)/esign.cpp',
+ '<(cryptopp_dir)/files.cpp',
+ '<(cryptopp_dir)/filters.cpp',
+ '<(cryptopp_dir)/fips140.cpp',
+ '<(cryptopp_dir)/fipsalgt.cpp',
+ '<(cryptopp_dir)/fipstest.cpp',
+ '<(cryptopp_dir)/gcm.cpp',
+ '<(cryptopp_dir)/gf2_32.cpp',
+ '<(cryptopp_dir)/gf256.cpp',
+ '<(cryptopp_dir)/gf2n.cpp',
+ '<(cryptopp_dir)/gfpcrypt.cpp',
+ '<(cryptopp_dir)/gost.cpp',
+ '<(cryptopp_dir)/gzip.cpp',
+ '<(cryptopp_dir)/hex.cpp',
+ '<(cryptopp_dir)/hmac.cpp',
+ '<(cryptopp_dir)/hrtimer.cpp',
+ '<(cryptopp_dir)/ida.cpp',
+ '<(cryptopp_dir)/idea.cpp',
+ '<(cryptopp_dir)/integer.cpp',
+ '<(cryptopp_dir)/iterhash.cpp',
+ '<(cryptopp_dir)/luc.cpp',
+ '<(cryptopp_dir)/mars.cpp',
+ '<(cryptopp_dir)/marss.cpp',
+ '<(cryptopp_dir)/md2.cpp',
+ '<(cryptopp_dir)/md4.cpp',
+ '<(cryptopp_dir)/md5.cpp',
+ '<(cryptopp_dir)/misc.cpp',
+ '<(cryptopp_dir)/modes.cpp',
+ '<(cryptopp_dir)/mqueue.cpp',
+ '<(cryptopp_dir)/mqv.cpp',
+ '<(cryptopp_dir)/nbtheory.cpp',
+ '<(cryptopp_dir)/network.cpp',
+ '<(cryptopp_dir)/oaep.cpp',
+ '<(cryptopp_dir)/osrng.cpp',
+ '<(cryptopp_dir)/panama.cpp',
+ '<(cryptopp_dir)/pch.cpp',
+ '<(cryptopp_dir)/pkcspad.cpp',
+ '<(cryptopp_dir)/polynomi.cpp',
+ '<(cryptopp_dir)/pssr.cpp',
+ '<(cryptopp_dir)/pubkey.cpp',
+ '<(cryptopp_dir)/queue.cpp',
+ '<(cryptopp_dir)/rabin.cpp',
+ '<(cryptopp_dir)/randpool.cpp',
+ '<(cryptopp_dir)/rc2.cpp',
+ '<(cryptopp_dir)/rc5.cpp',
+ '<(cryptopp_dir)/rc6.cpp',
+ '<(cryptopp_dir)/rdtables.cpp',
+ '<(cryptopp_dir)/regtest.cpp',
+ '<(cryptopp_dir)/rijndael.cpp',
+ '<(cryptopp_dir)/ripemd.cpp',
+ '<(cryptopp_dir)/rng.cpp',
+ '<(cryptopp_dir)/rsa.cpp',
+ '<(cryptopp_dir)/rw.cpp',
+ '<(cryptopp_dir)/safer.cpp',
+ '<(cryptopp_dir)/salsa.cpp',
+ '<(cryptopp_dir)/seal.cpp',
+ '<(cryptopp_dir)/seed.cpp',
+ '<(cryptopp_dir)/serpent.cpp',
+ '<(cryptopp_dir)/sha3.cpp',
+ '<(cryptopp_dir)/shacal2.cpp',
+ '<(cryptopp_dir)/sha.cpp',
+ '<(cryptopp_dir)/sharkbox.cpp',
+ '<(cryptopp_dir)/shark.cpp',
+ '<(cryptopp_dir)/simple.cpp',
+ '<(cryptopp_dir)/skipjack.cpp',
+ '<(cryptopp_dir)/socketft.cpp',
+ '<(cryptopp_dir)/sosemanuk.cpp',
+ '<(cryptopp_dir)/square.cpp',
+ '<(cryptopp_dir)/squaretb.cpp',
+ '<(cryptopp_dir)/strciphr.cpp',
+ '<(cryptopp_dir)/tea.cpp',
+ '<(cryptopp_dir)/test.cpp',
+ '<(cryptopp_dir)/tftables.cpp',
+ '<(cryptopp_dir)/tiger.cpp',
+ '<(cryptopp_dir)/tigertab.cpp',
+ '<(cryptopp_dir)/trdlocal.cpp',
+ '<(cryptopp_dir)/ttmac.cpp',
+ '<(cryptopp_dir)/twofish.cpp',
+ '<(cryptopp_dir)/validat1.cpp',
+ '<(cryptopp_dir)/validat2.cpp',
+ '<(cryptopp_dir)/validat3.cpp',
+ '<(cryptopp_dir)/vmac.cpp',
+ '<(cryptopp_dir)/wait.cpp',
+ '<(cryptopp_dir)/wake.cpp',
+ '<(cryptopp_dir)/whrlpool.cpp',
+ '<(cryptopp_dir)/winpipes.cpp',
+ '<(cryptopp_dir)/xtr.cpp',
+ '<(cryptopp_dir)/xtrcrypt.cpp',
+ '<(cryptopp_dir)/zdeflate.cpp',
+ '<(cryptopp_dir)/zinflate.cpp',
+ '<(cryptopp_dir)/zlib.cpp'
+ ],
+ 'lcp_client_lib_sources': [
+ '<(lcp_client_lib_dir)/Acquisition.cpp',
+ '<(lcp_client_lib_dir)/AesCbcSymmetricAlgorithm.cpp',
+ '<(lcp_client_lib_dir)/AlgorithmNames.cpp',
+ '<(lcp_client_lib_dir)/Certificate.cpp',
+ '<(lcp_client_lib_dir)/CertificateExtension.cpp',
+ '<(lcp_client_lib_dir)/CertificateRevocationList.cpp',
+ '<(lcp_client_lib_dir)/CrlDistributionPoints.cpp',
+ '<(lcp_client_lib_dir)/CrlUpdater.cpp',
+ '<(lcp_client_lib_dir)/CryptoLcpNode.cpp',
+ '<(lcp_client_lib_dir)/CryptoppCryptoProvider.cpp',
+ '<(lcp_client_lib_dir)/CryptoppUtils.cpp',
+ '<(lcp_client_lib_dir)/DateTime.cpp',
+ '<(lcp_client_lib_dir)/EncryptionProfileNames.cpp',
+ '<(lcp_client_lib_dir)/EncryptionProfilesManager.cpp',
+ '<(lcp_client_lib_dir)/JsonCanonicalizer.cpp',
+ '<(lcp_client_lib_dir)/JsonValueReader.cpp',
+ '<(lcp_client_lib_dir)/Lcp1dot0EncryptionProfile.cpp',
+ '<(lcp_client_lib_dir)/LcpService.cpp',
+ '<(lcp_client_lib_dir)/LcpServiceCreator.cpp',
+ '<(lcp_client_lib_dir)/LcpUtils.cpp',
+ '<(lcp_client_lib_dir)/LinksLcpNode.cpp',
+ '<(lcp_client_lib_dir)/RightsLcpNode.cpp',
+ '<(lcp_client_lib_dir)/RightsService.cpp',
+ '<(lcp_client_lib_dir)/RootLcpNode.cpp',
+ '<(lcp_client_lib_dir)/RsaSha256SignatureAlgorithm.cpp',
+ '<(lcp_client_lib_dir)/Sha256HashAlgorithm.cpp',
+ '<(lcp_client_lib_dir)/SymmetricAlgorithmEncryptedStream.cpp',
+ '<(lcp_client_lib_dir)/ThreadTimer.cpp',
+ '<(lcp_client_lib_dir)/UserLcpNode.cpp'
+ ],
+ 'lcp_content_filter_sources': [
+ '<(lcp_content_filter_dir)/LcpContentFilter.cpp',
+ '<(lcp_content_filter_dir)/LcpContentModule.cpp'
+ ]
+ }
+}
diff --git a/platform/cross-platform/lcp.gyp b/platform/cross-platform/lcp.gyp
new file mode 100644
index 0000000..13aba20
--- /dev/null
+++ b/platform/cross-platform/lcp.gyp
@@ -0,0 +1,215 @@
+{
+ 'includes': [
+ 'filenames.gypi'
+ ],
+ 'variables': {
+
+ },
+ 'target_defaults': {
+ 'include_dirs': [
+
+ ],
+ 'cflags': [
+ '-w',
+ '-fPIC',
+ '-fvisibility=hidden',
+ '-g', # Debug mode
+ ],
+ 'defines': [
+ 'BUILDING_EPUB3'
+ ]
+ },
+ 'targets': [
+ {
+ 'target_name': 'lcp_content_filter',
+ 'type': 'static_library',
+ 'cflags_cc': [
+ '-std=c++11'
+ ],
+ 'sources': [
+ '<@(lcp_content_filter_sources)'
+ ]
+ },
+ {
+ 'target_name': 'lcp_client_lib',
+ 'type': 'static_library',
+ 'dependencies': [
+ 'cryptopp',
+ 'zip_lib',
+ 'time64'
+ ],
+ 'include_dirs': [
+ '<(third_party_dir)'
+ ],
+ 'cflags_cc': [
+ '-std=c++11',
+ '-frtti',
+ '-fexceptions',
+ ],
+ 'sources': [
+ '<@(lcp_client_lib_sources)'
+ ]
+ },
+ {
+ 'target_name': 'cryptopp',
+ 'type': 'static_library',
+ 'cflags_cc': [
+ '-std=c++11',
+ '-fpermissive',
+ '-frtti',
+ '-fexceptions',
+ ],
+ 'sources': [
+ '<@(cryptopp_sources)'
+ ]
+ },
+ {
+ 'target_name': 'zip_lib',
+ 'type': 'static_library',
+ 'dependencies': [
+ 'zlib',
+ 'bzip2'
+ ],
+ 'cflags_cc': [
+ '-std=c++11',
+ '-fpermissive',
+ '-frtti',
+ '-fexceptions',
+ ],
+ 'sources': [
+ '<@(zip_lib_sources)'
+ ]
+ },
+ {
+ 'target_name': 'zlib',
+ 'type': 'static_library',
+ 'sources': [
+ '<@(zlib_sources)'
+ ]
+ },
+ {
+ 'target_name': 'bzip2',
+ 'type': 'static_library',
+ 'sources': [
+ '<@(bzip2_sources)'
+ ]
+ },
+ {
+ 'target_name': 'time64',
+ 'type': 'static_library',
+ 'sources': [
+ '<@(time64_sources)'
+ ]
+ }
+ ],
+ 'conditions': [
+ ['OS=="mac"', {
+ 'target_defaults': {
+ 'defines': [
+ 'LIBXML_THREAD_ENABLED',
+ 'CRYPTOPP_DISABLE_ASM',
+ 'ZLIB_ONLY'
+ ],
+ 'cflags_cc': [
+ #'-std=c++0x',
+ #'-stdlib=libc++',
+ #'-Wtautological-pointer-compare',
+ #'-Wc++11-extensions'
+ ],
+ 'xcode_settings': {
+ 'GCC_TREAT_WARNINGS_AS_ERRORS': 'NO',
+ #'MACOSX_DEPLOYMENT_TARGET': '10.8',
+ 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++0x',
+ 'CLANG_CXX_LIBRARY': 'libc++',
+ 'WARNING_CFLAGS': [
+ '-Wno-unknown-warning-option',
+ '-Wno-parentheses-equality',
+ '-Wno-unused-function',
+ '-Wno-sometimes-uninitialized',
+ '-Wno-pointer-sign',
+ '-Wno-sign-compare',
+ '-Wno-string-plus-int',
+ '-Wno-unused-variable',
+ '-Wno-deprecated-declarations',
+ '-Wno-return-type',
+ '-Wno-gnu-folding-constant',
+ '-Wno-shift-negative-value',
+ '-Wno-tautological-pointer-compare',
+ '-Wno-inconsistent-missing-override',
+ '-Wno-empty-body',
+ '-Wno-uninitialized',
+ '-Wno-potentially-evaluated-expression'
+ ]
+ },
+ 'ldflags': [
+
+ ],
+ 'link_settings': {
+ 'libraries': [
+
+ ]
+ }
+ }
+ }],
+ ['OS=="linux"', {
+ 'target_defaults': {
+ 'defines': [
+ #'LIBXML_THREAD_ENABLED',
+ #'_GLIBCXX_USE_CXX11_ABI=0' # to avoid std::locale issue
+ ],
+ 'cflags': [
+ '-m64',
+ '-march=x86-64',
+ ],
+ 'cflags_cc': [
+ ],
+ 'ldflags': [
+ '-m64',
+ ],
+ 'link_settings': {
+ 'libraries': [
+
+ ]
+ }
+ }
+ }],
+ ['OS=="win"', {
+ 'variables': {
+ },
+ 'target_defaults': {
+ 'defines': [
+ 'MSVS_VERSION_2015',
+ 'NDEBUG',
+ 'NOMINMAX',
+ 'WIN32'
+ ],
+ 'msvs_disabled_warnings': [
+ 4530,
+ 4577,
+ 4028,
+ 4090
+ ],
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'WarnAsError': 'false',
+ },
+ },
+ 'cflags': [
+ '/EHsc'
+ ],
+ 'cflags_cc': [
+ # '-std=c++11',
+ # '-fpermissive'
+ ],
+ 'include_dirs': [
+ ],
+ 'link_settings': {
+ 'library_dirs': [
+ ],
+ 'libraries': [
+ ]
+ }
+ }
+ }],
+ ]
+}
diff --git a/platform/cross-platform/utils.py b/platform/cross-platform/utils.py
new file mode 100644
index 0000000..b8e87da
--- /dev/null
+++ b/platform/cross-platform/utils.py
@@ -0,0 +1,12 @@
+import subprocess
+import os.path
+
+# Helper to execute command
+def execute_command(cmd, cwd=None):
+ cwd_abs_path = None
+
+ if cwd is not None:
+ cwd_abs_path = os.path.abspath(cwd)
+
+ p = subprocess.Popen(cmd, cwd=cwd_abs_path)
+ p.wait()
\ No newline at end of file
diff --git a/src/lcp-client-lib/Certificate.cpp b/src/lcp-client-lib/Certificate.cpp
index 8af23da..f9b2a07 100644
--- a/src/lcp-client-lib/Certificate.cpp
+++ b/src/lcp-client-lib/Certificate.cpp
@@ -58,7 +58,6 @@ DEFINE_OID(ASN1::joint_iso_ccitt() + 5, joint_iso_ccitt_ds);
DEFINE_OID(joint_iso_ccitt_ds() + 29, id_ce);
DEFINE_OID(id_ce() + 31, id_ce_CRLDistributionPoints);
-
namespace lcp
{
Certificate::Certificate(
@@ -74,7 +73,7 @@ namespace lcp
certData.Put(rawDecodedCert.data(), rawDecodedCert.size());
certData.MessageEnd();
- ByteQueue subjectPublicKey;
+ ByteQueue subjectPublicKey; //CryptoPP::BufferedTransformation
BERSequenceDecoder cert(certData);
{
@@ -98,13 +97,21 @@ namespace lcp
// subject
CryptoppUtils::Cert::SkipNextSequence(toBeSignedCert);
+
//subjectPublicKey (RSA or ECDSA)
//CryptoppUtils::Cert::ReadSubjectPublicKey(toBeSignedCert, m_publicKeyRSA);
- BERSequenceDecoder subjPublicInfoFrom(toBeSignedCert);
- DERSequenceEncoder subjPublicInfoOut(subjectPublicKey);
- subjPublicInfoFrom.TransferTo(subjPublicInfoOut, subjPublicInfoFrom.RemainingLength());
- subjPublicInfoOut.MessageEnd();
- subjPublicInfoFrom.MessageEnd();
+ // subjectPublicKeyInfo
+ BERSequenceDecoder spki(toBeSignedCert);
+ DERSequenceEncoder spkiEncoder(subjectPublicKey);
+ spki.CopyTo(spkiEncoder);
+ spkiEncoder.MessageEnd();
+ spki.SkipAll();
+ // ----- EQUIVALENT:
+// BERSequenceDecoder subjPublicInfoFrom(toBeSignedCert);
+// DERSequenceEncoder subjPublicInfoOut(subjectPublicKey);
+// subjPublicInfoFrom.TransferTo(subjPublicInfoOut, subjPublicInfoFrom.RemainingLength());
+// subjPublicInfoOut.MessageEnd();
+// subjPublicInfoFrom.MessageEnd();
while (!toBeSignedCert.EndReached())
@@ -157,60 +164,67 @@ namespace lcp
algo = AlgorithmNames::RsaMd5Id;
}
- if (algo == AlgorithmNames::EcdsaSha256Id) {
- m_publicKeyECDSA.BERDecode(subjectPublicKey);
- } else {
- m_publicKeyRSA.BERDecode(subjectPublicKey);
- }
+// m_publicKeyQueue = subjectPublicKey;
- //this->PublicKey()
- ByteQueue publicKeyQueue;
- if (algo == AlgorithmNames::EcdsaSha256Id) {
- m_publicKeyECDSA.DEREncode(publicKeyQueue);
- } else {
- m_publicKeyRSA.DEREncode(publicKeyQueue);
- }
- size_t size = static_cast(publicKeyQueue.MaxRetrievable());
+// if (algo == AlgorithmNames::EcdsaSha256Id) {
+// m_publicKeyECDSA.BERDecode(subjectPublicKey);
+// } else {
+// m_publicKeyRSA.BERDecode(subjectPublicKey);
+// }
+//
+// //this->PublicKey()
+// ByteQueue publicKeyQueue;
+// if (algo == AlgorithmNames::EcdsaSha256Id) {
+// m_publicKeyECDSA.DEREncode(publicKeyQueue);
+// } else {
+// m_publicKeyRSA.DEREncode(publicKeyQueue);
+// }
+
+ size_t size = static_cast(subjectPublicKey.MaxRetrievable());
KeyType outKey(size);
- publicKeyQueue.Get(&outKey.at(0), outKey.size());
+ subjectPublicKey.Get(&outKey.at(0), outKey.size());
+ m_publicKeyType = outKey;
- m_signatureAlgorithm.reset(m_encryptionProfile->CreateSignatureAlgorithm(outKey, algo));
+ m_signatureAlgorithm.reset(m_encryptionProfile->CreateSignatureAlgorithm(m_publicKeyType, algo));
}
KeyType Certificate::PublicKey() const
{
- ByteQueue publicKeyQueue;
- if (m_signatureAlgorithm->Name() == AlgorithmNames::EcdsaSha256Id) {
- m_publicKeyECDSA.DEREncode(publicKeyQueue);
- } else {
- m_publicKeyRSA.DEREncode(publicKeyQueue);
- }
-
- size_t size = static_cast(publicKeyQueue.MaxRetrievable());
- KeyType outKey(size);
- publicKeyQueue.Get(&outKey.at(0), outKey.size());
- return outKey;
- }
-
- bool Certificate::VerifyMessage(const std::string & message, const std::string & hashBase64)
- {
- return m_signatureAlgorithm->VerifySignature(message, hashBase64);
+ return m_publicKeyType;
+
+// ByteQueue publicKeyQueue;
+// if (m_signatureAlgorithm->Name() == AlgorithmNames::EcdsaSha256Id) {
+// m_publicKeyECDSA.DEREncode(publicKeyQueue);
+// } else {
+// m_publicKeyRSA.DEREncode(publicKeyQueue);
+// }
+//
+// ByteQueue publicKeyQueue = m_publicKeyQueue;
+// size_t size = static_cast(publicKeyQueue.MaxRetrievable());
+// KeyType outKey(size);
+// publicKeyQueue.Get(&outKey.at(0), outKey.size());
+// return outKey;
}
- bool Certificate::VerifyMessage(
- const unsigned char * message,
- size_t messageLength,
- const unsigned char * signature,
- size_t signatureLength
- )
- {
- return m_signatureAlgorithm->VerifySignature(
- message,
- messageLength,
- signature,
- signatureLength
- );
- }
+// bool Certificate::VerifyMessage(const std::string & message, const std::string & hashBase64)
+// {
+// return m_signatureAlgorithm->VerifySignature(message, hashBase64);
+// }
+//
+// bool Certificate::VerifyMessage(
+// const unsigned char * message,
+// size_t messageLength,
+// const unsigned char * signature,
+// size_t signatureLength
+// )
+// {
+// return m_signatureAlgorithm->VerifySignature(
+// message,
+// messageLength,
+// signature,
+// signatureLength
+// );
+// }
bool Certificate::VerifyCertificate(ICertificate * rootCertificate)
{
@@ -218,32 +232,32 @@ namespace lcp
KeyType rawPublicKey = rootCertificate->PublicKey();
publicKeyQueue.Put(&rawPublicKey.at(0), rawPublicKey.size());
publicKeyQueue.MessageEnd();
-
- CryptoPP::ECDSA::PublicKey publicKeyECDSA;
- CryptoPP::RSA::PublicKey publicKeyRSA;
-
- if (m_signatureAlgorithm->Name() == AlgorithmNames::EcdsaSha256Id) {
- publicKeyECDSA.BERDecode(publicKeyQueue);
- } else {
- publicKeyRSA.BERDecode(publicKeyQueue);
- }
+//
+// CryptoPP::ECDSA::PublicKey publicKeyECDSA;
+// CryptoPP::RSA::PublicKey publicKeyRSA;
+//
+// if (m_signatureAlgorithm->Name() == AlgorithmNames::EcdsaSha256Id) {
+// publicKeyECDSA.BERDecode(publicKeyQueue);
+// } else {
+// publicKeyRSA.BERDecode(publicKeyQueue);
+// }
std::unique_ptr rootVerifierPtr;
if (m_signatureAlgorithm->Name() == AlgorithmNames::EcdsaSha256Id) {
- rootVerifierPtr.reset(new ECDSA::Verifier(publicKeyECDSA));
+ rootVerifierPtr.reset(new ECDSA::Verifier(publicKeyQueue));
}
else if (m_signatureAlgorithmId == sha256withRSAEncryption())
{
- rootVerifierPtr.reset(new RSASS::Verifier(publicKeyRSA));
+ rootVerifierPtr.reset(new RSASS::Verifier(publicKeyQueue));
}
else if (m_signatureAlgorithmId == sha1withRSAEncryption())
{
- rootVerifierPtr.reset(new RSASS::Verifier(publicKeyRSA));
+ rootVerifierPtr.reset(new RSASS::Verifier(publicKeyQueue));
}
else if (m_signatureAlgorithmId == md5withRSAEncryption())
{
- rootVerifierPtr.reset(new RSASS::Verifier(publicKeyRSA));
+ rootVerifierPtr.reset(new RSASS::Verifier(publicKeyQueue));
}
else
{
diff --git a/src/lcp-client-lib/Certificate.h b/src/lcp-client-lib/Certificate.h
index 448621b..f656edc 100644
--- a/src/lcp-client-lib/Certificate.h
+++ b/src/lcp-client-lib/Certificate.h
@@ -63,13 +63,13 @@ namespace lcp
KeyType PublicKey() const;
bool VerifyCertificate(ICertificate * rootCertificate);
- bool VerifyMessage(const std::string & message, const std::string & hashBase64);
- bool VerifyMessage(
- const unsigned char * message,
- size_t messageLength,
- const unsigned char * signature,
- size_t signatureLength
- );
+// bool VerifyMessage(const std::string & message, const std::string & hashBase64);
+// bool VerifyMessage(
+// const unsigned char * message,
+// size_t messageLength,
+// const unsigned char * signature,
+// size_t signatureLength
+// );
ICrlDistributionPoints * DistributionPoints() const;
@@ -78,8 +78,11 @@ namespace lcp
std::string m_notBeforeDate;
std::string m_notAfterDate;
- CryptoPP::ECDSA::PublicKey m_publicKeyECDSA;
- CryptoPP::RSA::PublicKey m_publicKeyRSA;
+// CryptoPP::ECDSA::PublicKey m_publicKeyECDSA;
+//// CryptoPP::DL_PublicKey_EC m_publicKeyECDSA;
+// CryptoPP::RSA::PublicKey m_publicKeyRSA;
+// ByteQueue m_publicKeyQueue;
+ KeyType m_publicKeyType;
SecByteBlock m_toBeSignedData;
SecByteBlock m_rootSignature;
diff --git a/src/lcp-client-lib/CertificateRevocationList.cpp b/src/lcp-client-lib/CertificateRevocationList.cpp
index 482f415..a4499bd 100644
--- a/src/lcp-client-lib/CertificateRevocationList.cpp
+++ b/src/lcp-client-lib/CertificateRevocationList.cpp
@@ -39,63 +39,66 @@ using namespace CryptoPP;
namespace lcp
{
- CertificateRevocationList::CertificateRevocationList(const Buffer & crlRaw)
- {
- this->UpdateRevocationList(crlRaw);
- }
+// CertificateRevocationList::CertificateRevocationList(const Buffer & crlRaw)
+// {
+// this->UpdateRevocationList(crlRaw);
+// }
void CertificateRevocationList::UpdateRevocationList(const Buffer & crlRaw)
{
- std::unique_lock locker(m_sync);
+ try {
+ std::unique_lock locker(m_sync);
- ByteQueue crlData;
- crlData.Put(crlRaw.data(), crlRaw.size());
- crlData.MessageEnd();
+ ByteQueue crlData;
+ crlData.Put(crlRaw.data(), crlRaw.size());
+ crlData.MessageEnd();
- BERSequenceDecoder crl(crlData);
- {
- BERSequenceDecoder toBeSignedCertList(crl);
+ BERSequenceDecoder crl(crlData);
{
- word32 version = CryptoppUtils::Cert::ReadVersion(toBeSignedCertList, CertificateVersion::Certificatev2);
- if (version != CertificateVersion::Certificatev2)
+ BERSequenceDecoder toBeSignedCertList(crl);
{
- throw BERDecodeErr("Wrong version of the crl");
- }
+ word32 version = CryptoppUtils::Cert::ReadVersion(toBeSignedCertList,
+ CertificateVersion::Certificatev2);
+ if (version != CertificateVersion::Certificatev2) {
+ throw BERDecodeErr("Wrong version of the crl");
+ }
- // algorithmId
- CryptoppUtils::Cert::SkipNextSequence(toBeSignedCertList);
- // issuer
- CryptoppUtils::Cert::SkipNextSequence(toBeSignedCertList);
- // this update
- CryptoppUtils::Cert::BERDecodeTime(toBeSignedCertList, m_thisUpdate);
- // next update
- if (!toBeSignedCertList.EndReached())
- {
- byte nextId = toBeSignedCertList.PeekByte();
- if (nextId == UTC_TIME || nextId == GENERALIZED_TIME)
- {
- CryptoppUtils::Cert::BERDecodeTime(toBeSignedCertList, m_nextUpdate);
+ // algorithmId
+ CryptoppUtils::Cert::SkipNextSequence(toBeSignedCertList);
+ // issuer
+ CryptoppUtils::Cert::SkipNextSequence(toBeSignedCertList);
+ // this update
+ CryptoppUtils::Cert::BERDecodeTime(toBeSignedCertList, m_thisUpdate);
+ // next update
+ if (!toBeSignedCertList.EndReached()) {
+ byte nextId = toBeSignedCertList.PeekByte();
+ if (nextId == UTC_TIME || nextId == GENERALIZED_TIME) {
+ CryptoppUtils::Cert::BERDecodeTime(toBeSignedCertList, m_nextUpdate);
+ }
}
- }
- if (!toBeSignedCertList.EndReached())
- {
- BERSequenceDecoder revokedCertificates(toBeSignedCertList);
- {
- while (!revokedCertificates.EndReached())
+ if (!toBeSignedCertList.EndReached()) {
+ BERSequenceDecoder revokedCertificates(toBeSignedCertList);
{
- BERSequenceDecoder nextRevokedCertificate(revokedCertificates);
- {
- std::string serial = CryptoppUtils::Cert::ReadIntegerAsString(nextRevokedCertificate);
- m_revokedSerialNumbers.insert(serial);
+ while (!revokedCertificates.EndReached()) {
+ BERSequenceDecoder nextRevokedCertificate(revokedCertificates);
+ {
+ std::string serial = CryptoppUtils::Cert::ReadIntegerAsString(
+ nextRevokedCertificate);
+ m_revokedSerialNumbers.insert(serial);
+ }
+ nextRevokedCertificate.SkipAll();
}
- nextRevokedCertificate.SkipAll();
}
}
+ toBeSignedCertList.SkipAll();
}
- toBeSignedCertList.SkipAll();
}
}
+ catch (const std::exception & ex)
+ {
+ throw;
+ }
}
std::string CertificateRevocationList::ThisUpdateDate() const
@@ -133,6 +136,12 @@ namespace lcp
std::unique_lock locker(m_sync);
return m_revokedSerialNumbers;
}
+
+ const void CertificateRevocationList::InsertRevokedSerialNumber(std::string serial)
+ {
+ std::unique_lock locker(m_sync);
+ m_revokedSerialNumbers.insert(serial);
+ }
}
#endif //!DISABLE_CRL
diff --git a/src/lcp-client-lib/CertificateRevocationList.h b/src/lcp-client-lib/CertificateRevocationList.h
index fadcc62..3afbf7b 100644
--- a/src/lcp-client-lib/CertificateRevocationList.h
+++ b/src/lcp-client-lib/CertificateRevocationList.h
@@ -40,7 +40,7 @@ namespace lcp
{
public:
CertificateRevocationList() = default;
- explicit CertificateRevocationList(const Buffer & crlRaw);
+// explicit CertificateRevocationList(const Buffer & crlRaw);
// ICertificateRevocationList
virtual void UpdateRevocationList(const Buffer & crlRaw);
@@ -50,6 +50,8 @@ namespace lcp
virtual std::string NextUpdateDate() const;
virtual bool SerialNumberRevoked(const std::string & serialNumber) const;
virtual const StringsSet & RevokedSerialNumbers() const;
+ virtual const void InsertRevokedSerialNumber(std::string serial);
+
private:
mutable std::mutex m_sync;
diff --git a/src/lcp-client-lib/CrlUpdater.cpp b/src/lcp-client-lib/CrlUpdater.cpp
index 9d24649..c9347b8 100644
--- a/src/lcp-client-lib/CrlUpdater.cpp
+++ b/src/lcp-client-lib/CrlUpdater.cpp
@@ -33,8 +33,13 @@
#include "CrlUpdater.h"
#if !DISABLE_NET_PROVIDER
+#if !DISABLE_CRL_DOWNLOAD_IN_MEMORY
#include "SimpleMemoryWritableStream.h"
#include "DownloadInMemoryRequest.h"
+#else // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+#include "DownloadInFileRequest.h"
+#endif // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+
#endif //!DISABLE_NET_PROVIDER
#include "DateTime.h"
@@ -48,16 +53,26 @@ namespace lcp
#if !DISABLE_NET_PROVIDER
INetProvider * netProvider,
#endif //!DISABLE_NET_PROVIDER
+
+ IFileSystemProvider * fileSystemProvider,
+
ICertificateRevocationList * revocationList,
+#if !DISABLE_CRL_BACKGROUND_POLL
ThreadTimer * threadTimer,
+#endif //!DISABLE_CRL_BACKGROUND_POLL
const std::string & defaultCrlUrl
)
: m_requestRunning(false)
#if !DISABLE_NET_PROVIDER
, m_netProvider(netProvider)
#endif //!DISABLE_NET_PROVIDER
+
+ , m_fileSystemProvider(fileSystemProvider)
+
, m_revocationList(revocationList)
- , m_threadTimer(threadTimer)
+#if !DISABLE_CRL_BACKGROUND_POLL
+ , m_threadTimer(threadTimer)
+#endif //!DISABLE_CRL_BACKGROUND_POLL
, m_currentRequestStatus(Status(StatusCode::ErrorCommonSuccess))
{
if (!defaultCrlUrl.empty())
@@ -136,10 +151,17 @@ namespace lcp
void CrlUpdater::Download(const std::string & url)
{
#if !DISABLE_NET_PROVIDER
- m_crlStream.reset(new SimpleMemoryWritableStream());
+ m_requestRunning = true;
+
+#if !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+ m_crlStream.reset(new SimpleMemoryWritableStream()); // not actually used with NetProvider Java which operates on File only :(
m_downloadRequest.reset(new DownloadInMemoryRequest(url, m_crlStream.get()));
+#else // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+ m_crlFile.reset(m_fileSystemProvider->GetFile(PATH_TO_DOWNLOAD));
+ m_downloadRequest.reset(new DownloadInFileRequest(url, m_crlFile.get()));
+#endif // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+
m_netProvider->StartDownloadRequest(m_downloadRequest.get(), this);
- m_requestRunning = true;
#else
m_currentRequestStatus = Status(StatusCode::ErrorCommonSuccess);
m_requestRunning = false;
@@ -150,10 +172,12 @@ namespace lcp
#if !DISABLE_NET_PROVIDER
void CrlUpdater::OnRequestStarted(INetRequest * request)
{
+ bool breakpoint = true;
}
void CrlUpdater::OnRequestProgressed(INetRequest * request, float progress)
{
+ bool breakpoint = true;
}
void CrlUpdater::OnRequestCanceled(INetRequest * request)
@@ -170,7 +194,52 @@ namespace lcp
std::unique_lock locker(m_downloadSync);
if (Status::IsSuccess(result))
{
- m_revocationList->UpdateRevocationList(m_crlStream->Buffer());
+#if !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+ lcp::BaseDownloadRequest* request_ = dynamic_cast(request);
+ if (request_) {
+ std::string path = request_->SuggestedFileName();
+ if (path.length() && path.at(0) == '/') { // SUPER HACKY!! (because Android NetProvider only handles file download)
+ IFile* file = m_fileSystemProvider->GetFile(path, IFileSystemProvider::ReadOnly);
+
+ size_t bufferSize = 1024 * 1024;
+ std::vector buffer(bufferSize);
+
+ size_t read = 0;
+ size_t sizeToRead = bufferSize;
+ size_t fileSize = static_cast(file->Size());
+ while (read != fileSize)
+ {
+ sizeToRead = (fileSize - read > bufferSize) ? bufferSize : fileSize - read;
+ file->Read(buffer.data(), sizeToRead);
+ read += sizeToRead;
+ }
+
+ delete file;
+
+ m_revocationList->UpdateRevocationList(buffer); //std::vector
+ } else {
+ m_revocationList->UpdateRevocationList(m_crlStream->Buffer()); //std::vector
+ }
+ }
+
+#else // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+ // IFile == IReadableStream
+ size_t bufferSize = 1024 * 1024;
+ std::vector buffer(bufferSize);
+
+ size_t read = 0;
+ size_t sizeToRead = bufferSize;
+ size_t fileSize = static_cast(m_crlFile->Size());
+ while (read != fileSize)
+ {
+ sizeToRead = (fileSize - read > bufferSize) ? bufferSize : fileSize - read;
+ m_crlFile->Read(buffer.data(), sizeToRead);
+ read += sizeToRead;
+ }
+
+ m_revocationList->UpdateRevocationList(buffer); //std::vector
+#endif // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+
this->ResetNextUpdate();
}
m_currentRequestStatus = result;
@@ -180,12 +249,15 @@ namespace lcp
catch (const std::exception & ex)
{
m_currentRequestStatus = Status(StatusCode::ErrorNetworkingRequestFailed, "ErrorNetworkingRequestFailed: " + std::string(ex.what()));
+ m_requestRunning = false;
+ m_conditionDownload.notify_one();
}
}
#endif //!DISABLE_NET_PROVIDER
void CrlUpdater::ResetNextUpdate()
{
+#if !DISABLE_CRL_BACKGROUND_POLL
if (m_revocationList->HasNextUpdateDate())
{
DateTime nextUpdate(m_revocationList->NextUpdateDate());
@@ -205,8 +277,14 @@ namespace lcp
m_threadTimer->SetUsage(ThreadTimer::DurationUsage);
m_threadTimer->SetDuration(ThreadTimer::DurationType(TenMinutesPeriod));
}
+//
+//// TODO: remove this, for testing async update only!
+// m_threadTimer->SetUsage(ThreadTimer::DurationUsage);
+// m_threadTimer->SetDuration(ThreadTimer::DurationType(2000)); //TenMinutesPeriod == 1000 * 60 * 10
+
m_threadTimer->SetAutoReset(true);
+#endif //!DISABLE_CRL_BACKGROUND_POLL
}
}
-#endif //!DISABLE_CRL
\ No newline at end of file
+#endif //!DISABLE_CRL
diff --git a/src/lcp-client-lib/CrlUpdater.h b/src/lcp-client-lib/CrlUpdater.h
index 8b897b5..e403978 100644
--- a/src/lcp-client-lib/CrlUpdater.h
+++ b/src/lcp-client-lib/CrlUpdater.h
@@ -37,12 +37,17 @@
#include "ICertificate.h"
#if !DISABLE_NET_PROVIDER
-#include "SimpleMemoryWritableStream.h"
#include "public/INetProvider.h"
#endif //!DISABLE_NET_PROVIDER
#include "NonCopyable.h"
+#if !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+#include "SimpleMemoryWritableStream.h"
+#endif // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+
+#include "public/IFileSystemProvider.h"
+
namespace lcp
{
class ThreadTimer;
@@ -62,8 +67,13 @@ namespace lcp
#if !DISABLE_NET_PROVIDER
INetProvider * netProvider,
#endif //!DISABLE_NET_PROVIDER
+
+ IFileSystemProvider * fileSystemProvider,
+
ICertificateRevocationList * revocationList,
+#if !DISABLE_CRL_BACKGROUND_POLL
ThreadTimer * threadTimer,
+#endif //!DISABLE_CRL_BACKGROUND_POLL
const std::string & defaultCrlUrl
);
@@ -95,10 +105,20 @@ namespace lcp
INetProvider * m_netProvider;
#endif //!DISABLE_NET_PROVIDER
ICertificateRevocationList * m_revocationList;
+#if !DISABLE_CRL_BACKGROUND_POLL
ThreadTimer * m_threadTimer;
+#endif //!DISABLE_CRL_BACKGROUND_POLL
#if !DISABLE_NET_PROVIDER
+
+ IFileSystemProvider * m_fileSystemProvider;
+
+#if !DISABLE_CRL_DOWNLOAD_IN_MEMORY
std::unique_ptr m_crlStream;
+#else // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+ std::unique_ptr m_crlFile;
+#endif // !DISABLE_CRL_DOWNLOAD_IN_MEMORY
+
std::unique_ptr m_downloadRequest;
#endif //!DISABLE_NET_PROVIDER
diff --git a/src/lcp-client-lib/CryptoLcpNode.cpp b/src/lcp-client-lib/CryptoLcpNode.cpp
index 10dda22..839856d 100644
--- a/src/lcp-client-lib/CryptoLcpNode.cpp
+++ b/src/lcp-client-lib/CryptoLcpNode.cpp
@@ -96,11 +96,15 @@ namespace lcp
Status CryptoLcpNode::VerifyNode(ILicense * license, IClientProvider * clientProvider, ICryptoProvider * cryptoProvider)
{
+#if ENABLE_PROFILE_NAMES
m_encryptionProfile = m_encryptionProfilesManager->GetProfile(m_cryptoInfo.encryptionProfile);
if (m_encryptionProfile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ m_encryptionProfile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
if (m_encryptionProfile->ContentKeyAlgorithmCBC() != m_cryptoInfo.contentKeyAlgorithm && m_encryptionProfile->ContentKeyAlgorithmGCM() != m_cryptoInfo.contentKeyAlgorithm)
{
diff --git a/src/lcp-client-lib/CryptoppCryptoProvider.cpp b/src/lcp-client-lib/CryptoppCryptoProvider.cpp
index 360f1b8..5db7485 100644
--- a/src/lcp-client-lib/CryptoppCryptoProvider.cpp
+++ b/src/lcp-client-lib/CryptoppCryptoProvider.cpp
@@ -55,22 +55,41 @@ namespace lcp
, INetProvider * netProvider
#endif //!DISABLE_NET_PROVIDER
+ , IFileSystemProvider * fileSystemProvider
+
#if !DISABLE_CRL
, const std::string & defaultCrlUrl
#endif //!DISABLE_CRL
)
- : m_encryptionProfilesManager(encryptionProfilesManager)
+ :
+ m_encryptionProfilesManager(encryptionProfilesManager)
+
+ , m_fileSystemProvider(fileSystemProvider)
+
{
#if !DISABLE_CRL
m_revocationList.reset(new CertificateRevocationList());
+
+#if !DISABLE_CRL_BACKGROUND_POLL
m_threadTimer.reset(new ThreadTimer());
+#endif //!DISABLE_CRL_BACKGROUND_POLL
m_crlUpdater.reset(new CrlUpdater(
#if !DISABLE_NET_PROVIDER
netProvider,
#endif //!DISABLE_NET_PROVIDER
- m_revocationList.get(), m_threadTimer.get(), defaultCrlUrl));
+ m_fileSystemProvider,
+
+ m_revocationList.get(),
+
+#if !DISABLE_CRL_BACKGROUND_POLL
+ m_threadTimer.get(),
+#endif //!DISABLE_CRL_BACKGROUND_POLL
+
+ defaultCrlUrl));
+
+#if !DISABLE_CRL_BACKGROUND_POLL
m_threadTimer->SetHandler(std::bind(&CrlUpdater::Update, m_crlUpdater.get()));
m_threadTimer->SetAutoReset(false);
@@ -80,6 +99,8 @@ namespace lcp
m_threadTimer->SetDuration(ThreadTimer::DurationType(ThreadTimer::DurationType::zero()));
m_threadTimer->Start();
}
+#endif //!DISABLE_CRL_BACKGROUND_POLL
+
#endif //!DISABLE_CRL
}
@@ -89,7 +110,10 @@ namespace lcp
try
{
m_crlUpdater->Cancel();
+
+#if !DISABLE_CRL_BACKGROUND_POLL
m_threadTimer->Stop();
+#endif //!DISABLE_CRL_BACKGROUND_POLL
}
catch (...)
{
@@ -104,11 +128,15 @@ namespace lcp
{
try
{
+#if ENABLE_PROFILE_NAMES
IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
if (profile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
if (rootCertificateBase64.empty())
{
@@ -148,7 +176,9 @@ namespace lcp
}
#endif //!DISABLE_CRL
- if (!providerCertificate->VerifyMessage(license->CanonicalContent(), license->Crypto()->Signature()))
+ //providerCertificate->VerifyMessage
+ lcp::ISignatureAlgorithm* signatureAlgorithm = profile->CreateSignatureAlgorithm(providerCertificate->PublicKey(), license->Crypto()->SignatureAlgorithm());
+ if (!signatureAlgorithm->VerifySignature(license->CanonicalContent(), license->Crypto()->Signature()))
{
return Status(StatusCode::ErrorOpeningLicenseSignatureNotValid, "ErrorOpeningLicenseSignatureNotValid");
}
@@ -182,29 +212,56 @@ namespace lcp
}
}
+ Status CryptoppCryptoProvider::LegacyPassphraseUserKey(
+ const KeyType & userKey1,
+ KeyType & userKey2
+ )
+ {
+ try
+ {
+ userKey2.assign(userKey1.begin(), userKey1.end());
+
+ return Status(StatusCode::ErrorCommonSuccess);
+ }
+ catch (const std::exception & ex)
+ {
+ return Status(StatusCode::ErrorDecryptionUserPassphraseNotValid, "ErrorDecryptionUserPassphraseNotValid: " + std::string(ex.what()));
+ }
+ }
+
Status CryptoppCryptoProvider::DecryptUserKey(
const std::string & userPassphrase,
ILicense * license,
- KeyType & userKey
+ KeyType & userKey1,
+ KeyType & userKey2
)
{
try
{
+#if ENABLE_PROFILE_NAMES
IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
if (profile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
std::unique_ptr hashAlgorithm(profile->CreateUserKeyAlgorithm());
hashAlgorithm->UpdateHash(userPassphrase);
- userKey = hashAlgorithm->Hash();
+ userKey1 = hashAlgorithm->Hash();
+
+ Status resx = this->LegacyPassphraseUserKey(userKey1, userKey2);
+ if (!Status::IsSuccess(resx)) {
+ return resx;
+ }
//http://www.w3.org/2009/xmlenc11#aes256-gcm
//http://www.w3.org/2001/04/xmlenc#aes256-cbc
const std::string algorithm = license->Crypto()->ContentKeyAlgorithm();
- std::unique_ptr contentKeyAlgorithm(profile->CreateContentKeyAlgorithm(userKey, algorithm));
+ std::unique_ptr contentKeyAlgorithm(profile->CreateContentKeyAlgorithm(userKey2, algorithm));
std::string id = contentKeyAlgorithm->Decrypt(license->Crypto()->UserKeyCheck());
if (!EqualsUtf8(id, license->Id()))
{
@@ -226,11 +283,15 @@ namespace lcp
{
try
{
+#if ENABLE_PROFILE_NAMES
IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
if (profile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
//http://www.w3.org/2009/xmlenc11#aes256-gcm
//http://www.w3.org/2001/04/xmlenc#aes256-cbc
@@ -333,11 +394,15 @@ namespace lcp
{
try
{
+#if ENABLE_PROFILE_NAMES
IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
if (profile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
//http://www.w3.org/2009/xmlenc11#aes256-gcm
//http://www.w3.org/2001/04/xmlenc#aes256-cbc
@@ -365,11 +430,15 @@ namespace lcp
{
try
{
+#if ENABLE_PROFILE_NAMES
IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
if (profile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
std::unique_ptr algo(profile->CreatePublicationAlgorithm(keyProvider->ContentKey(), algorithm));
*decryptedDataLength = algo->Decrypt(
@@ -394,11 +463,15 @@ namespace lcp
{
try
{
+#if ENABLE_PROFILE_NAMES
IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
if (profile == nullptr)
{
return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
}
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
Status res(StatusCode::ErrorCommonSuccess);
std::unique_ptr algo(profile->CreatePublicationAlgorithm(keyProvider->ContentKey(), algorithm));
@@ -412,6 +485,43 @@ namespace lcp
}
#if !DISABLE_CRL
+
+ Status CryptoppCryptoProvider::CheckRevokation(ILicense* license) {
+
+#if ENABLE_PROFILE_NAMES
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile(license->Crypto()->EncryptionProfile());
+ if (profile == nullptr)
+ {
+ return Status(StatusCode::ErrorCommonEncryptionProfileNotFound, "ErrorCommonEncryptionProfileNotFound");
+ }
+#else
+ IEncryptionProfile * profile = m_encryptionProfilesManager->GetProfile();
+#endif //ENABLE_PROFILE_NAMES
+
+ std::unique_ptr providerCertificate;
+ try {
+ providerCertificate.reset(
+ new lcp::Certificate(license->Crypto()->SignatureCertificate(), profile));
+ }
+ catch (std::exception &ex) {
+ return Status(StatusCode::ErrorOpeningContentProviderCertificateNotValid,
+ "ErrorOpeningContentProviderCertificateNotValid: " +
+ std::string(ex.what()));
+ }
+
+ return this->CheckRevokation(providerCertificate.get());
+ }
+
+ Status CryptoppCryptoProvider::CheckRevokation(ICertificate * providerCertificate) {
+
+ if (m_revocationList->SerialNumberRevoked(providerCertificate->SerialNumber())) {
+ return Status(StatusCode::ErrorOpeningContentProviderCertificateRevoked,
+ "ErrorOpeningContentProviderCertificateRevoked");
+ }
+
+ return StatusCode::ErrorCommonSuccess;
+ }
+
Status CryptoppCryptoProvider::ProcessRevokation(ICertificate * rootCertificate, ICertificate * providerCertificate)
{
m_crlUpdater->UpdateCrlUrls(rootCertificate->DistributionPoints());
@@ -421,34 +531,53 @@ namespace lcp
std::unique_lock locker(m_processRevocationSync);
if (m_crlUpdater->ContainsAnyUrl() && !m_revocationList->HasThisUpdateDate())
{
+#if !DISABLE_CRL_BACKGROUND_POLL
if (m_threadTimer->IsRunning())
{
m_threadTimer->Stop();
}
+#endif //!DISABLE_CRL_BACKGROUND_POLL
- // Check once more, the CRL state could've been changed during the stop process
- if (!m_revocationList->HasThisUpdateDate())
- {
- // If CRL is absent, update it right before certificate verification
- m_crlUpdater->Update();
- }
+// // Check once more, the CRL state could've been changed during the stop process
+// if (!m_revocationList->HasThisUpdateDate())
+// {
+// // If CRL is absent, update it right before certificate verification
+// m_crlUpdater->Update();
+// }
+#if !DISABLE_CRL_BACKGROUND_POLL
// Start timer which will check CRL for updates periodically or by time point
m_threadTimer->SetAutoReset(true);
m_threadTimer->SetUsage(ThreadTimer::DurationUsage);
+
+ //std::function
+ m_threadTimer->SetHandler([&]{
+ m_crlUpdater->Update();
+ }); // std::bind(&CrlUpdater::Update, &m_crlUpdater);
+
m_threadTimer->SetDuration(ThreadTimer::DurationType(CrlUpdater::TenMinutesPeriod));
m_threadTimer->Start();
+#endif //!DISABLE_CRL_BACKGROUND_POLL
}
locker.unlock();
+#if !DISABLE_CRL_BACKGROUND_POLL
// If exception occurred in the timer thread, re-throw it
m_threadTimer->RethrowExceptionIfAny();
+#endif //!DISABLE_CRL_BACKGROUND_POLL
- if (m_revocationList->SerialNumberRevoked(providerCertificate->SerialNumber()))
+
+ Status resx = this->CheckRevokation(providerCertificate);
+ if (!Status::IsSuccess(resx))
{
- return Status(StatusCode::ErrorOpeningContentProviderCertificateRevoked, "ErrorOpeningContentProviderCertificateRevoked");
+ return resx;
}
+//
+// // TODO: only for testing fake mock revocation!!
+// // TODO: REMOVE !
+// m_revocationList->InsertRevokedSerialNumber(providerCertificate->SerialNumber());
+
return Status(StatusCode::ErrorCommonSuccess);
}
#endif //!DISABLE_CRL
-}
\ No newline at end of file
+}
diff --git a/src/lcp-client-lib/CryptoppCryptoProvider.h b/src/lcp-client-lib/CryptoppCryptoProvider.h
index 63074ef..1c45e27 100644
--- a/src/lcp-client-lib/CryptoppCryptoProvider.h
+++ b/src/lcp-client-lib/CryptoppCryptoProvider.h
@@ -30,6 +30,7 @@
#include
#include
+#include "public/IFileSystemProvider.h"
#include "ICryptoProvider.h"
#include "NonCopyable.h"
@@ -60,6 +61,9 @@ class ICertificateRevocationList;
, INetProvider * netProvider
#endif //!DISABLE_NET_PROVIDER
+ , IFileSystemProvider * fileSystemProvider
+
+
#if !DISABLE_CRL
, const std::string & defaultCrlUrl
#endif //!DISABLE_CRL
@@ -72,10 +76,16 @@ class ICertificateRevocationList;
);
virtual Status DecryptUserKey(
- const std::string & userPassphrase,
- ILicense * license,
- KeyType & userKey
- );
+ const std::string & userPassphrase,
+ ILicense * license,
+ KeyType & userKey1,
+ KeyType & userKey2
+ );
+
+ virtual Status LegacyPassphraseUserKey(
+ const KeyType & userKey1,
+ KeyType & userKey2
+ );
virtual Status DecryptContentKey(
const KeyType & userKey,
@@ -125,16 +135,27 @@ class ICertificateRevocationList;
const std::string & algorithm
);
+#if !DISABLE_CRL
+ public:
+ Status CheckRevokation(ILicense* license);
+
private:
+ Status CheckRevokation(ICertificate * providerCertificate);
Status ProcessRevokation(ICertificate * rootCertificate, ICertificate * providerCertificate);
- private:
-#if !DISABLE_CRL
+
std::unique_ptr m_revocationList;
+
+#if !DISABLE_CRL_BACKGROUND_POLL
std::unique_ptr m_threadTimer;
+#endif //!DISABLE_CRL_BACKGROUND_POLL
+
std::unique_ptr m_crlUpdater;
-#endif //!DISABLE_CRL
std::mutex m_processRevocationSync;
+#endif //!DISABLE_CRL
+
+ IFileSystemProvider * m_fileSystemProvider;
+
EncryptionProfilesManager * m_encryptionProfilesManager;
};
}
diff --git a/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.cpp b/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.cpp
index 9768e88..beedbcf 100644
--- a/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.cpp
+++ b/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.cpp
@@ -33,11 +33,7 @@ namespace lcp
{
EcdsaSha256SignatureAlgorithm::EcdsaSha256SignatureAlgorithm(const KeyType & publicKey)
{
- ByteQueue publicKeyQueue;
- KeyType rawPublicKey = publicKey;
- publicKeyQueue.Put(&rawPublicKey.at(0), rawPublicKey.size());
- publicKeyQueue.MessageEnd();
- m_publicKey.BERDecode(publicKeyQueue);
+ m_publicKeyType = publicKey;
}
std::string EcdsaSha256SignatureAlgorithm::Name() const
@@ -68,7 +64,13 @@ namespace lcp
size_t signatureLength
)
{
- ThisVerifier verifier(m_publicKey);
+ ByteQueue publicKeyQueue;
+ publicKeyQueue.Put(&m_publicKeyType.at(0), m_publicKeyType.size());
+ publicKeyQueue.MessageEnd();
+// m_publicKey.BERDecode(publicKeyQueue);
+// m_publicKeyQueue = publicKeyQueue;
+
+ ThisVerifier verifier(publicKeyQueue);
return verifier.VerifyMessage(
message,
messageLength,
diff --git a/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.h b/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.h
index 6d9c42b..a3a3539 100644
--- a/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.h
+++ b/src/lcp-client-lib/EcdsaSha256SignatureAlgorithm.h
@@ -59,7 +59,10 @@ namespace lcp
private:
typedef CryptoPP::ECDSA::Verifier ThisVerifier;
- CryptoPP::ECDSA::PublicKey m_publicKey;
+
+// CryptoPP::ECDSA::PublicKey m_publicKey;
+// CryptoPP::ByteQueue m_publicKeyQueue;
+ KeyType m_publicKeyType;
};
}
diff --git a/src/lcp-client-lib/EncryptionProfileNames.cpp b/src/lcp-client-lib/EncryptionProfileNames.cpp
index 441cd72..a407a1a 100644
--- a/src/lcp-client-lib/EncryptionProfileNames.cpp
+++ b/src/lcp-client-lib/EncryptionProfileNames.cpp
@@ -27,7 +27,12 @@
#include "EncryptionProfileNames.h"
+#if ENABLE_PROFILE_NAMES
+
namespace lcp
{
/*static*/ std::string EncryptionProfileNames::Lcp1dot0ProfileId = "http://readium.org/lcp/profile-1.0";
-}
\ No newline at end of file
+ /*static*/ std::string EncryptionProfileNames::LcpBasicProfileId = "http://readium.org/lcp/basic-profile";
+}
+
+#endif //ENABLE_PROFILE_NAMES
diff --git a/src/lcp-client-lib/EncryptionProfileNames.h b/src/lcp-client-lib/EncryptionProfileNames.h
index f816e48..2b099ed 100644
--- a/src/lcp-client-lib/EncryptionProfileNames.h
+++ b/src/lcp-client-lib/EncryptionProfileNames.h
@@ -28,6 +28,8 @@
#ifndef __ENCRYPTION_PROFILE_NAMES_H__
#define __ENCRYPTION_PROFILE_NAMES_H__
+#if ENABLE_PROFILE_NAMES
+
#include
namespace lcp
@@ -36,7 +38,10 @@ namespace lcp
{
public:
static std::string Lcp1dot0ProfileId;
+ static std::string LcpBasicProfileId;
};
}
+#endif //ENABLE_PROFILE_NAMES
+
#endif //__ENCRYPTION_PROFILE_NAMES_H__
diff --git a/src/lcp-client-lib/EncryptionProfilesManager.cpp b/src/lcp-client-lib/EncryptionProfilesManager.cpp
index 9787a09..635fa33 100644
--- a/src/lcp-client-lib/EncryptionProfilesManager.cpp
+++ b/src/lcp-client-lib/EncryptionProfilesManager.cpp
@@ -32,10 +32,15 @@ namespace lcp
{
EncryptionProfilesManager::EncryptionProfilesManager()
{
+#if ENABLE_PROFILE_NAMES
std::unique_ptr lcp1dot0(new Lcp1dot0EncryptionProfile());
m_profilesMap.insert(std::make_pair(lcp1dot0->Name(), std::move(lcp1dot0)));
+#else
+ m_profile.reset(new Lcp1dot0EncryptionProfile());
+#endif //ENABLE_PROFILE_NAMES
}
+#if ENABLE_PROFILE_NAMES
bool EncryptionProfilesManager::RegisterProfile(std::unique_ptr profile)
{
std::unique_lock locker(m_profilesSync);
@@ -53,4 +58,10 @@ namespace lcp
}
return nullptr;
}
-}
\ No newline at end of file
+#else
+ IEncryptionProfile * EncryptionProfilesManager::GetProfile() const
+ {
+ return m_profile.get();
+ }
+#endif //ENABLE_PROFILE_NAMES
+}
diff --git a/src/lcp-client-lib/EncryptionProfilesManager.h b/src/lcp-client-lib/EncryptionProfilesManager.h
index 09e6d6e..87d7862 100644
--- a/src/lcp-client-lib/EncryptionProfilesManager.h
+++ b/src/lcp-client-lib/EncryptionProfilesManager.h
@@ -28,9 +28,13 @@
#ifndef __ENCRYPTION_PROFILES_MANAGER_H__
#define __ENCRYPTION_PROFILES_MANAGER_H__
+#if ENABLE_PROFILE_NAMES
#include