commit b9f0240d1315e942de21f1a4ec742c665711b98a Author: luwenpeng Date: Tue Oct 26 11:49:04 2021 +0300 TSG-8214 基于LDK中的hasp_update构建RPM,用于获取机器指纹/设置Lience diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4ba7d4d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,109 @@ +image: "git.mesalab.cn:7443/mesa_platform/build-env:master" +variables: + GIT_STRATEGY: "clone" + BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/ + INSTALL_PREFIX: "/opt/tsg/licence_tool" + TESTING_VERSION_BUILD: 0 + +stages: +- build + +.build_by_travis: + before_script: + - mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/ + - ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH + - cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH + - chmod +x ./ci/travis.sh + script: + - yum makecache + - ./ci/travis.sh + tags: + - share + +branch_build_debug: + stage: build + extends: .build_by_travis + variables: + BUILD_TYPE: Debug + except: + - /^develop-.*$/i + - /^release-.*$/i + - tags + +branch_build_release: + stage: build + variables: + BUILD_TYPE: RelWithDebInfo + extends: .build_by_travis + except: + - /^develop-.*$/i + - /^release-.*$/i + - tags + +develop_build_debug: + stage: build + extends: .build_by_travis + variables: + TESTING_VERSION_BUILD: 1 + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: Debug + PACKAGE: 1 + PULP3_REPO_NAME: tsg-testing-x86_64.el7 + PULP3_DIST_NAME: tsg-testing-x86_64.el7 + artifacts: + name: "licence_tool-develop-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - /^develop-.*$/i + - /^release-.*$/i + +develop_build_release: + stage: build + extends: .build_by_travis + variables: + TESTING_VERSION_BUILD: 1 + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: RelWithDebInfo + PACKAGE: 1 + PULP3_REPO_NAME: tsg-testing-x86_64.el7 + PULP3_DIST_NAME: tsg-testing-x86_64.el7 + artifacts: + name: "licence_tool-develop-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - /^develop-.*$/i + - /^release-.*$/i + +release_build_debug: + stage: build + variables: + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: Debug + PACKAGE: 1 + PULP3_REPO_NAME: tsg-stable-x86_64.el7 + PULP3_DIST_NAME: tsg-stable-x86_64.el7 + extends: .build_by_travis + artifacts: + name: "licence_tool-install-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - tags + +release_build_release: + stage: build + variables: + BUILD_TYPE: RelWithDebInfo + UPLOAD_SYMBOL_FILES: 1 + PACKAGE: 1 + PULP3_REPO_NAME: tsg-stable-x86_64.el7 + PULP3_DIST_NAME: tsg-stable-x86_64.el7 + extends: .build_by_travis + artifacts: + name: "licence_tool-install-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - tags diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5a41b02 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.5) +project(licence_tool) + +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +include(Version) +include(Package) + +add_definitions(-D_GNU_SOURCE) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 11) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() + +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set (CMAKE_INSTALL_PREFIX "/opt/tsg/licence_tool" CACHE PATH "default install path" FORCE ) +endif() + +# Global compile options +option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE) +option(ENABLE_WARNING_ALL "Enable all optional warnings which are desirable for normal code" TRUE) + +if(NOT ASAN_OPTION) + option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE) +else() + option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" TRUE) +endif() + +option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE) + +if(ENABLE_PIC) + set(CMAKE_POSITION_INDEPENDENT_CODE 1) +endif() + +if(ENABLE_WARNING_ALL) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +endif() + +if(ENABLE_SANITIZE_ADDRESS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") +elseif(ENABLE_SANITIZE_THREAD) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") +endif() + +if(ENABLE_SANITIZE_ADDRESS AND ENABLE_SANITIZE_THREAD) + message(WARNING "Both ENABLE_SANITIZE_ADDRESS and ENABLE_SANITIZE_THREAD set, only ENABLE_SANITIZE_ADDRESS effected.") +endif() + +add_custom_target("install-program" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Program -P cmake_install.cmake) +add_custom_target("install-profile" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Profile -P cmake_install.cmake) + +add_subdirectory(platform) diff --git a/autorevision.sh b/autorevision.sh new file mode 100644 index 0000000..5746a4a --- /dev/null +++ b/autorevision.sh @@ -0,0 +1,1268 @@ +#!/bin/sh + +# Copyright (c) 2012 - 2016 dak180 and contributors. See +# https://opensource.org/licenses/mit-license.php or the included +# COPYING.md for licence terms. +# +# autorevision - extracts metadata about the head version from your +# repository. + +# Usage message. +arUsage() { + cat > "/dev/stderr" << EOF +usage: autorevision {-t output-type | -s symbol} [-o cache-file [-f] ] [-V] + Options include: + -t output-type = specify output type + -s symbol = specify symbol output + -o cache-file = specify cache file location + -f = force the use of cache data + -U = check for untracked files in svn + -V = emit version and exit + -? = help message + +The following are valid output types: + clojure = clojure file + c = C/C++ file + h = Header for use with c/c++ + hpp = Alternate C++ header strings with namespace + ini = INI file + java = Java file + javaprop = Java properties file + js = javascript file + json = JSON file + lua = Lua file + m4 = m4 file + matlab = matlab file + octave = octave file + php = PHP file + pl = Perl file + py = Python file + rpm = rpm file + scheme = scheme file + sh = Bash sytax + swift = Swift file + tex = (La)TeX file + xcode = Header useful for populating info.plist files + cmake = CMake file + + +The following are valid symbols: + VCS_TYPE + VCS_BASENAME + VCS_UUID + VCS_NUM + VCS_DATE + VCS_BRANCH + VCS_TAG + VCS_TICK + VCS_EXTRA + VCS_FULL_HASH + VCS_SHORT_HASH + VCS_WC_MODIFIED + VCS_ACTION_STAMP +EOF + exit 1 +} + +# Config +ARVERSION="&&ARVERSION&&" +TARGETFILE="/dev/stdout" +while getopts ":t:o:s:VfU" OPTION; do + case "${OPTION}" in + t) + AFILETYPE="${OPTARG}" + ;; + o) + CACHEFILE="${OPTARG}" + ;; + f) + CACHEFORCE="1" + ;; + s) + VAROUT="${OPTARG}" + ;; + U) + UNTRACKEDFILES="1" + ;; + V) + echo "autorevision ${ARVERSION}" + exit 0 + ;; + ?) + # If an unknown flag is used (or -?): + arUsage + ;; + esac +done + +if [ ! -z "${VAROUT}" ] && [ ! -z "${AFILETYPE}" ]; then + # If both -s and -t are specified: + echo "error: Improper argument combination." 1>&2 + exit 1 +elif [ -z "${VAROUT}" ] && [ -z "${AFILETYPE}" ]; then + # If neither -s or -t are specified: + arUsage +elif [ -z "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then + # If -f is specified without -o: + arUsage +elif [ ! -f "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then + # If we are forced to use the cache but it does not exist. + echo "error: Cache forced but no cache found." 1>&2 + exit 1 +fi + +# Make sure that the path we are given is one we can source +# (dash, we are looking at you). +if [ ! -z "${CACHEFILE}" ] && ! echo "${CACHEFILE}" | grep -q '^\.*/'; then + CACHEFILE="./${CACHEFILE}" +fi + +GENERATED_HEADER="Generated by autorevision - do not hand-hack!" + +# Functions to extract data from different repo types. +# For git repos +# shellcheck disable=SC2039,SC2164,SC2155 +gitRepo() { + local oldPath="${PWD}" + + cd "$(git rev-parse --show-toplevel)" + + VCS_TYPE="git" + + VCS_BASENAME="$(basename "${PWD}")" + + VCS_UUID="$(git rev-list --max-parents=0 --date-order --reverse HEAD 2>/dev/null | sed -n 1p)" + if [ -z "${VCS_UUID}" ]; then + VCS_UUID="$(git rev-list --topo-order HEAD | tail -n 1)" + fi + + # Is the working copy clean? + test -z "$(git status --untracked-files=normal --porcelain)" + VCS_WC_MODIFIED="${?}" + + # Enumeration of changesets + VCS_NUM="$(git rev-list --count HEAD 2>/dev/null)" + if [ -z "${VCS_NUM}" ]; then + echo "warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it." 1>&2 + VCS_NUM="$(git rev-list HEAD | wc -l)" + fi + + # This may be a git-svn remote. If so, report the Subversion revision. + if [ -z "$(git config svn-remote.svn.url 2>/dev/null)" ]; then + # The full revision hash + VCS_FULL_HASH="$(git rev-parse HEAD)" + + # The short hash + VCS_SHORT_HASH="$(echo "${VCS_FULL_HASH}" | cut -b 1-7)" + else + # The git-svn revision number + VCS_FULL_HASH="$(git svn find-rev HEAD)" + VCS_SHORT_HASH="${VCS_FULL_HASH}" + fi + + # Current branch + VCS_BRANCH="$(git rev-parse --symbolic-full-name --verify "$(git name-rev --name-only --no-undefined HEAD 2>/dev/null)" 2>/dev/null | sed -e 's:refs/heads/::' | sed -e 's:refs/::')" + + # Cache the description + local DESCRIPTION="$(git describe --long --tags 2>/dev/null)" + + # Current or last tag ancestor (empty if no tags) + VCS_TAG="$(echo "${DESCRIPTION}" | sed -e "s:-g${VCS_SHORT_HASH}\$::" -e 's:-[0-9]*$::')" + + # Distance to last tag or an alias of VCS_NUM if there is no tag + if [ ! -z "${DESCRIPTION}" ]; then + VCS_TICK="$(echo "${DESCRIPTION}" | sed -e "s:${VCS_TAG}-::" -e "s:-g${VCS_SHORT_HASH}::")" + else + VCS_TICK="${VCS_NUM}" + fi + + # Date of the current commit + VCS_DATE="$(TZ=UTC git show -s --date=iso-strict-local --pretty=format:%ad | sed -e 's|+00:00|Z|')" + if [ -z "${VCS_DATE}" ]; then + echo "warning: Action stamps require git version 2.7+." 1>&2 + VCS_DATE="$(git log -1 --pretty=format:%ci | sed -e 's: :T:' -e 's: ::' -e 's|+00:00|Z|')" + local ASdis="1" + fi + + # Action Stamp + if [ -z "${ASdis}" ]; then + VCS_ACTION_STAMP="${VCS_DATE}!$(git show -s --pretty=format:%cE)" + else + VCS_ACTION_STAMP="" + fi + + cd "${oldPath}" +} + +# For hg repos +# shellcheck disable=SC2039,SC2164 +hgRepo() { + local oldPath="${PWD}" + + cd "$(hg root)" + + VCS_TYPE="hg" + + VCS_BASENAME="$(basename "${PWD}")" + + VCS_UUID="$(hg log -r "0" -l 1 --template '{node}\n')" + + # Is the working copy clean? + test -z "$(hg status -duram)" + VCS_WC_MODIFIED="${?}" + + # Enumeration of changesets + VCS_NUM="$(hg id -n | tr -d '+')" + + # The full revision hash + VCS_FULL_HASH="$(hg log -r "${VCS_NUM}" -l 1 --template '{node}\n')" + + # The short hash + VCS_SHORT_HASH="$(hg id -i | tr -d '+')" + + # Current bookmark (bookmarks are roughly equivalent to git's branches) + # or branch if no bookmark + VCS_BRANCH="$(hg id -B | cut -d ' ' -f 1)" + # Fall back to the branch if there are no bookmarks + if [ -z "${VCS_BRANCH}" ]; then + VCS_BRANCH="$(hg id -b)" + fi + + # Current or last tag ancestor (excluding auto tags, empty if no tags) + VCS_TAG="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttag}\n' 2>/dev/null | sed -e 's:qtip::' -e 's:tip::' -e 's:qbase::' -e 's:qparent::' -e "s:$(hg --config 'extensions.color=' --config 'extensions.mq=' --color never qtop 2>/dev/null)::" | cut -d ' ' -f 1)" + + # Distance to last tag or an alias of VCS_NUM if there is no tag + if [ ! -z "${VCS_TAG}" ]; then + VCS_TICK="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttagdistance}\n' 2>/dev/null)" + else + VCS_TICK="${VCS_NUM}" + fi + + # Date of the current commit + VCS_DATE="$(hg log -r "${VCS_NUM}" -l 1 --template '{date|isodatesec}\n' 2>/dev/null | sed -e 's: :T:' -e 's: ::' -e 's|+00:00|Z|')" + + # Action Stamp + VCS_ACTION_STAMP="$(TZ=UTC hg log -r "${VCS_NUM}" -l 1 --template '{date|localdate|rfc3339date}\n' 2>/dev/null | sed -e 's|+00:00|Z|')!$(hg log -r "${VCS_NUM}" -l 1 --template '{author|email}\n' 2>/dev/null)" + + cd "${oldPath}" +} + +# For bzr repos +# shellcheck disable=SC2039,SC2164 +bzrRepo() { + local oldPath="${PWD}" + + cd "$(bzr root)" + + VCS_TYPE="bzr" + + VCS_BASENAME="$(basename "${PWD}")" + + # Currently unimplemented because more investigation is needed. + VCS_UUID="" + + # Is the working copy clean? + bzr version-info --custom --template='{clean}\n' | grep -q '1' + VCS_WC_MODIFIED="${?}" + + # Enumeration of changesets + VCS_NUM="$(bzr revno)" + + # The full revision hash + VCS_FULL_HASH="$(bzr version-info --custom --template='{revision_id}\n')" + + # The short hash + VCS_SHORT_HASH="${VCS_NUM}" + + # Nick of the current branch + VCS_BRANCH="$(bzr nick)" + + # Current or last tag ancestor (excluding auto tags, empty if no tags) + VCS_TAG="$(bzr tags --sort=time | sed '/?$/d' | tail -n1 | cut -d ' ' -f1)" + + # Distance to last tag or an alias of VCS_NUM if there is no tag + if [ ! -z "${VCS_TAG}" ]; then + VCS_TICK="$(bzr log --line -r "tag:${VCS_TAG}.." | tail -n +2 | wc -l | sed -e 's:^ *::')" + else + VCS_TICK="${VCS_NUM}" + fi + + # Date of the current commit + VCS_DATE="$(bzr version-info --custom --template='{date}\n' | sed -e 's: :T:' -e 's: ::')" + + # Action Stamp + # Currently unimplemented because more investigation is needed. + VCS_ACTION_STAMP="" + + cd "${oldPath}" +} + +# For svn repos +# shellcheck disable=SC2039,SC2164,SC2155 +svnRepo() { + local oldPath="${PWD}" + + VCS_TYPE="svn" + + case "${PWD}" in + /*trunk*|/*branches*|/*tags*) + local fn="${PWD}" + while [ "$(basename "${fn}")" != 'trunk' ] && [ "$(basename "${fn}")" != 'branches' ] && [ "$(basename "${fn}")" != 'tags' ] && [ "$(basename "${fn}")" != '/' ]; do + local fn="$(dirname "${fn}")" + done + local fn="$(dirname "${fn}")" + if [ "${fn}" = '/' ]; then + VCS_BASENAME="$(basename "${PWD}")" + else + VCS_BASENAME="$(basename "${fn}")" + fi + ;; + *) VCS_BASENAME="$(basename "${PWD}")" ;; + esac + + VCS_UUID="$(svn info --xml | sed -n -e 's:::' -e 's:::p')" + + # Cache svnversion output + local SVNVERSION="$(svnversion)" + + # Is the working copy clean? + echo "${SVNVERSION}" | grep -q "M" + case "${?}" in + 0) + VCS_WC_MODIFIED="1" + ;; + 1) + if [ ! -z "${UNTRACKEDFILES}" ]; then + # `svnversion` does not detect untracked files and `svn status` is really slow, so only run it if we really have to. + if [ -z "$(svn status)" ]; then + VCS_WC_MODIFIED="0" + else + VCS_WC_MODIFIED="1" + fi + else + VCS_WC_MODIFIED="0" + fi + ;; + esac + + # Enumeration of changesets + VCS_NUM="$(echo "${SVNVERSION}" | cut -d : -f 1 | sed -e 's:M::' -e 's:S::' -e 's:P::')" + + # The full revision hash + VCS_FULL_HASH="${SVNVERSION}" + + # The short hash + VCS_SHORT_HASH="${VCS_NUM}" + + # Current branch + case "${PWD}" in + /*trunk*|/*branches*|/*tags*) + local lastbase="" + local fn="${PWD}" + while : + do + base="$(basename "${fn}")" + if [ "${base}" = 'trunk' ]; then + VCS_BRANCH='trunk' + break + elif [ "${base}" = 'branches' ] || [ "${base}" = 'tags' ]; then + VCS_BRANCH="${lastbase}" + break + elif [ "${base}" = '/' ]; then + VCS_BRANCH="" + break + fi + local lastbase="${base}" + local fn="$(dirname "${fn}")" + done + ;; + *) VCS_BRANCH="" ;; + esac + + # Current or last tag ancestor (empty if no tags). But "current + # tag" can't be extracted reliably because Subversion doesn't + # have tags the way other VCSes do. + VCS_TAG="" + VCS_TICK="" + + # Date of the current commit + VCS_DATE="$(svn info --xml | sed -n -e 's:::' -e 's:::p')" + + # Action Stamp + VCS_ACTION_STAMP="${VCS_DATE}!$(svn log --xml -l 1 -r "${VCS_SHORT_HASH}" | sed -n -e 's:::' -e 's:::p')" + + cd "${oldPath}" +} + + +# Functions to output data in different formats. +# For bash output +shOutput() { + cat > "${TARGETFILE}" << EOF +# ${GENERATED_HEADER} + +VCS_TYPE="${VCS_TYPE}" +VCS_BASENAME="${VCS_BASENAME}" +VCS_UUID="${VCS_UUID}" +VCS_NUM="${VCS_NUM}" +VCS_DATE="${VCS_DATE}" +VCS_BRANCH="${VCS_BRANCH}" +VCS_TAG="${VCS_TAG}" +VCS_TICK="${VCS_TICK}" +VCS_EXTRA="${VCS_EXTRA}" + +VCS_ACTION_STAMP="${VCS_ACTION_STAMP}" +VCS_FULL_HASH="${VCS_FULL_HASH}" +VCS_SHORT_HASH="${VCS_SHORT_HASH}" + +VCS_WC_MODIFIED="${VCS_WC_MODIFIED}" + +# end +EOF +} + +# For source C output +cOutput() { + cat > "${TARGETFILE}" << EOF +/* ${GENERATED_HEADER} */ + +const char *VCS_TYPE = "${VCS_TYPE}"; +const char *VCS_BASENAME = "${VCS_BASENAME}"; +const char *VCS_UUID = "${VCS_UUID}"; +const int VCS_NUM = ${VCS_NUM}; +const char *VCS_DATE = "${VCS_DATE}"; +const char *VCS_BRANCH = "${VCS_BRANCH}"; +const char *VCS_TAG = "${VCS_TAG}"; +const int VCS_TICK = ${VCS_TICK}; +const char *VCS_EXTRA = "${VCS_EXTRA}"; + +const char *VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}"; +const char *VCS_FULL_HASH = "${VCS_FULL_HASH}"; +const char *VCS_SHORT_HASH = "${VCS_SHORT_HASH}"; + +const int VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}; + +/* end */ +EOF +} + +# For header output +hOutput() { + cat > "${TARGETFILE}" << EOF +/* ${GENERATED_HEADER} */ +#ifndef AUTOREVISION_H +#define AUTOREVISION_H + +#define VCS_TYPE "${VCS_TYPE}" +#define VCS_BASENAME "${VCS_BASENAME}" +#define VCS_UUID "${VCS_UUID}" +#define VCS_NUM ${VCS_NUM} +#define VCS_DATE "${VCS_DATE}" +#define VCS_BRANCH "${VCS_BRANCH}" +#define VCS_TAG "${VCS_TAG}" +#define VCS_TICK ${VCS_TICK} +#define VCS_EXTRA "${VCS_EXTRA}" + +#define VCS_ACTION_STAMP "${VCS_ACTION_STAMP}" +#define VCS_FULL_HASH "${VCS_FULL_HASH}" +#define VCS_SHORT_HASH "${VCS_SHORT_HASH}" + +#define VCS_WC_MODIFIED ${VCS_WC_MODIFIED} + +#endif + +/* end */ +EOF +} + +# A header output for use with xcode to populate info.plist strings +xcodeOutput() { + cat > "${TARGETFILE}" << EOF +/* ${GENERATED_HEADER} */ +#ifndef AUTOREVISION_H +#define AUTOREVISION_H + +#define VCS_TYPE ${VCS_TYPE} +#define VCS_BASENAME ${VCS_BASENAME} +#define VCS_UUID ${VCS_UUID} +#define VCS_NUM ${VCS_NUM} +#define VCS_DATE ${VCS_DATE} +#define VCS_BRANCH ${VCS_BRANCH} +#define VCS_TAG ${VCS_TAG} +#define VCS_TICK ${VCS_TICK} +#define VCS_EXTRA ${VCS_EXTRA} + +#define VCS_ACTION_STAMP ${VCS_ACTION_STAMP} +#define VCS_FULL_HASH ${VCS_FULL_HASH} +#define VCS_SHORT_HASH ${VCS_SHORT_HASH} + +#define VCS_WC_MODIFIED ${VCS_WC_MODIFIED} + +#endif + +/* end */ +EOF +} + +# For Swift output +swiftOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="false" ;; + 1) VCS_WC_MODIFIED="true" ;; + esac + # For values that may not exist depending on the type of repo we + # have read from, set them to `nil` when they are empty. + if [ -z "${VCS_UUID}" ]; then + VCS_UUID="nil" + else + VCS_UUID="\"${VCS_UUID}\"" + fi + if [ -z "${VCS_TAG}" ]; then + VCS_TAG="nil" + else + VCS_TAG="\"${VCS_TAG}\"" + fi + : "${VCS_TICK:="nil"}" + if [ -z "${VCS_EXTRA}" ]; then + VCS_EXTRA="nil" + else + VCS_EXTRA="\"${VCS_EXTRA}\"" + fi + if [ -z "${VCS_ACTION_STAMP}" ]; then + VCS_ACTION_STAMP="nil" + else + VCS_ACTION_STAMP="\"${VCS_ACTION_STAMP}\"" + fi + cat > "${TARGETFILE}" << EOF +/* ${GENERATED_HEADER} */ + +let VCS_TYPE = "${VCS_TYPE}" +let VCS_BASENAME = "${VCS_BASENAME}" +let VCS_UUID: String? = ${VCS_UUID} +let VCS_NUM: Int = ${VCS_NUM} +let VCS_DATE = "${VCS_DATE}" +let VCS_BRANCH: String = "${VCS_BRANCH}" +let VCS_TAG: String? = ${VCS_TAG} +let VCS_TICK: Int? = ${VCS_TICK} +let VCS_EXTRA: String? = ${VCS_EXTRA} + +let VCS_ACTION_STAMP: String? = ${VCS_ACTION_STAMP} +let VCS_FULL_HASH: String = "${VCS_FULL_HASH}" +let VCS_SHORT_HASH: String = "${VCS_SHORT_HASH}" + +let VCS_WC_MODIFIED: Bool = ${VCS_WC_MODIFIED} + +/* end */ +EOF +} + +# For Python output +pyOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="False" ;; + 1) VCS_WC_MODIFIED="True" ;; + esac + cat > "${TARGETFILE}" << EOF +# ${GENERATED_HEADER} + +VCS_TYPE = "${VCS_TYPE}" +VCS_BASENAME = "${VCS_BASENAME}" +VCS_UUID = "${VCS_UUID}" +VCS_NUM = ${VCS_NUM} +VCS_DATE = "${VCS_DATE}" +VCS_BRANCH = "${VCS_BRANCH}" +VCS_TAG = "${VCS_TAG}" +VCS_TICK = ${VCS_TICK} +VCS_EXTRA = "${VCS_EXTRA}" + +VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}" +VCS_FULL_HASH = "${VCS_FULL_HASH}" +VCS_SHORT_HASH = "${VCS_SHORT_HASH}" + +VCS_WC_MODIFIED = ${VCS_WC_MODIFIED} + +# end +EOF +} + +# For Perl output +plOutput() { + cat << EOF +# ${GENERATED_HEADER} + +\$VCS_TYPE = '${VCS_TYPE}'; +\$VCS_BASENAME = '${VCS_BASENAME}'; +\$VCS_UUID = '${VCS_UUID}'; +\$VCS_NUM = ${VCS_NUM}; +\$VCS_DATE = '${VCS_DATE}'; +\$VCS_BRANCH = '${VCS_BRANCH}'; +\$VCS_TAG = '${VCS_TAG}'; +\$VCS_TICK = ${VCS_TICK}; +\$VCS_EXTRA = '${VCS_EXTRA}'; + +\$VCS_ACTION_STAMP = '${VCS_ACTION_STAMP}'; +\$VCS_FULL_HASH = '${VCS_FULL_HASH}'; +\$VCS_SHORT_HASH = '${VCS_SHORT_HASH}'; + +\$VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}; + +# end +1; +EOF +} + +# For lua output +luaOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="false" ;; + 1) VCS_WC_MODIFIED="true" ;; + esac + cat > "${TARGETFILE}" << EOF +-- ${GENERATED_HEADER} + +VCS_TYPE = "${VCS_TYPE}" +VCS_BASENAME = "${VCS_BASENAME}" +VCS_UUID = "${VCS_UUID}" +VCS_NUM = ${VCS_NUM} +VCS_DATE = "${VCS_DATE}" +VCS_BRANCH = "${VCS_BRANCH}" +VCS_TAG = "${VCS_TAG}" +VCS_TICK = ${VCS_TICK} +VCS_EXTRA = "${VCS_EXTRA}" + +VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}" +VCS_FULL_HASH = "${VCS_FULL_HASH}" +VCS_SHORT_HASH = "${VCS_SHORT_HASH}" + +VCS_WC_MODIFIED = ${VCS_WC_MODIFIED} + +-- end +EOF +} + +# For php output +phpOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="false" ;; + 1) VCS_WC_MODIFIED="true" ;; + esac + cat > "${TARGETFILE}" << EOF + "${VCS_TYPE}", + "VCS_BASENAME" => "${VCS_BASENAME}", + "VCS_UUID" => "${VCS_UUID}", + "VCS_NUM" => ${VCS_NUM}, + "VCS_DATE" => "${VCS_DATE}", + "VCS_BRANCH" => "${VCS_BRANCH}", + "VCS_TAG" => "${VCS_TAG}", + "VCS_TICK" => ${VCS_TICK}, + "VCS_EXTRA" => "${VCS_EXTRA}", + "VCS_ACTION_STAMP" => "${VCS_ACTION_STAMP}", + "VCS_FULL_HASH" => "${VCS_FULL_HASH}", + "VCS_SHORT_HASH" => "${VCS_SHORT_HASH}", + "VCS_WC_MODIFIED" => ${VCS_WC_MODIFIED} +); + +# end +?> +EOF +} + +# For ini output +iniOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="false" ;; + 1) VCS_WC_MODIFIED="true" ;; + esac + cat > "${TARGETFILE}" << EOF +; ${GENERATED_HEADER} +[VCS] +VCS_TYPE = "${VCS_TYPE}" +VCS_BASENAME = "${VCS_BASENAME}" +VCS_UUID = "${VCS_UUID}" +VCS_NUM = ${VCS_NUM} +VCS_DATE = "${VCS_DATE}" +VCS_BRANCH = "${VCS_BRANCH}" +VCS_TAG = "${VCS_TAG}" +VCS_TICK = ${VCS_TICK} +VCS_EXTRA = "${VCS_EXTRA}" +VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}" +VCS_FULL_HASH = "${VCS_FULL_HASH}" +VCS_SHORT_HASH = "${VCS_SHORT_HASH}" +VCS_WC_MODIFIED = ${VCS_WC_MODIFIED} +; end +EOF +} + +# For javascript output +jsOutput() { + case "${VCS_WC_MODIFIED}" in + 1) VCS_WC_MODIFIED="true" ;; + 0) VCS_WC_MODIFIED="false" ;; + esac + cat > "${TARGETFILE}" << EOF +/** ${GENERATED_HEADER} */ + +var autorevision = { + VCS_TYPE: "${VCS_TYPE}", + VCS_BASENAME: "${VCS_BASENAME}", + VCS_UUID: "${VCS_UUID}", + VCS_NUM: ${VCS_NUM}, + VCS_DATE: "${VCS_DATE}", + VCS_BRANCH: "${VCS_BRANCH}", + VCS_TAG: "${VCS_TAG}", + VCS_TICK: ${VCS_TICK}, + VCS_EXTRA: "${VCS_EXTRA}", + + VCS_ACTION_STAMP: "${VCS_ACTION_STAMP}", + VCS_FULL_HASH: "${VCS_FULL_HASH}", + VCS_SHORT_HASH: "${VCS_SHORT_HASH}", + + VCS_WC_MODIFIED: ${VCS_WC_MODIFIED} +}; + +/** Node.js compatibility */ +if (typeof module !== 'undefined') { + module.exports = autorevision; +} + +/** end */ +EOF +} + +# For JSON output +jsonOutput() { + case "${VCS_WC_MODIFIED}" in + 1) VCS_WC_MODIFIED="true" ;; + 0) VCS_WC_MODIFIED="false" ;; + esac + cat > "${TARGETFILE}" << EOF +{ + "_comment": "${GENERATED_HEADER}", + "VCS_TYPE": "${VCS_TYPE}", + "VCS_BASENAME": "${VCS_BASENAME}", + "VCS_UUID": "${VCS_UUID}", + "VCS_NUM": ${VCS_NUM}, + "VCS_DATE": "${VCS_DATE}", + "VCS_BRANCH":"${VCS_BRANCH}", + "VCS_TAG": "${VCS_TAG}", + "VCS_TICK": ${VCS_TICK}, + "VCS_EXTRA": "${VCS_EXTRA}", + + "VCS_ACTION_STAMP": "${VCS_ACTION_STAMP}", + "VCS_FULL_HASH": "${VCS_FULL_HASH}", + "VCS_SHORT_HASH": "${VCS_SHORT_HASH}", + + "VCS_WC_MODIFIED": ${VCS_WC_MODIFIED} +} +EOF +} + +# For Java output +javaOutput() { + case "${VCS_WC_MODIFIED}" in + 1) VCS_WC_MODIFIED="true" ;; + 0) VCS_WC_MODIFIED="false" ;; + esac + cat > "${TARGETFILE}" << EOF +/* ${GENERATED_HEADER} */ + +public class autorevision { + public static final String VCS_TYPE = "${VCS_TYPE}"; + public static final String VCS_BASENAME = "${VCS_BASENAME}"; + public static final String VCS_UUID = "${VCS_UUID}"; + public static final long VCS_NUM = ${VCS_NUM}; + public static final String VCS_DATE = "${VCS_DATE}"; + public static final String VCS_BRANCH = "${VCS_BRANCH}"; + public static final String VCS_TAG = "${VCS_TAG}"; + public static final long VCS_TICK = ${VCS_TICK}; + public static final String VCS_EXTRA = "${VCS_EXTRA}"; + + public static final String VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}"; + public static final String VCS_FULL_HASH = "${VCS_FULL_HASH}"; + public static final String VCS_SHORT_HASH = "${VCS_SHORT_HASH}"; + + public static final boolean VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}; +} +EOF +} + +# For Java properties output +javapropOutput() { + case "${VCS_WC_MODIFIED}" in + 1) VCS_WC_MODIFIED="true" ;; + 0) VCS_WC_MODIFIED="false" ;; + esac + cat > "${TARGETFILE}" << EOF +# ${GENERATED_HEADER} + +VCS_TYPE=${VCS_TYPE} +VCS_BASENAME=${VCS_BASENAME} +VCS_UUID=${VCS_UUID} +VCS_NUM=${VCS_NUM} +VCS_DATE=${VCS_DATE} +VCS_BRANCH=${VCS_BRANCH} +VCS_TAG=${VCS_TAG} +VCS_TICK=${VCS_TICK} +VCS_EXTRA=${VCS_EXTRA} + +VCS_ACTION_STAMP=${VCS_ACTION_STAMP} +VCS_FULL_HASH=${VCS_FULL_HASH} +VCS_SHORT_HASH=${VCS_SHORT_HASH} + +VCS_WC_MODIFIED=${VCS_WC_MODIFIED} +EOF +} + +# For m4 output +m4Output() { + cat > "${TARGETFILE}" << EOF +dnl ${GENERATED_HEADER} +define(\`VCS_TYPE', \`${VCS_TYPE}')dnl +define(\`VCS_BASENAME', \`${VCS_BASENAME}')dnl +define(\`VCS_UUID', \`${VCS_UUID}')dnl +define(\`VCS_NUM', \`${VCS_NUM}')dnl +define(\`VCS_DATE', \`${VCS_DATE}')dnl +define(\`VCS_BRANCH', \`${VCS_BRANCH}')dnl +define(\`VCS_TAG', \`${VCS_TAG}')dnl +define(\`VCS_TICK', \`${VCS_TICK}')dnl +define(\`VCS_EXTRA', \`${VCS_EXTRA}')dnl +define(\`VCS_ACTIONSTAMP', \`${VCS_ACTION_STAMP}')dnl +define(\`VCS_FULLHASH', \`${VCS_FULL_HASH}')dnl +define(\`VCS_SHORTHASH', \`${VCS_SHORT_HASH}')dnl +define(\`VCS_WC_MODIFIED', \`${VCS_WC_MODIFIED}')dnl +EOF +} + +# For (La)TeX output +texOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="false" ;; + 1) VCS_WC_MODIFIED="true" ;; + esac + cat > "${TARGETFILE}" << EOF +% ${GENERATED_HEADER} +\def \vcsType {${VCS_TYPE}} +\def \vcsBasename {${VCS_BASENAME}} +\def \vcsUUID {${VCS_UUID}} +\def \vcsNum {${VCS_NUM}} +\def \vcsDate {${VCS_DATE}} +\def \vcsBranch {${VCS_BRANCH}} +\def \vcsTag {${VCS_TAG}} +\def \vcsTick {${VCS_TICK}} +\def \vcsExtra {${VCS_EXTRA}} +\def \vcsACTIONSTAMP {${VCS_ACTION_STAMP}} +\def \vcsFullHash {${VCS_FULL_HASH}} +\def \vcsShortHash {${VCS_SHORT_HASH}} +\def \vcsWCModified {${VCS_WC_MODIFIED}} +\endinput +EOF +} + +# For scheme output +schemeOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="#f" ;; + 1) VCS_WC_MODIFIED="#t" ;; + esac + cat > "${TARGETFILE}" << EOF +;; ${GENERATED_HEADER} +(define VCS_TYPE "${VCS_TYPE}") +(define VCS_BASENAME "${VCS_BASENAME}") +(define VCS_UUID "${VCS_UUID}") +(define VCS_NUM ${VCS_NUM}) +(define VCS_DATE "${VCS_DATE}") +(define VCS_BRANCH "${VCS_BRANCH}") +(define VCS_TAG "${VCS_TAG}") +(define VCS_TICK ${VCS_TICK}) +(define VCS_EXTRA "${VCS_EXTRA}") + +(define VCS_ACTION_STAMP "${VCS_ACTION_STAMP}") +(define VCS_FULL_HASH "${VCS_FULL_HASH}") +(define VCS_SHORT_HASH "${VCS_SHORT_HASH}") + +(define VCS_WC_MODIFIED ${VCS_WC_MODIFIED}) +;; end +EOF +} + +# For clojure output +clojureOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="false" ;; + 1) VCS_WC_MODIFIED="true" ;; + esac + cat > "${TARGETFILE}" << EOF +;; ${GENERATED_HEADER} +(def VCS_TYPE "${VCS_TYPE}") +(def VCS_BASENAME "${VCS_BASENAME}") +(def VCS_UUID "${VCS_UUID}") +(def VCS_NUM ${VCS_NUM}) +(def VCS_DATE "${VCS_DATE}") +(def VCS_BRANCH "${VCS_BRANCH}") +(def VCS_TAG "${VCS_TAG}") +(def VCS_TICK ${VCS_TICK}) +(def VCS_EXTRA "${VCS_EXTRA}") + +(def VCS_ACTION_STAMP "${VCS_ACTION_STAMP}") +(def VCS_FULL_HASH "${VCS_FULL_HASH}") +(def VCS_SHORT_HASH "${VCS_SHORT_HASH}") + +(def VCS_WC_MODIFIED ${VCS_WC_MODIFIED}) +;; end +EOF +} + +# For rpm spec file output +rpmOutput() { + cat > "${TARGETFILE}" << EOF +# ${GENERATED_HEADER} +$([ "${VCS_TYPE}" ] && echo "%define vcs_type ${VCS_TYPE}") +$([ "${VCS_BASENAME}" ] && echo "%define vcs_basename ${VCS_BASENAME}") +$([ "${VCS_UUID}" ] && echo "%define vcs_uuid ${VCS_UUID}") +$([ "${VCS_NUM}" ] && echo "%define vcs_num ${VCS_NUM}") +$([ "${VCS_DATE}" ] && echo "%define vcs_date ${VCS_DATE}") +$([ "${VCS_BRANCH}" ] && echo "%define vcs_branch ${VCS_BRANCH}") +$([ "${VCS_TAG}" ] && echo "%define vcs_tag ${VCS_TAG}") +$([ "${VCS_TICK}" ] && echo "%define vcs_tick ${VCS_TICK}") +$([ "${VCS_EXTRA}" ] && echo "%define vcs_extra ${VCS_EXTRA}") + +$([ "${VCS_ACTION_STAMP}" ] && echo "%define vcs_action_stamp ${VCS_ACTION_STAMP}") +$([ "${VCS_FULL_HASH}" ] && echo "%define vcs_full_hash ${VCS_FULL_HASH}") +$([ "${VCS_SHORT_HASH}" ] && echo "%define vcs_short_hash ${VCS_SHORT_HASH}") + +$([ "${VCS_WC_MODIFIED}" ] && echo "%define vcs_wc_modified ${VCS_WC_MODIFIED}") +# end +EOF +} + +# shellcheck disable=SC2155,SC2039 +hppOutput() { + local NAMESPACE="$(echo "${VCS_BASENAME}" | sed -e 's:_::g' | tr '[:lower:]' '[:upper:]')" + cat > "${TARGETFILE}" << EOF +/* ${GENERATED_HEADER} */ + +#ifndef ${NAMESPACE}_AUTOREVISION_H +#define ${NAMESPACE}_AUTOREVISION_H + +#include + +namespace $(echo "${NAMESPACE}" | tr '[:upper:]' '[:lower:]') +{ + const std::string VCS_TYPE = "${VCS_TYPE}"; + const std::string VCS_BASENAME = "${VCS_BASENAME}"; + const std::string VCS_UUID = "${VCS_UUID}"; + const int VCS_NUM = ${VCS_NUM}; + const std::string VCS_DATE = "${VCS_DATE}"; + const std::string VCS_BRANCH = "${VCS_BRANCH}"; + const std::string VCS_TAG = "${VCS_TAG}"; + const int VCS_TICK = ${VCS_TICK}; + const std::string VCS_EXTRA = "${VCS_EXTRA}"; + + const std::string VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}"; + const std::string VCS_FULL_HASH = "${VCS_FULL_HASH}"; + const std::string VCS_SHORT_HASH = "${VCS_SHORT_HASH}"; + + const int VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}; +} + +#endif + +/* end */ +EOF +} + +matlabOutput() { + case "${VCS_WC_MODIFIED}" in + 0) VCS_WC_MODIFIED="FALSE" ;; + 1) VCS_WC_MODIFIED="TRUE" ;; + esac + cat > "${TARGETFILE}" << EOF +% ${GENERATED_HEADER} + +VCS_TYPE = '${VCS_TYPE}'; +VCS_BASENAME = '${VCS_BASENAME}'; +VCS_UUID = '${VCS_UUID}'; +VCS_NUM = ${VCS_NUM}; +VCS_DATE = '${VCS_DATE}'; +VCS_BRANCH = '${VCS_BRANCH}'; +VCS_TAG = '${VCS_TAG}'; +VCS_TICK = ${VCS_TICK}; +VCS_EXTRA = '${VCS_EXTRA}'; + +VCS_ACTION_STAMP = '${VCS_ACTION_STAMP}'; +VCS_FULL_HASH = '${VCS_FULL_HASH}'; +VCS_SHORT_HASH = '${VCS_SHORT_HASH}'; + +VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}; + +% end +EOF +} + +octaveOutput() { + cat > "${TARGETFILE}" << EOF +% ${GENERATED_HEADER} + +VCS_TYPE = '${VCS_TYPE}'; +VCS_BASENAME = '${VCS_BASENAME}'; +VCS_UUID = '${VCS_UUID}'; +VCS_NUM = ${VCS_NUM}; +VCS_DATE = '${VCS_DATE}'; +VCS_BRANCH = '${VCS_BRANCH}'; +VCS_TAG = '${VCS_TAG}'; +VCS_TICK = ${VCS_TICK}; +VCS_EXTRA = '${VCS_EXTRA}'; + +VCS_ACTION_STAMP = '${VCS_ACTION_STAMP}'; +VCS_FULL_HASH = '${VCS_FULL_HASH}'; +VCS_SHORT_HASH = '${VCS_SHORT_HASH}'; + +VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}; + +% end +EOF +} + +cmakeOutput() { + cat > "${TARGETFILE}" << EOF +# ${GENERATED_HEADER} + +set(VCS_TYPE ${VCS_TYPE}) +set(VCS_BASENAME ${VCS_BASENAME}) +set(VCS_UUID ${VCS_UUID}) +set(VCS_NUM ${VCS_NUM}) +set(VCS_DATE ${VCS_DATE}) +set(VCS_BRANCH ${VCS_BRANCH}) +set(VCS_TAG ${VCS_TAG}) +set(VCS_TICK ${VCS_TICK}) +set(VCS_EXTRA ${VCS_EXTRA}) + +set(VCS_ACTION_STAMP ${VCS_ACTION_STAMP}) +set(VCS_FULL_HASH ${VCS_FULL_HASH}) +set(VCS_SHORT_HASH ${VCS_SHORT_HASH}) + +set(VCS_WC_MODIFIED ${VCS_WC_MODIFIED}) + +# end +EOF +} + + +# Helper functions +# Count path segments +# shellcheck disable=SC2039 +pathSegment() { + local pathz="${1}" + local depth="0" + + if [ ! -z "${pathz}" ]; then + # Continue until we are at / or there are no path separators left. + while [ ! "${pathz}" = "/" ] && [ ! "${pathz}" = "$(echo "${pathz}" | sed -e 's:/::')" ]; do + pathz="$(dirname "${pathz}")" + depth="$((depth+1))" + done + fi + echo "${depth}" +} + +# Largest of four numbers +# shellcheck disable=SC2039 +multiCompare() { + local larger="${1}" + local numA="${2}" + local numB="${3}" + local numC="${4}" + + [ "${numA}" -gt "${larger}" ] && larger="${numA}" + [ "${numB}" -gt "${larger}" ] && larger="${numB}" + [ "${numC}" -gt "${larger}" ] && larger="${numC}" + echo "${larger}" +} + +# Test for repositories +# shellcheck disable=SC2155,SC2039 +repoTest() { + REPONUM="0" + if [ ! -z "$(git rev-parse HEAD 2>/dev/null)" ]; then + local gitPath="$(git rev-parse --show-toplevel)" + local gitDepth="$(pathSegment "${gitPath}")" + REPONUM="$((REPONUM+1))" + else + local gitDepth="0" + fi + if [ ! -z "$(hg root 2>/dev/null)" ]; then + local hgPath="$(hg root 2>/dev/null)" + local hgDepth="$(pathSegment "${hgPath}")" + REPONUM="$((REPONUM+1))" + else + local hgDepth="0" + fi + if [ ! -z "$(bzr root 2>/dev/null)" ]; then + local bzrPath="$(bzr root 2>/dev/null)" + local bzrDepth="$(pathSegment "${bzrPath}")" + REPONUM="$((REPONUM+1))" + else + local bzrDepth="0" + fi + if [ ! -z "$(svn info 2>/dev/null)" ]; then + local stringz="" + local stringx="" + local svnPath="$(svn info --xml | sed -n -e "s:${stringz}::" -e "s:${stringx}::p")" + # An old enough svn will not be able give us a path; default + # to 1 for that case. + if [ -z "${svnPath}" ]; then + local svnDepth="1" + else + local svnDepth="$(pathSegment "${svnPath}")" + fi + REPONUM="$((REPONUM+1))" + else + local svnDepth="0" + fi + + # Do not do more work then we have to. + if [ "${REPONUM}" = "0" ]; then + return + fi + + # Figure out which repo is the deepest and use it. + local wonRepo="$(multiCompare "${gitDepth}" "${hgDepth}" "${bzrDepth}" "${svnDepth}")" + if [ "${wonRepo}" = "${gitDepth}" ]; then + gitRepo + elif [ "${wonRepo}" = "${hgDepth}" ]; then + hgRepo + elif [ "${wonRepo}" = "${bzrDepth}" ]; then + bzrRepo + elif [ "${wonRepo}" = "${svnDepth}" ]; then + svnRepo + fi +} + + + +# Detect which repos we are in and gather data. +# shellcheck source=/dev/null +if [ -f "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then + # When requested only read from the cache to populate our symbols. + . "${CACHEFILE}" +else + # If a value is not set through the environment set VCS_EXTRA to nothing. + : "${VCS_EXTRA:=""}" + repoTest + + if [ -f "${CACHEFILE}" ] && [ "${REPONUM}" = "0" ]; then + # We are not in a repo; try to use a previously generated cache to populate our symbols. + . "${CACHEFILE}" + # Do not overwrite the cache if we know we are not going to write anything new. + CACHEFORCE="1" + elif [ "${REPONUM}" = "0" ]; then + echo "error: No repo or cache detected." 1>&2 + exit 1 + fi +fi + + +# -s output is handled here. +if [ ! -z "${VAROUT}" ]; then + if [ "${VAROUT}" = "VCS_TYPE" ]; then + echo "${VCS_TYPE}" + elif [ "${VAROUT}" = "VCS_BASENAME" ]; then + echo "${VCS_BASENAME}" + elif [ "${VAROUT}" = "VCS_NUM" ]; then + echo "${VCS_NUM}" + elif [ "${VAROUT}" = "VCS_DATE" ]; then + echo "${VCS_DATE}" + elif [ "${VAROUT}" = "VCS_BRANCH" ]; then + echo "${VCS_BRANCH}" + elif [ "${VAROUT}" = "VCS_TAG" ]; then + echo "${VCS_TAG}" + elif [ "${VAROUT}" = "VCS_TICK" ]; then + echo "${VCS_TICK}" + elif [ "${VAROUT}" = "VCS_FULL_HASH" ]; then + echo "${VCS_FULL_HASH}" + elif [ "${VAROUT}" = "VCS_SHORT_HASH" ]; then + echo "${VCS_SHORT_HASH}" + elif [ "${VAROUT}" = "VCS_WC_MODIFIED" ]; then + echo "${VCS_WC_MODIFIED}" + elif [ "${VAROUT}" = "VCS_ACTION_STAMP" ]; then + echo "${VCS_ACTION_STAMP}" + else + echo "error: Not a valid output symbol." 1>&2 + exit 1 + fi +fi + + +# Detect requested output type and use it. +if [ ! -z "${AFILETYPE}" ]; then + if [ "${AFILETYPE}" = "c" ]; then + cOutput + elif [ "${AFILETYPE}" = "h" ]; then + hOutput + elif [ "${AFILETYPE}" = "xcode" ]; then + xcodeOutput + elif [ "${AFILETYPE}" = "swift" ]; then + swiftOutput + elif [ "${AFILETYPE}" = "sh" ]; then + shOutput + elif [ "${AFILETYPE}" = "py" ] || [ "${AFILETYPE}" = "python" ]; then + pyOutput + elif [ "${AFILETYPE}" = "pl" ] || [ "${AFILETYPE}" = "perl" ]; then + plOutput + elif [ "${AFILETYPE}" = "lua" ]; then + luaOutput + elif [ "${AFILETYPE}" = "php" ]; then + phpOutput + elif [ "${AFILETYPE}" = "ini" ]; then + iniOutput + elif [ "${AFILETYPE}" = "js" ]; then + jsOutput + elif [ "${AFILETYPE}" = "json" ]; then + jsonOutput + elif [ "${AFILETYPE}" = "java" ]; then + javaOutput + elif [ "${AFILETYPE}" = "javaprop" ]; then + javapropOutput + elif [ "${AFILETYPE}" = "tex" ]; then + texOutput + elif [ "${AFILETYPE}" = "m4" ]; then + m4Output + elif [ "${AFILETYPE}" = "scheme" ]; then + schemeOutput + elif [ "${AFILETYPE}" = "clojure" ]; then + clojureOutput + elif [ "${AFILETYPE}" = "rpm" ]; then + rpmOutput + elif [ "${AFILETYPE}" = "hpp" ]; then + hppOutput + elif [ "${AFILETYPE}" = "matlab" ]; then + matlabOutput + elif [ "${AFILETYPE}" = "octave" ]; then + octaveOutput + elif [ "${AFILETYPE}" = "cmake" ]; then + cmakeOutput + else + echo "error: Not a valid output type." 1>&2 + exit 1 + fi +fi + + +# If requested, make a cache file. +if [ ! -z "${CACHEFILE}" ] && [ ! "${CACHEFORCE}" = "1" ]; then + TARGETFILE="${CACHEFILE}.tmp" + shOutput + + # Check to see if there have been any actual changes. + if [ ! -f "${CACHEFILE}" ]; then + mv -f "${CACHEFILE}.tmp" "${CACHEFILE}" + elif cmp -s "${CACHEFILE}.tmp" "${CACHEFILE}"; then + rm -f "${CACHEFILE}.tmp" + else + mv -f "${CACHEFILE}.tmp" "${CACHEFILE}" + fi +fi diff --git a/ci/get-nprocessors.sh b/ci/get-nprocessors.sh new file mode 100644 index 0000000..4444e12 --- /dev/null +++ b/ci/get-nprocessors.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Copyright 2017 Google Inc. +# All Rights Reserved. +# +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * 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. +# * Neither the name of Google Inc. 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. + +# This file is typically sourced by another script. +# if possible, ask for the precise number of processors, +# otherwise take 2 processors as reasonable default; see +# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization +if [ -x /usr/bin/getconf ]; then + NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN) +else + NPROCESSORS=2 +fi + +# as of 2017-09-04 Travis CI reports 32 processors, but GCC build +# crashes if parallelized too much (maybe memory consumption problem), +# so limit to 4 processors for the time being. +if [ $NPROCESSORS -gt 4 ] ; then + echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4." + NPROCESSORS=4 +fi \ No newline at end of file diff --git a/ci/perpare_pulp3_netrc.sh b/ci/perpare_pulp3_netrc.sh new file mode 100644 index 0000000..7fa9a27 --- /dev/null +++ b/ci/perpare_pulp3_netrc.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +set -evx +echo "machine ${PULP3_SERVER_URL}\nlogin ${PULP3_SERVER_LOGIN}\npassword ${PULP3_SERVER_PASSWORD}\n" > ~/.netrc \ No newline at end of file diff --git a/ci/travis.sh b/ci/travis.sh new file mode 100644 index 0000000..3290ef0 --- /dev/null +++ b/ci/travis.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env sh +set -evx + +chmod +x ci/get-nprocessors.sh +. ci/get-nprocessors.sh + +# if possible, ask for the precise number of processors, +# otherwise take 2 processors as reasonable default; see +# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization +if [ -x /usr/bin/getconf ]; then + NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN) +else + NPROCESSORS=2 +fi + +# as of 2017-09-04 Travis CI reports 32 processors, but GCC build +# crashes if parallelized too much (maybe memory consumption problem), +# so limit to 4 processors for the time being. +if [ $NPROCESSORS -gt 4 ] ; then + echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4." + NPROCESSORS=4 +fi + +# Tell make to use the processors. No preceding '-' required. +MAKEFLAGS="j${NPROCESSORS}" +export MAKEFLAGS + +env | sort + +# Set default values to OFF for these variables if not specified. +: "${NO_EXCEPTION:=OFF}" +: "${NO_RTTI:=OFF}" +: "${COMPILER_IS_GNUCXX:=OFF}" + +# Install dependency from YUM +yum install -y libasan + +if [ $ASAN_OPTION ];then + source /opt/rh/devtoolset-7/enable +fi + +mkdir build || true +cd build + +cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DASAN_OPTION=$ASAN_OPTION \ + -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ + -DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \ + .. +make + +if [ -n "${PACKAGE}" ]; then + make package + cp ~/rpm_upload_tools.py ./ + python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm +fi + +if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then + rpm -i licence_tool*debuginfo*.rpm + cp /usr/lib/debug/opt/tsg/licence_tool/bin/licence_tool.debug /tmp/licence_tool.debuginfo.${CI_COMMIT_SHORT_SHA} + sentry-cli upload-dif -t elf /tmp/licence_tool.debuginfo.${CI_COMMIT_SHORT_SHA} +fi \ No newline at end of file diff --git a/cmake/Package.cmake b/cmake/Package.cmake new file mode 100644 index 0000000..7aa367d --- /dev/null +++ b/cmake/Package.cmake @@ -0,0 +1,30 @@ +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CPACK_PACKAGE_NAME "licence_tool-debug") +else() + set(CPACK_PACKAGE_NAME "licence_tool") +endif() + +message(STATUS "Package: ${CPACK_PACKAGE_NAME}") + +set(CPACK_PACKAGE_VENDOR "MESASOFT") +set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${DESCRIBE}") +set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + +# RPM Build +set(CPACK_GENERATOR "RPM") +set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON) +set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") +set(CPACK_RPM_PACKAGE_AUTOREQPROV "no") +set(CPACK_RPM_PACKAGE_RELEASE_DIST on) +set(CPACK_RPM_DEBUGINFO_PACKAGE on) + +# Must uninstall the debug package before install release package +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CPACK_RPM_PACKAGE_CONFLICTS "licence_tool") +else() + set(CPACK_RPM_PACKAGE_CONFLICTS "licence_tool-debug") +endif() + +include(CPack) \ No newline at end of file diff --git a/cmake/Version.cmake b/cmake/Version.cmake new file mode 100644 index 0000000..eeec748 --- /dev/null +++ b/cmake/Version.cmake @@ -0,0 +1,49 @@ + +# Using autorevision.sh to generate version information + +set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh) +set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh) +set(__VERSION_CACHE ${CMAKE_SOURCE_DIR}/version.txt) +set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake) + +file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR} + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) + +# execute autorevision.sh to generate version information +execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE} OUTPUT_FILE ${__VERSION_CONFIG}) +include(${__VERSION_CONFIG}) + +# extract major, minor, patch version from git tag +string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}") +string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}") +string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}") +string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}") + +if(NOT VERSION_MAJOR) + set(VERSION_MAJOR 1) +endif() + +if(NOT VERSION_MINOR) + set(VERSION_MINOR 0) +endif() + +if(NOT VERSION_PATCH) + set(VERSION_PATCH 0) +endif() + +if(VERSION_DAILY_BUILD) + set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE}) +endif() + +set(DESCRIBE "${VCS_SHORT_HASH}") +set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +set(GIT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${DESCRIBE}") + +# Replace .- with _ +string(REGEX REPLACE "[\\.\\-]" "_" VAR_VERSION "${GIT_VERSION}") + +# print information +message(STATUS "Welcome to Packet Adapter, Version: ${GIT_VERSION}") +add_definitions(-DGIT_VERSION=\"${GIT_VERSION}\") +add_definitions(-DVAR_VERSION=${VAR_VERSION}) \ No newline at end of file diff --git a/depend/aksusbd-8.23-1.x86_64.rpm b/depend/aksusbd-8.23-1.x86_64.rpm new file mode 100644 index 0000000..392efec Binary files /dev/null and b/depend/aksusbd-8.23-1.x86_64.rpm differ diff --git a/lib/libhasp_linux_x86_64_25743.a b/lib/libhasp_linux_x86_64_25743.a new file mode 100644 index 0000000..72573e3 Binary files /dev/null and b/lib/libhasp_linux_x86_64_25743.a differ diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt new file mode 100644 index 0000000..94ef373 --- /dev/null +++ b/platform/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(hasp_update src/hasp_update.c) + +target_include_directories(hasp_update PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/) + +target_link_libraries(hasp_update pthread) +target_link_libraries(hasp_update ${CMAKE_SOURCE_DIR}/lib/libhasp_linux_x86_64_25743.a) + +install(TARGETS hasp_update RUNTIME DESTINATION bin COMPONENT Program) \ No newline at end of file diff --git a/platform/include/hasp_api.h b/platform/include/hasp_api.h new file mode 100644 index 0000000..768872e --- /dev/null +++ b/platform/include/hasp_api.h @@ -0,0 +1,1832 @@ +/** + * \mainpage Sentinel Licensing API + * \file hasp_api.h Sentinel Licensing API declarations + * + * Copyright (C) 2013, SafeNet, Inc. All rights reserved. + */ + +#ifndef __HASP_API_H__ +#define __HASP_API_H__ + +#if !defined(WITH_AKSTYPES) && !defined(WITH_OEFTYPES) +#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) +typedef unsigned __int64 hasp_u64_t; +typedef signed __int64 hasp_s64_t; +#else +typedef unsigned long long hasp_u64_t; +typedef signed long long hasp_s64_t; +#endif +#if defined(_MSC_VER) +typedef unsigned long hasp_u32_t; +typedef signed long hasp_s32_t; +#else +typedef unsigned int hasp_u32_t; +typedef signed int hasp_s32_t; +#endif +typedef unsigned short hasp_u16_t; +typedef signed short hasp_s16_t; +typedef signed char hasp_s8_t; +typedef unsigned char hasp_u8_t; +#endif + +#if defined(_WIN32) || defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__) +#if defined(__MINGW32__) +#define HASP_CALLCONV __declspec(dllimport) __stdcall +#else +#define HASP_CALLCONV __stdcall +#endif +#else +#define HASP_CALLCONV +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @defgroup hasp_feature_ids Legacy HASP HL Run-time API: Feature ID defines + * + * @{ + */ + +/** + * \brief Legacy HASP HL Run-time API: "Feature Type" mask + * + * AND-mask used to identify Feature type. + */ +#define HASP_FEATURETYPE_MASK 0xffff0000 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number Feature" type + * + * After AND-ing with HASP_FEATURETYPE_MASK the Feature type contain this value. + */ +#define HASP_PROGNUM_FEATURETYPE 0xffff0000 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number Mask" + * + * AND-mask used to extract the Program Number from a + * "prognum" Feature ID. + */ +#define HASP_PROGNUM_MASK 0x000000ff + +/** + * \brief Legacy HASP HL Run-time API: "Program Number Options" mask + * + * AND-mask used to identify Program Number options: + * + * + * 3 bits of the mask are reserved for future extensions and currently unused. + * Initialize them with zero. + */ +#define HASP_PROGNUM_OPT_MASK 0x0000ff00 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number" option + * + * Disables the search for local licenses. + */ +#define HASP_PROGNUM_OPT_NO_LOCAL 0x00008000 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number" option + * + * Disables the search for network licenses. + */ +#define HASP_PROGNUM_OPT_NO_REMOTE 0x00004000 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number" option + * + * Sets session count of network licenses to "per-process". + */ +#define HASP_PROGNUM_OPT_PROCESS 0x00002000 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number" option + * + * Enables the API to access "classic" (HASP4 or earlier) keys. + */ +#define HASP_PROGNUM_OPT_CLASSIC 0x00001000 + +/** + * \brief Legacy HASP HL Run-time API: "Program Number" option + * + * Ignores the presence of terminal servers. + */ +#define HASP_PROGNUM_OPT_TS 0x00000800 + +/** + * \brief The Sentinel default Feature ID + * + * Available in every Sentinel key. + */ +#define HASP_DEFAULT_FID 0 + +/** + * \brief Legacy HASP HL Run-time API: The HASP default Feature ID + * + * Available in every legacy HASP hardware key. + */ +#define HASP_PROGNUM_DEFAULT_FID (HASP_DEFAULT_FID | HASP_PROGNUM_FEATURETYPE) + +/** + * @} + */ + +/** + * @defgroup hasp_file_ids Memory File ID defines + * + * @{ + */ + +/** + * \brief Legacy HASP HL Run-time API: HASP4 memory file + * + * File ID for HASP4-compatible memory contents w/o FAS. + */ +#define HASP_FILEID_MAIN 0xfff0 + +/** + * \brief Legacy HASP HL Run-time API: HASP4 FAS memory file + * + * (Dummy) File ID for the license data area of memory contents. + */ +#define HASP_FILEID_LICENSE 0xfff2 + +/** + * \brief Sentinel secure writable memory file + * + * File ID for Sentinel secure writable memory. + */ +#define HASP_FILEID_RW 0xfff4 + +/** + * \brief Sentinel secure read only memory file + * + * File ID for Sentinel read only memory. + */ +#define HASP_FILEID_RO 0xfff5 + +/** + * \brief Sentinel dynamic memory file ID avaliable range + * + * File ID lower limit for Sentinel dynamic memory file. + */ +#define HASP_FILEID_DYNAMIC_FIRST 0x1 + +/** + * \brief Sentinel dynamic memory file ID avaliable range + * + * File ID upper limit for Sentinel dynamic memory file. + */ +#define HASP_FILEID_DYNAMIC_LAST 0xffbf + + /** + * @} + */ + + /** + * @defgroup hasp_error_codes Run-time API Status Codes + * + * @{ + */ + + enum hasp_error_codes + { + /** Request successfully completed */ + HASP_STATUS_OK = 0, + + /** Request exceeds memory range of a Sentinel file */ + HASP_MEM_RANGE = 1, + + /** Legacy HASP HL Run-time API: Unknown/Invalid Feature ID option */ + HASP_INV_PROGNUM_OPT = 2, + + /** System is out of memory */ + HASP_INSUF_MEM = 3, + + /** Too many open Features/login sessions */ + HASP_TMOF = 4, + + /** Access to Feature, Sentinel protection key or functionality denied */ + HASP_ACCESS_DENIED = 5, + + /** Legacy decryption function cannot work on Feature */ + HASP_INCOMPAT_FEATURE = 6, + + /** Sentinel protection key not available */ + HASP_HASP_NOT_FOUND = 7, + + /* Deprecated - use HASP_HASP_NOT_FOUND */ + HASP_CONTAINER_NOT_FOUND = 7, + + /** Encrypted/decrypted data length too short to execute function call */ + HASP_TOO_SHORT = 8, + + /** Invalid login handle passed to function */ + HASP_INV_HND = 9, + + /** Specified File ID not recognized by API */ + HASP_INV_FILEID = 10, + + /** Installed driver or daemon too old to execute function */ + HASP_OLD_DRIVER = 11, + + /** Real-time clock (rtc) not available */ + HASP_NO_TIME = 12, + + /** Generic error from host system call */ + HASP_SYS_ERR = 13, + + /** Required driver not installed */ + HASP_NO_DRIVER = 14, + + /** Invalid XML format */ + HASP_INV_FORMAT = 15, + + /** Unable to execute function in this context; the requested + * functionality is not implemented */ + HASP_REQ_NOT_SUPP = 16, + + /** Binary data passed to function does not contain valid update */ + HASP_INV_UPDATE_OBJ = 17, + + /** Sentinel protection key not found */ + HASP_KEYID_NOT_FOUND = 18, + + /** Required XML tags not found; Contents in binary data are missing + * or invalid */ + HASP_INV_UPDATE_DATA = 19, + + /** Update request not supported by Sentinel protection key */ + HASP_INV_UPDATE_NOTSUPP = 20, + + /** Update counter set incorrectly */ + HASP_INV_UPDATE_CNTR = 21, + + /** Invalid Vendor Code passed */ + HASP_INV_VCODE = 22, + + /** Sentinel protection key does not support encryption type */ + HASP_ENC_NOT_SUPP = 23, + + /** Passed time value outside supported value range */ + HASP_INV_TIME = 24, + + /** Real-time clock battery out of power */ + HASP_NO_BATTERY_POWER = 25, + + /** Acknowledge data requested by update, but ack_data parameter + * is NULL */ + HASP_NO_ACK_SPACE = 26, + + /** Program running on a terminal server */ + HASP_TS_DETECTED = 27, + + /** Program running on a Remote Desktop */ + HASP_RDP_DETECTED = 27, + + /** Requested Feature type not implemented */ + HASP_FEATURE_TYPE_NOT_IMPL = 28, + + /** Unknown algorithm used in H2R/V2C file */ + HASP_UNKNOWN_ALG = 29, + + /** Signature verification operation failed */ + HASP_INV_SIG = 30, + + /** Requested Feature not available */ + HASP_FEATURE_NOT_FOUND = 31, + + /** Access log not enabled */ + HASP_NO_LOG = 32, + + /** Communication error between API and local Sentinel License Manager */ + HASP_LOCAL_COMM_ERR = 33, + + /** Vendor Code not recognized by API */ + HASP_UNKNOWN_VCODE = 34, + + /** Invalid XML specification */ + HASP_INV_SPEC = 35, + + /** Invalid XML scope */ + HASP_INV_SCOPE = 36, + + /** Too many Sentinel protection keys match the scope */ + HASP_TOO_MANY_KEYS = 37, + + /** Too many concurrent user sessions currently connected */ + HASP_TOO_MANY_USERS = 38, + + /** Session been interrupted */ + HASP_BROKEN_SESSION = 39, + + /** Communication error between local and remote Sentinel License Managers */ + HASP_REMOTE_COMM_ERR = 40, + + /** Feature expired */ + HASP_FEATURE_EXPIRED = 41, + + /** Sentinel License Manager version too old */ + HASP_OLD_LM = 42, + + /** Input/Output error occurred in secure storage area of Sentinel SL key OR + * a USB error occurred when communicating with a Sentinel HL key */ + HASP_DEVICE_ERR = 43, + + /** Update installation not permitted; This update was already applied */ + HASP_UPDATE_BLOCKED = 44, + + /** System time has been tampered with */ + HASP_TIME_ERR = 45, + + /** Communication error occurred in secure channel */ + HASP_SCHAN_ERR = 46, + + /** Corrupt data exists in secure storage area of Sentinel SL protection key */ + HASP_STORAGE_CORRUPT = 47, + + /** Unable to find Vendor library */ + HASP_NO_VLIB = 48, + + /** Unable to load Vendor library */ + HASP_INV_VLIB = 49, + + /** Unable to locate any Feature matching scope */ + HASP_SCOPE_RESULTS_EMPTY = 50, + + /** Program running on a virtual machine */ + HASP_VM_DETECTED = 51, + + /** Sentinel SL key incompatible with machine hardware; Sentinel SL key is locked + * to different hardware. OR: + * In the case of a V2C file, conflict between Sentinel SL key data and machine + * hardware data; Sentinel SL key locked to different hardware */ + HASP_HARDWARE_MODIFIED = 52, + + /** Login denied because of user restrictions */ + HASP_USER_DENIED = 53, + + /** Trying to install a V2C file with an update counter that is out of + * sequence with the update counter on the Sentinel protection key. + * The update counter value in the V2C file is lower than the value in + * Sentinel protection key. */ + HASP_UPDATE_TOO_OLD = 54, + + /** Trying to install a V2C file with an update counter that is out of + * sequence with update counter in the Sentinel protection key. The + * first value in the V2C file is greater than the value in the + * Sentinel protection key. */ + HASP_UPDATE_TOO_NEW = 55, + + /** Vendor library version too old */ + HASP_OLD_VLIB = 56, + + /** Upload via ACC failed, e.g. because of illegal format */ + HASP_UPLOAD_ERROR = 57, + + /** Invalid XML "recipient" parameter */ + HASP_INV_RECIPIENT = 58, + + /** Invalid XML "action" parameter */ + HASP_INV_ACTION = 59, + + /* Deprecated - use HASP_INV_ACTION */ + HASP_INV_DETACH_ACTION = 59, + + /** Scope does not specify a unique Product */ + HASP_TOO_MANY_PRODUCTS = 60, + + /** Invalid Product information */ + HASP_INV_PRODUCT = 61, + + /** Unknown Recipient; update can only be applied to the + * Recipient specified in hasp_detach(), and not to this computer */ + HASP_UNKNOWN_RECIPIENT = 62, + + /** Invalid duration */ + HASP_INV_DURATION = 63, + + /** Cloned secure storage area detected */ + HASP_CLONE_DETECTED = 64, + + /** Specified V2C update already installed in the LLM */ + HASP_UPDATE_ALREADY_ADDED = 65, + + /** Specified Hasp Id is in Inactive state */ + HASP_HASP_INACTIVE = 66, + + /** No detachable feature exists */ + HASP_NO_DETACHABLE_FEATURE = 67, + + /** No detachable feature exists (typo kept for compatibility */ + HASP_NO_DEATCHABLE_FEATURE = 67, + + /** Scope does not specify a unique host */ + HASP_TOO_MANY_HOSTS = 68, + + /** Rehost is not allowed for any license */ + HASP_REHOST_NOT_ALLOWED = 69, + + /** License is rehosted to other machine */ + HASP_LICENSE_REHOSTED = 70, + + /** Old rehost license try to apply */ + HASP_REHOST_ALREADY_APPLIED = 71, + + /** File not found or access denied */ + HASP_CANNOT_READ_FILE = 72, + + /** Extension of license not allowed as number of detached + * licenses is greater than current concurrency count */ + HASP_EXTENSION_NOT_ALLOWED = 73, + + /** Detach of license not allowed as product + * contains VM disabled feature and host machine is a virtual machine */ + HASP_DETACH_DISABLED = 74, + + /** Rehost of license not allowed as container + * contains VM disabled feature and host machine is a virtual machine */ + HASP_REHOST_DISABLED = 75, + + /** Format SL-AdminMode or migrate SL-Legacy to SL-AdminMode not allowed + * as container has detached license */ + HASP_DETACHED_LICENSE_FOUND = 76, + + /** Recipient of the requested operation is older than expected */ + HASP_RECIPIENT_OLD_LM = 77, + + /** Secure storage ID mismatch */ + HASP_SECURE_STORE_ID_MISMATCH = 78, + + /** Duplicate Hostname found while key contains Hostname Fingerprinting */ + HASP_DUPLICATE_HOSTNAME = 79, + + /** The Sentinel License Manager is required for this operation */ + HASP_MISSING_LM = 80, + + /** Attempting to consume multiple executions during log in to a Feature. + * However, the license for the Feature does not contain enough remaining executions */ + HASP_FEATURE_INSUFFICIENT_EXECUTION_COUNT = 81, + + /** Attempting to perform an operation not compatible with target platform */ + HASP_INCOMPATIBLE_PLATFORM = 82, + + /** The key is disabled due to suspected tampering */ + HASP_HASP_DISABLED = 83, + + /** The key is inaccessible due to sharing */ + HASP_SHARING_VIOLATION = 84, + + /** The session was killed due a network malfunction or manually from ACC */ + HASP_KILLED_SESSION = 85, + + /** Program running on a virtual storage */ + HASP_VS_DETECTED = 86, + + /** An identity is required */ + HASP_IDENTITY_REQUIRED = 87, + + /** The identity is not authenticated */ + HASP_IDENTITY_UNAUTHENTICATED = 88, + + /** The identity is disabled */ + HASP_IDENTITY_DISABLED = 89, + + /** The identity doesn't have enough permission for the operation */ + HASP_IDENTITY_DENIED = 90, + + /** A session for this identity from a different machine already exists */ + HASP_IDENTITY_SHARING_VIOLATION = 91, + + /** The maximum number of machines usable by the identity was reached */ + HASP_IDENTITY_TOO_MANY_MACHINES = 92, + + /** The server is not ready to authenticate */ + HASP_IDENTITY_SERVER_NOT_READY = 93, + + /** API dispatcher: API for this Vendor Code was not found */ + HASP_NO_API_DYLIB = 400, + + /** API dispatcher: Unable to load API; DLL possibly corrupt? */ + HASP_INV_API_DYLIB = 401, + + /** Invalid function parameter */ + HASP_INVALID_PARAMETER = 501, + + /** C++ API: Object incorrectly initialized */ + HASP_INVALID_OBJECT = 500, + + /** C++ API: Logging in twice to the same object */ + HASP_ALREADY_LOGGED_IN = 502, + + /** C++ API: Logging out twice of the same object */ + HASP_ALREADY_LOGGED_OUT = 503, + + /** .NET API: Incorrect use of system or platform */ + HASP_OPERATION_FAILED = 525, + + /* Internal use: no classic memory extension block available */ + HASP_NO_EXTBLOCK = 600, + + /* Internal use: invalid port type */ + HASP_INV_PORT_TYPE = 650, + + /* Internal use: invalid port value */ + HASP_INV_PORT = 651, + + /* Dot-Net DLL found broken */ + HASP_NET_DLL_BROKEN = 652, + + /** Requested function not implemented */ + HASP_NOT_IMPL = 698, + + /** Internal error occurred in API */ + HASP_INT_ERR = 699, + + /* Reserved for Sentinel helper libraries */ + HASP_FIRST_HELPER = 2001, + + /* Reserved for Sentinel Activation API */ + HASP_FIRST_HASP_ACT = 3001, + + HASP_NEXT_FREE_VALUES = 7001, + }; + + /** + * @} + */ + + /** + * @defgroup hasp_general Sentinel typedefs and macros + * + * @{ + */ + + /** A Sentinel status code */ + typedef enum hasp_error_codes hasp_status_t; + + /** Sentinel size type */ + typedef hasp_u32_t hasp_size_t; + + /** Sentinel connection handle */ + typedef hasp_u32_t hasp_handle_t; + + /** Sentinel Feature ID */ + typedef hasp_u32_t hasp_feature_t; + + /** Sentinel File ID */ + typedef hasp_u32_t hasp_fileid_t; + + /** Sentinel timestamp, representing elapsed seconds since + * Jan-01-1970 0:00:00 GMT */ + typedef hasp_u64_t hasp_time_t; + + /** Sentinel Vendor Code buffer */ + typedef const void *hasp_vendor_code_t; + +/** format to retrieve update info (C2V) */ +#define HASP_UPDATEINFO "" + +/* format to retrieve a small update info (C2V) */ +#define HASP_FASTUPDATEINFO "" + +/** format to retrieve session info */ +#define HASP_SESSIONINFO "" + +/** format to retrieve key/hardware info */ +#define HASP_KEYINFO "" + +/** format to retrieve host fingerprint info */ +#define HASP_FINGERPRINT "" + +/** format to retrieve recipient parameter for hasp_transfer */ +#define HASP_RECIPIENT "" \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + "" + +/* + * Invalid handle value for hasp_login() and hasp_login_scope() functions. + */ +#define HASP_INVALID_HANDLE_VALUE 0 + +/** + * \brief Minimum block size for hasp_encrypt() and hasp_decrypt() functions. + */ +#define HASP_MIN_BLOCK_SIZE 16 + +/** + * \brief Minimum block size for hasp_legacy_encrypt() + * and hasp_legacy_decrypt() legacy functions. + */ +#define HASP_MIN_BLOCK_SIZE_LEGACY 8 + + /** + * @} + */ + + /** + * @defgroup hasp_basic The Basic Sentinel Licensing API + * + * @{ + */ + + /** + * \brief Logs into a Feature and thereby establishes a session context. + * + * Sentinel Licensing API Usage Notes
+ * This function establishes a context to a Sentinel protection key + * containing a license for the requested Feature ID. + * + * The requisite Vendor Codes are stored in a VendorCodes folder in your + * system. Without the correct Vendor Code, the function call cannot succeed. + * + * You can open up to 512 simultaneous login sessions. + * + * Legacy HASP Remarks
+ * For local prognum Features, concurrency is not handled and each login + * performs a decrement if it is a counting license. + * + * Network "prognum" features continue to use the old HASP/Sentinel LM login logic, + * with its inherent limitations. + * + * There is only support for concurrent usage of one server (global + * server address). + * + * With "Program Number" features (see \ref HASP_FEATURETYPE_MASK), 8 + * bits are reserved for legacy options (see \ref HASP_PROGNUM_OPT_MASK, + * currently 5 bits are used): + *
    + *
  • only local
  • + *
  • only remote
  • + *
  • login is counted per process ID
  • + *
  • disable terminal server check
  • + *
  • enable access to old (HASP3/HASP4) keys
  • + *
