[#202] Certificate fail to save upon deletion during provisioning FIXED (#206)

* This commit fixes an error produced when provisioning when the certificate from a previous provision is deleted from the ACA.  The error involves doing a look up for an existing certificate and getting nothing however this is due to not using the 'includeArchived' attribute for the Certificate Selector.  Include Archived is used when manually uploading a certificate.
This commit is contained in:
Cyrus 2020-01-06 08:17:04 -05:00 committed by GitHub
parent 0f3cfeb7b5
commit 81e13831b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 6 deletions

View File

@ -109,7 +109,10 @@ public final class CredentialManagementHelper {
}
PlatformCredential existingCredential =
PlatformCredential.select(certificateManager)
.byHashCode(platformCredential.getCertificateHash()).getCertificate();
.includeArchived()
.byHashCode(platformCredential
.getCertificateHash())
.getCertificate();
if (existingCredential == null) {
if (platformCredential.getPlatformSerial() != null) {
List<PlatformCredential> certificates = PlatformCredential

View File

@ -739,7 +739,6 @@ public class CertificateRequestPageController extends PageController<NoPageParam
// if an identical certificate is archived, update the existing certificate to
// unarchive it and change the creation date
if (existingCertificate.isArchived()) {
existingCertificate.restore();
existingCertificate.resetCreateTime();
certificateManager.update(existingCertificate);

View File

@ -86,4 +86,14 @@ public abstract class AbstractEntity {
}
return this.hashCode() == obj.hashCode();
}
@Override
public String toString() {
try {
return String.format("UUID=%s, createTime=%s",
getId(), getCreateTime().toString());
} catch (NullPointerException npEx) {
return "";
}
}
}

View File

@ -107,4 +107,16 @@ public abstract class ArchivableEntity extends AbstractEntity {
public final String getArchivedDescription() {
return this.archivedDescription;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString());
if (archivedTime != null) {
sb.append(String.format(", archivedTime=%s, archiveDescription=%s",
archivedTime.toString(), archivedDescription));
}
return sb.toString();
}
}

View File

@ -394,4 +394,9 @@ public class Device extends AbstractEntity {
return this.name.equals(other.name);
}
@Override
public String toString() {
return String.format("Device{name=%s, status=%s}",
name, supplyChainValidationStatus);
}
}

View File

@ -1083,10 +1083,12 @@ public abstract class Certificate extends ArchivableEntity {
@Override
public String toString() {
return "Certificate{"
+ ", serialNumber=" + serialNumber
+ ", issuer='" + issuer + '\''
+ '}';
return String.format("Certificate{%s, AuthID=%s, serialNumber=%s, "
+ "issuer=%s, AuthSerialNumber=%s, publicKeySize=%d, "
+ "signatureAlg=%s, Hash=%d}", super.toString(),
authorityKeyIdentifier, serialNumber.toString(),
issuer, authoritySerialNumber.toString(), publicKeySize,
signatureAlgorithm, certificateHash);
}
@Override

View File

@ -70,4 +70,15 @@ public abstract class DeviceAssociatedCertificate extends Certificate {
public void setDevice(final Device device) {
this.device = device;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString());
if (device != null) {
sb.append(String.format("%nDevice -> %s", getDevice().toString()));
}
return sb.toString();
}
}