private void MainForm_Load(object sender, EventArgs e)
        {
            Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            this.Text           += " v" + version.ToString(3);
            m_server.OnLogEntry += Program.OnLogEntry;

            List <IPAddress> localIPs = GetHostIPAddresses();
            KeyValuePairList <string, IPAddress> list = new KeyValuePairList <string, IPAddress>();

            list.Add("Any", IPAddress.Any);
            foreach (IPAddress address in localIPs)
            {
                list.Add(address.ToString(), address);
            }
            comboIPAddress.DataSource    = list;
            comboIPAddress.DisplayMember = "Key";
            comboIPAddress.ValueMember   = "Value";
            lblStatus.Text = "Author: Tal Aloni ([email protected])";
#if Win32
            if (!SecurityHelper.IsAdministrator())
            {
                lblStatus.Text = "Some features require administrator privileges and have been disabled";
            }
#endif
        }
示例#2
0
        public Result Delete(int id, IAppUser user)
        {
            var entity = Load(id);
            var error  = ValidDelete(entity, user);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.Do(ResultCodes.验证失败, error));
            }

            KeyValuePairList sqls = new KeyValuePairList();

            sqls.Add("UPDATE Asset_Stock SET IsDel=1,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new
            {
                Id       = id,
                UserId   = user.Id,
                UserName = user.Name
            });
            sqls.Add("UPDATE Asset_StockItem SET IsDel=1,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE StockId=@Id", new
            {
                Id       = id,
                UserId   = user.Id,
                UserName = user.Name
            });
            var result = db.ExecuteTran(sqls);

            return(result ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败));
        }
示例#3
0
        /// <summary>
        /// 关闭盘点
        /// </summary>
        /// <param name="id">盘点ID</param>
        /// <param name="user">操作人</param>
        /// <returns></returns>
        public Result Finish(int id, IAppUser user)
        {
            var entity = Load(id);

            if (entity == null)
            {
                return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在"));
            }
            if (entity.IsFinish)
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "该盘点已结束,请勿重复操作"));
            }

            KeyValuePairList sqls = new KeyValuePairList();

            sqls.Add("UPDATE Asset_Stock SET IsFinish=1,FinishAt=GETDATE(),UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new
            {
                Id       = id,
                UserId   = user.Id,
                UserName = user.Name
            });
            sqls.Add("UPDATE Asset_StockItem SET IsFinish=1,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE StockId=@Id", new
            {
                Id       = id,
                UserId   = user.Id,
                UserName = user.Name
            });
            var result = db.ExecuteTran(sqls);

            return(result ? ResultUtil.Success(0) : ResultUtil.Do(ResultCodes.数据库操作失败, 0));
        }
示例#4
0
        public static KeyValuePairList <AVPairKey, byte[]> GetAVPairSequence(string domainName, string computerName)
        {
            KeyValuePairList <AVPairKey, byte[]> pairs = new KeyValuePairList <AVPairKey, byte[]>();

            pairs.Add(AVPairKey.NbDomainName, UnicodeEncoding.Unicode.GetBytes(domainName));
            pairs.Add(AVPairKey.NbComputerName, UnicodeEncoding.Unicode.GetBytes(computerName));
            return(pairs);
        }
        /// <param name="clustersToAllocate">Number of clusters to allocate</param>
        private KeyValuePairList <long, long> FindClustersToAllocate(long startLCN, long endLCN, long clustersToAllocate, out long leftToFind)
        {
            int bitsPerCluster = Volume.BytesPerCluster * 8;
            KeyValuePairList <long, long> result = new KeyValuePairList <long, long>();

            leftToFind = clustersToAllocate;

            long runStartLCN       = 0; // temporary
            long runLength         = 0;
            long nextLCN           = startLCN;
            long bufferedBitmapVCN = -1;

            byte[] bufferedBitmap = null;
            while (nextLCN <= endLCN && leftToFind > 0)
            {
                long currentBitmapVCN = (long)(nextLCN / (uint)bitsPerCluster);
                if (currentBitmapVCN != bufferedBitmapVCN)
                {
                    bufferedBitmap    = ReadDataCluster(currentBitmapVCN);
                    bufferedBitmapVCN = currentBitmapVCN;
                }

                int bitOffsetInBitmap = (int)(nextLCN % (uint)bitsPerCluster);
                if (IsBitClear(bufferedBitmap, bitOffsetInBitmap))
                {
                    if (runLength == 0)
                    {
                        runStartLCN = nextLCN;
                        runLength   = 1;
                    }
                    else
                    {
                        runLength++;
                    }
                    leftToFind--;
                }
                else
                {
                    if (runLength > 0)
                    {
                        // Add this run
                        result.Add(runStartLCN, runLength);
                        runLength = 0;
                    }
                }
                nextLCN++;
            }

            // Add the last run
            if (runLength > 0)
            {
                result.Add(runStartLCN, runLength);
            }

            return(result);
        }
