FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: how to use FTDI USB-Key  (Read 7820 times)

fiona_koo

  • Newbie
  • *
  • Posts: 2
    • View Profile
how to use FTDI USB-Key
« on: October 27, 2020, 01:10:42 AM »

Hi,

I am using FTDI USB Key as a dongle key. Does anyone know how to use FTDI USB Key? My software is using MFC C++ to program. Been study this usb-key two days, I have successfully generate private key and public key but I stuck at signing dongle key. I have some questions want to ask:

1) The sequence to make this USB-Key work is GenerateKey() -> put_PrivateKey() -> SignDonglePassword() -> VerifyDonglePassword(), correct?

2) When I called SingleDonglePassword() or SignDongle(), I get error message "Insufficient space in EEPROM user data area", does anyone know what it means? And what should I do to solve this issue?

3) Since the private key information and FTDI-ChipID will be store into USB-Key after calling SignDongle(), could I erase this file?

4) After calling SignDongle(), does it mean that this public key will only work corresponding to this FTDI USB Key?

Actually, I get "Exception Occurred" when using below code, if I used Microsoft Visual C++ example code, I will get "Insufficient space in EEPROM user data area" this error message.

The example code is from below link
https://www.ftdichip.com/Support/SoftwareExamples/SafeGuard-IT.htm


Code: [Select]

void CTestDlg::OnBnClickedGenerate()
{
HRESULT hResult;
SAFEARRAY *pPublicKey;
SAFEARRAY *pPrivateKey;
CFile file;

if(!ptrISetupDongle)
return;

hResult = ptrISetupDongle->GenerateKey(&pPublicKey);
if (FAILED(hResult))
{
MessageBox(L"Failed to generate public key!");
return;
}
else
{
if(WriteToKeyFile(pPublicKey, L"public.key"))
MessageBox(L"Success to create public key file!");
}

hResult = ptrISetupDongle->get_PrivateKey(&pPrivateKey);
if (FAILED(hResult))
{
MessageBox(L"Failed to generate private key!");
return;
}
else
{
if(WriteToKeyFile(pPrivateKey, L"private.key"))
MessageBox(L"Success to create private key file!");
}
}

void CTestDlg::OnBnClickedPutPrivatekey()
{
HRESULT hResult;

if(!ptrISetupDongle)
return;

SAFEARRAY *pPrivateKey = ReadKeyFile(L"private.key");
if(!pPrivateKey)
return;

hResult = ptrISetupDongle->put_PrivateKey(pPrivateKey);
if (FAILED(hResult))
{
MessageBox(L"Failed to put private key!");
SafeArrayDestroy(pPrivateKey);
}
else
{
MessageBox(L"Success to put private key!");
SafeArrayDestroy(pPrivateKey);
}
}

void CTestDlg::OnBnClickedSignDongle()
{
HRESULT hResult;

if(!ptrISetupDongle)
return;

hResult = ptrISetupDongle->SignDongle();
if (FAILED(hResult))
{
_com_error err(hResult); // _com_error
LPCTSTR errMsg = err.ErrorMessage();
MessageBox(errMsg);

}
else
{
MessageBox(L"Success to sign dongle key!");
}
}

SAFEARRAY* CTestDlg::ReadKeyFile(CString sFileName)
{
CFile file;
SAFEARRAY *pTheKey = nullptr;

if(file.Open(sFileName, (CFile::modeRead | CFile::typeBinary)))
{
UINT Length = (UINT)file.GetLength();
if(Length)
{
SAFEARRAYBOUND rgsabound;
rgsabound.lLbound = 0;
rgsabound.cElements = Length;
pTheKey = SafeArrayCreate(VT_UI1, 1, &rgsabound);
SafeArrayAccessData(pTheKey,&pTheKey->pvData);
if(pTheKey != NULL)
file.Read(pTheKey->pvData, Length);
}
file.Close();
SafeArrayUnaccessData(pTheKey);
}

return pTheKey;
}

BOOL CTestDlg::WriteToKeyFile(SAFEARRAY* pTheKey, CString sFileName)
{
CFile file;
long lLength;
SafeArrayGetUBound(pTheKey, pTheKey->cDims, &lLength);
SafeArrayAccessData(pTheKey,&pTheKey->pvData);

if (!(file.Open(sFileName, (CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))))
return FALSE;

file.Write(pTheKey->pvData, lLength+1); // 0 based
file.Close();
SafeArrayUnaccessData(pTheKey);
SafeArrayDestroy(pTheKey);

return TRUE;
}
« Last Edit: October 28, 2020, 01:15:26 AM by fiona_koo »
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 892
    • View Profile
Re: how to use FTDI USB-Key
« Reply #1 on: October 29, 2020, 04:33:36 PM »

Hello,

SafeGuard-IT is a very old application that’s no longer supported by R&D.
It was developed many years ago in 2007.
Note ChipID and SafeGuard are two different things.

SafeGuard-IT uses the Chip ID which can be found here:

http://www.ftdichip.com/Support/SoftwareExamples/FTDIChip-ID.htm

This Chip ID DLL is used with the D2XX Drivers.

It’s better to develop your own code using FTDIChip-ID.

There is another option to avoid using the Chip ID DLL which means even less dependency on our DLLs:
The FTChipID cannot be read from the FTD2XXX library directly as standard.
There is an NDA option available where we can provide the memory location of the raw FTChipID in EEPROM.
However, note that the FTDIChip-ID.dll does some additional manipulation of this EEPROM data, so the dll vs direct EEPROM read might not match.

If you would like this information under NDA, please Contact Us.

As for your error "Insufficient space in EEPROM user data area" there is a limited amount of memory available in the EEPROM (1024 bits).
The size of the user area depends on the length of the Manufacturer, ManufacturerId, Description and SerialNumber strings programmed into the internal EEPROM. More memory space is freed up if the lengths of the information strings are shortened. The Maximum length of the Manufacturer, ManufacturerId, Description and SerialNumber strings is 48 words (1 word = 2 bytes). If all the 48 words are used, then no user area space is available.
To reduce the memory already taken up and to free up more space available to User Area, you could reduce the serial number and description strings using FT_PROG.
Also see AN_121 Accessing The EEPROM User Area Of FTDI Devices for more information.

Maybe there are other community users who can help you further.

Best Regards,
FTDI Community
Logged

fiona_koo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: how to use FTDI USB-Key
« Reply #2 on: November 02, 2020, 05:14:48 AM »

Hi,

Thank you for your reply, I did use the unique FTDI Chip-ID and FT_EE_UAWrite() to write my own unique hashing string into FTDI USB-Key EEPROM user area.
Logged