Changeset efebecf


Ignore:
Timestamp:
Aug 22, 2014 2:34:13 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d7616467
Parents:
7b64586
Message:
  • SigTypes?:
    • Add isSupportedSince(), use in floodfill selection
    • Handle mixed-case 25519 enum
    • Fix 25519 type code
    • Add dup type code check
Files:
6 edited

Legend:

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

    r7b64586 refebecf  
    3030     *  @since 0.9.8
    3131     */
    32     DSA_SHA1(0, 128, 20, 20, 40, SigAlgo.DSA, "SHA-1", "SHA1withDSA", CryptoConstants.DSA_SHA1_SPEC),
     32    DSA_SHA1(0, 128, 20, 20, 40, SigAlgo.DSA, "SHA-1", "SHA1withDSA", CryptoConstants.DSA_SHA1_SPEC, "0"),
    3333    /**  Pubkey 64 bytes; privkey 32 bytes; hash 32 bytes; sig 64 bytes */
    34     ECDSA_SHA256_P256(1, 64, 32, 32, 64, SigAlgo.EC, "SHA-256", "SHA256withECDSA", ECConstants.P256_SPEC),
     34    ECDSA_SHA256_P256(1, 64, 32, 32, 64, SigAlgo.EC, "SHA-256", "SHA256withECDSA", ECConstants.P256_SPEC, "0.9.12"),
    3535    /**  Pubkey 96 bytes; privkey 48 bytes; hash 48 bytes; sig 96 bytes */
    36     ECDSA_SHA384_P384(2, 96, 48, 48, 96, SigAlgo.EC, "SHA-384", "SHA384withECDSA", ECConstants.P384_SPEC),
     36    ECDSA_SHA384_P384(2, 96, 48, 48, 96, SigAlgo.EC, "SHA-384", "SHA384withECDSA", ECConstants.P384_SPEC, "0.9.12"),
    3737    /**  Pubkey 132 bytes; privkey 66 bytes; hash 64 bytes; sig 132 bytes */
    38     ECDSA_SHA512_P521(3, 132, 66, 64, 132, SigAlgo.EC, "SHA-512", "SHA512withECDSA", ECConstants.P521_SPEC),
     38    ECDSA_SHA512_P521(3, 132, 66, 64, 132, SigAlgo.EC, "SHA-512", "SHA512withECDSA", ECConstants.P521_SPEC, "0.9.12"),
    3939
    4040    /**  Pubkey 256 bytes; privkey 512 bytes; hash 32 bytes; sig 256 bytes */
    41     RSA_SHA256_2048(4, 256, 512, 32, 256, SigAlgo.RSA, "SHA-256", "SHA256withRSA", RSAConstants.F4_2048_SPEC),
     41    RSA_SHA256_2048(4, 256, 512, 32, 256, SigAlgo.RSA, "SHA-256", "SHA256withRSA", RSAConstants.F4_2048_SPEC, "0.9.12"),
    4242    /**  Pubkey 384 bytes; privkey 768 bytes; hash 48 bytes; sig 384 bytes */
    43     RSA_SHA384_3072(5, 384, 768, 48, 384, SigAlgo.RSA, "SHA-384", "SHA384withRSA", RSAConstants.F4_3072_SPEC),
     43    RSA_SHA384_3072(5, 384, 768, 48, 384, SigAlgo.RSA, "SHA-384", "SHA384withRSA", RSAConstants.F4_3072_SPEC, "0.9.12"),
    4444    /**  Pubkey 512 bytes; privkey 1024 bytes; hash 64 bytes; sig 512 bytes */
    45     RSA_SHA512_4096(6, 512, 1024, 64, 512, SigAlgo.RSA, "SHA-512", "SHA512withRSA", RSAConstants.F4_4096_SPEC),
    46 
     45    RSA_SHA512_4096(6, 512, 1024, 64, 512, SigAlgo.RSA, "SHA-512", "SHA512withRSA", RSAConstants.F4_4096_SPEC, "0.9.12"),
     46
     47    /**
     48     *  Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes
     49     *  @since 0.9.15
     50     */
     51    EdDSA_SHA512_Ed25519(7, 32, 32, 64, 64, SigAlgo.EdDSA, "SHA-512", "SHA512withEdDSA", EdDSANamedCurveTable.getByName("ed25519-sha-512"), "0.9.15");
    4752
    4853
    4954    // TESTING....................
    5055
    51     /** Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes; */
    52     EdDSA_SHA512_Ed25519(4, 32, 32, 64, 64, SigAlgo.EdDSA, "SHA-512", "SHA512withEdDSA", EdDSANamedCurveTable.getByName("ed25519-sha-512"));
    5356
    5457    // others..........
     
    9194    private final int code, pubkeyLen, privkeyLen, hashLen, sigLen;
    9295    private final SigAlgo base;
    93     private final String digestName, algoName;
     96    private final String digestName, algoName, since;
    9497    private final AlgorithmParameterSpec params;
    9598
    9699    SigType(int cod, int pubLen, int privLen, int hLen, int sLen, SigAlgo baseAlgo,
    97             String mdName, String aName, AlgorithmParameterSpec pSpec) {
     100            String mdName, String aName, AlgorithmParameterSpec pSpec, String supportedSince) {
    98101        code = cod;
    99102        pubkeyLen = pubLen;
     
    105108        algoName = aName;
    106109        params = pSpec;
     110        since = supportedSince;
    107111    }
    108112
     
    164168
    165169    /**
     170     *  The router version in which this type was first supported.
     171     *
     172     *  @since 0.9.15
     173     */
     174    public String getSupportedSince() {
     175        return since;
     176    }
     177
     178    /**
    166179     *  @since 0.9.12
    167180     *  @return true if supported in this JVM
     
    209222    static {
    210223        for (SigType type : SigType.values()) {
    211             BY_CODE.put(Integer.valueOf(type.getCode()), type);
     224            if (BY_CODE.put(Integer.valueOf(type.getCode()), type) != null)
     225                throw new IllegalStateException("Duplicate SigType code");
    212226        }
    213227    }
     
    227241    public static SigType parseSigType(String stype) {
    228242        try {
    229             return valueOf(stype.toUpperCase(Locale.US));
     243            String uc = stype.toUpperCase(Locale.US);
     244            // handle mixed-case enum
     245            if (uc.equals("EDDSA_SHA512_ED25519"))
     246                return EdDSA_SHA512_Ed25519;
     247            return valueOf(uc);
    230248        } catch (IllegalArgumentException iae) {
    231249            try {
  • core/java/src/net/i2p/crypto/provider/I2PProvider.java

    r7b64586 refebecf  
    55import java.security.Provider;
    66
     7/**
     8 *  @since 0.9.15
     9 */
    710public final class I2PProvider extends Provider {
    811    public static final String PROVIDER_NAME = "I2P";
  • history.txt

    r7b64586 refebecf  
     12014-08-22 zzz
     2 * SigTypes:
     3   - Add isSupportedSince(), use in floodfill selection
     4   - Handle mixed-case 25519 enum
     5   - Fix 25519 type code
     6   - Add dup type code check
     7
     82014-08-21 str4d
     9 * Add Ed25519 SigType
     10
    1112014-08-21 zzz
    212 * i2psnark:
  • router/java/src/net/i2p/router/RouterVersion.java

    r7b64586 refebecf  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 8;
     21    public final static long BUILD = 9;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java

    r7b64586 refebecf  
    172172        Hash rkey = getContext().routingKeyGenerator().getRoutingKey(_key);
    173173        FloodfillPeerSelector sel = (FloodfillPeerSelector)_facade.getPeerSelector();
    174         boolean isKeyCert = false;
     174        Certificate keyCert = null;
    175175        if (!_isRouterInfo) {
    176176            LeaseSet ls = _facade.lookupLeaseSetLocally(_key);
    177             if (ls != null &&
    178                 ls.getDestination().getCertificate().getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY)
    179                 isKeyCert = true;
    180         }
    181         if (isKeyCert) {
     177            if (ls != null) {
     178                Certificate cert = ls.getDestination().getCertificate();
     179                if (cert.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY)
     180                    keyCert = cert;
     181            }
     182        }
     183        if (keyCert != null) {
    182184            while (true) {
    183185                List<Hash> peers = sel.selectFloodfillParticipants(rkey, 1, _ignore, _facade.getKBuckets());
     
    186188                Hash peer = peers.get(0);
    187189                RouterInfo ri = _facade.lookupRouterInfoLocally(peer);
    188                 if (ri != null && StoreJob.supportsKeyCerts(ri))
     190                if (ri != null && StoreJob.supportsCert(ri, keyCert))
    189191                    return peer;
    190192                if (_log.shouldLog(Log.INFO))
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    r7b64586 refebecf  
    1313import java.util.Set;
    1414
     15import net.i2p.crypto.SigType;
    1516import net.i2p.data.Certificate;
    1617import net.i2p.data.DatabaseEntry;
     18import net.i2p.data.DataFormatException;
    1719import net.i2p.data.Hash;
    1820import net.i2p.data.LeaseSet;
     
    171173                    skipped++;
    172174                } else if (_state.getData().getType() == DatabaseEntry.KEY_TYPE_LEASESET &&
    173                            ((LeaseSet)_state.getData()).getDestination().getCertificate().getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY &&
    174                            !supportsKeyCerts((RouterInfo)ds)) {
     175                           !supportsCert((RouterInfo)ds,
     176                                         ((LeaseSet)_state.getData()).getDestination().getCertificate())) {
    175177                    if (_log.shouldLog(Log.INFO))
    176178                        _log.info(getJobId() + ": Skipping router that doesn't support key certs " + peer);
     
    518520    }
    519521
    520     private static final String MIN_KEYCERT_VERSION = "0.9.12";
    521 
    522     /**
    523      * Does he support key certs (assumed with a non-DSA key)?
     522    /**
     523     * Does this router understand this cert?
     524     * @return true if not a key cert
    524525     * @since 0.9.12
    525526     */
    526     public static boolean supportsKeyCerts(RouterInfo ri) {
     527    public static boolean supportsCert(RouterInfo ri, Certificate cert) {
     528        if (cert.getCertificateType() != Certificate.CERTIFICATE_TYPE_KEY)
     529            return true;
     530        SigType type;
     531        try {
     532            type = cert.toKeyCertificate().getSigType();
     533        } catch (DataFormatException dfe) {
     534            return false;
     535        }
     536        if (type == null)
     537            return false;
    527538        String v = ri.getOption("router.version");
    528539        if (v == null)
    529540            return false;
    530         return VersionComparator.comp(v, MIN_KEYCERT_VERSION) >= 0;
     541        String since = type.getSupportedSince();
     542        return VersionComparator.comp(v, since) >= 0;
    531543    }
    532544
Note: See TracChangeset for help on using the changeset viewer.