+ * + * \param feature_id Unique identifier for a specific Feature stored + * in a Sentinel protection key + * \param vendor_code Pointer to the Vendor Code + * \param handle Pointer to the resulting session handle + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_HASP_NOT_FOUND
  • Required Sentinel + * protection key not found + *
  • HASP_FEATURE_NOT_FOUND
  • Cannot find requested + * Feature + *
  • HASP_FEATURE_TYPE_NOT_IMPL
  • Requested Feature + * type not available + *
  • HASP_TMOF
  • Too many open login sessions + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_INV_VCODE
  • Invalid Vendor Code + *
  • HASP_NO_DRIVER
  • Driver not installed + *
  • HASP_NO_VLIB
  • Vendor library cannot be found + *
  • HASP_INV_VLIB
  • Vendor library cannot be loaded + *
  • HASP_OLD_DRIVER
  • Driver too old + *
  • HASP_UNKNOWN_VCODE
  • Vendor Code not recognized + *
  • HASP_FEATURE_EXPIRED
  • Feature has expired + *
  • HASP_TOO_MANY_USERS
  • Too many users currently + * connected + *
  • HASP_OLD_LM
  • Sentinel License Manager version + * too old + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_TIME_ERR
  • System time has been tampered + * with + *
  • HASP_HARDWARE_MODIFIED
  • Sentinel SL key + * incompatible with machine hardware; Sentinel SL key is + * locked to different hardware + *
  • HASP_TS_DETECTED
  • Program is running on a + * Terminal Server + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
  • HASP_OLD_VLIB
  • Vendor Library version too old + *
  • HASP_CLONE_DETECTED
  • Cloned Sentinel SL storage + * detected. Feature unavailable + *
+ * + * \sa hasp_login_scope() + * \sa hasp_logout() + * + */ + hasp_status_t HASP_CALLCONV hasp_login(hasp_feature_t feature_id, + hasp_vendor_code_t vendor_code, + hasp_handle_t *handle); + + /** + * \brief Logs into a Feature to establish a session, according to + * predefined search parameters. + * + * Sentinel Licensing API Usage Notes
+ * This function is used to specify conditions that describe where login + * information is to searched for. + * + * The requisite Vendor Codes are stored in a VendorCodes folder in your + * system. Without the correct Vendor Code, the function call cannot succeed. + * + * You can open up to 512 simultaneous login sessions. + * + * This function does not work with legacy HASP Features. + * + * \param feature_id Unique identifier for a specific Feature stored in + * a Sentinel protection key + * \param scope Definition of the search parameters for + * this Feature ID. See the additional Sentinel API + * Reference documentation for more information + * about Scope XML Tags + * \param vendor_code Pointer to the vendor code + * \param handle Pointer to the resulting session handle + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_HASP_NOT_FOUND
  • Required Sentinel + * protection key not found + *
  • HASP_FEATURE_NOT_FOUND
  • Cannot find requested + * Feature + *
  • HASP_SCOPE_RESULTS_EMPTY
  • Unable to locate + * a Feature matching the scope + *
  • HASP_TMOF
  • Too many open login sessions + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_INV_VCODE
  • Invalid Vendor Code + *
  • HASP_NO_DRIVER
  • Driver not installed + *
  • HASP_NO_VLIB
  • Vendor library cannot be found + *
  • HASP_INV_VLIB
  • Vendor library cannot be loaded + *
  • HASP_OLD_DRIVER
  • Driver too old + *
  • HASP_UNKNOWN_VCODE
  • Vendor Code not recognized + *
  • HASP_INVALID_PARAMETER
  • Scope string too + * long (max. length 32 kb) + *
  • HASP_FEATURE_EXPIRED
  • Feature has expired + *
  • HASP_TOO_MANY_USERS
  • Too many users currently + * connected + *
  • HASP_OLD_LM
  • Sentinel License Manager version + * too old + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_TIME_ERR
  • System time has been tampered + * with + *
  • HASP_TS_DETECTED
  • Program is running on a + * Terminal Server + *
  • HASP_HARDWARE_MODIFIED
  • Sentinel SL key + * incompatible with machine hardware; Sentinel SL key is + * locked to different hardware + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
  • HASP_OLD_VLIB
  • Vendor Library version too old + *
  • HASP_CLONE_DETECTED
  • Cloned Sentinel SL storage + * detected. Feature unavailable + *
+ * + * \sa hasp_login() + * \sa hasp_logout() + * \sa hasp_get_info() + * + */ + hasp_status_t HASP_CALLCONV hasp_login_scope(hasp_feature_t feature_id, + const char *scope, + hasp_vendor_code_t vendor_code, + hasp_handle_t *handle); + + /** + * \brief Logs out from a context or session. + * + * Sentinel Licensing API Usage Notes
+ * Use this function to end a connection to an API session object. Once + * logged out from a session, all memory allocated for the session is released. + * + * \param handle Handle for the session being terminated + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \sa hasp_login() + * \sa hasp_login_scope() + * + */ + hasp_status_t HASP_CALLCONV hasp_logout(hasp_handle_t handle); + + /** + * \brief Encrypts a buffer. + * + * Sentinel Licensing API Usage Notes
+ * Encrypts data using the encryption engine in the Sentinel protection key. + * The specific session handle determines which Sentinel protection key and + * which Feature ID encrypts the data buffer. The encryption key remains + * in the Sentinel protection key. If the encryption fails, the buffer + * is not modified. To decrypt the data buffer, use the \ref hasp_decrypt + * function. + * + * \param handle Handle for the session + * \param buffer Pointer to the buffer to be encrypted + * \param length Size (in bytes) of the buffer to be encrypted + * (16 bytes minimum) + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL secure storage, OR in case of a Sentinel HL key, + * USB communication error + *
  • HASP_TIME_ERR
  • System time has been tampered + * with + *
  • HASP_TOO_SHORT
  • Encryption data length is + * too short + *
  • HASP_ENC_NOT_SUPP
  • Sentinel protection key + * does not support encryption type + *
  • HASP_SCHAN_ERR
  • Communication error occurred + * in secure channel OR Sentinel HL Firmware too old + * (update to 3.25 or later) + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \sa hasp_decrypt() + * + */ + hasp_status_t HASP_CALLCONV hasp_encrypt(hasp_handle_t handle, + void *buffer, + hasp_size_t length); + + /** + * \brief Decrypts a buffer. + * + * Sentinel Licensing API Usage Notes
+ * Decrypts data using the decryption engine in the Sentinel protection key + * The specific session handle determines which Sentinel protection key and + * which Feature ID decrypts the data buffer. The decryption key remains + * in the Sentinel protection key. If the decryption fails, the buffer + * is not modified. To encrypt the data buffer, use the \ref hasp_encrypt + * function. + * + * \param handle Handle for the session + * \param buffer Pointer to the buffer to be decrypted + * \param length Size (in bytes) of the buffer to be decrypted + * (16 bytes minimum) + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_TIME_ERR
  • System time has been tampered + * with + *
  • HASP_TOO_SHORT
  • Decryption data length is + * too short + *
  • HASP_SCHAN_ERR
  • Communication error occurred + * in secure channel OR Sentinel HL Firmware too old + * (update to 3.25 or later) + *
  • HASP_ENC_NOT_SUPP
  • Sentinel protection key + * does not support encryption type + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \sa hasp_encrypt() + * + */ + hasp_status_t HASP_CALLCONV hasp_decrypt(hasp_handle_t handle, + void *buffer, + hasp_size_t length); + + /** + * \brief Reads the memory of a Sentinel protection key. + * + * Sentinel Licensing API Usage Notes
+ * Valid File IDs are \ref HASP_FILEID_RW and \ref HASP_FILEID_RO. + * From Sentinel LDK 7.1, Sentinel HL Driverless keys support dynamic memory, + * the File IDs can be from HASP_FILEID_DYNAMIC_FIRST(0x1) to HASP_FILEID_DYNAMIC_LAST(0xFFBF). + * + * Legacy HASP Remarks
+ * Valid File IDs are \ref HASP_FILEID_LICENSE and \ref HASP_FILEID_MAIN. + * + * \param handle Handle for the session + * \param fileid Identifier for the file that is to be read + * \param offset Byte offset in the file + * \param length Number of bytes to be read from the file + * \param buffer Pointer to the retrieved data + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_INV_FILEID
  • Unrecognized file identifier + *
  • HASP_MEM_RANGE
  • Request exceeds the memory + * range of a Sentinel file + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_SCHAN_ERR
  • Communication error occurred + * in secure channel OR Sentinel HL Firmware too old + * (update to 3.25 or later) + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \remark + * Use the \ref hasp_get_size function to determine the size of the file you + * want to read. + * + * \sa hasp_write() + * \sa hasp_get_size() + * + */ + hasp_status_t HASP_CALLCONV hasp_read(hasp_handle_t handle, + hasp_fileid_t fileid, + hasp_size_t offset, + hasp_size_t length, + void *buffer); + + /** + * \brief Writes to the memory of a Sentinel protection key. + * + * Sentinel Licensing API Usage Notes
+ * Valid File ID is \ref HASP_FILEID_RW. + * From Sentinel LDK 7.1, Sentinel HL Driverless keys support dynamic memory, + * the File IDs can be from HASP_FILEID_DYNAMIC_FIRST(0x1) to HASP_FILEID_DYNAMIC_LAST(0xFFBF). + * + * Legacy HASP Remarks
+ * Depending on the provided session handle (either logged into the + * default Feature or any other Feature), write access to the FAS memory + * (\ref HASP_FILEID_LICENSE) is not permitted. + * + * \param handle Handle for the session + * \param fileid Identifier for the file that is to be written + * \param offset Byte offset in the file + * \param length Number of bytes to be written to the file + * \param buffer Pointer to the data + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_INV_FILEID
  • Unrecognized file identifier + *
  • HASP_MEM_RANGE
  • Request exceeds the memory + * range of a Sentinel file + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_SCHAN_ERR
  • Communication error occurred + * in secure channel OR Sentinel HL Firmware too old + * (update to 3.25 or later) + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \remark + * Use the \ref hasp_get_size function to determine the size of the file you + * want to write. + * + * \sa hasp_read() + * \sa hasp_get_size() + * + */ + hasp_status_t HASP_CALLCONV hasp_write(hasp_handle_t handle, + hasp_fileid_t fileid, + hasp_size_t offset, + hasp_size_t length, + const void *buffer); + + /** + * \brief Retrieves the byte size of a memory file from a Sentinel protection key. + * + * This function is used to determine the file size of a Sentinel + * memory file. + * + * Sentinel Licensing API Usage Notes
+ * From Sentinel LDK 7.1, Sentinel HL Driverless keys support dynamic memory, + * the file IDs can be from HASP_FILEID_DYNAMIC_FIRST(0x1) to HASP_FILEID_DYNAMIC_LAST(0xFFBF). + * + * \param handle Handle for the session + * \param fileid Identifier for the file that is to be queried. + * \param size Pointer to the resulting file size + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_INV_FILEID
  • Unrecognized file identifier + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \sa hasp_read() + * \sa hasp_write() + * + */ + hasp_status_t HASP_CALLCONV hasp_get_size(hasp_handle_t handle, + hasp_fileid_t fileid, + hasp_size_t *size); + + /** + * \brief Reads the current time. + * + * Sentinel Licensing API Usage Notes
+ * Only Sentinel HL keys with a Real-time clock (rtc) and Sentinel SL keys can + * provide the current time. + * + * Primarily used to obtain reliable timestamps that are independent from + * the system clock. + * + * Time values are returned as the number of seconds that have elapsed + * since Jan-01-1970 0:00:00 UTC. + * + * Legacy HASP Remarks
+ * This request is only supported on locally accessed keys. Trying to + * get the time from a remotely accessed key will return HASP_NO_TIME. + * + * \param handle Handle for the session + * \param time Pointer to the current time + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
  • HASP_NO_BATTERY_POWER
  • Real-time clock has + * run out of power + *
  • HASP_NO_TIME
  • Real-time clock is not + * available + *
+ * + * \sa hasp_datetime_to_hasptime() + * \sa hasp_hasptime_to_datetime() + * + */ + hasp_status_t HASP_CALLCONV hasp_get_rtc(hasp_handle_t handle, + hasp_time_t *time); + + /** + * @} + */ + + /** + * @defgroup hasp_classic Legacy HASP functionality for backward compatibility + * + * @{ + */ + + /** + * \brief Legacy HASP4 compatible encryption function. + * + * Sentinel Licensing API Usage Notes
+ * This function does not work with a Sentinel login handle. + * + * Legacy HASP Remarks
+ * The handle must have been obtained by calling \ref hasp_login() with + * a "prognum" Feature ID. + * + * \param handle Handle for the session + * \param buffer Pointer to the buffer to be encrypted + * \param length Size in bytes of the buffer (min. 8 bytes) + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_TOO_SHORT
  • Encryption data length is + * too short + *
  • HASP_ENC_NOT_SUPP
  • Sentinel protection key + * does not support encryption type + *
  • HASP_HASP_NOT_FOUND
  • Required Sentinel + * protection key not found + *
+ * + * \sa hasp_legacy_decrypt() + * \sa hasp_encrypt() + * \sa hasp_decrypt() + * + */ + hasp_status_t HASP_CALLCONV hasp_legacy_encrypt(hasp_handle_t handle, + void *buffer, + hasp_size_t length); + + /** + * \brief Legacy HASP4 compatible decryption function. + * + * Sentinel Licensing API Usage Notes
+ * This function does not work with a Sentinel login handle. + * + * Legacy HASP Remarks
+ * The handle must have been obtained by calling \ref hasp_login() with + * a "prognum" Feature ID. + * + * \param handle Handle for the session + * \param buffer Pointer to the buffer to be decrypted + * \param length Size in bytes of the buffer (min. 8 bytes) + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_TOO_SHORT
  • Encryption data length is + * too short + *
  • HASP_ENC_NOT_SUPP
  • Sentinel protection key + * does not support encryption type + *
  • HASP_HASP_NOT_FOUND
  • Required Sentinel + * protection key not found + *
+ * + * \sa hasp_legacy_encrypt() + * \sa hasp_decrypt() + * \sa hasp_encrypt() + * + */ + hasp_status_t HASP_CALLCONV hasp_legacy_decrypt(hasp_handle_t handle, + void *buffer, + hasp_size_t length); + + /** + * \brief Writes to HASP4-compatible real-time clock + * + * Sentinel Licensing API Usage Notes
+ * This function does not work with a Sentinel login handle. + * + * Legacy HASP Remarks
+ * The handle must have been obtained by calling \ref hasp_login() with + * a "prognum" Feature ID. + * + * This request is only supported on locally accessed keys. Attempting to + * set the time on a remotely accessed key will return HASP_NO_TIME. + * + * \param handle Handle for the session + * \param new_time The new time value + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_HASP_NOT_FOUND
  • Required Sentinel + * protection key not found + *
  • HASP_NO_TIME
  • Real-time clock not available + * OR access remote + *
+ * + * \sa hasp_get_rtc() + * \sa hasp_datetime_to_hasptime() + * \sa hasp_hasptime_to_datetime() + * + */ + hasp_status_t HASP_CALLCONV hasp_legacy_set_rtc(hasp_handle_t handle, + hasp_time_t new_time); + + /** + * \brief Set the LM idle time. + * + * Sentinel Licensing API Usage Notes
+ * This function does not work with a Sentinel login handle. + * + * Legacy HASP Remarks
+ * The handle must have been obtained by calling \ref hasp_login() with + * a "prognum" Feature ID. + * + * \param handle Handle for the session + * \param idle_time The idle time in minutes + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_HASP_NOT_FOUND
  • Required Sentinel + * protection key not found + *
  • HASP_REQ_NOT_SUPP
  • Tried to set the idle time + * for a local license + *
+ * + */ + hasp_status_t HASP_CALLCONV hasp_legacy_set_idletime(hasp_handle_t handle, + hasp_u16_t idle_time); + + /** + * @} + */ + + /** + * @defgroup hasp_extended Extended Sentinel Licensing API functionality + * + * The extended API consists of functions that provide extended + * functionality. This advanced functionality is sometimes necessary, + * and addresses the "advanced" user. + * + * @{ + */ + + /** + * \brief Retrieves information about system components, according to + * customizable search parameters, and presents it according to + * customizable formats. + * + * Sentinel Licensing API Usage Notes
+ * You do not need to be logged in to a Sentinel Feature in order to use + * this function. + * + * This function is used to specify conditions about where to search for + * information. In addition, it enables you to specify conditions about + * the format in which the retrieved information is presented. If + * retrieved information is appropriately formatted, it can be used as + * a template in the hasp_login_scope() function. + * + * The requisite Vendor Codes are stored in a VendorCodes folder in + * your system. Without the correct Vendor Code, the function call + * cannot succeed. + * + * This function allocates memory for the information it retrieves. To + * release allocated memory resources, use the \ref hasp_free function. + * + * This function cannot be used to retrieve legacy HASP Features. + * + * \param scope Definition of the data that is to be searched, in XML + * format. For more information, see the accompanying + * Sentinel Licensing API help documentation + * \param format Definition of the format in which the data is to be + * displayed, in XML format. For more information, see the + * accompanying Sentinel Licensing API help + * documentation + * \param vendor_code Pointer to the Vendor Code + * \param info Pointer to the information that is retrieved, in XML + * format + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_SCOPE_RESULTS_EMPTY
  • Unable to locate + * a Feature matching the scope + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_INV_VCODE
  • Invalid Vendor Code + *
  • HASP_UNKNOWN_VCODE
  • Vendor Code not recognized + *
  • HASP_INVALID_PARAMETER
  • Scope or format string + * too long (max. length 32 kb) + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
  • HASP_INV_FORMAT
  • Unrecognized format string + *
  • HASP_INV_SCOPE
  • Unrecognized scope string + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_TOO_MANY_KEYS
  • In case of getting C2V: + * Too many Sentinel protection keys match the scope + *
  • HASP_TOO_MANY_HOSTS
  • In case of getting host + * fingerrpint: Too many Sentinel License Manager + * match the scope + *
  • HASP_HASP_INACTIVE
  • In case of getting C2V: + * Inactive Sentinel SL-AdminMode/SL-UserMode key-id + *
+ * + * \sa hasp_get_sessioninfo() + * \sa hasp_free() + * + */ + hasp_status_t HASP_CALLCONV hasp_get_info(const char *scope, + const char *format, + hasp_vendor_code_t vendor_code, + char **info); + + /** + * \brief Retrieves information regarding a session context. + * + * Memory for the information is allocated by this function and has to + * be freed with the \ref hasp_free function. + * + * \param handle Handle for the session + * \param format Definition for the type of output data structure, in + * XML format. + * There are three format options: + *
    + *
  • HASP_KEYINFO
  • For retrieving information on + * the Sentinel protection key + *
  • HASP_SESSIONINFO
  • For retrieving information on + * the login session + *
  • HASP_UPDATEINFO
  • For retrieving information on + * a license update usually contained in a C2V file. + * The retrieved information includes the current + * state of the key, including update counters, + * license availability and memory images + *
+ * \param info Pointer to the information that is retrieved as XML text + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL secure storage, OR in case of a Sentinel HL key, + * USB communication error + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
  • HASP_INV_FORMAT
  • Unrecognized format string + *
  • HASP_INV_HND
  • Invalid input handle + *
  • HASP_BROKEN_SESSION
  • Session has been + * interrupted + *
  • HASP_TIME_ERR
  • System time has been tampered + * with + *
+ * + * \sa hasp_free() + * \sa HASP_UPDATEINFO + * \sa HASP_SESSIONINFO + * \sa HASP_KEYINFO + */ + hasp_status_t HASP_CALLCONV hasp_get_sessioninfo(hasp_handle_t handle, + const char *format, + char **info); + + /** + * \brief Frees memory resources utilized by other API functions. + * + * Used only in C code to release memory resources allocated to storing + * retrieved data from API calls. + * + * \param info Pointer to the memory resources to be released + * + * \sa hasp_get_info() + * \sa hasp_get_sessioninfo() + * \sa hasp_update() + * + */ + void HASP_CALLCONV hasp_free(char *info); + + /** + * \brief Updates a Sentinel protection key. + * + * This function writes update information. Note that the Sentinel + * protection key must be locally connected. + * + * The update code contains all necessary data to perform the update on + * a deployed Sentinel protection key including: + *
    + *
  • The Sentinel protection key on which the updated information is + * to be written
  • + *
  • The necessary Vendor Code that is required to access the + * Sentinel key
  • + *
  • The actual update information
  • + *
+ * + * Depending on the update data, the function returns an acknowledgement + * code that is signed/encrypted by the key. The code is evidence that + * an update has been applied to a license. This function allocates memory + * for the acknowledge data. To release allocated memory resources, use + * \a hasp_free(). + * + * \param update_data Pointer to the complete update data. + * \param ack_data Pointer to a buffer to retrieve the acknowledge data. + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_KEYID_NOT_FOUND
  • The Sentinel protection + * key was not found + *
  • HASP_INV_UPDATE_DATA
  • Required XML tags + * not found; Contents in binary data are missing + * or invalid + *
  • HASP_INV_UPDATE_NOTSUPP
  • Update request is + * not supported by Sentinel protection key + *
  • HASP_INV_UPDATE_CNTR
  • Update counter not + * set correctly + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL secure storage, OR in case of a Sentinel HL key, + * USB communication error + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
  • HASP_NO_ACK_SPACE
  • Acknowledge data + * requested by the update, but ack_data parameter + * is NULL + *
  • HASP_UNKNOWN_ALG
  • Unknown algorithm used + * in V2C file + *
  • HASP_INV_SIG
  • Signature verification failed + *
  • HASP_TOO_MANY_KEYS
  • Too many Sentinel + * protection keys match the scope + *
  • HASP_HARDWARE_MODIFIED
  • Conflict between + * Sentinel SL key data and machine hardware data; + * Sentinel SL key locked to different hardware + *
  • HASP_UPDATE_TOO_OLD
  • Trying to install a + * V2C file with an update counter that is out of + * sequence with the update counter in the Sentinel + * protection key. The values of the update counter + * in the file are lower than those in the Sentinel + * protection key + *
  • HASP_UPDATE_TOO_NEW
  • Trying to install a + * V2C file with an update counter that is out of + * sequence with the update counter in the Sentinel + * protection key. The first value in the file is more + * than 1 greater than the value in the Sentinel + * protection key + *
  • HASP_UNKNOWN_RECIPIENT
  • In case of an H2R: + * Update can only be applied to the Recipient + * specified in hasp_detach(), not to this machine + *
  • HASP_HASP_INACTIVE
  • Inactive Sentinel + * SL-AdminMode/SL-UserMode key-id + *
  • HASP_UPDATE_ALREADY_ADDED
  • Sentinel + * SL-AdminMode/SL-UserMode V2C update(s) already applied + *
  • HASP_REHOST_ALREADY_APPLIED
  • In case of SL-AdminMode + * /SL-UserMode H2H: Specified H2H already applied + *
  • HASP_LICENSE_REHOSTED
  • In case of SL-AdminMode + * /SL-UserMode V2C: Specified V2C already rehosted to another + * host + *
+ * + * \sa hasp_free() + * + */ + hasp_status_t HASP_CALLCONV hasp_update(const char *update_data, + char **ack_data); + +/** + * \brief Detaches or cancels an attached license, according to customizable + * parameters. + * + * Starting from Sentinel LDK version 6.0, the "hasp_detach" API has been deprecated. + * SafeNet recommends that user should use the "hasp_transfer" API to perform + * the detach/cancel actions.This API has been retained for backward compatibility. + * + * Sentinel Licensing API Usage Notes
+ * You do not need to be logged in to a Sentinel Feature in order to use + * this function. + * + * This function is used to detach a license for a Product (i.e. all Sentinel + * Features and Memory files which belong to this Product) from a Sentinel + * SL Protection key. The function returns a H2R file which must then be + * applied on the recipient machine using hasp_update() or the ACC. + * + * This function only works with Sentinel SL Protection Keys; Sentinel HL + * Protection Keys are ignored. + * + * This function can also be used on the recipient machine to cancel an + * attached license. In this case, the recipient parameter is ignored and + * should be set to NULL. For cancelling, the function returns a R2H file + * which must be applied on the host machine using hasp_update() or the + * ACC. If the detached Product is already expired, no R2H file will be + * returned. + * + * The required Vendor Codes are stored in a VendorCodes folder in + * your system. Without the correct Vendor Code, the function call + * cannot succeed. + * + * \param detach_action Parameters for the operation, in XML format. For + * more information, see the accompanying + * Sentinel Licensing API help documentation. + * \param scope Search parameters for the Product that is to be + * detached + * \param vc Pointer to the Vendor Code + * \param recipient Definition in XML format of the recipient computer, + * on which the detached Product will be installed. + * This information can be retrieved using either + * @a hasp_get_info or @a hasp_get_sessioninfo + * together with the format specifier + * @a HASP_RECIPIENT. + * Set to NULL if an attached protection key is cancelled. + * \param info Pointer to the information that is retrieved, in + * XML format. This information is a V2C, which can + * then be installed on the recipient computer + * via @a hasp_update. Use @a hasp_free to release this + * pointer after use. + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_DETACH_ACTION
  • Invalid XML + * "detach_action" parameter + *
  • HASP_INV_RECIPIENT
  • Invalid XML "recipient" + * parameter + *
  • HASP_TOO_MANY_PRODUCTS
  • Scope for hasp_detach + * does not specify a unique Parameter + *
  • HASP_TOO_MANY_USERS
  • Too many users currently + * connected, or: at least one detachable Feature + * does not have enough network seats available + *
  • HASP_ACCESS_DENIED
  • Request cannot be + * processed due to ACC restrictions + *
  • HASP_FEATURE_EXPIRED
  • All detachable + * Features are expired + *
  • HASP_INV_PRODUCT
  • Invalid Product information + *
  • HASP_INV_DURATION
  • In the case of a new + * detachable license, duration exceeds maximum allowed + * OR, in the case of a detachable license extension, + * expiration date earlier than original date + * or too short (if an existing detached Product is + * extended, and the new expiration date is earlier + * than the original expiration date) + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL secure storage, OR in case of a Sentinel HL key, + * USB communication error + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_REMOTE_COMM_ERR
  • Communication error + * between local and remote Sentinel License Manager + *
+ * + * \sa hasp_get_info() + * \sa hasp_update() + * \sa hasp_free() + */ +#if (_MSC_VER >= 1400) + __declspec(deprecated) hasp_status_t HASP_CALLCONV hasp_detach(const char *detach_action, + const char *scope, + hasp_vendor_code_t vc, + const char *recipient, + char **info); +#elif defined(__GNUC__) +hasp_status_t HASP_CALLCONV hasp_detach(const char *detach_action, + const char *scope, + hasp_vendor_code_t vc, + const char *recipient, + char **info) __attribute__((deprecated)); +#else +hasp_status_t HASP_CALLCONV hasp_detach(const char *detach_action, + const char *scope, + hasp_vendor_code_t vc, + const char *recipient, + char **info); +#endif + + /** + * \brief: Deprecate the above API "hasp_detach()" , This API performs + * same functionalities as "hasp_detach()" does. Along with this, + * "hasp_transfer()" API is used to rehost the SL-AdminMode/SL-UserMode + * V2C from one machine to another machine. + * + * Sentinel Licensing API Usage Notes
+ * You do not need to be logged in to a Sentinel Feature in + * order to use this function. + * + * This function is used to perform the following task as per its + * "action" parameter. + * for "detach" action: detach a license for a Product (i.e. all + * Sentinel Features and Memory files which + * belong to this Product) from a Sentinel + * SL/SL-AdminMode/SL-UserMode key. The function + * returns a bufferwhich should be saved as H2R file. + * + * for "cancel" action: This action runs on the recipient machine to + * cancel an attached license. In this case, the + * recipient parameter is ignored and should be + * set to NULL. For cancelling, the function returns + * a buffer which must be applied on the host machine + * using hasp_update() or ACC If the detached Product + * is already expired, no buffer will be returned. + * + * for "rehost" action: create a tranferable a license for given container + * (i.e. all Sentinel Features and Memory files + * which belong to this container) from SL-AdminMode/ + * SL-UserMode Protection key. The function returns + * buffer on success which must be saved as V2C file. + * hasp_update() or ACC is used to apply this on + * destination machine. + * + * This function only works with Sentinel SL/SL-AdminMode/SL-UserMode + * Protection Keys; Sentinel HL Protection Keys are ignored. + * + * The required Vendor Codes are stored in a VendorCodes folder in + * your system. Without the correct Vendor Code, the function call + * cannot succeed. + * + * \param action Parameters for the operation, in XML format. For + * more information, see the accompanying + * Sentinel Licensing API help documentation. + * \param scope Search parameters for the conatiner-id that is to be + * re-hosted. For more information, see the accompanying + * Sentinel Licensing API help documentation. + * \param vc Pointer to the Vendor Code + * \param recipient Definition in XML format of the recipient computer, + * on which the detached Product will be installed. + * This information can be retrieved using either + * @a hasp_get_info or @a hasp_get_sessioninfo + * together with the format specifier + * @a HASP_RECIPIENT. + * \param info Pointer to the information that is retrieved, in + * XML format. This information is a V2C, which can + * then be installed on the destination computer + * via @a hasp_update. Use @a hasp_free to release this + * pointer after use. + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_ACTION
  • Invalid XML + * "action" parameter + *
  • HASP_INV_RECIPIENT
  • Invalid XML "recipient" + * parameter + *
  • HASP_TOO_MANY_PRODUCTS
  • Scope for hasp_transfer + * for detach action does not specify a unique Parameter + *
  • HASP_TOO_MANY_USERS
  • Too many users currently + * connected, or: at least one detachable Feature + * does not have enough network seats available + *
  • HASP_ACCESS_DENIED
  • Request cannot be + * processed due to ACC restrictions + *
  • HASP_FEATURE_EXPIRED
  • All detachable + * Features are expired + *
  • HASP_INV_PRODUCT
  • Invalid Product information + *
  • HASP_INV_DURATION
  • In the case of a new + * detachable license, duration exceeds maximum allowed + * OR, in the case of a detachable license extension, + * expiration date earlier than original date + * or too short (if an existing detached Product is + * extended, and the new expiration date is earlier + * than the original expiration date) + *
  • HASP_TOO_MANY_KEYS
  • Scope for hasp_transfer + * does not specify a unique Parameter + *
  • HASP_ACCESS_DENIED
  • Request cannot be + * processed due to ACC restrictions + *
  • HASP_INSUF_MEM
  • Out of memory + *
  • HASP_DEVICE_ERR
  • Input/Output error in Sentinel + * SL/SL-AdminMode/SL-UserMode secure storage, OR in + * case of a Sentinel HL key, USB communication error + *
  • HASP_LOCAL_COMM_ERR
  • Communication error + * between API and local Sentinel License Manager + *
  • HASP_NO_DEATCHABLE_FEATURE
  • In case of H2R: + * No detachable feature found in specified product + *
  • Sentinel License Manager is + * not supported to SL-AdminMode/ SL-UserMode + *
  • SL-AdminMode/ + * SL-UserMode container is inactive + *
  • Specified + * SL-AdminMode/SL-UserMode container is not + * allowed for rehost + *
