2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-05-29 00:37:20 +03:00
|
|
|
package api
|
|
|
|
|
2018-08-14 22:29:22 +03:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2022-03-24 20:58:03 +03:00
|
|
|
"net/http"
|
2018-08-14 22:29:22 +03:00
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2015-05-29 00:37:20 +03:00
|
|
|
func (c *Sys) RekeyStatus() (*RekeyStatusResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyStatusWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyStatusWithContext(ctx context.Context) (*RekeyStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/init")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2015-05-29 00:37:20 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyStatus() (*RekeyStatusResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyStatusWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyStatusWithContext(ctx context.Context) (*RekeyStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey-recovery-key/init")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-04-04 17:44:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2018-05-20 09:42:15 +03:00
|
|
|
func (c *Sys) RekeyVerificationStatus() (*RekeyVerificationStatusResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyVerificationStatusWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyVerificationStatusWithContext(ctx context.Context) (*RekeyVerificationStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/verify")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2018-05-20 09:42:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyVerificationStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationStatus() (*RekeyVerificationStatusResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyVerificationStatusWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationStatusWithContext(ctx context.Context) (*RekeyVerificationStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey-recovery-key/verify")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2018-05-20 09:42:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyVerificationStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-02-12 22:24:36 +03:00
|
|
|
func (c *Sys) RekeyInit(config *RekeyInitRequest) (*RekeyStatusResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyInitWithContext(context.Background(), config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyInitWithContext(ctx context.Context, config *RekeyInitRequest) (*RekeyStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey/init")
|
2015-05-29 00:37:20 +03:00
|
|
|
if err := r.SetJSONBody(config); err != nil {
|
2016-02-12 22:24:36 +03:00
|
|
|
return nil, err
|
2015-05-29 00:37:20 +03:00
|
|
|
}
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-02-12 22:24:36 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-05-29 00:37:20 +03:00
|
|
|
}
|
2016-02-12 22:24:36 +03:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
2015-05-29 00:37:20 +03:00
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyInit(config *RekeyInitRequest) (*RekeyStatusResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyInitWithContext(context.Background(), config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyInitWithContext(ctx context.Context, config *RekeyInitRequest) (*RekeyStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey-recovery-key/init")
|
2016-04-04 17:44:22 +03:00
|
|
|
if err := r.SetJSONBody(config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-04-04 17:44:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2015-05-29 00:37:20 +03:00
|
|
|
func (c *Sys) RekeyCancel() error {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyCancelWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyCancelWithContext(ctx context.Context) error {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/init")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2015-05-29 00:37:20 +03:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyCancel() error {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyCancelWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyCancelWithContext(ctx context.Context) error {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey-recovery-key/init")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-04-04 17:44:22 +03:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-20 09:42:15 +03:00
|
|
|
func (c *Sys) RekeyVerificationCancel() error {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyVerificationCancelWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyVerificationCancelWithContext(ctx context.Context) error {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/verify")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2018-05-20 09:42:15 +03:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationCancel() error {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyVerificationCancelWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationCancelWithContext(ctx context.Context) error {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey-recovery-key/verify")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2018-05-20 09:42:15 +03:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-12-17 00:56:15 +03:00
|
|
|
func (c *Sys) RekeyUpdate(shard, nonce string) (*RekeyUpdateResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyUpdateWithContext(context.Background(), shard, nonce)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyUpdateWithContext(ctx context.Context, shard, nonce string) (*RekeyUpdateResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2015-12-17 00:56:15 +03:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
2015-05-29 00:37:20 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey/update")
|
2015-05-29 00:37:20 +03:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2015-05-29 00:37:20 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
func (c *Sys) RekeyRecoveryKeyUpdate(shard, nonce string) (*RekeyUpdateResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyUpdateWithContext(context.Background(), shard, nonce)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyUpdateWithContext(ctx context.Context, shard, nonce string) (*RekeyUpdateResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey-recovery-key/update")
|
2016-04-04 17:44:22 +03:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-04-04 17:44:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-01-08 22:09:40 +03:00
|
|
|
func (c *Sys) RekeyRetrieveBackup() (*RekeyRetrieveResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRetrieveBackupWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyRetrieveBackupWithContext(ctx context.Context) (*RekeyRetrieveResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/backup")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2015-12-17 00:56:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2018-08-14 22:29:22 +03:00
|
|
|
secret, err := ParseSecret(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if secret == nil || secret.Data == nil {
|
|
|
|
return nil, errors.New("data from server response is empty")
|
|
|
|
}
|
|
|
|
|
2015-12-17 00:56:15 +03:00
|
|
|
var result RekeyRetrieveResponse
|
2018-08-14 22:29:22 +03:00
|
|
|
err = mapstructure.Decode(secret.Data, &result)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-12-17 00:56:15 +03:00
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
func (c *Sys) RekeyRetrieveRecoveryBackup() (*RekeyRetrieveResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRetrieveRecoveryBackupWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyRetrieveRecoveryBackupWithContext(ctx context.Context) (*RekeyRetrieveResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/rekey/recovery-key-backup")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-04-04 17:44:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2018-08-14 22:29:22 +03:00
|
|
|
secret, err := ParseSecret(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if secret == nil || secret.Data == nil {
|
|
|
|
return nil, errors.New("data from server response is empty")
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
var result RekeyRetrieveResponse
|
2018-08-14 22:29:22 +03:00
|
|
|
err = mapstructure.Decode(secret.Data, &result)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-01-08 22:09:40 +03:00
|
|
|
func (c *Sys) RekeyDeleteBackup() error {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyDeleteBackupWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyDeleteBackupWithContext(ctx context.Context) error {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/backup")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2015-12-17 00:56:15 +03:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:44:22 +03:00
|
|
|
func (c *Sys) RekeyDeleteRecoveryBackup() error {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyDeleteRecoveryBackupWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) RekeyDeleteRecoveryBackupWithContext(ctx context.Context) error {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodDelete, "/v1/sys/rekey/recovery-key-backup")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2016-04-04 17:44:22 +03:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-20 09:42:15 +03:00
|
|
|
func (c *Sys) RekeyVerificationUpdate(shard, nonce string) (*RekeyVerificationUpdateResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyVerificationUpdateWithContext(context.Background(), shard, nonce)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyVerificationUpdateWithContext(ctx context.Context, shard, nonce string) (*RekeyVerificationUpdateResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2018-05-20 09:42:15 +03:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey/verify")
|
2018-05-20 09:42:15 +03:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2018-05-20 09:42:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyVerificationUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationUpdate(shard, nonce string) (*RekeyVerificationUpdateResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.RekeyRecoveryKeyVerificationUpdateWithContext(context.Background(), shard, nonce)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationUpdateWithContext(ctx context.Context, shard, nonce string) (*RekeyVerificationUpdateResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2018-05-20 09:42:15 +03:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodPut, "/v1/sys/rekey-recovery-key/verify")
|
2018-05-20 09:42:15 +03:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2018-05-20 09:42:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyVerificationUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2015-05-29 00:37:20 +03:00
|
|
|
type RekeyInitRequest struct {
|
2018-05-20 06:43:48 +03:00
|
|
|
SecretShares int `json:"secret_shares"`
|
|
|
|
SecretThreshold int `json:"secret_threshold"`
|
|
|
|
StoredShares int `json:"stored_shares"`
|
|
|
|
PGPKeys []string `json:"pgp_keys"`
|
|
|
|
Backup bool
|
|
|
|
RequireVerification bool `json:"require_verification"`
|
2015-05-29 00:37:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyStatusResponse struct {
|
2018-05-20 06:43:48 +03:00
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
Started bool `json:"started"`
|
|
|
|
T int `json:"t"`
|
|
|
|
N int `json:"n"`
|
|
|
|
Progress int `json:"progress"`
|
|
|
|
Required int `json:"required"`
|
|
|
|
PGPFingerprints []string `json:"pgp_fingerprints"`
|
|
|
|
Backup bool `json:"backup"`
|
|
|
|
VerificationRequired bool `json:"verification_required"`
|
2018-05-29 23:13:08 +03:00
|
|
|
VerificationNonce string `json:"verification_nonce"`
|
2015-05-29 00:37:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyUpdateResponse struct {
|
2018-05-20 06:43:48 +03:00
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
Complete bool `json:"complete"`
|
|
|
|
Keys []string `json:"keys"`
|
|
|
|
KeysB64 []string `json:"keys_base64"`
|
|
|
|
PGPFingerprints []string `json:"pgp_fingerprints"`
|
|
|
|
Backup bool `json:"backup"`
|
|
|
|
VerificationRequired bool `json:"verification_required"`
|
|
|
|
VerificationNonce string `json:"verification_nonce,omitempty"`
|
2015-12-17 00:56:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyRetrieveResponse struct {
|
2018-08-14 22:29:22 +03:00
|
|
|
Nonce string `json:"nonce" mapstructure:"nonce"`
|
|
|
|
Keys map[string][]string `json:"keys" mapstructure:"keys"`
|
|
|
|
KeysB64 map[string][]string `json:"keys_base64" mapstructure:"keys_base64"`
|
2015-05-29 00:37:20 +03:00
|
|
|
}
|
2018-05-20 06:43:48 +03:00
|
|
|
|
|
|
|
type RekeyVerificationStatusResponse struct {
|
|
|
|
Nonce string `json:"nonce"`
|
2018-05-28 07:39:53 +03:00
|
|
|
Started bool `json:"started"`
|
2018-05-20 06:43:48 +03:00
|
|
|
T int `json:"t"`
|
|
|
|
N int `json:"n"`
|
|
|
|
Progress int `json:"progress"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyVerificationUpdateResponse struct {
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
Complete bool `json:"complete"`
|
|
|
|
}
|