Signatures in NDN
This page is under construction.
In NDN, all data is digitally signed by the original data producer. The signature guarantees the authenticity and integrity of a given block of data, because the signature can only be generated by the original producer, and becomes invalid if the data is modified. These signatures stay with the data both during transit and at rest, and thus guarantee the security of the data at all times.
Signing Data
Digital signing is done by a pair of asymmetric keys, which consists of a private key and a public key. The private key is known only by the producer, used to generate signatures. Anyone who knows the public key can verify the signature.
import ndn.encoding as enc
import ndn.security as sec
from Cryptodome.PublicKey import ECC
# Generate key pairs (Recommend 'P-256' for ECDSA and 'ed25519' for EdDSA)
priv_key = ECC.generate(curve='ed25519')
pub_key = priv_key.public_key()
# Create a signer
signer = sec.Ed25519Signer('/edu/ucla/xinyu.ma', priv_key.export_key(format='DER'))
# Sign a data with it
data_wire = enc.make_data(
# String can be directly used as Name in most cases
name='/edu/ucla/cs/118/notes',
# Set the Interest packet's FreshnessPeriod to 10 seconds
meta_info=enc.MetaInfo(freshness_period=10000),
# Set the Data packet's content to "Hello, NDN!"
content=b'Hello, NDN!',
signer=signer
)
print('Data:', data_wire.hex())
# Export public keys
pub_key_bits = pub_key.export_key(format='DER')
print('Public Key bits:', pub_key_bits.hex())
# Can be imported by: ECC.import_key(pub_key_bits)
# Then verify the Data packet using it
_, _, _, sig_ptrs = enc.parse_data(data_wire)
if sec.verify_ed25519(pub_key, sig_ptrs):
print('Data verified')
else:
print('Data not verified')
import { Data, Name } from '@ndn/packet';
import { Decoder, Encoder } from '@ndn/tlv';
import { toHex, toUtf8 } from '@ndn/util';
import { Ed25519, generateSigningKey } from '@ndn/keychain';
// Generate key pairs (Recommend ECDSA and Ed25519 for EdDSA)
const identityName = new Name('/edu/ucla/xinyu.ma');
const [signer, verifier] = await generateSigningKey(identityName, Ed25519);
// Sign a Data with it
const data = new Data(
new Name('/edu/ucla/cs/118/notes'),
Data.FreshnessPeriod(10000),
toUtf8('Hello, NDN!'));
await signer.sign(data);
// Print the Data wire
const wire = Encoder.encode(data);
console.log('Data:', toHex(wire));
// Export public keys
const publicKeyBits = verifier.spki!;
console.log('Public Key bits:', toHex(publicKeyBits));
// Importing a public key in NDNts is very complicated
// so I recommend to use a certificate instead.
// I will show you how to do it later.
// Then verify the Data packet using it
const decodedData = Decoder.decode(wire, Data); // Be the same as `data`
try {
await verifier.verify(decodedData);
console.log('Data verified');
} catch {
console.log('Data not verified');
}
In a system, security is more than cryptographically verifying the signature. For example, we also need to
- Securely obtain the public key of the producer.
- A signed piece of data containing the pubic key is called a certificate.
- Associate the producer with a member (human or process) in the system.
- Make sure the member is allowed to sign the data.
These tasks can be roughly classified into four aspects:
- Bootstrapping: to enroll a new member into an application. Make sure that the new member learns necessary security information to recognize others, and the other members are able to securely recognize new member.
- Key Management: to manage the membership and certificates, including certification revocation, renewal, and other operations.
- Authentication: to verify a piece of data is produced by claimed producer and not manipulated by an impersonator. This includes cryptographically verifying the signature.
- Authorization: a piece of data is produced by an intended producer, and accessed by an intended consumer. This includes discarding of data whose producers are not allowed to produce, and encrypting data so that only permitted consumers can decrypt.
The classification described is not strict. Most work on NDN involves more than one aspects of the security.