+ * + * \sa hasp_get_info() + * \sa hasp_update() + * \sa hasp_free() + */ + hasp_status_t HASP_CALLCONV hasp_transfer(const char *action, + const char *scope, + hasp_vendor_code_t vc, + const char *recipient, + char **info); + + /** + * @} + */ + + /** + * @defgroup hasp_util Utility functions + * + * @{ + */ + + /** + * \brief Retrieves version and build number of the Sentinel library + * + * \param major_version Pointer to retrieve the major version number + * \param minor_version Pointer to retrieve the minor version number + * \param generation_version Pointer to retrieve the generation version number + * \param build_number Pointer to retrieve the build number + * \param vendor_code Pointer to the Vendor Code + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
+ * + * \remark Any pointer other than the vendor_code can be NULL if its + * information is not required. + * + */ + hasp_status_t HASP_CALLCONV hasp_get_version(unsigned int *major_version, + unsigned int *minor_version, + unsigned int *generation_version, + unsigned int *build_number, + hasp_vendor_code_t vendor_code); + + /** + * \brief Converts a date and time value to hasptime (the number of + * elapsed seconds since January 1 1970). + * + * \param day Input for day value (range 1-31) + * \param month Input for month value (range 1-12) + * \param year Input for year value (range 1970+) + * \param hour Input for hour value (range 0-23) + * \param minute Input for minute value (range 0-59) + * \param second Input for second value (range 0-59) + * \param time Pointer to the resulting time value + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_TIME
  • Passed time value is outside + * the supported value range + *
+ * + * \remark Time values are in UTC. + * + * \sa hasp_hasptime_to_datetime() + * + */ + hasp_status_t HASP_CALLCONV hasp_datetime_to_hasptime(unsigned int day, + unsigned int month, + unsigned int year, + unsigned int hour, + unsigned int minute, + unsigned int second, + hasp_time_t *time); + + /** + * \brief Converts a time value (elapsed seconds since January 1 1970) + * into a date and time + * + * \param time The input time value + * \param day Pointer to the day value + * \param month Pointer to the month value + * \param year Pointer to the year value + * \param hour Pointer to the hour value + * \param minute Pointer to the minute value + * \param second Pointer to the second value + * + * \return
    + *
  • HASP_STATUS_OK
  • Request was successfully + * completed + *
  • HASP_INV_TIME
  • Passed time value outside + * of supported value range + *
+ * + * \remark Time values are in UTC. + * + * \sa hasp_datetime_to_hasptime() + * + */ + hasp_status_t HASP_CALLCONV hasp_hasptime_to_datetime(hasp_time_t time, + unsigned int *day, + unsigned int *month, + unsigned int *year, + unsigned int *hour, + unsigned int *minute, + unsigned int *second); + + /** + * @} + */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* __HASP_API_H__ */ diff --git a/platform/include/hasp_vcode.h b/platform/include/hasp_vcode.h new file mode 100644 index 0000000..c0fea62 --- /dev/null +++ b/platform/include/hasp_vcode.h @@ -0,0 +1,5 @@ +/* HASP vendor code for demo keys + * Copyright (C) 2014, SafeNet, Inc. All rights reserved.*/ + +unsigned char vendor_code[] = + "r2LBW6gbZPJWitRjL9om2fSlXP5TohlpU2NaI8Dmmzp/HMZ3RcqUiD6IV4EcdvTyiX2H8n1lfuTUzF/d5egHTVt38iSZ+tHkzyqJ2UOMPcJImshcOH2htvG1YwdjFWmUYg1hRTTr+7fiBhD4luQ53o33zzSEL513IPaF3U/yf2zScJruyyrQP2QOvQ1XhgIl5hF/1rEwjGgzNM8SQGlgqseM+Gh1ODFWlW7Squ8wj0qpxlEJYLVmFNtncLTg5ICpVUMhBnWRLP6cb7bzDLpRGQk3jPOco5pcfnG6SGsZO1GWhAhTti+uHIWQdxDjJj1l6t3LvR0mnZkKy7qcTyTL59/GfNRMyGV/6EYZrHpb0E+hmsbzItQf1aDOBd4mmUGpV+vn8Kg0KDpidGhSM2Xs12TiNcRU/y90UdJ/v6hpuoWsSR7jmh7NxEr3dpuK65SJZKVwtC8oz/yGlfAcFa9u0Uyl3csHglNFROuSnbMCVPquG5Eg1nvSorxAa86gPBvCiJp2ZeAZ95AKm/K994ei4XKpeDdWF1Uwjfv2xMwuPKAPIcAYTJFHdqSG2i98VKTtlPzT/q05ZHMH+mRLYN28VFXMo2xKSYJavUIOxUTy7GJvLTmYX9of3NyOVMHwI7AtoafRf9iVzHrf6fH91QmCADFFq0wqmH0DE4A5kSr9mKUUa0ddZheFgr/sHL003XmPvfeK+JLD9v+fFxhSqZBH7wc7UzjcDeHqngmLogCOe2NsJEZq7IGUT1WQEJpMoonMQY7e8YDU6V1m1zMbV8KEpPLt8q54KBXEP4OpJ7DMmaHNBZEB5EY/zD587iKsJNXm64d0vShQGDaoq0En1Ts36znjfMVqLkZX6jKSDZyF3EmZ3aUULwEG7gqwAH2OUV/3XCo5UUboxAtlxBLWI7TNnjzqQO31ON6ZORuVMECJSSZNkiCvb2TDOU0Bs92Mzel+NDmC0GhcGWzs7DAyznJA3Q=="; diff --git a/platform/src/hasp_demo.c b/platform/src/hasp_demo.c new file mode 100644 index 0000000..c04153f --- /dev/null +++ b/platform/src/hasp_demo.c @@ -0,0 +1,846 @@ +/**************************************************************************** +* +* Demo program for Sentinel LDK licensing services +* +* +* Copyright (C) 2014, SafeNet, Inc. All rights reserved. +* +* +* Sentinel LDK DEMOMA key with features 1 and 42 required +* +****************************************************************************/ + +#include +#include +#include + +#include "hasp_api.h" +#include "hasp_vcode.h" /* contains HASP DEMOMA vendor code */ + +#define CUSTOM_FEATURE 42 + +unsigned char data[] = + { + 0x74, 0x65, 0x73, 0x74, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6E, 0x67, 0x20, 0x31, 0x32, 0x33, 0x34}; + +hasp_size_t datalen = sizeof(data); + +#define DEMO_MEMBUFFER_SIZE 128 + +unsigned char membuffer[DEMO_MEMBUFFER_SIZE]; + +/**************************************************************************** + * helper function: dumps a given block of data, in hex + */ + +#define DUMP_COLS_PER_ROW 16 +#define DUMP_SPACE_COLS 8 + +void dump_hex(unsigned char *data, unsigned int datalen, char *margin) +{ + unsigned int i; + + for (i = 0; i < datalen; i++) + { + if (((i % DUMP_SPACE_COLS) == 0) && (i != 0)) + printf(" "); + + if ((i % DUMP_COLS_PER_ROW) == 0) + { + if (i != 0) + printf("\n"); + + if (margin != NULL) + printf("%s", margin); + } + + /* dump character in hex */ + printf("%02X ", data[i]); + } +} /* dump_hex */ + +/**************************************************************************** + * helper function: dumps a given block of data, in ascii + */ + +void dump_ascii(unsigned char *data, unsigned int datalen, char *margin) +{ + unsigned int i; + + for (i = 0; i < datalen; i++) + { + if (((i % DUMP_SPACE_COLS) == 0) && (i != 0)) + printf(" "); + + if ((i % DUMP_COLS_PER_ROW) == 0) + { + if (i != 0) + printf("\n"); + + if (margin != NULL) + printf("%s", margin); + } + + /* dump printable character in ascii */ + printf("%c", ((data[i] > 31) && (data[i] < 128)) ? data[i] : '.'); + } +} /* dump_ascii */ + +/**************************************************************************** + * helper function: dumps a given block of data, in hex and ascii + */ + +void dump(unsigned char *data, unsigned int datalen, char *margin) +{ + unsigned int i, icols; + + for (i = 0; i < datalen;) + { + icols = datalen - i; + + if (icols > DUMP_COLS_PER_ROW) + icols = DUMP_COLS_PER_ROW; + + dump_hex(&data[i], icols, margin); + dump_ascii(&data[i], icols, " "); + printf("\n"); + + i += icols; + } +} /* dump */ + +/***************************************************************************/ + +void wait4key(char *hint) +{ + fflush(stdout); + fflush(stdin); + printf("\npress ENTER %s\n", hint); + while (getchar() == EOF) + ; +} + +/***************************************************************************/ + +hasp_status_t encrypt_decrypt(hasp_handle_t handle) +{ + hasp_status_t status; + + /* + * hasp_encrypt + * encrypts a block of data using the HASP key + * (minimum buffer size is 16 bytes) + */ + + printf("\nencrypting a data buffer:\n"); + dump(data, datalen, " "); + + status = hasp_encrypt(handle, data, datalen); + switch (status) + { + case HASP_STATUS_OK: + printf("encryption ok:\n"); + dump(data, datalen, " "); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_TOO_SHORT: + printf("data length too short\n"); + break; + + case HASP_ENC_NOT_SUPP: + printf("attached key does not support AES encryption\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("encryption failed\n"); + } + if (status) + return status; + + /* + * hasp_decrypt + * decrypts a block of data using the HASP key + * (minimum buffer size is 16 bytes) + */ + + status = hasp_decrypt(handle, data, datalen); + + switch (status) + { + case HASP_STATUS_OK: + printf("decryption ok:\n"); + dump(data, datalen, " "); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_TOO_SHORT: + printf("data length too short\n"); + break; + + case HASP_ENC_NOT_SUPP: + printf("attached key does not support AES encryption\n"); + break; + + default: + printf("decryption failed\n"); + } + if (status) + return status; + + return HASP_STATUS_OK; +} /* encrypt_decrypt */ + +/***************************************************************************/ + +int main(void) +{ + hasp_status_t status; + hasp_handle_t handle, handle2; + hasp_time_t time; + unsigned int day, month, year, hour, minute, second; + const char *scope; + const char *view; + char *info; + hasp_size_t fsize; + unsigned int i; + + printf("A simple demo program for the Sentinel LDK licensing functions\n"); + printf("Copyright (C) SafeNet, Inc. All rights reserved.\n\n"); + + /************************************************************************ + * hasp_login + * establishes a context for HASP services + */ + + printf("login to default feature : "); + + /* login to default feature (0) */ + /* this default feature is available on any key */ + /* search for local and remote HASP key */ + + status = hasp_login(HASP_DEFAULT_FID, + (hasp_vendor_code_t)vendor_code, + &handle); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_FEATURE_NOT_FOUND: + printf("login to default feature failed\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("no sentinel key with vendor code DEMOMA found\n"); + break; + + case HASP_OLD_DRIVER: + printf("outdated driver version installed\n"); + break; + + case HASP_NO_DRIVER: + printf("sentinel driver not installed\n"); + break; + + case HASP_INV_VCODE: + printf("invalid vendor code\n"); + break; + + default: + printf("login to default feature failed with status %d\n", status); + } + if (status) + { + exit(-1); + } + + /************************************************************************ + * hasp_get_sessioninfo + * retrieve Sentinel key attributes + * + * Please note: In case of performing an activation we recommend to use + * hasp_get_info() instead of hasp_get_sessioninfo(), as + * demonstrated in the activation sample. hasp_get_info() + * can be called without performing a login. + */ + + printf("\nget session info : "); + + status = hasp_get_sessioninfo(handle, + HASP_KEYINFO, + &info); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK, Sentinel key attributes retrieved\n\n" + "Key info:\n===============\n%s===============\n", + info); + hasp_free(info); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_INV_FORMAT: + printf("unrecognized format\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("hasp_get_sessioninfo failed\n"); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /***********************************************************************/ + + wait4key("to continue"); + + /************************************************************************ + * hasp_get_size + * retrieve the memory size of the HASP key + * you can also retrieve dynamic memory file size, + * only need to pass the dynamic memory file id which + * created in token + */ + + printf("\nretrieving the key's memory size : "); + + status = hasp_get_size(handle, + HASP_FILEID_RW, + &fsize); + + switch (status) + { + case HASP_STATUS_OK: + printf("sentinel memory size is %d bytes\n", fsize); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_INV_FILEID: + printf("invalid file id\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("could not retrieve memory size\n"); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + if (fsize != 0) /* skip memory access if no memory available */ + { + + /******************************************************************** + * hasp_read + * read from HASP memory + * you can also read dynamic memory file, + * only need to pass the dynamic memory file id which + * created in token + */ + + /* limit memory size to be used in this demo program */ + + if (fsize > DEMO_MEMBUFFER_SIZE) + fsize = DEMO_MEMBUFFER_SIZE; + + printf("\nreading %4d bytes from memory : ", fsize); + + status = hasp_read(handle, + HASP_FILEID_RW, /* read/write file ID */ + 0, /* offset */ + fsize, /* length */ + &membuffer[0]); /* file data */ + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + dump(membuffer, fsize, " "); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_INV_FILEID: + printf("invalid file id\n"); + break; + + case HASP_MEM_RANGE: + printf("beyond memory range of attached sentinel key\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("read memory failed\n"); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /******************************************************************** + * hasp_write + * write to HASP memory + * you can also write dynamic memory file, + * only need to pass the dynamic memory file id which + * created in token + */ + + printf("\nincrementing every byte in memory buffer\n"); + for (i = 0; i < fsize; i++) + membuffer[i]++; + + printf("\nwriting %4d bytes to memory : ", fsize); + + status = hasp_write(handle, + HASP_FILEID_RW, + 0, /* offset */ + fsize, /* length */ + &membuffer); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_INV_FILEID: + printf("invalid file id\n"); + break; + + case HASP_MEM_RANGE: + printf("beyond memory range of attached sentinel key\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("write memory failed\n"); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /******************************************************************** + * hasp_read + * read from HASP memory + */ + + printf("\nreading %4d bytes from memory : ", fsize); + + status = hasp_read(handle, + HASP_FILEID_RW, + 0, /* offset */ + fsize, /* length */ + &membuffer); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + dump(membuffer, fsize, " "); + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_INV_FILEID: + printf("invalid file id\n"); + break; + + case HASP_MEM_RANGE: + printf("beyond memory range of attached sentinel key\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("read memory failed\n"); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + } /* end of memory demo */ + + /***********************************************************************/ + /* hasp_encrypt and hasp_decrypt */ + + status = encrypt_decrypt(handle); + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /************************************************************************ + * hasp_login + * establishes a context for HASP services + * a new handle is used to log into another feature + */ + + printf("\n\nlogin to feature %4d : ", CUSTOM_FEATURE); + + status = hasp_login(CUSTOM_FEATURE, + (hasp_vendor_code_t)vendor_code, + &handle2); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_FEATURE_NOT_FOUND: + printf("no sentinel DEMOMA key found with feature 42\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key not available\n"); + break; + + case HASP_OLD_DRIVER: + printf("outdated driver version installed\n"); + break; + + case HASP_NO_DRIVER: + printf("sentinel driver not installed\n"); + break; + + case HASP_INV_VCODE: + printf("invalid vendor code\n"); + break; + + default: + printf("failed with status %d\n", status); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /***********************************************************************/ + + printf("\nencrypt/decrypt again to see different " + "encryption for different features:\n"); + + status = encrypt_decrypt(handle2); + if (status) + { + hasp_logout(handle); + hasp_logout(handle2); + exit(-1); + } + + /************************************************************************ + * hasp_logout + * closes established session and releases allocated memory + */ + + printf("\nlogout from feature %4d : ", CUSTOM_FEATURE); + + status = hasp_logout(handle2); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_INV_HND: + printf("failed: handle not active\n"); + break; + + default: + printf("failed with status %d\n", status); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /************************************************************************ + * hasp_get_rtc + * read current time from HASP Time key + */ + + printf("\nreading current time and date : "); + + status = hasp_get_rtc(handle, &time); + + switch (status) + { + case HASP_STATUS_OK: + /* convert HASP time value to time and date */ + status = hasp_hasptime_to_datetime(time, &day, &month, &year, + &hour, &minute, &second); + + switch (status) + { + case HASP_STATUS_OK: + printf("time: %d:%d:%d H/M/S\n " + " date: %d/%d/%d D/M/Y\n", + hour, minute, second, day, month, year); + break; + + case HASP_INV_TIME: + printf("time value outside supported range\n"); + break; + + default: + printf("time conversion failed\n"); + } + break; + + case HASP_INV_HND: + printf("handle not active\n"); + break; + + case HASP_NO_TIME: + printf("no sentinel Time connected\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("key/license container not available\n"); + break; + + default: + printf("could not read time from sentinel key, status %d\n", status); + } + if ((status) && (status != HASP_NO_TIME)) + { + hasp_logout(handle); + exit(-1); + } + + /************************************************************************ + * hasp_logout + * closes established session and releases allocated memory + */ + + printf("\nlogout from default feature : "); + + status = hasp_logout(handle); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_INV_HND: + printf("failed: handle not active\n"); + break; + + default: + printf("failed\n"); + } + if (status) + { + exit(-1); + } + + /***********************************************************************/ + + wait4key("to continue"); + + /************************************************************************ + * hasp_login_scope + * establishes a context for HASP services + * allows specification of several restrictions + */ + + printf("restricting the license to 'local':\n"); + + scope = "\n" + " \n" + "\n"; + printf("%s\n", scope); + printf("\nhasp_login_scope : "); + + status = hasp_login_scope(HASP_DEFAULT_FID, + scope, + (hasp_vendor_code_t)vendor_code, + &handle); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_FEATURE_NOT_FOUND: + printf("login to default feature failed\n"); + break; + + case HASP_CONTAINER_NOT_FOUND: + printf("no sentinel key with vendor code DEMOMA found\n"); + break; + + case HASP_OLD_DRIVER: + printf("outdated driver version installed\n"); + break; + + case HASP_NO_DRIVER: + printf("sentinel driver not installed\n"); + break; + + case HASP_INV_VCODE: + printf("invalid vendor code\n"); + break; + + case HASP_INV_SCOPE: + printf("invalid XML scope\n"); + break; + + default: + printf("login to default feature failed with status %d\n", status); + } + if (status) + { + exit(-1); + } + + /***********************************************************************/ + + wait4key("to continue"); + + /***********************************************************************/ + + printf("getting information about connected keys and usage: "); + scope = "\n"; + view = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + + status = hasp_get_info(scope, view, vendor_code, &info); + + switch (status) + { + case HASP_STATUS_OK: + /* use the info you received ... */ + printf("OK\n%s\n", info); + + /**************************************************************** + * hasp_free + * frees memory allocated by hasp_get_info, hasp_get_sessioninfo + * or hasp_update (if an acknowledge was requested) + */ + hasp_free(info); + break; + + case HASP_INV_FORMAT: + printf("invalid XML info format\n"); + break; + + case HASP_INV_SCOPE: + printf("invalid XML scope\n"); + break; + + default: + printf("hasp_get_info failed with status %d\n", status); + } + if (status) + { + hasp_logout(handle); + exit(-1); + } + + /************************************************************************ + * hasp_logout + * closes established session and releases allocated memory + */ + printf("\nlogout : "); + status = hasp_logout(handle); + + switch (status) + { + case HASP_STATUS_OK: + printf("OK\n"); + break; + + case HASP_INV_HND: + printf("failed: handle not active\n"); + break; + + default: + printf("failed\n"); + } + if (status) + { + exit(-1); + } + + /***********************************************************************/ + + wait4key("to close the sample"); + + return 0; + +} /* main */ diff --git a/platform/src/hasp_update.c b/platform/src/hasp_update.c new file mode 100644 index 0000000..eac3388 --- /dev/null +++ b/platform/src/hasp_update.c @@ -0,0 +1,684 @@ +/**************************************************************************** +* +* Demo program for the Sentinel LDK update process +* +* +* Copyright (C) 2014, SafeNet, Inc. All rights reserved. +* +* +* Sentinel LDK DEMOMA key required +* +****************************************************************************/ + +#include +#include +#include + +#include "hasp_api.h" + +#include "hasp_vcode.h" /* this header file holds the Sentinel DEMOMA vendor code */ + +static void usage(void) +{ + printf("This is a simple demo program for the Sentinel Update " + "and Transfer functions\n"); + printf("Copyright (C) SafeNet, Inc. All rights reserved.\n\n"); + + printf("Usage: hasp_update