I have never tried this myself, but I think it would work:

  • Obtain unencrypted password.
  • Set umask to 777 (backup original umask)
  • Open/create ".mypassword" (clobber existing file)
  • Delete ".mypassword".
  • Restore umask.
  • Write unencypted password to file.
  • Trash the memory resident copy of the password.

    Whenever the password is needed, a seek() and read() can be performed to obtain it. Do *not* close the file descriptor until it is known the password is never required again.

    No other user can open this file since it has no read or write permissions. Secondly, it will only exist on the file system for an extremely short period of time. If it were created in a directory with excessively restricted permissions then only root would ever be able to get to it.

    If your program dumps core, the .mypassword file will not be available since it has already been unlinked. Not until the last file descriptor is closed will the space be reclaimed. As far as I know, this is true of all unix file systems, not sure how it works with Windows. If you are concerned about core dumps, then I think Windows is irrelevant.

    For the majority of the runtime, all the core dump will contain is evidence of a file descriptor, which gives away zero information.

    For the remainder of the runtime, there is a slight chance a core dump might contain the password. This could be eliminated if the authentication mechanism allowed for passwords to be sent byte at a time, but I have never seen such a system.

    Alternatively, rotating the passwords might avoid this problem too.

    -Frank


    In reply to Re: hiding passwords by Anonymous Monk
    in thread hiding passwords by jfroebe

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.