Skip to content

Commit

Permalink
issue_847: Fixed the majority of the checkstyle errors in the CAPOrta…
Browse files Browse the repository at this point in the history
…l module. Need to fix 5 more and figure out why two tests are failing. Merged master into local branch.
  • Loading branch information
ThatSilentCoder committed Oct 28, 2024
1 parent 6d770e9 commit f9da128
Show file tree
Hide file tree
Showing 77 changed files with 39,332 additions and 595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected X509Certificate generateCredential(final PublicKey publicKey,
+ "Unable to issue certificates");
}

ContentSigner signer = new JcaContentSignerBuilder("SHA1WithRSA")
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA")
.setProvider("BC").build(getPrivateKey());
X509CertificateHolder holder = builder.build(signer);
return new JcaX509CertificateConverter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hirs.attestationca.persist.provision;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import hirs.attestationca.configuration.provisionerTpm2.ProvisionerTpm2;
import hirs.attestationca.persist.entity.manager.CertificateRepository;
Expand Down Expand Up @@ -161,16 +160,14 @@ public byte[] processCertificateRequest(final byte[] certificateRequest) {
attestationCertificate);
byte[] derEncodedLdevidCertificate = ProvisionUtils.getDerEncodedCertificate(
ldevidCertificate);
String pemEncodedAttestationCertificate = ProvisionUtils.getPemEncodedCertificate(
attestationCertificate);
String pemEncodedLdevidCertificate = ProvisionUtils.getPemEncodedCertificate(
ldevidCertificate);

// We validated the nonce and made use of the identity claim so state can be deleted
tpm2ProvisionerStateRepository.delete(tpm2ProvisionerState);

// Package the signed certificates into a response
ByteString certificateBytes = ByteString
.copyFrom(derEncodedAttestationCertificate);
ByteString ldevidCertificateBytes = ByteString
.copyFrom(derEncodedLdevidCertificate);

boolean generateAtt = saveAttestationCertificate(certificateRepository,
derEncodedAttestationCertificate,
endorsementCredential, platformCredentials, device, false);
Expand All @@ -181,32 +178,31 @@ public byte[] processCertificateRequest(final byte[] certificateRequest) {
ProvisionerTpm2.CertificateResponse.Builder builder = ProvisionerTpm2.CertificateResponse.
newBuilder().setStatus(ProvisionerTpm2.ResponseStatus.PASS);
if (generateAtt) {
builder = builder.setCertificate(certificateBytes);
builder = builder.setCertificate(pemEncodedAttestationCertificate);
}
if (generateLDevID) {
builder = builder.setLdevidCertificate(ldevidCertificateBytes);
builder = builder.setLdevidCertificate(pemEncodedLdevidCertificate);
}
ProvisionerTpm2.CertificateResponse response = builder.build();

return response.toByteArray();
} else {
byte[] derEncodedAttestationCertificate = ProvisionUtils.getDerEncodedCertificate(
attestationCertificate);

String pemEncodedAttestationCertificate = ProvisionUtils.getPemEncodedCertificate(
attestationCertificate);

// We validated the nonce and made use of the identity claim so state can be deleted
tpm2ProvisionerStateRepository.delete(tpm2ProvisionerState);

// Package the signed certificates into a response
ByteString certificateBytes = ByteString
.copyFrom(derEncodedAttestationCertificate);
ProvisionerTpm2.CertificateResponse.Builder builder = ProvisionerTpm2.CertificateResponse.
newBuilder().setStatus(ProvisionerTpm2.ResponseStatus.PASS);

boolean generateAtt = saveAttestationCertificate(certificateRepository,
derEncodedAttestationCertificate,
endorsementCredential, platformCredentials, device, false);
if (generateAtt) {
builder = builder.setCertificate(certificateBytes);
builder = builder.setCertificate(pemEncodedAttestationCertificate);
}
ProvisionerTpm2.CertificateResponse response = builder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import lombok.extern.log4j.Log4j2;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.ArrayUtils;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
Expand All @@ -26,6 +27,8 @@
import javax.crypto.spec.OAEPParameterSpec;
import javax.crypto.spec.PSource;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.StringWriter;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -138,6 +141,29 @@ public static byte[] getDerEncodedCertificate(final X509Certificate certificate)
}
}

/**
* Helper method to extract a PEM encoded certificate from an X509 certificate.
*
* @param certificate the X509 certificate to be converted to PEM encoding
* @throws {@link UnexpectedServerException} if error occurs during encoding retrieval
* @return the string representing the PEM encoded certificate
*/
public static String getPemEncodedCertificate(final X509Certificate certificate) {
try {
final StringWriter stringWriter = new StringWriter();
final JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter);
pemWriter.writeObject(certificate);
pemWriter.flush();
pemWriter.close();
return stringWriter.toString();
} catch (IOException ioEx) {
log.error("Error converting certificate to PEM Encoding.", ioEx);
throw new UnexpectedServerException(
"Encountered error while converting X509 Certificate to PEM Encoding: "
+ ioEx.getMessage(), ioEx);
}
}

/**
* Parse public key from public data segment generated by TPM 2.0.
*
Expand Down
4 changes: 3 additions & 1 deletion HIRS_AttestationCAPortal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ ospackage {
requires('mariadb-server', '10.3', GREATER | EQUAL)
requires('procps-ng', '3.3.15', GREATER | EQUAL)
requires('alternatives', '1.19', GREATER | EQUAL)
requires('hwdata', '0.314', GREATER | EQUAL)
// Post Trans stage (Occurs after required app and postInstall stage)
// Note postInstall wont wait forrequired apps
// Note postInstall wont wait for required apps
postTrans 'update-alternatives --set java java-17-openjdk.x86_64'
postTrans 'firewall-cmd --add-port=8443/tcp --permanent'
postTrans 'firewall-cmd --reload'
Expand All @@ -181,6 +182,7 @@ ospackage {
requires('openjdk-17-jdk', '17.0', GREATER | EQUAL)
requires('mariadb-server', '10.3', GREATER | EQUAL)
requires('curl')
requires('hwdata', '0.314', GREATER | EQUAL)
// Install after required packages
postInstall 'bash /opt/hirs/aca/scripts/aca/aca_setup.sh -u'
postInstall 'bash /opt/hirs/aca/scripts/systemd/aca_enable_service.sh'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@SpringBootApplication
//@EnableAutoConfiguration
@Log4j2
public class HIRSApplication {//extends SpringBootServletInitializer {
public class HIRSApplication {
//extends SpringBootServletInitializer {
// private static final Logger LOGGER = LogManager.getLogger(HIRSApplication.class);
// @Override
// protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
Expand All @@ -22,7 +23,10 @@ public class HIRSApplication {//extends SpringBootServletInitializer {
// appServlet.setLoadOnStartup(1);
// }

public static void main(String[] args) {
/**
* @param args
*/
public static void main(final String[] args) {
// SpringApplication springApplication = new SpringApplication(HIRSApplication.class);
// springApplication.setDefaultProperties(Collections.singletonMap("server.servlet.context-path",
// "/portal"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
public class HIRSDbInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
implements ServletContextListener {

/**
* Initialize context.
*
* @param servletContextEvent servlet context event.
*/
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
Expand All @@ -35,18 +40,33 @@ public void contextInitialized(final ServletContextEvent servletContextEvent) {
}
}

/**
* Retrieves root configuration classes.
*
* @return array of root configuration classes.
*/
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {
PersistenceJPAConfig.class, PageConfiguration.class, PersistenceConfiguration.class
};
}

/**
* Retrieves servlet configuration classes.
*
* @return null
*/
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}

/**
* Retrieves servlet mappings.
*
* @return string array of servlet mappings.
*/
@Override
protected String[] getServletMappings() {
return new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public class PersistenceJPAConfig implements WebMvcConfigurer {
@Autowired
private Environment environment;

/**
* Entity manager factory bean.
*
* @return a local container entity manager factory bean
*/
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean entityManagerBean =
Expand All @@ -94,6 +99,11 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
return entityManagerBean;
}

/**
* Data source bean.
*
* @return a data source
*/
@Bean
public DataSource dataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
Expand Down Expand Up @@ -213,13 +223,19 @@ public KeyStore keyStore() {
}
}

/**
* @return
*/
@Bean
public PlatformTransactionManager transactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}

/**
* @return
*/
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
Expand Down Expand Up @@ -258,6 +274,11 @@ public StandardServletMultipartResolver multipartResolver() {
// }


/**
* Configures the default servlet handling.
*
* @param configurer default servlet handler configurer.
*/
@Override
public void configureDefaultServletHandling(final DefaultServletHandlerConfigurer configurer) {
configurer.enable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
* Java representation of a jQuery DataTables Column.
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@NoArgsConstructor
@ToString
public class Column {

/**
Expand Down Expand Up @@ -64,14 +65,4 @@ public void setSearchValue(final String searchValue) {
this.search.setValue(searchValue);
}

@Override
public String toString() {
return "Column{"
+ "data='" + data + '\''
+ ", name='" + name + '\''
+ ", searchable=" + searchable
+ ", orderable=" + orderable
+ ", search=" + search
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
* Represents a column ordering with regards to a jQuery DataTable.
* Represents a column ordering in regard to a jQuery DataTable.
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@NoArgsConstructor
@ToString
public class Order {


Expand Down Expand Up @@ -53,18 +54,7 @@ public Order(final int column, final boolean isAscending) {
* @return true if ascending order, false otherwise.
*/
public boolean isAscending() {
if (dir.equalsIgnoreCase("asc")) {
return true;
}
return false;
}

@Override
public String toString() {
return "Order{"
+ "column=" + column
+ ", dir='" + dir + '\''
+ '}';
return dir.equalsIgnoreCase("asc");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static <T> FilteredRecordsList<T> getOrderedList(final Class<? extends T>

filteredRecordsList.setRecordsTotal(dbManager.count());
filteredRecordsList.addAll((Collection<? extends T>) dbManager.findAll());
filteredRecordsList.setRecordsFiltered(10);
final int recordsFilteredConstant = 10;
filteredRecordsList.setRecordsFiltered(recordsFilteredConstant);

return filteredRecordsList;

Expand All @@ -95,6 +96,16 @@ public static <T> FilteredRecordsList<T> getOrderedList(final Class<? extends T>
// searchableColumnMap, criteriaModifier);
}

/**
* Retrieves an ordered list of reference digest values.
*
* @param dbManager database manager.
* @param dataTableInput data table input.
* @param orderColumnName string representation of the order column name.
* @param criteriaModifier criteria modifier.
* @param entityManager entity manager.
* @return a filtered, ordered records list of the reference digest values
*/
public static FilteredRecordsList<ReferenceDigestValue> getOrderedList(
final JpaRepository<ReferenceDigestValue, UUID> dbManager,
final DataTableInput dataTableInput,
Expand Down Expand Up @@ -127,7 +138,8 @@ public static FilteredRecordsList<ReferenceDigestValue> getOrderedList(

filteredRecordsList.setRecordsTotal(dbManager.count());
filteredRecordsList.addAll(dbManager.findAll());
filteredRecordsList.setRecordsFiltered(10);
final int recordsFilteredConstant = 10;
filteredRecordsList.setRecordsFiltered(recordsFilteredConstant);

return filteredRecordsList;

Expand Down
Loading

0 comments on commit f9da128

Please sign in to comment.