Package org.xulfactory.gliese.algo

Examples of org.xulfactory.gliese.algo.SSHRSAPublicKey$SSHRSAPublicKeyFactory


    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(1024);
    KeyPair kp = kpg.generateKeyPair();
    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(kp.getPrivate());
    final SSHPublicKey pkey = new SSHRSAPublicKey(
        ((RSAPublicKey)kp.getPublic()).getModulus(),
        ((RSAPublicKey)kp.getPublic()).getPublicExponent());
    UserAuthFailureMessage uafm = new UserAuthFailureMessage();
    when(transport.readMessage("publickey")).thenReturn(uafm);
    when(transport.getSessionId()).thenReturn(new byte[20]);
    // When
    AuthenticationResult res = authMgr.authenticate("user", pkey, signature);
    // Then
    InOrder inorder = inOrder(transport);
    inorder.verify(transport, times(1)).writeMessage(any(SSHMessage.class));
    inorder.verify(transport, times(1)).writeMessage(argThat(new ArgumentMatcher<SSHMessage>() {
      @Override
      public boolean matches(Object arg)
      {
        UserAuthRequestMessage msg = (UserAuthRequestMessage)arg;
        assertTrue(msg.getAuthenticationData() instanceof PublicKeyMethodData);
        assertEquals("publickey", msg.getMethod());
        PublicKeyMethodData md = (PublicKeyMethodData)msg.getAuthenticationData();
        assertEquals("ssh-rsa", md.getAlgorithm());
        assertArrayEquals(pkey.encode(), md.getPubkey());
        return true;
      }
    }));
    assertFalse("Authentication should not succeed", res.isSuccess());   
  }
View Full Code Here


    kpg.initialize(1024);
    KeyPair kp = kpg.generateKeyPair();
    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(kp.getPrivate());
    final PublicKey publickey = kp.getPublic();
    final SSHPublicKey pkey = new SSHRSAPublicKey(
        ((RSAPublicKey)kp.getPublic()).getModulus(),
        ((RSAPublicKey)kp.getPublic()).getPublicExponent());
    UserAuthPublicKeyOk uapkok = new UserAuthPublicKeyOk();
    uapkok.setAlgorithm("ssh-rsa");
    uapkok.setPubkey(pkey.encode());
    UserAuthSuccessMessage uasm = new UserAuthSuccessMessage();
    when(transport.readMessage("publickey")).thenReturn(uapkok).thenReturn(uasm);
    when(transport.getSessionId()).thenReturn(new byte[20]);
    // When
    AuthenticationResult res = authMgr.authenticate("user", pkey, signature);
    // Then
    InOrder inorder = inOrder(transport);
    inorder.verify(transport, times(1)).writeMessage(any(SSHMessage.class));
    inorder.verify(transport, times(1)).writeMessage(any(SSHMessage.class));
    inorder.verify(transport, times(1)).writeMessage(argThat(new ArgumentMatcher<SSHMessage>() {
      @Override
      public boolean matches(Object arg)
      {
        UserAuthRequestMessage msg = (UserAuthRequestMessage)arg;
        assertTrue(msg.getAuthenticationData() instanceof PublicKeyMethodData);
        assertEquals("publickey", msg.getMethod());
        PublicKeyMethodData md = (PublicKeyMethodData)msg.getAuthenticationData();
        assertEquals("ssh-rsa", md.getAlgorithm());
        assertArrayEquals(pkey.encode(), md.getPubkey());
        assertNotNull(md.getSignature());
        try {
          Signature verify = Signature.getInstance("SHA1withRSA");
          verify.initVerify(publickey);
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          Utils.encodeBytes(out, new byte[20]);
          out.write((byte)50);
          Utils.encodeString(out, "user");
          Utils.encodeString(out, "ssh-connection");
          Utils.encodeString(out, "publickey");
          Utils.encodeBoolean(out, true);
          Utils.encodeString(out, "ssh-rsa");
          Utils.encodeBytes(out, pkey.encode());
          verify.update(out.toByteArray());
          assertTrue("Signature should be verified", verify.verify(md.getSignature()));
        } catch (InvalidKeyException ike) {
          fail(ike.getMessage());
        } catch (NoSuchAlgorithmException nsae) {
View Full Code Here

TOP

Related Classes of org.xulfactory.gliese.algo.SSHRSAPublicKey$SSHRSAPublicKeyFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.