Ejemplo n.º 1
0
        public string UnlockKey(GPGUnlockKeyData unlockData)
        {
            try {
                string fingerPrint = pgpManager.UnlockKey(unlockData.FingerPrint, unlockData.Password);
                sm.PutKeyPassword(fingerPrint, unlockData.Password);
            } catch (Exception e) {
                throw new ErrorObjectException(new ErrorObject {
                    ErrorCode  = ErrorCodes.InvalidFieldData,
                    ErrorField = "Password",
                    ErrorData  = e,
                    Message    = "Cannot Decrypt Key"
                });
            }

            return("OK");
        }
Ejemplo n.º 2
0
        public Task UnlockLocalKeys()
        {
            return(Task.Run(async() => {
                if (masterKeyFingerprint == null)
                {
                    Logger.Error("SecretsManager", "Cannot unlock keys. Master key not loaded.");
                    return;
                }

                Logger.Log("SecretsManager", "Loading encrypted keys");
                var keys = GetKeys();
                if (!gpg.IsKeyUnlocked(masterKeyFingerprint))
                {
                    Logger.Log("SecretsManager", "Decrypting master key");
                    string pass = File.ReadAllText(Configuration.MasterGPGKeyPasswordPath, Encoding.UTF8);
                    gpg.UnlockKey(masterKeyFingerprint, pass);
                }
                Logger.Log("SecretsManager", "Starting key unlock");
                foreach (var key in keys.Keys)
                {
                    try {
                        Logger.Log("SecretsManager", $"Unlocking key {key}");
                        string enc = keys[key];
                        var dec = gpg.Decrypt(enc);
                        var decPass = Encoding.UTF8.GetString(Convert.FromBase64String(dec.Base64Data));

                        var payload = new GPGUnlockKeyData {
                            FingerPrint = key,
                            Password = decPass,
                        };

                        string response = await Tools.Post("http://localhost:5100/remoteSigner/gpg/unlockKey", JsonConvert.SerializeObject(payload));
                        if (response != "OK")
                        {
                            Logger.Error("SecretsManager", $"Error unlocking key: {response}");
                        }
                    } catch (Exception e) {
                        Logger.Error("SecretsManager", $"Error unlocking key: {e.Message}");
                        Logger.Error("SecretsManager", e.StackTrace);
                    }
                }
            }));
        }