private int _passphrase_cb(IntPtr Hook, IntPtr uid_hint, IntPtr passphrase_info, int prev_was_bad, int fd) { bool prevbad; string hint, info; char[] passwd = null; hint = Gpgme.PtrToStringUTF8(uid_hint); info = Gpgme.PtrToStringUTF8(passphrase_info); if (prev_was_bad > 0) { prevbad = true; } else { prevbad = false; } PassphraseResult result; try { PassphraseInfo pinfo = new PassphraseInfo(Hook, hint, info, prevbad); result = passphraseFunc(this, pinfo, ref passwd); } catch (Exception ex) { LastCallbackException = ex; passwd = "".ToCharArray(); result = PassphraseResult.Canceled; } if (fd > 0) { byte[] utf8passwd = Gpgme.ConvertCharArrayToUTF8(passwd, 0); Stream fdstream = Gpgme.ConvertToStream(fd, FileAccess.Write); fdstream.Write(utf8passwd, 0, utf8passwd.Length); fdstream.Flush(); fdstream.WriteByte((byte)'\n'); fdstream.Flush(); // try to wipe the passwords int i; for (i = 0; i < utf8passwd.Length; i++) { utf8passwd[i] = 0; } } return((int)result); }
/// <summary> /// Passphrase callback method. Invoked if a action requires the user's password. /// </summary> /// <param name="ctx">Context that has invoked the callback.</param> /// <param name="info">Information about the key.</param> /// <param name="passwd">User supplied password.</param> /// <returns></returns> public static PassphraseResult MyNewPassphraseCallback( Context ctx, PassphraseInfo info, ref char[] passwd) { Console.Write("Please enter your new passphrase.\n" + "Uid: " + info.Uid + "\nKey id: " + info.UidKeyId + "\nNew password: "); passwd = Console.ReadLine().ToCharArray(); return PassphraseResult.Success; }
/// <summary> /// Passphrase callback method. Invoked if a action requires the user's password. /// </summary> /// <param name="ctx">Context that has invoked the callback.</param> /// <param name="info">Information about the key.</param> /// <param name="passwd">User supplied password.</param> /// <returns></returns> public static PassphraseResult MyPassphraseCallback( Context ctx, PassphraseInfo info, ref char[] passwd) { Console.Write("You need to enter your passphrase.\n" + "Uid: " + info.Uid + "\nKey id: " + info.UidKeyId + "\nPrevious passphrase was bad: " + info.PrevWasBad + "\nPassword: "); passwd = Console.ReadLine().ToCharArray(); return PassphraseResult.Success; }
private int PassphraseCb(IntPtr hook, IntPtr uid_hint, IntPtr passphrase_info, int prev_was_bad, int fd) { char[] passwd = null; string hint = Gpgme.PtrToStringUTF8(uid_hint); string info = Gpgme.PtrToStringUTF8(passphrase_info); bool prevbad = prev_was_bad > 0; PassphraseResult result; try { var pinfo = new PassphraseInfo(hook, hint, info, prevbad); result = _passphrase_delegate(this, pinfo, ref passwd); } catch (Exception ex) { _last_callback_exception = ex; passwd = "".ToCharArray(); result = PassphraseResult.Canceled; } if (fd > 0) { byte[] utf8_passwd = Gpgme.ConvertCharArrayToUTF8(passwd, 0); libgpgme.gpgme_io_write(fd, utf8_passwd, (UIntPtr)utf8_passwd.Length); libgpgme.gpgme_io_write(fd, new[] { (byte)0 }, (UIntPtr)1); // try to wipe the passwords int i; for (i = 0; i < utf8_passwd.Length; i++) { utf8_passwd[i] = 0; } } return((int)result); }
public BadPassphraseException(PassphraseInfo info) : base() { this.PassphraseInfo = info; }
public EmptyPassphraseException(PassphraseInfo info) : base() { this.PassphraseInfo = info; }