Format of ssh private key - WeOnlyDo Discussion board

Format of ssh private key (wodSFTP / wodSFTP.NET / wodSFTPdll)

by Marco, Tuesday, November 02, 2004, 01:26 (7118 days ago)

Hi,

I'm trying to use the Wodssh libraries with C/C++ program.
I'm working with Damiano and we have another problem:

we don't able to use a private key creating with ssh linux command (ssh-keygen).
the Wodssh support sent us a correct private key that they use, but we happen a strange thing:
if in the program we take the private key from a file, then it go, but if we load the key in a mysql database and later we use it in the program, then it doesn't go.
Why? What is the correct format for the private key?
Is there a direct way to create a correct private key with a command or function? Must the key be converted in some different format such as binary format or must it be modified?

Thank you
Bye

Re: Format of ssh private key

by wodSupport, Tuesday, November 02, 2004, 01:28 (7118 days ago) @ Marco

Marco,

just for a test - can you check if data you write to mysql database is same as data you read back from it?

Why don't you base64 encode key before you write it to a database - so you write only ASCII chars?

Re: Format of ssh private key

by Marco, Tuesday, November 02, 2004, 10:58 (7117 days ago) @ wodSupport

Marco,

just for a test - can you check if data you write to mysql database is same as data you read back from it?

Why don't you base64 encode key before you write it to a database - so you write only ASCII chars?

Thank you for your fast answer.

I have another problem...
if I use the key we sent us the program is perfect, go very good as with key from mysql db as with key direct from file.
if I create a key with ssh-keygen tool, the program don't go and we don't change nothing!
Because this I ask you which is the correct format of private key.
How we create your keys?
We have tried to base64 encode the key, but it's same.

thanks you to help me

Re: Format of ssh private key

by wodSupport, Tuesday, November 02, 2004, 11:25 (7117 days ago) @ Marco

Marco,

we have wodKeys component (shipped with wodSFTP) for dealing with keys. Call it's Generate method to create new keys.

Don't forget to upload public key to the server!

Regards.

Re: Format of ssh private key

by Marco, Tuesday, November 02, 2004, 11:42 (7117 days ago) @ wodSupport

Marco,

we have wodKeys component (shipped with wodSFTP) for dealing with keys. Call it's Generate method to create new keys.

Don't forget to upload public key to the server!

Regards.

Dear,

we have some problem to generate a key with wodssh C/C++ code.
You write us this VB code:

Private Sub Form_Load()
Dim K As Keys
Set K = New Keys
K.Load App.Path & id_dsa.txt

Dim b() As Byte
b = K.PrivateKeyData(DSAkey)
Open App.Path & keydata For Binary As #1 Len = 1
Dim i As Integer
Dim j As Integer
j = 1
For i = LBound(b) To UBound(b)
Put #1, j, b(i)
j = j + 1
Next i
Close #1
End Sub

we can't use the key from file (in your example id_dsa.txt) because of security problem and we need to use it from mysql db.
Is there a way to create a correct key to load manually to mysql db?

thanks

Re: Format of ssh private key

by Marco, Tuesday, November 02, 2004, 13:17 (7117 days ago) @ Marco

Marco,

we have wodKeys component (shipped with wodSFTP) for dealing with keys. Call it's Generate method to create new keys.

Don't forget to upload public key to the server!

Regards.

Help me!! Please!

Re: Format of ssh private key

by wodSupport, Tuesday, November 02, 2004, 13:22 (7117 days ago) @ Marco

Marco,

I'm trying to help you - but you have to help yourself too! Read your previous post - you do know how to generate key, and when you save it to a file everything works ok. Am I correct? If you load it from a file, it works ok, right?

So, your problem is that you're trying to put it into mysql. I wish I can help you with that - but I don't have your code, and I don't know how do you put it to mysql. wodKeys cannot write to mysql databases directly, naturally, so you have to do this. And you have to read it later on.

I have suggested you BASE64 encode private key before you write it, and then BASE64 decode after you read it from database, and then pass on to PrivateKeyData property. Have you tried that?

Did you, just for a test, try to
1. Generate key
2. Save to a file 'a.key'
3. store into database
and then
4. retrieve from database
5. save to a file 'b.key'
6. check if 'a.key' and 'b.key' are binary same?

If they mismatch then you have problems with storing keys to a database. If they match then you can skip storing to a file, and pass it to PrivateKeyData directly.

I'm really trying to help you out here with ideas - but I'm not sitting in front of your computer, you have to try these things out.

Best regards,
Kreso

Re: Format of ssh private key

by Marco, Tuesday, November 02, 2004, 15:17 (7117 days ago) @ wodSupport

Marco,

I'm trying to help you - but you have to help yourself too! Read your previous post - you do know how to generate key, and when you save it to a file everything works ok. Am I correct? If you load it from a file, it works ok, right?

So, your problem is that you're trying to put it into mysql. I wish I can help you with that - but I don't have your code, and I don't know how do you put it to mysql. wodKeys cannot write to mysql databases directly, naturally, so you have to do this. And you have to read it later on.

I have suggested you BASE64 encode private key before you write it, and then BASE64 decode after you read it from database, and then pass on to PrivateKeyData property. Have you tried that?

Did you, just for a test, try to
1. Generate key
2. Save to a file 'a.key'
3. store into database
and then
4. retrieve from database
5. save to a file 'b.key'
6. check if 'a.key' and 'b.key' are binary same?

If they mismatch then you have problems with storing keys to a database. If they match then you can skip storing to a file, and pass it to PrivateKeyData directly.

I'm really trying to help you out here with ideas - but I'm not sitting in front of your computer, you have to try these things out.

Best regards,
Kreso

Kreso,

i'm sorry for my bad english. Maybe I didn't explain very well.
I thank you for your time.
Now we have resolved everything.
The real problem was the function 'Open' under C/C++ .
We wasn't understanding because the key you sent us was different from our key generating by a linux command.
Now we generate the key with wodssh tool and use it (with the right Open function)very well.

Thank you very much by Marco and Damiano

see you later


Re: Format of ssh private key

by wodSupport, Tuesday, November 02, 2004, 15:23 (7117 days ago) @ Marco

Marco, Damiano,

I am really pleased to hear that!

Best regards,
Kreso