java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.Certificate
net.i2p.data.KeyCertificate
- All Implemented Interfaces:
Serializable, DataStructure
- Direct Known Subclasses:
KeyCertificate.ECDSA256Cert, KeyCertificate.Ed25519Cert, KeyCertificate.X25519_Ed25519Cert
Specialized certificate for defining cryptographic key types used in I2P identities.
KeyCertificate specifies the encryption and signature algorithms for I2P identities:
- Signature Type: Algorithm used for signing (2 bytes)
- Encryption Type: Algorithm used for encryption (2 bytes)
- Excess Data: Additional key-specific data if needed
- Optimized: Frequently used, so has dedicated class for performance
Format Structure:
- Header: 4 bytes total (2-byte sig type + 2-byte crypto type)
- Signature Data: Optional excess data for signature algorithm
- Encryption Data: Optional excess data for encryption algorithm
Supported Combinations:
- ElGamal + DSA-SHA1: Legacy combination (crypto type 0x0000)
- ElGamal + Ed25519: Modern signing with legacy encryption
- ElGamal + ECDSA-P256: Modern signing with legacy encryption
- X25519 + Ed25519: Modern combination (both algorithms)
Predefined Certificates:
- Ed25519: ElGamal + Ed25519 signing key
- ECDSA256: ElGamal + ECDSA-P256 signing key
- X25519_Ed25519: X25519 encryption + Ed25519 signing
Usage:
- Identity Specification: Defines algorithms for
Destination - Algorithm Negotiation: Communicates supported crypto to peers
- Backward Compatibility: Supports legacy and modern algorithms
- Future Proofing: Extensible for new algorithm combinations
Migration Path:
- Legacy: ElGamal encryption (assumed 0x0000) with various signing
- Modern: X25519 encryption with Ed25519 signing
- Transition: Mixed combinations during migration period
Performance Considerations:
- Frequently Used: Every Destination contains a KeyCertificate
- Optimized Creation: Pre-defined certificates for common combinations
- Caching: Immutable instances can be safely shared
- See Also:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classAn immutable ElG/ECDSA-256 certificate.private static final classAn immutable ElG/Ed25519 certificate.private static final classAn immutable X25519/Ed25519 certificate.Field Summary
Modifier and TypeFieldDescription(package private) static final byte[]ElG + P256.(package private) static final byte[]ElG + Ed25519.static final KeyCertificateAn immutable ElG/ECDSA-P256 certificate.static final KeyCertificateAn immutable ElG/Ed25519 certificate.private static final byte[]Shared result for the no-extra-data case.static final intKey certificate header length in bytes.static final KeyCertificateAn immutable X25519/Ed25519 certificate.(package private) static final byte[]X25519 + Ed25519.Fields inherited from class Certificate
_payload, _type, CERTIFICATE_LENGTH_SIGNED_WITH_HASH, CERTIFICATE_TYPE_HIDDEN, CERTIFICATE_TYPE_KEY, CERTIFICATE_TYPE_MULTIPLE, CERTIFICATE_TYPE_NULL, CERTIFICATE_TYPE_SIGNED, NULL_CERTModifier and TypeFieldDescriptionprotected byte[]Certificate payload data.protected intCertificate type identifier.static final intLength of signed certificate with hash (signature + hash).static final intWe should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us).static final intKey certificate type.static final intContains multiple certs.static final intSpecifies a null certificate type with no payload.static final intSigned with 40-byte Signature and (optional) 32-byte hash.static final CertificateNull certificate singleton.Constructor Summary
ConstructorsConstructorDescriptionKeyCertificate(byte[] payload) 4 bytes minimum if non-null.KeyCertificate(SigType type) A KeyCertificate with crypto type 0 (ElGamal) and the signature type as specified.KeyCertificate(SigType type, EncType etype) A KeyCertificate with crypto type and the signature type as specified.KeyCertificate(Certificate cert) Up-convert a cert to this class.A KeyCertificate with crypto type 0 (ElGamal) and the signature type and extra data from the given public key.KeyCertificate(SigningPublicKey spk, PublicKey pk) A KeyCertificate with enc type from the given public key, and the signature type and extra data from the given public key.Method Summary
All MethodsModifier and TypeMethodDescriptionintGets the crypto type code from the certificate.Gets the encryption type from the certificate.byte[]Signing Key extra data, if any, is first in the array.byte[]Signing Key extra data, if any.Gets the signature type from the certificate.intGets the signature type code from the certificate.Returns this certificate as a KeyCertificate.toString()Returns a string representation of this KeyCertificate.Methods inherited from class Certificate
create, create, equals, getCertificateType, getPayload, hashCode, readBytes, readBytes, setCertificateType, setPayload, size, writeBytes, writeBytesModifier and TypeMethodDescriptionstatic Certificatecreate(byte[] data, int off) If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new.static Certificatecreate(InputStream in) If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new.booleanintCertificate type.byte[]Payload carried by this certificate.inthashCode()intreadBytes(byte[] source, int offset) Reads the certificate from the source array.voidreadBytes(InputStream in) Reads the certificate from an input stream.voidsetCertificateType(int type) Certificate type to set.voidsetPayload(byte[] payload) Certificate payload to set.intsize()Serialized size of this certificate.intwriteBytes(byte[] target, int offset) Writes the certificate to the target array.voidwriteBytes(OutputStream out) Write out the data structure to the stream, using the format defined in the I2P data structure specification.Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.
Field Details
HEADER_LENGTH
public static final int HEADER_LENGTHKey certificate header length in bytes.- See Also:
EMPTY
private static final byte[] EMPTYShared result for the no-extra-data case. Zero-length arrays cannot be mutated, so a single instance may be handed to every caller.Ed25519_PAYLOAD
static final byte[] Ed25519_PAYLOADElG + Ed25519.ECDSA256_PAYLOAD
static final byte[] ECDSA256_PAYLOADElG + P256.X25519_Ed25519_PAYLOAD
static final byte[] X25519_Ed25519_PAYLOADX25519 + Ed25519.ELG_ECDSA256_CERT
An immutable ElG/ECDSA-P256 certificate.ELG_Ed25519_CERT
An immutable ElG/Ed25519 certificate.X25519_Ed25519_CERT
An immutable X25519/Ed25519 certificate.
Constructor Details
KeyCertificate
4 bytes minimum if non-null.- Parameters:
payload- 4 bytes minimum if non-null- Throws:
DataFormatException- if payload is too short
KeyCertificate
A KeyCertificate with crypto type 0 (ElGamal) and the signature type and extra data from the given public key.- Parameters:
spk- non-null data non-null- Throws:
IllegalArgumentException- if spk or spk data is null
KeyCertificate
A KeyCertificate with enc type from the given public key, and the signature type and extra data from the given public key. EncType lengths greater than 256 not supported.- Parameters:
spk- non-null data non-nullpk- non-null- Throws:
IllegalArgumentException- if spk, pk, or their data is null
KeyCertificate
A KeyCertificate with crypto type 0 (ElGamal) and the signature type as specified. Payload is created. If type.getPubkeyLen() is greater than 128, caller MUST fill in the extra key data in the payload.- Parameters:
type- non-null- Throws:
IllegalArgumentException- if type is null
KeyCertificate
A KeyCertificate with crypto type and the signature type as specified. Payload is created. If type.getPubkeyLen() is greater than 128, caller MUST fill in the extra key data in the payload. EncType lengths greater than 256 not supported.- Parameters:
type- non-nulletype- non-null- Throws:
IllegalArgumentException- if type or etype is null
KeyCertificate
Up-convert a cert to this class.- Parameters:
cert- payload 4 bytes minimum if non-null- Throws:
DataFormatException- if cert type != CERTIFICATE_TYPE_KEY
Method Details
getSigTypeCode
public int getSigTypeCode()Gets the signature type code from the certificate.- Returns:
- -1 if unset
getCryptoTypeCode
public int getCryptoTypeCode()Gets the crypto type code from the certificate.- Returns:
- -1 if unset
getSigType
Gets the signature type from the certificate.- Returns:
- null if unset or unknown
getEncType
Gets the encryption type from the certificate.- Returns:
- null if unset or unknown
getExtraKeyData
public byte[] getExtraKeyData()Signing Key extra data, if any, is first in the array. Crypto Key extra data, if any, is second in the array, at offset max(0,getSigType().getPubkeyLen() - 128).- Returns:
- empty array if unset or none
getExtraSigningKeyData
public byte[] getExtraSigningKeyData()Signing Key extra data, if any.- Returns:
- empty array if unset or none
- Throws:
UnsupportedOperationException- if the sig type is unsupported
toKeyCertificate
Returns this certificate as a KeyCertificate.- Overrides:
toKeyCertificatein classCertificate- Returns:
- a new KeyCertificate wrapping this certificate's payload
toString
Returns a string representation of this KeyCertificate.- Overrides:
toStringin classCertificate