Commit d6ba2f3a authored by mgiannopoulos's avatar mgiannopoulos
Browse files

Return serialized data

parent 5f53cb75
......@@ -68,11 +68,6 @@
<scope>system</scope>
<systemPath>${project.basedir}/lib/jpbc/jpbc-pbc-2.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
</dependency>
</dependencies>
<build>
......
package eu.ubitech.clapi.controllers;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.gson.Gson;
import edu.jhu.isi.CLSign.CLSign;
import eu.ubitech.clapi.dto.*;
//import org.springframework.util.SerializationUtils;
import eu.ubitech.clapi.util.SerializationUtils;
import it.unisa.dia.gas.plaf.jpbc.field.base.AbstractElementPowPreProcessing;
import it.unisa.dia.gas.plaf.jpbc.field.curve.CurveElement;
import it.unisa.dia.gas.plaf.jpbc.field.curve.ImmutableCurveElement;
import it.unisa.dia.gas.plaf.jpbc.field.z.ImmutableZrElement;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrField;
import eu.ubitech.clapi.dto.KeyPairDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -21,7 +9,6 @@ import org.springframework.web.bind.annotation.RestController;
import edu.jhu.isi.CLSign.keygen.KeyPair;
import java.io.IOException;
import java.io.Serializable;
import java.util.logging.Logger;
@RestController
......@@ -31,35 +18,10 @@ public class CLSignController {
private static final Logger logger = Logger.getLogger(CLSignController.class.getName());
@PostMapping(value = "/keyGen")
public BinaryValueDto keyGen() throws IOException {
KeyPair kp = CLSign.keyGen(1);
public KeyPairDto keyGen() throws IOException {
KeyPair kp = CLSign.keyGen(5);
logger.info("Generated key: " + kp);
// BinaryValueDto dto = new BinaryValueDto(SerializationUtils.convertToBytes(kp));
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
mapper.configure(SerializationFeature.FAIL_ON_SELF_REFERENCES, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.addMixIn(ZrElement.class, ZrElementMixin.class);
// mapper.addMixIn(ImmutableZrElement.class, ImmutableZrElementMixin.class);
mapper.addMixIn(AbstractElementPowPreProcessing.class, AbstractElementPowPreProcessingMixin.class);
// mapper.addMixIn(ZrField.class, ZrFieldMixin.class);
mapper.addMixIn(CurveElement.class, CurveElementMixin.class);
// mapper.addMixIn(ImmutableCurveElement.class, ImmutableCurveElementMixin.class);
//String json = mapper.writeValueAsString(kp);
byte[] content = mapper.writeValueAsBytes(kp);
// String gson = new Gson().toJson(kp);
//return json;
return new BinaryValueDto(null);
return new KeyPairDto(kp);
}
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class AbstractElementPowPreProcessingMixin {
@JsonIgnore
String field;
}
package eu.ubitech.clapi.dto;
import java.io.Serializable;
public class BinaryValueDto implements Serializable {
private byte[] content;
BinaryValueDto() {
}
public BinaryValueDto(byte[] content) {
this.content = content;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class CurveElementMixin {
@JsonIgnore
String field;
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class ImmutableCurveElementMixin {
@JsonIgnore
String immutable;
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class ImmutableZrElementMixin {
//ImmutableZrElement
@JsonIgnore
String immutable;
//it.unisa.dia.gas.plaf.jpbc.field.base.AbstractElementPowPreProcessing
@JsonIgnore
it.unisa.dia.gas.plaf.jpbc.field.base.AbstractElementPowPreProcessing field;
}
package eu.ubitech.clapi.dto;
import edu.jhu.isi.CLSign.keygen.KeyPair;
import edu.jhu.isi.CLSign.serialize.Serialize;
import it.unisa.dia.gas.jpbc.Pairing;
import java.io.IOException;
import java.io.Serializable;
public class KeyPairDto implements Serializable {
private byte[] pk;
private byte[] sk;
public KeyPairDto(final KeyPair kp) throws IOException {
pk = Serialize.serializePublicKey(kp.getPk());
Pairing pairing = kp.getPk().getPairing();
sk = Serialize.serializeSecretKey(kp.getSk(), pairing);
}
public byte[] getPk() {
return pk;
}
public void setPk(byte[] pk) {
this.pk = pk;
}
public byte[] getSk() {
return sk;
}
public void setSk(byte[] sk) {
this.sk = sk;
}
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public class RandomMixin {
@JsonIgnore
String random;
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class SecureRandomMixin {
@JsonIgnore
String seed;
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class TypeAPairingMixin {
@JsonIgnore
String random;
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class ZrElementMixin {
//ZrField
@JsonIgnore
String field;
//it.unisa.dia.gas.plaf.jpbc.field.z.ImmutableZrElement
@JsonIgnore
it.unisa.dia.gas.plaf.jpbc.field.z.ImmutableZrElement elementPowPreProcessing;
}
package eu.ubitech.clapi.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
public abstract class ZrFieldMixin {
@JsonIgnore
it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement immutable;
}
package eu.ubitech.clapi.util;
import java.io.*;
public class SerializationUtils {
// public static <T> byte[] serializeClObject(T cl) throws IOException {
// cl.getClass().toString();
//
//
//
// return convertToBytes(object);
// }
public static byte[] convertToBytes(Object object) throws IOException {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(object);
return bos.toByteArray();
}
}
public Object convertFromBytes(byte[] bytes) throws IOException, ClassNotFoundException {
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(bis)) {
return in.readObject();
}
}
}
package eu.ubitech.clapi;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import edu.jhu.isi.CLSign.CLSign;
import edu.jhu.isi.CLSign.keygen.KeyPair;
import eu.ubitech.clapi.dto.*;
import it.unisa.dia.gas.plaf.jpbc.field.base.AbstractElementPowPreProcessing;
import it.unisa.dia.gas.plaf.jpbc.field.curve.CurveElement;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
import it.unisa.dia.gas.plaf.jpbc.pairing.a.TypeAPairing;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.security.PublicKey;
import java.security.SecureRandom;
@SpringBootTest
class ClApiApplicationTests {
@Test
void contextLoads() throws JsonProcessingException {
KeyPair kp = CLSign.keyGen(5);
// ObjectMapper mapper = new ObjectMapper();
// mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
// .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
// .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
// .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
// .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
//
// mapper.configure(SerializationFeature.FAIL_ON_SELF_REFERENCES, false);
// mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// mapper.addMixIn(ZrElement.class, ZrElementMixin.class);
//// mapper.addMixIn(ImmutableZrElement.class, ImmutableZrElementMixin.class);
// mapper.addMixIn(AbstractElementPowPreProcessing.class, AbstractElementPowPreProcessingMixin.class);
//// mapper.addMixIn(ZrField.class, ZrFieldMixin.class);
// mapper.addMixIn(CurveElement.class, CurveElementMixin.class);
//// mapper.addMixIn(ImmutableCurveElement.class, ImmutableCurveElementMixin.class);
// //mapper.addMixIn(Object.class, SecureRandomMixin.class);
// mapper.addMixIn(Object.class, TypeAPairingMixin.class);
// //String json = mapper.writeValueAsString(kp);
// byte[] content = mapper.writeValueAsBytes(kp);
int i = 0;
void contextLoads() {
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment