private void EditAttributeValue() { ListViewItem selectedItem = WinFormsUtils.GetSingleSelectedItem(ListViewAttributes); if (selectedItem == null) { return; } ObjectAttribute objectAttribute = (ObjectAttribute)selectedItem.Tag; string attributeName = selectedItem.Text; byte[] attributeValue = (objectAttribute.CannotBeRead) ? new byte[0] : objectAttribute.GetValueAsByteArray(); using (HexEditor hexEditor = new HexEditor(attributeName, attributeValue)) { if (hexEditor.ShowDialog() == DialogResult.OK) { AttributeModified = true; ObjectAttribute updatedObjectAttribute = new ObjectAttribute(objectAttribute.Type, hexEditor.Bytes); _pkcs11Slot.SaveObjectAttributes(_pkcs11ObjectInfo, new List <ObjectAttribute>() { updatedObjectAttribute }); selectedItem.Tag = updatedObjectAttribute; ReloadListView(); } } }
public void _06_ByteArrayAttributeTest() { if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 1) { Assert.Inconclusive("Test cannot be executed on this platform"); } byte[] value = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; // Create attribute with byte array value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value)) { Assert.IsTrue(attr.Type == (uint)CKA.CKA_ID); Assert.IsTrue(Convert.ToBase64String(attr.GetValueAsByteArray()) == Convert.ToBase64String(value)); } value = null; // Create attribute with null byte array value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value)) { Assert.IsTrue(attr.Type == (uint)CKA.CKA_ID); Assert.IsTrue(attr.GetValueAsByteArray() == value); } }
public void _02_EmptyAttributeTest() { // Create attribute without the value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS)) { Assert.IsTrue(attr.Type == (ulong)CKA.CKA_CLASS); Assert.IsTrue(attr.GetValueAsByteArray() == null); } }
public void _02_EmptyAttributeTest() { Helpers.CheckPlatform(); // Create attribute without the value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS)) { Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_CLASS)); Assert.IsTrue(attr.GetValueAsByteArray() == null); } }
public void _02_EmptyAttributeTest() { if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 0) { Assert.Inconclusive("Test cannot be executed on this platform"); } // Create attribute without the value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS)) { Assert.IsTrue(attr.Type == (ulong)CKA.CKA_CLASS); Assert.IsTrue(attr.GetValueAsByteArray() == null); } }
private void ButtonAsn1_Click(object sender, EventArgs e) { ListViewItem selectedItem = WinFormsUtils.GetSingleSelectedItem(ListViewAttributes); if (selectedItem == null) { return; } ObjectAttribute objectAttribute = (ObjectAttribute)selectedItem.Tag; string attributeName = selectedItem.Text; byte[] attributeValue = (objectAttribute.CannotBeRead) ? new byte[0] : objectAttribute.GetValueAsByteArray(); using (Asn1Viewer asn1Viewer = new Asn1Viewer(attributeName, attributeValue)) asn1Viewer.ShowDialog(); }
private void ViewAsn1AttributeValue() { ListView activeListView = GetActiveListView(); ListViewItem selectedItem = WinFormsUtils.GetSingleSelectedItem(activeListView); if (selectedItem == null) { return; } ObjectAttribute objectAttribute = (ObjectAttribute)selectedItem.Tag; string attributeName = selectedItem.Text; byte[] attributeValue = (objectAttribute.CannotBeRead) ? new byte[0] : objectAttribute.GetValueAsByteArray(); using (Asn1Viewer asn1Viewer = new Asn1Viewer(attributeName, attributeValue)) asn1Viewer.ShowDialog(); }
public void _06_ByteArrayAttributeTest() { byte[] value = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; // Create attribute with byte array value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value)) { Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ID); Assert.IsTrue(Convert.ToBase64String(attr.GetValueAsByteArray()) == Convert.ToBase64String(value)); } value = null; // Create attribute with null byte array value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value)) { Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ID); Assert.IsTrue(attr.GetValueAsByteArray() == value); } }
public void _06_ByteArrayAttributeTest() { Helpers.CheckPlatform(); byte[] value = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; // Create attribute with byte array value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value)) { Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_ID)); Assert.IsTrue(ConvertUtils.BytesToBase64String(attr.GetValueAsByteArray()) == ConvertUtils.BytesToBase64String(value)); } value = null; // Create attribute with null byte array value using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value)) { Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_ID)); Assert.IsTrue(attr.GetValueAsByteArray() == value); } }
public static void GetAttributeNameAndValue(ObjectAttribute objectAttribute, out string name, out string value) { if (objectAttribute == null) { throw new ArgumentNullException("objectAttribute"); } string tmpName = null; string tmpValue = null; // Find attribute definition in configuration AttributeDefinition pkcs11Attribute = null; if (config.AttributeDefinitions.ContainsKey(objectAttribute.Type)) { pkcs11Attribute = config.AttributeDefinitions[objectAttribute.Type]; } // Determine attribute name if (pkcs11Attribute == null) { tmpName = string.Format("Unknown ({0})", objectAttribute.Type.ToString()); } else { tmpName = pkcs11Attribute.Name; } // Determine attribute value if (pkcs11Attribute == null) { if (objectAttribute.CannotBeRead) { tmpValue = "<unextractable>"; } else { tmpValue = BytesToHexString(objectAttribute.GetValueAsByteArray()); } } else { if (objectAttribute.CannotBeRead) { tmpValue = "<unextractable>"; } else { // TODO - More robust conversions switch (pkcs11Attribute.Type) { case AttributeType.Bool: tmpValue = objectAttribute.GetValueAsBool().ToString(); break; case AttributeType.ByteArray: tmpValue = BytesToHexString(objectAttribute.GetValueAsByteArray()); break; case AttributeType.DateTime: DateTime?dateTime = objectAttribute.GetValueAsDateTime(); tmpValue = (dateTime == null) ? null : dateTime.Value.ToShortDateString(); break; case AttributeType.String: tmpValue = objectAttribute.GetValueAsString(); break; case AttributeType.ULong: tmpValue = GetAttributeEnumValue(pkcs11Attribute, objectAttribute.GetValueAsUlong(), false); break; case AttributeType.AttributeArray: case AttributeType.MechanismArray: case AttributeType.ULongArray: tmpValue = "<unsupported>"; // TODO break; default: tmpValue = "<unknown>"; break; } if (string.IsNullOrEmpty(tmpValue)) { tmpValue = "<empty>"; } } } // Set output parameters name = tmpName; value = tmpValue; }