@ndn/keychain-cli v0.0.20250307
@ndn/keychain-cli
This package is part of NDNts, Named Data Networking libraries for the modern web.
ndnts-keychain is a command line utility to access an NDNts persistent KeyChain.
NDNTS_KEYCHAIN environment variable specifies location of the KeyChain.
If missing, the command will operate on an in-memory ephemeral KeyChain, which is not particularly useful.
NDNts does not provide a "default" KeyChain, because it is unsafe to access the same KeyChain from multiple processes concurrently.
ndnts-keychain list-keys: List Keys
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain list-keysThis command prints a list of key names to standard output.
ndnts-keychain gen-key: Generate Key
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain gen-key /A
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain gen-key /A --type ec --curve P-384
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain gen-key /A --type rsa --modulus-length 2048- The name can either be a subject name (called "identity" in other tools), or a key name.
--typespecifies key type: "ec" or "rsa".--curvespecifies ECDSA curve: "P-256", "P-384", or "P-521".--modulus-lengthspecifies RSA modulus length: 2048, 4096.- Default is ECDSA key with P-256 curve.
This command adds a self-signed certificate to the KeyChain, and prints the certificate name to stdout.
You may retrieve the self-signed certificate with ndnts-keychain show-cert command.
ndnts-keychain list-certs: List Certificates
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain list-certsThis command prints a list of certificate names to standard output.
ndnts-keychain show-cert: Show Certificate
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain show-cert /A/KEY/56=%00%05%96%BA%2C%A5%89%F8/self/52=%00%00%01nD%24%01%87This command prints the specified certificate in Base64 format to standard output.
ndnts-keychain issue-cert: Issue Certificate
NDNTS_KEYCHAIN=/tmp/issuer-keychain ndnts-keychain issue-cert --issuer /B --issuer-id B --valid-days 72 < A-request.cert > A.certThis command reads a certificate request (self-signed certificate) in Base64 format from standard input, signs (issues) a certificate to the public key enclosed in the certificate request, and prints the issued certificate in Base64 format to standard output.
--issuerspecifies a private key that signs (issues) the certificate. This may be a key name or a certificate name.--issuer-idspecifies the IssuerId name component. Default is an empty component.--valid-daysspecifies certificate ValidityPeriod in days from now. Default is 30 days.--use-key-name-locatorforces the KeyLocator of the issued certificate to contain a key name instead of a certificate name.
Example:
$ NDNTS_KEYCHAIN=/tmp/issuer ndnts-keychain gen-key /issuer
/issuer/KEY/56=%00%05%96%BAy%B2%60%90/self/54=%00%00%01nD7%BB%12
$ NDNTS_KEYCHAIN=/tmp/user ndnts-keychain gen-key /user
/user/KEY/56=%00%05%96%BAz%FCl%C0/self/54=%00%00%01nD8%0F%8E
$ NDNTS_KEYCHAIN=/tmp/user ndnts-keychain show-cert /user/KEY/56=%00%05%96%BAz%FCl%C0/self/54=%00%00%01nD8%0F%8E \
| NDNTS_KEYCHAIN=/tmp/issuer ndnts-keychain issue-cert --issuer /issuer --issuer-id parent --valid-days 72 \
| NDNTS_KEYCHAIN=/tmp/user ndnts-keychain add-cert
$ NDNTS_KEYCHAIN=/tmp/user ndnts-keychain list-certs
/user/KEY/56=%00%05%96%BAz%FCl%C0/self/54=%00%00%01nD8%0F%8E
/user/KEY/56=%00%05%96%BAz%FCl%C0/parent/54=%00%00%01nD9L%05- Generate
/issuerkey in issuer's KeyChain. - Generate
/userkey in user's KeyChain. - Show
/usercertificate request, have it signed by/issuer, and add the issued certificate to user's KeyChain. - Display certificates in user's KeyChain.
ndnts-keychain add-cert: Add Certificate
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain add-cert < A.certThis command reads a certificate in Base64 format from standard input, and saves it in the KeyChain. The corresponding key must exist in the KeyChain.
ndnts-keychain delete: Delete Keys and Certificates
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain delete /AThis command deletes keys and certificates under a name prefix.
ndnts-keychain import-safebag: Import ndn-cxx SafeBag
ndnsec export -i /subject -P 888888 | NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain import-safebag --passphrase 888888This command reads a ndn-cxx SafeBag object in Base64 format from standard input, and saves the enclosed private key, public key, and certificate in the KeyChain.
ndnts-keychain import-ndnsec: Import ndn-cxx KeyChain via ndnsec
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain import-ndnsec
NDNTS_KEYCHAIN=/tmp/my-keychain ndnts-keychain import-ndnsec --prefix /subjectThis command copies keys and certificates from ndn-cxx KeyChain using ndnsec executable, and prints imported key names to standard output.
--prefixlimits key names to be under a prefix. Default is importing all keys.
See @ndn/ndnsec package for more information.
ndnts-keychain ndncert03-*: NDNCERT 0.3
ndnts-keychain ndncert03-make-profile command generates a CA profile.
--outspecifies output filename. CA profile Data packet in binary format would be written to this file.--prefixspecifies the name prefix for the CA. Conventionally, it should end withCAcomponent.--certspecifies the certificate name for the CA. The certificate and the corresponding private key must exist in the keychain given inNDNTS_KEYCHAINenvironment variable.--valid-daysspecifies maximum validity period of issued certificates, in days. The default is 30 days.
ndnts-keychain ndncert03-show-profile command displays information in a CA profile.
--profilespecifies filename of CA profile. This may be either (1) the CA profile Data packet in binary format (2) client.conf format compatible with NDNCERT C++ implementation (3) CA certificate name with implicit digest.--outwrites the CA profile Data packet in binary format to a file. This option is useful for retrieving and verifying the binary CA profile, from another input format.--jsonchanges the output to machine-readable JSON format.--clientconfchanges the output to client.conf format. This option is useful for converting a binary CA profile to use with NDNCERT C++ implementation.
ndnts-keychain ndncert03-ca command runs a certificate authority.
--profilespecifies filename of CA profile. This should be the CA profile Data packet in binary format.--storespecifies directory path of a repository that stores issued certificates.--challenge nopenables "nop" challenge that approves all certificate requests.--challenge pinenables "pin" challenge that requires the requester to enter a 6-digit PIN code. The correct PIN code is displayed on the console of CA.--challenge emailenables "email" challenge. The following environment variables are required when enabling email challenge:CA_EMAIL_HOST,CA_EMAIL_PORT,CA_EMAIL_USER,CA_EMAIL_PASS,CA_EMAIL_FROM.--challenge possessionenables "possession" challenge that requires the requester to own a certificate from a specified issuer.--possession-issuerspecifies filename of issuer certificate to fulfill possession challenge. The default is the CA certificate in the CA profile.
ndnts-keychain ndncert03-probe command runs the PROBE procedure against a CA.
--profilespecifies filename of CA profile. This accepts the same formats asndncert03-show-profilesubcommand.--pp KEY VALUEsets a key-value pair in PROBE parameters. Unspecified keys will be prompted interactively.
ndnts-keychain ndncert03-client command requests a certificate.
--profilespecifies filename of CA profile. This accepts the same formats asndncert03-show-profilesubcommand.--ndnsecuses ndn-cxx keychain instead of NDNts keychain.--keyspecifies the key name to obtain certificate for. The key pair must exist in the keychain given inNDNTS_KEYCHAINenvironment variable, or ndn-cxx keychain if--ndnsecis specified. This also accepts a certificate name, whose key will be used.- If
--keyis omitted, the client sends a PROBE request to the CA. It then creates a new key whose subject name is the first available name in the PROBE response. PROBE response that contains only redirects is not supported and will result in an error, but such CA can be supported throughndnts-keychain ndncert03-probecommand. --pp KEY VALUEsets a key-value pair in PROBE parameters. Unspecified keys will be prompted interactively, except that--emailmay be used asemailparameter.--challenge nopenables "nop" challenge.--challenge pinenables "pin" challenge.--challenge emailenables "email" challenge.--emailspecifies email address to use in the email challenge.--challenge possessionenables "possession" challenge.--possession-certspecifies existing certificate name to fulfill possession challenge. If--keyis a certificate name, this may be omitted if using the same certificate. The specified certificate and its corresponding private key must exist in the keychain.- You may specify multiple challenges, and the first one allowed by the server will be used.
NDNCERT examples
CA setup with PIN challenge:
# generate CA key
CACERT=$(NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain gen-key /A)
# make CA profile
NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain ndncert03-make-profile --out /tmp/ca.data --prefix /localhost/my-ndncert/CA --cert $CACERT --valid-days 60
# display CA profile
ndnts-keychain ndncert03-show-profile --profile /tmp/ca.data
# start CA with PIN challenge
nfd-start
NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain ndncert03-ca --profile /tmp/ca.data --store /tmp/ca-repo --challenge pinClient using PIN challenge, with NDNts keychain:
# generate key pair
REQCERT=$(NDNTS_KEYCHAIN=/tmp/req-keychain ndnts-keychain gen-key /B)
REQKEY=$(echo $REQCERT | gawk 'BEGIN { FS=OFS="/" } { NF-=2; print }')
# request certificate with PIN challenge; you'll need to enter the PIN shown on CA console
NDNTS_KEYCHAIN=/tmp/req-keychain ndnts-keychain ndncert03-client --profile /tmp/ca.data --key $REQKEY --challenge pin
# view certificates
NDNTS_KEYCHAIN=/tmp/req-keychain ndnts-keychain list-certsClient using PIN challenge, with ndn-cxx keychain:
# generate key pair
ndnsec key-gen -te /C >/dev/null
REQKEY=$(ndnsec list -k | gawk '$1=="+->*" && $2 ~ "^/C/" { print $2 }')
# request certificate with PIN challenge; you'll need to enter the PIN shown on CA console
ndnts-keychain ndncert03-client --profile /tmp/ca.data --ndnsec --key $REQKEY --challenge pin
# view certificates
ndnsec list -cEmail challenge, NDNts keychain on client side:
# before start, prepare CA profile using commands in the PIN challenge example
export CA_EMAIL_HOST=smtp.ethereal.email
export CA_EMAIL_PORT=587
export CA_EMAIL_USER=mireya.hoeger51@ethereal.email
export CA_EMAIL_PASS=ZMGMfXc1E7NvMr9sJB
export CA_EMAIL_FROM=$CA_EMAIL_USER
# start CA with email challenge
nfd-start
NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain ndncert03-ca --profile /tmp/ca.data --store /tmp/ca-repo --challenge email
# generate key pair
REQCERT=$(NDNTS_KEYCHAIN=/tmp/req-keychain ndnts-keychain gen-key /M)
REQKEY=$(echo $REQCERT | gawk 'BEGIN { FS=OFS="/" } { NF-=2; print }')
# request certificate with email challenge; you'll need to enter the PIN received from email
REQEMAIL=someone@example.com
NDNTS_KEYCHAIN=/tmp/req-keychain ndnts-keychain ndncert03-client --profile /tmp/ca.data --key $REQKEY --challenge email --email $REQEMAIL
# view certificates
NDNTS_KEYCHAIN=/tmp/req-keychain ndnts-keychain list-certsProof of possession challenge, ndn-cxx keychain on client side:
# generate "other" issuer key
ndnsec key-gen -te /O >/dev/null
ndnsec cert-dump -i /O >/tmp/O.ndncert
# issue "existing" certificate
ndnsec key-gen -te /E >/tmp/E-self.ndncert
ndnsec cert-gen -s /O -i ISSUER-O /tmp/E-self.ndncert >/tmp/E.ndncert
ndnsec cert-install /tmp/E.ndncert
# generate CA key, make CA profile
CACERT=$(NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain gen-key /A)
NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain ndncert03-make-profile --out /tmp/ca.data --prefix /localhost/my-ndncert/CA --cert $CACERT --valid-days 60
# start CA with possession challenge
nfd-start
NDNTS_KEYCHAIN=/tmp/ca-keychain ndnts-keychain ndncert03-ca --profile /tmp/ca.data --store /tmp/ca-repo --challenge possession --possession-issuer /tmp/O.ndncert
# request certificate with possession challenge
REQKEY=$(ndnsec list -k | gawk '$1=="+->*" && $2 ~ "^/E/" { print $2 }')
OCERT=$(ndnsec list -c | gawk '$1=="+->*" && $2 ~ "^'$REQKEY'/ISSUER-O/" { print $2 }')
ndnts-keychain ndncert03-client --profile /tmp/ca.data --ndnsec --key $REQKEY --challenge possession --possession-cert $OCERT
# view certificates
ndnsec list -c
ndnsec cert-dump -p -i /EEmail challenge with Ethereal Email, for global NDN testbed:
export NDNTS_UPLINK=autoconfig:
export NDNTS_KEYCHAIN=/tmp/req-keychain
# download root CA profile
http --json --follow --output /tmp/ndn-root-ca.client.conf \
GET https://github.com/named-data/ndncert/raw/master/client.conf.sample
# generate a random institutional email address for running PROBE command
PROBE_EMAIL=$(openssl rand -hex 8)@ucla.edu
# run PROBE command to obtain a redirect to a sub CA
PROBE_CACERT=$( \
ndnts-keychain ndncert03-probe --profile /tmp/ndn-root-ca.client.conf --pp email $PROBE_EMAIL |\
tee /dev/stderr | jq -r ".redirects[0].caCertFullName")
# request certificate from the sub CA, solving email challenge automatically
# CA profile is retrieved and verified according to provided CA certificate full name
ndnts-keychain ndncert03-client --profile $PROBE_CACERT --pp email $PROBE_EMAIL \
--challenge email --email ethereal8 months ago
10 months ago
1 year ago
2 years ago
3 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago