Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ikedam/feature/JENKIS-32376_ServerBasedDow…
…nloading [FIXED JENKINS-32376] Supports server-based downloading
- Loading branch information
Showing
6 changed files
with
243 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../jp/ikedam/jenkins/plugins/updatesitesmanager/internal/ExtendedCertJsonSignValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package jp.ikedam.jenkins.plugins.updatesitesmanager.internal; | ||
|
||
import jenkins.util.JSONSignatureValidator; | ||
import org.apache.tools.ant.filters.StringInputStream; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.cert.Certificate; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.TrustAnchor; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import static java.lang.String.format; | ||
|
||
/** | ||
* Adds provided cert to trust anchors when validating update center json | ||
* | ||
* @author lanwen (Merkushev Kirill) | ||
*/ | ||
public class ExtendedCertJsonSignValidator extends JSONSignatureValidator { | ||
private static final Logger LOGGER = Logger.getLogger(ExtendedCertJsonSignValidator.class.getName()); | ||
|
||
private String cert; | ||
|
||
public ExtendedCertJsonSignValidator(String id, String cert) { | ||
super(format("Update site with own cert for %s", id)); | ||
this.cert = cert; | ||
} | ||
|
||
@Override | ||
protected Set<TrustAnchor> loadTrustAnchors(CertificateFactory cf) throws IOException { | ||
Set<TrustAnchor> trustAnchors = super.loadTrustAnchors(cf); | ||
InputStream stream = null; | ||
try { | ||
stream = new StringInputStream(cert); | ||
Certificate certificate = cf.generateCertificate(stream); | ||
trustAnchors.add(new TrustAnchor((X509Certificate) certificate, null)); | ||
} catch (CertificateException e) { | ||
LOGGER.log(Level.SEVERE, e.getMessage(), e); | ||
} finally { | ||
if (stream != null) { | ||
stream.close(); | ||
stream = null; | ||
} | ||
} | ||
return trustAnchors; | ||
} | ||
} |
Oops, something went wrong.