Changeset 7d4acb62 for core


Ignore:
Timestamp:
Apr 10, 2019 7:52:03 PM (12 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
9a72c4b
Parents:
cddace2
Message:

i2ptunnel: Display encrypted b32
Blinding: Allow secret flag without attached secret

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/Blinding.java

    rcddace2 r7d4acb62  
    3333    private static final String INFO = "i2pblinding1";
    3434    private static final byte[] INFO_ALPHA = DataHelper.getASCII("I2PGenerateAlpha");
     35
     36    private static final byte FLAG_TWOBYTE = 0x01;
     37    private static final byte FLAG_SECRET = 0x02;
     38    private static final byte FLAG_AUTH = 0x04;
    3539
    3640    // following copied from RouterKeyGenerator
     
    234238        if ((flag & 0xf8) != 0)
    235239            throw new IllegalArgumentException("Corrupt b32 or unsupported options");
    236         if ((flag & 0x01) != 0)
     240        if ((flag & FLAG_TWOBYTE) != 0)
    237241            throw new IllegalArgumentException("Two byte sig types unsupported");
    238         if ((flag & 0x04) != 0)
     242        if ((flag & FLAG_AUTH) != 0)
    239243            throw new IllegalArgumentException("Per-client auth unsupported");
    240244        // TODO two-byte sigtypes
     
    259263        SigningPublicKey spk = new SigningPublicKey(sigt1, spkData);
    260264        String secret;
    261         if ((flag & 0x02) != 0) {
    262             if (4 + spkLen > b.length)
    263                 throw new IllegalArgumentException("No secret data");
    264             int secLen = b[3 + spkLen] & 0xff;
    265             if (4 + spkLen + secLen != b.length)
    266                 throw new IllegalArgumentException("Bad b32 length");
    267             secret = DataHelper.getUTF8(b, 4 + spkLen, secLen);
     265        if ((flag & FLAG_SECRET) != 0) {
     266            if (4 + spkLen > b.length) {
     267                //throw new IllegalArgumentException("No secret data");
     268                secret = null;
     269            } else {
     270                int secLen = b[3 + spkLen] & 0xff;
     271                if (4 + spkLen + secLen != b.length)
     272                    throw new IllegalArgumentException("Bad b32 length");
     273                secret = DataHelper.getUTF8(b, 4 + spkLen, secLen);
     274            }
    268275        } else if (3 + spkLen != b.length) {
    269276            throw new IllegalArgumentException("b32 too long");
     
    279286     *  PRELIMINARY - Subject to change - see proposal 149
    280287     *
     288     *  @return (56 chars).b32.i2p
     289     *  @throws IllegalArgumentException on bad inputs
     290     *  @throws UnsupportedOperationException unless supported SigTypes
     291     *  @since 0.9.40
     292     */
     293    public static String encode(I2PAppContext ctx, SigningPublicKey key) throws RuntimeException {
     294        return encode(ctx, key, false, false, null);
     295    }
     296
     297    /**
     298     *  Encode a public key as a new-format b32 address.
     299     *  PRELIMINARY - Subject to change - see proposal 149
     300     *
     301     *  @return (56 chars).b32.i2p
     302     *  @throws IllegalArgumentException on bad inputs
     303     *  @throws UnsupportedOperationException unless supported SigTypes
     304     *  @since 0.9.40
     305     */
     306    public static String encode(I2PAppContext ctx, SigningPublicKey key,
     307                                boolean requireSecret, boolean requireAuth) throws RuntimeException {
     308        return encode(ctx, key, requireSecret, requireAuth, null);
     309    }
     310
     311    /**
     312     *  Encode a public key as a new-format b32 address.
     313     *  PRELIMINARY - Subject to change - see proposal 149
     314     *
    281315     *  @param secret may be empty or null
    282316     *  @return (56+ chars).b32.i2p
     
    285319     *  @since 0.9.40
    286320     */
    287     public static String encode(I2PAppContext ctx, SigningPublicKey key, String secret) throws RuntimeException {
     321    public static String encode(I2PAppContext ctx, SigningPublicKey key,
     322                                boolean requireSecret, boolean requireAuth,
     323                                String secret) throws RuntimeException {
    288324        SigType type = key.getType();
    289325        if (type != TYPE && type != TYPER)
     
    304340        long check = crc.getValue();
    305341        // TODO two-byte sigtypes
    306         if (slen > 0)
    307             b[0] = 0x02;
     342        if (slen > 0 || requireSecret)
     343            b[0] = FLAG_SECRET;
     344        if (requireAuth)
     345            b[0] |= FLAG_AUTH;
    308346        b[1] = (byte) (type.getCode() & 0xff);
    309347        b[2] = (byte) (TYPER.getCode() & 0xff);
Note: See TracChangeset for help on using the changeset viewer.