示例#1
0
        /// <summary>
        /// Generates a new key for the account. (Account keys are managed by the CSP.)
        /// </summary>
        /// <param name="AccountLocation">URL of the account resource.</param>
        public async Task <AcmeAccount> NewKey(Uri AccountLocation)
        {
            if (this.directory == null)
            {
                await this.GetDirectory();
            }
            RSA NewKey = RSA.Create();

            NewKey.KeySize = KeySize;

            if (NewKey.KeySize != KeySize)              // Happens when using library from traditioanl .NET FW
            {
                Type T = Runtime.Inventory.Types.GetType("System.Security.Cryptography.RSACryptoServiceProvider");
                if (T == null)
                {
                    throw new Exception("Unable to set RSA key size to anything but default (" + NewKey.KeySize.ToString() + " bits).");
                }

                NewKey = Activator.CreateInstance(T, KeySize) as RSA;
            }

            RsaSsaPkcsSha256 Jws2 = new RsaSsaPkcsSha256(NewKey);

            try
            {
                Jws2.Sign(new KeyValuePair <string, object>[]
                {
                    new KeyValuePair <string, object>("url", this.directory.KeyChange.ToString())
                }, new KeyValuePair <string, object>[]
                {
                    new KeyValuePair <string, object>("account", AccountLocation.ToString()),
                    new KeyValuePair <string, object>("oldkey", this.jws.PublicWebKey),
                }, out string Header, out string Payload, out string Signature);

                AcmeResponse Response = await this.POST(this.directory.KeyChange, AccountLocation,
                                                        new KeyValuePair <string, object>("protected", Header),
                                                        new KeyValuePair <string, object>("payload", Payload),
                                                        new KeyValuePair <string, object>("signature", Signature));

                this.jwkThumbprint = null;
                this.jws.ImportKey(NewKey);

                return(new AcmeAccount(this, Response.Location, Response.Payload));
            }
            finally
            {
                Jws2.Dispose();
            }
        }
示例#2
0
        /// <summary>
        /// Generates a new key for the account. (Account keys are managed by the CSP.)
        /// </summary>
        /// <param name="AccountLocation">URL of the account resource.</param>
        public async Task <AcmeAccount> NewKey(Uri AccountLocation)
        {
            if (this.directory == null)
            {
                await this.GetDirectory();
            }

            RSACryptoServiceProvider NewKey = new RSACryptoServiceProvider(KeySize);
            RsaSsaPkcsSha256         Jws2   = new RsaSsaPkcsSha256(NewKey);

            try
            {
                Jws2.Sign(new KeyValuePair <string, object>[]
                {
                    new KeyValuePair <string, object>("url", this.directory.KeyChange.ToString())
                }, new KeyValuePair <string, object>[]
                {
                    new KeyValuePair <string, object>("account", AccountLocation.ToString()),
                    new KeyValuePair <string, object>("newkey", Jws2.PublicWebKey)
                }, out string Header, out string Payload, out string Signature);

                AcmeResponse Response = await this.POST(this.directory.KeyChange, AccountLocation,
                                                        new KeyValuePair <string, object>("protected", Header),
                                                        new KeyValuePair <string, object>("payload", Payload),
                                                        new KeyValuePair <string, object>("signature", Signature));

                this.jwkThumbprint = null;
                this.jws.ImportKey(NewKey);

                return(new AcmeAccount(this, Response.Location, Response.Payload));
            }
            finally
            {
                Jws2.Dispose();
            }
        }