示例#6
0
 public NTLMv2ClientChallenge(DateTime timeStamp, byte[] clientChallenge, string domainName, string computerName)
 {
     CurrentVersion          = StructureVersion;
     MaximumSupportedVersion = StructureVersion;
     TimeStamp       = timeStamp;
     ClientChallenge = clientChallenge;
     AVPairs         = new KeyValuePairList <AVPairKey, byte[]>();
     AVPairs.Add(AVPairKey.NbDomainName, UnicodeEncoding.Unicode.GetBytes(domainName));
     AVPairs.Add(AVPairKey.NbComputerName, UnicodeEncoding.Unicode.GetBytes(computerName));
 }
示例#7
0
 public NTLMv2ClientChallengeStructure(DateTime time, byte[] clientChallenge, string domainName, string computerName)
 {
     ResponseVersion     = 1;
     ResponseVersionHigh = 1;
     Time            = time;
     ClientChallenge = clientChallenge;
     AVPairs         = new KeyValuePairList <AVPairKey, byte[]>();
     AVPairs.Add(AVPairKey.NbDomainName, UnicodeEncoding.Unicode.GetBytes(domainName));
     AVPairs.Add(AVPairKey.NbComputerName, UnicodeEncoding.Unicode.GetBytes(computerName));
 }
