private bool CreateUserInfoFile(DONGLE_HANDLER hDongle) { DATA_FILE_ATTR dataAttr; dataAttr.m_Size = DongleConst.USER_INFO_FILE_LEN; //allow anonymous read dataAttr.m_Lic.m_Read_Priv = 0; //only admin could write dataAttr.m_Lic.m_Write_Priv = 2; IntPtr ptr = IntPtrUtil.CreateByStru(dataAttr); this.lastErrorCode = Dongle_CreateFile(hDongle, RockeyArmFileType.FILE_DATA, DongleConst.USER_INFO_DESCRIPTOR, ptr); IntPtrUtil.Free(ref ptr); return(IsSucc); }
/// <summary> /// create RSA private key file /// </summary> private bool CreateAuthenKeyFile(DONGLE_HANDLER hDongle) { PRIKEY_FILE_ATTR priAttr = new PRIKEY_FILE_ATTR(); priAttr.m_Size = DongleConst.RSA_KEY_LEN * 8; priAttr.m_Type = RockeyArmFileType.FILE_PRIKEY_RSA; priAttr.m_Lic.m_Count = 0xFFFFFFFF; // un-limitted priAttr.m_Lic.m_IsDecOnRAM = 0; priAttr.m_Lic.m_IsReset = 0; priAttr.m_Lic.m_Priv = 0; IntPtr ptr = IntPtrUtil.CreateByStru(priAttr); try { this.lastErrorCode = Dongle_CreateFile(hDongle, RockeyArmFileType.FILE_PRIKEY_RSA, DongleConst.AUTHEN_KEY_DESCRIPTOR, ptr); } finally { IntPtrUtil.Free(ref ptr); } return(IsSucc); }
public bool CreateUserInfo(DONGLE_HANDLER hDongle, DongleUserInfo userInfo) { if (!CreateUserInfoFile(hDongle)) { return(false); } DongleUserInfoStru stru = CreateUserInfoStru(userInfo); IntPtr ptr = IntPtrUtil.CreateByStru(stru); byte[] dest = new byte[IntPtrUtil.SizeOf(stru.GetType())]; Marshal.Copy(ptr, dest, 0, dest.Length); this.lastErrorCode = Dongle_WriteFile( hDongle, RockeyArmFileType.FILE_DATA, DongleConst.USER_INFO_DESCRIPTOR, 0, dest, dest.Length); IntPtrUtil.Free(ref ptr); return(IsSucc); }
/// <summary> /// create User root key file,and Key is request 16 bytes at least /// </summary> private bool CreateUserRootKeyFile(DONGLE_HANDLER hDongle, ushort fileDescriptor, byte[] userRootkey) { KEY_FILE_ATTR keyAttr = new KEY_FILE_ATTR(); keyAttr.m_Size = 16; keyAttr.m_Lic.m_Priv_Enc = 0; IntPtr ptr = IntPtrUtil.CreateByStru(keyAttr); this.lastErrorCode = Dongle_CreateFile(hDongle, RockeyArmFileType.FILE_KEY, fileDescriptor, ptr); IntPtrUtil.Free(ref ptr); if (!IsSucc) { return(false); } // dongle key require 16 bytes key logger.Debug(String.Format("Create Key file, descriptor={0}, key={1}", fileDescriptor, BitConverter.ToString(userRootkey))); this.lastErrorCode = Dongle_WriteFile(hDongle, RockeyArmFileType.FILE_KEY, fileDescriptor, 0, userRootkey, 16); return(IsSucc); }