Beispiel #1
0
  public ResponseEntity<?> addFriend(Long userId, Long friendId)
      throws InvalidKeyException, NoSuchAlgorithmException, SignatureException, Exception {

    KeyPair friendKeyPair = serviceKeyPair.findOne(friendId);
    String signature = serviceSession.sign(friendKeyPair.getPubkey());

    Friendship friendship = new Friendship();
    friendship.setSignature(signature);
    friendship.setFriendId(friendId);

    HttpEntity<Friendship> toPost = new HttpEntity<Friendship>(friendship, client.getHeaders());
    return client
        .getRestTemplate()
        .postForObject(
            "http://localhost:8080/api/" + userId + "/friends", toPost, ResponseEntity.class);
  }
Beispiel #2
0
  public ResponseEntity<?> addUserToGroup(Long userId, Long friendId, Long groupId)
      throws Exception {
    KeyPair friendKeyPair = serviceKeyPair.findOne(friendId);
    KeySym groupKey = clientKeySym.findGroupKeySym(groupId);

    String dec_groupSecretKey = serviceSession.decryptWithCurrentUserPK(groupKey.getSymkey());
    RSACrypto rsa = new RSACrypto();
    String enc_groupSecretKey = rsa.encrypt(friendKeyPair.getPubkey(), dec_groupSecretKey);
    groupKey.setSymkey(enc_groupSecretKey);

    HttpEntity<KeySym> toPost = new HttpEntity<KeySym>(groupKey, client.getHeaders());
    return client
        .getRestTemplate()
        .postForObject(
            "http://localhost:8080/api/xx/" + groupId + "/users/" + friendId,
            toPost,
            ResponseEntity.class);
  }