示例#8
0
        public KeyValuePairList <long, int> TranslateToLBN(long firstSectorIndex, int sectorCount, int sectorsPerCluster)
        {
            KeyValuePairList <long, int> result = new KeyValuePairList <long, int>();

            long previousLCN            = 0;
            long sectorOffset           = firstSectorIndex;
            int  sectorsLeftToTranslate = sectorCount;
            bool translating            = false;

            for (int index = 0; index < this.Count; index++)
            {
                DataRun run                 = this[index];
                long    runStartLCN         = previousLCN + run.RunOffset;
                long    runStartLSN         = runStartLCN * sectorsPerCluster;
                long    runLengthInClusters = run.RunLength;
                long    runLengthInSectors  = runLengthInClusters * sectorsPerCluster;

                if (!translating)                           // still searching for firstSectorIndex
                {
                    if (sectorOffset >= runLengthInSectors) // firstSectorIndex is not in this run, check in the next run
                    {
                        sectorOffset -= runLengthInSectors;
                    }
                    else
                    {
                        translating = true;

                        long startSectorLSN    = runStartLSN + sectorOffset;
                        long sectorsLeftInRun  = runLengthInSectors - sectorOffset; // how many sectors can be read from this run
                        int  sectorsTranslated = (int)Math.Min(sectorsLeftToTranslate, sectorsLeftInRun);
                        result.Add(startSectorLSN, sectorsTranslated);
                        sectorsLeftToTranslate -= sectorsTranslated;

                        if (sectorsLeftToTranslate == 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    int sectorsTranslated = (int)Math.Min(sectorsLeftToTranslate, runLengthInSectors);
                    result.Add(runStartLSN, sectorsTranslated);
                    sectorsLeftToTranslate -= sectorsTranslated;

                    if (sectorsLeftToTranslate == 0)
                    {
                        break;
                    }
                }
                previousLCN = runStartLCN;
            }

            return(result);
        }
示例#9
0
        private byte[] DecryptHeader(byte[] headerBytes, byte[] password)
        {
            Pbkdf2 pbkdf2;

            KeyValuePairList <HMAC, int> hmacs = new KeyValuePairList <HMAC, int>();

            hmacs.Add(new HMACSHA512(), 1000);
            hmacs.Add(new HMACRIPEMD160(), 2000);
            hmacs.Add(new HMACWhirlpool(), 1000);

            foreach (KeyValuePair <HMAC, int> entry in hmacs)
            {
                HMAC hmac       = entry.Key;
                int  iterations = entry.Value;
                pbkdf2 = new Pbkdf2(hmac, password, Salt, iterations);
                byte[] key = pbkdf2.GetBytes(192);

                List <KeyValuePairList <SymmetricAlgorithm, byte[]> > algorithms = GetAlgorithms(key);

                foreach (KeyValuePairList <SymmetricAlgorithm, byte[]> algorithmChain in algorithms)
                {
                    byte[] decrypt = (byte[])headerBytes.Clone();

                    // TrueCrypt 7.1a Source (Common\Crypto.c):
                    // ----------------------------------------
                    // When encrypting/decrypting a buffer (typically a volume header) the sequential number
                    // of the first XTS data unit in the buffer is always 0 and the start of the buffer is
                    // always assumed to be aligned with the start of the data unit 0.
                    decrypt = XTSHelper.XTSChainDecrypt(algorithmChain, 0, decrypt, 0, 448);

                    string signature     = ByteReader.ReadAnsiString(decrypt, 0, 4);
                    ushort formatVersion = BigEndianConverter.ToUInt16(decrypt, 4);
                    uint   checksum256   = BigEndianConverter.ToUInt32(decrypt, 8);

                    byte[] temp             = ByteReader.ReadBytes(decrypt, 192, 256);
                    uint   computedChecksum = Utilities.CRC32.Compute(temp);

                    if (signature == TrueCryptSignature && checksum256 == computedChecksum)
                    {
                        m_isValid = true;
                        if (formatVersion == SupportedFormatVersion)
                        {
                            m_isSupported = true;
                        }
                        m_algorithmChain = algorithmChain;
                        m_hmac           = hmac;
                        return(decrypt);
                    }
                }
            }

            return(null);
        }
示例#10
0
        public KeyValuePairList <long, long> TranslateToLCN(long firstClusterVCN, long clusterCount)
        {
            KeyValuePairList <long, long> result = new KeyValuePairList <long, long>();

            long previousLCN             = 0;
            long clusterOffset           = firstClusterVCN;
            long clustersLeftToTranslate = clusterCount;
            bool translating             = false;

            for (int index = 0; index < this.Count; index++)
            {
                DataRun run         = this[index];
                long    runStartLCN = previousLCN + run.RunOffset;

                if (!translating)                       // still searching for firstClusterVCN
                {
                    if (clusterOffset >= run.RunLength) // firstClusterVCN is not in this run, check in the next run
                    {
                        clusterOffset -= run.RunLength;
                    }
                    else
                    {
                        translating = true;

                        long startClusterLCN    = runStartLCN + clusterOffset;
                        long clustersLeftInRun  = run.RunLength - clusterOffset; // how many clusters can be read from this run
                        long clustersTranslated = (long)Math.Min(clustersLeftToTranslate, clustersLeftInRun);
                        result.Add(startClusterLCN, clustersTranslated);
                        clustersLeftToTranslate -= clustersTranslated;

                        if (clustersLeftToTranslate == 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    long clustersTranslated = (long)Math.Min(clustersLeftToTranslate, run.RunLength);
                    result.Add(runStartLCN, clustersTranslated);
                    clustersLeftToTranslate -= clustersTranslated;

                    if (clustersLeftToTranslate == 0)
                    {
                        break;
                    }
                }
                previousLCN = runStartLCN;
            }

            return(result);
        }
示例#11
0
        // Note: The PC is simply a BTH with cbKey set to 2 and cbEnt set to 6
        public List <T> GetAll()
        {
            List <T> result = new List <T>();

            List <byte[]> leaves = new List <byte[]>();

            if (BTreeHeader.bIdxLevels > 0)
            {
                KeyValuePairList <byte[], byte> parents = new KeyValuePairList <byte[], byte>();
                parents.Add(GetHeapItem(BTreeHeader.hidRoot), BTreeHeader.bIdxLevels);
                while (parents.Count > 0)
                {
                    byte[] parentBytes = parents[0].Key;
                    byte   level       = parents[0].Value;

                    int offset = 0;
                    while (offset < parentBytes.Length)
                    {
                        HeapID hid   = new HeapID(parentBytes, offset + BTreeHeader.cbKey);
                        byte[] bytes = GetHeapItem(hid);
                        if (level == 1)
                        {
                            leaves.Add(bytes);
                        }
                        else
                        {
                            parents.Add(bytes, (byte)(level - 1));
                        }
                        offset += BTreeHeader.cbKey + HeapID.Length;
                    }
                    parents.RemoveAt(0);
                }
            }
            else
            {
                leaves.Add(GetHeapItem(BTreeHeader.hidRoot));
            }

            foreach (byte[] leafBytes in leaves)
            {
                int offset = 0;

                while (offset < leafBytes.Length)
                {
                    T record = BTreeOnHeapDataRecord.CreateInstance <T>(leafBytes, offset);
                    result.Add(record);
                    offset += BTreeHeader.cbKey + BTreeHeader.cbEnt;
                }
            }

            return(result);
        }
示例#12
0
        private void ServerUI_Load(object sender, EventArgs e)
        {
            List <IPAddress> localIPs = NetworkInterfaceHelper.GetHostIPAddresses();
            KeyValuePairList <string, IPAddress> list = new KeyValuePairList <string, IPAddress>();

            list.Add("Any", IPAddress.Any);
            foreach (IPAddress address in localIPs)
            {
                list.Add(address.ToString(), address);
            }
            comboIPAddress.DataSource    = list;
            comboIPAddress.DisplayMember = "Key";
            comboIPAddress.ValueMember   = "Value";
        }
        public KeyValuePairList <MftSegmentReference, FileNameRecord> GetAllEntries(NTFSVolume volume, IndexRootRecord rootRecord)
        {
            KeyValuePairList <MftSegmentReference, FileNameRecord> result = new KeyValuePairList <MftSegmentReference, FileNameRecord>();
            List <IndexNodeEntry> parents = new List <IndexNodeEntry>(rootRecord.IndexEntries);
            List <IndexRecord>    leaves  = new List <IndexRecord>();

            int parentIndex = 0;

            while (parentIndex < parents.Count)
            {
                IndexNodeEntry parent   = parents[parentIndex];
                byte[]         clusters = this.ReadDataClusters(volume, parent.SubnodeVCN, rootRecord.ClustersPerIndexRecord);
                IndexRecord    record   = new IndexRecord(clusters, 0);
                if (record.HasChildren)
                {
                    foreach (IndexNodeEntry node in record.IndexEntries)
                    {
                        parents.Add(node);
                    }
                }
                else
                {
                    leaves.Add(record);
                }

                parentIndex++;
            }

            foreach (IndexNodeEntry node in parents)
            {
                if (!node.IsLastEntry)
                {
                    // Some of the tree data in NTFS is contained in non-leaf keys
                    FileNameRecord parentRecord = new FileNameRecord(node.Key, 0);
                    result.Add(node.SegmentReference, parentRecord);
                }
            }

            foreach (IndexRecord record in leaves)
            {
                foreach (FileNameIndexEntry entry in record.FileNameEntries)
                {
                    result.Add(entry.FileReference, entry.Record);
                }
            }

            result.Sort(Compare);

            return(result);
        }
示例#14
0
        public KeyValuePairList <MftSegmentReference, byte[]> GetAllEntries()
        {
            KeyValuePairList <MftSegmentReference, byte[]> result = new KeyValuePairList <MftSegmentReference, byte[]>();

            if (!m_rootRecord.IsParentNode)
            {
                foreach (IndexEntry entry in m_rootRecord.IndexEntries)
                {
                    result.Add(entry.FileReference, entry.Key);
                }
            }
            else
            {
                List <IndexEntry> parents         = new List <IndexEntry>(m_rootRecord.IndexEntries);
                SortedList <long> subnodesVisited = new SortedList <long>();

                while (parents.Count > 0)
                {
                    IndexEntry parent = parents[0];
                    if (!subnodesVisited.Contains(parent.SubnodeVBN))
                    {
                        IndexRecord record = ReadIndexRecord(parent.SubnodeVBN);
                        if (record.IsParentNode)
                        {
                            parents.InsertRange(0, record.IndexEntries);
                        }
                        else
                        {
                            foreach (IndexEntry entry in record.IndexEntries)
                            {
                                result.Add(entry.FileReference, entry.Key);
                            }
                        }
                        subnodesVisited.Add(parent.SubnodeVBN);
                    }
                    else
                    {
                        if (!parent.IsLastEntry)
                        {
                            // Some of the tree data in NTFS is contained in non-leaf keys
                            result.Add(parent.FileReference, parent.Key);
                        }
                        parents.RemoveAt(0);
                    }
                }
            }
            return(result);
        }
示例#15
0
        private KeyValuePairList <int, IndexRecord> FindRemovalPath(byte[] key, out int indexOfEntryToRemove)
        {
            bool isParentNode         = true;
            List <IndexEntry> entries = m_rootRecord.IndexEntries;
            KeyValuePairList <int, IndexRecord> path = new KeyValuePairList <int, IndexRecord>();

            while (isParentNode)
            {
                int index = CollationHelper.FindIndexInParentNode(entries, key, m_rootRecord.CollationRule);
                if (!entries[index].IsLastEntry && CollationHelper.Compare(entries[index].Key, key, m_rootRecord.CollationRule) == 0)
                {
                    indexOfEntryToRemove = index;
                    return(path);
                }
                long        subnodeVBN  = entries[index].SubnodeVBN;
                IndexRecord indexRecord = ReadIndexRecord(subnodeVBN);
                isParentNode = indexRecord.IsParentNode;
                entries      = indexRecord.IndexEntries;
                path.Add(index, indexRecord);
            }

            indexOfEntryToRemove = CollationHelper.FindIndexInLeafNode(entries, key, m_rootRecord.CollationRule);
            if (indexOfEntryToRemove >= 0)
            {
                return(path);
            }
            else
            {
                return(null);
            }
        }
示例#16
0
        private KeyValuePairList <long, int> MapSectors(long sectorIndex, int sectorCount)
        {
            if (m_grainTableStartSector == null)
            {
                byte[] grainDirectoryBytes = m_file.ReadSectors((long)m_header.GDOffset, 1);
                m_grainTableStartSector = LittleEndianConverter.ToUInt32(grainDirectoryBytes, 0);
            }

            long grainIndex = sectorIndex / (long)m_header.GrainSize;
            long grainSectorIndexInTable = grainIndex / 128;
            int  grainIndexInBuffer      = (int)grainIndex % 128;
            int  sectorsToReadFromTable  = (int)Math.Max(Math.Ceiling((double)(sectorCount - (128 - grainIndexInBuffer)) / 4), 1);

            byte[] grainTableBuffer = m_file.ReadSectors(m_grainTableStartSector.Value + grainSectorIndexInTable, sectorsToReadFromTable);

            long sectorIndexInGrain = sectorIndex % (long)m_header.GrainSize;

            KeyValuePairList <long, int> result = new KeyValuePairList <long, int>();
            uint grainOffset = LittleEndianConverter.ToUInt32(grainTableBuffer, grainIndexInBuffer * 4);

            grainOffset += (uint)sectorIndexInGrain;
            int sectorsLeft             = sectorCount;
            int sectorsProcessedInGrain = (int)Math.Min(sectorsLeft, (long)m_header.GrainSize - sectorIndexInGrain);

            result.Add(grainOffset, sectorsProcessedInGrain);
            sectorsLeft -= sectorsProcessedInGrain;

            while (sectorsLeft > 0)
            {
                grainIndexInBuffer++;
                grainOffset             = LittleEndianConverter.ToUInt32(grainTableBuffer, grainIndexInBuffer * 4);
                sectorsProcessedInGrain = (int)Math.Min(sectorsLeft, (long)m_header.GrainSize);
                long lastSectorIndex = result[result.Count - 1].Key;
                int  lastSectorCount = result[result.Count - 1].Value;
                if (lastSectorIndex + lastSectorCount == grainOffset)
                {
                    result[result.Count - 1] = new KeyValuePair <long, int>(lastSectorIndex, lastSectorCount + sectorsProcessedInGrain);
                }
                else
                {
                    result.Add(grainOffset, sectorsProcessedInGrain);
                }
                sectorsLeft -= sectorsProcessedInGrain;
            }

            return(result);
        }
示例#17
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List <IPAddress> localIPs = NetworkInterfaceHelper.GetHostIPAddresses();
            KeyValuePairList <string, IPAddress> list = new KeyValuePairList <string, IPAddress>();

            list.Add("Any", IPAddress.Any);
            foreach (IPAddress address in localIPs)
            {
                if (address.ToString().Equals("127.0.0.1"))
                {
                    continue;
                }
                list.Add(address.ToString(), address);
            }

            this.address_combobox.ItemsSource       = list;
            this.address_combobox.DisplayMemberPath = "Key";
            this.address_combobox.SelectedIndex     = 0;


            UserCollection users = this.GetUserCollection();

            if (users != null)
            {
                List <string> userNames = users.ListUsers();
                if (userNames.Count > 0)
                {
                    string username = userNames[0];
                    this.username_textbox.Text = username;
                    this.password_box.Password = users.GetUserPassword(username);
                }
            }

            m_sharesSettings = this.GetShareSettings();
            this.shares_listbox.ItemsSource       = m_sharesSettings;
            this.shares_listbox.DisplayMemberPath = "SharePath";

            int port = SettingsHelper.ReadServerPort();

            this.port_textbox.Text = port.ToString();

            bool shouldRunAsService = SettingsHelper.ReadRunAsService();

            this.service_checkbox.IsChecked = shouldRunAsService;
        }
        /// <param name="clustersToAllocate">Number of clusters to allocate</param>
        private KeyValuePairList <ulong, long> FindClustersToAllocate(ulong startLCN, ulong endLCN, long clustersToAllocate, out long leftToAllocate)
        {
            KeyValuePairList <ulong, long> result = new KeyValuePairList <ulong, long>();

            leftToAllocate = clustersToAllocate;

            ulong runStartLCN = 0; // temporary
            long  runLength   = 0;
            ulong nextLCN     = startLCN;

            while (nextLCN <= endLCN && leftToAllocate > 0)
            {
                if (IsClusterFree(nextLCN))
                {
                    if (runLength == 0)
                    {
                        runStartLCN = nextLCN;
                        runLength   = 1;
                    }
                    else
                    {
                        runLength++;
                    }
                    leftToAllocate--;
                }
                else
                {
                    if (runLength > 0)
                    {
                        result.Add(runStartLCN, runLength);
                        runLength = 0;
                        // add this run
                    }
                }
                nextLCN++;
            }

            // add the last run
            if (runLength > 0)
            {
                result.Add(runStartLCN, runLength);
            }

            return(result);
        }
        public void Add_OneItem_AddsCorrectItem()
        {
            var          list  = new KeyValuePairList <string, string>();
            const string key   = "key1";
            const string value = "value1";

            list.Add(key, value);

            Assert.AreEqual(key, list.InnerList[0].Key);
            Assert.AreEqual(value, list.InnerList[0].Value);
        }
示例#20
0
        /// <summary>
        /// This method is slower and should only be used for recovery purposes.
        /// </summary>
        private KeyValuePairList <MftSegmentReference, FileNameRecord> GetFileNameRecordsInDirectoryFromMft(long directoryBaseSegmentNumber)
        {
            KeyValuePairList <MftSegmentReference, FileNameRecord> result = new KeyValuePairList <MftSegmentReference, FileNameRecord>();
            List <FileRecord> fileRecords = GetFileRecordsInDirectoryFromMft(directoryBaseSegmentNumber);

            foreach (FileRecord fileRecord in fileRecords)
            {
                result.Add(fileRecord.BaseSegmentReference, fileRecord.FileNameRecord);
            }
            return(result);
        }
示例#21
0
        } // End Sub BuildAlternativeNameNetCoreVariant

        // https://codereview.stackexchange.com/questions/84752/net-bouncycastle-csr-and-private-key-generation
        public static Org.BouncyCastle.Asn1.X509.X509Name CreateSubject(
            string countryIso2Characters
            , string stateOrProvince
            , string localityOrCity
            , string companyName
            , string division
            , string domainName
            , string email)
        {
            // https://people.eecs.berkeley.edu/~jonah/bc/org/bouncycastle/asn1/x509/X509Name.html
            KeyValuePairList <Org.BouncyCastle.Asn1.DerObjectIdentifier, string> attrs =
                new KeyValuePairList <Org.BouncyCastle.Asn1.DerObjectIdentifier, string>();


            if (!string.IsNullOrEmpty(countryIso2Characters) && countryIso2Characters.Trim() != string.Empty)
            {
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.C, countryIso2Characters);
            }

            if (!string.IsNullOrEmpty(stateOrProvince) && stateOrProvince.Trim() != string.Empty)
            {
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.ST, stateOrProvince);
            }

            if (!string.IsNullOrEmpty(localityOrCity) && localityOrCity.Trim() != string.Empty)
            {
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.L, localityOrCity);
            }

            if (!string.IsNullOrEmpty(companyName) && companyName.Trim() != string.Empty)
            {
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.O, companyName);
            }

            if (!string.IsNullOrEmpty(division) && division.Trim() != string.Empty)
            {
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.OU, division);
            }

            // Must have ?
            if (!string.IsNullOrEmpty(domainName) && domainName.Trim() != string.Empty)
            {
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.CN, domainName);
            }

            if (!string.IsNullOrEmpty(email) && email.Trim() != string.Empty)
            {
                //attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.E, email); // email address in Verisign certificates
                attrs.Add(Org.BouncyCastle.Asn1.X509.X509Name.EmailAddress, email); //  Email address (RSA PKCS#9 extension)
            }

            Org.BouncyCastle.Asn1.X509.X509Name subject =
                new Org.BouncyCastle.Asn1.X509.X509Name(attrs.Keys, attrs.Values);

            return(subject);
        } // End Function CreateSubject
