All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
There are two conditions for the permissibility of purchasing shares or subscribing in them:
First condition: The transactions and practices of the company from which you buy shares and subscribe in it must be permissible.
Second condition: The company should not put part of the shareholders’ money in interest-based banks to take interests and add them to shareholders' profits.
Accordingly, these two conditions must be taken into account. For more benefit, please refer to fataawa 85042 and 92713.
As regards your previous dealings: given that you do not know of anything forbidden entering into your money, then you are not obliged to get rid of any of it, but if you doubt about it and want to be on the safe side, then you may get rid of the estimated amount about which you have doubts and give it to the poor and needy. For more benefit, please refer to fatwa 87149.
Finally, we should point out the issue of signing on behalf of someone else; if this is with his permission and the party with whom you deal knows this, and there is no cheating in it, then there is nothing wrong in it. But if there is any cheating or deceit in doing so, then it is forbidden, as the Prophet said, “Whoever cheats us is not one of us.” [Muslim]
Indeed, there are many means of lawful earning and lawful investment for anyone who seeks to find them, and no soul will die until it wholly consumes its provision and reaches its appointed time [for death], as Allaah says (what means): {And whoever fears Allaah - He will make for him a way out. And will provide for him from where he does not expect.} [Quran 65: 2-3]
Allaah knows best.