public static void TestSubkeyMethods(CryptoImplementation cryptoImplementation) { SetupAssembly.AssemblySetupCrypto(cryptoImplementation); SymmetricKey key = new SymmetricKey(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }); Subkey subkey = null; Assert.Throws <ArgumentNullException>(() => { subkey = new Subkey(null, HeaderSubkey.Data); }); Assert.Throws <InternalErrorException>(() => { subkey = new Subkey(key, HeaderSubkey.None); }); subkey = new Subkey(key, HeaderSubkey.Data); Assert.That(subkey.Key.Size, Is.EqualTo(128), "A Subkey is exactly 16 bytes."); Assert.That(subkey.Key.GetBytes(), Is.EquivalentTo(new byte[] { 0x5f, 0xfe, 0x14, 0x56, 0xd5, 0x94, 0xf9, 0x22, 0x42, 0xe3, 0x66, 0x8f, 0x8c, 0xe6, 0xea, 0xc6 }), "Comparing with a pre-calculated value assumed to be correct."); subkey = new Subkey(key, HeaderSubkey.Headers); Assert.That(subkey.Key.Size, Is.EqualTo(128), "A Subkey is exactly 16 bytes."); Assert.That(subkey.Key.GetBytes(), Is.EquivalentTo(new byte[] { 0x1c, 0x81, 0x0e, 0xe7, 0x65, 0xe7, 0x0b, 0x8f, 0x7a, 0xa3, 0x2b, 0x03, 0x05, 0x07, 0xf8, 0x8a }), "Comparing with a pre-calculated value assumed to be correct."); subkey = new Subkey(key, HeaderSubkey.Hmac); Assert.That(subkey.Key.Size, Is.EqualTo(128), "A Subkey is exactly 16 bytes."); Assert.That(subkey.Key.GetBytes(), Is.EquivalentTo(new byte[] { 0xdb, 0xf1, 0x84, 0x11, 0x2e, 0xb9, 0x11, 0x16, 0x59, 0x71, 0x2b, 0xaf, 0xcf, 0xf2, 0xab, 0x24 }), "Comparing with a pre-calculated value assumed to be correct."); subkey = new Subkey(key, HeaderSubkey.Validator); Assert.That(subkey.Key.Size, Is.EqualTo(128), "A Subkey is exactly 16 bytes."); Assert.That(subkey.Key.GetBytes(), Is.EquivalentTo(new byte[] { 0x45, 0x22, 0xa0, 0x3d, 0x98, 0x00, 0x9d, 0x55, 0x45, 0xed, 0x42, 0xfb, 0xd8, 0x35, 0x78, 0xd0 }), "Comparing with a pre-calculated value assumed to be correct."); Assert.That(new Subkey(key, HeaderSubkey.Hmac).Key.GetBytes(), Is.EquivalentTo(new Subkey(key, HeaderSubkey.Hmac).Key.GetBytes()), "The subkey generation should be stable."); }
internal void Encode(AsnWriter writer, Asn1Tag tag) { writer.PushSequence(tag); writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); writer.WriteInteger(AuthenticatorVersionNumber); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1)); writer.WriteCharacterString(UniversalTagNumber.GeneralString, Realm); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1)); writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2)); CName?.Encode(writer); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2)); if (Asn1Extension.HasValue(Checksum)) { writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3)); Checksum?.Encode(writer); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3)); } writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4)); writer.WriteInteger(CuSec); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4)); writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 5)); writer.WriteGeneralizedTime(CTime); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 5)); if (Asn1Extension.HasValue(Subkey)) { writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 6)); Subkey?.Encode(writer); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 6)); } if (Asn1Extension.HasValue(SequenceNumber)) { writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 7)); writer.WriteInteger(SequenceNumber.Value); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 7)); } if (Asn1Extension.HasValue(AuthorizationData)) { writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 8)); writer.PushSequence(); for (int i = 0; i < AuthorizationData.Length; i++) { AuthorizationData[i]?.Encode(writer); } writer.PopSequence(); writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 8)); } writer.PopSequence(tag); }
/// <summary>Locks all subkeys and overwrites their secret data.</summary> public void Lock() { if (_ltSubkeys != null) { foreach (PgpSignature Subkey in _ltSubkeys) { Subkey.Lock(); } } }
/// <summary>Given a <see cref="Subkey"/>, returns a string that can be used to represent the key to a user.</summary> public static string GetKeyName(Subkey key) { if(key == null) throw new ArgumentNullException(); bool signing = key.HasCapabilities(KeyCapabilities.Sign); bool encryption = key.HasCapabilities(KeyCapabilities.Encrypt); string type = signing && encryption ? " signing/encryption" : encryption ? " encryption" : signing ? " signing" : null; return key.Length.ToString() + "-bit " + key.KeyType + type + " key, created on " + key.CreationTime.ToShortDateString(); }
} // correctly until the form is redrawn... /// <summary>Gets the <see cref="Subkey"/> objects selected by the user.</summary> Subkey[] GetSelectedKeys() { Subkey[] keys = new Subkey[subkeys.SelectedItems.Count]; for(int i=0; i<keys.Length; i++) keys[i] = ((SubkeyItem)subkeys.SelectedItems[i]).Subkey; return keys; }
internal void UpdateFromMem(IntPtr keyPtr) { _gpgme_key key = (_gpgme_key) Marshal.PtrToStructure(keyPtr, typeof(_gpgme_key)); this.keyPtr = keyPtr; revoked = key.revoked; expired = key.expired; disabled = key.disabled; invalid = key.invalid; can_encrypt = key.can_encrypt; can_sign = key.can_sign; can_certify = key.can_certify; can_authenticate = key.can_authenticate; is_qualified = key.is_qualified; secret = key.secret; protocol = (Protocol)key.protocol; owner_trust = (Validity)key.owner_trust; keylistmode = (KeylistMode)key.keylist_mode; issuer_name = Gpgme.PtrToStringUTF8(key.issuer_name); issuer_serial = Gpgme.PtrToStringAnsi(key.issuer_serial); chain_id = Gpgme.PtrToStringAnsi(key.chain_id); if (key.subkeys != (IntPtr)0) subkeys = new Subkey(key.subkeys); if (key.uids != (IntPtr)0) uids = new UserId(key.uids); }
/// <summary>Initializes a new <see cref="SubkeyItem"/> with the <see cref="PGP.Subkey"/> that it represents, and the /// text of the item. /// </summary> public SubkeyItem(Subkey subkey, string text) : base(text) { if(subkey == null) throw new ArgumentNullException(); this.subkey = subkey; this.Name = subkey.EffectiveId; }
/// <summary>Initializes a new <see cref="SubkeyItem"/> with the <see cref="PGP.Subkey"/> that it represents.</summary> public SubkeyItem(Subkey subkey) : this(subkey, string.Empty) { }