示例#22
0
        public static KeyValuePairList <string, string> ParseParameters(string[] args, int start)
        {
            KeyValuePairList <string, string> result = new KeyValuePairList <string, string>();

            for (int index = start; index < args.Length; index++)
            {
                string[] pair = args[index].Split('=');
                if (pair.Length >= 2)
                {
                    string key   = pair[0].ToLower(); // we search by the key, so it should be set to lowercase
                    string value = pair[1];
                    value = Unquote(value);
                    result.Add(key, value);
                }
                else
                {
                    result.Add(pair[0].ToLower(), String.Empty);
                }
            }
            return(result);
        }
示例#23
0
        private HttpResponseMessage SendText(string deviceId, PushbulletPushType type, string title, string content)
        {
            var postData = new KeyValuePairList <string, string>
            {
                { "device_iden", deviceId },
                { "type", type.ToString().ToLowerInvariant() },
                {
                    type != PushbulletPushType.Address
                                                ? "title"
                                                : "name",
                    title
                }
            };

            switch (type)
            {
            case PushbulletPushType.Note:
                postData.Add("body", content);
                break;

            case PushbulletPushType.Link:
                postData.Add("url", content);
                break;

            case PushbulletPushType.Address:
                postData.Add("address", content);
                break;

            case PushbulletPushType.List:
                foreach (var item in content.Split(';'))
                {
                    postData.Add("items", item);
                }
                break;
            }
            using (var postContent = new FormUrlEncodedContent(postData))
            {
                return(_client.PostAsync(PushbulletApiConstants.PushesUrl, postContent).Result);
            }
        }
        public CodeSignatureSuperBlob(byte[] buffer, int offset)
        {
            uint length = BigEndianConverter.ToUInt32(buffer, offset + 4);
            uint count  = BigEndianConverter.ToUInt32(buffer, offset + 8);

            for (int index = 0; index < count; index++)
            {
                CodeSignatureEntryType entryType = (CodeSignatureEntryType)BigEndianConverter.ToUInt32(buffer, offset + 12 + index * 8);
                uint entryOffset       = BigEndianConverter.ToUInt32(buffer, offset + 12 + index * 8 + 4);
                CodeSignatureBlob blob = CodeSignatureBlob.ReadBlob(buffer, offset + (int)entryOffset);
                Entries.Add(entryType, blob);
            }
        }
