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
a5b2e182
Commit
a5b2e182
authored
Feb 23, 2015
by
Jason Frisvold
Browse files
- Code to generate new ssh keypairs and store them in SQL
parent
c7f1de39
Changes
4
Hide whitespace changes
Inline
Side-by-side
gui/app/keymgmt.php
View file @
a5b2e182
...
...
@@ -20,8 +20,65 @@
$app
->
get
(
'/keymgmt'
,
$isauthenticated
(),
function
()
use
(
$app
)
{
global
$smarty_data
;
// Pull all data from the keymgmt table
$result
=
$app
->
db
->
table
(
'keymgmt'
)
->
select
(
'id'
,
'name'
,
'type'
,
'size'
,
'created'
)
->
get
();
$smarty_data
[
'results'
]
=
$result
;
prep_smarty
(
$app
);
$app
->
render
(
'keymgmt.tpl'
,
$smarty_data
);
});
// Edit Server Item
$app
->
get
(
'/edit-key'
,
$isauthenticated
(),
function
()
use
(
$app
)
{
global
$smarty_data
;
$keytypes
=
Array
(
'SSH'
=>
'SSH'
);
$keysizes
=
Array
(
1024
=>
1024
,
2048
=>
2048
,
4096
=>
4096
,
8192
=>
8192
);
$smarty_data
[
'keytypes'
]
=
$keytypes
;
$smarty_data
[
'keysizes'
]
=
$keysizes
;
prep_smarty
(
$app
);
$app
->
render
(
'edit-key.tpl'
,
$smarty_data
);
});
$app
->
post
(
'/edit-key'
,
$isauthenticated
(),
function
()
use
(
$app
)
{
$req
=
$app
->
request
();
require
(
'libs/sshkeylib.php'
);
// Retrieve parameters from the form
// TODO : These need to be validated
$id
=
$req
->
params
(
'id'
);
$keytype
=
$req
->
params
(
'keytype'
);
$keysize
=
$req
->
params
(
'keysize'
);
$keyname
=
$req
->
params
(
'keyname'
);
$newkey
=
sshGenerateKeys
((
int
)
$keysize
);
// Insert/Update array
$rowArray
=
array
(
'name'
=>
$keyname
,
'type'
=>
$keytype
,
'size'
=>
$keysize
,
'private'
=>
$newkey
[
'private'
],
'public'
=>
$newkey
[
'public'
],
'created'
=>
null
);
if
(
$id
)
{
$app
->
db
->
table
(
'keymgmt'
)
->
where
(
'id'
,
$id
)
->
update
(
$rowArray
);
}
else
{
$app
->
db
->
table
(
'keymgmt'
)
->
insert
(
$rowArray
);
}
$app
->
flash
(
'success'
,
'Form Submitted'
);
$app
->
redirect
(
'/keymgmt'
);
});
?>
\ No newline at end of file
gui/app/libs/sshkeylib.php
View file @
a5b2e182
...
...
@@ -41,17 +41,12 @@
// Get the private key and convert it to PEM format
$privKey
=
openssl_pkey_get_private
(
$rsaKey
);
openssl_pkey_export
(
$privKey
,
$
pem
);
//P
rivate
Key
openssl_pkey_export
(
$privKey
,
$
key
[
'p
rivate
'
]);
// Encode the public key
$
pubKey
=
sshEncodePublicKey
(
$rsaKey
);
//Public Key
$
key
[
'public'
]
=
sshEncodePublicKey
(
$rsaKey
);
//$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";
return
(
$key
);
}
?>
\ No newline at end of file
gui/app/templates/edit-key.tpl
0 → 100644
View file @
a5b2e182
{
--*
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*}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<link
rel=
'shortcut icon'
type=
'image/x-icon'
href=
'
{
$skynet_favicon
}
'
>
{
include
file
=
'head-css.tpl'
}
<title>
Skynet Automated Security Scanner
</title>
</head>
<body>
{
assign
var
=
page
value
=
'timer'
}
{
include
file
=
'header.tpl'
}
<div
class=
'container'
>
<div
class=
'page-header'
>
<h1>
Key Management
</h1>
</div>
<form
action=
'/edit-key'
method=
'post'
>
<div
class=
'row'
>
<div
class=
"col-md-4"
>
<div
class=
'input-group'
>
<span
class=
"input-group-addon"
>
Name
</span>
<input
type=
'text'
name=
'keyname'
value=
'
{
$result.name
|
default
:
""
}
'
/>
</div>
</div>
</div>
<div
class=
'row'
>
<div
class=
"col-md-4"
>
<div
class=
'input-group'
>
<span
class=
"input-group-addon"
>
Key Type
</span>
{
html_options
name
=
keytype
options
=
$keytypes
selected
=
$result.type
|
default
:
""
}
</div>
</div>
</div>
<div
class=
'row'
>
<div
class=
"col-md-4"
>
<div
class=
'input-group'
>
<span
class=
"input-group-addon"
>
Size
</span>
{
html_options
name
=
keysize
options
=
$keysizes
selected
=
$result.size
|
default
:
""
}
</div>
</div>
</div>
<div
class=
'input-group'
>
<input
type=
'submit'
name=
'save'
value=
'Generate'
/>
</div>
<input
type=
'hidden'
name=
'id'
value=
'
{
$result.id
|
default
:
""
}
'
/>
</form>
</div>
{
include
file
=
'footer.tpl'
}
</body>
</html>
\ No newline at end of file
gui/app/templates/keymgmt.tpl
0 → 100644
View file @
a5b2e182
{
--*
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*}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<link
rel=
'shortcut icon'
type=
'image/x-icon'
href=
'
{
$skynet_favicon
}
'
>
{
include
file
=
'head-css.tpl'
}
<title>
Skynet Automated Security Scanner
</title>
</head>
<body>
{
assign
var
=
page
value
=
'timer'
}
{
include
file
=
'header.tpl'
}
<div
class=
'container'
>
<div
class=
'page-header'
>
<h1>
Key Management
</h1>
<h5><a
href=
'/edit-key'
>
Generate New Keypair
</a></h5>
</div>
<div>
<table
class=
'table table-striped'
>
<tr>
<th>
Name
</th>
<th>
Key Type
</th>
<th>
Size
</th>
<th>
Created
</th>
</tr>
{
foreach
from
=
$results
item
=
row
}
<tr>
<td><a
href=
'/edit-key/
{
$row.id
}
'
>
{
$row.name
}
</a></td>
<td>
{
$row.type
}
</td>
<td>
{
$row.size
}
</td>
<td>
{
$row.created
}
</td>
</tr>
{/
foreach
}
</table>
</div>
</div>
{
include
file
=
'footer.tpl'
}
</body>
</html>
\ 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