TSG-8214 基于LDK中的hasp_update构建RPM,用于获取机器指纹/设置Lience

This commit is contained in:
luwenpeng
2021-10-26 11:49:04 +03:00
commit b9f0240d13
16 changed files with 5003 additions and 0 deletions

109
.gitlab-ci.yml Normal file
View File

@@ -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

58
CMakeLists.txt Normal file
View File

@@ -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)

1268
autorevision.sh Normal file

File diff suppressed because it is too large Load Diff

48
ci/get-nprocessors.sh Normal file
View File

@@ -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

View File

@@ -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

63
ci/travis.sh Normal file
View File

@@ -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

30
cmake/Package.cmake Normal file
View File

@@ -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)

49
cmake/Version.cmake Normal file
View File

@@ -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})

Binary file not shown.

Binary file not shown.

8
platform/CMakeLists.txt Normal file
View File

@@ -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)

1832
platform/include/hasp_api.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -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==";

846
platform/src/hasp_demo.c Normal file
View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 = "<haspscope>\n"
" <license_manager hostname=\"localhost\" />\n"
"</haspscope>\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 = "<haspscope />\n";
view = "<haspformat root=\"my_custom_scope\">\n"
" <hasp>\n"
" <attribute name=\"id\" />\n"
" <attribute name=\"type\" />\n"
" <feature>\n"
" <attribute name=\"id\" />\n"
" <element name=\"concurrency\" />\n"
" <element name=\"license\" />\n"
" <session>\n"
" <element name=\"username\" />\n"
" <element name=\"hostname\" />\n"
" <element name=\"ip\" />\n"
" <element name=\"apiversion\" />\n"
" </session>\n"
" </feature>\n"
" </hasp>\n"
"</haspformat>\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 */

684
platform/src/hasp_update.c Normal file
View File

