/// <exception cref="System.IO.IOException"/> public override void StoreTokenMasterKey(DelegationKey key) { if (Log.IsDebugEnabled()) { Log.Debug("Storing master key " + key.GetKeyId()); } Path keyPath = new Path(tokenKeysStatePath, TokenMasterKeyFilePrefix + key.GetKeyId ()); if (fs.Exists(keyPath)) { throw new IOException(keyPath + " already exists"); } ByteArrayOutputStream memStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(memStream); try { key.Write(dataStream); dataStream.Close(); dataStream = null; } finally { IOUtils.Cleanup(Log, dataStream); } CreateNewFile(keyPath, memStream.ToByteArray()); }
/// <exception cref="System.IO.IOException"/> public override void RemoveTokenMasterKey(DelegationKey key) { if (Log.IsDebugEnabled()) { Log.Debug("Removing master key " + key.GetKeyId()); } Path keyPath = new Path(tokenKeysStatePath, TokenMasterKeyFilePrefix + key.GetKeyId ()); DeleteFile(keyPath); }
protected override void StoreNewMasterKey(DelegationKey newKey) { try { Log.Info("storing master key with keyID " + newKey.GetKeyId()); rmContext.GetStateStore().StoreRMDTMasterKey(newKey); } catch (Exception e) { Log.Error("Error in storing master key with KeyID: " + newKey.GetKeyId()); ExitUtil.Terminate(1, e); } }
protected override void RemoveStoredMasterKey(DelegationKey key) { try { Log.Info("removing master key with keyID " + key.GetKeyId()); rmContext.GetStateStore().RemoveRMDTMasterKey(key); } catch (Exception e) { Log.Error("Error in removing master key with KeyID: " + key.GetKeyId()); ExitUtil.Terminate(1, e); } }
protected override void RemoveStoredMasterKey(DelegationKey key) { if (Log.IsDebugEnabled()) { Log.Debug("Removing master key " + key.GetKeyId()); } try { store.RemoveTokenMasterKey(key); } catch (IOException e) { Log.Error("Unable to remove master key " + key.GetKeyId(), e); } }
/// <exception cref="System.IO.IOException"/> public override void StoreTokenMasterKey(DelegationKey masterKey) { if (Log.IsDebugEnabled()) { Log.Debug("Storing master key " + masterKey.GetKeyId()); } ByteArrayOutputStream memStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(memStream); try { masterKey.Write(dataStream); dataStream.Close(); dataStream = null; } finally { IOUtils.Cleanup(Log, dataStream); } string dbKey = GetTokenMasterKeyDatabaseKey(masterKey); try { db.Put(JniDBFactory.Bytes(dbKey), memStream.ToByteArray()); } catch (DBException e) { throw new IOException(e); } }
/// <exception cref="System.Exception"/> private void LoadRMDTSecretManagerState(RMStateStore.RMState rmState) { CheckAndResumeUpdateOperation(rmDTSecretManagerRoot); FileStatus[] childNodes = ListStatusWithRetries(rmDTSecretManagerRoot); foreach (FileStatus childNodeStatus in childNodes) { System.Diagnostics.Debug.Assert(childNodeStatus.IsFile()); string childNodeName = childNodeStatus.GetPath().GetName(); if (CheckAndRemovePartialRecordWithRetries(childNodeStatus.GetPath())) { continue; } if (childNodeName.StartsWith(DelegationTokenSequenceNumberPrefix)) { rmState.rmSecretManagerState.dtSequenceNumber = System.Convert.ToInt32(childNodeName .Split("_")[1]); continue; } Path childNodePath = GetNodePath(rmDTSecretManagerRoot, childNodeName); byte[] childData = ReadFileWithRetries(childNodePath, childNodeStatus.GetLen()); ByteArrayInputStream @is = new ByteArrayInputStream(childData); using (DataInputStream fsIn = new DataInputStream(@is)) { if (childNodeName.StartsWith(DelegationKeyPrefix)) { DelegationKey key = new DelegationKey(); key.ReadFields(fsIn); rmState.rmSecretManagerState.masterKeyState.AddItem(key); if (Log.IsDebugEnabled()) { Log.Debug("Loaded delegation key: keyId=" + key.GetKeyId() + ", expirationDate=" + key.GetExpiryDate()); } } else { if (childNodeName.StartsWith(DelegationTokenPrefix)) { RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData (); identifierData.ReadFields(fsIn); RMDelegationTokenIdentifier identifier = identifierData.GetTokenIdentifier(); long renewDate = identifierData.GetRenewDate(); rmState.rmSecretManagerState.delegationTokenState[identifier] = renewDate; if (Log.IsDebugEnabled()) { Log.Debug("Loaded RMDelegationTokenIdentifier: " + identifier + " renewDate=" + renewDate ); } } else { Log.Warn("Unknown file for recovering RMDelegationTokenSecretManager"); } } } } }
/// <exception cref="System.IO.IOException"/> protected override void StoreNewMasterKey(DelegationKey key) { if (Log.IsDebugEnabled()) { Log.Debug("Storing master key " + key.GetKeyId()); } try { if (stateStore != null) { stateStore.StoreTokenMasterKey(key); } } catch (IOException e) { Log.Error("Unable to store master key " + key.GetKeyId(), e); } }
/// <exception cref="System.Exception"/> protected internal override void RemoveRMDTMasterKeyState(DelegationKey masterKey ) { lock (this) { Path nodeCreatePath = GetNodePath(rmDTSecretManagerRoot, DelegationKeyPrefix + masterKey .GetKeyId()); Log.Info("Removing RMDelegationKey_" + masterKey.GetKeyId()); DeleteFileWithRetries(nodeCreatePath); } }
/// <exception cref="System.Exception"/> protected internal override void RemoveRMDTMasterKeyState(DelegationKey delegationKey ) { lock (this) { Log.Info("Remove RMDT master key with key id: " + delegationKey.GetKeyId()); ICollection <DelegationKey> rmDTMasterKeyState = state.rmSecretManagerState.GetMasterKeyState (); rmDTMasterKeyState.Remove(delegationKey); } }
/// <exception cref="System.Exception"/> protected internal override void StoreRMDTMasterKeyState(DelegationKey delegationKey ) { lock (this) { ICollection <DelegationKey> rmDTMasterKeyState = state.rmSecretManagerState.GetMasterKeyState (); if (rmDTMasterKeyState.Contains(delegationKey)) { IOException e = new IOException("RMDTMasterKey with keyID: " + delegationKey.GetKeyId () + " is already stored"); Log.Info("Error storing info for RMDTMasterKey with keyID: " + delegationKey.GetKeyId (), e); throw e; } state.GetRMDTSecretManagerState().GetMasterKeyState().AddItem(delegationKey); Log.Info("Store RMDT master key with key id: " + delegationKey.GetKeyId() + ". Currently rmDTMasterKeyState size: " + rmDTMasterKeyState.Count); } }
/// <exception cref="System.IO.IOException"/> public override void RemoveTokenMasterKey(DelegationKey key) { try { byte[] k = CreateTokenMasterKeyEntryKey(key.GetKeyId()); db.Delete(k); } catch (DBException e) { throw new IOException(e); } }
/// <exception cref="System.Exception"/> protected internal override void StoreRMDTMasterKeyState(DelegationKey masterKey) { lock (this) { Path nodeCreatePath = GetNodePath(rmDTSecretManagerRoot, DelegationKeyPrefix + masterKey .GetKeyId()); ByteArrayOutputStream os = new ByteArrayOutputStream(); using (DataOutputStream fsOut = new DataOutputStream(os)) { Log.Info("Storing RMDelegationKey_" + masterKey.GetKeyId()); masterKey.Write(fsOut); WriteFileWithRetries(nodeCreatePath, os.ToByteArray(), true); } } }
/// <exception cref="System.IO.IOException"/> public override void RemoveTokenMasterKey(DelegationKey masterKey) { if (Log.IsDebugEnabled()) { Log.Debug("Removing master key " + masterKey.GetKeyId()); } string dbKey = GetTokenMasterKeyDatabaseKey(masterKey); try { db.Delete(JniDBFactory.Bytes(dbKey)); } catch (DBException e) { throw new IOException(e); } }
/// <exception cref="System.IO.IOException"/> public override void StoreTokenMasterKey(DelegationKey key) { try { byte[] k = CreateTokenMasterKeyEntryKey(key.GetKeyId()); if (db.Get(k) != null) { throw new IOException(key + " already exists"); } byte[] v = BuildTokenMasterKeyData(key); db.Put(k, v); } catch (DBException e) { throw new IOException(e); } }
/// <exception cref="System.IO.IOException"/> private int LoadRMDTSecretManagerKeys(RMStateStore.RMState state) { int numKeys = 0; LeveldbIterator iter = null; try { iter = new LeveldbIterator(db); iter.Seek(JniDBFactory.Bytes(RmDtMasterKeyKeyPrefix)); while (iter.HasNext()) { KeyValuePair <byte[], byte[]> entry = iter.Next(); string key = JniDBFactory.AsString(entry.Key); if (!key.StartsWith(RmDtMasterKeyKeyPrefix)) { break; } DelegationKey masterKey = LoadDelegationKey(entry.Value); state.rmSecretManagerState.masterKeyState.AddItem(masterKey); ++numKeys; if (Log.IsDebugEnabled()) { Log.Debug("Loaded RM delegation key from " + key + ": keyId=" + masterKey.GetKeyId () + ", expirationDate=" + masterKey.GetExpiryDate()); } } } catch (DBException e) { throw new IOException(e); } finally { if (iter != null) { iter.Close(); } } return(numKeys); }
private string GetTokenMasterKeyDatabaseKey(DelegationKey masterKey) { return TokenMasterKeyKeyPrefix + masterKey.GetKeyId(); }
private string GetRMDTMasterKeyNodeKey(DelegationKey masterKey) { return(RmDtMasterKeyKeyPrefix + masterKey.GetKeyId()); }