Skip to content

Commit

Permalink
squid:S1943 - Classes and methods that rely on the default system enc…
Browse files Browse the repository at this point in the history
…oding should not be used.
  • Loading branch information
Faisal Hameed committed Apr 10, 2016
1 parent b3e388f commit ca2771f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
package org.jvnet.hudson.update_center;

import java.io.Closeable;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.File;
import java.io.FileWriter;
Expand All @@ -48,7 +50,7 @@ private static PrintWriter openIndexHtml(File dir) throws IOException {
if (dir==null) return new PrintWriter(new ByteArrayOutputStream()); // ignore output

dir.mkdirs();
return new PrintWriter(new FileWriter(new File(dir,"index.html")));
return new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(dir,"index.html")), "UTF-8"));
}

public IndexHtmlBuilder(PrintWriter out, String title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

/**
Expand All @@ -21,7 +23,7 @@ public LatestLinkBuilder(File dir) throws IOException {
System.out.println(String.format("Writing plugin symlinks and redirects to dir: %s", dir));

index = new IndexHtmlBuilder(dir,"Permalinks to latest files");
htaccess = new PrintWriter(new FileWriter(new File(dir,".htaccess")),true);
htaccess = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(dir,".htaccess"), true), "UTF-8"));

htaccess.println("# GENERATED. DO NOT MODIFY.");
// Redirect directive doesn't let us write redirect rules relative to the directory .htaccess exists,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public String getDigest() throws IOException {
while ((len=fin.read(buf,0,buf.length))>=0)
sig.update(buf,0,len);

return new String(Base64.encodeBase64(sig.digest()));
return new String(Base64.encodeBase64(sig.digest()), "UTF-8");
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private File loadIndex(String id, URL url) throws IOException, UnsupportedExisti

URLConnection con = url.openConnection();
if (url.getUserInfo()!=null) {
con.setRequestProperty("Authorization","Basic "+new sun.misc.BASE64Encoder().encode(url.getUserInfo().getBytes()));
con.setRequestProperty("Authorization","Basic "+new sun.misc.BASE64Encoder().encode(url.getUserInfo().getBytes("UTF-8")));
}

if (!expanded.exists() || !local.exists() || (local.lastModified()!=con.getLastModified() && !offlineIndex)) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jvnet/hudson/update_center/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public JSONObject sign(JSONObject o) throws GeneralSecurityException, IOExceptio
// and certificate chain
JSONArray a = new JSONArray();
for (X509Certificate cert : certs)
a.add(new String(Base64.encodeBase64(cert.getEncoded())));
a.add(new String(Base64.encodeBase64(cert.getEncoded()), "UTF-8"));
sign.put("certificates",a);

o.put("signature",sign);
Expand Down Expand Up @@ -165,11 +165,11 @@ public TeeOutputStream getOut() {
public void addRecord(JSONObject sign, String prefix) throws GeneralSecurityException, IOException {
// digest
byte[] digest = sha1.digest();
sign.put(prefix+"digest",new String(Base64.encodeBase64(digest)));
sign.put(prefix+"digest",new String(Base64.encodeBase64(digest), "UTF-8"));

// signature
byte[] s = sig.sign();
sign.put(prefix+"signature",new String(Base64.encodeBase64(s)));
sign.put(prefix+"signature",new String(Base64.encodeBase64(s), "UTF-8"));

// did the signature validate?
if (!verifier.verify(s))
Expand Down

0 comments on commit ca2771f

Please sign in to comment.