@@ -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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#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 <option> [filename]\n");
printf("Options: u: updates a Sentinel protection key/attaches a "
"detached license\n");
printf(" i: retrieves Sentinel protection key information\n");
printf(" d: detaches a license from a Sentinel SL-AdminMode/SL-Legacy key (Not supported for SL-UserMode)\n");
printf(" r: rehost a license from a Sentinel SL-AdminMode/SL-UserMode key\n");
printf(" f: retrieves fingerprint information\n");
printf("Filename: Path to the V2C/H2R file (in case of 'u'pdate/attach), "
"OR\n"
" Path to the C2V file; Optional: uses \"stdout\" if\n"
" file name is not specified (in case of 'i'nfo)\n");
}
static unsigned char *read_file(FILE *fp)
{
unsigned char *buffer;
size_t buffer_length, file_size;
/* get the file size */
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
buffer = (unsigned char *)malloc(file_size + 1);
if (!buffer)
{
printf("out of memory\n");
return 0;
}
buffer_length = fread(buffer, sizeof(char), file_size, fp);
if (buffer_length <= 0)
{
printf("failed to read v2c data\n");
free(buffer);
return 0;
}
/* terminate update information */
buffer[buffer_length] = 0;
return buffer;
}
int main(int argc, char **argv)
{
hasp_status_t status;
FILE *fp;
char *info = 0;
if ((argc < 2) || (argc > 3))
{
usage();
return -1;
}
if (strcmp(argv[1], "d") == 0) /* use hasp_transfer to detach a license */
{
char *recipient;
char *h2r = 0;
/* get local recipient information */
status = hasp_get_info(
"<haspscope>"
" <license_manager hostname=\"localhost\" />"
"</haspscope>",
HASP_RECIPIENT,
(hasp_vendor_code_t)vendor_code, &info);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_SCOPE_RESULTS_EMPTY:
printf("Unable to locate a Feature matching the scope\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_INV_VCODE:
printf("Invalid Vendor Code\n");
break;
case HASP_UNKNOWN_VCODE:
printf("Unknown Vendor Code\n");
break;
case HASP_INVALID_PARAMETER:
printf("Invalid parameter (scope/format too long?)\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_REMOTE_COMM_ERR:
printf("Remote communication error\n");
break;
case HASP_TOO_MANY_KEYS:
printf("Too many keys connected\n");
break;
case HASP_INV_FORMAT:
printf("Unrecognized format string\n");
break;
case HASP_INV_SCOPE:
printf("Unrecognized scope string\n");
break;
default:
printf("hasp_get_info failed with status %u\n", status);
break;
}
return -1;
}
recipient = info;
/* detach license for local recipient (duration 120 seconds.)
* Note: Please change the product ID to which you want to
* operate.
*/
status = hasp_transfer(
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
"<detach><duration>120</duration></detach>",
"<haspscope><product id=\"123\" /></haspscope>",
(hasp_vendor_code_t)vendor_code,
recipient,
&h2r);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_INV_DETACH_ACTION:
printf("Invalid XML detach_action parameter\n");
break;
case HASP_INV_RECIPIENT:
printf("Invalid XML recipient parameter\n");
break;
case HASP_TOO_MANY_PRODUCTS:
printf("Scope for hasp_detach does not select a unique Parameter\n");
break;
case HASP_ACCESS_DENIED:
printf("Request not possible because of ACC restrictions\n");
break;
case HASP_INV_PRODUCT:
printf("Invalid Product information\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_REMOTE_COMM_ERR:
printf("Remote communication error\n");
break;
case HASP_INV_SCOPE:
printf("Unrecognized scope string\n");
break;
default:
printf("hasp_transfer failed with status %u\n", status);
break;
}
return -1;
}
/* write h2r to file or stdout */
if (argc == 3)
{
fp = fopen(argv[2], "wt");
if (!fp)
{
printf("could not open file %s\n", argv[2]);
return -1;
}
}
else
{
fp = stdout;
}
fprintf(fp, "%s\n", h2r);
hasp_free(info);
hasp_free(h2r);
if (fp != stdout)
fclose(fp);
return 0;
}
else if (strcmp(argv[1], "r") == 0) /* use hasp_transfer to rehost a license */
{
char *info = 0;
char *recipient;
char *v2c = 0;
/* get local recipient information */
status = hasp_get_info(
"<haspscope>"
" <license_manager hostname=\"localhost\" />"
"</haspscope>",
HASP_RECIPIENT,
(hasp_vendor_code_t)vendor_code, &info);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_SCOPE_RESULTS_EMPTY:
printf("Unable to locate a Feature matching the scope\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_INV_VCODE:
printf("Invalid Vendor Code\n");
break;
case HASP_UNKNOWN_VCODE:
printf("Unknown Vendor Code\n");
break;
case HASP_INVALID_PARAMETER:
printf("Invalid parameter (scope/format too long?)\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_REMOTE_COMM_ERR:
printf("Remote communication error\n");
break;
case HASP_TOO_MANY_KEYS:
printf("Too many keys connected\n");
break;
case HASP_INV_FORMAT:
printf("Unrecognized format string\n");
break;
case HASP_INV_SCOPE:
printf("Unrecognized scope string\n");
break;
default:
printf("hasp_get_info failed with status %u\n", status);
break;
}
return -1;
}
else
{
printf("\n hasp_get_info function is executed successfully\n");
}
recipient = info;
/* hasp_transfer function being used. This function is used to rehost
* the v2c form one machine to another machine.
* For this we will use the recipient information generated from
* hasp_get_info function.
* Note: please change the value '123456789' to your key ID that you
* want to operate.
*/
status = hasp_transfer(
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
"<rehost><hasp id=\"123456789\"/></rehost>",
"<haspscope><hasp id=\"123456789\"/></haspscope>",
(hasp_vendor_code_t)vendor_code,
recipient,
&v2c);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_INV_RECIPIENT:
printf("Invalid XML recipient parameter\n");
break;
case HASP_ACCESS_DENIED:
printf("Request not possible because of ACC restrictions\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_REMOTE_COMM_ERR:
printf("Remote communication error\n");
break;
case HASP_INV_SCOPE:
printf("Unrecognized scope string\n");
break;
case HASP_REHOST_NOT_ALLOWED:
printf("Rehost not allowed\n");
break;
case HASP_TOO_MANY_KEYS:
printf("Scope for hasp_transfer does not specify a unique Parameter\n");
break;
case HASP_OLD_LM:
printf("License Manager is too old for SL-AdminMode/SL-UserMode licenses\n");
break;
case HASP_HASP_INACTIVE:
printf("Container is inactive\n");
break;
case HASP_CLONE_DETECTED:
printf("Cloned secure storage area detected\n");
break;
case HASP_REQ_NOT_SUPP:
printf("Rehost request not supported for SL-AdminMode/SL-UserMode licenses\n");
break;
default:
printf("hasp_transfer failed with status %u\n", status);
break;
}
return -1;
}
else
{
printf("\n hasp_transfer command executed successfully\n");
}
/* write v2c to stdout */
if (argc == 3)
{
fp = fopen(argv[2], "wt");
if (!fp)
{
printf("could not open file %s\n", argv[2]);
return -1;
}
}
else
{
fp = stdout;
}
fprintf(fp, "%s\n", v2c);
hasp_free(info);
hasp_free(v2c);
if (fp != stdout)
fclose(fp);
return 0;
}
else if (strcmp(argv[1], "u") == 0) /* use hasp_update to install a v2c/h2r */
{
unsigned char *buffer = 0;
/* read update from file */
if (argc != 3)
{
usage();
return -1;
}
fp = fopen(argv[2], "r");
if (!fp)
{
printf("could not open file %s\n", argv[2]);
free(buffer);
return -1;
}
/* read the file; this function allocates 'buffer' with 'malloc' */
buffer = read_file(fp);
if (!buffer)
{
return -1;
}
fclose(fp);
status = hasp_update((void *)buffer, &info);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_INV_UPDATE_DATA:
printf("Update data is invalid\n");
break;
case HASP_INV_UPDATE_NOTSUPP:
printf("Update request is not supported\n");
break;
case HASP_INV_UPDATE_CNTR:
printf("Update counter not set correctly\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_NO_ACK_SPACE:
printf("Acknowledge pointer is NULL\n");
break;
case HASP_UNKNOWN_ALG:
printf("Unknown v2c algorithm\n");
break;
case HASP_INV_SIG:
printf("v2c signature broken\n");
break;
case HASP_TOO_MANY_KEYS:
printf("Too many keys connected\n");
break;
case HASP_HARDWARE_MODIFIED:
printf("v2c data and SL key data mismatch\n");
break;
case HASP_UPDATE_TOO_OLD:
printf("v2c was already installed\n");
break;
case HASP_UPDATE_TOO_NEW:
printf("v2c is too new (update counter too high)\n");
break;
case HASP_LICENSE_REHOSTED:
printf("License is rehosted to other machine\n");
break;
case HASP_REHOST_ALREADY_APPLIED:
printf("Old rehost license try to apply\n");
break;
case HASP_NO_VLIB:
printf("Unable to find Vendor Library\n");
break;
case HASP_INV_VLIB:
printf("Unable to load Vendor Library\n");
break;
case HASP_OLD_VLIB:
printf("Vendor Library version too old\n");
break;
case HASP_OLD_LM:
printf("License Manager version too old\n");
break;
case HASP_MISSING_LM:
printf("License Manager is required for this operation\n");
break;
case HASP_STORAGE_CORRUPT:
printf("Corrupt data exists in secure storage area\n");
break;
case HASP_VM_DETECTED:
printf("Running on a virtual machine\n");
break;
case HASP_RECIPIENT_OLD_LM:
printf("Recipient of the requested operation is older than expected\n");
break;
case HASP_SECURE_STORE_ID_MISMATCH:
printf("Secure storage ID mismatch\n");
break;
case HASP_CLONE_DETECTED:
printf("Cloned secure storage area detected\n");
break;
case HASP_INCOMPATIBLE_PLATFORM:
printf("Attempting to perform an operation not compatible with target platform\n");
break;
default:
printf("hasp_update failed with status %u\n", status);
break;
}
free(buffer);
return -1;
}
/* print acknowledge data to stdout */
if (info)
printf("%s\n", info);
hasp_free(info);
free(buffer);
return 0;
}
else if (strcmp(argv[1], "i") == 0) /* use hasp_get_info to retrieve a c2v */
{
/* restrict the c2v to local Sentinel keys */
status = hasp_get_info(
"<haspscope>"
" <license_manager hostname=\"localhost\" />"
"</haspscope>",
HASP_UPDATEINFO,
(hasp_vendor_code_t)vendor_code, &info);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_SCOPE_RESULTS_EMPTY:
printf("Unable to locate a Feature matching the scope\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_INV_VCODE:
printf("Invalid Vendor Code\n");
break;
case HASP_UNKNOWN_VCODE:
printf("Unknown Vendor Code\n");
break;
case HASP_INVALID_PARAMETER:
printf("Invalid parameter (scope/format too long?)\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_REMOTE_COMM_ERR:
printf("Remote communication error\n");
break;
case HASP_TOO_MANY_KEYS:
printf("Too many keys connected\n");
break;
case HASP_INV_FORMAT:
printf("Unrecognized format string\n");
break;
case HASP_INV_SCOPE:
printf("Unrecognized scope string\n");
break;
default:
printf("hasp_get_info failed with status %u\n", status);
break;
}
return -1;
}
/* write info to file or stdout */
if (argc == 3)
{
fp = fopen(argv[2], "wt");
if (!fp)
{
printf("Could not open file %s\n", argv[2]);
return -1;
}
}
else
{
fp = stdout;
}
fprintf(fp, "%s\n", info);
hasp_free(info);
if (fp != stdout)
fclose(fp);
return 0;
}
else if (strcmp(argv[1], "f") == 0) /* use hasp_get_info to retrieve a c2v */
{
/* restrict the c2v to local Sentinel keys */
status = hasp_get_info(
"<haspscope>"
" <license_manager hostname=\"localhost\" />"
"</haspscope>",
HASP_FINGERPRINT,
(hasp_vendor_code_t)vendor_code, &info);
/* check if operation was successful */
if (status != HASP_STATUS_OK)
{
switch (status)
{
case HASP_SCOPE_RESULTS_EMPTY:
printf("Unable to locate a Feature matching the scope\n");
break;
case HASP_INSUF_MEM:
printf("Out of memory\n");
break;
case HASP_INV_VCODE:
printf("Invalid Vendor Code\n");
break;
case HASP_UNKNOWN_VCODE:
printf("Unknown Vendor Code\n");
break;
case HASP_INVALID_PARAMETER:
printf("Invalid parameter (scope/format too long?)\n");
break;
case HASP_DEVICE_ERR:
printf("Input/Output error\n");
break;
case HASP_LOCAL_COMM_ERR:
printf("Communication error\n");
break;
case HASP_REMOTE_COMM_ERR:
printf("Remote communication error\n");
break;
case HASP_TOO_MANY_KEYS:
printf("Too many keys connected\n");
break;
case HASP_INV_FORMAT:
printf("Unrecognized format string\n");
break;
case HASP_INV_SCOPE:
printf("Unrecognized scope string\n");
break;
default:
printf("hasp_get_info failed with status %u\n", status);
break;
}
return -1;
}
/* write info to file or stdout */
if (argc == 3)
{
fp = fopen(argv[2], "wt");
if (!fp)
{
printf("Could not open file %s\n", argv[2]);
return -1;
}
}
else
{
fp = stdout;
}
fprintf(fp, "%s\n", info);
hasp_free(info);
if (fp != stdout)
fclose(fp);
return 0;
}
else
{
usage();
}
return -1;
} /* main */

BIN
tool/hasp_rus-25743-newend Normal file

Binary file not shown.