Package org.xulfactory.gliese.message

Examples of org.xulfactory.gliese.message.PublicKeyMethodData


    @Override
    public SSHMessage interact(SSHMessage lastMessage) throws SSHException
    {
      if (lastMessage == null) {
        UserAuthRequestMessage msg = initUserAuthRequestMessage();
        PublicKeyMethodData md = new PublicKeyMethodData(key.getName(), key.encode());
        msg.setAuthenticationData(md);
        return msg;
      } else if (lastMessage.getID() == UserAuthPublicKeyOk.ID) {
        UserAuthRequestMessage msg = initUserAuthRequestMessage();
        PublicKeyMethodData md = new PublicKeyMethodData(key.getName(), key.encode());
        md.prepareTBS();
        msg.setAuthenticationData(md);
        byte[] sig = null;
        try {
          signer.update(Utils.encodeBytes(transport.getSessionId()));
          signer.update(msg.getEncoding());
          sig = signer.sign();
        } catch (SignatureException e) {
          throw new SSHException("Signature failed", e);
        }
        md = new PublicKeyMethodData(key.getName(), key.encode());
        md.setSignature(sig);
        msg.setAuthenticationData(md);
        return msg;
      }
      throw new UnsupportedOperationException("Not supported yet.");
    }
View Full Code Here


      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

      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) {
          fail(nsae.getMessage());
        } catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of org.xulfactory.gliese.message.PublicKeyMethodData

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.