use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.
the class HelperTest method makeMinimalAtt.
public static Attestation makeMinimalAtt() {
Attestation att = new Attestation();
// Our initial version
att.setVersion(IdentifierAttestation.HIDDEN_IDENTIFIER_VERSION);
att.setSerialNumber(42);
// Blank subject info
att.setSubject("CN=");
att.setSigningAlgorithm(IdentifierAttestation.DEFAULT_SIGNING_ALGORITHM);
ASN1EncodableVector dataObject = new ASN1EncodableVector();
dataObject.add(new DEROctetString("hello world".getBytes()));
att.setDataObject(new DERSequence(dataObject));
assertTrue(att.checkValidity());
return att;
}
use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.
the class HelperTest method makeMaximalAtt.
public static IdentifierAttestation makeMaximalAtt(AsymmetricKeyParameter key) throws IOException {
IdentifierAttestation att = new IdentifierAttestation("205521676", "https://www.deviantart.com/some_user", key);
att.setSerialNumber(42);
att.setSigningAlgorithm(IdentifierAttestation.DEFAULT_SIGNING_ALGORITHM);
att.setIssuer("CN=ALX");
att.setSmartcontracts(Arrays.asList(42L, 1337L));
ASN1EncodableVector dataObject = new ASN1EncodableVector();
dataObject.add(new DEROctetString("hello world".getBytes()));
dataObject.add(new ASN1Integer(42));
att.setDataObject(new DERSequence(dataObject));
assertTrue(att.checkValidity());
return att;
}
use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.
the class HelperTest method makeUnsignedx509Att.
/* the unsigned x509 attestation will have a subject of "CN=0x2042424242424564648" */
public static Attestation makeUnsignedx509Att(AsymmetricKeyParameter key) throws IOException {
Attestation att = new Attestation();
// =v3 since counting starts from 0
att.setVersion(2);
att.setSerialNumber(42);
// ECDSA with SHA256 which is needed for a proper x509
att.setSigningAlgorithm(SignedIdentifierAttestation.ECDSA_WITH_SHA256);
att.setIssuer("CN=ALX");
Date now = new Date();
att.setNotValidBefore(now);
att.setNotValidAfter(new Date(System.currentTimeMillis() + VALIDITY));
att.setSubject("CN=0x2042424242424564648");
SubjectPublicKeyInfo spki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(key);
att.setSubjectPublicKeyInfo(spki);
ASN1EncodableVector extensions = new ASN1EncodableVector();
extensions.add(Attestation.OID_OCTETSTRING);
extensions.add(ASN1Boolean.TRUE);
extensions.add(new DEROctetString("hello world".getBytes()));
// Double Sequence is needed to be compatible with X509V3
att.setExtensions(new DERSequence(new DERSequence(extensions)));
assertTrue(att.isValidX509());
return att;
}
use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.
the class CoSignedIdentifierAttestation method constructSignedAttestation.
static byte[] constructSignedAttestation(SignedIdentifierAttestation unsignedAtt, byte[] signature) {
try {
byte[] rawAtt = unsignedAtt.getDerEncoding();
ASN1EncodableVector res = new ASN1EncodableVector();
res.add(ASN1Primitive.fromByteArray(rawAtt));
res.add(unsignedAtt.getUnsignedAttestation().getSigningAlgorithm());
res.add(new DERBitString(signature));
return new DERSequence(res).getEncoded();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.
the class DERUtility method encodeSecret.
public static byte[] encodeSecret(BigInteger secret) {
try {
ASN1EncodableVector asn1 = new ASN1EncodableVector();
asn1.add(new DEROctetString(secret.toByteArray()));
return new DERSequence(asn1).getEncoded();
} catch (IOException e) {
throw ExceptionUtil.makeRuntimeException(logger, "Could not encode asn1", e);
}
}
Aggregations