Fix: various coverity charset issues.
authorFelix Dörre <felix@dogcraft.de>
Fri, 20 Feb 2015 00:16:51 +0000 (01:16 +0100)
committerFelix Dörre <felix@dogcraft.de>
Fri, 20 Feb 2015 00:16:51 +0000 (01:16 +0100)
16 files changed:
src/org/cacert/gigi/DevelLauncher.java
src/org/cacert/gigi/email/EmailProvider.java
src/org/cacert/gigi/email/Sendmail.java
src/org/cacert/gigi/ping/SSLPinger.java
tests/org/cacert/gigi/api/IssueCert.java
tests/org/cacert/gigi/crypto/TestSPKAC.java
tests/org/cacert/gigi/email/TestSendmail.java
tests/org/cacert/gigi/pages/account/TestCertificateAdd.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java
tests/org/cacert/gigi/ping/TestHTTP.java
tests/org/cacert/gigi/testUtils/ManagedTest.java
tests/org/cacert/gigi/testUtils/PingTest.java
tests/org/cacert/gigi/testUtils/TestEmailReciever.java
util-testing/org/cacert/gigi/util/SimpleSigner.java
util/org/cacert/gigi/util/DatabaseManager.java
util/org/cacert/gigi/util/FetchLocales.java

index 5e0235939ea5b80fb1b0f392a3d8a65fd480f751..fe19ebd479250362b90e22afa29927f34ae1be4c 100644 (file)
@@ -54,7 +54,7 @@ public class DevelLauncher {
         byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
         byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
 
-        DevelLauncher.writeGigiConfig(dos, "changeit".getBytes(), "changeit".getBytes(), mainProps, cacerts, keystore);
+        DevelLauncher.writeGigiConfig(dos, "changeit".getBytes("UTF-8"), "changeit".getBytes("UTF-8"), mainProps, cacerts, keystore);
         dos.flush();
         InputStream oldin = System.in;
         System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
index 918d7da34a4caed5f5fec3cf5053a5720647972d..d76fd6ef1d185f002b76a464717bb170e28035ea 100644 (file)
@@ -3,6 +3,7 @@ package org.cacert.gigi.email;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.net.Socket;
 import java.security.GeneralSecurityException;
@@ -87,7 +88,8 @@ public abstract class EmailProvider {
                 } else {
                     return "Strange MX records.";
                 }
-                try (Socket s = new Socket(host, 25); BufferedReader br0 = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8")); PrintWriter pw0 = new PrintWriter(s.getOutputStream())) {
+                try (Socket s = new Socket(host, 25); BufferedReader br0 = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8"));//
+                        PrintWriter pw0 = new PrintWriter(new OutputStreamWriter(s.getOutputStream(), "UTF-8"))) {
                     BufferedReader br = br0;
                     PrintWriter pw = pw0;
                     String line;
index c12523611ac09d9b93565bba01d5bd5568ca123d..2c8958cb443cc48fdfbe92dfdf2ea8b8777b90aa 100644 (file)
@@ -28,7 +28,7 @@ public class Sendmail extends EmailProvider {
 
         Socket smtp = new Socket("localhost", 25);
         PrintWriter out = new PrintWriter(smtp.getOutputStream());
-        BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream()));
+        BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream(), "UTF-8"));
         readSMTPResponse(in, 220);
         out.print("HELO www.cacert.org\r\n");
         out.flush();
