Beispiel #1
0
        unsafe public string MessageReceiving(string accountName, string protocol, string sender, string message)
        {
            IntPtr contextp;
            IntPtr newmessagep;
            int    r = OtrApi.otrl_message_receiving(
                Handle,
                ref ops,
                GCHandle.ToIntPtr(GCHandle), // opdata
                accountName,
                protocol,
                sender,
                message,
                out newmessagep,
                IntPtr.Zero,
                out contextp,
                null,
                IntPtr.Zero
                );

            //Console.WriteLine(r);
            //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));

            var decryptedMessage = Marshal.PtrToStringAnsi(newmessagep);

            OtrApi.otrl_message_free(newmessagep);
            return(decryptedMessage);
        }
Beispiel #2
0
        public void UserState()
        {
            var us = OtrApi.otrl_userstate_create();

            Assert.AreNotEqual(us, IntPtr.Zero);
            OtrApi.otrl_userstate_free(us);
        }
Beispiel #3
0
        unsafe public string MessageSending(string accountName, string protocol, string recipient, string message)
        {
            IntPtr contextp;
            IntPtr messagep; // this will contain the encrypted message
            int    r = OtrApi.otrl_message_sending(
                Handle,
                ref ops,
                GCHandle.ToIntPtr(GCHandle), // opdata
                accountName,
                protocol,
                recipient,
                InstanceTag.Best,
                message,
                IntPtr.Zero, //otrltlv
                out messagep,
                OtrlFragmentPolicy.Skip,
                //ref NULL,
                out contextp,
                null,
                IntPtr.Zero
                );

            //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));

            string encryptedMessage = Marshal.PtrToStringAnsi(messagep);

            OtrApi.otrl_message_free(messagep);
            return(encryptedMessage);
        }
Beispiel #4
0
        public void GeneratePrivateKey(string filename, string accountname, string protocol)
        {
            int r = OtrApi.otrl_privkey_generate(Handle, filename, accountname, protocol);

            //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));

            r = OtrApi.otrl_privkey_write_fingerprints(Handle, string.Format("{0}.fingerprints", filename));
            //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
        }
Beispiel #5
0
        public void Dispose()
        {
            var handle = Handle;

            if (handle == IntPtr.Zero)
            {
                return;
            }
            OtrApi.otrl_userstate_free(handle);
        }
Beispiel #6
0
        public IntPtr StartPrivateKeyGeneration(string accountname, string protocol)
        {
            IntPtr newkeyp;
            int    r = OtrApi.otrl_privkey_generate_start(Handle, accountname, protocol, out newkeyp);

            //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
            Console.WriteLine("calculating");
            r = OtrApi.otrl_privkey_generate_calculate(newkeyp);
            //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
            return(newkeyp);
        }
Beispiel #7
0
        // TODO: make it not static, put it somewhere useful
        unsafe public void HashToHuman(ArraySegment <byte> hash, ArraySegment <byte> human)
        {
            if (hash.Count < 20)
            {
                throw new ArgumentException("hash has to be at least 20 bytes long", nameof(hash));
            }

            if (human.Count < 44)
            {
                throw new ArgumentException("buffer for the human readable format has to be at least 45 bytes long", nameof(human));
            }

            fixed(byte *humanp = human.Array)
            fixed(byte *hashp = hash.Array)
            {
                IntPtr humanpointer = (IntPtr)humanp + human.Offset;
                IntPtr hashpointer  = (IntPtr)hashp + hash.Offset;

                OtrApi.otrl_privkey_hash_to_human(humanpointer, hashpointer);
            }
        }
Beispiel #8
0
 void CreateInstag(string accountname, string protocol)
 {
     OtrApi.otrl_instag_generate(Handle, "/dev/null", accountname, protocol);
     OtrApi.otrl_instag_write(Handle, string.Format("{0}.instag", accountname));
 }
Beispiel #9
0
 public void InstanceTagsRead(string filename)
 {
     int r = OtrApi.otrl_instag_read(Handle, filename);
     //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
 }
Beispiel #10
0
 static void Init()
 {
     var version = Version;
     int r       = OtrApi.otrl_init((uint)version.Major, (uint)version.Minor, (uint)version.Revision);
     //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
 }
Beispiel #11
0
 public void ReadFingerprints(string filename)
 {
     int r = OtrApi.otrl_privkey_read_fingerprints(Handle, filename, null, IntPtr.Zero);
     //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
 }
Beispiel #12
0
 public void ReadPrivateKey(string filename)
 {
     int r = OtrApi.otrl_privkey_read(Handle, filename);
     //Console.WriteLine(GCryptApi.MessageFromErrorCode(r));
 }
Beispiel #13
0
 unsafe public bool Fingerprint(ArraySegment <byte> segment, string accountname, string protocol)
 {
     return(Fill(segment, OtrApi.OTRL_PRIVKEY_FPRINT_HUMAN_LEN - 1, (IntPtr pointer) => OtrApi.otrl_privkey_fingerprint(Handle, pointer, accountname, protocol)));
 }
Beispiel #14
0
 unsafe public bool FingerprintRaw(ArraySegment <byte> segment, string accountname, string protocol)
 {
     return(Fill(segment, 20, (IntPtr pointer) => OtrApi.otrl_privkey_fingerprint_raw(Handle, pointer, accountname, protocol)));
 }
Beispiel #15
0
        public UserState()
        {
            Handle = OtrApi.otrl_userstate_create();

            GCHandle = GCHandle.Alloc(this);
        }
Beispiel #16
0
 public UserState()
 {
     Handle = OtrApi.otrl_userstate_create();
 }