Skip to content

Commit

Permalink
merge v2.1.0 (#36)
Browse files Browse the repository at this point in the history
* begin v2.1.0 dev

Signed-off-by: Edi Permadi <[email protected]>

* deny adding the same path to container twice (closes #33)

Signed-off-by: Edi Permadi <[email protected]>

* change exception message

Signed-off-by: Edi Permadi <[email protected]>

* ensure no certificate added twice. closes #34

Signed-off-by: Edi Permadi <[email protected]>

* update doc

Signed-off-by: Edi Permadi <[email protected]>

* update doc

Signed-off-by: Edi Permadi <[email protected]>

* added tag creation feature, closes #16

Signed-off-by: Edi Permadi <[email protected]>

* update doc

Signed-off-by: Edi Permadi <[email protected]>

* assign tag to blob. closes #18

Signed-off-by: Edi Permadi <[email protected]>

* get tag value by tag uuid. closes #35

Signed-off-by: Edi Permadi <[email protected]>

* rename BlobPool functions

Signed-off-by: Edi Permadi <[email protected]>

* added remove tag from blob feature. close #19

Signed-off-by: Edi Permadi <[email protected]>

* added feature to update tag. close #20

Signed-off-by: Edi Permadi <[email protected]>

* added feature to remove tag. close #17

Signed-off-by: Edi Permadi <[email protected]>

* bump to v2.1.0

Signed-off-by: Edi Permadi <[email protected]>
  • Loading branch information
edipermadi authored Oct 18, 2017
1 parent 60c96dd commit 047f6db
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 42 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# Blobfish Changelog

## v2.1.0 [October 19, 2017]

**Bugfix**

- Fixed duplicated blob path
- Fixed duplicated recipient certificate

**New Features**

- Create tag
- Remove tag
- Get tag value by `tag-uuid`
- Update tag by `tag-uuid`
- Add tag to blob by `blob-uuid` and `tag-uuid`
- Remove tag from blob by `blob-uuid` and `tag-uuid`

## v2.0.0 [October 17, 2017]

**New Features**

- Create `BlobPool` from existing blobfish container
- List blobs within `BlobPool`
- List tags within `BlobPool`
- List associated to a blob
- List tags associated to a blob

## v1.1.0 [October 4, 2017]

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ An ugly blob container based on protobuf. The project is meant to be an educatio
- [x] List blob by tags
- [x] List blob by partial/full path
- [ ] BlobPool, a mutable intermediate container
- [ ] Import from blobfish container
- [x] Import from blobfish container
- [ ] Export to blobfish container
- [ ] Recipient CRUD access
- [ ] Bob CRUD access
- [ ] Blob CRUD access

## Blobfish Random Facts
- [The Ugliest Animal](https://www.theguardian.com/environment/2013/sep/12/blobfish-world-ugliest-animal)
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.edipermadi.security</groupId>
<artifactId>blobfish</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -65,6 +65,12 @@
<version>1.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class ContainerEncoderBase extends ContainerBase {
protected final PrivateKey signingPrivateKey;
protected final int version;
private final boolean compressed;
protected Set<String> paths = new HashSet<>();

/**
* Class constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class ContainerEncoderBuilder {
*/
public ContainerEncoderBuilder setVersion(final int version) {
if (version < 1) {
throw new IllegalArgumentException("illegal version number");
throw new IllegalArgumentException("invalid version number");
}
this.version = version;
return this;
Expand All @@ -45,7 +45,7 @@ public ContainerEncoderBuilder setVersion(final int version) {
*/
public ContainerEncoderBuilder setSigningCertificate(final X509Certificate signingCertificate) {
if ((signingCertificate == null) || (!"EC".equals(signingCertificate.getPublicKey().getAlgorithm()))) {
throw new IllegalArgumentException("illegal signing certificate");
throw new IllegalArgumentException("invalid signing certificate");
}

this.signingCertificate = signingCertificate;
Expand All @@ -54,7 +54,7 @@ public ContainerEncoderBuilder setSigningCertificate(final X509Certificate signi

public ContainerEncoderBuilder setSigningKey(final PrivateKey signingPrivateKey) {
if ((signingPrivateKey == null) || (!"EC".equals(signingPrivateKey.getAlgorithm()))) {
throw new IllegalArgumentException("illegal signing certificate");
throw new IllegalArgumentException("invalid signing certificate");
}

this.signingPrivateKey = signingPrivateKey;
Expand All @@ -69,7 +69,7 @@ public ContainerEncoderBuilder setSigningKey(final PrivateKey signingPrivateKey)
*/
public ContainerEncoderBuilder setPassword(final String password) {
if ((password == null) || password.trim().isEmpty()) {
throw new IllegalArgumentException("illegal password");
throw new IllegalArgumentException("invalid password");
}
this.password = password.toCharArray();
return this;
Expand All @@ -84,7 +84,9 @@ public ContainerEncoderBuilder setPassword(final String password) {
*/
public ContainerEncoderBuilder addRecipientCertificate(final X509Certificate certificate) {
if ((certificate == null) || (!"RSA".equals(certificate.getPublicKey().getAlgorithm()))) {
throw new IllegalArgumentException("illegal signing certificate");
throw new IllegalArgumentException("invalid signing certificate");
} else if (recipientCertificates.contains(certificate)) {
throw new IllegalArgumentException("recipient already exist");
}

this.recipientCertificates.add(certificate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.github.edipermadi.security.blobfish.codec;

import com.github.edipermadi.security.blobfish.exc.BlobfishCryptoException;
import com.github.edipermadi.security.blobfish.exc.BlobfishEncodeException;
import com.github.edipermadi.security.blobfish.exc.KeyDerivationException;
import com.github.edipermadi.security.blobfish.exc.SignCalculationException;
import com.github.edipermadi.security.blobfish.exc.*;
import com.github.edipermadi.security.blobfish.generated.BlobfishProto;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedOutputStream;
Expand All @@ -15,7 +12,10 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.SignatureException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Set;
Expand Down Expand Up @@ -99,13 +99,15 @@ class ContainerEncoderV1 extends ContainerEncoderBase implements ContainerEncode
public ContainerEncoderV1 addBlob(final String path, final Set<String> tags, final String mimeType,
final InputStream inputStream) throws BlobfishCryptoException, BlobfishEncodeException, IOException {
if ((path == null) || path.isEmpty() || path.endsWith("/") || !path.startsWith("/")) {
throw new IllegalArgumentException("illegal path");
throw new IllegalArgumentException("invalid path");
} else if (tags == null) {
throw new IllegalArgumentException("tags is null");
} else if ((mimeType == null) || mimeType.isEmpty()) {
throw new IllegalArgumentException("mimetype is null/empty");
} else if (inputStream == null) {
throw new IllegalArgumentException("input-stream is null/empty");
} else if (paths.contains(path)) {
throw new BlobAlreadyExistException();
}

/* encode metadata and payload */
Expand All @@ -126,6 +128,7 @@ public ContainerEncoderV1 addBlob(final String path, final Set<String> tags, fin
.setPayload(payload)
.build();
bodyBuilder.addBlob(blob);
paths.add(path);
} catch (final IOException ex) {
throw new BlobfishEncodeException("failed to encode blob", ex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.edipermadi.security.blobfish.exc;

/**
* An exception denoting a particular path is already associated to a blob
*
* @author Edi Permadi
*/
public final class BlobAlreadyExistException extends BlobfishEncodeException {

/**
* Class constructor
*/
public BlobAlreadyExistException() {
super("blob already exist");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ public interface BlobPool {
void importPayload(InputStream inputStream, final X509Certificate certificate, final PrivateKey privateKey) throws BlobfishDecodeException, BlobfishCryptoException, IOException, CertificateException, SQLException;

/**
* List tags
* List available tags
*
* @param page number starts from 1
* @param size page size at least 1
* @return map of tag id and string
* @throws SQLException when reading tags failed
*/
Map<UUID, String> listTags(int page, int size) throws SQLException;
Map<UUID, String> listAvailableTags(int page, int size) throws SQLException;

/**
* List blobs
* List available blobs
*
* @param page number starts from 1
* @param size page size at least 1
* @return map of blob uuid and corresponding metadata
* @throws SQLException when reading blob failed
*/
Map<UUID, Blob.SimplifiedMetadata> listBlobs(int page, int size) throws SQLException;
Map<UUID, Blob.SimplifiedMetadata> listAvailableBlobs(int page, int size) throws SQLException;

/**
* Get tags of a particular blob
Expand All @@ -74,7 +74,63 @@ public interface BlobPool {
* @return set of tags
* @throws SQLException when reading tags failed
*/
Set<String> getTags(UUID blobId) throws SQLException;
Set<String> getBlobTags(UUID blobId) throws SQLException;

/**
* Create a new tag
*
* @param tag new tag to be created
* @return UUID of new or existing tag
* @throws SQLException when inserting tag failed
*/
UUID createTag(String tag) throws SQLException;

/**
* Get tag value by tag uuid
*
* @param tagId tag identifier
* @return tag value
* @throws SQLException when fetching tag value failed
*/
String getTag(UUID tagId) throws SQLException;

/**
* Remove a tag
*
* @param tagId tag identifier
* @param tag new value of tag
* @return true when updated successfully
* @throws SQLException when updating tag failed
*/
boolean updateTag(UUID tagId, String tag) throws SQLException;

/**
* Remove a tag
* @param tagId tag identifier
* @return true when tag deleted successfully
* @throws SQLException when updating tag failed
*/
boolean removeTag(UUID tagId) throws SQLException;

/**
* Add tag to a blob
*
* @param blobId blob identifier
* @param tagId tag identifier
* @return true when added successfully
* @throws SQLException when assigning tag failed
*/
boolean addTagToBlob(UUID blobId, UUID tagId) throws SQLException;

/**
* Remove tag from a blob
*
* @param blobId blob identifier
* @param tagId tag identifier
* @return true when removed successfully
* @throws SQLException when de-assigning tag failed
*/
boolean removeTagFromBlob(UUID blobId, UUID tagId) throws SQLException;

/**
* Get blob payload
Expand All @@ -84,5 +140,5 @@ public interface BlobPool {
* @throws SQLException when reading payload failed
* @throws IOException when reading blob payload failed
*/
byte[] getPayload(UUID blobId) throws SQLException, IOException;
byte[] getBlobPayload(UUID blobId) throws SQLException, IOException;
}
Loading

0 comments on commit 047f6db

Please sign in to comment.