Skip to content

Commit

Permalink
Merge #93: Improve GetAttributeValue+FindObjectsInit tracing
Browse files Browse the repository at this point in the history
5dc5898 Trace FindObjectsInit (Jeremy Rand)
7dc4b42 p11mod: Friendly trace for GetAttributeValue query (Jeremy Rand)

Pull request description:

  Refs #58

Top commit has no ACKs.

Tree-SHA512: 74a083216a68d6cb56736e7b7d892add4359ae5762246ff13c6582dff16021b0be1978c3573b434a1c1ed349d1b20eff5fce7eef09f9936ef00726212ecc5193
  • Loading branch information
Jeremy Rand committed Aug 10, 2022
2 parents 464e518 + 5dc5898 commit b71ecf8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion p11mod/p11mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func (ll *llBackend) GetAttributeValue(sh pkcs11.SessionHandle, oh pkcs11.Object
result := make([]*pkcs11.Attribute, len(a))
for i, t := range a {
if trace {
log.Printf("p11mod GetAttributeValue: Type %d", t.Type)
log.Printf("p11mod GetAttributeValue: querying %s", pkcs11mod.AttrTrace(t))
}

value, err := object.Attribute(t.Type)
Expand Down
14 changes: 14 additions & 0 deletions pkcs11mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,27 @@ func Go_SetAttributeValue(sessionHandle C.CK_SESSION_HANDLE, hObject C.CK_OBJECT

//export Go_FindObjectsInit
func Go_FindObjectsInit(sessionHandle C.CK_SESSION_HANDLE, pTemplate C.CK_ATTRIBUTE_PTR, ulCount C.CK_ULONG) C.CK_RV {
if trace {
log.Println("pkcs11mod FindObjectsInit")
}

if pTemplate == nil && ulCount > 0 {
if trace {
log.Println("pkcs11mod FindObjectsInit: CKR_ARGUMENTS_BAD")
}

return C.CKR_ARGUMENTS_BAD
}

goSessionHandle := pkcs11.SessionHandle(sessionHandle)
goTemplate := toTemplate(pTemplate, ulCount)

if trace {
for _, attr := range goTemplate {
log.Printf("pkcs11mod FindObjectsInit: template %s", AttrTrace(attr))
}
}

err := backend.FindObjectsInit(goSessionHandle, goTemplate)
return fromError(err)
}
Expand Down
4 changes: 2 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func fromTemplate(template []*pkcs11.Attribute, clist C.CK_ATTRIBUTE_PTR) error
bufferTooSmall := false
for i, x := range template {
if trace {
log.Printf("pkcs11mod fromTemplate: %s", attrTrace(x))
log.Printf("pkcs11mod fromTemplate: %s", AttrTrace(x))
}

c := l1[i]
Expand Down Expand Up @@ -371,7 +371,7 @@ var strCKA = map[uint]string{
pkcs11.CKA_CERT_MD5_HASH:"CKA_CERT_MD5_HASH",
}

func attrTrace(a *pkcs11.Attribute) string {
func AttrTrace(a *pkcs11.Attribute) string {
t, ok := strCKA[a.Type]
if !ok {
t = fmt.Sprintf("%d", a.Type)
Expand Down

0 comments on commit b71ecf8

Please sign in to comment.