java.lang.Object
net.i2p.client.naming.HostTxtEntry

public class HostTxtEntryextends Object
A hostname, b64 destination, and optional properties. Includes methods to sign and verify the entry. Used by addressbook to parse subscription data, and by i2ptunnel to generate signed metadata.
  • Field Details

    • name

      private final String name
      The subscription's name.
    • dest

      private final String dest
      The destination, as text.
    • props

      private final OrderedProperties props
      Timing and other properties of the entry.
    • isValidated

      private boolean isValidated
      True once the entry has been checked.
    • isValid

      private boolean isValid
      False if the line was malformed.
    • KV_SEPARATOR

      public static final char KV_SEPARATOR
      Separator between name and destination in the hosts.txt line.
      See Also:
    • PROPS_SEPARATOR

      public static final String PROPS_SEPARATOR
      Separator between the destination part and the properties part.
      See Also:
    • PROP_SEPARATOR

      public static final char PROP_SEPARATOR
      Separator between individual properties.
      See Also:
    • PROP_ACTION

      public static final String PROP_ACTION
      Property key for the action type (e.g. adddest, remove).
      See Also:
    • PROP_DATE

      public static final String PROP_DATE
      Property key for the date timestamp (seconds since epoch).
      See Also:
    • PROP_DEST

      public static final String PROP_DEST
      Property key for the destination Base64 string.
      See Also:
    • PROP_EXPIRES

      public static final String PROP_EXPIRES
      Property key for the expiry time.
      See Also:
    • PROP_NAME

      public static final String PROP_NAME
      Property key for the hostname.
      See Also:
    • PROP_OLDDEST

      public static final String PROP_OLDDEST
      Property key for the old destination (used in change operations).
      See Also:
    • PROP_OLDNAME

      public static final String PROP_OLDNAME
      Property key for the old hostname (used in rename operations).
      See Also:
    • PROP_OLDSIG

      public static final String PROP_OLDSIG
      Property key for the old signature for inner verification.
      See Also:
    • PROP_SIG

      public static final String PROP_SIG
      Property key for the signature.
      See Also:
    • ACTION_ADDDEST

      public static final String ACTION_ADDDEST
      Action value: add a new destination.
      See Also:
    • ACTION_ADDNAME

      public static final String ACTION_ADDNAME
      Action value: add a new hostname.
      See Also:
    • ACTION_ADDSUBDOMAIN

      public static final String ACTION_ADDSUBDOMAIN
      Action value: add a subdomain entry.
      See Also:
    • ACTION_CHANGEDEST

      public static final String ACTION_CHANGEDEST
      Action value: change an existing destination.
      See Also:
    • ACTION_CHANGENAME

      public static final String ACTION_CHANGENAME
      Action value: change an existing hostname.
      See Also:
    • ACTION_REMOVE

      public static final String ACTION_REMOVE
      Action value: remove an entry.
      See Also:
    • ACTION_REMOVEALL

      public static final String ACTION_REMOVEALL
      Action value: remove all entries.
      See Also:
    • ACTION_UPDATE

      public static final String ACTION_UPDATE
      Action value: update an existing entry.
      See Also:
  • Constructor Details

    • HostTxtEntry

      public HostTxtEntry(String name, String dest)
      Create a new host text entry with name and destination, no properties.
      Parameters:
      name - the hostname, null for a 'remove' entry
      dest - the Base64 destination
    • HostTxtEntry

      public HostTxtEntry(String name, String dest, String sprops) throws IllegalArgumentException
      Create a new host text entry with name, destination, and serialized properties.
      Parameters:
      name - the hostname, null for a 'remove' entry
      dest - the Base64 destination
      sprops - line part after the #!, non-null
      Throws:
      IllegalArgumentException - on dup key in sprops and other errors
    • HostTxtEntry

      public HostTxtEntry(String sprops) throws IllegalArgumentException
      A 'remove' entry. Name and Dest will be null.
      Parameters:
      sprops - line part after the #!, non-null
      Throws:
      IllegalArgumentException - on dup key in sprops and other errors
    • HostTxtEntry

      public HostTxtEntry(String name, String dest, OrderedProperties props)
      Create a new host text entry with optional properties.
      Parameters:
      name - the hostname, null for a 'remove' entry
      dest - the Base64 destination
      props - may be null
  • Method Details

    • getName

      public String getName()
      The hostname mapped by this entry, or null for a 'remove' entry.
      Returns:
      the hostname, or null for a 'remove' entry
    • getDest

      public String getDest()
      Return the Base64 destination.
      Returns:
      the Base64 destination
    • getProps

      public OrderedProperties getProps()
      Return the properties, or null.
      Returns:
      the properties, or null
    • parseProps

      private static OrderedProperties parseProps(String line) throws IllegalArgumentException
      Part after the #!.
      Parameters:
      line - part after the #!
      Returns:
      the parsed properties
      Throws:
      IllegalArgumentException - on dup key and other errors
    • write

      public void write(BufferedWriter out) throws IOException
      Write as a standard line name=dest[#!k1=v1#k2=v2...] Includes newline.
      Parameters:
      out - the writer to write to
      Throws:
      IOException - if writing fails
    • write

      public void write(Writer out) throws IOException
      Write as a standard line name=dest[#!k1=v1#k2=v2...] Does not include newline.
      Parameters:
      out - the writer to write to
      Throws:
      IOException - if writing fails
    • writeRemoveLine

      public void writeRemoveLine(BufferedWriter out) throws IOException
      Write as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] This works whether constructed with name and dest, or just properties. Includes newline. Must have been constructed with non-null properties.
      Parameters:
      out - the writer to write to
      Throws:
      IOException - if writing fails
    • writeRemove

      public void writeRemove(Writer out) throws IOException
      Write as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] This works whether constructed with name and dest, or just properties. Does not include newline. Must have been constructed with non-null properties.
      Parameters:
      out - the writer to write to
      Throws:
      IOException - if writing fails
    • writeProps

      public void writeProps(Writer out) throws IOException
      Write the props part (if any) only, without newline.
      Parameters:
      out - the writer to write to
      Throws:
      IOException - if writing fails
    • writeProps

      private void writeProps(Writer out, boolean omitSig, boolean omitOldSig) throws IOException
      Write the props part (if any) only, without newline.
      Parameters:
      out - the writer to write to
      omitSig - true to skip the "sig" property
      omitOldSig - true to skip the "oldsig" property
      Throws:
      IOException - if writing fails
    • hasValidSig

      public boolean hasValidSig()
      Verify with the dest public key using the "sig" property.
      Returns:
      whether valid sig is present
    • hasValidInnerSig

      public boolean hasValidInnerSig()
      Verify with the "olddest" property's public key using the "oldsig" property.
      Returns:
      whether valid inner sig is present
    • hasValidRemoveSig

      public boolean hasValidRemoveSig()
      Verify with the "dest" property's public key using the "sig" property.
      Returns:
      whether valid remove sig is present
    • hashCode

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

      public boolean equals(Object o)
      Compares Destination only, not properties.
      Overrides:
      equals in class Object
    • sign

      public void sign(SigningPrivateKey spk)
      Sign and set the "sig" property Must have been constructed with non-null properties.
      Parameters:
      spk - the signing key the entry's destination is signed with, so a receiver can tell the entry was issued by the destination itself
    • signInner

      public void signInner(SigningPrivateKey spk)
      Sign and set the "oldsig" property Must have been constructed with non-null properties.
      Parameters:
      spk - the signing key used for the "oldsig" signature, which covers the entry as previously published and lets the server tell an unchanged entry from one that has since been replaced
    • signRemove

      public void signRemove(SigningPrivateKey spk)
      Sign as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] Must have been constructed with non-null properties.
      Parameters:
      spk - the signing key the removal line is signed with, identifying the key that published the entry being withdrawn
    • signIt

      private void signIt(SigningPrivateKey spk, String sigprop)
      Sign the entry and set the specified signature property.
      Parameters:
      spk - the signing private key
      sigprop - The signature property to set