Yes, that is true. It does require root priviledges (assuming you are running on a Unix machine). This is a common concern. The usual trick is to overwrite the memory storing the plain text password with something else, as soon as you are done.

But! This might not be so easy, as compilers are smart. Last year, I saw an article showing some C code using this method. First a password was stored in a string, used to get some access, then the password was overwritten with spaces, and not used anymore. Or at least, the source code indicated that. However, the compiler noticed that the string had spaces put in it, and then it was no longer used. So, the compiler optimized the assignment to spaces away - it wasn't going to be used anyway.

In Perl, things are even more complex. A string isn't just a sequence of bytes terminated by a NUL with you holding a pointer to it. That sequence of bytes is there, but you aren't holding a pointer to it. I wouldn't know a pure Perl way of making sure that piece of memory gets overwritten. One could dive into the sources, and find a way that guarantees the string gets overwritten, but that may not work in another version anymore. But writing some XS code lets you get to the pointer, and then you can overwrite it.

Abigail


In reply to Re: Handling encryption safely by Abigail-II
in thread Handling encryption safely by bagu

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.