Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
reg-app
Regapp
Commits
dd8b4457
Commit
dd8b4457
authored
Jan 23, 2019
by
michael.simon
Browse files
Don't break on unsupported key type
parent
0a41f178
Changes
4
Hide whitespace changes
Inline
Side-by-side
bwreg-service/src/main/java/edu/kit/scc/webreg/ssh/OpenSshKeyDecoder.java
View file @
dd8b4457
...
...
@@ -25,10 +25,10 @@ public class OpenSshKeyDecoder implements Serializable {
private
static
final
long
serialVersionUID
=
1L
;
public
OpenSshPublicKey
decode
(
String
opensshPublicKey
)
{
public
OpenSshPublicKey
decode
(
String
opensshPublicKey
)
throws
UnsupportedKeyTypeException
{
OpenSshPublicKey
key
=
new
OpenSshPublicKey
();
key
.
setBytes
(
getKeyBytes
(
opensshPublicKey
)
)
;
getKeyBytes
(
key
,
opensshPublicKey
);
try
{
String
type
=
decodeType
(
key
);
...
...
@@ -54,21 +54,23 @@ public class OpenSshKeyDecoder implements Serializable {
ECPublicKeySpec
spec
=
new
ECPublicKeySpec
(
ecPoint
,
ecParameterSpec
);
key
.
setPublicKey
(
KeyFactory
.
getInstance
(
"EC"
).
generatePublic
(
spec
));
}
else
{
throw
new
IllegalArgumentException
(
"Unsupported key type
"
+
type
);
key
.
setDecoderResult
(
"Unsupported key type
"
);
}
return
key
;
}
catch
(
NoSuchAlgorithmException
|
InvalidKeySpecException
e
)
{
throw
new
IllegalArgumentException
(
"Unable to decode public key"
,
e
);
key
.
setDecoderResult
(
"Unable to decode public key"
);
return
key
;
}
}
private
byte
[]
getKeyBytes
(
String
opensshPublicKey
)
{
private
void
getKeyBytes
(
OpenSshPublicKey
key
,
String
opensshPublicKey
)
throws
UnsupportedKeyTypeException
{
for
(
String
part
:
opensshPublicKey
.
split
(
" "
))
{
if
(
Base64
.
isBase64
(
part
)
&&
part
.
startsWith
(
"AAAA"
))
{
return
Base64
.
decodeBase64
(
part
);
key
.
setBaseDate
(
part
);
key
.
setBytes
(
Base64
.
decodeBase64
(
part
));
}
}
throw
new
IllegalArgument
Exception
(
"no Base64 part to decode"
);
throw
new
UnsupportedKeyType
Exception
(
"no Base64 part to decode"
);
}
private
String
decodeType
(
OpenSshPublicKey
key
)
{
...
...
@@ -104,7 +106,7 @@ public class OpenSshKeyDecoder implements Serializable {
return
new
ECPoint
(
x
,
y
);
}
ECParameterSpec
getECParameterSpec
(
String
identifier
)
{
ECParameterSpec
getECParameterSpec
(
String
identifier
)
throws
UnsupportedKeyTypeException
{
try
{
// http://www.bouncycastle.org/wiki/pages/viewpage.action?pageId=362269#SupportedCurves(ECDSAandECGOST)-NIST(aliasesforSECcurves)
String
name
=
identifier
.
replace
(
"nist"
,
"sec"
)
+
"r1"
;
...
...
@@ -112,7 +114,7 @@ public class OpenSshKeyDecoder implements Serializable {
parameters
.
init
(
new
ECGenParameterSpec
(
name
));
return
parameters
.
getParameterSpec
(
ECParameterSpec
.
class
);
}
catch
(
InvalidParameterSpecException
|
NoSuchAlgorithmException
e
)
{
throw
new
IllegalArgument
Exception
(
"Unable to get parameter spec for identifier "
+
identifier
,
e
);
throw
new
UnsupportedKeyType
Exception
(
"Unable to get parameter spec for identifier "
+
identifier
,
e
);
}
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/ssh/OpenSshPublicKey.java
View file @
dd8b4457
...
...
@@ -7,6 +7,8 @@ public class OpenSshPublicKey {
private
byte
[]
bytes
;
private
int
decoderPos
;
private
PublicKey
publicKey
;
private
String
baseDate
;
private
String
decoderResult
;
public
OpenSshPublicKey
()
{
super
();
...
...
@@ -40,4 +42,20 @@ public class OpenSshPublicKey {
public
void
setPublicKey
(
PublicKey
publicKey
)
{
this
.
publicKey
=
publicKey
;
}
public
String
getBaseDate
()
{
return
baseDate
;
}
public
void
setBaseDate
(
String
baseDate
)
{
this
.
baseDate
=
baseDate
;
}
public
String
getDecoderResult
()
{
return
decoderResult
;
}
public
void
setDecoderResult
(
String
decoderResult
)
{
this
.
decoderResult
=
decoderResult
;
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/ssh/UnsupportedKeyTypeException.java
0 → 100644
View file @
dd8b4457
package
edu.kit.scc.webreg.ssh
;
public
class
UnsupportedKeyTypeException
extends
Exception
{
private
static
final
long
serialVersionUID
=
1L
;
public
UnsupportedKeyTypeException
()
{
super
();
}
public
UnsupportedKeyTypeException
(
String
arg0
,
Throwable
arg1
)
{
super
(
arg0
,
arg1
);
}
public
UnsupportedKeyTypeException
(
String
arg0
)
{
super
(
arg0
);
}
public
UnsupportedKeyTypeException
(
Throwable
arg0
)
{
super
(
arg0
);
}
}
bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/UserSshKeyManagementBean.java
View file @
dd8b4457
...
...
@@ -24,6 +24,7 @@ import edu.kit.scc.webreg.service.UserService;
import
edu.kit.scc.webreg.session.SessionManager
;
import
edu.kit.scc.webreg.ssh.OpenSshKeyDecoder
;
import
edu.kit.scc.webreg.ssh.OpenSshPublicKey
;
import
edu.kit.scc.webreg.ssh.UnsupportedKeyTypeException
;
@ManagedBean
@ViewScoped
...
...
@@ -53,8 +54,13 @@ public class UserSshKeyManagementBean implements Serializable {
}
public
void
deployKey
()
{
OpenSshPublicKey
key
=
keyDecoder
.
decode
(
newKey
);
keyList
.
add
(
key
);
OpenSshPublicKey
key
;
try
{
key
=
keyDecoder
.
decode
(
newKey
);
keyList
.
add
(
key
);
}
catch
(
UnsupportedKeyTypeException
e
)
{
// happenes when there is not base64 part in key
}
}
public
UserEntity
getUser
()
{
...
...
Write
Preview
Markdown
is supported
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