Holder for a collection of PGP secret keys.
Inheritance: PgpKeyRing
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Create an instance of the OCPI HTTP API for Charge Point Operators
        /// using a newly created HTTP server.
        /// </summary>
        public CPOAPI(RoamingNetwork    RoamingNetwork,
                      String            HTTPServerName    = DefaultHTTPServerName,
                      IPPort            HTTPServerPort    = null,
                      String            URIPrefix         = "",

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

                      DNSClient         DNSClient         = null,
                      String            LogfileName       = DefaultLogfileName)
            : base(RoamingNetwork,
                   HTTPServerName,
                   HTTPServerPort != null ? HTTPServerPort : DefaultHTTPServerPort,
                   URIPrefix,
                   ResourceName => typeof(CPOAPI).Assembly.GetManifestResourceStream("org.GraphDefined.WWCP.OCPIv2_1.HTTPAPI.CPOAPI.HTTPRoot." + ResourceName),

                   ServiceName,
                   APIEMailAddress,
                   null,//OpenPGP.ReadPublicKeyRing(typeof(CPOAPI).Assembly.GetManifestResourceStream("org.GraphDefined.WWCP.OCPIv2_1.HTTPAPI.GenericAPI.HTTPRoot.robot@offenes-jena_pubring.gpg")),
                   APISecretKeyRing,
                   APIPassphrase,
                   APIAdminEMail,
                   APISMTPClient,

                   DNSClient,
                   LogfileName)
        {
            RegisterCPOURITemplates();
        }
Esempio n. 3
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;
        }
Esempio n. 4
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;
 }
Esempio n. 5
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));
        }
Esempio n. 6
0
        /// <summary>
        /// Return a copy of the passed in secret key ring, with the master key and sub keys encrypted
        /// using a new password and the passed in algorithm.
        /// </summary>
        /// <param name="ring">The <c>PgpSecretKeyRing</c> to be copied.</param>
        /// <param name="oldPassPhrase">The current password for key.</param>
        /// <param name="newPassPhrase">The new password for the key.</param>
        /// <param name="newEncAlgorithm">The algorithm to be used for the encryption.</param>
        /// <param name="rand">Source of randomness.</param>
        public static PgpSecretKeyRing CopyWithNewPassword(
            PgpSecretKeyRing ring,
            char[]                                          oldPassPhrase,
            char[]                                          newPassPhrase,
            SymmetricKeyAlgorithmTag newEncAlgorithm,
            SecureRandom rand)
        {
            IList newKeys = Platform.CreateArrayList(ring.keys.Count);

            foreach (PgpSecretKey secretKey in ring.GetSecretKeys())
            {
                newKeys.Add(PgpSecretKey.CopyWithNewPassword(secretKey, oldPassPhrase, newPassPhrase, newEncAlgorithm, rand));
            }

            return(new PgpSecretKeyRing(newKeys, ring.extraPubKeys));
        }
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in secret key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpSecretKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="secretKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpSecretKeyRingBundle</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 PgpSecretKeyRingBundle AddSecretKeyRing(PgpSecretKeyRingBundle bundle, PgpSecretKeyRing secretKeyRing)
        {
            var key = secretKeyRing.GetPublicKey().KeyId;

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

            var newSecretRings = Platform.CreateHashtable(bundle._secretRings);
            var newOrder       = Platform.CreateArrayList(bundle._order);

            newSecretRings[key] = secretKeyRing;
            newOrder.Add(key);

            return(new PgpSecretKeyRingBundle(newSecretRings, newOrder));
        }
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in secret key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpSecretKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="secretKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpSecretKeyRingBundle</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 PgpSecretKeyRingBundle RemoveSecretKeyRing(
            PgpSecretKeyRingBundle bundle,
            PgpSecretKeyRing secretKeyRing)
        {
            long key = secretKeyRing.GetPublicKey().KeyId;

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

            IDictionary newSecretRings = new Hashtable(bundle.secretRings);
            ArrayList   newOrder       = new ArrayList(bundle.order);

            newSecretRings.Remove(key);
            newOrder.Remove(key);

            return(new PgpSecretKeyRingBundle(newSecretRings, newOrder));
        }
        /// <summary>Returns a new key ring with the secret key passed in removed from the key ring.</summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be removed.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c>, or null if secKey is not found.</returns>
        public static PgpSecretKeyRing RemoveSecretKey(PgpSecretKeyRing secRing, PgpSecretKey secKey)
        {
            var keys  = Platform.CreateArrayList(secRing._keys);
            var found = false;

            for (var i = 0; i < keys.Count; i++)
            {
                var key = keys[i];
                if (key.KeyId != secKey.KeyId)
                {
                    continue;
                }

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

            return(found ? new PgpSecretKeyRing(keys, secRing._extraPubKeys) : null);
        }
Esempio n. 10
0
        /// <summary>
        /// Returns a new key ring with the secret key passed in either added or
        /// replacing an existing one with the same key ID.
        /// </summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be inserted.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c></returns>
        public static PgpSecretKeyRing InsertSecretKey(
            PgpSecretKeyRing secRing,
            PgpSecretKey secKey)
        {
            IList keys        = Platform.CreateArrayList(secRing.keys);
            bool  found       = false;
            bool  masterFound = false;

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

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

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

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

            return(new PgpSecretKeyRing(keys, secRing.extraPubKeys));
        }
        public PgpSecretKeyRingBundle(
            IEnumerable e)
        {
            this.secretRings = new Hashtable();
            this.order       = new ArrayList();

            foreach (object obj in e)
            {
                PgpSecretKeyRing pgpSecret = obj as PgpSecretKeyRing;

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

                long key = pgpSecret.GetPublicKey().KeyId;
                secretRings.Add(key, pgpSecret);
                order.Add(key);
            }
        }
Esempio n. 12
0
        public static PgpSecretKeyRing RemoveSecretKey(PgpSecretKeyRing secRing, PgpSecretKey secKey)
        {
            global::System.Collections.IList list = Platform.CreateArrayList((global::System.Collections.ICollection)secRing.keys);
            bool flag = false;

            for (int i = 0; i < ((global::System.Collections.ICollection)list).get_Count(); i++)
            {
                PgpSecretKey pgpSecretKey = (PgpSecretKey)list.get_Item(i);
                if (pgpSecretKey.KeyId == secKey.KeyId)
                {
                    flag = true;
                    list.RemoveAt(i);
                }
            }
            if (!flag)
            {
                return(null);
            }
            return(new PgpSecretKeyRing(list, secRing.extraPubKeys));
        }
Esempio n. 13
0
        /// <summary>Returns a new key ring with the secret key passed in removed from the key ring.</summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be removed.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c>, or null if secKey is not found.</returns>
        public static PgpSecretKeyRing RemoveSecretKey(
            PgpSecretKeyRing secRing,
            PgpSecretKey secKey)
        {
            IList keys  = Platform.CreateArrayList(secRing.keys);
            bool  found = false;

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

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

            return(found ? new PgpSecretKeyRing(keys, secRing.extraPubKeys) : null);
        }
Esempio n. 14
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));
 }
