DDI supports sha256 (#869)

* Add SHA256 file hash to ddi GET outputs

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Integrate review findings for SHA256 changes

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Renamed hashes to base16hases in store() parameters

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Added missing javadoc according to sonarqube findings

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>
This commit is contained in:
Alexander Dobler
2019-07-29 14:11:40 +02:00
committed by Dominic Schabel
parent fba6cf9787
commit bde3548846
20 changed files with 131 additions and 53 deletions

View File

@@ -38,6 +38,11 @@ public interface Artifact extends TenantAwareBaseEntity {
*/
String getSha1Hash();
/**
* @return SHA-256 hash of the artifact.
*/
String getSha256Hash();
/**
* @return size of the artifact in bytes.
*/

View File

@@ -35,6 +35,8 @@ public class ArtifactUpload {
private final String providedSha1Sum;
private final String providedSha256Sum;
private final boolean overrideExisting;
private final String contentType;
@@ -90,6 +92,7 @@ public class ArtifactUpload {
this.filename = filename;
this.providedMd5Sum = providedMd5Sum;
this.providedSha1Sum = providedSha1Sum;
this.providedSha256Sum = null;
this.overrideExisting = overrideExisting;
this.contentType = contentType;
this.filesize = filesize;
@@ -115,6 +118,10 @@ public class ArtifactUpload {
return providedSha1Sum;
}
public String getProvidedSha256Sum() {
return providedSha256Sum;
}
public boolean overrideExisting() {
return overrideExisting;
}

View File

@@ -128,7 +128,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
try {
return artifactRepository.store(tenantAware.getCurrentTenant(), artifactUpload.getInputStream(),
artifactUpload.getFilename(), artifactUpload.getContentType(),
new DbArtifactHash(artifactUpload.getProvidedSha1Sum(), artifactUpload.getProvidedMd5Sum()));
new DbArtifactHash(artifactUpload.getProvidedSha1Sum(), artifactUpload.getProvidedMd5Sum(), artifactUpload.getProvidedSha256Sum()));
} catch (final ArtifactStoreException e) {
throw new ArtifactUploadFailedException(e);
} catch (final HashNotMatchException e) {
@@ -256,6 +256,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
artifact = new JpaArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
}
artifact.setMd5Hash(result.getHashes().getMd5());
artifact.setSha256Hash(result.getHashes().getSha256());
artifact.setSha1Hash(result.getHashes().getSha1());
artifact.setSize(result.getSize());

View File

@@ -57,6 +57,9 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
@Column(name = "md5_hash", length = 32, updatable = false, nullable = true)
private String md5Hash;
@Column(name = "sha256_hash", length = 64, updatable = false, nullable = true)
private String sha256Hash;
@Column(name = "file_size", updatable = false)
private long size;
@@ -94,6 +97,11 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
return sha1Hash;
}
@Override
public String getSha256Hash() {
return sha256Hash;
}
public void setMd5Hash(final String md5Hash) {
this.md5Hash = md5Hash;
}
@@ -102,6 +110,11 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
this.sha1Hash = sha1Hash;
}
public void setSha256Hash(final String sha256Hash) {
this.sha256Hash = sha256Hash;
}
@Override
public long getSize() {
return size;

View File

@@ -0,0 +1 @@
ALTER TABLE sp_artifact ADD COLUMN sha256_hash CHAR(64);

View File

@@ -0,0 +1 @@
ALTER TABLE sp_artifact ADD COLUMN sha256_hash CHAR(64);

View File

@@ -0,0 +1 @@
ALTER TABLE sp_artifact ADD COLUMN sha256_hash CHAR(64);

View File

@@ -0,0 +1 @@
ALTER TABLE sp_artifact ADD sha256_hash CHAR(64);

View File

@@ -139,6 +139,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
.isEqualTo(HashGeneratorUtils.generateSHA1(randomBytes));
assertThat(artifactManagement.getByFilename("file1").get().getMd5Hash())
.isEqualTo(HashGeneratorUtils.generateMD5(randomBytes));
assertThat(artifactManagement.getByFilename("file1").get().getSha256Hash())
.isEqualTo(HashGeneratorUtils.generateSHA256(randomBytes));
assertThat(artifactRepository.findAll()).hasSize(4);
assertThat(softwareModuleRepository.findAll()).hasSize(3);