SSL error JRJC

Ameya Bhagat August 18, 2013

Is there a way to attach a file to Jira issue using JRJC 2.0 ? If yes, can you give me some examples of it? Also, is there a way to ignore ssl errors in JRJC? The following code (using earlier version of JRJC) gives SSL certificate validation error. If there is no way to ignore, from where can I get the certificate to add to my java keystore?

:

final java.net.URI jiraServerUri = new java.net.URI(<jira company url>);

FileInputStream fileStreamPath = new FileInputStream(filepath);

JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();

// final JiraRestClientFactory factory = new JiraRestClientFactory();

NullProgressMonitor pm = new NullProgressMonitor();

System.out.println("Server Url :"+jiraServerUri);

// JiraRestClient restClient = new JiraRestClient();

String newKey = <issue-key>;

final java.net.URI AttachmentUri = new java.net.URI(jiraServerUri+"/rest/api/2/issue/"+newKey+"/attachments");

JiraRestClient restClient = factory.createWithBasicHttpAuthentication(AttachmentUri,<username>,<password>);

Issue issue1 = restClient.getIssueClient().getIssue(newKey,pm);

System.out.println("URI :"+issue1.getAttachmentsUri());

//restClient.getIssueClient().addAttachment(pm,issue1.getAttachmentsUri(), fileStreamPath , imageName);

restClient.getIssueClient().addAttachment(pm,AttachmentUri, fileStreamPath, "Test Image");

// return attachmentfilepath;

3 answers

1 accepted

1 vote
Answer accepted
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 18, 2013

You can find example code for adding atachments in testAddAttachment:

https://bitbucket.org/atlassian/jira-rest-java-client/src/483536cf7956295b4e1f6d9a46aa9bcb7c21379b/test/src/test/java/it/AsynchronousIssueRestClientTest.java?at=master
 
For SSL problem you can just add certificate to keystore and use that keystore.
To get certificate you can use openssl command line tool:
 
openssl s_client -connect ${your-jira-url}:${ssl-port} -showcerts

How to add key to keystore: 
http://stackoverflow.com/questions/2893819/telling-java-to-accept-self-signed-ssl-certificate
 
How to tell java to use your keystore: 
http://stackoverflow.com/questions/5871279/java-ssl-and-cert-keystore
 
Puting this together:
# Get cert (you need copy the cert and save to file my.jks)
openssl s_client -connect localhost:8090 -showcerts 

# Add cert to keystore
keytool -import -v -trustcacerts -alias localhost-8090 -file some.cert -keystore my.jks -keypass changeit -storepass changeit

# Run app
java -Djavax.net.ssl.trustStore=my.jks ...

 

Ameya Bhagat August 19, 2013

Thank you for the response. I've added the certificate to my keystore and that error seems to have gone away. However, I'm getting the following error on getIssue:

"The method getIssue from type IssueRestClient refers to missing type Promise".

From where can I import com.atlassian.util.concurrent.Promise?

Here is my code:

final JiraRestClient client ;

final IssueRestClient issueClient = client.getIssueClient();

final Issue issue = issueClient.getIssue("TST-3").claim();

String str = "Wojtek";

final String filename1 = "my-test-file";

issueClient.addAttachment(issue.getAttachmentsUri(), new ByteArrayInputStream(str.getBytes("UTF-8")), filename1).claim();

final String filename2 = "my-picture.png";

final Issue issueWithAttachments = issueClient.getIssue("TST-3").claim();

Thank you. Your help is appreciated.

Ameya Bhagat August 19, 2013

Thank you for the response. I've added the certificate to my keystore and that error seems to have gone away. Why does the following not work:

final JiraRestClientFactory clientFactory = new AsynchronousJiraRestClientFactory();

It erros and tells me to change type of JiraRestClientFactory.

Thanks!

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 19, 2013

What exact version of JRJC do you use? How does look your dependency in pom.xml? Do you have also dependency to older version of JRJC?

It looks like you have incorrect dependency in pom.xml, as the code above looks fine to me.

Roberto Luis Rodriguez-Estevez June 24, 2015

Hello Aleksander, your hint, how to get certificate from (cloud/hosted) JIRA server using openssl (instead of IE/Internet Options/Content/Certificates… export) save me. Thank you! Best regards, Roberto.

Roberto Luis Rodriguez-Estevez June 24, 2015

I.e. How to get certificates from a JIRA server instance in the Atlassian cloud: openssl s_client -connect myJiraInstanceInTheCloud.atlassian.net:443 -showcerts

1 vote
Al Sko April 27, 2015

what if I don't want / can't add a certificate to some specific server?

how can I force JIRA Rest client Java library to accept expired certificates? 

0 votes
Ratheesh Nair September 26, 2013

JRJC is great, I belive it uses customized Apache HTTP Client internally, why not externalize this dependency and give an option for the user to specify a HttpClient instance. That will add the capability of setting custom HttpClient with SSL Context in it, thereby allowing both static certificate configuration (via Keystore) as well as dynamic setting of required certificates.

Most of the companies hosts JIRA under HTTPS protocol and assigns private certificates for each users.

thanks,

Ratheesh R Nair

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events