Beispiel #1
0
        /// <summary>
        /// Make keys for given encryption types.
        /// </summary>
        /// <param name="principal">Principal name</param>
        /// <param name="realm">Realm</param>
        /// <param name="password">Password</param>
        /// <param name="salt">Salt</param>
        /// <param name="type">Encryption type</param>
        public void MakeKey(string principal, string realm, string password, string salt, EncryptionType type)
        {
            EncryptionKey key         = KerberosUtility.MakeKey(type, password, salt);
            var           ExistingKey = QueryKey(principal, realm, type);

            if (ExistingKey != null)
            {
                throw new Exception("Key already exists.");
            }
            KeytabItem item = new KeytabItem()
            {
                Principal = principal,
                Realm     = realm.ToLower(),
                Kvno      = 0, // Set to 0 for self generated keys.
                KeyType   = type,
                Key       = key
            };

            keytabItems.Add(item);
        }
 /// <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(),
             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();
 }
Beispiel #3
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();
        }
 /// <summary>
 /// Make keys for given encryption types.
 /// </summary>
 /// <param name="principal">Principal name</param>
 /// <param name="realm">Realm</param>
 /// <param name="password">Password</param>
 /// <param name="salt">Salt</param>
 /// <param name="type">Encryption type</param>
 public void MakeKey(string principal, string realm, string password, string salt, EncryptionType type)
 {
     EncryptionKey key = KerberosUtility.MakeKey(type, password, salt);
     var ExistingKey = QueryKey(principal, realm, type);
     if (ExistingKey != null) throw new Exception("Key already exists.");
     KeytabItem item = new KeytabItem()
     {
         Principal = principal,
         Realm = realm,
         Kvno = 0, // Set to 0 for self generated keys.
         KeyType = type,
         Key = key
     };
     keytabItems.Add(item);
 }