Esempio n. 1
0
        public static Keytab Decode(byte[] buffer)
        {
            List <KeytabEntry> entryList    = new List <KeytabEntry>();
            KeytabDecodeBuffer decodeBuffer = new KeytabDecodeBuffer(buffer);
            Keytab             keytab       = new Keytab();

            keytab.FormatVersion = decodeBuffer.DecodeUInt16();  //0x502, or 0x501
            keytab.entries       = new KeytabEntry[1];
            while (!decodeBuffer.EOS)
            {
                entryList.Add(KeytabEntry.Decode(decodeBuffer, keytab.FormatVersion));
            }
            keytab.entries = new KeytabEntry[entryList.Count];
            for (int i = 0; i < entryList.Count; i++)
            {
                keytab.entries[i] = entryList[i];
            }
            return(keytab);
        }
Esempio n. 2
0
        /// <summary>
        /// Load keys from keytab file.
        /// </summary>
        /// <param name="filename">Filename</param>
        public void LoadKeytab(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

            byte[] buf = new byte[fs.Length];
            fs.Read(buf, 0, (int)fs.Length);
            Keytab kt = Keytab.Decode(buf);

            foreach (var entry in kt.entries)
            {
                string principal = entry.Components[0].ToString() +
                                   (entry.NumComponents > 1 ? ("/" + entry.Components[1].ToString()) : "");
                KeytabItem item = new KeytabItem()
                {
                    Principal = principal,
                    Realm     = entry.Realm.ToString().ToLower(),
                    Kvno      = entry.Kvno,
                    KeyType   = (EncryptionType)entry.Key.type,
                    Key       = new EncryptionKey(new KerbInt32((long)entry.Key.type), new Asn1OctetString(entry.Key.Data.Data))
                };
                keytabItems.Add(item);
            }
            fs.Close();
        }
 public static Keytab Decode(byte[] buffer)
 {
     List<KeytabEntry> entryList = new List<KeytabEntry>();
     KeytabDecodeBuffer decodeBuffer = new KeytabDecodeBuffer(buffer);
     Keytab keytab = new Keytab();
     keytab.FormatVersion = decodeBuffer.DecodeUInt16();  //0x502, or 0x501
     keytab.entries = new KeytabEntry[1];
     while (!decodeBuffer.EOS)
     {
         entryList.Add(KeytabEntry.Decode(decodeBuffer, keytab.FormatVersion));
     }
     keytab.entries = new KeytabEntry[entryList.Count];
     for (int i = 0; i < entryList.Count; i++)
     {
         keytab.entries[i] = entryList[i];
     }
     return keytab;
 }