Skip to content

Commit

Permalink
Merge pull request #27 from Seagate/FMW-74138_Refactor_Rekey_for_KMIP…
Browse files Browse the repository at this point in the history
…_2.0

FMW-74138: Refactor Rekey and SetAttribute for KMIP 2.0
  • Loading branch information
BoonKhoonSim authored Dec 18, 2024
2 parents 184c125 + 287aafb commit f39891a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
47 changes: 47 additions & 0 deletions kmip20/op_rekey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package kmip20

import (
"context"
"time"

"github.com/Seagate/kmip-go"
)

// 6.1.42 Re-key

// Table 278

type ReKeyRequestPayload struct {
UniqueIdentifier *UniqueIdentifierValue
Offset time.Time `ttlv:",omitempty"`
Attributes interface{} `ttlv:",omitempty"`
ProtectionStorageMasks ProtectionStorageMask `ttlv:",omitempty"`
}

// Table 280

type ReKeyResponsePayload struct {
UniqueIdentifier string
}

type ReKeyHandler struct {
ReKey func(ctx context.Context, payload *ReKeyRequestPayload) (*ReKeyResponsePayload, error)
}

func (h *ReKeyHandler) HandleItem(ctx context.Context, req *kmip.Request) (*kmip.ResponseBatchItem, error) {
var payload ReKeyRequestPayload

err := req.DecodePayload(&payload)
if err != nil {
return nil, err
}

respPayload, err := h.ReKey(ctx, &payload)
if err != nil {
return nil, err
}

return &kmip.ResponseBatchItem{
ResponsePayload: respPayload,
}, nil
}
2 changes: 1 addition & 1 deletion kmip20/op_setattribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type SetAttributeRequestPayload struct {
UniqueIdentifier *UniqueIdentifierValue
NewAttribute Attributes `ttlv:"DerivationData"`
NewAttribute interface{}
}

// Table 297
Expand Down
27 changes: 15 additions & 12 deletions src/kmipapi/kmip20.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func (kmips *kmip20service) GetKey(ctx context.Context, connection *tls.Conn, se

if respPayload.SymmetricKey != nil {
if respPayload.SymmetricKey.KeyBlock.KeyValue != nil {
// keybytes := memguard.NewBuffer(64)
if bytes, ok := respPayload.SymmetricKey.KeyBlock.KeyValue.KeyMaterial.([]byte); ok {
// convert byes to an encoded string
keybytes := hex.EncodeToString(bytes)
Expand Down Expand Up @@ -507,16 +506,22 @@ func (kmips *kmip20service) Locate(ctx context.Context, connection *tls.Conn, se
// SetAttribute:
func (kmips *kmip20service) SetAttribute(ctx context.Context, connection *tls.Conn, settings *ConfigurationSettings, req *SetAttributeRequest) (*SetAttributeResponse, error) {
logger := ctx.Value(common.LoggerKey).(*slog.Logger)
logger.Debug("====== set attribute ======", "uid", req.UniqueIdentifier, "value", req.AttributeValue)
logger.Debug("====== set attribute ======", "uid", req.UniqueIdentifier, "name", req.AttributeName, "value", req.AttributeValue)

type newAttribute struct {
AttributeName string
AttributeValue string
}
payload := kmip20.SetAttributeRequestPayload{
UniqueIdentifier: &kmip20.UniqueIdentifierValue{
Text: req.UniqueIdentifier,
Enum: 0,
Index: 0,
},
// FIXME AttributeName: req.AttributeName,
// FIXME AttributeValue: req.AttributeValue,
NewAttribute: newAttribute{
AttributeName: req.AttributeName,
AttributeValue: req.AttributeValue,
},
}

decoder, item, err := SendRequestMessage(ctx, connection, settings, uint32(kmip20.OperationSetAttribute), &payload, false)
Expand All @@ -541,15 +546,13 @@ func (kmips *kmip20service) ReKey(ctx context.Context, connection *tls.Conn, set
logger := ctx.Value(common.LoggerKey).(*slog.Logger)
logger.Debug("====== rekey ======", "uid", req.UniqueIdentifier)

payload := kmip.ReKeyRequestPayload{
UniqueIdentifier: "FIXME",
payload := kmip20.ReKeyRequestPayload{
UniqueIdentifier: &kmip20.UniqueIdentifierValue{
Text: req.UniqueIdentifier,
Enum: 0,
Index: 0,
},
}
// FIXME UniqueIdentifier: kmip20.UniqueIdentifierValue{
// FIXME Text: req.UniqueIdentifier,
// FIXME Enum: 0,
// FIXME Index: 0,
// FIXME },
// FIXME }

decoder, item, err := SendRequestMessage(ctx, connection, settings, uint32(kmip20.OperationReKey), &payload, false)
if err != nil {
Expand Down

0 comments on commit f39891a

Please sign in to comment.