Skip to content

Commit

Permalink
Merge pull request #21 from Seagate/feat/batchcount2
Browse files Browse the repository at this point in the history
Refactor Batch Commands
  • Loading branch information
BoonKhoonSim authored Jan 27, 2023
2 parents 896b42b + 16aff15 commit 77de15e
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 190 deletions.
9 changes: 5 additions & 4 deletions kmip20/op_getattributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kmip20

import (
"context"

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

Expand All @@ -10,15 +11,15 @@ import (
// Table 196

type GetAttributesRequestPayload struct {
UniqueIdentifier *UniqueIdentifierValue // Required: No
Attributes interface{} // Required: No
UniqueIdentifier *UniqueIdentifierValue // Required: No
Attributes interface{} // Required: No
}

// Table 197

type GetAttributesResponsePayload struct {
UniqueIdentifier string // Required: Yes
Attributes interface{} // Required: No
UniqueIdentifier string // Required: Yes
Attributes interface{} // Required: No
}

type GetAttributesHandler struct {
Expand Down
24 changes: 12 additions & 12 deletions kmip20/op_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ import (
// Table 169

type RegisterRequestPayload struct {
ObjectType kmip14.ObjectType
Attributes interface{}
Certificate *kmip.Certificate
SymmetricKey *kmip.SymmetricKey
PrivateKey *kmip.PrivateKey
PublicKey *kmip.PublicKey
SplitKey *kmip.SplitKey
Template *kmip.Template
SecretData *kmip.SecretData
OpaqueObject *kmip.OpaqueObject
ProtectionStorageMasks uint32
ObjectType kmip14.ObjectType
Attributes interface{}
Certificate *kmip.Certificate
SymmetricKey *kmip.SymmetricKey
PrivateKey *kmip.PrivateKey
PublicKey *kmip.PublicKey
SplitKey *kmip.SplitKey
Template *kmip.Template
SecretData *kmip.SecretData
OpaqueObject *kmip.OpaqueObject
ProtectionStorageMasks uint32
}

// Table 170

type RegisterResponsePayload struct {
UniqueIdentifier string
UniqueIdentifier string
}

type RegisterHandler struct {
Expand Down
3 changes: 2 additions & 1 deletion op_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (h *CreateHandler) HandleItem(ctx context.Context, req *Request) (*Response

idAttr := respPayload.TemplateAttribute.GetTag(kmip14.TagUniqueIdentifier)

req.IDPlaceholder, ok = idAttr.AttributeValue.(string)
// req.IDPlaceholder, ok = idAttr.AttributeValue.(string)
req.IDPlaceholder = respPayload.UniqueIdentifier
if !ok {
return nil, merry.Errorf("invalid response returned by CreateHandler: unique identifier tag in attributes should have been a string, was %t", idAttr.AttributeValue)
}
Expand Down
1 change: 1 addition & 0 deletions op_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (h *DestroyHandler) HandleItem(ctx context.Context, req *Request) (*Respons
}

// req.Key = respPayload.Key
req.IDPlaceholder = respPayload.UniqueIdentifier

return &ResponseBatchItem{
ResponsePayload: respPayload,
Expand Down
1 change: 1 addition & 0 deletions op_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (h *GetHandler) HandleItem(ctx context.Context, req *Request) (*ResponseBat
}

// req.Key = respPayload.Key
req.IDPlaceholder = respPayload.UniqueIdentifier

return &ResponseBatchItem{
ResponsePayload: respPayload,
Expand Down
2 changes: 2 additions & 0 deletions op_locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (h *LocateHandler) HandleItem(ctx context.Context, req *Request) (*Response
return nil, err
}

req.IDPlaceholder = respPayload.UniqueIdentifier

return &ResponseBatchItem{
ResponsePayload: respPayload,
}, nil
Expand Down
14 changes: 13 additions & 1 deletion op_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ type QueryRequestPayload struct {
QueryFunction []kmip14.QueryFunction
}

type CapabilityInformation struct {
StreamingCapability bool // Required: No
AsynchronousCapability bool // Required: No
AttestationCapability bool // Required: No
BatchUndoCapability bool // Required: No
BatchContinueCapability bool // Required: No
UnwrapMode kmip14.UnwrapMode // Required: No
DestroyAction kmip14.DestroyAction // Required: No
ShreddingAlgorithm kmip14.ShreddingAlgorithm // Required: No
RNGMode kmip14.RNGMode // Required: No
}

// Table 260

type QueryResponsePayload struct {
Expand All @@ -27,7 +39,7 @@ type QueryResponsePayload struct {
RNGParameters string
ProfileInformation []kmip14.ProfileName
ValidationInformation []kmip14.ValidationAuthorityType
CapabilityInformation []string
CapabilityInformation CapabilityInformation
ClientRegistrationMethod kmip14.ClientRegistrationMethod
DefaultsInformation string
ProtectionStorageMasks string
Expand Down
1 change: 0 additions & 1 deletion op_rekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

// ReKeyRequestPayload ////////////////////////////////////////
//
type ReKeyRequestPayload struct {
UniqueIdentifier string
}
Expand Down
2 changes: 2 additions & 0 deletions op_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func (h *RevokeHandler) HandleItem(ctx context.Context, req *Request) (*Response
return nil, err
}

req.IDPlaceholder = respPayload.UniqueIdentifier

return &ResponseBatchItem{
ResponsePayload: respPayload,
}, nil
Expand Down
1 change: 0 additions & 1 deletion src/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func Initialize() {
"clear": ClearKey,
"register": RegisterKey,
"getattribute": GetAttribute,

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func LocateKey(ctx context.Context, settings *kmipapi.ConfigurationSettings, lin
attribvalue1 := kmipapi.GetValue(line, "attribvalue1")
attribname2 := kmipapi.GetValue(line, "attribname2")
attribvalue2 := kmipapi.GetValue(line, "attribvalue2")

if id == "" && attribvalue2 == "" {
fmt.Printf("locate id, attribname2, and attribvalue2 are required, example: locate id=SASED-M-2-14-name attribname2=ObjectType attribvalue2=SecretData\n")
return
Expand Down Expand Up @@ -246,7 +246,7 @@ func GetAttribute(ctx context.Context, settings *kmipapi.ConfigurationSettings,
return
}
attribname1 := kmipapi.GetValue(line, "attribname1")

uid, err := kmipapi.GetAttribute(ctx, settings, uid, attribname1)
if err != nil {
fmt.Printf("get attribute failed for uid (%s) with error: %v\n", uid, err)
Expand Down
32 changes: 32 additions & 0 deletions src/kmipapi/clientapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,35 @@ func ReKey(ctx context.Context, settings *ConfigurationSettings, uid string) (st

return kmipResp.UniqueIdentifier, nil
}

type (
CreateNullStruct struct{}
RevokeNullStruct struct {
RevocationReason kmip.RevocationReasonStruct // Required: Yes
}
)

type BatchListItem struct {
Operation kmip14.Operation
RequestPayload interface{}
}

func BatchCmdCreateList() []kmip.RequestBatchItem {
var BatchList []kmip.RequestBatchItem
return BatchList
}

func BatchCmdAddItem(ctx context.Context, BatchList []kmip.RequestBatchItem, BatchItems BatchListItem, batchnum []byte, batchcount byte) ([]kmip.RequestBatchItem, []byte, error) {
logger := klog.FromContext(ctx)

batchnum = append(batchnum, byte(batchcount+1))
BatchList = append(BatchList, kmip.RequestBatchItem{
UniqueBatchItemID: batchnum[batchcount : batchcount+1],
Operation: kmip14.Operation(BatchItems.Operation),
RequestPayload: BatchItems.RequestPayload,
},
)
logger.V(2).Info("++ batch cmd add item", "BatchList", BatchList)

return BatchList, batchnum, nil
}
27 changes: 17 additions & 10 deletions src/kmipapi/clientops.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type CreateKeyRequest struct {
Algorithm kmip14.CryptographicAlgorithm
CryptographicLength uint32
CryptographicUsageMask uint32
Operation kmip14.Operation
}

type CreateKeyResponse struct {
Expand All @@ -41,7 +42,8 @@ type CreateKeyResponse struct {

type DeleteKeyRequest struct {
// Contains all attributes of a caller request to delete a KMIP key.
Type kmip14.ObjectType
Type kmip14.ObjectType
Operation kmip14.Operation
}

type DeleteKeyResponse struct {
Expand All @@ -53,6 +55,7 @@ type DeleteKeyResponse struct {
type GetKeyRequest struct {
// Contains all attributes of a caller request to get a KMIP key.
UniqueIdentifier string
Operation kmip14.Operation
}

type GetKeyResponse struct {
Expand All @@ -65,6 +68,7 @@ type GetKeyResponse struct {
type DestroyKeyRequest struct {
// Contains all attributes of a caller request to destroy a KMIP key.
UniqueIdentifier string
Operation kmip14.Operation
}

type DestroyKeyResponse struct {
Expand All @@ -75,6 +79,7 @@ type DestroyKeyResponse struct {
type ActivateKeyRequest struct {
// Contains all attributes of a caller request to activate a KMIP key.
UniqueIdentifier string
Operation kmip14.Operation
}

type ActivateKeyResponse struct {
Expand All @@ -87,6 +92,7 @@ type RevokeKeyRequest struct {
UniqueIdentifier string
RevocationReason uint32
CompromiseDate time.Time // optional
Operation kmip14.Operation
}

type RevokeKeyResponse struct {
Expand Down Expand Up @@ -135,11 +141,12 @@ type GetAttributeResponse struct {

type LocateRequest struct {
// Contains all attributes of a caller request to revoke a KMIP key.
Name string
AttribName1 string
AttribValue1 string
AttribName2 string
AttribValue2 string
Name string
AttribName1 string
AttribValue1 string
AttribName2 string
AttribValue2 string
Operation kmip14.Operation
}

type LocateResponse struct {
Expand All @@ -157,12 +164,12 @@ type QueryRequest struct {
QueryFunction []kmip14.QueryFunction
Id string
}

type QueryResponse struct {
// Contains all attributes of the query response operation that are relevant to the caller.
Operation []kmip14.Operation `json:"Operation,omitempty"`
ObjectType []kmip14.ObjectType `json:"Object Type,omitempty"`
VendorIdentification string `json:"Vendor Identification,omitempty"`
Operation []kmip14.Operation `json:"Operation,omitempty"`
ObjectType []kmip14.ObjectType `json:"Object Type,omitempty"`
VendorIdentification string `json:"Vendor Identification,omitempty"`
CapabilityInformation interface{}
}

type SetAttributeRequest struct {
Expand Down
Loading

0 comments on commit 77de15e

Please sign in to comment.