示例#25
0
        public KeyValuePairList <MftSegmentReference, FileNameRecord> GetAllFileNameRecords()
        {
            KeyValuePairList <MftSegmentReference, FileNameRecord> result  = new KeyValuePairList <MftSegmentReference, FileNameRecord>();
            KeyValuePairList <MftSegmentReference, byte[]>         entries = GetAllEntries();

            foreach (KeyValuePair <MftSegmentReference, byte[]> entry in entries)
            {
                FileNameRecord fileNameRecord = new FileNameRecord(entry.Value, 0);
                result.Add(entry.Key, fileNameRecord);
            }

            return(result);
        }
        public PositiveNameQueryResponse(byte[] buffer, int offset)
        {
            Header   = new NameServicePacketHeader(buffer, ref offset);
            Resource = new ResourceRecord(buffer, ref offset);
            int position = 0;

            while (position < Resource.Data.Length)
            {
                NameFlags nameFlags = (NameFlags)BigEndianReader.ReadUInt16(Resource.Data, ref position);
                byte[]    address   = ByteReader.ReadBytes(Resource.Data, ref position, 4);
                Addresses.Add(address, nameFlags);
            }
        }
示例#27
0
        public CodeRequirementsBlob(byte[] buffer, int offset) : base(buffer, offset)
        {
            uint length = BigEndianConverter.ToUInt32(buffer, offset + 4);
            uint count  = BigEndianConverter.ToUInt32(buffer, offset + 8);

            for (int index = 0; index < count; index++)
            {
                SecurityRequirementType entryType = (SecurityRequirementType)BigEndianConverter.ToUInt32(buffer, offset + 12 + index * 8);
                uint entryOffset         = BigEndianConverter.ToUInt32(buffer, offset + 12 + index * 8 + 4);
                CodeRequirementBlob blob = CodeRequirementBlob.ReadCodeRequirementBlob(buffer, offset + (int)entryOffset);
                Entries.Add(entryType, blob);
            }
        }
示例#28
0
        public static KeyValuePairList <AVPairKey, byte[]> ReadAVPairSequence(byte[] buffer, int offset)
        {
            KeyValuePairList <AVPairKey, byte[]> result = new KeyValuePairList <AVPairKey, byte[]>();
            AVPairKey key = (AVPairKey)LittleEndianConverter.ToUInt16(buffer, offset);

            while (key != AVPairKey.EOL)
            {
                KeyValuePair <AVPairKey, byte[]> pair = ReadAVPair(buffer, ref offset);
                result.Add(pair);
                key = (AVPairKey)LittleEndianConverter.ToUInt16(buffer, offset);
            }

            return(result);
        }
示例#29
0
        /// <param name="targetName">Set to null for discovery session</param>
        internal static LoginRequestPDU GetFirstStageLoginRequest(string initiatorName, string targetName, ConnectionParameters connection)
        {
            ISCSISession    session = connection.Session;
            LoginRequestPDU request = new LoginRequestPDU();

            request.InitiatorTaskTag = session.GetNextTaskTag();
            request.ISID             = session.ISID;
            request.TSIH             = 0; // used on the first connection for a new session
            request.CID       = connection.CID;
            request.CmdSN     = session.GetNextCmdSN(false);
            request.ExpStatSN = 0;
            // The stage codes are:
            // 0 - SecurityNegotiation
            // 1 - LoginOperationalNegotiation
            // 3 - FullFeaturePhase
            request.CurrentStage = 0;
            request.NextStage    = 1;
            request.Transit      = true;
            request.VersionMax   = 0;
            request.VersionMin   = 0;
            KeyValuePairList <string, string> loginParameters = new KeyValuePairList <string, string>();

            loginParameters.Add("InitiatorName", initiatorName);
            loginParameters.Add("AuthMethod", "None");
            if (targetName == null)
            {
                loginParameters.Add("SessionType", "Discovery");
            }
            else
            {
                // RFC 3720: For any connection within a session whose type is not "Discovery", the first Login Request MUST also include the TargetName key=value pair.
                loginParameters.Add("SessionType", "Normal");
                loginParameters.Add("TargetName", targetName);
            }
            request.LoginParameters = loginParameters;
            return(request);
        }