Esempio n. 15
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));
        }
        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();
                    PgpSecretKeyRing pgpSecretKeyRing = (PgpSecretKeyRing)secretRings.get_Item((object)num);
                    pgpSecretKeyRing.Encode((Stream)(object)outStr2);
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Esempio n. 17
0
        public static PgpSecretKeyRing InsertSecretKey(PgpSecretKeyRing secRing, PgpSecretKey secKey)
        {
            //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)secRing.keys);
            bool flag  = false;
            bool flag2 = false;

            for (int i = 0; i != ((global::System.Collections.ICollection)list).get_Count(); i++)
            {
                PgpSecretKey pgpSecretKey = (PgpSecretKey)list.get_Item(i);
                if (pgpSecretKey.KeyId == secKey.KeyId)
                {
                    flag = true;
                    list.set_Item(i, (object)secKey);
                }
                if (pgpSecretKey.IsMasterKey)
                {
                    flag2 = true;
                }
            }
            if (!flag)
            {
                if (secKey.IsMasterKey)
                {
                    if (flag2)
                    {
                        throw new ArgumentException("cannot add a master key to a ring that already has one");
                    }
                    list.Insert(0, (object)secKey);
                }
                else
                {
                    list.Add((object)secKey);
                }
            }
            return(new PgpSecretKeyRing(list, secRing.extraPubKeys));
        }
