Search in sources :

Example 1 with NotFoundException

use of com.google.nigori.common.NotFoundException 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 2 with NotFoundException

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

the class CryptoNigoriDatastore method getRevisions.

@Override
public List<Revision> getRevisions(Index index) throws NigoriCryptographyException, UnsupportedEncodingException, IOException, UnauthorisedException {
    byte[] encIndex = keyManager.encryptDeterministically(index.getBytes());
    try {
        GetRevisionsResponse getResponse = protocol.getRevisions(MessageLibrary.getRevisionsRequestAsProtobuf(keyManager.getServerName(), keyManager.signer(), encIndex));
        if (getResponse == null) {
            return null;
        }
        List<ByteString> revisions = getResponse.getRevisionsList();
        List<Revision> answer = new ArrayList<Revision>(revisions.size());
        for (ByteString revision : revisions) {
            answer.add(new Revision(keyManager.decrypt(revision.toByteArray())));
        }
        return answer;
    } catch (NotFoundException e) {
        return null;
    }
}
Also used : Revision(com.google.nigori.common.Revision) GetRevisionsResponse(com.google.nigori.common.NigoriMessages.GetRevisionsResponse) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) NotFoundException(com.google.nigori.common.NotFoundException)

Example 3 with NotFoundException

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

the class CryptoNigoriDatastore method get.

/**
 * Retrieve the value associated with {@code index} on the server.
 *
 * @param index
 * @param revision
 * @return a list of RevValues containing the data associated with {@code index} or {@code null}
 *         if no data exists. WARNING: there is no assurance that the value for the revision is a
 *         pair once specified by a valid client - the server can pair any value with any
 *         revision.
 */
private List<RevValue> get(byte[] encKey, Index index, Revision revision) throws IOException, NigoriCryptographyException, UnauthorisedException {
    byte[] encIndex;
    byte[] encRevision = null;
    if (encKey == null) {
        encIndex = keyManager.encryptDeterministically(index.getBytes());
        if (revision != null) {
            encRevision = keyManager.encryptDeterministically(revision.getBytes());
        }
    } else {
        encIndex = keyManager.encryptDeterministically(encKey, index.getBytes());
        if (revision != null) {
            encRevision = keyManager.encryptDeterministically(encKey, revision.getBytes());
        }
    }
    try {
        GetResponse getResponse = protocol.get(MessageLibrary.getRequestAsProtobuf(keyManager.getServerName(), keyManager.signer(), encIndex, encRevision));
        if (getResponse == null) {
            return null;
        }
        List<RevisionValue> revisions = getResponse.getRevisionsList();
        List<RevValue> answer = new ArrayList<RevValue>(revisions.size());
        for (RevisionValue revisionValue : revisions) {
            byte[] revisionciphertext = revisionValue.getRevision().toByteArray();
            byte[] valueciphertext = revisionValue.getValue().toByteArray();
            if (encKey == null) {
                answer.add(new RevValue(keyManager.decrypt(revisionciphertext), keyManager.decrypt(valueciphertext)));
            } else {
                answer.add(new RevValue(keyManager.decrypt(encKey, revisionciphertext), keyManager.decrypt(encKey, valueciphertext)));
            }
        }
        return answer;
    } catch (NotFoundException e) {
        return null;
    }
}
Also used : RevisionValue(com.google.nigori.common.NigoriMessages.RevisionValue) RevValue(com.google.nigori.common.RevValue) ArrayList(java.util.ArrayList) NotFoundException(com.google.nigori.common.NotFoundException) GetResponse(com.google.nigori.common.NigoriMessages.GetResponse)

Example 4 with NotFoundException

use of com.google.nigori.common.NotFoundException 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)

Example 5 with NotFoundException

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

the class DatabaseNigoriProtocol method getRevisions.

@Override
public GetRevisionsResponse getRevisions(GetRevisionsRequest request) throws IOException, NotFoundException, UnauthorisedException {
    byte[] index = request.getKey().toByteArray();
    AuthenticateRequest auth = request.getAuth();
    User user = authenticateUser(auth, MessageLibrary.REQUEST_GET_REVISIONS, index);
    Collection<byte[]> value = database.getRevisions(user, index);
    if (value == null) {
        throw new NotFoundException("Cannot find requested key");
    }
    return MessageLibrary.getRevisionsResponseAsProtobuf(value);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) NotFoundException(com.google.nigori.common.NotFoundException)

Aggregations

NotFoundException (com.google.nigori.common.NotFoundException)7 AuthenticateRequest (com.google.nigori.common.NigoriMessages.AuthenticateRequest)4 ArrayList (java.util.ArrayList)3 RevValue (com.google.nigori.common.RevValue)2 ByteString (com.google.protobuf.ByteString)2 Index (com.google.nigori.common.Index)1 GetIndicesResponse (com.google.nigori.common.NigoriMessages.GetIndicesResponse)1 GetResponse (com.google.nigori.common.NigoriMessages.GetResponse)1 GetRevisionsResponse (com.google.nigori.common.NigoriMessages.GetRevisionsResponse)1 RevisionValue (com.google.nigori.common.NigoriMessages.RevisionValue)1 Revision (com.google.nigori.common.Revision)1