Bug 434711 - SignatureBlockProcessor can't handle special characters in
filenames
- Use UTF-8 Charset for all string constructions
Change-Id: If71a21be27682249d290605fb3040dc186be20d3
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/BERProcessor.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/BERProcessor.java
index 902cd8b..48ab732 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/BERProcessor.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/BERProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 IBM Corporation and others.
+ * Copyright (c) 2006, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -216,7 +216,7 @@
* @return the content from the current structure as a String.
*/
public String getString() {
- return new String(buffer, contentOffset, contentLength);
+ return new String(buffer, contentOffset, contentLength, SignedContentConstants.UTF8);
}
/**
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/PKCS7Processor.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/PKCS7Processor.java
index 7650083..eed079e 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/PKCS7Processor.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/PKCS7Processor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2006, 2014 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -194,7 +194,7 @@
eContentBER.stepOver();
// check time ends w/ 'Z'
- String dateString = new String(eContentBER.getBytes());
+ String dateString = new String(eContentBER.getBytes(), SignedContentConstants.UTF8);
if (!dateString.endsWith("Z")) //$NON-NLS-1$
throw new SignatureException("Wrong dateformat used in time-stamp token"); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignatureBlockProcessor.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignatureBlockProcessor.java
index bed2258..2d01cb1 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignatureBlockProcessor.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignatureBlockProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2007, 2014 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -8,7 +8,8 @@
******************************************************************************/
package org.eclipse.osgi.internal.signedcontent;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
@@ -127,7 +128,7 @@
*/
private void verifyManifestAndSignatureFile(byte[] manifestBytes, byte[] sfBytes) throws SignatureException {
- String sf = new String(sfBytes);
+ String sf = new String(sfBytes, SignedContentConstants.UTF8);
sf = stripContinuations(sf);
// check if there -Digest-Manfiest: header in the file
@@ -162,9 +163,9 @@
}
}
- private void populateMDResults(byte mfBuf[], SignerInfo signerInfo) throws NoSuchAlgorithmException, UnsupportedEncodingException {
+ private void populateMDResults(byte mfBuf[], SignerInfo signerInfo) throws NoSuchAlgorithmException {
// need to make a string from the MF file data bytes
- String mfStr = new String(mfBuf, "UTF-8"); //$NON-NLS-1$
+ String mfStr = new String(mfBuf, SignedContentConstants.UTF8);
// start parsing each entry in the MF String
int entryStartOffset = mfStr.indexOf(MF_ENTRY_NEWLN_NAME);
@@ -306,7 +307,7 @@
* Returns the Base64 encoded digest of the passed set of bytes.
*/
private static String calculateDigest(MessageDigest digest, byte[] bytes) {
- return new String(Base64.encode(digest.digest(bytes)));
+ return new String(Base64.encode(digest.digest(bytes)), SignedContentConstants.UTF8);
}
synchronized MessageDigest getMessageDigest(String algorithm) {
@@ -327,7 +328,7 @@
*/
private static String getDigAlgFromSF(byte SFBuf[]) {
// need to make a string from the MF file data bytes
- String mfStr = new String(SFBuf);
+ String mfStr = new String(SFBuf, SignedContentConstants.UTF8);
String entryStr = null;
// start parsing each entry in the MF String
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedContentConstants.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedContentConstants.java
index 352809e..adc32ce 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedContentConstants.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/signedcontent/SignedContentConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2006, 2014 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -9,6 +9,8 @@
package org.eclipse.osgi.internal.signedcontent;
+import java.nio.charset.Charset;
+
public interface SignedContentConstants {
public static final String SHA1_STR = "SHA1"; //$NON-NLS-1$
@@ -28,6 +30,7 @@
public static final String META_INF = "META-INF/"; //$NON-NLS-1$
public static final String META_INF_MANIFEST_MF = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
public static final String[] EMPTY_STRING = new String[0];
+ public static final Charset UTF8 = Charset.forName("UTF-8"); //$NON-NLS-1$
//
// following are variables and methods to cache the entries related data