Skip to content

tools/sec: Add certificates to key-list, add cert-export#181

Open
greetingsuniverse wants to merge 8 commits intonamed-data:mainfrom
greetingsuniverse:securityutil
Open

tools/sec: Add certificates to key-list, add cert-export#181
greetingsuniverse wants to merge 8 commits intonamed-data:mainfrom
greetingsuniverse:securityutil

Conversation

@greetingsuniverse
Copy link
Copy Markdown
Contributor

Resolves #129

If the corresponding key to a certificate is not contained, cert-export still works but key-list will not list it

key-list displays certificates under keys in this format:

/alice
==> /alice/KEY/%D32%D6%C9%05k%FB%DF
    ==> /alice/KEY/%D32%D6%C9%05k%FB%DF/NA/v=0
/ndn/bob
==> /ndn/bob/KEY/q%D7%8Fn%D7%14%EEA
    ==> /ndn/bob/KEY/q%D7%8Fn%D7%14%EEA/ALICE/v=0
    ==> /ndn/bob/KEY/q%D7%8Fn%D7%14%EEA/CAROL/v=0
/ndn/carol
==> /ndn/carol/KEY/%24%CC-5%BB%A1%9B%F8

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds certificate visibility/export capabilities to ndnd sec keychain tooling to address issue #129 (listing/exporting certificates even when corresponding keys may be absent).

Changes:

  • Update key-list to display certificates associated with each key.
  • Add new cert-export subcommand to export a certificate from a keychain.
  • Update security utility docs to reflect the expanded CLI behavior and flag syntax.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tools/sec/keychain.go Extends key-list output to include certs and introduces cert-export implementation.
docs/security-util.md Updates CLI documentation (flag syntax, key-list description, and adds cert-export section).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/sec/keychain.go Outdated
Comment thread tools/sec/keychain.go Outdated
Comment on lines +236 to +238
wire, err := kc.Store().Get(name.Prefix(-1), true)
if err != nil || wire == nil {
fmt.Fprintf(os.Stderr, "Certificate not found: %s\n", name)
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cert-export takes CERT-NAME, but the lookup uses name.Prefix(-1) with prefix=true, which drops the version component and can export a different (newest) version than the one explicitly requested. Consider using an exact Get(name, false) when a version component is present, and only falling back to prefix search when the user provides a non-versioned cert name.

Suggested change
wire, err := kc.Store().Get(name.Prefix(-1), true)
if err != nil || wire == nil {
fmt.Fprintf(os.Stderr, "Certificate not found: %s\n", name)
wire, err := kc.Store().Get(name, false)
if err == nil && wire == nil {
wire, err = kc.Store().Get(name, true)
}
if err != nil || wire == nil {
fmt.Fprintf(os.Stderr, "Certificate not found: %s\n", name)
os.Exit(1)
return

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you remove the last component of the certificate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UniqueCerts() always returns names with v=0 so it would fail if that was passed to it, I updated so that it works for all 3 cases (v=0, prefix, or specific cert).

Should I change key-list to get the full cert names instead of output of UniqueCerts() with v=0? I didn't before because no function currently exists in the Keychain or Store interface to make it possible to list every version of a unique certificate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already forgot about the keystore. @tianyuan129 What do you think?

Comment thread tools/sec/keychain.go
Comment thread docs/security-util.md Outdated
Comment thread docs/security-util.md Outdated
Comment thread tools/sec/keychain.go
Comment thread tools/sec/keychain.go Outdated
Comment on lines +236 to +238
wire, err := kc.Store().Get(name.Prefix(-1), true)
if err != nil || wire == nil {
fmt.Fprintf(os.Stderr, "Certificate not found: %s\n", name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you remove the last component of the certificate?

Comment thread tools/sec/keychain.go Outdated
Copy link
Copy Markdown
Member

@zjkmxy zjkmxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tools/sec] list and export certificates

3 participants