java.lang.Object
net.i2p.sam.SAMUtils
Protocol helpers for SAM: destination/key parsing, naming lookups, SAM parameter parsing, and random destination generation.
Field Summary
Constructor Summary
ConstructorsConstructorDescriptionSAMUtils()The parsers and key helpers below are static, and so is the logger, so an instance carries nothing.Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck whether a base64-encoded {dest,privkey,signingprivkey[,offlinesig]} is validstatic voidgenRandomKey(OutputStream priv, OutputStream pub) Generate a random destination key using DSA_SHA1 signature type.static voidgenRandomKey(OutputStream priv, OutputStream pub, SigType sigType) Generate a random destination key.static DestinationResolve the destination from a key or a hostname.private static DestinationlookupHost(String name) Resolved the specified hostname.static PropertiesparseParams(String args) Parse SAM parameters, and put them into a Properties object
Field Details
_log
Logger for this class.COMMAND
The key for the command portion of a parsed SAM message.- See Also:
OPCODE
The key for the opcode portion of a parsed SAM message.- See Also:
Constructor Details
SAMUtils
SAMUtils()The parsers and key helpers below are static, and so is the logger, so an instance carries nothing.
Method Details
genRandomKey
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 keyspub- Stream used to write the destination (may be null)
genRandomKey
Generate a random destination key. Caller must close streams. Fails silently.- Parameters:
priv- Stream used to write the destination and private keyspub- Stream used to write the destination (may be null)sigType- what signature type
checkPrivateDestination
Check whether a base64-encoded {dest,privkey,signingprivkey[,offlinesig]} is validThis 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
lookupHost
Resolved the specified hostname.- Parameters:
name- Hostname to be resolved- Returns:
- the Destination for the specified hostname, or null if not found
getDest
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 Base64 or name not found
parseParams
Parse SAM parameters, and put them into a Properties objectModified 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