interledger-deprecated / java-crypto-conditions

WE'VE MOVED: This project has moved to Hyperledger Quilt
https://github.com/hyperledger/quilt/tree/master/crypto-conditions
Apache License 2.0
5 stars 12 forks source link

NullPointerException by CryptoConditionReader.readFulfillment() #69

Closed ManujSubhankar closed 7 years ago

ManujSubhankar commented 7 years ago

CryptoConditionReader.readFulfillment()

throws NullPointerException.

Below is the sample code where in I am encoding a Fulfillment and reading it back using CryptoConditionReader.readFulfillment(), which throws NullPointerException.

import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;

import org.interledger.cryptoconditions.Fulfillment;
import org.interledger.cryptoconditions.der.CryptoConditionReader;
import org.interledger.cryptoconditions.der.DEREncodingException;
import org.interledger.cryptoconditions.types.Ed25519Sha256Fulfillment;

import net.i2p.crypto.eddsa.EdDSAEngine;
import net.i2p.crypto.eddsa.EdDSAPublicKey;
import net.i2p.crypto.eddsa.KeyPairGenerator;

public class Bug {

    public static void main(String[] args) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException, DEREncodingException {
        KeyPairGenerator kpg= new KeyPairGenerator();
        KeyPair kp= kpg.generateKeyPair();

        MessageDigest md= MessageDigest.getInstance("SHA-512");
        Signature sign= new EdDSAEngine(md);
        sign.initSign(kp.getPrivate());
        sign.update("Hello_world".getBytes());

        Ed25519Sha256Fulfillment ffill= new Ed25519Sha256Fulfillment((EdDSAPublicKey) kp.getPublic(), sign.sign());

        Fulfillment fill2= CryptoConditionReader.readFulfillment(ffill.getEncoded());

    }
}
sappenin commented 7 years ago

Hi @ManujSubhankar, thanks for reporting this bug.

I have a pretty substantial PR (#68) that tries to fixup the project quite a bit. If you have time, I'd be curious to hear if this issue still exists in the features/immutable-crypto-conditions branch.

Otherwise, I'll try to take a look once I have some spare cycles. Thanks!

sappenin commented 7 years ago

Just a follow-up here: the features/immutable-crypto-conditions branch that I alluded to in my previous comment has now been merged into master, and is now part of version 0.3.0-SNAPSHOT.

sappenin commented 7 years ago

This is verified to be fixed as of version 0.3.0-SNAPSHOT of this library. This issue will be closed when #81 (which adds more formalized tests for this issue) is merged.