Changeset f0b9986e for core


Ignore:
Timestamp:
Mar 2, 2019 4:00:56 PM (13 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
335736b
Parents:
82d1874
Message:

Enc LS2 debug logging changes

File:
1 edited

Legend:

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

    r82d1874 rf0b9986e  
    3131    private Hash __calculatedHash;
    3232    private SigningPrivateKey _alpha;
     33    private final Log _log;
    3334
    3435    private static final int MIN_ENCRYPTED_SIZE = 8 + 16;
     
    4344    public EncryptedLeaseSet() {
    4445        super();
     46        _log = I2PAppContext.getGlobalContext().logManager().getLog(EncryptedLeaseSet.class);
    4547    }
    4648
     
    335337        System.arraycopy(salt, 0, ciphertext, 1, SALT_LEN);
    336338        ChaCha20.encrypt(key, iv, plaintext, 0, ciphertext, 1 + SALT_LEN, plaintext.length);
    337         System.out.println("Encrypt: inner plaintext:\n" + net.i2p.util.HexDump.dump(plaintext));
    338         System.out.println("Encrypt: inner ciphertext:\n" + net.i2p.util.HexDump.dump(ciphertext));
     339        if (_log.shouldDebug()) {
     340            _log.debug("Encrypt: inner plaintext:\n" + net.i2p.util.HexDump.dump(plaintext));
     341            _log.debug("Encrypt: inner ciphertext:\n" + net.i2p.util.HexDump.dump(ciphertext));
     342        }
    339343
    340344        // layer 1 (outer) encryption
     
    346350        System.arraycopy(salt, 0, ciphertext, 0, SALT_LEN);
    347351        ChaCha20.encrypt(key, iv, plaintext, 0, ciphertext, SALT_LEN, plaintext.length);
    348         System.out.println("Encrypt: outer ciphertext:\n" + net.i2p.util.HexDump.dump(ciphertext));
     352        if (_log.shouldDebug())
     353            _log.debug("Encrypt: outer ciphertext:\n" + net.i2p.util.HexDump.dump(ciphertext));
    349354        _encryptedData = ciphertext;
    350355    }
     
    374379        hkdf.calculate(ciphertext, input, ELS2L1K, key, iv, 0);
    375380        ChaCha20.decrypt(key, iv, ciphertext, SALT_LEN, plaintext, 0, plaintext.length);
    376         System.out.println("Decrypt: outer ciphertext:\n" + net.i2p.util.HexDump.dump(ciphertext));
    377         System.out.println("Decrypt: outer plaintext:\n" + net.i2p.util.HexDump.dump(plaintext));
     381        if (_log.shouldDebug()) {
     382            _log.debug("Decrypt: outer ciphertext:\n" + net.i2p.util.HexDump.dump(ciphertext));
     383            _log.debug("Decrypt: outer plaintext:\n" + net.i2p.util.HexDump.dump(plaintext));
     384        }
    378385
    379386        boolean perClient = (plaintext[0] & 0x01) != 0;
     
    392399        hkdf.calculate(salt, input, ELS2L2K, key, iv, 0);
    393400        ChaCha20.decrypt(key, iv, ciphertext, 1 + SALT_LEN, plaintext, 0, plaintext.length);
    394         System.out.println("Decrypt: inner plaintext:\n" + net.i2p.util.HexDump.dump(plaintext));
     401        if (_log.shouldDebug())
     402            _log.debug("Decrypt: inner plaintext:\n" + net.i2p.util.HexDump.dump(plaintext));
    395403        ByteArrayInputStream bais = new ByteArrayInputStream(plaintext);
    396404        int type = bais.read();
     
    462470    @Override
    463471    public void sign(SigningPrivateKey key) throws DataFormatException {
    464         Log log = I2PAppContext.getGlobalContext().logManager().getLog(EncryptedLeaseSet.class);
    465472        // now sign inner with the unblinded key
    466473        // inner LS is always unpublished
     
    469476        super.sign(key);
    470477        _flags = saveFlags;
    471         if (log.shouldDebug()) {
    472             log.debug("Sign inner with key: " + key.getType() + ' ' + key.toBase64());
    473             log.debug("Corresponding pubkey: " + key.toPublic().toBase64());
    474             log.debug("Sign inner: " + _signature.getType() + ' ' + _signature.toBase64());
     478        if (_log.shouldDebug()) {
     479            _log.debug("Sign inner with key: " + key.getType() + ' ' + key.toBase64());
     480            _log.debug("Corresponding pubkey: " + key.toPublic().toBase64());
     481            _log.debug("Sign inner: " + _signature.getType() + ' ' + _signature.toBase64());
    475482        }
    476483        encrypt(null);
     
    490497        if (_signature == null)
    491498            throw new DataFormatException("Signature failed with " + key.getType() + " key");
    492         if (log.shouldDebug()) {
    493             log.debug("Sign outer with key: " + bkey.getType() + ' ' + bkey.toBase64());
    494             log.debug("Corresponding pubkey: " + bkey.toPublic().toBase64());
    495             log.debug("Sign outer: " + _signature.getType() + ' ' + _signature.toBase64());
     499        if (_log.shouldDebug()) {
     500            _log.debug("Sign outer with key: " + bkey.getType() + ' ' + bkey.toBase64());
     501            _log.debug("Corresponding pubkey: " + bkey.toPublic().toBase64());
     502            _log.debug("Sign outer: " + _signature.getType() + ' ' + _signature.toBase64());
    496503        }
    497504    }
     
    506513    @Override
    507514    public boolean verifySignature() {
    508         Log log = I2PAppContext.getGlobalContext().logManager().getLog(EncryptedLeaseSet.class);
    509         if (log.shouldDebug()) {
    510             log.debug("Sig verify outer with key: " + _signingKey.getType() + ' ' + _signingKey.toBase64());
    511             log.debug("Sig verify outer: " + _signature.getType() + ' ' + _signature.toBase64());
     515        if (_log.shouldDebug()) {
     516            _log.debug("Sig verify outer with key: " + _signingKey.getType() + ' ' + _signingKey.toBase64());
     517            _log.debug("Sig verify outer: " + _signature.getType() + ' ' + _signature.toBase64());
    512518        }
    513519        if (!super.verifySignature()) {
    514             log.error("ELS2 outer sig verify fail");
     520            _log.warn("ELS2 outer sig verify fail");
    515521            return false;
    516522        }
    517         log.error("ELS2 outer sig verify success");
     523        _log.info("ELS2 outer sig verify success");
    518524        if (_destination == null) {
    519             log.warn("ELS2 no dest to decrypt with");
     525            _log.warn("ELS2 no dest to decrypt with");
    520526            return true;
    521527        }
     
    523529            decrypt();
    524530        } catch (DataFormatException dfe) {
    525             log.error("ELS2 decrypt fail", dfe);
     531            _log.warn("ELS2 decrypt fail", dfe);
    526532            return false;
    527533        } catch (IOException ioe) {
    528             log.error("ELS2 decrypt fail", ioe);
     534            _log.warn("ELS2 decrypt fail", ioe);
    529535            return false;
    530536        }
    531         if (log.shouldDebug()) {
    532             log.debug("Decrypted inner LS2:\n" + _decryptedLS2);
    533             log.debug("Sig verify inner with key: " + _decryptedLS2.getDestination().getSigningPublicKey().getType() + ' ' + _decryptedLS2.getDestination().getSigningPublicKey().toBase64());
    534             log.debug("Sig verify inner: " + _decryptedLS2.getSignature().getType() + ' ' + _decryptedLS2.getSignature().toBase64());
     537        if (_log.shouldDebug()) {
     538            _log.debug("Decrypted inner LS2:\n" + _decryptedLS2);
     539            _log.debug("Sig verify inner with key: " + _decryptedLS2.getDestination().getSigningPublicKey().getType() + ' ' + _decryptedLS2.getDestination().getSigningPublicKey().toBase64());
     540            _log.debug("Sig verify inner: " + _decryptedLS2.getSignature().getType() + ' ' + _decryptedLS2.getSignature().toBase64());
    535541        }
    536542        boolean rv = _decryptedLS2.verifySignature();
    537543        if (!rv)
    538             log.error("ELS2 inner sig verify fail");
     544            _log.warn("ELS2 inner sig verify fail");
    539545        else
    540             log.debug("ELS2 inner sig verify success");
     546            _log.info("ELS2 inner sig verify success");
    541547        return rv;
    542548    }
Note: See TracChangeset for help on using the changeset viewer.