Java Code Examples for net.schmizz.sshj.common.SecurityUtils

The following examples show how to use net.schmizz.sshj.common.SecurityUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: roboconf-platform   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void testVerify() throws Exception {

	// Setup
	final String ip1 = "ip1";
	final String ip2 = "ip2";

	Map<String,String> targetProperties = new HashMap<> ();
	FingerPrintVerifier verifier = new FingerPrintVerifier( targetProperties );

	// Find finger prints to use in the tests
	KeyPairGenerator keyGen = KeyPairGenerator.getInstance( "RSA" );
	PublicKey publicKey1 = keyGen.generateKeyPair().getPublic();
	PublicKey publicKey2 = keyGen.generateKeyPair().getPublic();
	PublicKey publicKey3 = keyGen.generateKeyPair().getPublic();
	Assert.assertNotEquals( publicKey1, publicKey2 );
	Assert.assertNotEquals( publicKey3, publicKey2 );
	Assert.assertNotEquals( publicKey3, publicKey1 );

	targetProperties.put( EmbeddedHandler.SCP_HOST_KEY_PREFIX + ip1, SecurityUtils.getFingerprint( publicKey1 ));
	targetProperties.put( EmbeddedHandler.SCP_HOST_KEY_PREFIX + ip2, SecurityUtils.getFingerprint( publicKey2 ));

	// Check
	Assert.assertTrue( verifier.verify( ip1, 22, publicKey1 ));
	Assert.assertTrue( verifier.verify( ip2, 22, publicKey2 ));

	Assert.assertFalse( verifier.verify( ip1, 22, publicKey2 ));
	Assert.assertFalse( verifier.verify( ip2, 2215, publicKey3 ));
Example 2
Source Project: datacollector   Source File:    License: Apache License 2.0 4 votes vote down vote up
protected String getPublicKeyFingerprint() {
  return SecurityUtils.getFingerprint(sshdHostKeyPair.getPublic());
Example 3
Source Project: roboconf-platform   Source File:    License: Apache License 2.0 4 votes vote down vote up
public boolean verify( String hostname, int port, PublicKey key ) {
	String expectedFingerPrint = this.targetProperties.get( EmbeddedHandler.SCP_HOST_KEY_PREFIX + hostname );
	String fingerPrint = SecurityUtils.getFingerprint( key );
	return Objects.equals( expectedFingerPrint, fingerPrint );