You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2015/12/20 16:09:20 UTC
svn commit: r1721033 - in /santuario/xml-security-java/trunk: ./
src/main/java/org/apache/xml/security/algorithms/implementations/
src/main/java/org/apache/xml/security/stax/ext/
src/main/java/org/apache/xml/security/stax/impl/algorithms/ src/main/java...
Author: coheigea
Date: Sun Dec 20 15:09:20 2015
New Revision: 1721033
URL: http://svn.apache.org/viewvc?rev=1721033&view=rev
Log:
More PMD rules + consolidating some code
Removed:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/DSAUtils.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/ECDSAUtils.java
Modified:
santuario/xml-security-java/trunk/pom.xml
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/PKISignatureAlgorithm.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/ECKeyValueSecurityToken.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/JavaUtils.java
Modified: santuario/xml-security-java/trunk/pom.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/pom.xml?rev=1721033&r1=1721032&r2=1721033&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/pom.xml (original)
+++ santuario/xml-security-java/trunk/pom.xml Sun Dec 20 15:09:20 2015
@@ -113,6 +113,15 @@
<artifactId>maven-pmd-plugin</artifactId>
<version>3.5</version>
<configuration>
+ <rulesets>
+ <ruleset>/rulesets/java/basic.xml</ruleset>
+ <ruleset>/rulesets/java/braces.xml</ruleset>
+ <ruleset>/rulesets/java/unusedcode.xml</ruleset>
+ <ruleset>/rulesets/java/imports.xml</ruleset>
+ <ruleset>/rulesets/java/empty.xml</ruleset>
+ <ruleset>/rulesets/java/unnecessary.xml</ruleset>
+ <ruleset>/rulesets/java/migrating.xml</ruleset>
+ </rulesets>
<linkXRef>false</linkXRef>
<sourceEncoding>UTF-8</sourceEncoding>
<failOnViolation>true</failOnViolation>
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java?rev=1721033&r1=1721032&r2=1721033&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java Sun Dec 20 15:09:20 2015
@@ -66,45 +66,7 @@ public abstract class SignatureECDSA ext
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
public static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
-
- if (asn1Bytes.length < 8 || asn1Bytes[0] != 48) {
- throw new IOException("Invalid ASN.1 format of ECDSA signature");
- }
- int offset;
- if (asn1Bytes[1] > 0) {
- offset = 2;
- } else if (asn1Bytes[1] == (byte) 0x81) {
- offset = 3;
- } else {
- throw new IOException("Invalid ASN.1 format of ECDSA signature");
- }
-
- byte rLength = asn1Bytes[offset + 1];
- int i;
-
- for (i = rLength; i > 0 && asn1Bytes[offset + 2 + rLength - i] == 0; i--);
-
- byte sLength = asn1Bytes[offset + 2 + rLength + 1];
- int j;
-
- for (j = sLength;
- j > 0 && asn1Bytes[offset + 2 + rLength + 2 + sLength - j] == 0; j--);
-
- int rawLen = Math.max(i, j);
-
- if ((asn1Bytes[offset - 1] & 0xff) != asn1Bytes.length - offset
- || (asn1Bytes[offset - 1] & 0xff) != 2 + rLength + 2 + sLength
- || asn1Bytes[offset] != 2
- || asn1Bytes[offset + 2 + rLength] != 2) {
- throw new IOException("Invalid ASN.1 format of ECDSA signature");
- }
- byte xmldsigBytes[] = new byte[2*rawLen];
-
- System.arraycopy(asn1Bytes, offset + 2 + rLength - i, xmldsigBytes, rawLen - i, i);
- System.arraycopy(asn1Bytes, offset + 2 + rLength + 2 + sLength - j, xmldsigBytes,
- 2 * rawLen - j, j);
-
- return xmldsigBytes;
+ return ECDSAUtils.convertASN1toXMLDSIG(asn1Bytes);
}
/**
@@ -121,58 +83,7 @@ public abstract class SignatureECDSA ext
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
public static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
-
- int rawLen = xmldsigBytes.length/2;
-
- int i;
-
- for (i = rawLen; i > 0 && xmldsigBytes[rawLen - i] == 0; i--);
-
- int j = i;
-
- if (xmldsigBytes[rawLen - i] < 0) {
- j += 1;
- }
-
- int k;
-
- for (k = rawLen; k > 0 && xmldsigBytes[2*rawLen - k] == 0; k--);
-
- int l = k;
-
- if (xmldsigBytes[2*rawLen - k] < 0) {
- l += 1;
- }
-
- int len = 2 + j + 2 + l;
- if (len > 255) {
- throw new IOException("Invalid XMLDSIG format of ECDSA signature");
- }
- int offset;
- byte asn1Bytes[];
- if (len < 128) {
- asn1Bytes = new byte[2 + 2 + j + 2 + l];
- offset = 1;
- } else {
- asn1Bytes = new byte[3 + 2 + j + 2 + l];
- asn1Bytes[1] = (byte) 0x81;
- offset = 2;
- }
- asn1Bytes[0] = 48;
- asn1Bytes[offset++] = (byte) len;
- asn1Bytes[offset++] = 2;
- asn1Bytes[offset++] = (byte) j;
-
- System.arraycopy(xmldsigBytes, rawLen - i, asn1Bytes, offset + j - i, i);
-
- offset += j;
-
- asn1Bytes[offset++] = 2;
- asn1Bytes[offset++] = (byte) l;
-
- System.arraycopy(xmldsigBytes, 2*rawLen - k, asn1Bytes, offset + l - k, k);
-
- return asn1Bytes;
+ return ECDSAUtils.convertXMLDSIGtoASN1(xmldsigBytes);
}
/**
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java?rev=1721033&r1=1721032&r2=1721033&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java Sun Dec 20 15:09:20 2015
@@ -20,6 +20,7 @@ package org.apache.xml.security.stax.ext
import org.apache.commons.codec.binary.Base64;
import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.implementations.ECDSAUtils;
import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.keys.content.x509.XMLX509SKI;
import org.apache.xml.security.stax.config.TransformerAlgorithmMapper;
@@ -27,7 +28,6 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.ext.stax.XMLSecNamespace;
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
-import org.apache.xml.security.stax.impl.algorithms.ECDSAUtils;
import org.apache.xml.security.stax.impl.util.ConcreteLSInput;
import org.apache.xml.security.stax.securityEvent.*;
import org.apache.xml.security.stax.securityToken.InboundSecurityToken;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/PKISignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/PKISignatureAlgorithm.java?rev=1721033&r1=1721032&r2=1721033&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/PKISignatureAlgorithm.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/algorithms/PKISignatureAlgorithm.java Sun Dec 20 15:09:20 2015
@@ -18,7 +18,9 @@
*/
package org.apache.xml.security.stax.impl.algorithms;
+import org.apache.xml.security.algorithms.implementations.ECDSAUtils;
import org.apache.xml.security.exceptions.XMLSecurityException;
+import org.apache.xml.security.utils.JavaUtils;
import java.io.IOException;
import java.security.*;
@@ -103,7 +105,7 @@ public class PKISignatureAlgorithm imple
if (this.jceName.contains("ECDSA")) {
return ECDSAUtils.convertASN1toXMLDSIG(jcebytes);
} else if (this.jceName.contains("DSA")) {
- return DSAUtils.convertASN1toXMLDSIG(jcebytes);
+ return JavaUtils.convertDsaASN1toXMLDSIG(jcebytes, 20);
}
return jcebytes;
} catch (SignatureException e) {
@@ -129,7 +131,7 @@ public class PKISignatureAlgorithm imple
if (this.jceName.contains("ECDSA")) {
jcebytes = ECDSAUtils.convertXMLDSIGtoASN1(jcebytes);
} else if (this.jceName.contains("DSA")) {
- jcebytes = DSAUtils.convertXMLDSIGtoASN1(jcebytes);
+ jcebytes = JavaUtils.convertDsaXMLDSIGtoASN1(jcebytes, 20);
}
return this.signature.verify(jcebytes);
} catch (SignatureException e) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/ECKeyValueSecurityToken.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/ECKeyValueSecurityToken.java?rev=1721033&r1=1721032&r2=1721033&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/ECKeyValueSecurityToken.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/ECKeyValueSecurityToken.java Sun Dec 20 15:09:20 2015
@@ -18,10 +18,10 @@
*/
package org.apache.xml.security.stax.impl.securityToken;
+import org.apache.xml.security.algorithms.implementations.ECDSAUtils;
import org.apache.xml.security.binding.xmldsig11.ECKeyValueType;
import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.InboundSecurityContext;
-import org.apache.xml.security.stax.impl.algorithms.ECDSAUtils;
import org.apache.xml.security.stax.impl.util.IDGenerator;
import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/JavaUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/JavaUtils.java?rev=1721033&r1=1721032&r2=1721033&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/JavaUtils.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/JavaUtils.java Sun Dec 20 15:09:20 2015
@@ -162,12 +162,11 @@ public final class JavaUtils {
byte rLength = asn1Bytes[3];
int i;
- for (i = rLength; i > 0 && asn1Bytes[4 + rLength - i] == 0; i--);
+ for (i = rLength; i > 0 && asn1Bytes[4 + rLength - i] == 0; i--); //NOPMD
byte sLength = asn1Bytes[5 + rLength];
int j;
- for (j = sLength;
- j > 0 && asn1Bytes[6 + rLength + sLength - j] == 0; j--);
+ for (j = sLength; j > 0 && asn1Bytes[6 + rLength + sLength - j] == 0; j--); //NOPMD
if (i > size || asn1Bytes[4 + rLength] != 2 || j > size) {
throw new IOException("Invalid ASN.1 format of DSA signature");
@@ -203,7 +202,7 @@ public final class JavaUtils {
}
int i;
- for (i = size; i > 0 && xmldsigBytes[size - i] == 0; i--);
+ for (i = size; i > 0 && xmldsigBytes[size - i] == 0; i--); //NOPMD
int j = i;
if (xmldsigBytes[size - i] < 0) {
@@ -211,7 +210,7 @@ public final class JavaUtils {
}
int k;
- for (k = size; k > 0 && xmldsigBytes[totalSize - k] == 0; k--);
+ for (k = size; k > 0 && xmldsigBytes[totalSize - k] == 0; k--); //NOPMD
int l = k;
if (xmldsigBytes[totalSize - k] < 0) {