mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-18 20:47:58 +00:00
fixing checkstyles
This commit is contained in:
parent
7efbcc270e
commit
9c8d936e51
@ -57,9 +57,14 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test suite for {@link AttestationCertificateAuthority}.
|
||||
@ -75,11 +80,28 @@ public class AttestationCertificateAuthorityTest {
|
||||
*/
|
||||
@Nested
|
||||
public class AccessAbstractProcessor extends AbstractProcessor {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param privateKey the private key of the ACA
|
||||
* @param validDays int for the time in which a certificate is valid.
|
||||
*/
|
||||
public AccessAbstractProcessor(final PrivateKey privateKey,
|
||||
final int validDays) {
|
||||
super(privateKey, validDays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public wrapper for the protected function generateCredential(), to access for testing.
|
||||
*
|
||||
* @param publicKey cannot be null
|
||||
* @param endorsementCredential the endorsement credential
|
||||
* @param platformCredentials the set of platform credentials
|
||||
* @param deviceName The host name used in the subject alternative name
|
||||
* @param acaCertificate the aca certificate
|
||||
* @return the generated X509 certificate
|
||||
*/
|
||||
public X509Certificate accessGenerateCredential(final PublicKey publicKey,
|
||||
final EndorsementCredential endorsementCredential,
|
||||
final List<PlatformCredential> platformCredentials,
|
||||
@ -165,7 +187,7 @@ public class AttestationCertificateAuthorityTest {
|
||||
null, null, null, null, null, null, 1,
|
||||
null, null, null, null) {
|
||||
};
|
||||
abstractProcessor = new AccessAbstractProcessor(keyPair.getPrivate(),1);
|
||||
abstractProcessor = new AccessAbstractProcessor(keyPair.getPrivate(), 1);
|
||||
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
@ -232,7 +254,8 @@ public class AttestationCertificateAuthorityTest {
|
||||
byte[] encrypted = encryptBlob(expected, encryptionScheme.toString());
|
||||
|
||||
// perform the decryption and assert that the decrypted bytes equal the expected bytes
|
||||
assertArrayEquals(expected, ProvisionUtils.decryptAsymmetricBlob(encrypted, encryptionScheme, keyPair.getPrivate()));
|
||||
assertArrayEquals(expected, ProvisionUtils.decryptAsymmetricBlob(
|
||||
encrypted, encryptionScheme, keyPair.getPrivate()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,6 +310,9 @@ public class AttestationCertificateAuthorityTest {
|
||||
assertTrue(symmetricKey.getKeySize() == symmetricKey.getKey().length);
|
||||
}
|
||||
|
||||
private void assertTrue(final boolean b) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link ProvisionUtils#generateAsymmetricContents(
|
||||
* byte[], byte[], PublicKey)}.
|
||||
@ -639,7 +665,7 @@ public class AttestationCertificateAuthorityTest {
|
||||
* @return encrypted blob
|
||||
* @throws Exception during the encryption process
|
||||
*/
|
||||
private byte[] encryptBlob(byte[] blob, String transformation) throws Exception {
|
||||
private byte[] encryptBlob(final byte[] blob, final String transformation) throws Exception {
|
||||
// initialize a cipher using the specified transformation
|
||||
Cipher cipher = Cipher.getInstance(transformation);
|
||||
|
||||
@ -661,8 +687,8 @@ public class AttestationCertificateAuthorityTest {
|
||||
* @return encrypted blob
|
||||
* @throws Exception
|
||||
*/
|
||||
private byte[] encryptBlob(byte[] blob, byte[] key, byte[] iv, String transformation)
|
||||
throws Exception {
|
||||
private byte[] encryptBlob(final byte[] blob, final byte[] key, final byte[] iv,
|
||||
final String transformation) throws Exception {
|
||||
// initialize a cipher using the specified transformation
|
||||
Cipher cipher = Cipher.getInstance(transformation);
|
||||
|
||||
@ -686,7 +712,7 @@ public class AttestationCertificateAuthorityTest {
|
||||
* @return decrypted blob
|
||||
* @throws Exception
|
||||
*/
|
||||
private byte[] decryptBlob(byte[] blob) throws Exception {
|
||||
private byte[] decryptBlob(final byte[] blob) throws Exception {
|
||||
// initialize a cipher using the specified transformation
|
||||
Cipher cipher = Cipher.getInstance(EncryptionScheme.OAEP.toString());
|
||||
|
||||
@ -711,8 +737,8 @@ public class AttestationCertificateAuthorityTest {
|
||||
* @return decrypted blob
|
||||
* @throws Exception
|
||||
*/
|
||||
private byte[] decryptBlob(byte[] blob, byte[] key, byte[] iv, String transformation)
|
||||
throws Exception {
|
||||
private byte[] decryptBlob(final byte[] blob, final byte[] key, final byte[] iv,
|
||||
final String transformation) throws Exception {
|
||||
// initialize a cipher using the specified transformation
|
||||
Cipher cipher = Cipher.getInstance(transformation);
|
||||
|
||||
@ -728,5 +754,4 @@ public class AttestationCertificateAuthorityTest {
|
||||
// return the cipher text
|
||||
return cipher.doFinal(blob);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package hirs.attestationca.persist.entity;
|
||||
|
||||
import hirs.attestationca.persist.entity.userdefined.certificate.CertificateAuthorityCredential;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.cert.CertificateException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the class <code>Appraiser</code>.
|
||||
@ -160,5 +162,4 @@ public final class AppraiserTest {
|
||||
assertNotEquals(appraiser1.hashCode(), appraiser2.hashCode());
|
||||
assertNotEquals(appraiser2.hashCode(), appraiser1.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity;
|
@ -87,13 +87,16 @@ public class TPM2ProvisionerStateTest {
|
||||
|
||||
|
||||
/**
|
||||
* Test that {@link TPM2ProvisionerState#getTPM2ProvisionerState(TPM2ProvisionerStateRepository, byte[])} works.
|
||||
* {@link TPM2ProvisionerState#getTPM2ProvisionerState(TPM2ProvisionerStateRepository, byte[])}, null is returned.
|
||||
* Test that {@link TPM2ProvisionerState#getTPM2ProvisionerState(
|
||||
* TPM2ProvisionerStateRepository, byte[])} works.
|
||||
* {@link TPM2ProvisionerState#getTPM2ProvisionerState(
|
||||
* TPM2ProvisionerStateRepository, byte[])}, null is returned.
|
||||
* @throws IOException this will never happen
|
||||
*/
|
||||
@Test
|
||||
public final void testGetTPM2ProvisionerStateNominal() throws IOException {
|
||||
TPM2ProvisionerStateRepository tpm2ProvisionerStateRepository = mock(TPM2ProvisionerStateRepository.class);
|
||||
TPM2ProvisionerStateRepository tpm2ProvisionerStateRepository =
|
||||
mock(TPM2ProvisionerStateRepository.class);
|
||||
byte[] nonce = new byte[32];
|
||||
byte[] identityClaim = new byte[360];
|
||||
random.nextBytes(nonce);
|
||||
@ -112,12 +115,14 @@ public class TPM2ProvisionerStateTest {
|
||||
|
||||
/**
|
||||
* Test that if a null is passed as a nonce to
|
||||
* {@link TPM2ProvisionerState#getTPM2ProvisionerState(TPM2ProvisionerStateRepository, byte[])}, null is returned.
|
||||
* {@link TPM2ProvisionerState#getTPM2ProvisionerState(
|
||||
* TPM2ProvisionerStateRepository, byte[])}, null is returned.
|
||||
* @throws IOException this will never happen
|
||||
*/
|
||||
@Test
|
||||
public final void testGetTPM2ProvisionerStateNullNonce() throws IOException {
|
||||
TPM2ProvisionerStateRepository tpm2ProvisionerStateRepository = mock(TPM2ProvisionerStateRepository.class);
|
||||
TPM2ProvisionerStateRepository tpm2ProvisionerStateRepository =
|
||||
mock(TPM2ProvisionerStateRepository.class);
|
||||
byte[] nonce = new byte[32];
|
||||
byte[] identityClaim = new byte[360];
|
||||
random.nextBytes(nonce);
|
||||
@ -133,12 +138,14 @@ public class TPM2ProvisionerStateTest {
|
||||
|
||||
/**
|
||||
* Test that if a nonce that is less than 8 bytes is passed to
|
||||
* {@link TPM2ProvisionerState#getTPM2ProvisionerState(TPM2ProvisionerStateRepository, byte[])}, null is returned.
|
||||
* {@link TPM2ProvisionerState#getTPM2ProvisionerState(
|
||||
* TPM2ProvisionerStateRepository, byte[])}, null is returned.
|
||||
* @throws IOException this will never happen
|
||||
*/
|
||||
@Test
|
||||
public final void testGetTPM2ProvisionerStateNonceTooSmall() throws IOException {
|
||||
TPM2ProvisionerStateRepository tpm2ProvisionerStateRepository = mock(TPM2ProvisionerStateRepository.class);
|
||||
TPM2ProvisionerStateRepository tpm2ProvisionerStateRepository =
|
||||
mock(TPM2ProvisionerStateRepository.class);
|
||||
byte[] nonce = new byte[32];
|
||||
byte[] identityClaim = new byte[360];
|
||||
random.nextBytes(nonce);
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.tpm;
|
@ -103,7 +103,7 @@ public class AbstractUserdefinedEntityTest {
|
||||
private static final Logger LOGGER = LogManager.getLogger(DeviceInfoReportTest.class);
|
||||
|
||||
/**
|
||||
* Dummy message for supply chain validation test
|
||||
* Dummy message for supply chain validation test.
|
||||
*/
|
||||
public static final String VALIDATION_MESSAGE = "Some message.";
|
||||
|
||||
|
@ -772,4 +772,4 @@ public class PlatformCredentialTest extends AbstractUserdefinedEntityTest {
|
||||
PlatformCredential credential = new PlatformCredential(path);
|
||||
Assertions.assertNotNull(credential);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,4 @@ public class TPMSecurityAssertionsTest {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.userdefined.certificate.attributes;
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.userdefined.certificate;
|
@ -124,4 +124,4 @@ public class PortalInfoTest {
|
||||
assertNull(info.getContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.userdefined.info;
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.userdefined;
|
@ -26,7 +26,8 @@ public class TPMMeasurementRecordTest {
|
||||
private static final int DEFAULT_PCR_ID = 3;
|
||||
private static final String DEFAULT_HASH =
|
||||
"3d5f3c2f7f3003d2e4baddc46ed4763a4954f648";
|
||||
private static final ExaminableRecord.ExamineState DEFAULT_STATE = ExaminableRecord.ExamineState.UNEXAMINED;
|
||||
private static final ExaminableRecord.ExamineState DEFAULT_STATE =
|
||||
ExaminableRecord.ExamineState.UNEXAMINED;
|
||||
|
||||
/**
|
||||
* Tests instantiation of new <code>PCRMeasurementRecord</code>.
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.userdefined.record;
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.entity.userdefined.report;
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist;
|
@ -65,7 +65,8 @@ public class CredentialManagementHelperTest {
|
||||
@Test
|
||||
public void processEmptyEndorsementCredential() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
CredentialManagementHelper.storeEndorsementCredential(certificateRepository, new byte[0], "testName"));
|
||||
CredentialManagementHelper.storeEndorsementCredential(
|
||||
certificateRepository, new byte[0], "testName"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +76,8 @@ public class CredentialManagementHelperTest {
|
||||
public void processInvalidEndorsementCredentialCase1() {
|
||||
byte[] ekBytes = new byte[] {1};
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
CredentialManagementHelper.storeEndorsementCredential(certificateRepository, ekBytes, "testName"));
|
||||
CredentialManagementHelper.storeEndorsementCredential(
|
||||
certificateRepository, ekBytes, "testName"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +186,7 @@ public class IssuedCertificateAttributeHelperTest {
|
||||
}
|
||||
|
||||
private Map<String, String> getSubjectAlternativeNameAttributes(
|
||||
Extension subjectAlternativeName) {
|
||||
final Extension subjectAlternativeName) {
|
||||
Map<String, String> subjectAlternativeNameAttrMap = new HashMap<>();
|
||||
|
||||
DLSequence dlSequence = (DLSequence) subjectAlternativeName.getParsedValue();
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.provision.helper;
|
@ -244,17 +244,16 @@ public class SupplyChainCredentialValidatorTest {
|
||||
@Test
|
||||
public final void testValidateEndorsementCredential()
|
||||
throws URISyntaxException, IOException, CertificateException, KeyStoreException {
|
||||
Certificate rootcacert, intermediateca02cert;
|
||||
|
||||
EndorsementCredential ekcert = new EndorsementCredential(Files.readAllBytes(
|
||||
Paths.get(Objects.requireNonNull(getClass().getResource(TEST_EK_CERT)).toURI()))
|
||||
);
|
||||
|
||||
intermediateca02cert = new CertificateAuthorityCredential(Files.readAllBytes(Paths.get(
|
||||
Certificate intermediateca02cert = new CertificateAuthorityCredential(Files.readAllBytes(Paths.get(
|
||||
Objects.requireNonNull(getClass().getResource(INT_CA_CERT02)).toURI()))
|
||||
);
|
||||
|
||||
rootcacert = new CertificateAuthorityCredential(Files.readAllBytes(Paths.get(
|
||||
Certificate rootcacert = new CertificateAuthorityCredential(Files.readAllBytes(Paths.get(
|
||||
Objects.requireNonNull(getClass().getResource(FAKE_ROOT_CA_ORIG)).toURI()))
|
||||
);
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
package hirs.attestationca.persist.validation;
|
Loading…
Reference in New Issue
Block a user