示例#30
0
        public Result Scrap(int assetId, DateTime operateAt, string pics, string remark, IAppUser user)
        {
            var asset = LoadDto(assetId);

            if (asset == null)
            {
                return(ResultUtil.Do(ResultCodes.数据不存在, "资产不存在或已删除"));
            }
            if (asset.State == "借出")
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "该资产处于借出状态,禁止报废"));
            }

            var log = new AssetLog
            {
                AssetId           = asset.Id,
                AssetName         = asset.Name,
                AssetCode         = asset.Code,
                FromAccountId     = asset.AccountId,
                FromAccountName   = asset.AccountName,
                FromDeptId        = asset.DeptId,
                FromDeptName      = asset.DeptName,
                TargetAccountId   = 0,
                TargetAccountName = "",
                TargetDeptId      = 0,
                TargetDeptName    = "",
                Type      = "报废",
                OperateAt = operateAt,
                Remark    = remark,
                Pics      = pics
            };

            log.BeforeCreate(user);

            var sqls = new KeyValuePairList
            {
                {
                    "UPDATE Asset_Asset SET [State]='报废',UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id",
                    new { Id = log.AssetId, UserId = user.Id, UserName = user.Name }
                }
            };

            log.BeforeCreate(user);
            sqls.Add(db.GetCommonInsertSql <AssetLog>(), log);

            var row = db.ExecuteTran(sqls);

            return(row ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败"));
        }