Exemple #1
0
        // TODO: handle "Change of TOS" error response
        //    https://tools.ietf.org/html/draft-ietf-acme-acme-12#section-7.3.4


        /// <summary>
        /// Rotates the current Public key that is associated with this Account by the
        /// target ACME CA with a new Public key.  If successful, updates the current
        /// Account key pair registered with the client.
        /// </summary>
        /// <remarks>
        /// https://tools.ietf.org/html/draft-ietf-acme-acme-18#section-7.3.5
        /// </remarks>
        public async Task <AccountDetails> ChangeAccountKeyAsync(IJwsTool newSigner,
                                                                 CancellationToken cancel = default(CancellationToken))
        {
            if (Account == null)
            {
                Signer = newSigner;
                return(null);
            }

            var requUrl = new Uri(_http.BaseAddress, Directory.KeyChange);
            var message = new KeyChangeRequest
            {
                Account = Account.Kid,
                OldKey  = Signer.ExportJwk(),
            };
            var innerPayload = ComputeAcmeSigned(message, requUrl.ToString(),
                                                 signer: newSigner, includePublicKey: true, excludeNonce: true);
            var resp = await SendAcmeAsync(
                requUrl,
                method : HttpMethod.Post,
                message : innerPayload,
                cancel : cancel);

            Signer = newSigner;

            return(await DecodeAccountResponseAsync(resp, existing : Account));
        }
Exemple #2
0
        public object ChangeApiKey([FromBody] KeyChangeRequest req)
        {
            var username = CurrentUserName;

            Audit("Change API key for user {0}", username);

            try
            {
                req.Key = Store.ChangeApiKey(username, req.Key);
                return(req);
            }
            catch (UserNotFoundException)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User " + username + " not found."));
            }
            catch (UserPermissionException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, ex.Message));
            }
        }