public static async Task <(uint, string)> GenerateEncodedShareMDataRequest(List <ShareMDataModel> mDataList)
        {
            var shareMDataReq = new ShareMDataReq
            {
                App   = Utilities.GetAppExchangeInfo(),
                MData = new List <ShareMData>()
            };

            foreach (var item in mDataList)
            {
                shareMDataReq.MData.Add(new ShareMData()
                {
                    Name    = item.Name,
                    TypeTag = item.TypeTag,
                    Perms   = new PermissionSet
                    {
                        Read              = item.Access.Read,
                        Insert            = item.Access.Insert,
                        Delete            = item.Access.Delete,
                        Update            = item.Access.Update,
                        ManagePermissions = item.Access.ManagePermissions,
                    }
                });
            }

            var encodedShareMDataRequest = await Session.EncodeShareMDataRequestAsync(shareMDataReq);

            return(encodedShareMDataRequest);
        }
Esempio n. 2
0
        private static void OnDecodeIpcReqShareMDataCb(IntPtr userData, uint reqId, IntPtr authReq, IntPtr metadataPtr, UIntPtr metadataLen)
        {
            var tcs                  = BindingUtils.FromHandlePtr <TaskCompletionSource <IpcReq> >(userData);
            var shareMdReq           = new ShareMDataReq(Marshal.PtrToStructure <ShareMDataReqNative>(authReq));
            var metadataResponseList = BindingUtils.CopyToObjectList <MetadataResponse>(metadataPtr, (int)metadataLen);

            tcs.SetResult(new ShareMDataIpcReq(reqId, shareMdReq, metadataResponseList));
        }
Esempio n. 3
0
        public Task <string> EncodeShareMDataRespAsync(IntPtr auth, ref ShareMDataReq req, uint reqId, bool isGranted)
        {
            var reqNative = req.ToNative();

            var(ret, userData) = BindingUtils.PrepareTask <string>();
            EncodeShareMDataRespNative(auth, ref reqNative, reqId, isGranted, userData, DelegateOnFfiResultStringCb);
            reqNative.Free();
            return(ret);
        }
Esempio n. 4
0
        public Task <(uint, string)> EncodeShareMDataReqAsync(ref ShareMDataReq req)
        {
            var reqNative = req.ToNative();

            var(ret, userData) = BindingUtils.PrepareTask <(uint, string)>();
            EncodeShareMDataReqNative(ref reqNative, userData, DelegateOnFfiResultUIntStringCb);
            reqNative.Free();
            return(ret);
        }
Esempio n. 5
0
        public async Task ShareMDataAuthTest()
        {
            var locator = Utils.GetRandomString(10);
            var secret  = Utils.GetRandomString(20);
            var typeTag = 150001;
            var authReq = new AuthReq {
                App = new AppExchangeInfo {
                    Id = "net.maidsafe.test", Name = "TestApp", Scope = null, Vendor = "MaidSafe.net Ltd."
                },
                AppContainer = true,
                Containers   = new List <ContainerPermissions>()
            };
            var session = await Utils.CreateTestApp(locator, secret, authReq);

            var mdInfo = await session.MDataInfoActions.RandomPrivateAsync((ulong)typeTag);

            var actKey   = Utils.GetRandomData(10).ToList();
            var actValue = Utils.GetRandomData(10).ToList();

            using (var userSignKeyHandle = await session.Crypto.AppPubSignKeyAsync())
                using (var permissionsHandle = await session.MDataPermissions.NewAsync()) {
                    var permissionSet = new PermissionSet {
                        Read = true, Insert = true, Delete = false, Update = false, ManagePermissions = false
                    };
                    await session.MDataPermissions.InsertAsync(permissionsHandle, userSignKeyHandle, permissionSet);

                    using (var entriesHandle = await session.MDataEntries.NewAsync()) {
                        var key = await session.MDataInfoActions.EncryptEntryKeyAsync(mdInfo, actKey);

                        var value = await session.MDataInfoActions.EncryptEntryKeyAsync(mdInfo, actValue);

                        await session.MDataEntries.InsertAsync(entriesHandle, key, value);

                        await session.MData.PutAsync(mdInfo, permissionsHandle, entriesHandle);
                    }
                }

            session.Dispose();
            authReq.App = new AppExchangeInfo {
                Id = "net.maidsafe.test.app", Name = "Test App", Scope = null, Vendor = "MaidSafe.net Ltd."
            };
            var msg = await Session.EncodeAuthReqAsync(authReq);

            var authResponse = await Utils.AuthenticateAuthRequest(locator, secret, msg.Item2, true);

            var authGranted = await Session.DecodeIpcMessageAsync(authResponse) as AuthIpcMsg;

            Assert.That(authGranted, Is.Not.Null);
            session = await Session.AppRegisteredAsync(authReq.App.Id, authGranted.AuthGranted);

            var shareMdReq = new ShareMDataReq {
                App   = authReq.App,
                MData = new List <ShareMData> {
                    new ShareMData {
                        Name = mdInfo.Name, TypeTag = mdInfo.TypeTag, Perms = new PermissionSet {
                            Read = true, Insert = true
                        }
                    }
                }
            };
            var ipcMsg = await Session.EncodeShareMDataRequestAsync(shareMdReq);

            var response = await Utils.AuthenticateShareMDataRequest(locator, secret, ipcMsg.Item2, true);

            var responseMsg = await Session.DecodeIpcMessageAsync(response) as ShareMDataIpcMsg;

            Assert.That(responseMsg, Is.Not.Null);
            Assert.That(ipcMsg.Item1, Is.EqualTo(responseMsg.ReqId));
            var keys = await session.MData.ListKeysAsync(mdInfo);

            Assert.That(keys.Count, Is.EqualTo(1));
            session.Dispose();
        }
Esempio n. 6
0
 /// <summary>
 /// Initialises a ShareMDataReq instance.
 /// </summary>
 /// <param name="reqId">Request Id.</param>
 /// <param name="shareMDataReq">Share Mutable Data request.</param>
 /// <param name="metadataResponseList">Mutable Data MetaDataResonse list.</param>
 public ShareMDataIpcReq(uint reqId, ShareMDataReq shareMDataReq, List <MetadataResponse> metadataResponseList)
 {
     ReqId            = reqId;
     ShareMDataReq    = shareMDataReq;
     MetadataResponse = metadataResponseList;
 }
Esempio n. 7
0
 /// <summary>
 /// Encodes a MDataShareReq.
 /// </summary>
 /// <param name="shareMDataReq">Mutable Data share request.</param>
 /// <returns>Request Id, Encoded Mutable Data share request.</returns>
 public static Task <(uint, string)> EncodeShareMDataRequestAsync(ShareMDataReq shareMDataReq)
 {
     return(AppBindings.EncodeShareMDataReqAsync(ref shareMDataReq));
 }
 public ShareMDataIpcReq(uint reqId, ShareMDataReq shareMDataReq, MetadataResponse metadataResponse)
 {
     ReqId            = reqId;
     ShareMDataReq    = shareMDataReq;
     MetadataResponse = metadataResponse;
 }