Package net.i2p.sam

Class SAMUtils


  • class SAMUtils
    extends Object
    Miscellaneous utility methods used by SAM protocol handlers.
    Author:
    human
    • Constructor Detail

      • SAMUtils

        SAMUtils()
    • Method Detail

      • genRandomKey

        public static void genRandomKey​(OutputStream priv,
                                        OutputStream pub)
        Generate a random destination key using DSA_SHA1 signature type. Caller must close streams. Fails silently.
        Parameters:
        priv - Stream used to write the destination and private keys
        pub - Stream used to write the destination (may be null)
      • genRandomKey

        public static void genRandomKey​(OutputStream priv,
                                        OutputStream pub,
                                        SigType sigType)
        Generate a random destination key. Caller must close streams. Fails silently.
        Parameters:
        priv - Stream used to write the destination and private keys
        pub - Stream used to write the destination (may be null)
        sigType - what signature type
        Since:
        0.9.14
      • checkPrivateDestination

        public static boolean checkPrivateDestination​(String dest)
        Check whether a base64-encoded {dest,privkey,signingprivkey[,offlinesig]} is valid This only checks that the length is correct. It does not validate for pubkey/privkey match, or check the signatures.
        Parameters:
        dest - The base64-encoded destination and keys to be checked (same format as PrivateKeyFile)
        Returns:
        true if valid
      • getDest

        public static Destination getDest​(String s)
                                   throws DataFormatException
        Resolve the destination from a key or a hostname
        Parameters:
        s - Hostname or key to be resolved
        Returns:
        the Destination for the specified hostname, non-null
        Throws:
        DataFormatException - on bad Base 64 or name not found
      • parseParams

        public static Properties parseParams​(String args)
                                      throws SAMException
        Parse SAM parameters, and put them into a Propetries object Modified from EepGet. COMMAND and OPCODE are mapped to upper case; keys, values, and ping data are not. Double quotes around values are stripped. Possible input:
          COMMAND
          COMMAND OPCODE
          COMMAND OPCODE [key=val]...
          COMMAND OPCODE [key=" val with spaces "]...
          PING
          PONG
          PING any   thing goes
          PONG any   thing   goes
        
          Escaping is allowed with a backslash, e.g. \"
          No spaces before or after '=' allowed
          Keys may not be quoted
          COMMAND, OPCODE, and keys may not have '=' or whitespace unless escaped
          Duplicate keys not allowed
        
        A key without a value is not allowed by the spec, but is returned with the value "true". COMMAND is returned as the value of the key ""COMMAND"". OPCODE, or the remainder of the PING/PONG line if any, is returned as the value of the key ""OPCODE"".
        Parameters:
        args - non-null
        Returns:
        non-null, may be empty. Does not throw on missing COMMAND or OPCODE; caller must check.
        Throws:
        SAMException - on some errors but not all