All Implemented Interfaces:
Serializable, DataStructure
Direct Known Subclasses:
Certificate.NullCert, KeyCertificate

public class Certificateextends DataStructureImpl
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:

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:

See Also:
  • Field Details

    • NULL_CERT

      public static final Certificate NULL_CERT
      Null certificate singleton.
    • _type

      protected int _type
      Certificate type identifier.
    • _payload

      protected byte[] _payload
      Certificate payload data.
    • CERTIFICATE_TYPE_NULL

      public static final int CERTIFICATE_TYPE_NULL
      Specifies a null certificate type with no payload.
      See Also:
    • CERTIFICATE_TYPE_HIDDEN

      public static final int CERTIFICATE_TYPE_HIDDEN
      We 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_SIGNED
      Signed with 40-byte Signature and (optional) 32-byte hash.
      See Also:
    • CERTIFICATE_LENGTH_SIGNED_WITH_HASH

      public static final int CERTIFICATE_LENGTH_SIGNED_WITH_HASH
      Length of signed certificate with hash (signature + hash).
    • CERTIFICATE_TYPE_MULTIPLE

      public static final int CERTIFICATE_TYPE_MULTIPLE
      Contains multiple certs.
      See Also:
    • CERTIFICATE_TYPE_KEY

      public static final int CERTIFICATE_TYPE_KEY
      Key certificate type.
      See Also:
  • 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 type
      payload - the certificate payload (may be null)
      Throws:
      IllegalArgumentException - if type < 0
  • Method Details

    • create

      public static Certificate create(byte[] data, int off) throws DataFormatException
      If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new.
      Parameters:
      data - the source data
      off - the offset into data
      Returns:
      the Certificate instance
      Throws:
      DataFormatException - if not enough bytes
    • create

      public static Certificate create(InputStream in) throws DataFormatException, IOException
      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 malformed
      IOException - 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 < 0
      IllegalStateException - 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

      public void readBytes(InputStream in) throws DataFormatException, IOException
      Reads the certificate from an input stream.
      Parameters:
      in - stream to read from
      Throws:
      IllegalStateException - if already set
      DataFormatException - if the data is improperly formatted
      IOException - if there was a problem reading the stream
    • writeBytes

      public void writeBytes(OutputStream out) throws DataFormatException, IOException
      Description copied from interface: DataStructure
      Write 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 written
      IOException - 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 array
      offset - the starting offset in the target
      Returns:
      the written length (NOT the new offset)
    • readBytes

      public int readBytes(byte[] source, int offset) throws DataFormatException
      Reads the certificate from the source array.
      Parameters:
      source - the array holding the certificate data
      offset - the starting offset in the source
      Returns:
      the bytes consumed
      Throws:
      IllegalStateException - if already set
      DataFormatException - 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

      public KeyCertificate toKeyCertificate() throws DataFormatException
      Up-convert this to a KeyCertificate.
      Returns:
      a new KeyCertificate wrapping this certificate's payload
      Throws:
      DataFormatException - if cert type != CERTIFICATE_TYPE_KEY
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object