// Token: 0x06000947 RID: 2375 RVA: 0x0004BB88 File Offset: 0x00049D88 public Stream Download(INode node, CancellationToken?cancellationToken = null) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File) { throw new ArgumentException("Invalid node"); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } this.EnsureLoggedIn(); DownloadUrlRequest request = new DownloadUrlRequest(node); DownloadUrlResponse downloadUrlResponse = this.Request <DownloadUrlResponse>(request, null); Stream stream = new MegaAesCtrStreamDecrypter(new BufferedStream(this.webClient.GetRequestRaw(new Uri(downloadUrlResponse.Url))), downloadUrlResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac); if (cancellationToken != null) { stream = new CancellableStream(stream, cancellationToken.Value); } return(stream); }
// Token: 0x0600094E RID: 2382 RVA: 0x0004C218 File Offset: 0x0004A418 public INode Rename(INode node, string newName) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.Directory && node.Type != NodeType.File) { throw new ArgumentException("Invalid node type"); } if (string.IsNullOrEmpty(newName)) { throw new ArgumentNullException("newName"); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } this.EnsureLoggedIn(); byte[] data = Crypto.EncryptAttributes(new Attributes(newName, ((Node)node).Attributes), nodeCrypto.Key); this.Request(new RenameRequest(node, data.ToBase64())); return(this.GetNodes().First((INode n) => n.Equals(node))); }
// Token: 0x0600098C RID: 2444 RVA: 0x0003D668 File Offset: 0x0003B868 public ShareNodeRequest(INode node, byte[] masterKey, IEnumerable <INode> nodes) : base("s2") { this.Id = node.Id; this.Options = new object[] { new { r = 0, u = "EXP" } }; INodeCrypto nodeCrypto = (INodeCrypto)node; byte[] array = nodeCrypto.SharedKey; if (array == null) { array = Crypto.CreateAesKey(); } this.SharedKey = Crypto.EncryptKey(array, masterKey).ToBase64(); if (nodeCrypto.SharedKey == null) { this.Share = new ShareData(node.Id); this.Share.AddItem(node.Id, nodeCrypto.FullKey, array); foreach (INode node2 in this.GetRecursiveChildren(nodes.ToArray <INode>(), node)) { this.Share.AddItem(node2.Id, ((INodeCrypto)node2).FullKey, array); } } byte[] data = (node.Id + node.Id).ToBytes(); this.HandleAuth = Crypto.EncryptKey(data, masterKey).ToBase64(); }
// Token: 0x06000944 RID: 2372 RVA: 0x0004B9A0 File Offset: 0x00049BA0 public Uri GetDownloadLink(INode node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File && node.Type != NodeType.Directory) { throw new ArgumentException("Invalid node"); } this.EnsureLoggedIn(); if (node.Type == NodeType.Directory) { this.Request(new ShareNodeRequest(node, this.masterKey, this.GetNodes())); node = this.GetNodes().First((INode x) => x.Equals(node)); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } GetDownloadLinkRequest request = new GetDownloadLinkRequest(node); string arg = this.Request <string>(request, null); return(new Uri(MegaApiClient.BaseUri, string.Format("/{0}/{1}#{2}", (node.Type == NodeType.Directory) ? "folder" : "file", arg, (node.Type == NodeType.Directory) ? nodeCrypto.SharedKey.ToBase64() : nodeCrypto.FullKey.ToBase64()))); }
/// <summary> /// Retrieve a Stream to download and decrypt the specified node /// </summary> /// <param name="node">Node to download (only <see cref="NodeType.File" /> can be downloaded)</param> /// <exception cref="NotSupportedException">Not logged in</exception> /// <exception cref="ApiException">Mega.co.nz service reports an error</exception> /// <exception cref="ArgumentNullException">node or outputFile is null</exception> /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> can be downloaded)</exception> /// <exception cref="DownloadException">Checksum is invalid. Downloaded data are corrupted</exception> public Stream Download(INode node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File) { throw new ArgumentException("Invalid node"); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } this.EnsureLoggedIn(); // Retrieve download URL DownloadUrlRequest downloadRequest = new DownloadUrlRequest(node); DownloadUrlResponse downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest); Stream dataStream = this.webClient.GetRequestRaw(new Uri(downloadResponse.Url)); return(new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac)); }
// Token: 0x06000A44 RID: 2628 RVA: 0x0004D9E8 File Offset: 0x0004BBE8 private CreateNodeRequest(INode parentNode, NodeType type, string attributes, string encryptedKey, byte[] key, string completionHandle) : base("p") { this.ParentId = parentNode.Id; this.Nodes = new CreateNodeRequest.CreateNodeRequestData[] { new CreateNodeRequest.CreateNodeRequestData { Attributes = attributes, Key = encryptedKey, Type = type, CompletionHandle = completionHandle } }; INodeCrypto nodeCrypto = parentNode as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("parentNode node must implement INodeCrypto"); } if (nodeCrypto.SharedKey != null) { this.Share = new ShareData(parentNode.Id); this.Share.AddItem(completionHandle, key, nodeCrypto.SharedKey); } }
public ShareNodeRequest(INode node, byte[] masterKey, IEnumerable <INode> nodes) : base("s2") { Id = node.Id; Options = new object[] { new { r = 0, u = "EXP" } }; INodeCrypto nodeCrypto = (INodeCrypto)node; byte[] uncryptedSharedKey = nodeCrypto.SharedKey; if (uncryptedSharedKey == null) { uncryptedSharedKey = Crypto.CreateAesKey(); } SharedKey = Crypto.EncryptKey(uncryptedSharedKey, masterKey).ToBase64(); if (nodeCrypto.SharedKey == null) { Share = new ShareData(node.Id); Share.AddItem(node.Id, nodeCrypto.FullKey, uncryptedSharedKey); // Add all children IEnumerable <INode> allChildren = GetRecursiveChildren(nodes.ToArray(), node); foreach (var child in allChildren) { Share.AddItem(child.Id, ((INodeCrypto)child).FullKey, uncryptedSharedKey); } } byte[] handle = (node.Id + node.Id).ToBytes(); HandleAuth = Crypto.EncryptKey(handle, masterKey).ToBase64(); }
/// <summary> /// Retrieve an url to download specified node /// </summary> /// <param name="node">Node to retrieve the download link (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</param> /// <returns>Download link to retrieve the node with associated key</returns> /// <exception cref="NotSupportedException">Not logged in</exception> /// <exception cref="ApiException">Mega.co.nz service reports an error</exception> /// <exception cref="ArgumentNullException">node is null</exception> /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</exception> public Uri GetDownloadLink(INode node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File && node.Type != NodeType.Directory) { throw new ArgumentException("Invalid node"); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } this.EnsureLoggedIn(); GetDownloadLinkRequest request = new GetDownloadLinkRequest(node); string response = this.Request <string>(request); return(new Uri(BaseUri, string.Format( "/#{0}!{1}!{2}", node.Type == NodeType.Directory ? "F" : string.Empty, response, nodeCrypto.FullKey.ToBase64()))); }
public MegaKeyCrypto(INodeCrypto CryptoKey) { if (CryptoKey == null) { return; } this.key = CryptoKey.Key; this.sharedkey = CryptoKey.SharedKey; this.iv = CryptoKey.Iv; this.metamac = CryptoKey.MetaMac; this.fullkey = CryptoKey.FullKey; }
/// <summary> /// Retrieve a Stream to download and decrypt the specified node /// </summary> /// <param name="node">Node to download (only <see cref="NodeType.File" /> can be downloaded)</param> /// <exception cref="NotSupportedException">Not logged in</exception> /// <exception cref="ApiException">Mega.co.nz service reports an error</exception> /// <exception cref="ArgumentNullException">node or outputFile is null</exception> /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> can be downloaded)</exception> /// <exception cref="DownloadException">Checksum is invalid. Downloaded data are corrupted</exception> public Stream Download(INode node, CancellationToken?cancellationToken = null) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File) { throw new ArgumentException("Invalid node"); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } this.EnsureLoggedIn(); // Retrieve download URL DownloadUrlRequest downloadRequest = new DownloadUrlRequest(node); DownloadUrlResponse downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest); Uri downloadUrl = new Uri(downloadResponse.Url); Stream dataStream = new SeekableReadStream(this.webClient.GetLength(downloadUrl), (buffer, bufferOffset, offset, count) => this.webClient.GetRequestRawWithRange( downloadUrl, offset, offset + count).Read(buffer, bufferOffset, count)); Stream resultStream = new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac); if (cancellationToken.HasValue) { resultStream = new CancellableStream(resultStream, cancellationToken.Value); } return(resultStream); }
public Stream Download(INode node, CancellationToken?cancellationToken = null) #endif { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File) { throw new ArgumentException("Invalid node"); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } this.EnsureLoggedIn(); // Retrieve download URL DownloadUrlRequest downloadRequest = new DownloadUrlRequest(node); DownloadUrlResponse downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest); Stream dataStream = this.webClient.GetRequestRaw(new Uri(downloadResponse.Url)); Stream resultStream = new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac); #if !NET35 if (cancellationToken.HasValue) { resultStream = new CancellableStream(resultStream, cancellationToken.Value); } #endif return(resultStream); }
/// <summary> /// Retrieve an url to download specified node /// </summary> /// <param name="node">Node to retrieve the download link (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</param> /// <returns>Download link to retrieve the node with associated key</returns> /// <exception cref="NotSupportedException">Not logged in</exception> /// <exception cref="ApiException">Mega.co.nz service reports an error</exception> /// <exception cref="ArgumentNullException">node is null</exception> /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</exception> public Uri GetDownloadLink(INode node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Type != NodeType.File && node.Type != NodeType.Directory) { throw new ArgumentException("Invalid node"); } this.EnsureLoggedIn(); if (node.Type == NodeType.Directory) { // Request an export share on the node or we will receive an AccessDenied this.Request(new ShareNodeRequest(node, this.masterKey, this.GetNodes())); node = this.GetNodes().First(x => x.Equals(node)); } INodeCrypto nodeCrypto = node as INodeCrypto; if (nodeCrypto == null) { throw new ArgumentException("node must implement INodeCrypto"); } GetDownloadLinkRequest request = new GetDownloadLinkRequest(node); string response = this.Request <string>(request); return(new Uri(BaseUri, string.Format( "/#{0}!{1}!{2}", node.Type == NodeType.Directory ? "F" : string.Empty, response, node.Type == NodeType.Directory ? nodeCrypto.SharedKey.ToBase64() : nodeCrypto.FullKey.ToBase64()))); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { ShareData data = value as ShareData; if (data == null) { throw new ArgumentException("invalid data to serialize"); } INodeCrypto parent = data.Parent as INodeCrypto; if (parent == null) { throw new ArgumentException("parent node must implement INodeCrypto"); } writer.WriteStartArray(); if (parent.SharedKey != null) { writer.WriteStartArray(); writer.WriteValue(data.Parent.Id); writer.WriteEndArray(); writer.WriteStartArray(); writer.WriteValue(data.CompletionHandle); writer.WriteEndArray(); writer.WriteStartArray(); writer.WriteValue(0); writer.WriteValue(0); writer.WriteValue(Crypto.EncryptAesEcb(data.Key, parent.SharedKey).ToBase64()); writer.WriteEndArray(); } writer.WriteEndArray(); }
public MegaNzNode(string Name, string ID, string parentid, long Size, NodeType type, DateTime mod_d, INodeCrypto keyDeCrypt) : base(keyDeCrypt) { this.name = Name; this.id = ID; this.parentid = parentid; this.size = Size; this.type = type; this.mod_d = mod_d; }
public MegaNzNode(string ID, INodeCrypto keyDeCrypt) : this(null, ID, null, -1, NodeType.File, new DateTime(), keyDeCrypt) { }