From 48f4f9a6542ac4713a7426650054794f6adeee85 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Wed, 29 Jul 2020 13:54:41 -0400 Subject: [PATCH] This could was not tested against a tpm 1.2 environment. The branch was failing on Travis because there was a timeout request from the provision to the aca, however no error from the aca could be shown. However the problem is occurring when the tpm 1.2 provision is attempting to save an issued attestation certificate. This part of the code touches the code changes for the 2.0 updates. The variable pcrValues is null when the 1.2 process is called and therefore when Files.write method is called, the pcrValues.getBytes call is throwing a null pointer exception. This code checks for that condition before operating over the code. --- ...stractAttestationCertificateAuthority.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java index f8bd4151..46686746 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java @@ -1488,23 +1488,25 @@ public abstract class AbstractAttestationCertificateAuthority } private String savePcrValues(final String pcrValues, final String deviceName) { - try { - if (Files.notExists(Paths.get(PCR_UPLOAD_FOLDER))) { - Files.createDirectory(Paths.get(PCR_UPLOAD_FOLDER)); + if (pcrValues != null && !pcrValues.isEmpty()) { + try { + if (Files.notExists(Paths.get(PCR_UPLOAD_FOLDER))) { + Files.createDirectory(Paths.get(PCR_UPLOAD_FOLDER)); + } + Path pcrPath = Paths.get(String.format("%s/%s", + PCR_UPLOAD_FOLDER, deviceName)); + if (Files.notExists(pcrPath)) { + Files.createFile(pcrPath); + } + Files.write(pcrPath, pcrValues.getBytes("UTF8")); + return pcrPath.toString(); + } catch (NoSuchFileException nsfEx) { + LOG.error(String.format("File Not found!: %s", + deviceName)); + LOG.error(nsfEx); + } catch (IOException ioEx) { + LOG.error(ioEx); } - Path pcrPath = Paths.get(String.format("%s/%s", - PCR_UPLOAD_FOLDER, deviceName)); - if (Files.notExists(pcrPath)) { - Files.createFile(pcrPath); - } - Files.write(pcrPath, pcrValues.getBytes("UTF8")); - return pcrPath.toString(); - } catch (NoSuchFileException nsfEx) { - LOG.error(String.format("File Not found!: %s", - deviceName)); - LOG.error(nsfEx); - } catch (IOException ioEx) { - LOG.error(ioEx); } return "empty";