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);
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations