[authsaml2] Java binding testing file and cleaning.

This commit is contained in:
Mikaël Ates 2011-02-01 10:27:11 +01:00
parent 286aaced3d
commit b7fcd2db0b
3 changed files with 157 additions and 106 deletions

View File

@ -1,78 +1,60 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2011 Mikaël Ates <mates@entrouvert.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* $ javac -g Myclass.java
$ LD_LIBRARY_PATH=.libs/ gij -classpath cryptic.jar:. Myclass*/
import com.entrouvert.cryptic.*;
class Myclass{
public static void main(String[] arg){
//System.out.println(System.getProperty("java.library.path"));
System.out.println("\n\t############## JAVA TESTS ##############\n");
test_1();
test_2();
}
private static void test_1(){
System.out.println("\n\t############## TEST 1 ##############\n");
System.out.println("\n\t-------------- JAVA BINDING TEST --------------\n");
String[] quantities = { "1234567890c", "1234567890b", "1234567890a", };
System.out.println("Group generation...");
PrimeOrderGroup g = new PrimeOrderGroup(256);
g.moreBases(5);
String[] bases = (String[]) g.getbases();
int i;
for(i=0;i<5;i++){
System.out.println("Base: " + bases[i]);
}
System.out.println("Group generation successful.");
System.out.println("Prover: DLREP to prove generation...");
String dlrep = CrypticJNI.get_dlrep(3,quantities,bases,g.getp());
System.out.println("DLREP: " + dlrep);
System.out.println("Prover: Proof round1");
ZkpkSchnorr s = new ZkpkSchnorr(g.getbases(),3,g.getp());
s.round1();
System.out.println("Prover: Send DLREP: " + dlrep);
System.out.println("Prover: Send commitments.");
String challenge = CrypticJNI.ret_random(80);
System.out.println("Verifier: Send challenge: " + challenge);
System.out.println("Prover: Proof round2");
s.round2(g.getorder(),challenge,quantities);
System.out.println("Prover: Send responses.");
ZkpkSchnorr s2 = new ZkpkSchnorr(g.getbases(),3,g.getp());
int rc = s2.verifyInteractiveProof(dlrep,s.getcommitment(),challenge,s.getresponses());
System.out.println("Verifier: Proof verification: " + rc);
}
private static void test_2(){
System.out.println("\n\t############## TEST 2 ##############\n");
int rc;
System.out.println("\nServer: clsig parameters generation...");
Clsig c = new Clsig(1024,256,600,0,0,0,10);
c.generateParameters();
rc = c.generateParameters();
System.out.println("\trc: " + rc);
System.out.println("Server: clsig parameters generated.");
System.out.println("\nProver: clsig parameters init on the prover side.");
Clsig c2;
c2 = Clsig.newLoadPublicParameters(c.getz(),c.gets(),10,c.getbases(),c.getlgQuantities(),c.getlgExponent(),c.getmodulus(),c.getlgSecParam(),c.getlgZkSecParam(),c.getlgClsigSecParam());
System.out.println("\nProver: build a commitment to include in the certificate.");
System.out.println("Prover: build a commitment to include in the certificate.");
String qa = CrypticJNI.char_to_bn("Kirk");
String qb = CrypticJNI.char_to_bn("Captain");
String[] tab_q = {qa, qb};
System.out.println("Attributes encoding...");
System.out.println("Kirk - " + tab_q[0]);
System.out.println("Captain - " + tab_q[1]);
System.out.println("Prover: Attributes encoding...");
System.out.println("\tKirk - " + tab_q[0]);
System.out.println("\tCaptain - " + tab_q[1]);
System.out.println("Init commitment store with bases: 1, 5");
System.out.println("Prover: Init commitment store with bases: 1, 5");
CommitDataStore pdc = new CommitDataStore();
String[] tab_b = {(String)c2.getbases()[1],(String)c2.getbases()[5]};
System.out.println("Compute commitment");
c2.computeCommittedValue(pdc,tab_b,tab_q,2);
System.out.println("Prover: Compute commitment");
rc = c2.computeCommittedValue(pdc,tab_b,tab_q,2);
System.out.println("\trc: " + rc);
System.out.println("\nServer: Attributes in certificate.");
String q1 = CrypticJNI.char_to_bn("Mik");
@ -80,56 +62,111 @@ class Myclass{
String q3 = CrypticJNI.char_to_bn("Clermont-Fd");
String q4 = CrypticJNI.int_to_bn(1982280100);
String[] tab_q2 = {q1, q2, q3, q4};
System.out.println("Mik - " + tab_q2[0]);
System.out.println("Ates - " + tab_q2[1]);
System.out.println("Clermont-Fd - " + tab_q2[2]);
System.out.println("1982280100 - " + tab_q2[3]);
System.out.println("\tMik - " + tab_q2[0]);
System.out.println("\tAtes - " + tab_q2[1]);
System.out.println("\tClermont-Fd - " + tab_q2[2]);
System.out.println("\t1982280100 - " + tab_q2[3]);
int[] index = {0,2,3,4};
System.out.println("\nServer: compute dlrep");
System.out.println("Bases index: " + index[0] + index[1] + index[2] + index[3]);
c.computeDlrepByIndex(tab_q2, index, 4);
System.out.println("Server: compute dlrep");
rc = c.computeDlrepByIndex(tab_q2, index, 4);
System.out.println("\trc: " + rc);
System.out.println("\nServer: sign with the commitment");
c.signWithCommittedValue(pdc.getdlrep());
System.out.println("\nServer: verify signature");
c.verifySignatureNotRandomized();
System.out.println("Server: sign with the commitment");
rc = c.signWithCommittedValue(pdc.getdlrep());
System.out.println("\trc: " + rc);
System.out.println("Server: verify signature");
rc = c.verifySignatureNotRandomized();
System.out.println("Server: signature verification: " + rc);
System.out.println("\tSignature: " + c.geta());
System.out.println("\tExponent: " + c.gete());
System.out.println("\tBlind factor: " + c.getv());
/*c2.loadCertificateWithIndexWithCommittedValue(c.a,c.e,c.v,c.quantities,4,(qa,qb),2,pdc.dlrep,pdc.vprime,(0,2,3,4))
c2.randomizeSignature()
c2.verifySignatureRandomized()
dlrep = c2.buildDlrepBeforeProving((1,),(2,),1)
fixed_add_size = c2.lgZkSecParam + c2.lgQuantities
r0 = cryptic.retRandom(c2.intervalExponent + fixed_add_size)
r1 = cryptic.retRandom(c2.lgBlind + fixed_add_size)
r2 = cryptic.retRandom(c2.lgQuantities + fixed_add_size)
r3 = cryptic.retRandom(c2.lgQuantities + fixed_add_size)
r4 = cryptic.retRandom(c2.lgQuantities + fixed_add_size)
r5 = cryptic.retRandom(c2.lgQuantities + fixed_add_size)
r6 = cryptic.retRandom(c2.lgQuantities + fixed_add_size)
s = cryptic.ZkpkSchnorr((c2.aRand,c2.s,c2.bases[0],c2.bases[3],c2.bases[4],c2.bases[1],c2.bases[5]),7,c2.modulus)
s.round1RandomsChosen((r0,r1,r2,r3,r4,r5,r6))
pr = cryptic.ProofrangeQrg(c2.s,c2.z,c2.modulus)
b = cryptic.intToBn(1992040400)
pr.round1(cryptic.PROOF_RANGE_LT,q4,b,s.randoms[4],c2.lgSecParam,c2.lgZkSecParam,256)
h = cryptic.HashForNiProofs(256)
h.addProof(s,dlrep)
h.addProofrangeProver(pr)
h.computeHash()
s.round2WithoutOrder(h.hValue,(c2.eCorrected,c2.vRand,q1,q3,q4,qa,qb))
pr.round2(h.hValue)
c3 = cryptic.Clsig.newLoadPublicParameters(c.z,c.s,10,c.bases,c.lgQuantities,c.lgExponent,c.modulus,c.lgSecParam,c.lgZkSecParam,c.lgClsigSecParam)
s2 = cryptic.ZkpkSchnorr((c2.aRand,c3.s,c3.bases[0],c3.bases[3],c3.bases[4],c2.bases[1],c2.bases[5]),7,c3.modulus)
s2.verifyNoninteractiveProof(dlrep,h.hValue,s.responses)
pr2 = cryptic.ProofrangeQrg(c3.s,c3.z,c3.modulus)
pr2.verifyNoninteractiveProof(cryptic.PROOF_RANGE_LT,b,pr.dlreps,h.hValue,pr.responses)
h2 = cryptic.HashForNiProofs(256)
h2.addProof(s2,dlrep)
h2.addProofrangeVerifier(pr2,pr.dlreps)
h2.computeHash()
cryptic.cmpBn(h.hValue,h2.hValue)*/
System.out.println("\nProver: load certificate");
rc = c2.loadCertificateWithIndexWithCommittedValue(c.geta(),c.gete(),c.getv(),c.getquantities(),4,tab_q,2,pdc.getdlrep(),pdc.getvprime(),index);
System.out.println("Prover: rc " + rc);
System.out.println("Prover: randomize signature");
rc = c2.randomizeSignature();
System.out.println("\trc: " + rc);
System.out.println("Prover: verify randomized signature");
rc = c2.verifySignatureRandomized();
System.out.println("Prover: signature verification: " + rc);
System.out.println("Prover: get DLREP to prove");
System.out.println("Prover: the name will be revealed");
int[] i1 = {1};
int[] i2 = {2};
String dlrep = c2.buildDlrepBeforeProving(i1, i2, 1);
System.out.println("Prover: compute randoms");
int fixed_add_size = c2.getlgZkSecParam() + c2.getlgQuantities();
String r0 = CrypticJNI.ret_random(c2.getintervalExponent() + fixed_add_size);
String r1 = CrypticJNI.ret_random(c2.getlgBlind() + fixed_add_size);
String r2 = CrypticJNI.ret_random(c2.getlgQuantities() + fixed_add_size);
String r3 = CrypticJNI.ret_random(c2.getlgQuantities() + fixed_add_size);
String r4 = CrypticJNI.ret_random(c2.getlgQuantities() + fixed_add_size);
String r5 = CrypticJNI.ret_random(c2.getlgQuantities() + fixed_add_size);
String r6 = CrypticJNI.ret_random(c2.getlgQuantities() + fixed_add_size);
System.out.println("Prover: build proof");
String[] tab_b2 = {c2.getaRand(),c2.gets(),c2.getbases()[0],c2.getbases()[3],c2.getbases()[4],c2.getbases()[1],c2.getbases()[5]};
ZkpkSchnorr s = new ZkpkSchnorr(tab_b2,7,c2.getmodulus());
String[] tab_r = {r0,r1,r2,r3,r4,r5,r6};
System.out.println("Prover: proof round 1");
rc = s.round1RandomsChosen(tab_r);
System.out.println("\trc: " + rc);
System.out.println("Prover: build proof range");
ProofrangeQrg pr = new ProofrangeQrg(c2.gets(),c2.getz(),c2.getmodulus());
System.out.println("Prover: proof range round 1");
String b = CrypticJNI.int_to_bn(1992040400);
rc = pr.round1(CrypticJNI.CRYPTIC_PROOF_RANGE_LT_get(),q4,b,s.getrandoms()[4],c2.getlgSecParam(),c2.getlgZkSecParam(),256);
System.out.println("\trc: " + rc);
System.out.println("Prover: build hash for non interactive proof");
HashForNiProofs h = new HashForNiProofs(256);
rc = h.addProof(s,dlrep);
System.out.println("\trc: " + rc);
rc = h.addProofrangeProver(pr);
System.out.println("\trc: " + rc);
rc = h.computeHash();
System.out.println("\trc: " + rc);
String[] tab_q3 = {c2.geteCorrected(),c2.getvRand(),q1,q3,q4,qa,qb};
System.out.println("Prover: proof round 2");
rc = s.round2WithoutOrder(h.gethValue(),tab_q3);
System.out.println("\trc: " + rc);
System.out.println("Prover: proof range round 2");
rc = pr.round2(h.gethValue());
System.out.println("\trc: " + rc);
System.out.println("\nVerifier: clsig parameters init on the verifier side.");
Clsig c3;
c3 = Clsig.newLoadPublicParameters(c.getz(),c.gets(),10,c.getbases(),c.getlgQuantities(),c.getlgExponent(),c.getmodulus(),c.getlgSecParam(),c.getlgZkSecParam(),c.getlgClsigSecParam());
String[] tab_b3 = {c2.getaRand(),c3.gets(),c3.getbases()[0],c3.getbases()[3],c3.getbases()[4],c2.getbases()[1],c2.getbases()[5]};
System.out.println("Verifier: build proof");
ZkpkSchnorr s2 = new ZkpkSchnorr(tab_b3,7,c3.getmodulus());
System.out.println("Verifier: verify proof");
rc = s2.verifyNoninteractiveProof(dlrep,h.gethValue(),s.getresponses());
System.out.println("\trc: " + rc);
System.out.println("Verifier: build proof range");
ProofrangeQrg pr2 = new ProofrangeQrg(c3.gets(),c3.getz(),c3.getmodulus());
System.out.println("Verifier: verify proof range");
rc = pr2.verifyNoninteractiveProof(CrypticJNI.CRYPTIC_PROOF_RANGE_LT_get(),b,pr.getdlreps(),h.gethValue(),pr.getresponses());
System.out.println("\trc: " + rc);
System.out.println("Verifier: add proof and proof range to the hash for non interactive proof");
HashForNiProofs h2 = new HashForNiProofs(256);
rc = h2.addProof(s2,dlrep);
System.out.println("\trc: " + rc);
rc = h2.addProofrangeVerifier(pr2,pr.getdlreps());
System.out.println("\trc: " + rc);
rc = h2.computeHash();
System.out.println("\trc: " + rc);
rc = CrypticJNI.cmp_bn(h.gethValue(),h2.gethValue());
System.out.println("Verifier: Proof verification: " + rc);
}
}

View File

@ -638,7 +638,6 @@ protected static native void destroy(long cptr);
klass = c.name
prefix = self.JNI_member_function_prefix(c,m)
return_type = self.jni_return_type(m)
print 'return_type ' + return_type
signature = wrapper_decl("%s_get" % prefix, return_type)
field = 'gobj->%s' % name
d = locals()
@ -737,10 +736,7 @@ protected static native void destroy(long cptr);
def generate_wrapper_getter_setter(self, c, fd):
klassname = c.name
print klassname
for m in c.members:
print m
print m[0]
# getter
self.generate_wrapper_getter(c, m, fd)
self.generate_wrapper_setter(c, m, fd)
@ -748,7 +744,6 @@ protected static native void destroy(long cptr);
prefix = self.JNI_member_function_prefix(c,m)
jtype = self.jni_return_type(mtype)
# add/remove
print jtype
if is_glist(mtype):
self.generate_wrapper_adder(c, m, fd)
self.generate_wrapper_remover(c, m, fd)

View File

@ -1,3 +1,21 @@
/* Cryptic -- Cryptographic tools and protocols
* Copyright (C) 2010 Mikaël Ates <mates@entrouvert.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <glib.h>
#include <glib-object.h>
#include <cryptic/cryptic.h>
@ -90,7 +108,7 @@ G_GNUC_UNUSED static int get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray
#define add_to_list_of_bignum(env,list,obj) add_to_list(env,list,obj,(OutConverter)jstring_to_bignum)
#define get_hash_of_bignum(env,hash,jarr) get_hash(env,"java/lang/String",hash,(Converter)bignum_to_jstring, jarr)
static int int_to_jint(JNIEnv *env, int i, jint *ji);
//static int int_to_jint(JNIEnv *env, int i, jint *ji);
//static int jint_to_int(JNIEnv *env, jint ji, int *i);
//G_GNUC_UNUSED static int set_list_of_int(JNIEnv *env, int **list, jobjectArray jarr);
G_GNUC_UNUSED static int* set_list_of_int(JNIEnv *env, jobjectArray jarr);
@ -210,11 +228,11 @@ set_list_of_bn(JNIEnv *env, jobjectArray jarr) {
return list;
}
static int
/*static int
int_to_jint(JNIEnv *env, int i, jint *ji)
{
return 1;
}
return 1;
}*/
static int
get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
@ -232,7 +250,8 @@ get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
cryptic_return_val_if_fail(create_object_array(env, "java/lang/Integer", size, jarr), 0);
for (i=0; i<size; i++) {
jint item;
int_to_jint(env,list[i],&item);
//int_to_jint(env,list[i],&item);
item = (jint) list[i];
cryptic_return_val_if_fail(set_array_element(env, *jarr, i, &item), 0);
}
return 1;