Example of using OTP to authenticate HSM users.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define HSM_USR_ADM "master"
#define HSM_USR "user"
#define HSM_IP "127.0.0.1"
#define HSM_PWD "12345678"
int NewHsmUser
(HSESSIONCTX hSession,
const char *szUser,
const char *szPwd)
{
int nRet = 0;
strncpy(stUserInfo.
szUserId, szUser,
sizeof(stUserInfo
.szUserId));
strncpy(stUserInfo.
szPassword, szPwd,
sizeof(stUserInfo
.szPassword));
if (nRet)
{
printf("DCreateUser : Failed! %d.\n", nRet);
return nRet;
}
return 0;
}
int main(void)
{
int nRet = 0;
const char cszOTP[] = "992271";
{
0xD5, 0x17, 0xED, 0x40, 0x1D, 0xF3, 0x03, 0x38, 0x37, 0xE0, 0x8B, 0x62, 0x55, 0xBE, 0xDB, 0xF9,
0x52, 0x0E, 0xF8, 0x8E,
};
strncpy(stAuthInfoAdm.
szAddr, HSM_IP,
sizeof(stAuthInfoAdm
.szAddr));
strncpy(stAuthInfoAdm.
szUserId, HSM_USR_ADM,
sizeof(stAuthInfoAdm
.szUserId));
strncpy(stAuthInfoAdm.
szPassword, HSM_PWD,
sizeof(stAuthInfoAdm
.szPassword));
stAuthInfoAdm.
nStrongAuthLen = 0;
stAuthInfoAdm.
pbStrongAuth = NULL;
if(nRet)
{
printf("DOpenSession (adm) : Failed! %d.\n", nRet);
goto clean;
}
nRet = NewHsmUser(hSessionAdm, HSM_USR, HSM_PWD);
if (nRet)
{
printf("NewHsmUser : Failed! %d.\n", nRet);
goto clean;
}
memcpy(stTokenParam.
key, pbOtpKey,
sizeof(pbOtpKey));
stTokenParam.
key_len =
sizeof(pbOtpKey);
HSM_USR,
sizeof(stTokenParam));
if( nRet )
{
printf("DAssignToken : Failed! %d.\n", nRet);
goto clean;
}
strncpy(stAuthInfoUser
.szAddr, HSM_IP,
sizeof(stAuthInfoUser
.szAddr));
if (nRet)
{
printf("DOpenSession (user) : Failed! %d.\n", nRet);
goto clean;
}
HSM_USR,
"758993",
"864532",
0);
if (nRet)
{
printf("DOATHResync : Failed! %d.\n", nRet);
goto clean;
}
HSM_USR);
if (nRet)
{
printf("DUnassignToken : Failed! %d.\n", nRet);
goto clean;
}
clean:
if (hSessionAdm != NULL)
{
}
return nRet;
}
HSM Application Programming Interface (API) Dinamo.
void * HSESSIONCTX
Definition dinamo.h:68
#define DEFAULT_PORT
Definition dinamo.h:1948
#define CACHE_BYPASS
Definition dinamo.h:589
#define SA_AUTH_NONE
Definition dinamo.h:594
#define SA_AUTH_OTP
Definition dinamo.h:595
unsigned char BYTE
Definition dinamo.h:45
#define LB_BYPASS
Definition dinamo.h:588
#define OATH_SA_v1_HOTP_DYN_TRUNC_OFF
Definition dinamo.h:853
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define OATH_SA_v1_type_SHA1
Definition dinamo.h:852
#define SS_USR_PWD_EX
Definition dinamo.h:579
#define AT_OATH_TOKEN
Definition dinamo.h:844
int AAP_API DOpenSession(HSESSIONCTX *phSession, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
int AAP_API DCloseSession(HSESSIONCTX *phSession, DWORD dwFlags)
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DRemoveUser(HSESSIONCTX hSession, char *szUserId)
int AAP_API DUnassignToken(const HSESSIONCTX hSession, const DWORD dwParam, const char *szUserId)
int AAP_API DAssignToken(const HSESSIONCTX hSession, const char *szUserId, const DWORD dwParam, BYTE *pbData, const DWORD dwDataLen)
int AAP_API DCreateUser(HSESSIONCTX hSession, struct USER_INFO userInfo)
int AAP_API DOATHResync(const HSESSIONCTX hSession, char *szUser, char *szOTP1, char *szOTP2, DWORD dwParam)
int nPort
Definition dinamo.h:3103
char szUserId[MAX_USR_LEN]
Definition dinamo.h:3104
DWORD dwAuthType
Definition dinamo.h:3106
char szAddr[MAX_ADDR_LEN]
Definition dinamo.h:3102
char szPassword[MAX_USR_PWD]
Definition dinamo.h:3105
int nStrongAuthLen
Definition dinamo.h:3112
BYTE * pbStrongAuth
Definition dinamo.h:3111
BYTE key_len
Definition dinamo.h:2811
BYTE key[MAX_OATH_HMAC_LEN]
Definition dinamo.h:2812
BYTE type
Definition dinamo.h:2807
BYTE truncation_offset
Definition dinamo.h:2813
char szPassword[MAX_USR_PWD+1]
Definition dinamo.h:3169
char szUserId[MAX_USR_LEN+1]
Definition dinamo.h:3168