Changeset 33b1851 for core


Ignore:
Timestamp:
Feb 23, 2017 7:45:33 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f420a99
Parents:
3c735ea
Message:

PrivateKeyFile?: Add option to generate addressbook authentication string
fix inadvertent fallthru
HostTxtParser?: Add -q command line option, enhance return codes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/PrivateKeyFile.java

    r3c735ea r33b1851  
    99import java.io.IOException;
    1010import java.io.OutputStream;
     11import java.io.OutputStreamWriter;
    1112import java.security.GeneralSecurityException;
    1213import java.security.NoSuchAlgorithmException;
     
    2425import net.i2p.client.I2PSession;
    2526import net.i2p.client.I2PSessionException;
     27import net.i2p.client.naming.HostTxtEntry;
    2628import net.i2p.crypto.DSAEngine;
    2729import net.i2p.crypto.KeyGenerator;
    2830import net.i2p.crypto.SigType;
     31import net.i2p.util.OrderedProperties;
    2932import net.i2p.util.RandomSource;
    3033import net.i2p.util.SecureFileOutputStream;
     
    7376        int hashEffort = HASH_EFFORT;
    7477        String stype = null;
     78        String hostname = null;
    7579        int mode = 0;
    7680        boolean error = false;
    77         Getopt g = new Getopt("pkf", args, "t:nuxhse:c:");
     81        Getopt g = new Getopt("pkf", args, "t:nuxhse:c:a:");
    7882        int c;
    7983        while ((c = g.getopt()) != -1) {
     
    9296            case 'h':
    9397            case 's':
     98                if (mode == 0)
     99                    mode = c;
     100                else
     101                    error = true;
     102                break;
     103
     104            case 'a':
     105                hostname = g.getOptarg();
    94106                if (mode == 0)
    95107                    mode = c;
     
    172184                pkf.setSignedCert(pkf2);
    173185                System.out.println("New destination with signed cert is:");
     186                break;
    174187
    175188              case 't':
     
    182195                break;
    183196
     197              case 'a':
     198                // addressbook auth
     199                OrderedProperties props = new OrderedProperties();
     200                HostTxtEntry he = new HostTxtEntry(hostname, d.toBase64(), props);
     201                he.sign(pkf.getSigningPrivKey());
     202                System.out.println("Addressbook Authentication String:");
     203                OutputStreamWriter out = new OutputStreamWriter(System.out);
     204                he.write(out);
     205                out.flush();
     206                System.out.println("");
     207                return;
     208
    184209              default:
    185210                // shouldn't happen
     
    203228    private static void usage() {
    204229        System.err.println("Usage: PrivateKeyFile [-c sigtype] filename (generates if nonexistent, then prints)\n" +
     230                           "       PrivateKeyFile -a example.i2p filename (generate addressbook authentication string)\n" +
    205231                           "       PrivateKeyFile -h filename (generates if nonexistent, adds hashcash cert)\n" +
    206232                           "       PrivateKeyFile -h -e effort filename (specify HashCash effort instead of default " + HASH_EFFORT + ")\n" +
Note: See TracChangeset for help on using the changeset viewer.