Skip to content

Commit

Permalink
p11kit: allow servers to overwrite generated object CK_OBJECT_HANDLE
Browse files Browse the repository at this point in the history
  • Loading branch information
joelferrier authored and ericchiang committed Jun 3, 2022
1 parent e9ff994 commit 29bc85e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions p11kit/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func (o *Object) matches(tmpl attribute) bool {
return false
}

// SetID assigns a pre-determined identifier for an object, overriding the
// random one generated by this package. This is required for some clients,
// such as Chrome, to identify the same object over multiple sessions.
//
// SetID should only be required when combined with Slot.GetObjects.
func (o *Object) SetID(id uint64) {
o.id = id
}

// SetLabel applies a label to the object, allowing clients to differentiate
// between different objects of the same type on a single slot.
func (o *Object) SetLabel(label string) {
Expand Down
31 changes: 31 additions & 0 deletions p11kit/p11kit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,29 @@ func newTestServer(t *testing.T) *Handler {
if err := ecdsaPrivObj.SetCertificate(ecdsaCert); err != nil {
t.Fatalf("ecdsaPrivObject.SetCertificate failed: %v", err)
}
ecdsaCertObj2, ecdsaCert2 := parseCert(t, testECDSACert)
ecdsaPubObj2 := parsePub(t, testECDSAPrivKey)
ecdsaPrivObj2 := parsePriv(t, testECDSAPrivKey)
if err := ecdsaPubObj2.SetCertificate(ecdsaCert2); err != nil {
t.Fatalf("ecdsaPubObject.SetCertificate failed: %v", err)
}
if err := ecdsaPrivObj2.SetCertificate(ecdsaCert2); err != nil {
t.Fatalf("ecdsaPrivObject2.SetCertificate failed: %v", err)
}

rsaCertObj.SetLabel("foo")
rsaPubObj.SetLabel("foo")
rsaPrivObj.SetLabel("fookey")
ecdsaCertObj.SetLabel("bar")
ecdsaPubObj.SetLabel("bar")
ecdsaPrivObj.SetLabel("barkey")
ecdsaCertObj2.SetLabel("baz")
ecdsaPubObj2.SetLabel("baz")
ecdsaPrivObj2.SetLabel("bazkey")

ecdsaCertObj2.SetID(1)
ecdsaPubObj2.SetID(2)
ecdsaPrivObj2.SetID(3)

objects := []Object{
rsaCertObj,
Expand All @@ -225,6 +241,11 @@ func newTestServer(t *testing.T) *Handler {
ecdsaPubObj,
ecdsaPrivObj,
}
objects3 := []Object{
ecdsaCertObj2,
ecdsaPubObj2,
ecdsaPrivObj2,
}

hwVersion := Version{0x01, 0x01}
fwVersion := Version{0x02, 0x02}
Expand Down Expand Up @@ -256,6 +277,16 @@ func newTestServer(t *testing.T) *Handler {
FirmwareVersion: fwVersion,
Objects: objects2,
},
{
ID: 0x03,
Label: "slot-0x03",
Manufacturer: "test_man",
Model: "test_model",
Serial: "serial-0x03",
HardwareVersion: hwVersion,
FirmwareVersion: fwVersion,
Objects: objects3,
},
},
}
}
Expand Down

0 comments on commit 29bc85e

Please sign in to comment.