private static PgpPublicKey AddCert( PgpPublicKey key, object id, PgpSignature certification) { PgpPublicKey returnKey = new PgpPublicKey(key); IList sigList = null; for (int i = 0; i != returnKey.ids.Count; i++) { if (id.Equals(returnKey.ids[i])) { sigList = (IList) returnKey.idSigs[i]; } } if (sigList != null) { sigList.Add(certification); } else { sigList = Platform.CreateArrayList(); sigList.Add(certification); returnKey.ids.Add(id); returnKey.idTrusts.Add(null); returnKey.idSigs.Add(sigList); } return returnKey; }
/// <summary>Add a certification for an id to the given public key.</summary> /// <param name="key">The key the certification is to be added to.</param> /// <param name="id">The ID the certification is associated with.</param> /// <param name="certification">The new certification.</param> /// <returns>The re-certified key.</returns> public static PgpPublicKey AddCertification( PgpPublicKey key, string id, PgpSignature certification) { return AddCert(key, id, certification); }
/// <summary>Add a certification for the given UserAttributeSubpackets to the given public key.</summary> /// <param name="key">The key the certification is to be added to.</param> /// <param name="userAttributes">The attributes the certification is associated with.</param> /// <param name="certification">The new certification.</param> /// <returns>The re-certified key.</returns> public static PgpPublicKey AddCertification( PgpPublicKey key, PgpUserAttributeSubpacketVector userAttributes, PgpSignature certification) { return AddCert(key, userAttributes, certification); }
private static PgpPublicKey RemoveCert(IPgpPublicKey key, object id, PgpSignature certification) { var returnKey = new PgpPublicKey(key); var found = false; for (var i = 0; i < returnKey._ids.Count; i++) { if (!id.Equals(returnKey._ids[i])) continue; var certs = returnKey.IdSigs[i]; found = certs.Contains(certification); if (found) { certs.Remove(certification); } } return found ? returnKey : null; }
public void Encode(Stream outStr) { BcpgOutputStream bcpgOutputStream = BcpgOutputStream.Wrap(outStr); bcpgOutputStream.WritePacket(secret); if (pub.trustPk != null) { bcpgOutputStream.WritePacket(pub.trustPk); } global::System.Collections.IEnumerator enumerator; if (pub.subSigs == null) { { enumerator = ((global::System.Collections.IEnumerable)pub.keySigs).GetEnumerator(); try { while (enumerator.MoveNext()) { PgpSignature pgpSignature = (PgpSignature)enumerator.get_Current(); pgpSignature.Encode((Stream)(object)bcpgOutputStream); } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } for (int i = 0; i != ((global::System.Collections.ICollection)pub.ids).get_Count(); i++) { object obj = pub.ids.get_Item(i); if (obj is string) { string id = (string)obj; bcpgOutputStream.WritePacket(new UserIdPacket(id)); } else { PgpUserAttributeSubpacketVector pgpUserAttributeSubpacketVector = (PgpUserAttributeSubpacketVector)obj; bcpgOutputStream.WritePacket(new UserAttributePacket(pgpUserAttributeSubpacketVector.ToSubpacketArray())); } if (pub.idTrusts.get_Item(i) != null) { bcpgOutputStream.WritePacket((ContainedPacket)pub.idTrusts.get_Item(i)); } { enumerator = ((global::System.Collections.IEnumerable)(global::System.Collections.IList) pub.idSigs.get_Item(i)).GetEnumerator(); try { while (enumerator.MoveNext()) { PgpSignature pgpSignature2 = (PgpSignature)enumerator.get_Current(); pgpSignature2.Encode((Stream)(object)bcpgOutputStream); } } finally { global::System.IDisposable disposable2 = enumerator as global::System.IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } } } return; } enumerator = ((global::System.Collections.IEnumerable)pub.subSigs).GetEnumerator(); try { while (enumerator.MoveNext()) { PgpSignature pgpSignature3 = (PgpSignature)enumerator.get_Current(); pgpSignature3.Encode((Stream)(object)bcpgOutputStream); } } finally { global::System.IDisposable disposable3 = enumerator as global::System.IDisposable; if (disposable3 != null) { disposable3.Dispose(); } } }
/// <summary>Add a revocation or some other key certification to a key.</summary> /// <param name="key">The key the revocation is to be added to.</param> /// <param name="certification">The key signature to be added.</param> /// <returns>The new changed public key object.</returns> public static PgpPublicKey AddCertification(IPgpPublicKey key, PgpSignature certification) { if (key.IsMasterKey) { if (certification.SignatureType == PgpSignature.SubkeyRevocation) { throw new ArgumentException("signature type incorrect for master key revocation."); } } else { if (certification.SignatureType == PgpSignature.KeyRevocation) { throw new ArgumentException("signature type incorrect for sub-key revocation."); } } var returnKey = new PgpPublicKey(key); if (returnKey.SubSigs != null) { returnKey.SubSigs.Add(certification); } else { returnKey.KeySigs.Add(certification); } return returnKey; }
/// <summary>Remove a certification associated with a given user attributes on a key.</summary> /// <param name="key">The key the certifications are to be removed from.</param> /// <param name="userAttributes">The user attributes that the certfication is to be removed from.</param> /// <param name="certification">The certification to be removed.</param> /// <returns>The re-certified key, or null if the certification was not found.</returns> public static PgpPublicKey RemoveCertification(IPgpPublicKey key, IPgpUserAttributeSubpacketVector userAttributes, PgpSignature certification) { return RemoveCert(key, userAttributes, certification); }
/// <summary>Return the next object in the stream, or null if the end is reached.</summary> /// <exception cref="IOException">On a parse error</exception> public PgpObject NextPgpObject() { PacketTag tag = bcpgIn.NextPacketTag(); if ((int) tag == -1) return null; switch (tag) { case PacketTag.Signature: { IList l = Platform.CreateArrayList(); while (bcpgIn.NextPacketTag() == PacketTag.Signature) { try { l.Add(new PgpSignature(bcpgIn)); } catch (PgpException e) { throw new IOException("can't create signature object: " + e); } } PgpSignature[] sigs = new PgpSignature[l.Count]; for (int i = 0; i < l.Count; ++i) { sigs[i] = (PgpSignature)l[i]; } return new PgpSignatureList(sigs); } case PacketTag.SecretKey: try { return new PgpSecretKeyRing(bcpgIn); } catch (PgpException e) { throw new IOException("can't create secret key object: " + e); } case PacketTag.PublicKey: return new PgpPublicKeyRing(bcpgIn); // TODO Make PgpPublicKey a PgpObject or return a PgpPublicKeyRing // case PacketTag.PublicSubkey: // return PgpPublicKeyRing.ReadSubkey(bcpgIn); case PacketTag.CompressedData: return new PgpCompressedData(bcpgIn); case PacketTag.LiteralData: return new PgpLiteralData(bcpgIn); case PacketTag.PublicKeyEncryptedSession: case PacketTag.SymmetricKeyEncryptedSessionKey: return new PgpEncryptedDataList(bcpgIn); case PacketTag.OnePassSignature: { IList l = Platform.CreateArrayList(); while (bcpgIn.NextPacketTag() == PacketTag.OnePassSignature) { try { l.Add(new PgpOnePassSignature(bcpgIn)); } catch (PgpException e) { throw new IOException("can't create one pass signature object: " + e); } } PgpOnePassSignature[] sigs = new PgpOnePassSignature[l.Count]; for (int i = 0; i < l.Count; ++i) { sigs[i] = (PgpOnePassSignature)l[i]; } return new PgpOnePassSignatureList(sigs); } case PacketTag.Marker: return new PgpMarker(bcpgIn); case PacketTag.Experimental1: case PacketTag.Experimental2: case PacketTag.Experimental3: case PacketTag.Experimental4: return new PgpExperimental(bcpgIn); } throw new IOException("unknown object in stream " + bcpgIn.NextPacketTag()); }
public void SetEmbeddedSignature( bool isCritical, PgpSignature pgpSignature) { byte[] sig = pgpSignature.GetEncoded(); byte[] data; // TODO Should be >= ? if (sig.Length - 1 > 256) { data = new byte[sig.Length - 3]; } else { data = new byte[sig.Length - 2]; } Array.Copy(sig, sig.Length - data.Length, data, 0, data.Length); list.Add(new EmbeddedSignature(isCritical, data)); }
/// <summary>Return the next object in the stream, or null if the end is reached.</summary> /// <exception cref="IOException">On a parse error</exception> public PgpObject NextPgpObject() { PacketTag tag = bcpgIn.NextPacketTag(); if ((int)tag == -1) { return(null); } switch (tag) { case PacketTag.Signature: { IList l = Platform.CreateArrayList(); while (bcpgIn.NextPacketTag() == PacketTag.Signature) { try { l.Add(new PgpSignature(bcpgIn)); } catch (PgpException e) { throw new IOException("can't create signature object: " + e); } } PgpSignature[] sigs = new PgpSignature[l.Count]; for (int i = 0; i < l.Count; ++i) { sigs[i] = (PgpSignature)l[i]; } return(new PgpSignatureList(sigs)); } case PacketTag.SecretKey: try { return(new PgpSecretKeyRing(bcpgIn)); } catch (PgpException e) { throw new IOException("can't create secret key object: " + e); } case PacketTag.PublicKey: return(new PgpPublicKeyRing(bcpgIn)); // TODO Make PgpPublicKey a PgpObject or return a PgpPublicKeyRing // case PacketTag.PublicSubkey: // return PgpPublicKeyRing.ReadSubkey(bcpgIn); case PacketTag.CompressedData: return(new PgpCompressedData(bcpgIn)); case PacketTag.LiteralData: return(new PgpLiteralData(bcpgIn)); case PacketTag.PublicKeyEncryptedSession: case PacketTag.SymmetricKeyEncryptedSessionKey: return(new PgpEncryptedDataList(bcpgIn)); case PacketTag.OnePassSignature: { IList l = Platform.CreateArrayList(); while (bcpgIn.NextPacketTag() == PacketTag.OnePassSignature) { try { l.Add(new PgpOnePassSignature(bcpgIn)); } catch (PgpException e) { throw new IOException("can't create one pass signature object: " + e); } } PgpOnePassSignature[] sigs = new PgpOnePassSignature[l.Count]; for (int i = 0; i < l.Count; ++i) { sigs[i] = (PgpOnePassSignature)l[i]; } return(new PgpOnePassSignatureList(sigs)); } case PacketTag.Marker: return(new PgpMarker(bcpgIn)); case PacketTag.Experimental1: case PacketTag.Experimental2: case PacketTag.Experimental3: case PacketTag.Experimental4: return(new PgpExperimental(bcpgIn)); } throw new IOException("unknown object in stream " + bcpgIn.NextPacketTag()); }
private static void ProcessLine( PgpSignature sig, byte[] line) { // note: trailing white space needs to be removed from the end of // each line for signature calculation RFC 4880 Section 7.1 int length = GetLengthWithoutWhiteSpace(line); if (length > 0) { sig.Update(line, 0, length); } }
} //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown public PgpObject NextPgpObject() { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) PacketTag packetTag = bcpgIn.NextPacketTag(); if (packetTag == (PacketTag)(-1)) { return(null); } switch (packetTag) { case PacketTag.Signature: { global::System.Collections.IList list2 = Platform.CreateArrayList(); while (bcpgIn.NextPacketTag() == PacketTag.Signature) { try { list2.Add((object)new PgpSignature(bcpgIn)); } catch (PgpException ex3) { throw new IOException(string.Concat((object)"can't create signature object: ", (object)ex3)); } } PgpSignature[] array2 = new PgpSignature[((global::System.Collections.ICollection)list2).get_Count()]; for (int j = 0; j < ((global::System.Collections.ICollection)list2).get_Count(); j++) { array2[j] = (PgpSignature)list2.get_Item(j); } return(new PgpSignatureList(array2)); } case PacketTag.SecretKey: try { return(new PgpSecretKeyRing((Stream)(object)bcpgIn)); } catch (PgpException ex2) { throw new IOException(string.Concat((object)"can't create secret key object: ", (object)ex2)); } case PacketTag.PublicKey: return(new PgpPublicKeyRing((Stream)(object)bcpgIn)); case PacketTag.CompressedData: return(new PgpCompressedData(bcpgIn)); case PacketTag.LiteralData: return(new PgpLiteralData(bcpgIn)); case PacketTag.PublicKeyEncryptedSession: case PacketTag.SymmetricKeyEncryptedSessionKey: return(new PgpEncryptedDataList(bcpgIn)); case PacketTag.OnePassSignature: { global::System.Collections.IList list = Platform.CreateArrayList(); while (bcpgIn.NextPacketTag() == PacketTag.OnePassSignature) { try { list.Add((object)new PgpOnePassSignature(bcpgIn)); } catch (PgpException ex) { throw new IOException(string.Concat((object)"can't create one pass signature object: ", (object)ex)); } } PgpOnePassSignature[] array = new PgpOnePassSignature[((global::System.Collections.ICollection)list).get_Count()]; for (int i = 0; i < ((global::System.Collections.ICollection)list).get_Count(); i++) { array[i] = (PgpOnePassSignature)list.get_Item(i); } return(new PgpOnePassSignatureList(array)); } case PacketTag.Marker: return(new PgpMarker(bcpgIn)); case PacketTag.Experimental1: case PacketTag.Experimental2: case PacketTag.Experimental3: case PacketTag.Experimental4: return(new PgpExperimental(bcpgIn)); default: throw new IOException(string.Concat((object)"unknown object in stream ", (object)bcpgIn.NextPacketTag())); } }
public PgpSignatureList(PgpSignature sig) { sigs = new PgpSignature[1] { sig }; }
public bool Verify(PgpSignature pgpSig) { byte[] signatureTrailer = pgpSig.GetSignatureTrailer(); sig.BlockUpdate(signatureTrailer, 0, signatureTrailer.Length); return(sig.VerifySignature(pgpSig.GetSignature())); }
private static PgpPublicKey RemoveCert( PgpPublicKey key, object id, PgpSignature certification) { PgpPublicKey returnKey = new PgpPublicKey(key); bool found = false; for (int i = 0; i < returnKey.ids.Count; i++) { if (id.Equals(returnKey.ids[i])) { IList certs = (IList) returnKey.idSigs[i]; found = certs.Contains(certification); if (found) { certs.Remove(certification); } } } return found ? returnKey : null; }
/// <summary>Verify the calculated signature against the passed in PgpSignature.</summary> public bool Verify( PgpSignature pgpSig) { byte[] trailer = pgpSig.GetSignatureTrailer(); sig.BlockUpdate(trailer, 0, trailer.Length); return sig.VerifySignature(pgpSig.GetSignature()); }
/// <summary>Remove a certification from the key.</summary> /// <param name="key">The key the certifications are to be removed from.</param> /// <param name="certification">The certfication to be removed.</param> /// <returns>The modified key, null if the certification was not found.</returns> public static PgpPublicKey RemoveCertification( PgpPublicKey key, PgpSignature certification) { PgpPublicKey returnKey = new PgpPublicKey(key); IList sigs = returnKey.subSigs != null ? returnKey.subSigs : returnKey.keySigs; // bool found = sigs.Remove(certification); int pos = sigs.IndexOf(certification); bool found = pos >= 0; if (found) { sigs.RemoveAt(pos); } else { foreach (String id in key.GetUserIds()) { foreach (object sig in key.GetSignaturesForId(id)) { // TODO Is this the right type of equality test? if (certification == sig) { found = true; returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification); } } } if (!found) { foreach (PgpUserAttributeSubpacketVector id in key.GetUserAttributes()) { foreach (object sig in key.GetSignaturesForUserAttribute(id)) { // TODO Is this the right type of equality test? if (certification == sig) { found = true; returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification); } } } } } return returnKey; }
/// <summary>Add a certification to the given public key.</summary> /// <param name="key">The key the certification is to be added to.</param> /// <param name="id">The ID the certification is associated with.</param> /// <param name="certification">The new certification.</param> /// <returns>The re-certified key.</returns> public static PgpPublicKey AddCertification( PgpPublicKey key, string id, PgpSignature certification) { PgpPublicKey returnKey = new PgpPublicKey(key); ArrayList sigList = null; for (int i = 0; i != returnKey.ids.Count; i++) { if (id.Equals(returnKey.ids[i])) { sigList = (ArrayList) returnKey.idSigs[i]; } } if (sigList != null) { sigList.Add(certification); } else { sigList = new ArrayList(); sigList.Add(certification); returnKey.ids.Add(id); returnKey.idTrusts.Add(null); returnKey.idSigs.Add(sigList); } return returnKey; }
/// <summary>Remove a certification associated with a given ID on a key.</summary> /// <param name="key">The key the certifications are to be removed from.</param> /// <param name="id">The ID that the certfication is to be removed from.</param> /// <param name="certification">The certfication to be removed.</param> /// <returns>The re-certified key, or null if the certification was not found.</returns> public static PgpPublicKey RemoveCertification(IPgpPublicKey key, string id, PgpSignature certification) { return RemoveCert(key, id, certification); }
public PgpSignatureList( PgpSignature[] sigs) { this.sigs = (PgpSignature[]) sigs.Clone(); }
/// <summary>Remove a certification from the key.</summary> /// <param name="key">The key the certifications are to be removed from.</param> /// <param name="certification">The certfication to be removed.</param> /// <returns>The modified key, null if the certification was not found.</returns> public static PgpPublicKey RemoveCertification(PgpPublicKey key, PgpSignature certification) { var returnKey = new PgpPublicKey(key); var sigs = returnKey.SubSigs ?? returnKey.KeySigs; // bool found = sigs.Remove(certification); var pos = sigs.IndexOf(certification); var found = pos >= 0; if (found) { sigs.RemoveAt(pos); } else { foreach (string id in key.GetUserIds()) { foreach (var sig in key.GetSignaturesForId(id)) { // TODO Is this the right type of equality test? if (certification != sig) continue; found = true; returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification); } } if (!found) { foreach (IPgpUserAttributeSubpacketVector id in key.GetUserAttributes()) { foreach (var sig in key.GetSignaturesForUserAttribute(id)) { // TODO Is this the right type of equality test? if (certification != sig) continue; // found = true; returnKey = PgpPublicKey.RemoveCertification(returnKey, id, certification); } } } } return returnKey; }
public PgpSignatureList( PgpSignature sig) { this.sigs = new PgpSignature[]{ sig }; }
internal OpenPgpDigitalSignature (PgpPublicKey pubkey, PgpSignature signature) { SignerCertificate = pubkey != null ? new OpenPgpDigitalCertificate (pubkey) : null; Signature = signature; }
public PgpSignatureList( PgpSignature sig) { this.sigs = new PgpSignature[] { sig }; }