Best Testsigma code snippet using com.testsigma.service.CertificateService.TestsigmaException
Source:ProvisioningProfileService.java
1package com.testsigma.service;2import com.testsigma.config.StorageServiceFactory;3import com.testsigma.exception.ResourceNotFoundException;4import com.testsigma.exception.TestsigmaException;5import com.testsigma.model.ProvisioningProfile;6import com.testsigma.model.ProvisioningProfileDevice;7import com.testsigma.model.ProvisioningProfileStatus;8import com.testsigma.model.TestDevice;9import com.testsigma.repository.ProvisioningProfileRepository;10import com.testsigma.tasks.ReSignTask;11import lombok.RequiredArgsConstructor;12import lombok.extern.log4j.Log4j2;13import org.springframework.beans.factory.annotation.Autowired;14import org.springframework.data.domain.Page;15import org.springframework.data.domain.Pageable;16import org.springframework.data.jpa.domain.Specification;17import org.springframework.stereotype.Service;18import org.springframework.web.context.WebApplicationContext;19import org.springframework.web.multipart.MultipartFile;20import java.io.File;21import java.io.IOException;22import java.sql.Timestamp;23import java.util.List;24import java.util.stream.Collectors;25@Log4j226@Service27@RequiredArgsConstructor(onConstructor = @__({@Autowired}))28public class ProvisioningProfileService {29 private final ProvisioningProfileRepository provisioningProfileRepository;30 private final CertificateService certificateService;31 private final ProvisioningProfileParserService profileParserService;32 private final ProvisioningProfileDeviceService provisioningProfileDeviceService;33 private final TestDeviceService testDeviceService;34 private final WebApplicationContext webApplicationContext;35 private final StorageServiceFactory storageServiceFactory;36 public Page<ProvisioningProfile> findAll(Specification<ProvisioningProfile> spec, Pageable pageable) {37 return this.provisioningProfileRepository.findAll(spec, pageable);38 }39 public List<ProvisioningProfile> findAll() {40 return this.provisioningProfileRepository.findAll();41 }42 public ProvisioningProfile find(Long id) throws ResourceNotFoundException {43 ProvisioningProfile provisioningProfile = this.provisioningProfileRepository.findById(id).orElseThrow(44 () -> new ResourceNotFoundException("Profile missing with id:" + id));45 certificateService.setPreSignedURLs(provisioningProfile);46 return provisioningProfile;47 }48 public ProvisioningProfile create(ProvisioningProfile provisioningProfile) {49 provisioningProfile.setStatus(ProvisioningProfileStatus.CSR_REQUESTED);50 provisioningProfile = this.provisioningProfileRepository.save(provisioningProfile);51 try {52 log.info(String.format("Generating CSR for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),53 provisioningProfile.getName()));54 String csrPathPrefix = certificateService.s3Prefix(provisioningProfile.getId());55 String csrFileName = +provisioningProfile.getId() + CertificateService.CSR_FILE_SUFFIX;56 String privateKeyFileName = provisioningProfile.getId()57 + CertificateService.PRIVATE_KEY_FILE_SUFFIX;58 String csrS3FileName = csrPathPrefix + CertificateService.CSR_FILE_SUFFIX;59 String privateKeyS3FileName = csrPathPrefix + CertificateService.PRIVATE_KEY_FILE_SUFFIX;60 File csrFile = File.createTempFile(csrFileName, CertificateService.CSR_EXTENSION);61 File privateKeyFile = File.createTempFile(privateKeyFileName, CertificateService.PEM_EXTENSION);62 certificateService.writeCSR(csrFile, privateKeyFile);63 log.info(String.format("Uploading CSR for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),64 provisioningProfile.getName()));65 storageServiceFactory.getStorageService().addFile(csrS3FileName + CertificateService.CSR_EXTENSION, csrFile);66 storageServiceFactory.getStorageService().addFile(privateKeyS3FileName + CertificateService.PEM_EXTENSION, privateKeyFile);67 provisioningProfile.setStatus(ProvisioningProfileStatus.AWAITING_FOR_CERTIFICATE);68 provisioningProfile = this.provisioningProfileRepository.save(provisioningProfile);69 certificateService.setPreSignedURLs(provisioningProfile);70 } catch (Exception e) {71 log.error(e.getMessage(), e);72 }73 return provisioningProfile;74 }75 public ProvisioningProfile update(ProvisioningProfile provisioningProfile) throws TestsigmaException {76 try {77 MultipartFile cer = provisioningProfile.getCer();78 MultipartFile provFile = provisioningProfile.getProvisioningProfile();79 if (cer != null) {80 log.info(String.format("Uploading Certificate files(cer, crt, pem) for provisioningProfile [%s] - [%s]",81 provisioningProfile.getId(), provisioningProfile.getName()));82 updateCRT(cer, provisioningProfile);83 provisioningProfile.setStatus(ProvisioningProfileStatus.AWAITING_FOR_PROVISIONING_PROFILE);84 provisioningProfile.setUpdatedDate(new Timestamp(System.currentTimeMillis()));85 provisioningProfile = this.provisioningProfileRepository.save(provisioningProfile);86 }87 if (provFile != null) {88 log.info(String.format("Uploading Certificate mobile provisioning file for provisioningProfile [%s] - [%s]",89 provisioningProfile.getId(), provisioningProfile.getName()));90 File tempProvFile = File.createTempFile(provisioningProfile.getId() + CertificateService.MOBILE_PROVISION_FILE_SUFFIX,91 CertificateService.MOBILE_PROVISION_EXTENSION);92 provFile.transferTo(tempProvFile.toPath());93 parseDeviceInfoFromProvisioningProfile(tempProvFile, provisioningProfile);94 updateProvisioningProfile(tempProvFile, provisioningProfile);95 provisioningProfile.setStatus(ProvisioningProfileStatus.READY);96 provisioningProfile.setUpdatedDate(new Timestamp(System.currentTimeMillis()));97 provisioningProfileRepository.save(provisioningProfile);98 certificateService.setPreSignedURLs(provisioningProfile);99 ReSignTask reSignTask = new ReSignTask(webApplicationContext, provisioningProfile, null);100 ReSignTaskFactory.getInstance().startTask(reSignTask);101 }102 } catch (IOException e) {103 throw new TestsigmaException(e.getMessage(), e);104 }105 return provisioningProfile;106 }107 private void checkIfDevicesIsAlreadyProvisioned(List<String> deviceUDIDs, ProvisioningProfile provisioningProfile)108 throws TestsigmaException {109 List<ProvisioningProfileDevice> conflictingDevices = provisioningProfileDeviceService110 .findAllByDeviceUDIdInAndProvisioningProfileIdNot(deviceUDIDs, provisioningProfile.getId());111 if (conflictingDevices.size() > 0) {112 List<String> conflictingDeviceUDIDs = conflictingDevices.stream()113 .map(ProvisioningProfileDevice::getDeviceUDId).collect(Collectors.toList());114 String errorMsg = "These devices are already provisioned through difference provisioning profile"115 + conflictingDeviceUDIDs + " Devices with multiple provisioning profiles are not allowed.";116 throw new TestsigmaException(errorMsg, errorMsg);117 }118 }119 private void removeProvisionedDevicesNotInProvisioningProfile(List<String> deviceUDIDs, ProvisioningProfile provisioningProfile)120 throws TestsigmaException {121 List<ProvisioningProfileDevice> existingDevices = provisioningProfileDeviceService122 .findAllByProvisioningProfileId(provisioningProfile.getId());123 if (existingDevices.size() > 0) {124 List<String> existingDeviceUDIDs = existingDevices.stream()125 .map(ProvisioningProfileDevice::getDeviceUDId).collect(Collectors.toList());126 existingDeviceUDIDs.removeAll(deviceUDIDs);127 if (existingDeviceUDIDs.size() > 0) {128 log.info("Removing existing device from provisioning profile devices - " + existingDeviceUDIDs);129 List<ProvisioningProfileDevice> removableDevices = provisioningProfileDeviceService130 .findAllByDeviceUDIdIn(existingDeviceUDIDs);131 List<Long> removedAgentDeviceIds = removableDevices.stream()132 .map(ProvisioningProfileDevice::getAgentDeviceId).collect(Collectors.toList());133 List<TestDevice> testDeviceServices = testDeviceService134 .findAllByAgentDeviceIds(removedAgentDeviceIds);135 if (testDeviceServices.size() > 0) {136 List<Long> existingExecutionIds = testDeviceServices.stream()137 .map(TestDevice::getTestPlanId).collect(Collectors.toList());138 throw new TestsigmaException("There are bellow devices removed from provision profile but have executions ::"139 + existingExecutionIds);140 }141 provisioningProfileDeviceService.deleteAllByDeviceUDIDIn(existingDeviceUDIDs);142 }143 log.info("Final list of device UUID's post cleanup - " + deviceUDIDs);144 }145 }146 private void parseDeviceInfoFromProvisioningProfile(File tempProvFile, ProvisioningProfile provisioningProfile)147 throws TestsigmaException, IOException {148 List<String> deviceUDIDs = profileParserService.parseDevices(tempProvFile);149 String teamId = profileParserService.getTeamId(tempProvFile);150 log.info("Identified devices from provisioning profile - " + deviceUDIDs);151 log.info("Identified team id from provisioning profile - " + teamId);152 provisioningProfile.setDeviceUDIDs(deviceUDIDs);153 provisioningProfile.setTeamId(teamId);154 checkIfDevicesIsAlreadyProvisioned(deviceUDIDs, provisioningProfile);155 removeProvisionedDevicesNotInProvisioningProfile(deviceUDIDs, provisioningProfile);156 provisioningProfileDeviceService.create(deviceUDIDs, provisioningProfile);157 }158 private void updateCRT(MultipartFile cer, ProvisioningProfile provisioningProfile) throws TestsigmaException {159 try {160 String profilePathPrefix = certificateService.s3Prefix(provisioningProfile.getId());161 String certificateLocalName = provisioningProfile.getId()162 + CertificateService.CERTIFICATE_FILE_SUFFIX;163 String certificateS3Name = profilePathPrefix + CertificateService.CERTIFICATE_FILE_SUFFIX;164 File cerFile = File.createTempFile(certificateLocalName, CertificateService.CERTIFICATE_CER_EXTENSION);165 File crt = File.createTempFile(certificateLocalName, CertificateService.CERTIFICATE_CRT_EXTENSION);166 File pem = File.createTempFile(certificateLocalName, CertificateService.PEM_EXTENSION);167 cer.transferTo(cerFile.toPath());168 log.info(String.format("Uploading certificate(cer) for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),169 provisioningProfile.getName()));170 storageServiceFactory.getStorageService().addFile(certificateS3Name + CertificateService.CERTIFICATE_CER_EXTENSION, cerFile);171 log.info(String.format("Uploading certificate(crt) for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),172 provisioningProfile.getName()));173 certificateService.writeCRT(cerFile, crt);174 storageServiceFactory.getStorageService().addFile(certificateS3Name + CertificateService.CERTIFICATE_CRT_EXTENSION, crt);175 log.info(String.format("Uploading certificate(pem) for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),176 provisioningProfile.getName()));177 certificateService.writePem(crt, pem);178 storageServiceFactory.getStorageService().addFile(certificateS3Name + CertificateService.PEM_EXTENSION, pem);179 } catch (Exception e) {180 throw new TestsigmaException(e.getMessage(), e);181 }182 }183 private void updateProvisioningProfile(File provFile, ProvisioningProfile provisioningProfile) throws IOException {184 log.debug(String.format("Uploading ProvisioningProfile for provisioningProfile [%s] - [%s]",185 provisioningProfile.getId(), provisioningProfile.getName()));186 String profilePathPrefix = certificateService.s3Prefix(provisioningProfile.getId());187 storageServiceFactory.getStorageService().addFile(profilePathPrefix + CertificateService.MOBILE_PROVISION_FILE_SUFFIX188 + CertificateService.MOBILE_PROVISION_EXTENSION, provFile);189 }190 public void destroy(Long id) throws ResourceNotFoundException {191 ProvisioningProfile profile = find(id);192 this.provisioningProfileRepository.delete(profile);193 }194}...
Source:ResignService.java
...4import com.testsigma.config.StorageServiceFactory;5import com.testsigma.config.URLConstants;6import com.testsigma.model.*;7import com.testsigma.dto.ResignRequestUsingUrlsDTO;8import com.testsigma.exception.TestsigmaException;9import com.testsigma.util.HttpClient;10import com.testsigma.util.HttpResponse;11import lombok.RequiredArgsConstructor;12import lombok.extern.log4j.Log4j2;13import org.apache.commons.io.FileUtils;14import org.apache.commons.io.FilenameUtils;15import org.apache.http.Header;16import org.apache.http.HttpHeaders;17import org.apache.http.client.methods.HttpPut;18import org.apache.http.entity.ContentType;19import org.apache.http.entity.mime.HttpMultipartMode;20import org.apache.http.entity.mime.MultipartEntityBuilder;21import org.apache.http.entity.mime.content.FileBody;22import org.apache.http.entity.mime.content.StringBody;23import org.apache.http.impl.client.CloseableHttpClient;24import org.apache.http.impl.client.HttpClients;25import org.apache.http.message.BasicHeader;26import org.apache.logging.log4j.ThreadContext;27import org.springframework.beans.factory.annotation.Autowired;28import org.springframework.http.HttpStatus;29import org.springframework.stereotype.Service;30import java.io.*;31import java.net.MalformedURLException;32import java.net.URL;33import java.nio.file.Paths;34import java.util.ArrayList;35import java.util.List;36@Log4j237@Service38@RequiredArgsConstructor(onConstructor = @__({@Autowired}))39public class ResignService {40 private static final String ISIGN_USING_FILES_URL = "/api/sign/files";41 private static final String ISIGN_USING_URLS_URL = "/api/sign/urls";42 private final ProvisioningProfileUploadService provisioningProfileUploadService;43 private final HttpClient httpClient;44 private final CertificateService certificateService;45 private final UploadService uploadService;46 private final UploadVersionService uploadVersionService;47 private final StorageServiceFactory storageServiceFactory;48 private final TestsigmaOSConfigService testsigmaOSConfigService;49 public void reSignWda(ProvisioningProfile profile) throws TestsigmaException {50 log.info(String.format("Resigning wda.ipa file for provisioning profile [%s] - [%s]", profile.getId(),51 profile.getName()));52 certificateService.setPreSignedURLs(profile);53 String ipaName = profile.getId() + "_wda";54 String resignedPathPrefix = "wda/" + profile.getId() + "/wda.ipa";55 if (storageServiceFactory.getStorageService().getStorageType() == StorageType.ON_PREMISE) {56 File resignedIpa = resignUsingFiles(profile, ipaName, commonWdaS3Path());57 storageServiceFactory.getStorageService().addFile(resignedPathPrefix, resignedIpa);58 } else {59 resignUsingUrls(profile, ipaName, commonWdaS3Path(),60 storageServiceFactory.getStorageService().generatePreSignedURL(resignedPathPrefix, StorageAccessLevel.WRITE, 60));61 }62 }63 public void reSignUpload(ProvisioningProfile profile, UploadVersion uploadVersion) throws TestsigmaException {64 log.info(String.format("Resigning Upload [%s] - [%s] file for provisioning profile [%s] - [%s]",65 uploadVersion.getId(), uploadVersion.getName(), profile.getId(), profile.getName()));66 certificateService.setPreSignedURLs(profile);67 String ipaName = profile.getId() + "_" + uploadVersion.getId();68 String resignedPathPrefix = uploadVersion.getResignedAppS3PathSuffix(profile.getId());69 try {70 if (storageServiceFactory.getStorageService().getStorageType() == StorageType.ON_PREMISE) {71 File resignedIpa = resignUsingFiles(profile, ipaName, new URL(uploadVersionService.getPreSignedURL(uploadVersion)));72 storageServiceFactory.getStorageService().addFile(resignedPathPrefix, resignedIpa);73 } else {74 resignUsingUrls(profile, ipaName, new URL(uploadVersionService.getPreSignedURL(uploadVersion)),75 storageServiceFactory.getStorageService().generatePreSignedURL(resignedPathPrefix, StorageAccessLevel.WRITE, 60));76 }77 } catch (MalformedURLException e) {78 log.error(e.getMessage(), e);79 throw new TestsigmaException(e.getMessage(), e);80 }81 }82 public void resignPublicUrlApp(ProvisioningProfile profile, String presignedAppUrl, String resignedPathSuffix)83 throws TestsigmaException {84 log.info(String.format("Resigning App [%s] - [%s] file for provisioning profile [%s] - [%s]",85 presignedAppUrl, resignedPathSuffix, profile.getId(), profile.getName()));86 try {87 certificateService.setPreSignedURLs(profile);88 String ipaName = profile.getId() + "_" + FilenameUtils.getBaseName(new URL(presignedAppUrl).getPath());89 File resignedIpa = resignUsingFiles(profile, ipaName, new URL(presignedAppUrl));90 storageServiceFactory.getStorageService().addFile(resignedPathSuffix, resignedIpa);91 } catch (Exception e) {92 throw new TestsigmaException(e.getMessage(), e);93 }94 }95 public void reSignForAllProfiles(UploadVersion upload, List<ProvisioningProfile> profiles) throws TestsigmaException {96 provisioningProfileUploadService.removeEntitiesForUpload(upload);97 for (ProvisioningProfile profile : profiles) {98 reSignUpload(profile, upload);99 provisioningProfileUploadService.create(profile, upload);100 }101 }102 public void reSignAllUploads(ProvisioningProfile profile, List<UploadVersion> uploadVersions)103 throws TestsigmaException {104 provisioningProfileUploadService.removeEntitiesForProfile(profile);105 for (UploadVersion uploadVersion : uploadVersions) {106 try {107 reSignUpload(profile, uploadVersion);108 provisioningProfileUploadService.create(profile, uploadVersion);109 } catch (Exception e) {110 log.error(e.getMessage(), e);111 }112 }113 }114 public URL commonWdaS3Path() throws TestsigmaException {115 ArrayList<Header> headers = new ArrayList<>();116 headers.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));117 HttpResponse<String> response = httpClient.get(testsigmaOSConfigService.getUrl() +118 URLConstants.TESTSIGMA_OS_PUBLIC_WDA_URL, headers, new TypeReference<>() {119 });120 try {121 return new URL(response.getResponseEntity());122 } catch (MalformedURLException e) {123 throw new TestsigmaException(e.getMessage(), e);124 }125 }126 private List<Header> getResignHeaders() {127 Header authorization = new BasicHeader(org.apache.http.HttpHeaders.AUTHORIZATION, "Bearer " + testsigmaOSConfigService.find().getAccessKey());128 Header accept = new BasicHeader(HttpHeaders.ACCEPT, "*/*");129 return Lists.newArrayList(authorization, accept);130 }131 public File resignUsingFiles(ProvisioningProfile profile, String name, URL ipaUrl)132 throws TestsigmaException {133 File ipa = new File(ThreadContext.get("X-Request-Id") + "_" + name + ".ipa");134 try {135 certificateService.setPreSignedURLs(profile);136 CloseableHttpClient httpClient = HttpClients.custom().build();137 List<Header> headers = getResignHeaders();138 String url = testsigmaOSConfigService.getUrl() + ISIGN_USING_FILES_URL;139 log.info(String.format("Sending a resign request for file %s to server url %s", name, url));140 HttpPut putRequest = new HttpPut(url);141 putRequest.setHeaders(headers.toArray(Header[]::new));142 MultipartEntityBuilder builder = MultipartEntityBuilder.create();143 builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);144 builder.addPart("certificate", copyUrlToFile(profile.getCertificateCrtPresignedUrl()));145 builder.addPart("privateKey", copyUrlToFile(profile.getPrivateKeyPresignedUrl()));146 builder.addPart("provisioningProfile", copyUrlToFile(profile.getProvisioningProfilePresignedUrl()));147 builder.addPart("ipa", copyUrlToFile(ipaUrl));148 builder.addPart("name", new StringBody(name, ContentType.MULTIPART_FORM_DATA));149 putRequest.setEntity(builder.build());150 org.apache.http.HttpResponse res = httpClient.execute(putRequest);151 Integer status = res.getStatusLine().getStatusCode();152 log.info("Resign Using Files Service Response - " + status);153 if (status.equals(HttpStatus.OK.value())) {154 BufferedInputStream bis = new BufferedInputStream(res.getEntity().getContent());155 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(ipa));156 int inByte;157 while ((inByte = bis.read()) != -1) bos.write(inByte);158 bis.close();159 bos.close();160 }161 } catch (Exception e) {162 log.error(e.getMessage(), e);163 throw new TestsigmaException(e);164 }165 return ipa;166 }167 public void resignUsingUrls(ProvisioningProfile profile, String name, URL ipaUrl, URL resignedIpaUrl)168 throws TestsigmaException {169 certificateService.setPreSignedURLs(profile);170 ResignRequestUsingUrlsDTO resignRequestUsingUrlsDTO = new ResignRequestUsingUrlsDTO();171 resignRequestUsingUrlsDTO.setCertificate(profile.getCertificateCrtPresignedUrl());172 resignRequestUsingUrlsDTO.setPrivateKey(profile.getPrivateKeyPresignedUrl());173 resignRequestUsingUrlsDTO.setProvisioningProfile(profile.getProvisioningProfilePresignedUrl());174 resignRequestUsingUrlsDTO.setIpa(ipaUrl);175 resignRequestUsingUrlsDTO.setResignedIpa(resignedIpaUrl);176 resignRequestUsingUrlsDTO.setName(name);177 HttpResponse<String> response = httpClient.put(testsigmaOSConfigService.getUrl()178 + ISIGN_USING_URLS_URL,179 getResignHeaders(),180 resignRequestUsingUrlsDTO, new TypeReference<>() {181 });182 log.info("Resign Service Response - " + response);183 if (response.getStatusCode() >= 300) {184 throw new TestsigmaException(String.format("Exception while re-signing the " + name + " ipa file [%s] - [%s]"185 , response.getStatusCode(), response.getStatusMessage()));186 }187 }188 private FileBody copyUrlToFile(URL url) throws IOException {189 String fileName = getFileName(url);190 File localFile = Paths.get(System.getProperty("java.io.tmpdir"), fileName).toFile();191 FileUtils.copyURLToFile(url, localFile, (60 * 1000), (60 * 1000));192 return new FileBody(localFile, ContentType.DEFAULT_BINARY);193 }194 private String getFileName(URL url) {195 String fileName = FilenameUtils.getName(url.getPath());196 if (fileName.indexOf("?") > 0) {197 fileName = fileName.substring(0, fileName.indexOf("?"));198 }...
TestsigmaException
Using AI Code Generation
1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileNotFoundException;5import java.io.IOException;6import java.security.KeyStore;7import java.security.KeyStoreException;8import java.security.NoSuchAlgorithmException;9import java.security.UnrecoverableEntryException;10import java.security.cert.Certificate;11import java.security.cert.CertificateException;12import java.security.cert.X509Certificate;13import java.util.ArrayList;14import java.util.Enumeration;15import java.util.List;16import org.apache.commons.io.IOUtils;17public class CertificateService {18 public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableEntryException {19 CertificateService certificateService = new CertificateService();20 List<Certificate> certificates = certificateService.getCertificates("C:\\Users\\sudhanshu\\Desktop\\Testsigma.com.p12", "testsigma");21 for (Certificate certificate : certificates) {22 System.out.println(certificate.toString());23 }24 }25 public List<Certificate> getCertificates(String p12File, String password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableEntryException {26 KeyStore keyStore = KeyStore.getInstance("PKCS12");27 keyStore.load(new FileInputStream(new File(p12File)), password.toCharArray());28 Enumeration<String> aliases = keyStore.aliases();29 List<Certificate> certificates = new ArrayList<Certificate>();30 while (aliases.hasMoreElements()) {31 String alias = aliases.nextElement();32 Certificate certificate = keyStore.getCertificate(alias);33 certificates.add(certificate);34 }35 return certificates;36 }37 public void TestsigmaException() throws CertificateException {38 throw new CertificateException("Testsigma Exception");39 }40}41package com.testsigma.service;42import java.io.File;43import java.io.FileInputStream;44import java.io.FileNotFoundException;45import java.io.IOException;46import java.security.KeyStore;47import java.security.KeyStoreException;48import java.security.NoSuchAlgorithmException;49import java.security.UnrecoverableEntryException;50import java.security.cert.Certificate;51import java.security.cert.CertificateException;52import java.security.cert.X509Certificate;53import java.util.ArrayList;54import java.util.Enumeration;55import java.util.List;56import org.apache.commons.io.IOUtils;57public class CertificateService {58 public static void main(String[] args) throws KeyStoreException
TestsigmaException
Using AI Code Generation
1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileOutputStream;5import java.io.IOException;6import java.security.KeyStore;7import java.security.KeyStoreException;8import java.security.NoSuchAlgorithmException;9import java.security.cert.Certificate;10import java.security.cert.CertificateException;11import java.util.Enumeration;12import com.testsigma.exception.TestsigmaException;13public class CertificateService {14public static void main(String[] args) throws TestsigmaException {15CertificateService certificateService = new CertificateService();16certificateService.getKeystoreCertificate();17}18public void getKeystoreCertificate() throws TestsigmaException {19try {20File file = new File("C:\\Users\\Testsigma\\Desktop\\keystore.jks");21FileInputStream is = new FileInputStream(file);22KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());23String password = "password";24keystore.load(is, password.toCharArray());25Enumeration<String> enumeration = keystore.aliases();26String alias = "";27while (enumeration.hasMoreElements()) {28alias = (String) enumeration.nextElement();29System.out.println("alias name: " + alias);30}31Certificate certificate = keystore.getCertificate(alias);32System.out.println("certificate: " + certificate);33System.out.println("certificate type: " + certificate.getType());34FileOutputStream os = new FileOutputStream("C:\\Users\\Testsigma\\Desktop\\cert.cer");35os.write(certificate.getEncoded());36os.close();37} catch (KeyStoreException e) {38throw new TestsigmaException(e);39} catch (NoSuchAlgorithmException e) {40throw new TestsigmaException(e);41} catch (CertificateException e) {42throw new TestsigmaException(e);43} catch (IOException e) {44throw new TestsigmaException(e);45}46}47}48package com.testsigma.service;49import java.io.File;50import java.io.FileInputStream;51import java.io.FileOutputStream;52import java.io.IOException;53import java.security.KeyStore;54import java.security.KeyStoreException;55import java.security.NoSuchAlgorithmException;56import java.security.cert.Certificate;57import java.security.cert.CertificateException;58import java.util.Enumeration;59import com.testsigma.exception.TestsigmaException;60public class CertificateService {61public static void main(String[] args) throws TestsigmaException {62CertificateService certificateService = new CertificateService();63certificateService.getKeystoreCertificate();64}65public void getKeystoreCertificate() throws TestsigmaException {66try {
TestsigmaException
Using AI Code Generation
1import com.testsigma.service.CertificateService;2import com.testsigma.service.TestsigmaException;3public class 2 {4 public static void main(String[] args) {5 CertificateService certificateService = new CertificateService();6 try {7 certificateService.TestsigmaException();8 } catch (TestsigmaException e) {9 e.printStackTrace();10 }11 }12}13import com.testsigma.service.CertificateService;14import com.testsigma.service.TestsigmaException;15public class 3 {16 public static void main(String[] args) {17 CertificateService certificateService = new CertificateService();18 try {19 certificateService.TestsigmaException();20 } catch (TestsigmaException e) {21 e.printStackTrace();22 }23 }24}25import com.testsigma.service.CertificateService;26import com.testsigma.service.TestsigmaException;27public class 4 {28 public static void main(String[] args) {29 CertificateService certificateService = new CertificateService();30 try {31 certificateService.TestsigmaException();32 } catch (TestsigmaException e) {33 e.printStackTrace();34 }35 }36}37import com.testsigma.service.CertificateService;38import com.testsigma.service.TestsigmaException;39public class 5 {40 public static void main(String[] args) {41 CertificateService certificateService = new CertificateService();42 try {43 certificateService.TestsigmaException();44 } catch (TestsigmaException e) {45 e.printStackTrace();46 }47 }48}49import com.testsigma.service.CertificateService;50import com.testsigma.service.TestsigmaException;51public class 6 {52 public static void main(String[] args) {53 CertificateService certificateService = new CertificateService();54 try {55 certificateService.TestsigmaException();56 } catch (TestsigmaException e) {57 e.printStackTrace();58 }59 }60}61import com.testsigma.service.CertificateService;62import com.testsigma
TestsigmaException
Using AI Code Generation
1import com.testsigma.service.CertificateService;2import com.testsigma.service.CertificateServiceService;3import com.testsigma.service.CertificateServiceServiceLocator;4public class TestsigmaException {5 public static void main(String[] args) {6 try {7 CertificateServiceService service = new CertificateServiceServiceLocator();8 CertificateService port = service.getCertificateServicePort();9 port.testsigmaException();10 } catch (Exception e) {11 e.printStackTrace();12 }13 }14}15import com.testsigma.service.CertificateService;16import com.testsigma.service.CertificateServiceService;17import com.testsigma.service.CertificateServiceServiceLocator;18public class TestsigmaException {19 public static void main(String[] args) {20 try {21 CertificateServiceService service = new CertificateServiceServiceLocator();22 CertificateService port = service.getCertificateServicePort();23 port.testsigmaException();24 } catch (Exception e) {25 e.printStackTrace();26 }27 }28}29import com.testsigma.service.CertificateService;30import com.testsigma.service.CertificateServiceService;31import com.testsigma.service.CertificateServiceServiceLocator;32public class TestsigmaException {33 public static void main(String[] args) {34 try {35 CertificateServiceService service = new CertificateServiceServiceLocator();36 CertificateService port = service.getCertificateServicePort();37 port.testsigmaException();38 } catch (Exception e) {39 e.printStackTrace();40 }41 }42}43import com.testsigma.service.CertificateService;44import com.testsigma.service.CertificateServiceService;45import com.testsigma.service.CertificateServiceServiceLocator;46public class TestsigmaException {47 public static void main(String[] args) {48 try {49 CertificateServiceService service = new CertificateServiceServiceLocator();50 CertificateService port = service.getCertificateServicePort();51 port.testsigmaException();52 } catch (Exception e) {53 e.printStackTrace();54 }55 }56}57import com.testsigma.service.C
TestsigmaException
Using AI Code Generation
1import com.testsigma.service.CertificateService;2import com.testsigma.service.TestsigmaException;3import java.util.List;4import java.util.ArrayList;5import java.util.Map;6import java.util.HashMap;7import java.util.Iterator;8import java.util.Set;9import java.util.HashSet;10import java.util.Collections;11import java.util.Date;12import java.util.Calendar;13import java.util.TimeZone;14import java.util.TimeZone;15import java.util.Locale;16import java.io.File;17import java.io.IOException;18import java.io.InputStream;19import java.io.FileInputStream;20import java.io.FileNotFoundException;21import java.io.FileOutputStream;22import java.io.OutputStream;23import java.io.BufferedOutputStream;24import java.io.BufferedInputStream;25import java.io.ByteArrayInputStream;26import java.io.ByteArrayOutputStream;27import java.io.DataInputStream;28import java.io.DataOutputStream;29import java.io.PrintWriter;30import java.io.StringWriter;31import java.io.UnsupportedEncodingException;32import java.io.BufferedReader;33import java.io.InputStreamReader;34import java.io.Reader;35import java.io.FileReader;36import java.io.FileWriter;37import java.io.BufferedWriter;38import java.io.Writer;39import java.io.ObjectInputStream;40import java.io.ObjectOutputStream;41import java.io.Serializable;42import java.io.ObjectStreamClass;43import java.io.ObjectStreamField;44import java.io.Closeable;45import java.io.SerializablePermission;46import java.io.ObjectStreamConstants;47import java.io.Externalizable;48import java.io.NotSerializableException;49import java.io.InvalidObjectException;50import java.io.NotActiveException;51import java.io.StreamCorruptedException;52import java.io.OptionalDataException;53import java.io.EOFException;54import java.io.ObjectInputValidation;55import java.io.ObjectInput;56import java.io.ObjectOutput;57import java.io.ObjectOutputStream.PutField;58import java.io.ObjectOutputStream.GetField;59import java.io.InvalidClassException;60import java.io.InvalidClassException;61import java.io.ObjectStreamException;62import java.io.WriteAbortedException;63import java.io.NotActiveException;64import java.io.StreamCorruptedException;65import java.io.OptionalDataException;66import java.io.InvalidClassException;67import java.io.ObjectStreamException;68import java.io.NotActiveException;69import java.io.StreamCorruptedException;70import java.io.OptionalDataException;71import java.io.InvalidClassException;72import java.io.ObjectStreamException;73import java.io.NotActiveException;74import java.io.StreamCorruptedException;75import java.io.OptionalDataException;76import java.io.InvalidClassException;77import java.io.ObjectStreamException;78import java.io.NotActiveException;79import java.io.StreamCorruptedException;80import java.io
TestsigmaException
Using AI Code Generation
1package com.testsigma.service;2import java.io.IOException;3import org.testng.annotations.Test;4public class TestCertificateService {5public void testCertificateService() throws TestsigmaException, IOException {6CertificateService certificateService = new CertificateService();7}8}9package com.testsigma.service;10import java.io.File;11import java.io.FileOutputStream;12import java.io.IOException;13import java.security.KeyPair;14import java.security.KeyPairGenerator;15import java.security.NoSuchAlgorithmException;16import java.security.PrivateKey;17import java.security.PublicKey;18import java.security.SecureRandom;19import java.security.cert.Certificate;20import java.security.cert.CertificateEncodingException;21import java.security.cert.CertificateException;22import java.security.cert.CertificateFactory;23import java.security.cert.X509Certificate;24import java.util.Date;25import org.bouncycastle.asn1.x500.X500Name;26import org.bouncycastle.asn1.x509.BasicConstraints;27import org.bouncycastle.asn1.x509.Extension;28import org.bouncycastle.asn1.x509.KeyUsage;29import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;30import org.bouncycastle.cert.X509v3CertificateBuilder;31import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;32import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;33import org.bouncycastle.crypto.params.AsymmetricKeyParameter;34import org.bouncycastle.crypto.util.PrivateKeyFactory;35import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory;36import org.bouncycastle.jce.provider.BouncyCastleProvider;37import org.bouncycastle.operator.ContentSigner;38import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;39import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;40import org.bouncycastle.operator.OperatorCreationException;41import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;42import org.bouncycastle.pkcs.PKCS10CertificationRequest;43public class CertificateService {44private static final String SIGNATURE_ALGORITHM = "SHA256WithRSAEncryption";45private static final String KEY_ALGORITHM = "RSA";46private static final String PROVIDER = "BC";47public Certificate generateCertificate(PKCS10CertificationRequest csr, String issuerName, Date startDate, Date expiryDate, int serialNumber) throws TestsigmaException {48try {49import com.testsigma.service.C
TestsigmaException
Using AI Code Generation
1import com.testsigma.service.CertificateService;2import com.testsigma.service.TestsigmaException;3import java.util.List;4import java.util.ArrayList;5import java.util.Map;6import java.util.HashMap;7import java.util.Iterator;8import java.util.Set;9import java.util.HashSet;10import java.util.Collections;11import java.util.Date;12import java.util.Calendar;13import java.util.TimeZone;14import java.util.TimeZone;15import java.util.Locale;16import java.io.File;17import java.io.IOException;18import java.io.InputStream;19import java.io.FileInputStream;20import java.io.FileNotFoundException;21import java.io.FileOutputStream;22import java.io.OutputStream;23import java.io.BufferedOutputStream;24import java.io.BufferedInputStream;25import java.io.ByteArrayInputStream;26import java.io.ByteArrayOutputStream;27import java.io.DataInputStream;28import java.io.DataOutputStream;29import java.io.PrintWriter;30import java.io.StringWriter;31import java.io.UnsupportedEncodingException;32import java.io.BufferedReader;33import java.io.InputStreamReader;34import java.io.Reader;35import java.io.FileReader;36import java.io.FileWriter;37import java.io.BufferedWriter;38import java.io.Writer;39import java.io.ObjectInputStream;40import java.io.ObjectOutputStream;41import java.io.Serializable;42import java.io.ObjectStreamClass;43import java.io.ObjectStreamField;44import java.io.Closeable;45import java.io.SerializablePermission;46import java.io.ObjectStreamConstants;47import java.io.Externalizable;48import java.io.NotSerializableException;49import java.io.InvalidObjectException;50import java.io.NotActiveException;51import java.io.StreamCorruptedException;52import java.io.OptionalDataException;53import java.io.EOFException;54import java.io.ObjectInputValidation;55import java.io.ObjectInput;56import java.io.ObjectOutput;57import java.io.ObjectOutputStream.PutField;58import java.io.ObjectOutputStream.GetField;59import java.io.InvalidClassException;60import java.io.InvalidClassException;61import java.io.ObjectStreamException;62import java.io.WriteAbortedException;63import java.io.NotActiveException;64import java.io.StreamCorruptedException;65import java.io.OptionalDataException;66import java.io.InvalidClassException;67import java.io.ObjectStreamException;68import java.io.NotActiveException;69import java.io.StreamCorruptedException;70import java.io.OptionalDataException;71import java.io.InvalidClassException;72import java.io.ObjectStreamException;73import java.io.NotActiveException;74import java.io.StreamCorruptedException;75import java.io.OptionalDataException;76import java.io.InvalidClassException;77import java.io.ObjectStreamException;78import java.io.NotActiveException;79import java.io.StreamCorruptedException;80import java.io
TestsigmaException
Using AI Code Generation
1package com.testsigma.service;2import java.io.IOException;3import org.testng.annotations.Test;4public class TestCertificateService {5public void testCertificateService() throws TestsigmaException, IOException {6CertificateService certificateService = new CertificateService();7}8}9package com.testsigma.service;10import java.io.File;11import java.io.FileOutputStream;12import java.io.IOException;13import java.security.KeyPair;14import java.security.KeyPairGenerator;15import java.security.NoSuchAlgorithmException;16import java.security.PrivateKey;17import java.security.PublicKey;18import java.security.SecureRandom;19import java.security.cert.Certificate;20import java.security.cert.CertificateEncodingException;21import java.security.cert.CertificateException;22import java.security.cert.CertificateFactory;23import java.security.cert.X509Certificate;24import java.util.Date;25import org.bouncycastle.asn1.x500.X500Name;26import org.bouncycastle.asn1.x509.BasicConstraints;27import org.bouncycastle.asn1.x509.Extension;28import org.bouncycastle.asn1.x509.KeyUsage;29import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;30import org.bouncycastle.cert.X509v3CertificateBuilder;31import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;32import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;33import org.bouncycastle.crypto.params.AsymmetricKeyParameter;34import org.bouncycastle.crypto.util.PrivateKeyFactory;35import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory;36import org.bouncycastle.jce.provider.BouncyCastleProvider;37import org.bouncycastle.operator.ContentSigner;38import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;39import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;40import org.bouncycastle.operator.OperatorCreationException;41import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;42import org.bouncycastle.pkcs.PKCS10CertificationRequest;43public class CertificateService {44private static final String SIGNATURE_ALGORITHM = "SHA256WithRSAEncryption";45private static final String KEY_ALGORITHM = "RSA";46private static final String PROVIDER = "BC";47public Certificate generateCertificate(PKCS10CertificationRequest csr, String issuerName, Date startDate, Date expiryDate, int serialNumber) throws TestsigmaException {48try {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!