Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-11

Is it necessary to protect passed passwords in memory?

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Johannes Nohl

Dear list,

I was thinking of writing a daemon in freepascal. When the program is started it will ask for a password. Then keep the pass in a string variable, using it every 10 minutes.

It's not for an high security environment but I'm interested in general. How to protect those information in memory?

Johannes

Marc PERTRON
to Johannes Nohl
Johannes Nohl wrote 8 lines
Dear list, I was thinking of writing a daemon in freepascal. When the program is started it will ask for a password. Then keep the pass in a string variable, using it every 10 minutes. It's not for an high security environment but I'm interested in general. How to protect those information in memory?

Under Linux or BSD, only the owner can access the memory of his program. So if launched by root, only readable by root.
If possible, store a hash and not a clear password, just to be paranoid as we should :o)
Ex :

var
  salt : string;
  pwd : string;
begin
  salt := 'Something random or my software name, just used to avoid
dictionary attacks';
  pwd := md5('My Secret Password' + salt);
end;

So only a hash is stored in pwd, and it's unique.
But always remember that local access to a computer = quit easy to hack anything, unless you use strong cryptography.

Marc
Michael Van Canneyt
to Johannes Nohl: I was thinking of writing a daemon in freepascal. When the program is started it will ask…
Johannes Nohl wrote 8 lines
Dear list, I was thinking of writing a daemon in freepascal. When the program is started it will ask for a password. Then keep the pass in a string variable, using it every 10 minutes. It's not for an high security environment but I'm interested in general. How to protect those information in memory?

Just keep the password encrypted in memory, and decrypt it before you use it.
You can use the XOrEncode and XOrDecode functions for this. They are in the strutils unit.

Michael.

Johannes Nohl
to Vinzent Hoefler
And where do you think the phrase 'My Secret Password' would be stored other than memory?

so you have to override variables after use? like

var pwd: array[0..15] of char;
     xpwd: string;

[...]

readln(pwd);
xpwd := encrypt(pwd);
pwd := '123456789012345'; // override

[...]

???

Tomas Hajny
to Johannes Nohl
Johannes Nohl wrote 17 lines
> And where do you think the phrase 'My Secret Password' would be stored > other than memory? so you have to override variables after use? like var pwd: array[0..15] of char; xpwd: string; [...] readln(pwd); xpwd := encrypt(pwd); pwd := '123456789012345'; // override [...] ???

Yes, and obviously don't declare it within the
program (that's what appeared in the original
example from Marc Pertron) - your example is
indeed better from this point of view. I'd add
that the disadvantage of ReadLn (used by you) is
that it shows typed characters on console and in
addition, I believe that these characters might
be temporarily stored in a buffer in memory too
(before they get overwritten with following
input).

Tomas

Marc PERTRON
to Tomas Hajny
Tomas Hajny wrote 13 lines
On 1 Nov 06, at 18:13, Johannes Nohl wrote: Yes, and obviously don't declare it within the program (that's what appeared in the original example from Marc Pertron) - your example is indeed better from this point of view. I'd add that the disadvantage of ReadLn (used by you) is that it shows typed characters on console and in addition, I believe that these characters might be temporarily stored in a buffer in memory too (before they get overwritten with following input).

Of course my example or the ReadLn are because we don't know your program and where the password comes from.
It appears obvious that you should not write the password in clear text in the software if you want it not to be read from memory ! It was an example for hashing password which are one of the best solution but need a salt to avoid dictionary attacks. Marc