Class to hold a single master public key and its subkeys.

Often PGP keyring files consist of multiple master keys, if you are trying to process or construct one of these you should use the PgpPublicKeyRingBundle class.

Inheritance: PgpKeyRing, IPgpPublicKeyRing
Ejemplo n.º 1
14
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing	secretRing,
            PgpPublicKeyRing	publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = publicRing.GetPublicKey(sk.KeyId);

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return new PgpSecretKeyRing(newList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a new key ring with the public key passed in either added or
        /// replacing an existing one.
        /// </summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be inserted.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c></returns>
        public static PgpPublicKeyRing InsertPublicKey(
            PgpPublicKeyRing pubRing,
            PgpPublicKey pubKey)
        {
            ArrayList keys  = new ArrayList(pubRing.keys);
            bool      found = false;

            for (int i = 0; i != keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey)keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found   = true;
                    keys[i] = pubKey;
                }
            }

            if (!found)
            {
                keys.Add(pubKey);
            }

            return(new PgpPublicKeyRing(keys));
        }
Ejemplo n.º 3
0
 public PgpPublicKeyRingBundle(global::System.Collections.IEnumerable e)
 {
     pubRings = Platform.CreateHashtable();
     order    = Platform.CreateArrayList();
     global::System.Collections.IEnumerator enumerator = e.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             object           current          = enumerator.get_Current();
             PgpPublicKeyRing pgpPublicKeyRing = current as PgpPublicKeyRing;
             if (pgpPublicKeyRing == null)
             {
                 throw new PgpException(Platform.GetTypeName(current) + " found where PgpPublicKeyRing expected");
             }
             long keyId = pgpPublicKeyRing.GetPublicKey().KeyId;
             pubRings.Add((object)keyId, (object)pgpPublicKeyRing);
             order.Add((object)keyId);
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
 }
Ejemplo n.º 4
0
 public PgpPublicKeyRing GetPublicKeyRing(long keyId)
 {
     if (pubRings.Contains((object)keyId))
     {
         return((PgpPublicKeyRing)pubRings.get_Item((object)keyId));
     }
     global::System.Collections.IEnumerator enumerator = GetKeyRings().GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpPublicKeyRing pgpPublicKeyRing = (PgpPublicKeyRing)enumerator.get_Current();
             PgpPublicKey     publicKey        = pgpPublicKeyRing.GetPublicKey(keyId);
             if (publicKey != null)
             {
                 return(pgpPublicKeyRing);
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a new key ring with the public key passed in either added or
        /// replacing an existing one.
        /// </summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be inserted.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c></returns>
        public static PgpPublicKeyRing InsertPublicKey(
            PgpPublicKeyRing	pubRing,
            PgpPublicKey		pubKey)
        {
            ArrayList keys = new ArrayList(pubRing.keys);
            bool found = false;

            for (int i = 0; i != keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey) keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found = true;
                    keys[i] = pubKey;
                }
            }

            if (!found)
            {
                keys.Add(pubKey);
            }

            return new PgpPublicKeyRing(keys);
        }
