2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-07-22 18:15:19 +00:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2015-07-22 18:15:19 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-07-22 18:15:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const SecretOTPType = "secret_otp_type"
|
|
|
|
|
|
|
|
func secretOTP(b *backend) *framework.Secret {
|
|
|
|
return &framework.Secret{
|
|
|
|
Type: SecretOTPType,
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
2021-04-08 16:43:39 +00:00
|
|
|
"otp": {
|
2015-07-22 18:15:19 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "One time password",
|
|
|
|
},
|
|
|
|
},
|
2016-01-29 22:44:09 +00:00
|
|
|
|
|
|
|
Revoke: b.secretOTPRevoke,
|
2015-07-22 18:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) secretOTPRevoke(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
2015-07-22 18:15:19 +00:00
|
|
|
otpRaw, ok := req.Secret.InternalData["otp"]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("secret is missing internal data")
|
|
|
|
}
|
|
|
|
otp, ok := otpRaw.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("secret is missing internal data")
|
|
|
|
}
|
|
|
|
|
2018-03-08 19:21:11 +00:00
|
|
|
salt, err := b.Salt(ctx)
|
2017-05-09 21:51:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
err = req.Storage.Delete(ctx, "otp/"+salt.SaltID(otp))
|
2015-07-22 18:15:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|