Skip to content

Commit

Permalink
fix: fixed integration tests with attested object (#290)
Browse files Browse the repository at this point in the history
Co-authored-by: Tore Kasper Frederiksen <[email protected]>
  • Loading branch information
jot2re and Tore Kasper Frederiksen authored Aug 25, 2022
1 parent 84c2042 commit a8ce290
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
43 changes: 21 additions & 22 deletions src/main/javascript/crypto/src/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {Issuer} from "./libs/Issuer";
import { AttestedObject } from './libs/AttestedObject';
import { AttestableObject } from './libs/AttestableObject';
import { UseToken } from './asn1/shemas/UseToken';
import { Console } from 'console';
const url = require('url');

let EC = require("elliptic");
Expand Down Expand Up @@ -627,18 +628,16 @@ describe("executeCombinedEipFlow", () => {
})

describe("read public key", () => {

const keyFile1 = '-----BEGIN PUBLIC KEY-----\n' +
'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEQKYTwFMIzSq1QVxoRKoOZXLQ9mUhce8M\n' +
'dIzvJx3unbpR3m3TiuWKZKTP4/XCPnS56d1tAhjM43hHjHbZ0k3RKQ==\n' +
'-----END PUBLIC KEY-----';
let addr1 = "0x4F3CEF0C905EB4EDF9C4FFC71C4C4B06417BAC3E";
// Standard PKCS stored key
const pubKeyPem1 = readFileSync(PREFIX_PATH + 'ticket-issuer-key.txt', 'utf8');
let addr1 = "0x94085A072E5481D64D6E2165268801B87A362B64";
// Pure base64 dump
const keyFile2 = 'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEOt9mWLpQVOxiOvswFK4GGI0oOZ2GqS2Q6ec0AWIeuVoCuTD+atppPvjMgNLg9qQzJxsDW3zLxnOPFWO/Decnag==';
let addr2 = "0x17C0B3B51A75F1A001F255A7CAD4FA45529CAC20";


test('read 2 keys', async () => {
let key1 = Authenticator.decodePublicKey(keyFile1);
let key1 = Authenticator.decodePublicKey(pubKeyPem1);
expect(key1.getAddress().toLocaleLowerCase()).toBe(addr1.toLocaleLowerCase());

let key2 = Authenticator.decodePublicKey(keyFile2);
Expand All @@ -647,30 +646,30 @@ describe("read public key", () => {
})

describe("read attested object", () => {

const base64senderPublicKeys = {
"AttestationDAO" : 'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEOt9mWLpQVOxiOvswFK4GGI0oOZ2GqS2Q6ec0AWIeuVoCuTD+atppPvjMgNLg9qQzJxsDW3zLxnOPFWO/Decnag=='
const ticketPubPEM = readFileSync(PREFIX_PATH + 'ticket-issuer-key.txt', 'utf8');
let ticketPubKey = KeyPair.publicFromBase64orPEM(ticketPubPEM);

const issuerPublicKeys = {
"hejJ" : ticketPubKey
}
const base64attestorPubKey = "MIIBMzCB7AYHKoZIzj0CATCB4AIBATAsBgcqhkjOPQEBAiEA/////////////////////////////////////v///C8wRAQgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHBEEEeb5mfvncu6xVoGKVzocLBwKb/NstzijZWfKBWxb4F5hIOtp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuAIhAP////////////////////66rtzmr0igO7/SXozQNkFBAgEBA0IABL+y43T1OJFScEep69/yTqpqnV/jzONz9Sp4TEHyAJ7IPN9+GHweCX1hT4OFxt152sBN3jJc1s0Ymzd8pNGZNoQ="

// one month attestation up to 23.07.2022
let attestation = "3082036130819f30590c0e4174746573746174696f6e44414f02011102010004410429f318186b80c87cbfcacbc6b3b05bf4b030ae1e3208aa29cca0085ee260b7a91f6dad8a905618e2254accaf53c804a3d53fc52681ad97f57ced42b8ee4b5a43034200e7f0bbce8bde24dda89aec03e7dcc667a6ba36d8faa43b73f494c4ed660ac9827def644fafa5c565378275ad2d3d8ab4b6b97340368268c02574c05d4ea91bc21c30820252308201ffa00302011202084955fbc320282b73300906072a8648ce3d040230163114301206035504030c0b416c70686157616c6c6574302e180f32303232303632333030353234375a020462b3b95f180f32303232303732333030353234375a020462db465f300b3109300706035504030c00308201333081ec06072a8648ce3d02013081e0020101302c06072a8648ce3d0101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f3044042000000000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000000704410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020101034200042f196ec33ad04c6398fe8eef1a84d8855397641bb4cbbbcf576e3baa34c516a51b2eac6b201dd24950b6513cbd85f6bd1a11b7bad511343d9dadeccb30f72642a35730553053060b2b060104018b3a737901280101ff0441042d733bb6f9bff3490a611cd6eb4bbacbebd92e250349b637e7704fa42a2c12910963fbb308ce4ce42f7badcab147c641a100b372c9a4993f52c5db4f778534f5300906072a8648ce3d0402034200b31c662704c2300433bfff711965f23efdf9df06719c7f4f71f011cf82792ca8671a86375c033f00bbbda7530e32797798db7eadf6e1890e702409d6c4d006551c306704200ddc39622f14204d4079231353da5d578d7ab11d7afcd17891f274a9531ddc9d0441041f7312aff9358a02fb5b1ce508f6da19280e9b1a2742fe98b2c4efe72264a24c0008570f8ad1235ebcaf31fb68e1cadadab27a3c263fe5c1e9bc98886fd10dd10400";
const attestorPubPEM = readFileSync(PREFIX_PATH + 'att-issuer-key.txt', 'utf8');
let attestorPubKey = KeyPair.publicFromBase64orPEM(attestorPubPEM);

test('validate attestation', async () => {
let attestation = readFileSync(PREFIX_PATH + 'attested-ticket.txt', 'utf8');

let attestor = KeyPair.publicFromBase64orPEM(base64attestorPubKey);
let issuers = {"AttestationDAO" : KeyPair.publicFromBase64orPEM(base64senderPublicKeys.AttestationDAO)}
test('validate attestation', async () => {

let subj = "0x2F21dC12dd43bd15b86643332041ab97010357D7";
let subj = "0x7A181CB7250776E16783F9D3C9166DE0F95AB283";

let attest = AttestedObject.fromBytes(
hexStringToUint8(attestation),
base64ToUint8array(attestation),
UseToken,
attestor,
attestorPubKey,
Ticket,
issuers
issuerPublicKeys
);

console.log(attest);
expect(attest.checkValidity(subj)).toBe(true);

})
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/org/devcon/ticket/UseTicketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.tokenscript.attestation.core.SignatureUtility;
import org.tokenscript.attestation.demo.SmartContract;

import java.io.File;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -53,8 +54,8 @@ public static void setupKeys() throws Exception {

crypto = new AttestationCrypto(rand);
subjectKeys = SignatureUtility.constructECKeysWithSmallestY(rand);
attestorKeys = SignatureUtility.constructECKeys(rand);
ticketIssuerKeys = SignatureUtility.constructECKeys(rand);
attestorKeys = SignatureUtility.constructECKeysWithSmallestY(rand);
ticketIssuerKeys = SignatureUtility.constructECKeysWithSmallestY(rand);
fakeSupplimentalKey = SignatureUtility.constructECKeys(rand);

System.out.println("subject: " + SignatureUtility.addressFromKey(subjectKeys.getPublic()));
Expand All @@ -76,7 +77,8 @@ public void makeAttestedTicket() {
@Test
void writeTestMaterial() throws Exception {
FileImportExport.storeKey(ticketIssuerKeys.getPublic(), "ticket-issuer-key");
Ticket ticket = new Ticket(MAIL, CONFERENCE_ID, TICKET_ID, TICKET_CLASS, ticketIssuerKeys, TICKET_SECRET);
// TODO it is a known issue that using non-ascii chars cause a failure in the JS decoding, hence we use a conference ID with ascii chars
Ticket ticket = new Ticket(MAIL, "hejJ", TICKET_ID, TICKET_CLASS, ticketIssuerKeys, TICKET_SECRET);
FileImportExport.storeMaterial(ticket, "ticket");
IdentifierAttestation att = HelperTest.makeUnsignedStandardAtt(subjectKeys.getPublic(), ATTESTATION_SECRET, MAIL);
FileImportExport.storeKey(attestorKeys.getPublic(), "att-issuer-key");
Expand Down

0 comments on commit a8ce290

Please sign in to comment.