Ejemplo n.º 6
0
 public global::System.Collections.IEnumerable GetKeyRings(string userId, bool matchPartial, bool ignoreCase)
 {
     global::System.Collections.IList list = Platform.CreateArrayList();
     if (ignoreCase)
     {
         userId = Platform.ToUpperInvariant(userId);
     }
     global::System.Collections.IEnumerator enumerator = GetKeyRings().GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpPublicKeyRing pgpPublicKeyRing = (PgpPublicKeyRing)enumerator.get_Current();
             {
                 global::System.Collections.IEnumerator enumerator2 = pgpPublicKeyRing.GetPublicKey().GetUserIds().GetEnumerator();
                 try
                 {
                     while (enumerator2.MoveNext())
                     {
                         string text  = (string)enumerator2.get_Current();
                         string text2 = text;
                         if (ignoreCase)
                         {
                             text2 = Platform.ToUpperInvariant(text2);
                         }
                         if (matchPartial)
                         {
                             if (Platform.IndexOf(text2, userId) > -1)
                             {
                                 list.Add((object)pgpPublicKeyRing);
                             }
                         }
                         else if (text2.Equals(userId))
                         {
                             list.Add((object)pgpPublicKeyRing);
                         }
                     }
                 }
                 finally
                 {
                     global::System.IDisposable disposable2 = enumerator2 as global::System.IDisposable;
                     if (disposable2 != null)
                     {
                         disposable2.Dispose();
                     }
                 }
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(new EnumerableProxy((global::System.Collections.IEnumerable)list));
 }
Ejemplo n.º 7
0
 public static byte[] ToAsc(byte[] pgp)
 {
     MemoryStream ms = new MemoryStream();
     var ring = new PgpPublicKeyRing(GetStream(pgp));
     var armored = new ArmoredOutputStream(ms);
     ring.Encode(armored);
     armored.Dispose();
     return ms.ToArray();
 }
Ejemplo n.º 8
0
        public OpenPgpCrypter(PgpPublicKeyRing publicKeyRing, PgpSecretKeyRing privateKeyRing, char[] cPassword)
        {
            if ( publicKeyRing == null || privateKeyRing == null || cPassword == null)
                throw new ArgumentNullException("encryptionKeys", "encryptionKeys or password is null.");

            this.m_PublicKeyRing = publicKeyRing;
            this.m_PrivateKeyRing = privateKeyRing;
            this.m_cPassword = cPassword;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Create a new e-mail address.
 /// </summary>
 /// <param name="OwnerName">The name of the owner of the e-mail address.</param>
 /// <param name="SimpleEMailAddress">A simple e-mail address.</param>
 /// <param name="SecretKeyRing">The secret key ring for an e-mail address.</param>
 /// <param name="PublicKeyRing">The public key ring for an e-mail address.</param>
 public EMailAddress(String              OwnerName,
                     SimpleEMailAddress  SimpleEMailAddress,
                     PgpSecretKeyRing    SecretKeyRing = null,
                     PgpPublicKeyRing    PublicKeyRing = null)
 {
     this._OwnerName      = OwnerName.Trim();
     this._Address        = SimpleEMailAddress;
     this._PublicKeyRing  = PublicKeyRing;
     this._SecretKeyRing  = SecretKeyRing;
 }
Ejemplo n.º 10
0
        public void Encode(
            Stream outStr)
        {
            BcpgOutputStream bcpgOut = BcpgOutputStream.Wrap(outStr);

            foreach (long key in order)
            {
                PgpPublicKeyRing sec = (PgpPublicKeyRing)pubRings[key];

                sec.Encode(bcpgOut);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing secretRing,
            PgpPublicKeyRing publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = publicRing.GetPublicKey(sk.KeyId);

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return(new PgpSecretKeyRing(newList));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in public key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="publicKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> not containing the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is not present.</exception>
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(
            PgpPublicKeyRingBundle bundle,
            PgpPublicKeyRing publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = Platform.CreateHashtable(bundle.pubRings);
            IList       newOrder    = Platform.CreateArrayList(bundle.order);

            newPubRings.Remove(key);
            newOrder.Remove(key);

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns a new key ring with the public key passed in either added or
        /// replacing an existing one.
        /// </summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be inserted.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c></returns>
        public static PgpPublicKeyRing InsertPublicKey(
            PgpPublicKeyRing pubRing,
            PgpPublicKey pubKey)
        {
            IList keys        = Platform.CreateArrayList(pubRing.keys);
            bool  found       = false;
            bool  masterFound = false;

            for (int i = 0; i != keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey)keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found   = true;
                    keys[i] = pubKey;
                }
                if (key.IsMasterKey)
                {
                    masterFound = true;
                }
            }

            if (!found)
            {
                if (pubKey.IsMasterKey)
                {
                    if (masterFound)
                    {
                        throw new ArgumentException("cannot add a master key to a ring that already has one");
                    }

                    keys.Insert(0, pubKey);
                }
                else
                {
                    keys.Add(pubKey);
                }
            }

            return(new PgpPublicKeyRing(keys));
        }
Ejemplo n.º 14
0
        public static PgpPublicKeyRing RemovePublicKey(PgpPublicKeyRing pubRing, PgpPublicKey pubKey)
        {
            global::System.Collections.IList list = Platform.CreateArrayList((global::System.Collections.ICollection)pubRing.keys);
            bool flag = false;

            for (int i = 0; i < ((global::System.Collections.ICollection)list).get_Count(); i++)
            {
                PgpPublicKey pgpPublicKey = (PgpPublicKey)list.get_Item(i);
                if (pgpPublicKey.KeyId == pubKey.KeyId)
                {
                    flag = true;
                    list.RemoveAt(i);
                }
            }
            if (!flag)
            {
                return(null);
            }
            return(new PgpPublicKeyRing(list));
        }
Ejemplo n.º 15
0
        /// <summary>Returns a new key ring with the public key passed in removed from the key ring.</summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c>, or null if pubKey is not found.</returns>
        public static PgpPublicKeyRing RemovePublicKey(
            PgpPublicKeyRing pubRing,
            PgpPublicKey pubKey)
        {
            ArrayList keys  = new ArrayList(pubRing.keys);
            bool      found = false;

            for (int i = 0; i < keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey)keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found = true;
                    keys.RemoveAt(i);
                }
            }

            return(found ? new PgpPublicKeyRing(keys) : null);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in public key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="publicKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> merging the current one with the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is already present.</exception>
        public static PgpPublicKeyRingBundle AddPublicKeyRing(
            PgpPublicKeyRingBundle bundle,
            PgpPublicKeyRing publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle already contains a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = new Hashtable(bundle.pubRings);
            ArrayList   newOrder    = new ArrayList(bundle.order);

            newPubRings[key] = publicKeyRing;

            newOrder.Add(key);

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }
Ejemplo n.º 17
0
        public PgpPublicKeyRingBundle(
            IEnumerable e)
        {
            this.pubRings = Platform.CreateHashtable();
            this.order    = Platform.CreateArrayList();

            foreach (object obj in e)
            {
                PgpPublicKeyRing pgpPub = obj as PgpPublicKeyRing;

                if (pgpPub == null)
                {
                    throw new PgpException(obj.GetType().FullName + " found where PgpPublicKeyRing expected");
                }

                long key = pgpPub.GetPublicKey().KeyId;
                pubRings.Add(key, pgpPub);
                order.Add(key);
            }
        }
Ejemplo n.º 18
0
        /// <summary>Returns a new key ring with the public key passed in removed from the key ring.</summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c>, or null if pubKey is not found.</returns>
        public static PgpPublicKeyRing RemovePublicKey(PgpPublicKeyRing pubRing, PgpPublicKey pubKey)
        {
            var keys  = Platform.CreateArrayList(pubRing._keys);
            var found = false;

            for (var i = 0; i < keys.Count; i++)
            {
                var key = (PgpPublicKey)keys[i];

                if (key.KeyId != pubKey.KeyId)
                {
                    continue;
                }

                found = true;
                keys.RemoveAt(i);
            }

            return(found ? new PgpPublicKeyRing(keys) : null);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing secretRing,
            PgpPublicKeyRing publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = null;
                try
                {
                    pk = publicRing.GetPublicKey(sk.KeyId);
                }
                catch (PgpException e)
                {
                    throw new InvalidOperationException(e.Message, e);
                }

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return(new PgpSecretKeyRing(newList));
        }
Ejemplo n.º 20
0
        public void Encode(Stream outStr)
        {
            BcpgOutputStream outStr2 = BcpgOutputStream.Wrap(outStr);

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)order).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    long             num = (long)enumerator.get_Current();
                    PgpPublicKeyRing pgpPublicKeyRing = (PgpPublicKeyRing)pubRings.get_Item((object)num);
                    pgpPublicKeyRing.Encode((Stream)(object)outStr2);
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Ejemplo n.º 21
0
        public static PgpPublicKeyRing InsertPublicKey(PgpPublicKeyRing pubRing, PgpPublicKey pubKey)
        {
            //IL_0066: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IList list = Platform.CreateArrayList((global::System.Collections.ICollection)pubRing.keys);
            bool flag  = false;
            bool flag2 = false;

            for (int i = 0; i != ((global::System.Collections.ICollection)list).get_Count(); i++)
            {
                PgpPublicKey pgpPublicKey = (PgpPublicKey)list.get_Item(i);
                if (pgpPublicKey.KeyId == pubKey.KeyId)
                {
                    flag = true;
                    list.set_Item(i, (object)pubKey);
                }
                if (pgpPublicKey.IsMasterKey)
                {
                    flag2 = true;
                }
            }
            if (!flag)
            {
                if (pubKey.IsMasterKey)
                {
                    if (flag2)
                    {
                        throw new ArgumentException("cannot add a master key to a ring that already has one");
                    }
                    list.Insert(0, (object)pubKey);
                }
                else
                {
                    list.Add((object)pubKey);
                }
            }
            return(new PgpPublicKeyRing(list));
        }
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in public key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="publicKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> merging the current one with the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is already present.</exception>
        public static PgpPublicKeyRingBundle AddPublicKeyRing(
            PgpPublicKeyRingBundle  bundle,
            PgpPublicKeyRing        publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle already contains a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = Platform.CreateHashtable(bundle.pubRings);
            IList newOrder = Platform.CreateArrayList(bundle.order);

            newPubRings[key] = publicKeyRing;

            newOrder.Add(key);

            return new PgpPublicKeyRingBundle(newPubRings, newOrder);
        }
Ejemplo n.º 23
0
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(PgpPublicKeyRingBundle bundle, PgpPublicKeyRing publicKeyRing)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            long keyId = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.Contains((object)keyId))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }
            IDictionary val = Platform.CreateHashtable(bundle.pubRings);

            global::System.Collections.IList list = Platform.CreateArrayList((global::System.Collections.ICollection)bundle.order);
            val.Remove((object)keyId);
            list.Remove((object)keyId);
            return(new PgpPublicKeyRingBundle(val, list));
        }
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in public key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="publicKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> not containing the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is not present.</exception>
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(
            PgpPublicKeyRingBundle	bundle,
            PgpPublicKeyRing		publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = new Hashtable(bundle.pubRings);
            ArrayList newOrder = new ArrayList(bundle.order);

            newPubRings.Remove(key);
            newOrder.Remove(key);

            return new PgpPublicKeyRingBundle(newPubRings, newOrder);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Create a new e-mail address.
 /// </summary>
 /// <param name="SimpleEMailAddress">A simple e-mail address.</param>
 /// <param name="SecretKeyRing">The secret key ring for an e-mail address.</param>
 /// <param name="PublicKeyRing">The public key ring for an e-mail address.</param>
 public EMailAddress(SimpleEMailAddress SimpleEMailAddress,
                     PgpSecretKeyRing    SecretKeyRing  = null,
                     PgpPublicKeyRing    PublicKeyRing  = null)
     : this("", SimpleEMailAddress, SecretKeyRing, PublicKeyRing)
 {
 }
Ejemplo n.º 26
0
		/// <summary>
		/// Imports a public pgp keyring.
		/// </summary>
		/// <remarks>
		/// Imports a public pgp keyring.
		/// </remarks>
		/// <param name="keyring">The pgp keyring.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="keyring"/> is <c>null</c>.
		/// </exception>
		public void Import (PgpPublicKeyRing keyring)
		{
			if (keyring == null)
				throw new ArgumentNullException (nameof (keyring));

			if (PublicKeyRingBundle.Contains (keyring.GetPublicKey ().KeyId))
				return;

			PublicKeyRingBundle = PgpPublicKeyRingBundle.AddPublicKeyRing (PublicKeyRingBundle, keyring);
			SavePublicKeyRingBundle ();
		}
Ejemplo n.º 27
0
        internal GenericAPI(RoamingNetwork        RoamingNetwork,
                            String                HTTPServerName          = DefaultHTTPServerName,
                            IPPort                HTTPServerPort          = null,
                            String                URIPrefix               = "",
                            Func<String, Stream>  GetRessources           = null,

                            String                ServiceName             = DefaultHTTPServerName,
                            EMailAddress          APIEMailAddress         = null,
                            PgpPublicKeyRing      APIPublicKeyRing        = null,
                            PgpSecretKeyRing      APISecretKeyRing        = null,
                            String                APIPassphrase           = null,
                            EMailAddressList      APIAdminEMail           = null,
                            SMTPClient            APISMTPClient           = null,

                            DNSClient             DNSClient               = null,
                            String                LogfileName             = DefaultLogfileName)
            : this(RoamingNetwork,
                   new HTTPServer(DefaultServerName: DefaultHTTPServerName).AttachTCPPorts(HTTPServerPort != null ? HTTPServerPort : DefaultHTTPServerPort),
                   URIPrefix,
                   GetRessources,

                   ServiceName,
                   APIEMailAddress,
                   APIPublicKeyRing,
                   APISecretKeyRing,
                   APIPassphrase,
                   APIAdminEMail,
                   APISMTPClient,

                   LogfileName)
        {
        }
Ejemplo n.º 28
0
		/// <summary>
		/// Replace the public key set on the secret ring with the corresponding key off the public ring.
		/// </summary>
		/// <param name="secretRing">Secret ring to be changed.</param>
		/// <param name="publicRing">Public ring containing the new public key set.</param>
		public static PgpSecretKeyRing ReplacePublicKeys(
			PgpSecretKeyRing	secretRing,
			PgpPublicKeyRing	publicRing)
		{
			IList newList = new ArrayList(secretRing.keys.Count);

			foreach (PgpSecretKey sk in secretRing.keys)
			{
				PgpPublicKey pk = null;
				try
				{
					pk = publicRing.GetPublicKey(sk.KeyId);
				}
				catch (PgpException e)
				{
					throw new InvalidOperationException(e.Message, e);
				}

				newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
			}

			return new PgpSecretKeyRing(newList);
		}
Ejemplo n.º 29
0
        /// <summary>
        /// Returns a new key ring with the public key passed in either added or
        /// replacing an existing one.
        /// </summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be inserted.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c></returns>
        public static PgpPublicKeyRing InsertPublicKey(
            PgpPublicKeyRing	pubRing,
            PgpPublicKey		pubKey)
        {
            IList keys = Platform.CreateArrayList(pubRing.keys);
            bool found = false;
            bool masterFound = false;

            for (int i = 0; i != keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey) keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found = true;
                    keys[i] = pubKey;
                }
                if (key.IsMasterKey)
                {
                    masterFound = true;
                }
            }

            if (!found)
            {
                if (pubKey.IsMasterKey)
                {
                    if (masterFound)
                        throw new ArgumentException("cannot add a master key to a ring that already has one");

                    keys.Insert(0, pubKey);
                }
                else
                {
                    keys.Add(pubKey);
                }
            }

            return new PgpPublicKeyRing(keys);
        }