index ec63a787d98e866c535baa419576fb17c5dd10a5..85189e9c05beed6e8cbf33d89afd9ef1917fd0da 100644 (file)
@@ -85,7 +85,7 @@ public class SSLPinger extends DomainPinger {
         Socket s = sch.socket();
         InputStream is = s.getInputStream();
         OutputStream os = s.getOutputStream();
-        os.write(("<stream:stream to=\"" + domain + "\" xmlns=\"jabber:" + (server ? "server" : "client") + "\"" + " xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">").getBytes());
+        os.write(("<stream:stream to=\"" + domain + "\" xmlns=\"jabber:" + (server ? "server" : "client") + "\"" + " xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">").getBytes("UTF-8"));
         os.flush();
         os.write("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>".getBytes("UTF-8"));
         os.flush();
index 6a6f320c4908c19c5ac94988163dec3f1fdb0297..83a20a98cb472f56f04b2204db05e5b5f52e6054 100644 (file)
@@ -37,7 +37,7 @@ public class IssueCert extends ClientTest {
         authenticateClientCert(pk, ce, connection);
         connection.setDoOutput(true);
         OutputStream os = connection.getOutputStream();
-        os.write(("csr=" + URLEncoder.encode(generatePEMCSR(kp, "CN=a b"), "UTF-8")).getBytes());
+        os.write(("csr=" + URLEncoder.encode(generatePEMCSR(kp, "CN=a b"), "UTF-8")).getBytes("UTF-8"));
         os.flush();
         assertEquals(connection.getResponseCode(), 200);
         String cert = IOUtils.readURL(new InputStreamReader(connection.getInputStream(), "UTF-8"));
index 9f02204533f50f0ac304845a16aa07719fb1d7d0..3dd39a2d5f13c62c9fee09bf93df23aa1b9e8fb9 100644 (file)
@@ -21,7 +21,7 @@ public class TestSPKAC {
 
     @Test
     public void testParse() throws GeneralSecurityException, IOException {
-        String spkac = IOUtils.readURL(new InputStreamReader(TestSPKAC.class.getResourceAsStream("sampleSPKAC.txt")));
+        String spkac = IOUtils.readURL(new InputStreamReader(TestSPKAC.class.getResourceAsStream("sampleSPKAC.txt"), "UTF-8"));
         SPKAC parsed = new SPKAC(Base64.getDecoder().decode(spkac.replaceAll("[\r\n]", "")));
         assertEquals("i am in the testcase", parsed.getChallenge());
         RSAKey k = ((RSAKey) parsed.getPubkey());
@@ -33,7 +33,7 @@ public class TestSPKAC {
 
     @Test
     public void testAddData() throws GeneralSecurityException, IOException {
-        String spkac = IOUtils.readURL(new InputStreamReader(TestSPKAC.class.getResourceAsStream("sampleSPKAC.txt")));
+        String spkac = IOUtils.readURL(new InputStreamReader(TestSPKAC.class.getResourceAsStream("sampleSPKAC.txt"), "UTF-8"));
         byte[] data = Base64.getDecoder().decode(spkac.replaceAll("[\r\n]", ""));
         byte[] tampered = new byte[data.length + 1];
         System.arraycopy(data, 0, tampered, 0, data.length);
index 962fa837f0ac1a0d734872e1fa939923a5816665..3b21541fc059eab3e83215d135279233fcea8d0e 100644 (file)
@@ -7,6 +7,7 @@ import static org.junit.Assume.*;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.net.Socket;
 import java.security.GeneralSecurityException;
@@ -52,7 +53,7 @@ public class TestSendmail extends ConfiguredTest {
         EmailProvider.getInstance().sendmail(succmail, subj, msg, "system@cacert.org", "system@cacert.org", "Testtarget", "Testsender", null, false);
 
         Socket s = SSLSocketFactory.getDefault().createSocket(imap, 993);
-        PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
+        PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream(), "UTF-8"), true);
         BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
         pw.println("a001 login " + imapuser + " " + pass);
         imapUntil(br, "a001");
index b22141eadc585d0f90261ecdf8a74cdf7c4ffa72..aa118973862eb2a2c0821fa83e7deaa52ce09713 100644 (file)
@@ -128,9 +128,9 @@ public class TestCertificateAdd extends ClientTest {
         huc.setRequestProperty("Cookie", cookie);
         huc.setDoOutput(true);
         OutputStream out = huc.getOutputStream();
-        out.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8")).getBytes());
-        out.write(("&profile=client&CN=a+b&SANs=" + URLEncoder.encode("email:" + email + "\n", "UTF-8")).getBytes());
-        out.write(("&hash_alg=SHA512&CCA=y").getBytes());
+        out.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8")).getBytes("UTF-8"));
+        out.write(("&profile=client&CN=a+b&SANs=" + URLEncoder.encode("email:" + email + "\n", "UTF-8")).getBytes("UTF-8"));
+        out.write(("&hash_alg=SHA512&CCA=y").getBytes("UTF-8"));
         URLConnection uc = authenticate(new URL(huc.getHeaderField("Location") + ".crt"));
         String crt = IOUtils.readURL(new InputStreamReader(uc.getInputStream(), "UTF-8"));
 
@@ -211,10 +211,10 @@ public class TestCertificateAdd extends ClientTest {
         huc.setRequestProperty("Cookie", cookie);
         huc.setDoOutput(true);
         OutputStream out = huc.getOutputStream();
-        out.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8")).getBytes());
-        out.write(("&profile=client&CN=a+b&SANs=" + URLEncoder.encode("email:" + email + "\n", "UTF-8")).getBytes());
-        out.write(("&hash_alg=SHA512&CCA=y&").getBytes());
-        out.write(validity.getBytes());
+        out.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8")).getBytes("UTF-8"));
+        out.write(("&profile=client&CN=a+b&SANs=" + URLEncoder.encode("email:" + email + "\n", "UTF-8")).getBytes("UTF-8"));
+        out.write(("&hash_alg=SHA512&CCA=y&").getBytes("UTF-8"));
+        out.write(validity.getBytes("UTF-8"));
 
         String certurl = huc.getHeaderField("Location");
         if (certurl == null) {
@@ -224,7 +224,7 @@ public class TestCertificateAdd extends ClientTest {
         String crt = IOUtils.readURL(new InputStreamReader(uc.getInputStream(), "UTF-8"));
 
         CertificateFactory cf = CertificateFactory.getInstance("X.509");
-        X509Certificate parsed = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(crt.getBytes()));
+        X509Certificate parsed = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(crt.getBytes("UTF-8")));
         return parsed;
     }
 
@@ -291,7 +291,7 @@ public class TestCertificateAdd extends ClientTest {
         HttpURLConnection uc = (HttpURLConnection) ncert.openConnection();
         uc.setRequestProperty("Cookie", cookie);
         uc.setDoOutput(true);
-        uc.getOutputStream().write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" + pem).getBytes());
+        uc.getOutputStream().write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" + pem).getBytes("UTF-8"));
         uc.getOutputStream().flush();
 
         return extractFormData(uc);
index f519fb4e4744c4cbab15a775200efc3d3228f0d0..a1d61940a5f4d78ad8867245e53793c57154cb77 100644 (file)
@@ -70,7 +70,7 @@ public class TestAssurance extends ManagedTest {
         URLConnection uc = u.openConnection();
         uc.setDoOutput(true);
         uc.addRequestProperty("Cookie", cookie);
-        uc.getOutputStream().write(("search&" + query).getBytes());
+        uc.getOutputStream().write(("search&" + query).getBytes("UTF-8"));
         uc.getOutputStream().flush();
 
         return IOUtils.readURL(uc);
@@ -86,7 +86,7 @@ public class TestAssurance extends ManagedTest {
     public void testAssureFormNoCSRF() throws IOException {
         // override csrf
         HttpURLConnection uc = (HttpURLConnection) buildupAssureFormConnection(false);
-        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10").getBytes());
+        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10").getBytes("UTF-8"));
         uc.getOutputStream().flush();
         assertEquals(500, uc.getResponseCode());
     }
@@ -95,7 +95,7 @@ public class TestAssurance extends ManagedTest {
     public void testAssureFormWrongCSRF() throws IOException {
         // override csrf
         HttpURLConnection uc = (HttpURLConnection) buildupAssureFormConnection(false);
-        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10&csrf=aragc").getBytes());
+        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10&csrf=aragc").getBytes("UTF-8"));
         uc.getOutputStream().flush();
         assertEquals(500, uc.getResponseCode());
     }
@@ -119,7 +119,7 @@ public class TestAssurance extends ManagedTest {
 
         assertNull(executeBasicWebInteraction(assureeCookie, MyDetails.PATH, newName + "&" + newDob + "&processDetails", 0));
 
-        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10").getBytes());
+        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10").getBytes("UTF-8"));
         uc.getOutputStream().flush();
         String error = fetchStartErrorMessage(IOUtils.readURL(uc));
         assertTrue(error, !error.startsWith("</div>"));
@@ -189,7 +189,7 @@ public class TestAssurance extends ManagedTest {
 
     private String getError(String query) throws MalformedURLException, IOException {
         URLConnection uc = buildupAssureFormConnection(true);
-        uc.getOutputStream().write((query).getBytes());
+        uc.getOutputStream().write((query).getBytes("UTF-8"));
         uc.getOutputStream().flush();
         String error = fetchStartErrorMessage(IOUtils.readURL(uc));
         return error;
@@ -200,14 +200,14 @@ public class TestAssurance extends ManagedTest {
         URLConnection uc = u.openConnection();
         uc.addRequestProperty("Cookie", cookie);
         uc.setDoOutput(true);
-        uc.getOutputStream().write(("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes());
+        uc.getOutputStream().write(("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes("UTF-8"));
 
         String csrf = getCSRF(uc);
         uc = u.openConnection();
         uc.addRequestProperty("Cookie", cookie);
         uc.setDoOutput(true);
         if (doCSRF) {
-            uc.getOutputStream().write(("csrf=" + csrf + "&").getBytes());
+            uc.getOutputStream().write(("csrf=" + csrf + "&").getBytes("UTF-8"));
         }
         return uc;
     }
index 2cad443d0e6059e7bf53fbd81232d159ea26275d..6ee6f6e821cecc958eb2a338ea9503fd3437dd25 100644 (file)
@@ -105,7 +105,7 @@ public class TestHTTP extends PingTest {
         String httpDom = getTestProps().getProperty("domain.http");
         assumeNotNull(httpDom);
         URL u = new URL("http://" + httpDom + "/cacert-" + token + ".txt");
-        return IOUtils.readURL(new InputStreamReader(u.openStream())).trim();
+        return IOUtils.readURL(new InputStreamReader(u.openStream(), "UTF-8")).trim();
 
     }
 }
index 312c351e294aee8f6668109054b7c6d0e674f42a..4c3a8c9de640fdd9e6d0fcb249958f29d7c07d5b 100644 (file)
@@ -114,10 +114,10 @@ public class ManagedTest extends ConfiguredTest {
             byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
             byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
 
-            DevelLauncher.writeGigiConfig(toGigi, "changeit".getBytes(), "changeit".getBytes(), mainProps, cacerts, keystore);
+            DevelLauncher.writeGigiConfig(toGigi, "changeit".getBytes("UTF-8"), "changeit".getBytes("UTF-8"), mainProps, cacerts, keystore);
             toGigi.flush();
 
-            final BufferedReader br = new BufferedReader(new InputStreamReader(gigi.getErrorStream()));
+            final BufferedReader br = new BufferedReader(new InputStreamReader(gigi.getErrorStream(), "UTF-8"));
             String line;
             while ((line = br.readLine()) != null && !line.contains("Server:main: Started")) {
             }
@@ -246,7 +246,7 @@ public class ManagedTest extends ConfiguredTest {
         String csrf = getCSRF(csrfConn);
         uc.addRequestProperty("Cookie", headerField);
         uc.setDoOutput(true);
-        uc.getOutputStream().write((param + "&csrf=" + csrf).getBytes());
+        uc.getOutputStream().write((param + "&csrf=" + csrf).getBytes("UTF-8"));
         String d = IOUtils.readURL(uc);
         return d;
     }
@@ -295,7 +295,7 @@ public class ManagedTest extends ConfiguredTest {
     public static void grant(String email, Group g) throws IOException {
         HttpURLConnection huc = (HttpURLConnection) new URL("https://" + getServerName() + Manager.PATH).openConnection();
         huc.setDoOutput(true);
-        huc.getOutputStream().write(("addpriv=y&priv=" + URLEncoder.encode(g.getDatabaseName(), "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8")).getBytes());
+        huc.getOutputStream().write(("addpriv=y&priv=" + URLEncoder.encode(g.getDatabaseName(), "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8")).getBytes("UTF-8"));
         assertEquals(200, huc.getResponseCode());
     }
 
@@ -351,7 +351,7 @@ public class ManagedTest extends ConfiguredTest {
         huc.setDoOutput(true);
         OutputStream os = huc.getOutputStream();
         String data = "username=" + URLEncoder.encode(email, "UTF-8") + "&password=" + URLEncoder.encode(pw, "UTF-8") + "&csrf=" + URLEncoder.encode(csrf, "UTF-8");
-        os.write(data.getBytes());
+        os.write(data.getBytes("UTF-8"));
         os.flush();
         headerField = huc.getHeaderField("Set-Cookie");
         if (headerField == null) {
@@ -458,7 +458,7 @@ public class ManagedTest extends ConfiguredTest {
         OutputStream os = uc.getOutputStream();
         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
         + query//
-        ).getBytes());
+        ).getBytes("UTF-8"));
         os.flush();
         String error = fetchStartErrorMessage(IOUtils.readURL(uc));
         return error;
index 4fb49595c316e84a5e9452f14bd6ebb7e82fd991..20395878fb4411dc7251bd0166f8cfb2df0eef44 100644 (file)
@@ -50,7 +50,7 @@ public abstract class PingTest extends ClientTest {
         URLConnection openConnection = u.openConnection();
         openConnection.setRequestProperty("Cookie", cookie);
         openConnection.setDoOutput(true);
-        openConnection.getOutputStream().write(content.getBytes());
+        openConnection.getOutputStream().write(content.getBytes("UTF-8"));
         openConnection.getHeaderField("Location");
 
         String newcontent = IOUtils.readURL(cookie(u.openConnection(), cookie));
index 50e3aace1f1cd3ebe77ff8e1df7b46cffaf00a8b..b7cbc38999420b208af82d78c9f21846d99fc90a 100644 (file)
@@ -74,7 +74,7 @@ public class TestEmailReciever extends EmailProvider implements Runnable {
             URLConnection uc = u.openConnection();
             ManagedTest.cookie(uc, ManagedTest.stripCookie(csrfConn.getHeaderField("Set-Cookie")));
             uc.setDoOutput(true);
-            uc.getOutputStream().write((parts[1] + "&csrf=" + csrf).getBytes());
+            uc.getOutputStream().write((parts[1] + "&csrf=" + csrf).getBytes("UTF-8"));
             uc.connect();
             uc.getInputStream().close();
         }
index 32983a39f730426d2d188fe785885a1d7b6f06db..1c635c2e73a55082ea17124d3a8468293c3cb4ad 100644 (file)
@@ -3,11 +3,11 @@ package org.cacert.gigi.util;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.io.Reader;
 import java.math.BigInteger;
 import java.security.GeneralSecurityException;
 import java.security.cert.CertificateFactory;
@@ -58,7 +58,7 @@ public class SimpleSigner {
 
     public static void main(String[] args) throws IOException, SQLException, InterruptedException {
         Properties p = new Properties();
-        try (FileReader reader = new FileReader("config/gigi.properties")) {
+        try (Reader reader = new InputStreamReader(new FileInputStream("config/gigi.properties"), "UTF-8")) {
             p.load(reader);
         }
         DatabaseConnection.init(p);
@@ -322,7 +322,7 @@ public class SimpleSigner {
                         continue;
                     }
                 } else {
-                    BufferedReader br = new BufferedReader(new InputStreamReader(p1.getErrorStream()));
+                    BufferedReader br = new BufferedReader(new InputStreamReader(p1.getErrorStream(), "UTF-8"));
                     String s;
                     while ((s = br.readLine()) != null) {
                         System.out.println(s);
index 0e30463edd67a217abf78e93b7e86ab2dcbd9ae4..84c012c3586a55d564e43d747dd7a61528ce6c26 100644 (file)
@@ -2,9 +2,10 @@ package org.cacert.gigi.util;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
@@ -27,7 +28,7 @@ public class DatabaseManager {
         }
         if (args.length == 0) {
             Properties p = new Properties();
-            try (FileReader reader = new FileReader("config/gigi.properties")) {
+            try (Reader reader = new InputStreamReader(new FileInputStream("config/gigi.properties"), "UTF-8")) {
                 p.load(reader);
             }
             args = new String[] {
index 4c93021e9e38acf9f44e3ef947e2a885e27c9c8e..87beaacef16fa53275f2771e2e60a96f44f7fe05 100644 (file)
@@ -3,6 +3,7 @@ package org.cacert.gigi.util;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Scanner;
@@ -43,7 +44,7 @@ public class FetchLocales {
             doc.appendChild(doc.createElement("translations"));
             URL fetch = new URL(PO_URL_TEMPLATE.replace("%", lang));
             URLConnection uc = fetch.openConnection();
-            Scanner sc = new Scanner(uc.getInputStream());
+            Scanner sc = new Scanner(new InputStreamReader(uc.getInputStream(), "UTF-8"));
             String s = readLine(sc);
             StringBuffer contents = new StringBuffer();
             String id = "";