java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.Certificate
- All Implemented Interfaces:
Serializable, DataStructure
- Direct Known Subclasses:
Certificate.NullCert, KeyCertificate
Extensible certificate system for I2P structures providing metadata and capabilities.
Certificate offers flexible metadata attachment to I2P identities:
- Metadata: Additional information beyond cryptographic keys
- DoS Protection: Help manage denial of service attacks
- Network Utilization: Control resource usage and capabilities
- Extensible: Support for multiple certificate types and formats
- Optional: Structures can have NULL certificates for minimal overhead
Supported Certificate Types:
CERTIFICATE_TYPE_NULL- No certificate (default)CERTIFICATE_TYPE_HIDDEN- Service should not be publishedCERTIFICATE_TYPE_SIGNED- Signed by certificate authorityCERTIFICATE_TYPE_MULTIPLE- Contains multiple certificatesCERTIFICATE_TYPE_KEY- Specifies key types (KeyCertificate)
Common Use Cases:
- Identity Verification: Prove authenticity of routers/destinations
- Capability Advertising: Announce supported features and protocols
- Access Control: Specify service restrictions or requirements
- Resource Management: Indicate bandwidth or usage limitations
- Trust Establishment: Certificate authority-based trust chains
Security Considerations:
- Anonymous Network: CA-based certificates may not be appropriate
- Signature Verification: Always verify certificate signatures
- Trust Validation: Carefully evaluate certificate authorities
- Privacy Impact: Consider anonymity implications of certificates
Implementation Notes:
- Multiple Certificates: Support for multiple certificates is planned
- Size Efficiency: Minimal overhead for NULL certificates
- Flexibility: Payload can contain arbitrary metadata
- Backward Compatibility: Existing formats continue to be supported
Related Structures:
Destination- Uses certificates for service identityRouterIdentity- Router certificatesKeyCertificate- Specialized certificate for key type specification
- See Also:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classAn immutable null certificate.Field Summary
FieldsModifier 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
ConstructorsConstructorDescriptionCreates a new Certificate with default values.Certificate(int type, byte[] payload) Certificate with the given type and payload.Method Summary
Modifier 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.Up-convert this to a KeyCertificate.toString()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
NULL_CERT
Null certificate singleton._type
protected int _typeCertificate type identifier._payload
protected byte[] _payloadCertificate payload data.CERTIFICATE_TYPE_NULL
public static final int CERTIFICATE_TYPE_NULLSpecifies a null certificate type with no payload.- See Also:
CERTIFICATE_TYPE_HIDDEN
public static final int CERTIFICATE_TYPE_HIDDENWe should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us).- See Also:
CERTIFICATE_TYPE_SIGNED
public static final int CERTIFICATE_TYPE_SIGNEDSigned with 40-byte Signature and (optional) 32-byte hash.- See Also:
CERTIFICATE_LENGTH_SIGNED_WITH_HASH
public static final int CERTIFICATE_LENGTH_SIGNED_WITH_HASHLength of signed certificate with hash (signature + hash).CERTIFICATE_TYPE_MULTIPLE
public static final int CERTIFICATE_TYPE_MULTIPLEContains multiple certs.- See Also:
CERTIFICATE_TYPE_KEY
Constructor Details
Certificate
public Certificate()Creates a new Certificate with default values.Certificate
public Certificate(int type, byte[] payload) Certificate with the given type and payload.- Parameters:
type- the certificate typepayload- the certificate payload (may be null)- Throws:
IllegalArgumentException- if type < 0
Method Details
create
If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new.- Parameters:
data- the source dataoff- the offset into data- Returns:
- the Certificate instance
- Throws:
DataFormatException- if not enough bytes
create
If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new.- Parameters:
in- the input stream- Returns:
- the Certificate instance
- Throws:
DataFormatException- if the data is malformedIOException- if there is an I/O error
getCertificateType
public int getCertificateType()Certificate type.- Returns:
- one of the CERTIFICATE_TYPE_* constants, 0 for none
setCertificateType
public void setCertificateType(int type) Certificate type to set.- Parameters:
type- the certificate type to set- Throws:
IllegalArgumentException- if type < 0IllegalStateException- if already set
getPayload
public byte[] getPayload()Payload carried by this certificate.- Returns:
- the payload bytes, or null if the certificate has no payload
setPayload
public void setPayload(byte[] payload) Certificate payload to set.- Parameters:
payload- the payload to set- Throws:
IllegalStateException- if already set
readBytes
Reads the certificate from an input stream.- Parameters:
in- stream to read from- Throws:
IllegalStateException- if already setDataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
writeBytes
Description copied from interface:DataStructureWrite out the data structure to the stream, using the format defined in the I2P data structure specification.- Parameters:
out- stream to write to- Throws:
DataFormatException- if the data was incomplete or not yet ready to be writtenIOException- if there was a problem writing to the stream
writeBytes
public int writeBytes(byte[] target, int offset) Writes the certificate to the target array.- Parameters:
target- the output arrayoffset- the starting offset in the target- Returns:
- the written length (NOT the new offset)
readBytes
Reads the certificate from the source array.- Parameters:
source- the array holding the certificate dataoffset- the starting offset in the source- Returns:
- the bytes consumed
- Throws:
IllegalStateException- if already setDataFormatException- if the data is malformed
size
public int size()Serialized size of this certificate.- Returns:
- the size in bytes: 3 plus the payload length
toKeyCertificate
Up-convert this to a KeyCertificate.- Returns:
- a new KeyCertificate wrapping this certificate's payload
- Throws:
DataFormatException- if cert type != CERTIFICATE_TYPE_KEY
equals
hashCode
toString