-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly determine KeyType for ECDSA public key (Fixes #356)
- Loading branch information
1 parent
0918bc6
commit c6c9a3f
Showing
4 changed files
with
67 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/groovy/com/hierynomus/sshj/common/KeyTypeSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.hierynomus.sshj.common | ||
|
||
import net.schmizz.sshj.common.KeyType | ||
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class KeyTypeSpec extends Specification { | ||
|
||
@Unroll | ||
def "should determine correct keytype for #type key"() { | ||
given: | ||
OpenSSHKeyFile kf = new OpenSSHKeyFile() | ||
kf.init(privKey, pubKey) | ||
|
||
expect: | ||
KeyType.fromKey(kf.getPublic()) == type | ||
KeyType.fromKey(kf.getPrivate()) == type | ||
|
||
where: | ||
privKey << ["""-----BEGIN EC PRIVATE KEY----- | ||
MHcCAQEEIGhcvG8anyHew/xZJfozh5XIc1kmZZs6o2f0l3KFs4jgoAoGCCqGSM49 | ||
AwEHoUQDQgAEDUA1JYVD7URSoOGdwPxjea+ETD6IABMD9CWfk3NVTNkdu/Ksn7uX | ||
cLTQhx4N16z1IgW2bRbSbsmM++UKXmeWyg== | ||
-----END EC PRIVATE KEY-----"""] | ||
pubKey << ["""ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBA1ANSWFQ+1EUqDhncD8Y3mvhEw+iAATA/Qln5NzVUzZHbvyrJ+7l3C00IceDdes9SIFtm0W0m7JjPvlCl5nlso= SSH Key"""] | ||
type << [KeyType.ECDSA256] | ||
|
||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/groovy/net/schmizz/sshj/userauth/password/ConsolePasswordFinderSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.schmizz.sshj.userauth.password | ||
|
||
import spock.lang.Specification | ||
|
||
class ConsolePasswordFinderSpec extends Specification { | ||
|
||
def "should read password from console"() { | ||
given: | ||
def console = Mock(Console) { | ||
readPassword(*_) >> "password".toCharArray() | ||
} | ||
def cpf = new ConsolePasswordFinder(console) | ||
def resource = new AccountResource("test", "localhost") | ||
|
||
when: | ||
def password = cpf.reqPassword(resource) | ||
|
||
then: | ||
password == "password".toCharArray() | ||
|
||
} | ||
} |