Esempio n. 18
0
 public OpenPGPRing(PgpPublicKeyRing _pgpPublicKeyRing, PgpSecretKeyRing _pgpSecretKeyRing)
 {
     this.m_PublicKeyRing = _pgpPublicKeyRing;
     this.m_PrivateKeyRing = _pgpSecretKeyRing;
 }
        /// <summary>Returns a new key ring with the secret key passed in removed from the key ring.</summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be removed.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c>, or null if secKey is not found.</returns>
        public static PgpSecretKeyRing RemoveSecretKey(
            PgpSecretKeyRing  secRing,
            PgpSecretKey      secKey)
        {
            IList keys = Platform.CreateArrayList(secRing.keys);
            bool found = false;

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

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

            return found ? new PgpSecretKeyRing(keys, secRing.extraPubKeys) : null;
        }
        /// <summary>
        /// Returns a new key ring with the secret key passed in either added or
        /// replacing an existing one with the same key ID.
        /// </summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be inserted.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c></returns>
        public static PgpSecretKeyRing InsertSecretKey(
            PgpSecretKeyRing  secRing,
            PgpSecretKey      secKey)
        {
            IList keys = Platform.CreateArrayList(secRing.keys);
            bool found = false;
            bool masterFound = false;

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

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

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

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

            return new PgpSecretKeyRing(keys, secRing.extraPubKeys);
        }
        /// <summary>
        /// Return a copy of the passed in secret key ring, with the master key and sub keys encrypted
        /// using a new password and the passed in algorithm.
        /// </summary>
        /// <param name="ring">The <c>PgpSecretKeyRing</c> to be copied.</param>
        /// <param name="oldPassPhrase">The current password for key.</param>
        /// <param name="newPassPhrase">The new password for the key.</param>
        /// <param name="newEncAlgorithm">The algorithm to be used for the encryption.</param>
        /// <param name="rand">Source of randomness.</param>
        public static PgpSecretKeyRing CopyWithNewPassword(
            PgpSecretKeyRing			ring,
            char[]						oldPassPhrase,
            char[]						newPassPhrase,
            SymmetricKeyAlgorithmTag	newEncAlgorithm,
            SecureRandom				rand)
        {
            IList newKeys = Platform.CreateArrayList(ring.keys.Count);
            foreach (PgpSecretKey secretKey in ring.GetSecretKeys())
            {
                if (secretKey.IsPrivateKeyEmpty)
                {
                    newKeys.Add(secretKey);
                }
                else
                {
                    newKeys.Add(PgpSecretKey.CopyWithNewPassword(secretKey, oldPassPhrase, newPassPhrase, newEncAlgorithm, rand));
                }
            }

            return new PgpSecretKeyRing(newKeys, ring.extraPubKeys);
        }
Esempio n. 22
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)
 {
 }
Esempio n. 23
0
 public OpenPGPRing(PgpPublicKeyRing _pgpPublicKeyRing, PgpSecretKeyRing _pgpSecretKeyRing, char [] cPassword)
 {
     this.m_PublicKeyRing = _pgpPublicKeyRing;
     this.m_PrivateKeyRing = _pgpSecretKeyRing;
     this.m_cPassword = cPassword;
 }
        /// <summary>
        /// Return a copy of the passed in secret key ring, with the master key and sub keys encrypted
        /// using a new password and the passed in algorithm.
        /// </summary>
        /// <param name="ring">The <c>PgpSecretKeyRing</c> to be copied.</param>
        /// <param name="oldPassPhrase">The current password for key.</param>
        /// <param name="newPassPhrase">The new password for the key.</param>
        /// <param name="newEncAlgorithm">The algorithm to be used for the encryption.</param>
        /// <param name="rand">Source of randomness.</param>
        public static PgpSecretKeyRing CopyWithNewPassword(
            PgpSecretKeyRing ring,
            char[] oldPassPhrase,
            char[] newPassPhrase,
            SymmetricKeyAlgorithmTag newEncAlgorithm,
            SecureRandom rand)
        {
            var newKeys = Platform.CreateArrayList<IPgpSecretKey>(ring.SecretKeyCount);
            foreach (PgpSecretKey secretKey in ring.GetSecretKeys())
            {
                newKeys.Add(PgpSecretKey.CopyWithNewPassword(secretKey, oldPassPhrase, newPassPhrase, newEncAlgorithm, rand));
            }

            return new PgpSecretKeyRing(newKeys, ring._extraPubKeys);
        }
		/// <summary>
		/// Return a new bundle containing the contents of the passed in bundle with
		/// the passed in secret key ring removed.
		/// </summary>
		/// <param name="bundle">The <c>PgpSecretKeyRingBundle</c> the key ring is to be removed from.</param>
		/// <param name="secretKeyRing">The key ring to be removed.</param>
		/// <returns>A new <c>PgpSecretKeyRingBundle</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 PgpSecretKeyRingBundle RemoveSecretKeyRing(
            PgpSecretKeyRingBundle  bundle,
            PgpSecretKeyRing        secretKeyRing)
        {
            long key = secretKeyRing.GetPublicKey().KeyId;

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

            IDictionary newSecretRings = Platform.CreateHashtable(bundle.secretRings);
            IList newOrder = Platform.CreateArrayList(bundle.order);

			newSecretRings.Remove(key);
			newOrder.Remove(key);

			return new PgpSecretKeyRingBundle(newSecretRings, newOrder);
        }