Ejemplo n.º 30
0
 public static PgpSecretKeyRing ReplacePublicKeys(PgpSecretKeyRing secretRing, PgpPublicKeyRing publicRing)
 {
     global::System.Collections.IList       list       = Platform.CreateArrayList(((global::System.Collections.ICollection)secretRing.keys).get_Count());
     global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)secretRing.keys).GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpSecretKey pgpSecretKey = (PgpSecretKey)enumerator.get_Current();
             PgpPublicKey publicKey    = publicRing.GetPublicKey(pgpSecretKey.KeyId);
             list.Add((object)PgpSecretKey.ReplacePublicKey(pgpSecretKey, publicKey));
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(new PgpSecretKeyRing(list));
 }
Ejemplo n.º 31
0
        /// <summary>Returns a new key ring with the public key passed in removed from the key ring.</summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c>, or null if pubKey is not found.</returns>
        public static PgpPublicKeyRing RemovePublicKey(
            PgpPublicKeyRing	pubRing,
            PgpPublicKey		pubKey)
        {
            IList keys = Platform.CreateArrayList(pubRing.keys);
            bool found = false;

            for (int i = 0; i < keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey) keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found = true;
                    keys.RemoveAt(i);
                }
            }

            return found ? new PgpPublicKeyRing(keys) : null;
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Create a new e-mail address.
 /// </summary>
 /// <param name="OwnerName">The name of the owner of the e-mail address.</param>
 /// <param name="SimpleEMailAddressString">A string representation of a simple e-mail address.</param>
 /// <param name="SecretKeyRing">The public key ring for an e-mail address.</param>
 /// <param name="PublicKeyRing">The secret key ring for an e-mail address.</param>
 public EMailAddress(String            OwnerName,
                     String            SimpleEMailAddressString,
                     PgpSecretKeyRing  SecretKeyRing = null,
                     PgpPublicKeyRing  PublicKeyRing = null)
     : this(OwnerName, SimpleEMailAddress.Parse(SimpleEMailAddressString), SecretKeyRing, PublicKeyRing)
 {
 }
