Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Holger Friedrich <[email protected]>
  • Loading branch information
holgerfriedrich committed Sep 15, 2024
1 parent 4f456bd commit 1192718
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected String decrypt(String secret) {
if (secret.startsWith(KNXBindingConstants.ENCYRPTED_PASSWORD_SERIALIZATION_PREFIX)) {
try {
logger.info("trying to access TPM module");
return TpmInterface.TPM.deserializeAndDectryptSecret(
return TpmInterface.TPM.deserializeAndDecryptSecret(
secret.substring(KNXBindingConstants.ENCYRPTED_PASSWORD_SERIALIZATION_PREFIX.length()));
} catch (SecurityException e) {
logger.error("Unable to decode stored password using TPM: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void execute(String[] args, Console console) {
console.println(KNXBindingConstants.ENCYRPTED_PASSWORD_SERIALIZATION_PREFIX + p);

// check if TPM can decrypt
String decrypted = TpmInterface.TPM.deserializeAndDectryptSecret(p);
String decrypted = TpmInterface.TPM.deserializeAndDecryptSecret(p);
if (args[1].equals(decrypted)) {
console.println("Password successfully recovered from encrypted representation");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ STANDARD_EK_POLICY, new TPMS_RSA_PARMS(new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.AES, 1

/**
* @param secret plain text representation of password
* @return offline representation enctypted and bound to this TPM
* @return offline representation encrypted and bound to this TPM
* @throws SecurityException
*/
public SecuredPassword encryptSecret(String secret) throws SecurityException {
Expand Down Expand Up @@ -237,7 +237,7 @@ public String encryptAndSerializeSecret(String secret) throws SecurityException
}

/**
* @param secret offline repesentation of secret encrypted with this TPM.
* @param secret offline representation of secret encrypted with this TPM.
* @return secret in clear text
* @throws SecurityException
*/
Expand Down Expand Up @@ -292,7 +292,7 @@ public String decryptSecret(SecuredPassword secret) throws SecurityException {
}
}

public String deserializeAndDectryptSecret(String encryptedSecret) throws SecurityException {
public String deserializeAndDecryptSecret(String encryptedSecret) throws SecurityException {
init();
Tpm tpm = this.tpm; // local copy to avoid Null warnings
if (tpm == null) {
Expand All @@ -313,7 +313,7 @@ public String deserializeAndDectryptSecret(String encryptedSecret) throws Securi
}

/**
* Fetch random numbers from the hardware random number genrator of the TPM.
* Fetch random numbers from the hardware random number generator of the TPM.
*
* @param bytesRequested
* @return array of random numbers
Expand Down Expand Up @@ -341,7 +341,7 @@ public String getTpmFirmwareVersion() throws SecurityException {
int ret = TpmHelpers.getTpmProperty(tpm, TPM_PT.FIRMWARE_VERSION_1);
int major = ret >> 16;
int minor = ret & 0xffff;
return "" + major + "." + minor;
return major + "." + minor;
} catch (TpmException e) {
throw new SecurityException("TPM exception", e);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ public String getTpmTcgRevision() throws SecurityException {
}
try {
int ret = TpmHelpers.getTpmProperty(tpm, TPM_PT.REVISION);
return "" + (ret / 100) + "." + (ret % 100);
return (ret / 100) + "." + (ret % 100);
} catch (TpmException e) {
throw new SecurityException("TPM exception", e);
}
Expand All @@ -444,7 +444,7 @@ public String getTpmTcgRevision() throws SecurityException {
/**
* @return Return supported version of TPM standard is supported, typically
* "1.2" or "2.0".
* @throws SecurityException
* @throws SecurityException in case of a TPM error
*/
public String getTpmVersion() throws SecurityException {
init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Holger Friedrich - Initial contribution
*
* This tests are intended to test the interface class for Trusted Platform Modules (TPM).
* These tests are intended to test the interface class for Trusted Platform Modules (TPM).
* The tests will succeed, in case no TPM is available during test execution.
* Some tests will be skipped on Windows, as some operations require admin access to the TPM.
*
Expand Down Expand Up @@ -62,7 +62,7 @@ void testTpmEncDec() {

assertEquals(secret, TpmInterface.TPM.decryptSecret(sPwd));
} catch (SecurityException e) {
assertEquals("", e.toString() + " " + Objects.toString(e.getCause(), ""));
assertEquals("", e + " " + Objects.toString(e.getCause(), ""));
}
}
}
Expand All @@ -74,7 +74,7 @@ void testTpmRandom() {
byte[] r = TpmInterface.TPM.getRandom(20);
assertEquals(20, r.length);
} catch (SecurityException e) {
assertEquals("", e.toString() + " " + Objects.toString(e.getCause(), ""));
assertEquals("", e + " " + Objects.toString(e.getCause(), ""));
}
}
}
Expand Down

0 comments on commit 1192718

Please sign in to comment.