Changeset 3379432


Ignore:
Timestamp:
Jun 27, 2014 9:05:54 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f191e50
Parents:
bb9129b
Message:

SAM: Cherrypick from patch in ticket #1318:

  • Check for extra bytes in private key string
  • checkPrivateDestination() returns boolean instead of throws
Location:
apps/sam/java/src/net/i2p/sam
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/sam/java/src/net/i2p/sam/SAMUtils.java

    rbb9129b r3379432  
    7878        }
    7979    }
    80    
    81     public static class InvalidDestinationException extends Exception {
    82         private static final long serialVersionUID = 0x1;
    83     }
    84 
    8580
    8681    /**
     
    8883     *
    8984     * @param dest The base64-encoded destination and keys to be checked (same format as PrivateKeyFile)
    90      *
    91      * @throws InvalidDestination if invalid
    92      */
    93     public static void checkPrivateDestination(String dest) throws InvalidDestinationException {
     85     * @return true if valid
     86     */
     87    public static boolean checkPrivateDestination(String dest) {
    9488        ByteArrayInputStream destKeyStream = new ByteArrayInputStream(Base64.decode(dest));
    95 
    9689        try {
    9790                Destination d = new Destination();
     
    10093                SigningPrivateKey spk = new SigningPrivateKey(d.getSigningPublicKey().getType());
    10194                spk.readBytes(destKeyStream);
    102         } catch (Exception e) {
    103                 throw new InvalidDestinationException();
     95        } catch (DataFormatException e) {
     96                return false;
     97        } catch (IOException e) {
     98                return false;
    10499        }
     100        return destKeyStream.available() == 0;
    105101    }
    106102
  • apps/sam/java/src/net/i2p/sam/SAMv3Handler.java

    rbb9129b r3379432  
    501501                                }
    502502
    503                                 try {
    504                                         SAMUtils.checkPrivateDestination(dest);
    505                                 } catch ( SAMUtils.InvalidDestinationException e ) {
    506                     return writeString("SESSION STATUS RESULT=INVALID_KEY\n");
    507                                 }
     503                                if (!SAMUtils.checkPrivateDestination(dest))
     504                                        return writeString("SESSION STATUS RESULT=INVALID_KEY\n");
    508505
    509506                                nick = props.getProperty("ID");
Note: See TracChangeset for help on using the changeset viewer.