use of com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo in project attestation by TokenScript.
the class AttestationTest method testGetterSetter.
@Test
public void testGetterSetter() throws Exception {
Attestation att = new Attestation();
att.setVersion(19);
assertEquals(att.getVersion(), 19);
att.setSerialNumber(42);
assertEquals(att.getSerialNumber(), 42);
att.setIssuer("CN=ALX");
assertEquals(att.getIssuer(), "CN=ALX");
Date now = new Date();
att.setNotValidBefore(now);
assertEquals(att.getNotValidBefore().toString(), now.toString());
Date later = new Date(Clock.systemUTC().millis() + 1000);
att.setNotValidAfter(later);
assertEquals(att.getNotValidAfter().toString(), later.toString());
att.setSubject("CN=me");
assertEquals(att.getSubject(), "CN=me");
SubjectPublicKeyInfo newSpki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(subjectKeys.getPublic());
att.setSubjectPublicKeyInfo(newSpki);
assertEquals(att.getSubjectPublicKeyInfo(), newSpki);
att.setSmartcontracts(Arrays.asList(42L, 13L));
assertEquals(att.getSmartcontracts(), Arrays.asList(42L, 13L));
att.setExtensions(new DERSequence());
assertEquals(att.getExtensions(), new DERSequence());
Attestation att2 = new Attestation();
att2.setDataObject(new DERSequence());
assertEquals(att2.getDataObject(), new DERSequence());
}
use of com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo 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.x509.SubjectPublicKeyInfo in project attestation by TokenScript.
the class IdentifierAttestationTest method testInvalidPublicKey.
@Test
public void testInvalidPublicKey() throws Exception {
IdentifierAttestation initial = HelperTest.makeUnsignedStandardAtt(subjectKeys.getPublic(), BigInteger.ONE, mail);
Field field = initial.getClass().getSuperclass().getDeclaredField("subjectPublicKeyInfo");
field.setAccessible(true);
// Change the public key
SubjectPublicKeyInfo spki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(otherKeys.getPublic());
field.set(initial, spki);
// The key is only stored one place so it is allowed to change it as long as the attestation has not been signed
assertTrue(initial.checkValidity());
}
use of com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo in project attestation by TokenScript.
the class TestRedeemCheque method testNegativeUnmatchingKeys.
// Test that the key used to sign the RedeemCheque is the same as attested to
@Test
public void testNegativeUnmatchingKeys() throws Exception {
Attestation att = attestedCheque.getAtt().getUnsignedAttestation();
Field field = att.getClass().getSuperclass().getDeclaredField("subjectPublicKeyInfo");
field.setAccessible(true);
SubjectPublicKeyInfo spki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(issuerKeys.getPublic());
assertFalse(Arrays.equals(spki.getEncoded(), att.getSubjectPublicKeyInfo().getEncoded()));
// Change public key
field.set(att, spki);
// Validation should not fail for attestation
assertTrue(attestedCheque.getAtt().checkValidity());
// However it should for the whole object since the keys no longer match
assertFalse(attestedCheque.checkValidity());
// Verification should fail
assertFalse(attestedCheque.getAtt().verify());
assertFalse(attestedCheque.verify());
}
use of com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo in project attestation by TokenScript.
the class TicketTest method sunshine.
@Test
public void sunshine() throws Exception {
Ticket ticket = new Ticket(MAIL, CONFERENCE_ID, TICKET_ID, TICKET_CLASS, senderKeys, SECRET);
assertEquals(TICKET_ID, ticket.getTicketId());
assertEquals(TICKET_CLASS, ticket.getTicketClass());
assertEquals(CONFERENCE_ID, ticket.getDevconId());
SubjectPublicKeyInfo ticketSpki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(ticket.getPublicKey());
SubjectPublicKeyInfo senderSpki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(senderKeys.getPublic());
assertArrayEquals(senderSpki.getEncoded(), ticketSpki.getEncoded());
}
Aggregations