예제 #1
0
        void prover_main(string channel_name)
        {
            Channel channel          = Channel.connect(channel_name);
            Nonce   picoNonce        = new Nonce();
            KeyPair picoEphemeralKey = new KeyPair();

            picoEphemeralKey.generate();
            KeyPair picoIdentityKey = new KeyPair();

            picoIdentityKey.generate();
            picoNonce.generate_random();

            Nonce   serviceNonce    = new Nonce();
            IntPtr  serviceEphemKey = IntPtr.Zero;
            EncKeys keys            = new EncKeys();

            // Send start message
            send_start_message(channel, 2, picoEphemeralKey, picoNonce);

            // Receive service auth message
            receive_service_auth_message(channel, ref keys, picoEphemeralKey, picoNonce, ref serviceEphemKey, ref serviceNonce);

            // Send pico auth message
            send_pico_auth_message(channel, keys, serviceNonce, picoIdentityKey, picoEphemeralKey, "Test data");

            // Receive status message
            receive_status_message(channel, keys, "123456");

            picoEphemeralKey.delete();
            picoIdentityKey.delete();
            channel.delete();
            picoNonce.delete();
            serviceNonce.delete();
        }
예제 #2
0
        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();
        }