Esempio n. 26
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);
		}
Esempio n. 27
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();
        }
Esempio n. 28
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)
        {
        }
        public static PgpSecretKeyRingBundle RemoveSecretKeyRing(PgpSecretKeyRingBundle bundle, PgpSecretKeyRing secretKeyRing)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            long keyId = secretKeyRing.GetPublicKey().KeyId;

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

            global::System.Collections.IList list = Platform.CreateArrayList((global::System.Collections.ICollection)bundle.order);
            val.Remove((object)keyId);
            list.Remove((object)keyId);
            return(new PgpSecretKeyRingBundle(val, list));
        }
        /// <summary>Returns a new key ring with the secret key passed in removed from the key ring.</summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be removed.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c>, or null if secKey is not found.</returns>
        public static PgpSecretKeyRing RemoveSecretKey(PgpSecretKeyRing secRing, PgpSecretKey secKey)
        {
            var keys = Platform.CreateArrayList(secRing._keys);
            var found = false;

            for (var i = 0; i < keys.Count; i++)
            {
                var key = keys[i];
                if (key.KeyId != secKey.KeyId)
                    continue;

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

            return found ? new PgpSecretKeyRing(keys, secRing._extraPubKeys) : null;
        }
Esempio n. 31
0
        /// <summary>
        /// Returns a new key ring with the secret key passed in either added or
        /// replacing an existing one with the same key ID.
        /// </summary>
        /// <param name="secRing">The secret key ring to be modified.</param>
        /// <param name="secKey">The secret key to be inserted.</param>
        /// <returns>A new <c>PgpSecretKeyRing</c></returns>
        public static PgpSecretKeyRing InsertSecretKey(
            PgpSecretKeyRing  secRing,
            PgpSecretKey      secKey)
        {
            ArrayList keys = new ArrayList(secRing.keys);
            bool found = false;

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

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

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

            return new PgpSecretKeyRing(keys);
        }
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in secret key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpSecretKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="secretKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpSecretKeyRingBundle</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 PgpSecretKeyRingBundle AddSecretKeyRing(
            PgpSecretKeyRingBundle  bundle,
            PgpSecretKeyRing        secretKeyRing)
        {
            long key = secretKeyRing.GetPublicKey().KeyId;

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

            IDictionary newSecretRings = new Hashtable(bundle.secretRings);
            ArrayList newOrder = new ArrayList(bundle.order);

            newSecretRings[key] = secretKeyRing;
            newOrder.Add(key);

            return new PgpSecretKeyRingBundle(newSecretRings, newOrder);
        }
Esempio n. 33
0
		/// <summary>
		/// Imports a secret pgp keyring.
		/// </summary>
		/// <remarks>
		/// Imports a secret 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 (PgpSecretKeyRing keyring)
		{
			if (keyring == null)
				throw new ArgumentNullException (nameof (keyring));

			if (SecretKeyRingBundle.Contains (keyring.GetSecretKey ().KeyId))
				return;

			SecretKeyRingBundle = PgpSecretKeyRingBundle.AddSecretKeyRing (SecretKeyRingBundle, keyring);
			SaveSecretKeyRingBundle ();
		}
Esempio n. 34
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)
 {
 }
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in secret key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpSecretKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="secretKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpSecretKeyRingBundle</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 PgpSecretKeyRingBundle AddSecretKeyRing(PgpSecretKeyRingBundle bundle, PgpSecretKeyRing secretKeyRing)
        {
            var key = secretKeyRing.GetPublicKey().KeyId;

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

            var newSecretRings = Platform.CreateHashtable(bundle._secretRings);
            var newOrder = Platform.CreateArrayList(bundle._order);

            newSecretRings[key] = secretKeyRing;
            newOrder.Add(key);

            return new PgpSecretKeyRingBundle(newSecretRings, newOrder);
        }