Well this is my first code on github. This is a code to save a password encrypted with an RSA key for a script like python to use it when running as a crontab for example. I’m new to go and also to coding well there is probably a lot of room for improvement in my Go code.
I build main component of the code with google go and i’m compiling it as a c-share library for other languages to use it. I build a python library to make use of it and a sample python script using it with parmiko.
The main concept is to take a script wiht all the code in it, tested and operational, then to add to that code the function to call the decrypt password. When done, a function call from another script or the REPL will generate an RSA key pair, encrypt the password and save the key in p12 PEM format with a password build by the Go code. The RSA key password is made of a cuimulation of information of the system on which the script is running and the passsword was encrypted for and sha256 checksum of the major file involved in the decrypt process to prevent the library to decrypt the password if the script or a library was changed.
It impose a restriction on the script as it prevent the script from any modification for the library to return the decrypt password, however, I found it necessary as I was saving a password in an encrypted format to pass it to a script.
The GO folder includes the code code to create the library on Linux with
go build -o ssecret.so -buildmode=c-shared main.go
on Windows, first run
go build -o ssecret.a -buildmode=c-archive main.go
and then use the C file to compile as a .dll with gcc (or other C compiler)
gcc -shared -pthread -o ssecret.dll ssecret.c ssecret.a -lWinMM -lntdll -lWS2_32
The Python folder includes the python library to call a python function that already include the ctype code, and a sample of usage with paramiko. To use it in my python script, I’m just copying the ssecret.so or ssecret.dll and the SaveSecret.py file in the lib folder of my python install.
To encrypt my password for the script, i’m just doing a single line call in the same folder as where is my script form the command line: python -c “import SaveSecret; SaveSecret.Ssecret()