Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Godshell
Skynet
Commits
c7f1de39
Commit
c7f1de39
authored
Feb 23, 2015
by
Jason Frisvold
Browse files
- Initial code for ssh library
parent
6790d7d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
gui/app/libs/sshkeylib.php
0 → 100644
View file @
c7f1de39
<?php
if
(
!
defined
(
'skynet'
))
exit
();
/* Skynet - Automated "Cloud" Security Scanner *#
#* Copyright (C) 2014-present Jason Frisvold <friz@godshell.com> *#
#* *#
#* This program is free software; you can redistribute it and/or modify *#
#* it under the terms of the GNU General Public License as published by *#
#* the Free Software Foundation; either version 2 of the License, or *#
#* (at your option) any later version. *#
#* *#
#* This program is distributed in the hope that it will be useful, *#
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *#
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *#
#* GNU General Public License for more details. *#
#* *#
#* You should have received a copy of the GNU General Public License *#
#* along with this program; if not, write to the Free Software *#
#* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
function
sshEncodeBuffer
(
$buffer
)
{
$len
=
strlen
(
$buffer
);
if
(
ord
(
$buffer
[
0
])
&
0x80
)
{
$len
++
;
$buffer
=
"
\x00
"
.
$buffer
;
}
return
pack
(
"Na*"
,
$len
,
$buffer
);
}
function
sshEncodePublicKey
(
$privKey
)
{
$keyInfo
=
openssl_pkey_get_details
(
$privKey
);
$buffer
=
pack
(
"N"
,
7
)
.
"ssh-rsa"
.
sshEncodeBuffer
(
$keyInfo
[
'rsa'
][
'e'
])
.
sshEncodeBuffer
(
$keyInfo
[
'rsa'
][
'n'
]);
return
"ssh-rsa "
.
base64_encode
(
$buffer
);
}
function
sshGenerateKeys
(
$bits
=
1024
)
{
// Generate a new public/private key pair
$rsaKey
=
openssl_pkey_new
(
array
(
'private_key_bits'
=>
$bits
,
'private_key_type'
=>
OPENSSL_KEYTYPE_RSA
));
// Get the private key and convert it to PEM format
$privKey
=
openssl_pkey_get_private
(
$rsaKey
);
openssl_pkey_export
(
$privKey
,
$pem
);
//Private Key
// Encode the public key
$pubKey
=
sshEncodePublicKey
(
$rsaKey
);
//Public Key
//$umask = umask(0066);
//file_put_contents('/tmp/test.rsa', $pem); // save private key into file
//file_put_contents('/tmp/test.rsa.pub', $pubKey); // save public key into file
//
//print "Private Key:\n $pem \n\n";
//echo "Public key:\n$pubKey\n\n";
}
?>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment