2015-05-28 21:37:20 +00:00
|
|
|
package api
|
|
|
|
|
2018-08-14 19:29:22 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
2018-07-24 22:49:55 +00:00
|
|
|
|
2015-05-28 21:37:20 +00:00
|
|
|
func (c *Sys) RekeyStatus() (*RekeyStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/rekey/init")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2015-05-28 21:37:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Sys) RekeyRecoveryKeyStatus() (*RekeyStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/rekey-recovery-key/init")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2018-05-20 06:42:15 +00:00
|
|
|
func (c *Sys) RekeyVerificationStatus() (*RekeyVerificationStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/rekey/verify")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2018-05-20 06:42:15 +00: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) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/rekey-recovery-key/verify")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2018-05-20 06:42:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyVerificationStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:24:36 +00:00
|
|
|
func (c *Sys) RekeyInit(config *RekeyInitRequest) (*RekeyStatusResponse, error) {
|
2015-05-28 21:37:20 +00:00
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/rekey/init")
|
|
|
|
if err := r.SetJSONBody(config); err != nil {
|
2016-02-12 19:24:36 +00:00
|
|
|
return nil, err
|
2015-05-28 21:37:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-02-12 19:24:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-05-28 21:37:20 +00:00
|
|
|
}
|
2016-02-12 19:24:36 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
2015-05-28 21:37:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Sys) RekeyRecoveryKeyInit(config *RekeyInitRequest) (*RekeyStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/rekey-recovery-key/init")
|
|
|
|
if err := r.SetJSONBody(config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:37:20 +00:00
|
|
|
func (c *Sys) RekeyCancel() error {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/rekey/init")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2015-05-28 21:37:20 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Sys) RekeyRecoveryKeyCancel() error {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/rekey-recovery-key/init")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-20 06:42:15 +00:00
|
|
|
func (c *Sys) RekeyVerificationCancel() error {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/rekey/verify")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2018-05-20 06:42:15 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) RekeyRecoveryKeyVerificationCancel() error {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/rekey-recovery-key/verify")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2018-05-20 06:42:15 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-12-16 21:56:15 +00:00
|
|
|
func (c *Sys) RekeyUpdate(shard, nonce string) (*RekeyUpdateResponse, error) {
|
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
2015-05-28 21:37:20 +00:00
|
|
|
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/rekey/update")
|
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2015-05-28 21:37:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Sys) RekeyRecoveryKeyUpdate(shard, nonce string) (*RekeyUpdateResponse, error) {
|
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/rekey-recovery-key/update")
|
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-01-08 19:09:40 +00:00
|
|
|
func (c *Sys) RekeyRetrieveBackup() (*RekeyRetrieveResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/rekey/backup")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2015-12-16 21:56:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2018-08-14 19:29:22 +00: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-16 21:56:15 +00:00
|
|
|
var result RekeyRetrieveResponse
|
2018-08-14 19:29:22 +00:00
|
|
|
err = mapstructure.Decode(secret.Data, &result)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-12-16 21:56:15 +00:00
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Sys) RekeyRetrieveRecoveryBackup() (*RekeyRetrieveResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/rekey/recovery-backup")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2018-08-14 19:29:22 +00: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 14:44:22 +00:00
|
|
|
var result RekeyRetrieveResponse
|
2018-08-14 19:29:22 +00:00
|
|
|
err = mapstructure.Decode(secret.Data, &result)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-01-08 19:09:40 +00:00
|
|
|
func (c *Sys) RekeyDeleteBackup() error {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/rekey/backup")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2015-12-16 21:56:15 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Sys) RekeyDeleteRecoveryBackup() error {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/rekey/recovery-backup")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-20 06:42:15 +00:00
|
|
|
func (c *Sys) RekeyVerificationUpdate(shard, nonce string) (*RekeyVerificationUpdateResponse, error) {
|
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/rekey/verify")
|
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2018-05-20 06:42:15 +00: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) {
|
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/rekey-recovery-key/verify")
|
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2018-05-20 06:42:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result RekeyVerificationUpdateResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:37:20 +00:00
|
|
|
type RekeyInitRequest struct {
|
2018-05-20 03:43:48 +00: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-28 21:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyStatusResponse struct {
|
2018-05-20 03:43:48 +00: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 20:13:08 +00:00
|
|
|
VerificationNonce string `json:"verification_nonce"`
|
2015-05-28 21:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyUpdateResponse struct {
|
2018-05-20 03:43:48 +00: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-16 21:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyRetrieveResponse struct {
|
2018-08-14 19:29:22 +00: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-28 21:37:20 +00:00
|
|
|
}
|
2018-05-20 03:43:48 +00:00
|
|
|
|
|
|
|
type RekeyVerificationStatusResponse struct {
|
|
|
|
Nonce string `json:"nonce"`
|
2018-05-28 04:39:53 +00:00
|
|
|
Started bool `json:"started"`
|
2018-05-20 03:43:48 +00:00
|
|
|
T int `json:"t"`
|
|
|
|
N int `json:"n"`
|
|
|
|
Progress int `json:"progress"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RekeyVerificationUpdateResponse struct {
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
Complete bool `json:"complete"`
|
|
|
|
}
|