Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connectusing KeyText #70

Open
VegaTom opened this issue Oct 18, 2018 · 0 comments
Open

Connectusing KeyText #70

VegaTom opened this issue Oct 18, 2018 · 0 comments

Comments

@VegaTom
Copy link

VegaTom commented Oct 18, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant