Skip to content

Connectusing KeyText #70

@VegaTom

Description

@VegaTom

Im trying to make an ssh connection using the keytext instead of a keypath with no success.

Im saving the key text encrypted in database for mobility and security reasons but i am not able to inyect into ssh config to make the connection. All i get is "cannot connect to server".

I have tried also using the keytext hardcoded with no success.

I think there is no problem storing the key in the database and retrieving it later because if i save the retrieved key from database into a temp file in the storage and use the key path, i make a successfully connection.

This works:

public function getSshConfig(): array
    {
        $identity = $this->identityByServiceNumber(22);
        $config = array_merge([
            'host' => $this->connectionRoute(22),
            'username' => $identity->username,
            'agent' => '',
            'timeout' => 60,
        ], $identity->private_key ? [
            'key' => Storage::put('keys' . DIRECTORY_SEPARATOR . $identity->id, $identity->private_key) ?
            storage_path('app' . DIRECTORY_SEPARATOR . 'keys' . DIRECTORY_SEPARATOR . $identity->id) : null,
            'keyphrase' => $identity->password,
        ] : [
            'password' => $identity->password,
        ]);

        return $config;
    }

This doesnt work:

public function getSshConfig(): array
    {
        $identity = $this->identityByServiceNumber(22);
        $config = array_merge([
            'host' => $this->connectionRoute(22),
            'username' => $identity->username,
            'key' => '',
            'agent' => '',
            'timeout' => 60,
        ], $identity->private_key ? [
            'keytext' => $identity->private_key,
            'keyphrase' => $identity->password,
        ] : [
            'password' => $identity->password,
        ]);

        return $config;
    }

neither this work:

public function getSshConfig(): array
    {
        $identity = $this->identityByServiceNumber(22);
        $config = array_merge([
            'host' => $this->connectionRoute(22),
            'username' => $identity->username,
            'key' => '',
            'agent' => '',
            'timeout' => 60,
        ], $identity->private_key ? [
            'keytext' => '-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,069AEAFA71947BEDA3AAA1EC609D62B0
*********************************************************************
*********************************************************************
-----END RSA PRIVATE KEY-----',
            'keyphrase' => $identity->password,
        ] : [
            'password' => $identity->password,
        ]);

        return $config;
    }

and this:
'-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,069AEAFA71947BEDA3AAA1EC609D62B0



-----END RSA PRIVATE KEY-----'

is exactly what is stored in database (encrypted at store and decrypted when retrieved) and as i said, work if i save to temp file and use the key path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions