use of com.stnetix.ariaddna.commonutils.dto.CertificateDTO in project ariADDna by StnetixDevTeam.
the class CertFactory method getNewCertificate.
public File getNewCertificate(String alias) throws KeyStoreException {
KeyPairGenerator keyPairGenerator = null;
try {
keyPairGenerator = KeyPairGenerator.getInstance(CRYPTO_ALGORITHM_RSA);
keyPairGenerator.initialize(CERTIFICATE_SIZE);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
X509CertInfo certInfo = new X509CertInfo();
CertificateValidity interval = new CertificateValidity(FROM, TO);
BigInteger sn = new BigInteger(64, new SecureRandom());
X500Name owner = new X500Name(SUBJECT_CN + alias + ", " + SUBJECT_L_C);
certInfo.set(X509CertInfo.VALIDITY, interval);
certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn));
certInfo.set(X509CertInfo.SUBJECT, owner);
certInfo.set(X509CertInfo.ISSUER, owner);
certInfo.set(X509CertInfo.KEY, new CertificateX509Key(keyPair.getPublic()));
certInfo.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
AlgorithmId algorithm = new AlgorithmId(AlgorithmId.md2WithRSAEncryption_oid);
certInfo.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algorithm));
X509CertImpl cert = new X509CertImpl(certInfo);
cert.sign(privateKey, CRYPTO_ALGORITHM_SHA1RSA);
algorithm = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG);
certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, algorithm);
cert = new X509CertImpl(certInfo);
cert.sign(privateKey, CRYPTO_ALGORITHM_SHA1RSA);
File certFile = new File(alias + ".cer");
if (certFile.createNewFile()) {
FileOutputStream fos = new FileOutputStream(certFile);
fos.write(cert.getEncoded());
fos.close();
}
LOGGER.info("Certificate generated with filename {}", certFile.getAbsolutePath());
CertificateDTO storedCert = persistHelper.storeCertificete(new CertificateDTO(alias, true));
LOGGER.info("Certificate stored id DB with id {}", storedCert.getId());
return certFile;
} catch (Exception e) {
LOGGER.error("Exception: ", e);
throw new KeyStoreException("Caused by: ", e);
}
}
use of com.stnetix.ariaddna.commonutils.dto.CertificateDTO in project ariADDna by StnetixDevTeam.
the class CertificateServiceImplTest method getDisableCertificatesTest.
@Test
public void getDisableCertificatesTest() throws Exception {
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
UUID uuid3 = UUID.randomUUID();
CertificateDTO certificateDTO1 = new CertificateDTO();
CertificateDTO certificateDTO2 = new CertificateDTO();
CertificateDTO certificateDTO3 = new CertificateDTO();
certificateDTO1.setActive(true);
certificateDTO1.setUuid(uuid1.toString());
certificateDTO2.setUuid(uuid2.toString());
certificateDTO3.setUuid(uuid3.toString());
certificateService.save(certificateDTO1);
certificateService.save(certificateDTO2);
certificateService.save(certificateDTO3);
List<CertificateDTO> certificateDTOList = certificateService.getDisableCertificates();
assertEquals(certificateDTOList.size(), 2);
}
use of com.stnetix.ariaddna.commonutils.dto.CertificateDTO in project ariADDna by StnetixDevTeam.
the class CertificateServiceImplTest method saveTest.
@Test
public void saveTest() throws Exception {
CertificateDTO certificateDTO = new CertificateDTO();
certificateDTO.setActive(true);
UUID uuid = UUID.randomUUID();
certificateDTO.setUuid(uuid.toString());
CertificateDTO savedCertDTO = certificateService.save(certificateDTO);
assertNotNull(savedCertDTO);
assertNotNull(savedCertDTO.getId());
}
use of com.stnetix.ariaddna.commonutils.dto.CertificateDTO in project ariADDna by StnetixDevTeam.
the class CertificateServiceImplTest method getActiveCertificatesTest.
@Test
public void getActiveCertificatesTest() throws Exception {
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
UUID uuid3 = UUID.randomUUID();
CertificateDTO certificateDTO1 = new CertificateDTO();
CertificateDTO certificateDTO2 = new CertificateDTO();
CertificateDTO certificateDTO3 = new CertificateDTO();
certificateDTO1.setActive(true);
certificateDTO3.setActive(true);
certificateDTO1.setUuid(uuid1.toString());
certificateDTO2.setUuid(uuid2.toString());
certificateDTO3.setUuid(uuid3.toString());
certificateService.save(certificateDTO1);
certificateService.save(certificateDTO2);
certificateService.save(certificateDTO3);
List<CertificateDTO> certificateDTOList = certificateService.getActiveCertificates();
assertEquals(certificateDTOList.size(), 2);
}
use of com.stnetix.ariaddna.commonutils.dto.CertificateDTO in project ariADDna by StnetixDevTeam.
the class CertificateServiceImplTest method getAllCertificatesTest.
@Test
public void getAllCertificatesTest() throws Exception {
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
UUID uuid3 = UUID.randomUUID();
CertificateDTO certificateDTO1 = new CertificateDTO();
CertificateDTO certificateDTO2 = new CertificateDTO();
CertificateDTO certificateDTO3 = new CertificateDTO();
certificateDTO1.setActive(true);
certificateDTO1.setUuid(uuid1.toString());
certificateDTO2.setUuid(uuid2.toString());
certificateDTO3.setUuid(uuid3.toString());
certificateService.save(certificateDTO1);
certificateService.save(certificateDTO2);
certificateService.save(certificateDTO3);
List<CertificateDTO> certificateDTOList = certificateService.getAllCertificates();
assertEquals(certificateDTOList.size(), 3);
}
Aggregations