Search in sources :

Example 1 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method put.

@Override
public boolean put(PutRequest request) throws IOException, UnauthorisedException {
    AuthenticateRequest auth = request.getAuth();
    byte[] index = request.getKey().toByteArray();
    byte[] revision = request.getRevision().toByteArray();
    byte[] value = request.getValue().toByteArray();
    User user = authenticateUser(auth, MessageLibrary.REQUEST_PUT, index, revision, value);
    return database.putRecord(user, index, revision, value);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest)

Example 2 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method getIndices.

@Override
public GetIndicesResponse getIndices(GetIndicesRequest request) throws IOException, NotFoundException, UnauthorisedException {
    AuthenticateRequest auth = request.getAuth();
    User user = authenticateUser(auth, MessageLibrary.REQUEST_GET_INDICES);
    Collection<byte[]> value = database.getIndices(user);
    if (value == null) {
        throw new NotFoundException("Cannot find indices");
    }
    return MessageLibrary.getIndicesResponseAsProtobuf(value);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) NotFoundException(com.google.nigori.common.NotFoundException)

Example 3 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class MessageLibrary method authenticateRequestAsProtobuf.

protected static AuthenticateRequest authenticateRequestAsProtobuf(String serverName, DSASign signer, String command, byte[]... payload) throws NigoriCryptographyException {
    try {
        Nonce nonce = new Nonce();
        DSASignature signedNonce = signer.sign(Util.joinBytes(MessageLibrary.toBytes(serverName), nonce.nt(), nonce.nr(), toBytes(command), Util.joinBytes(payload)));
        byte[] sig = Util.joinBytes(signedNonce.getR(), signedNonce.getS());
        AuthenticateRequest req = AuthenticateRequest.newBuilder().setPublicKey(ByteString.copyFrom(signer.getPublicHash())).setSig(ByteString.copyFrom(sig)).setNonce(ByteString.copyFrom(nonce.toToken())).setServerName(serverName).build();
        return req;
    } catch (NoSuchAlgorithmException e) {
        throw new NigoriCryptographyException("Platform does have required crypto support:" + e.getMessage());
    }
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method unregister.

@Override
public boolean unregister(UnregisterRequest request) throws IOException, UnauthorisedException {
    AuthenticateRequest auth = request.getAuth();
    User user = authenticateUser(auth, MessageLibrary.REQUEST_UNREGISTER);
    return database.deleteUser(user);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest)

Example 5 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method delete.

@Override
public boolean delete(DeleteRequest request) throws IOException, NotFoundException, UnauthorisedException {
    AuthenticateRequest auth = request.getAuth();
    byte[] index = request.getKey().toByteArray();
    User user = authenticateUser(auth, MessageLibrary.REQUEST_DELETE, index);
    boolean exists = database.getRecord(user, index) != null;
    if (!exists) {
        throw new NotFoundException("No such index: " + Base64.encodeBase64(request.getKey().toByteArray()));
    }
    return database.deleteRecord(user, index);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) NotFoundException(com.google.nigori.common.NotFoundException)

Aggregations

AuthenticateRequest (com.google.nigori.common.NigoriMessages.AuthenticateRequest)7 NotFoundException (com.google.nigori.common.NotFoundException)4 RevValue (com.google.nigori.common.RevValue)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1