Skip to content

Commit

Permalink
Get ceritifcate chain associated with private key entry without a pas…
Browse files Browse the repository at this point in the history
…sword
  • Loading branch information
pavlo-v-chernykh committed Aug 31, 2023
1 parent 1fdc529 commit 8dabcfb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: golangci/[email protected]
with:
args: --timeout=5m0s -c .golangci.yaml
version: v1.46.2
version: v1.54.2
test:
name: Test
runs-on: ubuntu-latest
Expand Down
16 changes: 16 additions & 0 deletions keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ func (ks KeyStore) GetPrivateKeyEntry(alias string, password []byte) (PrivateKey
return pke, nil
}

// GetPrivateKeyEntryCertificateChain returns certificate chain associated with
// PrivateKeyEntry from the keystore by the alias.
func (ks KeyStore) GetPrivateKeyEntryCertificateChain(alias string) ([]Certificate, error) {
e, ok := ks.m[ks.convertAlias(alias)]
if !ok {
return nil, ErrEntryNotFound
}

pke, ok := e.(PrivateKeyEntry)
if !ok {
return nil, ErrWrongEntryType
}

return pke.CertificateChain, nil
}

// IsPrivateKeyEntry returns true if the keystore has PrivateKeyEntry by the alias.
func (ks KeyStore) IsPrivateKeyEntry(alias string) bool {
_, ok := ks.m[ks.convertAlias(alias)].(PrivateKeyEntry)
Expand Down
9 changes: 9 additions & 0 deletions keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func TestSetGetMethods(t *testing.T) {
t.Fatal(err)
}

chainGet, err := ks.GetPrivateKeyEntryCertificateChain(pkeAlias)
if err != nil {
t.Fatal(err)
}

tceGet, err := ks.GetTrustedCertificateEntry(tceAlias)
if err != nil {
t.Fatal(err)
Expand All @@ -60,6 +65,10 @@ func TestSetGetMethods(t *testing.T) {
t.Fatal("private key entries not equal")
}

if !reflect.DeepEqual(pke.CertificateChain, chainGet) {
t.Fatal("certificate chains of private key entries are not equal")
}

if !reflect.DeepEqual(tce, tceGet) {
t.Fatal("private key entries not equal")
}
Expand Down

0 comments on commit 8dabcfb

Please sign in to comment.