public void Verify() { Channel channel; Shared shared; PicoBuffer returnedExtraData; shared = new Shared(); shared.load_or_generate_keys("testkey.pub", "testkey.priv"); channel = new Channel(); Thread prover_td = new Thread(() => prover_main(channel.get_name())); prover_td.Start(); returnedExtraData = new PicoBuffer(0); Sigma.verify(shared, channel, null, "123456", returnedExtraData, null); returnedExtraData.append(new byte[] { 0x00 }); Assert.AreEqual(returnedExtraData.to_string(), "Test data"); prover_td.Join(); shared.delete(); channel.delete(); returnedExtraData.delete(); }
void receive_status_message(Channel channel, EncKeys keys, string expected_extra_data) { Json json = new Json(); PicoBuffer buf = new PicoBuffer(0); PicoBuffer iv = new PicoBuffer(0); PicoBuffer cleartext = new PicoBuffer(0); channel.read(buf); json.deserialize(buf); Assert.AreEqual(json.get_decimal("sessionId"), 0); Base64.decode(json.get_string("iv"), iv); buf.clear(); Base64.decode(json.get_string("encryptedData"), buf); CryptoSupport.decrypt(keys.vEncKey, iv, buf, cleartext); PicoBuffer receivedExtraData = new PicoBuffer(0); byte[] status = new byte[2]; cleartext.copy_to_array(status, 2); Assert.AreEqual(status[0], 0x00); cleartext.copy_lengthprepend(1, receivedExtraData); receivedExtraData.append(new byte[] { 0x00 }); Assert.AreEqual(receivedExtraData.to_string(), expected_extra_data); json.delete(); buf.delete(); cleartext.delete(); iv.delete(); receivedExtraData.delete(); }
public void append_string() { PicoBuffer b; b = new PicoBuffer(3); b.append("1234567890"); Assert.AreEqual(b.get_pos(), 10); Assert.AreEqual(b.get_size() % 3, 0); Assert.AreEqual(b.to_string(), "1234567890"); b.delete(); }
public void truncate() { PicoBuffer b; b = new PicoBuffer(3); b.append("1234567890"); b.truncate(6); Assert.AreEqual(b.get_pos(), 4); Assert.AreEqual(b.get_size(), 6); Assert.AreEqual(b.to_string(), "1234"); b.delete(); }
public void GetUrl() { Channel channel = Channel.connect("c348ff95f0bd49aabe55ea35a637c680"); PicoBuffer buf = new PicoBuffer(0); channel.get_url(buf); buf.append(new byte[] { 0x00 }); Assert.AreEqual(buf.to_string(), "http://rendezvous.mypico.org/channel/c348ff95f0bd49aabe55ea35a637c680"); channel.delete(); buf.delete(); }
public void append_buffer() { PicoBuffer b; PicoBuffer b2; b = new PicoBuffer(3); b2 = new PicoBuffer(3); b.append("12345"); b2.append("67890"); Assert.AreEqual(b.get_pos(), 5); Assert.AreEqual(b.get_size() % 3, 0); Assert.AreEqual(b2.get_pos(), 5); Assert.AreEqual(b2.get_size() % 3, 0); b2.append(b); Assert.AreEqual(b2.to_string(), "6789012345"); b.delete(); b2.delete(); }
public void EchoTest() { Channel channel = new Channel(); PicoBuffer buf = new PicoBuffer(0); PicoBuffer recvbuf = new PicoBuffer(0); Thread echo_td = new Thread(() => echo_main(channel.get_name())); echo_td.Start(); buf.append("HELLO WORLD!"); channel.write_buffer(buf); channel.read(recvbuf); recvbuf.append(new byte[] { 0x00 }); Assert.AreEqual(recvbuf.to_string(), "HELLO WORLD!"); echo_td.Join(); channel.delete(); buf.delete(); recvbuf.delete(); }
public void KeyDeriv() { SigmaKeyDeriv sigmakeyderiv; PicoBuffer sharedSecret; Nonce picoNonce; Nonce serviceNonce; PicoBuffer keyBytes; PicoBuffer nonceData; PicoBuffer base64; sharedSecret = new PicoBuffer(0); sharedSecret.append("\x23\x02\x38\x40\x70\x23\x49\x08\x23\x04\x48\x20\x39\x48\x02\x70\x8"); nonceData = new PicoBuffer(0); nonceData.append("\x01\x02\x03\x04\x05\x06\x07\x08"); picoNonce = new Nonce(); picoNonce.set_buffer(nonceData); nonceData.clear(); nonceData.append("\x07\x04\x09\x02\x03\x07\x05\x06"); serviceNonce = new Nonce(); serviceNonce.set_buffer(nonceData); nonceData.delete(); sigmakeyderiv = new SigmaKeyDeriv(); sigmakeyderiv.set(sharedSecret, picoNonce, serviceNonce); sharedSecret.delete();; picoNonce.delete(); serviceNonce.delete(); // sharedKey keyBytes = new PicoBuffer(0); base64 = new PicoBuffer(0); sigmakeyderiv.get_next_key(keyBytes, 128); Base64.encode(keyBytes, base64); base64.append(new byte[] { 0x00 }); Assert.AreEqual(base64.to_string(), "7iU6mLgArgvtO9HW0lvk/g=="); // pMacKey keyBytes.clear(); base64.clear(); sigmakeyderiv.get_next_key(keyBytes, 256); Base64.encode(keyBytes, base64); base64.append(new byte[] { 0x00 }); Assert.AreEqual(base64.to_string(), "L0VyA6JS5ZMggVMvJB22s61K+9INGk3OqK0eyJLMnSs="); // pEncKey keyBytes.clear(); base64.clear(); sigmakeyderiv.get_next_key(keyBytes, 128); Base64.encode(keyBytes, base64); base64.append(new byte[] { 0x00 }); Assert.AreEqual(base64.to_string(), "ynUis+NzmrGp5yC3nX0Gjw=="); // vMacKey keyBytes.clear(); base64.clear(); sigmakeyderiv.get_next_key(keyBytes, 256); Base64.encode(keyBytes, base64); base64.append(new byte[] { 0x00 }); Assert.AreEqual(base64.to_string(), "J1mluN+sD9qrhdQ83vd/o7BKQvsq5l80t7CuTcs6A0A="); // pEncKey keyBytes.clear(); base64.clear(); sigmakeyderiv.get_next_key(keyBytes, 128); Base64.encode(keyBytes, base64); base64.append(new byte[] { 0x00 }); Assert.AreEqual(base64.to_string(), "7HK9ZbFCzAiVXUnlzOGDVA=="); keyBytes.delete(); base64.delete(); sigmakeyderiv.delete(); }