Announcements

SecurID® Discussions

Browse the SecurID discussion board to get product help and collaborate with other SecurID users.
RanYohai
Beginner
Beginner

Failed to import token file record into RSA SecureID Software Token for Android due to an "invalid token record"

********** Last edited on 01/03/18 **********

 

Hi!

 

I need some help with creating a valid token file record (of SDTID format).

Currently I manage to create one, but on both, Android RSA app and Token Converter 3.1.0, I failed to load it because it is an "invalid token record".

 

The error in Token Converter 3.1.0 starts with:

[Fatal Error] :1:1: Content is not allowed in prolog.

 

Here is an example of my code:

 

// Get token
PrincipalDTO principal = lookupUser(userId);
ListTokenDTO[] tokensArray = getUserTokens(principal);
String tokenSerialNumber = tokensArray[0].getSerialNumber();
LookupTokenCommand LTC = new LookupTokenCommand();
LTC.setSerialNumber(tokenSerialNumber);
LTC.execute();
TokenDTO token = LTC.getToken();

// Set software token profile attributes values
LookupSoftTokenProfileCommand profile = new LookupSoftTokenProfileCommand();
profile.setSoftTokenProfileGuid(token.getSoftTokenProfileId());
profile.execute();
SoftTokenProfileDTO profileObj = profile.getSoftTokenProfileDTO();
AMTokenAttributeValueDTO[] profileAttributes = getTokenAttributeValues(...);

if (profileAttributes.length > 0) {
    token.setSoftTokenProfileAttrValueDTOs(profileAttributes);
}

// Set software token device type attributes values
String deviceTypeId = token.getSoftTokenDeviceTypeId();
LookupSoftTokenDeviceTypeCommand devType = new LookupSoftTokenDeviceTypeCommand();
devType.setSoftTokenDeviceTypeGuid(deviceTypeId);
devType.setLookupType(LookupSoftTokenDeviceTypeCommand.BY_SELF_GUID);
devType.execute();
SoftTokenDeviceTypeDTO deviceTypeObj = devType.getSoftTokenDeviceTypeDTO();
AMTokenAttributeValueDTO[] deviceTypeAttributes = getTokenAttributeValues(...);

if (deviceTypeAttributes.length > 0) {
    token.setSoftTokenDeviceTypeAttrValueDTOs(deviceTypeAttributes);
}

// Update new token attributes values on server
UpdateTokenCommand update = new UpdateTokenCommand();
update.setToken(token);
update.execute();

// Distribute token
DistributeSoftTokenRequest req = new DistributeSoftTokenRequest();
req.setSoftTokenProfileGuid(profileObj.getGuid());
req.setTokenGuids(new String[] { token.getId() });
req.setProtectedMethod(IssueSoftTokenRequestBase.ST_PROTECTED_NONE);
req.setOutputMethod(IssueSoftTokenRequestBase.ST_OUTPUT_ONE_PER_FILE);
req.setDeviceTypeGuid(token.getSoftTokenDeviceTypeId());
req.setDeviceTypePluginModuleName(deviceTypeObj.getPluginModuleName());
IssueSoftwareTokensCommand issueCmd = new IssueSoftwareTokensCommand(req);
issueCmd.execute(session);

// Get SDTID file content
String fileId = issueCmd.getFileId();
GetSoftwareTokenFileCommand getSoftwareTokenFileCommand = new GetSoftwareTokenFileCommand(fileId);
getSoftwareTokenFileCommand.execute();
byte[] fileContent = getSoftwareTokenFileCommand.getFileContent();

// Forward file
if (isSaveOnDisk) {
    String folderPath = subOptions.getFolderPathToSaveIn();
    String fileName = userId + "." + getSoftwareTokenFileCommand.getFileId() + SDTID_FILE_EXTENSION;
    String filePath = combine(folderPath, fileName);
    saveFile(filePath, fileContent);

} else if (isSendByEmail) {
    sendEmail(subOptions.getEmailToSendTo(), fileContent);
}

 

************* Update - 01/03/18 *************

 

I found out that when distributing a token using the web interface, the SDTID output file is in XML format (textual file).

BUT, using the my code section above, distributing a token creates a binary output file.

I'm almost sure that here is my problem, but STILL I don't have any idea how to get it textual and in XML format.

I need your help, please.

 

************************************************

 

 

Thanks in advance for any help!

 

BR,

Ran

Labels (1)
0 Likes
1 Reply
MennaElsharkawy
Occasional Contributor Occasional Contributor
Occasional Contributor

You can remove what's under // Forward file with the below code and it will work:

 

ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(fileContent));
ZipEntry entry = null;
while ((entry = zipStream.getNextEntry()) != null) {

String entryName = entry.getName();

//EntryName is the file name; USER_NAME_TokenSerialNumber.sdtid
//You can change the location before it to change where the token is saved
FileOutputStream out = new FileOutputStream("C:\\Users\\elsham5\\Documents\\Tokens\\"+entryName);
//System.out.println(entryName); //Prints the .stdid file name

byte[] byteBuff = new byte[4096];
int bytesRead = 0;
while ((bytesRead = zipStream.read(byteBuff)) != -1)
{
out.write(byteBuff, 0, bytesRead);
}

out.close();
zipStream.closeEntry();
}
zipStream.close();

0 Likes