Ejemplo n.º 33
0
 public OpenPGPRing(PgpPublicKeyRing _pgpPublicKeyRing, PgpSecretKeyRing _pgpSecretKeyRing, char [] cPassword)
 {
     this.m_PublicKeyRing = _pgpPublicKeyRing;
     this.m_PrivateKeyRing = _pgpSecretKeyRing;
     this.m_cPassword = cPassword;
 }
Ejemplo n.º 34
0
 public OpenPGPRing(PgpPublicKeyRing _pgpPublicKeyRing, PgpSecretKeyRing _pgpSecretKeyRing)
 {
     this.m_PublicKeyRing = _pgpPublicKeyRing;
     this.m_PrivateKeyRing = _pgpSecretKeyRing;
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Initialize the OCPI HTTP server using IPAddress.Any, http port 8080 and maybe start the server.
        /// </summary>
        internal GenericAPI(RoamingNetwork        RoamingNetwork,
                            HTTPServer            HTTPServer,
                            String                URIPrefix               = "/ext/OCPI",
                            Func<String, Stream>  GetRessources           = null,

                            String                ServiceName             = DefaultHTTPServerName,
                            EMailAddress          APIEMailAddress         = null,
                            PgpPublicKeyRing      APIPublicKeyRing        = null,
                            PgpSecretKeyRing      APISecretKeyRing        = null,
                            String                APIPassphrase           = null,
                            EMailAddressList      APIAdminEMail           = null,
                            SMTPClient            APISMTPClient           = null,

                            String                LogfileName             = DefaultLogfileName)
        {
            #region Initial checks

            if (RoamingNetwork == null)
                throw new ArgumentNullException("RoamingNetwork", "The given parameter must not be null!");

            if (HTTPServer == null)
                throw new ArgumentNullException("HTTPServer", "The given parameter must not be null!");

            if (URIPrefix.IsNullOrEmpty())
                throw new ArgumentNullException("URIPrefix", "The given parameter must not be null or empty!");

            if (!URIPrefix.StartsWith("/"))
                URIPrefix = "/" + URIPrefix;

            #endregion

            #region Init data

            this._HTTPServer              = HTTPServer;
            this._GetRessources           = GetRessources;
            this._URIPrefix               = URIPrefix;

            this._ServiceName             = ServiceName;
            this._APIEMailAddress         = APIEMailAddress;
            this._APIPublicKeyRing        = APIPublicKeyRing;
            this._APISecretKeyRing        = APISecretKeyRing;
            this._APIPassphrase           = APIPassphrase;
            this._APIAdminEMail           = APIAdminEMail;
            this._APISMTPClient           = APISMTPClient;

            this._DNSClient               = HTTPServer.DNSClient;

            #endregion

            RegisterURITemplates();
        }
        /// <summary>Returns a new key ring with the public key passed in removed from the key ring.</summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c>, or null if pubKey is not found.</returns>
        public static PgpPublicKeyRing RemovePublicKey(PgpPublicKeyRing pubRing, PgpPublicKey pubKey)
        {
            var keys = Platform.CreateArrayList(pubRing._keys);
            var found = false;

            for (var i = 0; i < keys.Count; i++)
            {
                var key = (PgpPublicKey)keys[i];

                if (key.KeyId != pubKey.KeyId)
                    continue;

                found = true;
                keys.RemoveAt(i);
            }

            return found ? new PgpPublicKeyRing(keys) : null;
        }