net.i2p.data
Class PrivateKeyFile

java.lang.Object
  extended by net.i2p.data.PrivateKeyFile

public class PrivateKeyFile
extends java.lang.Object

This helper class reads and writes files in the same "eepPriv.dat" format used by the client code. The format is: - Destination (387 bytes if no certificate, otherwise longer) - Public key (256 bytes) - Signing Public key (128 bytes) - Cert. type (1 byte) - Cert. length (2 bytes) - Certificate if length != 0 - Private key (256 bytes) - Signing Private key (20 bytes) Total 663 bytes

Author:
welterde, zzz

Constructor Summary
PrivateKeyFile(java.io.File file)
           
PrivateKeyFile(java.io.File file, I2PClient client)
           
PrivateKeyFile(java.lang.String file)
           
 
Method Summary
static boolean checkSignature(Signature s, byte[] data, SigningPublicKey spk)
           
 Destination createIfAbsent()
          Also reads in the file to get the privKey and signingPrivKey, which aren't available from I2PClient.
static java.lang.String estimateHashCashTime(int hashEffort)
           
 Destination getDestination()
          Also sets the local privKey and signingPrivKey
 PrivateKey getPrivKey()
           
 SigningPrivateKey getSigningPrivKey()
           
static void main(java.lang.String[] args)
          Create a new PrivateKeyFile, or modify an existing one, with various types of Certificates.
 I2PSession open()
           
 I2PSession open(java.util.Properties opts)
           
 Certificate setCertType(int t)
          change cert type - caller must also call write()
 void setDestination(Destination d)
           
 Certificate setHashCashCert(int effort)
          change to hashcash cert - caller must also call write()
 Certificate setSignedCert(PrivateKeyFile pkf2)
          sign this dest by dest found in pkf2 - caller must also call write()
 java.lang.String toString()
           
static boolean verifySignature(Destination d)
          Sample code to verify a 3rd party signature.
 void write()
          Copied from I2PClientImpl.createDestination()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrivateKeyFile

public PrivateKeyFile(java.lang.String file)

PrivateKeyFile

public PrivateKeyFile(java.io.File file)

PrivateKeyFile

public PrivateKeyFile(java.io.File file,
                      I2PClient client)
Method Detail

main

public static void main(java.lang.String[] args)
Create a new PrivateKeyFile, or modify an existing one, with various types of Certificates. Changing a Certificate does not change the public or private keys. But it does change the Destination Hash, which effectively makes it a new Destination. In other words, don't change the Certificate on a Destination you've already registered in a hosts.txt key add form. Copied and expanded from that in Destination.java


createIfAbsent

public Destination createIfAbsent()
                           throws I2PException,
                                  java.io.IOException,
                                  DataFormatException
Also reads in the file to get the privKey and signingPrivKey, which aren't available from I2PClient.

Throws:
I2PException
java.io.IOException
DataFormatException

getDestination

public Destination getDestination()
                           throws I2PSessionException,
                                  java.io.IOException,
                                  DataFormatException
Also sets the local privKey and signingPrivKey

Throws:
I2PSessionException
java.io.IOException
DataFormatException

setDestination

public void setDestination(Destination d)

setCertType

public Certificate setCertType(int t)
change cert type - caller must also call write()


setHashCashCert

public Certificate setHashCashCert(int effort)
change to hashcash cert - caller must also call write()


setSignedCert

public Certificate setSignedCert(PrivateKeyFile pkf2)
sign this dest by dest found in pkf2 - caller must also call write()


getPrivKey

public PrivateKey getPrivKey()

getSigningPrivKey

public SigningPrivateKey getSigningPrivKey()

open

public I2PSession open()
                throws I2PSessionException,
                       java.io.IOException
Throws:
I2PSessionException
java.io.IOException

open

public I2PSession open(java.util.Properties opts)
                throws I2PSessionException,
                       java.io.IOException
Throws:
I2PSessionException
java.io.IOException

write

public void write()
           throws java.io.IOException,
                  DataFormatException
Copied from I2PClientImpl.createDestination()

Throws:
java.io.IOException
DataFormatException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

estimateHashCashTime

public static java.lang.String estimateHashCashTime(int hashEffort)

verifySignature

public static boolean verifySignature(Destination d)
Sample code to verify a 3rd party signature. This just goes through all the hosts.txt files and tries everybody. You need to be in the $I2P directory or have a local hosts.txt for this to work. Doubt this is what you want as it is super-slow, and what good is a signing scheme where anybody is allowed to sign? In a real application you would make a list of approved signers, do a naming lookup to get their Destinations, and try those only. Or do a netDb lookup of the Hash in the Certificate, do a reverse naming lookup to see if it is allowed, then verify the Signature.


checkSignature

public static boolean checkSignature(Signature s,
                                     byte[] data,
                                     SigningPublicKey spk)