public boolean getPublicKey(String hostName) {

        HexString hex = new HexString();

        try {
            // send the message to the server:
            Message m = new Message(hostName, ServerAction.GET_KEY, null, messageCounter++);
            output.writeObject(m);

            // get a message back, report any errors:
            m = (Message) input.readObject();
            if (!m.success) {
                System.out.println(m.message);
                return false;
            }

            // re-build the public key from the byte[] stored in the message:
            Token t = (Token) m.token;
            KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
            PublicKey publicKey = kf.generatePublic(new X509EncodedKeySpec(t.getSignature()));
            GroupServerRecord record = new GroupServerRecord(hostName, publicKey);

            // check if we recognize this server and key:
            if (!securityManager.isKnownGroupServer(record)) {


                // TODO: Here we should send an encrypted challenge to the
                // GroupServer before even asking if the user wants to
                // accept:
                

                // ask if the user trusts the finger print of the
                // of the received public key:
                System.out.println(String.format(
                        "\nThe public key of host '%s' does not match current records.", hostName));

                String s = hex.toHexFingerprint(SecurityManager.digest(publicKey.getEncoded()));
                System.out.println(String.format("The RSA key fingerprint is\n %s", s));
                System.out.print("Do you want to accept this key and continue (y/n)? ");
                s = new Scanner(System.in).next();
                if (s.equalsIgnoreCase("y") || s.equalsIgnoreCase("yes")) {
                    securityManager.setGroupKey(hostName, publicKey);
                } else {
                    // fail if the user does not trust this key:
                    return false;
                }
            }

            // this code runs if we trust the server:
            // generate client's random number
            byte[] serverKeyPart = hex.toByteArray(m.message);
            byte[] clientKeyPart = securityManager.getRandom(32);
            securityManager.setGroupSessionKey(serverKeyPart, clientKeyPart);

            // encrypt this with the public RSA key of the file Server!
            clientKeyPart = securityManager.encrypSessionKey(clientKeyPart, true);

            // send client's random number:
            m.message = hex.toHexString(clientKeyPart);
            output.writeObject(m);

            // get a message back, report any errors:
            m = securityManager.decryptMessage((SealedObject)input.readObject());
            if (!m.success) {
                System.out.println(m.message);
                return false;
            }

        } catch (Exception e) {
            System.err.println("here: " + e);
            e.printStackTrace();
            return false;
        }

        return true;
    }