Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Problem connecting TSA using https

Avatar of tropocolo
tropocolo asked on
Java
8 Comments1 Solution654 ViewsLast Modified:
I want to know how use TSA to connect to https.
Actually I do this (I resume it)

To connect with the Server I try to include automatically the server's certificate when I receive it to elude this Exception:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

If you need, I can send all the project.

Thanks
TimeStampRequester respond =new TimeStampRequester(url);--> To process
the response of the TSA server
byte[] request = null;
request = respuesta.getTimeStampRequest(document,
"1.3.14.3.2.26");-->getTimeStampRequest explain below
byte[] response = null;
TimeStampResponse tsResponse = null;
response = respond.getTimeStampResponseFromRequest(request);-->
getTimeStampResponseFromRequest explain below
tsResponse = new TimeStampResponse(response);
File f = new File(this.parameters.tokenPath);
           FileOutputStream fos = new FileOutputStream(f);
           fos.write(tsResponse.getTimeStampToken().getEncoded());
           fos.flush();
           fos.close();
 
 public byte[]  getTimeStampRequest(byte[] inputDigest, String
hashAlgorithmOID) throws Exception {
 
       // Hash of date to stamp
       SHA1Digest digest = new SHA1Digest();
       digest.update(inputDigest, 0, inputDigest.length);
       byte[] digestValue = new byte[digest.getDigestSize()];
       digest.doFinal(digestValue, 0);
 
       DERObjectIdentifier sha1OID = new DERObjectIdentifier(hashAlgorithmOID);
       AlgorithmIdentifier algorithmId = new AlgorithmIdentifier(sha1OID);
       MessageImprint imprint = new MessageImprint(algorithmId, digestValue);
       Random random = new Random(new Date().getTime());
       long nonceLong = random.nextLong();
       BigInteger nonce = BigInteger.valueOf(nonceLong);
       String policyOID = "1.1.2";
       TimeStampReq request = new TimeStampReq(imprint, new
DERObjectIdentifier(policyOID),
               new DERInteger(nonce), new DERBoolean(true), null);
 
       byte[] req = request.toASN1Object().getDEREncoded();
       return req;
   }
 
public byte[] getTimeStampResponseFromRequest(byte[] req) throws Exception {
 
       DERSequence der = getDERSequence(req);
       TimeStampReq request = new TimeStampReq(der);
 
       PostMethod postMethod = new PostMethod(tsaUrl);
 
       ByteArrayRequestEntity requestByte = new
ByteArrayRequestEntity(request.getEncoded(),
"application/timestamp-query");
       postMethod.setRequestEntity(requestByte);
 
       HttpClient http_client = new HttpClient();
 
       http_client.executeMethod(postMethod);
       int status = postMethod.getStatusCode();
       if (status != 200) {
           throw new HttpException("Server error. Error code is " + status);
       }
       InputStream in = postMethod.getResponseBodyAsStream();
       ASN1InputStream asnIS = new ASN1InputStream(in);
       DERSequence s = (DERSequence) asnIS.readObject();
 
       //read TSP response
       TimeStampResp response = new TimeStampResp(s);
       byte[] resp = response.toASN1Object().getDEREncoded();
       return resp;
}
ASKER CERTIFIED SOLUTION
Avatar of tropocolo
tropocolo

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers