private static async Task TestSecureChannel(DaplugAPI api, DaplugKeySet keyset, DaplugSecurityLevel secLevel) { WriteTitle(); await api.OpenSecureChannelAsync(keyset, secLevel); WriteSuccess("Success!"); api.CloseSecureChannel(); }
private static async Task TestPutKey(DaplugAPI api) { WriteTitle(); await api.OpenSecureChannelAsync(defaultKeyset, cMacSecurityLevel); WriteInfo("Putting key 0x65..."); await api.PutKeyAsync(testKeyset); api.CloseSecureChannel(); WriteInfo("Opening Secure Channel with key 0x{0:X2}...", testKeyset.Version); await api.OpenSecureChannelAsync(testKeyset, cMacSecurityLevel); WriteSuccess("Success!"); api.CloseSecureChannel(); WriteInfo("Deleting key 0x{0:X2}...", testKeyset.Version); await api.OpenSecureChannelAsync(defaultKeyset, cMacSecurityLevel); await api.DeleteKeyAsync(testKeyset.Version); api.CloseSecureChannel(); }
public static async Task TestGenerateRandom(DaplugAPI api) { byte numBytes = 128; WriteTitle(); WriteInfo("Opening Secure Channel..."); await api.OpenSecureChannelAsync(defaultKeyset, fullSecurityLevel); var randomBytes = await api.GenerateRandomAsync(numBytes); WriteSuccess("Success! Got {0} random bytes.", numBytes); api.CloseSecureChannel(); }
public static async Task TestFilesystem(DaplugAPI api) { ushort dirId = 0x2012; ushort fileId = 1001; ushort testDataLength = 600; byte[] testBytes = new byte[testDataLength]; Random rnd = new Random(); rnd.NextBytes(testBytes); WriteTitle(); WriteInfo("Opening Secure Channel..."); await api.OpenSecureChannelAsync(defaultKeyset, fullSecurityLevel); WriteInfo("Selecting Master File..."); await api.SelectPathAsync(DaplugConstants.MasterFileId); WriteInfo("Creating DF 0x{0:X2}...", dirId); await api.CreateDirectoryAsync(dirId, DaplugConstants.AccessAlways); WriteInfo("Selecting DF 0x{0:X2}...", dirId); var result = await api.SelectPathAsync(dirId); WriteInfo("Creating File 0x{0:X2}...", fileId); await api.CreateFileAsync(fileId, testDataLength, DaplugConstants.AccessAlways); WriteInfo("Selecting File 0x{0:X2}...", fileId); await api.SelectFileAsync(fileId); WriteInfo("Writing test data to file..."); await api.WriteFileDataAsync(0, testBytes); WriteInfo("Reading test data to file..."); var fileContents = await api.ReadFileDataAsync(0, testDataLength); bool readTestSuccess = testBytes.SequenceEqual(fileContents); if (readTestSuccess) { WriteSuccess("Success! Read data matches Test data."); } else { WriteFail("Fail! Read data does not match Test data."); } WriteInfo("Selecting Master File..."); await api.SelectPathAsync(DaplugConstants.MasterFileId); WriteInfo("Selecting DF 0x{0:X2}...", dirId); await api.SelectPathAsync(dirId); WriteInfo("Deleting File 0x{0:X2}...", fileId); await api.DeleteFileOrDirAsync(fileId); WriteInfo("Selecting Master File..."); await api.SelectPathAsync(DaplugConstants.MasterFileId); WriteInfo("Deleting DF 0x{0:X2}...", dirId); await api.DeleteFileOrDirAsync(dirId); api.CloseSecureChannel(); WriteSuccess("Success!"); }