提交 fb8826a3 编写于 作者: L lana

Merge

...@@ -219,3 +219,6 @@ a2a2a91075ad85becbe10a39d7fd04ef9bea8df5 jdk8-b92 ...@@ -219,3 +219,6 @@ a2a2a91075ad85becbe10a39d7fd04ef9bea8df5 jdk8-b92
42aa9f1828852bb8b77e98ec695211493ae0759d jdk8-b95 42aa9f1828852bb8b77e98ec695211493ae0759d jdk8-b95
4a5d3cf2b3af1660db0237e8da324c140e534fa4 jdk8-b96 4a5d3cf2b3af1660db0237e8da324c140e534fa4 jdk8-b96
978a95239044f26dcc8a6d59246be07ad6ca6be2 jdk8-b97 978a95239044f26dcc8a6d59246be07ad6ca6be2 jdk8-b97
c4908732fef5235f1b98cafe0ce507771ef7892c jdk8-b98
6a099a36589bd933957272ba63e5263bede29971 jdk8-b99
5be9c5bfcfe9b2a40412b4fb364377d49de014eb jdk8-b100
...@@ -102,7 +102,7 @@ SUNWprivate_1.1 { ...@@ -102,7 +102,7 @@ SUNWprivate_1.1 {
Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle; Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle;
Java_sun_security_pkcs11_Secmod_nssLoadLibrary; Java_sun_security_pkcs11_Secmod_nssLoadLibrary;
Java_sun_security_pkcs11_Secmod_nssVersionCheck; Java_sun_security_pkcs11_Secmod_nssVersionCheck;
Java_sun_security_pkcs11_Secmod_nssInit; Java_sun_security_pkcs11_Secmod_nssInitialize;
Java_sun_security_pkcs11_Secmod_nssGetModuleList; Java_sun_security_pkcs11_Secmod_nssGetModuleList;
local: local:
......
# #
# Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -102,7 +102,7 @@ SUNWprivate_1.1 { ...@@ -102,7 +102,7 @@ SUNWprivate_1.1 {
Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle; Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle;
Java_sun_security_pkcs11_Secmod_nssLoadLibrary; Java_sun_security_pkcs11_Secmod_nssLoadLibrary;
Java_sun_security_pkcs11_Secmod_nssVersionCheck; Java_sun_security_pkcs11_Secmod_nssVersionCheck;
Java_sun_security_pkcs11_Secmod_nssInit; Java_sun_security_pkcs11_Secmod_nssInitialize;
Java_sun_security_pkcs11_Secmod_nssGetModuleList; Java_sun_security_pkcs11_Secmod_nssGetModuleList;
local: local:
......
...@@ -382,7 +382,7 @@ static unichar NsGetDeadKeyChar(unsigned short keyCode) ...@@ -382,7 +382,7 @@ static unichar NsGetDeadKeyChar(unsigned short keyCode)
{ {
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData); CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
if (uchr == nil) { return; } if (uchr == nil) { return 0; }
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr); const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
// Carbon modifiers should be used instead of NSEvent modifiers // Carbon modifiers should be used instead of NSEvent modifiers
UInt32 modifierKeyState = (GetCurrentEventKeyModifiers() >> 8) & 0xFF; UInt32 modifierKeyState = (GetCurrentEventKeyModifiers() >> 8) & 0xFF;
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,6 +31,7 @@ import javax.crypto.spec.DESKeySpec; ...@@ -31,6 +31,7 @@ import javax.crypto.spec.DESKeySpec;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.SecretKeySpec;
/** /**
* This class implements the DES key factory of the Sun provider. * This class implements the DES key factory of the Sun provider.
...@@ -60,20 +61,22 @@ public final class DESKeyFactory extends SecretKeyFactorySpi { ...@@ -60,20 +61,22 @@ public final class DESKeyFactory extends SecretKeyFactorySpi {
*/ */
protected SecretKey engineGenerateSecret(KeySpec keySpec) protected SecretKey engineGenerateSecret(KeySpec keySpec)
throws InvalidKeySpecException { throws InvalidKeySpecException {
DESKey desKey = null;
try { try {
if (!(keySpec instanceof DESKeySpec)) { if (keySpec instanceof DESKeySpec) {
throw new InvalidKeySpecException return new DESKey(((DESKeySpec)keySpec).getKey());
("Inappropriate key specification");
} }
else {
DESKeySpec desKeySpec = (DESKeySpec)keySpec; if (keySpec instanceof SecretKeySpec) {
desKey = new DESKey(desKeySpec.getKey()); return new DESKey(((SecretKeySpec)keySpec).getEncoded());
} }
throw new InvalidKeySpecException(
"Inappropriate key specification");
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
throw new InvalidKeySpecException(e.getMessage());
} }
return desKey;
} }
/** /**
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,6 +31,7 @@ import javax.crypto.spec.DESedeKeySpec; ...@@ -31,6 +31,7 @@ import javax.crypto.spec.DESedeKeySpec;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.SecretKeySpec;
/** /**
* This class implements the DES-EDE key factory of the Sun provider. * This class implements the DES-EDE key factory of the Sun provider.
...@@ -60,20 +61,20 @@ public final class DESedeKeyFactory extends SecretKeyFactorySpi { ...@@ -60,20 +61,20 @@ public final class DESedeKeyFactory extends SecretKeyFactorySpi {
*/ */
protected SecretKey engineGenerateSecret(KeySpec keySpec) protected SecretKey engineGenerateSecret(KeySpec keySpec)
throws InvalidKeySpecException { throws InvalidKeySpecException {
DESedeKey desEdeKey = null;
try { try {
if (keySpec instanceof DESedeKeySpec) { if (keySpec instanceof DESedeKeySpec) {
DESedeKeySpec desEdeKeySpec = (DESedeKeySpec)keySpec; return new DESedeKey(((DESedeKeySpec)keySpec).getKey());
desEdeKey = new DESedeKey(desEdeKeySpec.getKey()); }
if (keySpec instanceof SecretKeySpec) {
return new DESedeKey(((SecretKeySpec)keySpec).getEncoded());
} else {
throw new InvalidKeySpecException
("Inappropriate key specification");
} }
throw new InvalidKeySpecException
("Inappropriate key specification");
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
throw new InvalidKeySpecException(e.getMessage());
} }
return desEdeKey;
} }
/** /**
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -83,7 +83,7 @@ public final class DHKeyFactory extends KeyFactorySpi { ...@@ -83,7 +83,7 @@ public final class DHKeyFactory extends KeyFactorySpi {
} }
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
throw new InvalidKeySpecException throw new InvalidKeySpecException
("Inappropriate key specification"); ("Inappropriate key specification", e);
} }
} }
...@@ -118,7 +118,7 @@ public final class DHKeyFactory extends KeyFactorySpi { ...@@ -118,7 +118,7 @@ public final class DHKeyFactory extends KeyFactorySpi {
} }
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
throw new InvalidKeySpecException throw new InvalidKeySpecException
("Inappropriate key specification"); ("Inappropriate key specification", e);
} }
} }
...@@ -227,7 +227,7 @@ public final class DHKeyFactory extends KeyFactorySpi { ...@@ -227,7 +227,7 @@ public final class DHKeyFactory extends KeyFactorySpi {
} }
} catch (InvalidKeySpecException e) { } catch (InvalidKeySpecException e) {
throw new InvalidKeyException("Cannot translate key"); throw new InvalidKeyException("Cannot translate key", e);
} }
} }
} }
...@@ -167,15 +167,16 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi { ...@@ -167,15 +167,16 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi {
BigInteger pMinus2 = p.subtract(BigInteger.valueOf(2)); BigInteger pMinus2 = p.subtract(BigInteger.valueOf(2));
// //
// Handbook of Applied Cryptography: Menezes, et.al. // PKCS#3 section 7.1 "Private-value generation"
// Repeat if the following does not hold: // Repeat if either of the followings does not hold:
// 1 <= x <= p-2 // 0 < x < p-1
// 2^(lSize-1) <= x < 2^(lSize)
// //
do { do {
// generate random x up to 2^lSize bits long // generate random x up to 2^lSize bits long
x = new BigInteger(lSize, random); x = new BigInteger(lSize, random);
} while ((x.compareTo(BigInteger.ONE) < 0) || } while ((x.compareTo(BigInteger.ONE) < 0) ||
((x.compareTo(pMinus2) > 0))); ((x.compareTo(pMinus2) > 0)) || (x.bitLength() != lSize));
// calculate public value y // calculate public value y
BigInteger y = g.modPow(x, p); BigInteger y = g.modPow(x, p);
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.io.*; import java.io.*;
import java.util.Objects;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.KeyRep; import java.security.KeyRep;
import java.security.PrivateKey; import java.security.PrivateKey;
...@@ -67,7 +68,7 @@ javax.crypto.interfaces.DHPrivateKey, Serializable { ...@@ -67,7 +68,7 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
// the base generator // the base generator
private BigInteger g; private BigInteger g;
// the private-value length // the private-value length (optional)
private int l; private int l;
private int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 }; private int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 };
...@@ -179,20 +180,9 @@ javax.crypto.interfaces.DHPrivateKey, Serializable { ...@@ -179,20 +180,9 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
this.key = val.data.getOctetString(); this.key = val.data.getOctetString();
parseKeyBits(); parseKeyBits();
// ignore OPTIONAL attributes
this.encodedKey = encodedKey.clone(); this.encodedKey = encodedKey.clone();
} catch (IOException | NumberFormatException e) {
} catch (NumberFormatException e) { throw new InvalidKeyException("Error parsing key encoding", e);
InvalidKeyException ike = new InvalidKeyException(
"Private-value length too big");
ike.initCause(e);
throw ike;
} catch (IOException e) {
InvalidKeyException ike = new InvalidKeyException(
"Error parsing key encoding: " + e.getMessage());
ike.initCause(e);
throw ike;
} }
} }
...@@ -234,8 +224,9 @@ javax.crypto.interfaces.DHPrivateKey, Serializable { ...@@ -234,8 +224,9 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
DerOutputStream params = new DerOutputStream(); DerOutputStream params = new DerOutputStream();
params.putInteger(this.p); params.putInteger(this.p);
params.putInteger(this.g); params.putInteger(this.g);
if (this.l != 0) if (this.l != 0) {
params.putInteger(this.l); params.putInteger(this.l);
}
// wrap parameters into SEQUENCE // wrap parameters into SEQUENCE
DerValue paramSequence = new DerValue(DerValue.tag_Sequence, DerValue paramSequence = new DerValue(DerValue.tag_Sequence,
params.toByteArray()); params.toByteArray());
...@@ -273,10 +264,11 @@ javax.crypto.interfaces.DHPrivateKey, Serializable { ...@@ -273,10 +264,11 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
* @return the key parameters * @return the key parameters
*/ */
public DHParameterSpec getParams() { public DHParameterSpec getParams() {
if (this.l != 0) if (this.l != 0) {
return new DHParameterSpec(this.p, this.g, this.l); return new DHParameterSpec(this.p, this.g, this.l);
else } else {
return new DHParameterSpec(this.p, this.g); return new DHParameterSpec(this.p, this.g);
}
} }
public String toString() { public String toString() {
...@@ -312,26 +304,21 @@ javax.crypto.interfaces.DHPrivateKey, Serializable { ...@@ -312,26 +304,21 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
* Objects that are equal will also have the same hashcode. * Objects that are equal will also have the same hashcode.
*/ */
public int hashCode() { public int hashCode() {
int retval = 0; return Objects.hash(x, p, g);
byte[] enc = getEncoded();
for (int i = 1; i < enc.length; i++) {
retval += enc[i] * i;
}
return(retval);
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true;
if (!(obj instanceof PrivateKey)) if (!(obj instanceof javax.crypto.interfaces.DHPrivateKey)) {
return false; return false;
}
byte[] thisEncoded = this.getEncoded(); javax.crypto.interfaces.DHPrivateKey other =
byte[] thatEncoded = ((PrivateKey)obj).getEncoded(); (javax.crypto.interfaces.DHPrivateKey) obj;
DHParameterSpec otherParams = other.getParams();
return java.util.Arrays.equals(thisEncoded, thatEncoded); return ((this.x.compareTo(other.getX()) == 0) &&
(this.p.compareTo(otherParams.getP()) == 0) &&
(this.g.compareTo(otherParams.getG()) == 0));
} }
/** /**
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.io.*; import java.io.*;
import java.util.Objects;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.KeyRep; import java.security.KeyRep;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
...@@ -64,7 +65,7 @@ javax.crypto.interfaces.DHPublicKey, Serializable { ...@@ -64,7 +65,7 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
// the base generator // the base generator
private BigInteger g; private BigInteger g;
// the private-value length // the private-value length (optional)
private int l; private int l;
private int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 }; private int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 };
...@@ -173,13 +174,8 @@ javax.crypto.interfaces.DHPublicKey, Serializable { ...@@ -173,13 +174,8 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
} }
this.encodedKey = encodedKey.clone(); this.encodedKey = encodedKey.clone();
} catch (IOException | NumberFormatException e) {
} catch (NumberFormatException e) { throw new InvalidKeyException("Error parsing key encoding", e);
throw new InvalidKeyException("Private-value length too big");
} catch (IOException e) {
throw new InvalidKeyException(
"Error parsing key encoding: " + e.toString());
} }
} }
...@@ -212,8 +208,9 @@ javax.crypto.interfaces.DHPublicKey, Serializable { ...@@ -212,8 +208,9 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
DerOutputStream params = new DerOutputStream(); DerOutputStream params = new DerOutputStream();
params.putInteger(this.p); params.putInteger(this.p);
params.putInteger(this.g); params.putInteger(this.g);
if (this.l != 0) if (this.l != 0) {
params.putInteger(this.l); params.putInteger(this.l);
}
// wrap parameters into SEQUENCE // wrap parameters into SEQUENCE
DerValue paramSequence = new DerValue(DerValue.tag_Sequence, DerValue paramSequence = new DerValue(DerValue.tag_Sequence,
params.toByteArray()); params.toByteArray());
...@@ -253,10 +250,11 @@ javax.crypto.interfaces.DHPublicKey, Serializable { ...@@ -253,10 +250,11 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
* @return the key parameters * @return the key parameters
*/ */
public DHParameterSpec getParams() { public DHParameterSpec getParams() {
if (this.l != 0) if (this.l != 0) {
return new DHParameterSpec(this.p, this.g, this.l); return new DHParameterSpec(this.p, this.g, this.l);
else } else {
return new DHParameterSpec(this.p, this.g); return new DHParameterSpec(this.p, this.g);
}
} }
public String toString() { public String toString() {
...@@ -290,26 +288,22 @@ javax.crypto.interfaces.DHPublicKey, Serializable { ...@@ -290,26 +288,22 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
* Objects that are equal will also have the same hashcode. * Objects that are equal will also have the same hashcode.
*/ */
public int hashCode() { public int hashCode() {
int retval = 0; return Objects.hash(y, p, g);
byte[] enc = getEncoded();
for (int i = 1; i < enc.length; i++) {
retval += enc[i] * i;
}
return(retval);
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true;
if (!(obj instanceof PublicKey)) if (!(obj instanceof javax.crypto.interfaces.DHPublicKey)) {
return false; return false;
}
byte[] thisEncoded = this.getEncoded(); javax.crypto.interfaces.DHPublicKey other =
byte[] thatEncoded = ((PublicKey)obj).getEncoded(); (javax.crypto.interfaces.DHPublicKey) obj;
DHParameterSpec otherParams = other.getParams();
return java.util.Arrays.equals(thisEncoded, thatEncoded); return ((this.y.compareTo(other.getY()) == 0) &&
(this.p.compareTo(otherParams.getP()) == 0) &&
(this.g.compareTo(otherParams.getG()) == 0));
} }
/** /**
......
...@@ -134,7 +134,7 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker { ...@@ -134,7 +134,7 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
} else { } else {
try { try {
(new NativeUnpack(this)).run(in0, out); (new NativeUnpack(this)).run(in0, out);
} catch (UnsatisfiedLinkError ule) { } catch (UnsatisfiedLinkError | NoClassDefFoundError ex) {
// failover to java implementation // failover to java implementation
(new DoUnpack()).run(in0, out); (new DoUnpack()).run(in0, out);
} }
......
...@@ -52,6 +52,7 @@ import javax.management.NotCompliantMBeanException; ...@@ -52,6 +52,7 @@ import javax.management.NotCompliantMBeanException;
import com.sun.jmx.remote.util.EnvHelp; import com.sun.jmx.remote.util.EnvHelp;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import javax.management.AttributeNotFoundException; import javax.management.AttributeNotFoundException;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import sun.reflect.misc.MethodUtil; import sun.reflect.misc.MethodUtil;
...@@ -64,7 +65,11 @@ import sun.reflect.misc.ReflectUtil; ...@@ -64,7 +65,11 @@ import sun.reflect.misc.ReflectUtil;
* @since 1.5 * @since 1.5
*/ */
public class Introspector { public class Introspector {
final public static boolean ALLOW_NONPUBLIC_MBEAN;
static {
String val = AccessController.doPrivileged(new GetPropertyAction("jdk.jmx.mbeans.allowNonPublic"));
ALLOW_NONPUBLIC_MBEAN = Boolean.parseBoolean(val);
}
/* /*
* ------------------------------------------ * ------------------------------------------
...@@ -223,11 +228,27 @@ public class Introspector { ...@@ -223,11 +228,27 @@ public class Introspector {
return testCompliance(baseClass, null); return testCompliance(baseClass, null);
} }
/**
* Tests the given interface class for being a compliant MXBean interface.
* A compliant MXBean interface is any publicly accessible interface
* following the {@link MXBean} conventions.
* @param interfaceClass An interface class to test for the MXBean compliance
* @throws NotCompliantMBeanException Thrown when the tested interface
* is not public or contradicts the {@link MXBean} conventions.
*/
public static void testComplianceMXBeanInterface(Class<?> interfaceClass) public static void testComplianceMXBeanInterface(Class<?> interfaceClass)
throws NotCompliantMBeanException { throws NotCompliantMBeanException {
MXBeanIntrospector.getInstance().getAnalyzer(interfaceClass); MXBeanIntrospector.getInstance().getAnalyzer(interfaceClass);
} }
/**
* Tests the given interface class for being a compliant MBean interface.
* A compliant MBean interface is any publicly accessible interface
* following the {@code MBean} conventions.
* @param interfaceClass An interface class to test for the MBean compliance
* @throws NotCompliantMBeanException Thrown when the tested interface
* is not public or contradicts the {@code MBean} conventions.
*/
public static void testComplianceMBeanInterface(Class<?> interfaceClass) public static void testComplianceMBeanInterface(Class<?> interfaceClass)
throws NotCompliantMBeanException{ throws NotCompliantMBeanException{
StandardMBeanIntrospector.getInstance().getAnalyzer(interfaceClass); StandardMBeanIntrospector.getInstance().getAnalyzer(interfaceClass);
...@@ -299,18 +320,18 @@ public class Introspector { ...@@ -299,18 +320,18 @@ public class Introspector {
* not a JMX compliant Standard MBean. * not a JMX compliant Standard MBean.
*/ */
public static <T> Class<? super T> getStandardMBeanInterface(Class<T> baseClass) public static <T> Class<? super T> getStandardMBeanInterface(Class<T> baseClass)
throws NotCompliantMBeanException { throws NotCompliantMBeanException {
Class<? super T> current = baseClass; Class<? super T> current = baseClass;
Class<? super T> mbeanInterface = null; Class<? super T> mbeanInterface = null;
while (current != null) { while (current != null) {
mbeanInterface = mbeanInterface =
findMBeanInterface(current, current.getName()); findMBeanInterface(current, current.getName());
if (mbeanInterface != null) break; if (mbeanInterface != null) break;
current = current.getSuperclass(); current = current.getSuperclass();
} }
if (mbeanInterface != null) { if (mbeanInterface != null) {
return mbeanInterface; return mbeanInterface;
} else { } else {
final String msg = final String msg =
"Class " + baseClass.getName() + "Class " + baseClass.getName() +
" is not a JMX compliant Standard MBean"; " is not a JMX compliant Standard MBean";
...@@ -507,8 +528,11 @@ public class Introspector { ...@@ -507,8 +528,11 @@ public class Introspector {
} }
Class<?>[] interfaces = c.getInterfaces(); Class<?>[] interfaces = c.getInterfaces();
for (int i = 0;i < interfaces.length; i++) { for (int i = 0;i < interfaces.length; i++) {
if (interfaces[i].getName().equals(clMBeanName)) if (interfaces[i].getName().equals(clMBeanName) &&
(Modifier.isPublic(interfaces[i].getModifiers()) ||
ALLOW_NONPUBLIC_MBEAN)) {
return Util.cast(interfaces[i]); return Util.cast(interfaces[i]);
}
} }
return null; return null;
......
...@@ -28,6 +28,8 @@ package com.sun.jmx.mbeanserver; ...@@ -28,6 +28,8 @@ package com.sun.jmx.mbeanserver;
import static com.sun.jmx.mbeanserver.Util.*; import static com.sun.jmx.mbeanserver.Util.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
...@@ -50,7 +52,6 @@ import javax.management.NotCompliantMBeanException; ...@@ -50,7 +52,6 @@ import javax.management.NotCompliantMBeanException;
* @since 1.6 * @since 1.6
*/ */
class MBeanAnalyzer<M> { class MBeanAnalyzer<M> {
static interface MBeanVisitor<M> { static interface MBeanVisitor<M> {
public void visitAttribute(String attributeName, public void visitAttribute(String attributeName,
M getter, M getter,
...@@ -107,6 +108,10 @@ class MBeanAnalyzer<M> { ...@@ -107,6 +108,10 @@ class MBeanAnalyzer<M> {
if (!mbeanType.isInterface()) { if (!mbeanType.isInterface()) {
throw new NotCompliantMBeanException("Not an interface: " + throw new NotCompliantMBeanException("Not an interface: " +
mbeanType.getName()); mbeanType.getName());
} else if (!Modifier.isPublic(mbeanType.getModifiers()) &&
!Introspector.ALLOW_NONPUBLIC_MBEAN) {
throw new NotCompliantMBeanException("Interface is not public: " +
mbeanType.getName());
} }
try { try {
......
...@@ -2,82 +2,78 @@ ...@@ -2,82 +2,78 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.algorithms; package com.sun.org.apache.xml.internal.security.algorithms;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* The Algorithm class which stores the Algorithm URI as a string. * The Algorithm class which stores the Algorithm URI as a string.
*
*/ */
public abstract class Algorithm extends SignatureElementProxy { public abstract class Algorithm extends SignatureElementProxy {
/** /**
* *
* @param doc * @param doc
* @param algorithmURI is the URI of the algorithm as String * @param algorithmURI is the URI of the algorithm as String
*/ */
public Algorithm(Document doc, String algorithmURI) { public Algorithm(Document doc, String algorithmURI) {
super(doc);
super(doc);
this.setAlgorithmURI(algorithmURI);
}
/** this.setAlgorithmURI(algorithmURI);
* Constructor Algorithm }
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public Algorithm(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/** /**
* Method getAlgorithmURI * Constructor Algorithm
* *
* @return The URI of the alogrithm * @param element
*/ * @param BaseURI
public String getAlgorithmURI() { * @throws XMLSecurityException
return this._constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM); */
} public Algorithm(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/** /**
* Sets the algorithm's URI as used in the signature. * Method getAlgorithmURI
* *
* @param algorithmURI is the URI of the algorithm as String * @return The URI of the algorithm
*/ */
protected void setAlgorithmURI(String algorithmURI) { public String getAlgorithmURI() {
return this.constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
if ( (algorithmURI != null)) { /**
this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, * Sets the algorithm's URI as used in the signature.
algorithmURI); *
} * @param algorithmURI is the URI of the algorithm as String
} */
protected void setAlgorithmURI(String algorithmURI) {
if (algorithmURI != null) {
this.constructionElement.setAttributeNS(
null, Constants._ATT_ALGORITHM, algorithmURI
);
}
}
} }
...@@ -114,6 +114,18 @@ public class JCEMapper { ...@@ -114,6 +114,18 @@ public class JCEMapper {
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1, XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1,
new Algorithm("", "SHA1withECDSA", "Signature") new Algorithm("", "SHA1withECDSA", "Signature")
); );
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256,
new Algorithm("", "SHA256withECDSA", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384,
new Algorithm("", "SHA384withECDSA", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512,
new Algorithm("", "SHA512withECDSA", "Signature")
);
algorithmsMap.put( algorithmsMap.put(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5, XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5,
new Algorithm("", "HmacMD5", "Mac") new Algorithm("", "HmacMD5", "Mac")
...@@ -154,6 +166,18 @@ public class JCEMapper { ...@@ -154,6 +166,18 @@ public class JCEMapper {
XMLCipher.AES_256, XMLCipher.AES_256,
new Algorithm("AES", "AES/CBC/ISO10126Padding", "BlockEncryption", 256) new Algorithm("AES", "AES/CBC/ISO10126Padding", "BlockEncryption", 256)
); );
algorithmsMap.put(
XMLCipher.AES_128_GCM,
new Algorithm("AES", "AES/GCM/NoPadding", "BlockEncryption", 128)
);
algorithmsMap.put(
XMLCipher.AES_192_GCM,
new Algorithm("AES", "AES/GCM/NoPadding", "BlockEncryption", 192)
);
algorithmsMap.put(
XMLCipher.AES_256_GCM,
new Algorithm("AES", "AES/GCM/NoPadding", "BlockEncryption", 256)
);
algorithmsMap.put( algorithmsMap.put(
XMLCipher.RSA_v1dot5, XMLCipher.RSA_v1dot5,
new Algorithm("RSA", "RSA/ECB/PKCS1Padding", "KeyTransport") new Algorithm("RSA", "RSA/ECB/PKCS1Padding", "KeyTransport")
...@@ -162,6 +186,10 @@ public class JCEMapper { ...@@ -162,6 +186,10 @@ public class JCEMapper {
XMLCipher.RSA_OAEP, XMLCipher.RSA_OAEP,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport") new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
); );
algorithmsMap.put(
XMLCipher.RSA_OAEP_11,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
);
algorithmsMap.put( algorithmsMap.put(
XMLCipher.DIFFIE_HELLMAN, XMLCipher.DIFFIE_HELLMAN,
new Algorithm("", "", "KeyAgreement") new Algorithm("", "", "KeyAgreement")
......
...@@ -2,265 +2,254 @@ ...@@ -2,265 +2,254 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.algorithms; package com.sun.org.apache.xml.internal.security.algorithms;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchProviderException; import java.security.NoSuchProviderException;
import java.util.HashMap;
import java.util.Map;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants; import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants;
import org.w3c.dom.Document; import org.w3c.dom.Document;
/** /**
* Digest Message wrapper & selector class. * Digest Message wrapper & selector class.
* *
* <pre> * <pre>
* MessageDigestAlgorithm.getInstance() * MessageDigestAlgorithm.getInstance()
* </pre> * </pre>
*
*/ */
public class MessageDigestAlgorithm extends Algorithm { public class MessageDigestAlgorithm extends Algorithm {
/** Message Digest - NOT RECOMMENDED MD5*/ /** Message Digest - NOT RECOMMENDED MD5*/
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 = Constants.MoreAlgorithmsSpecNS + "md5"; public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 =
/** Digest - Required SHA1*/ Constants.MoreAlgorithmsSpecNS + "md5";
public static final String ALGO_ID_DIGEST_SHA1 = Constants.SignatureSpecNS + "sha1"; /** Digest - Required SHA1*/
/** Message Digest - RECOMMENDED SHA256*/ public static final String ALGO_ID_DIGEST_SHA1 = Constants.SignatureSpecNS + "sha1";
public static final String ALGO_ID_DIGEST_SHA256 = EncryptionConstants.EncryptionSpecNS + "sha256"; /** Message Digest - RECOMMENDED SHA256*/
/** Message Digest - OPTIONAL SHA384*/ public static final String ALGO_ID_DIGEST_SHA256 =
public static final String ALGO_ID_DIGEST_SHA384 = Constants.MoreAlgorithmsSpecNS + "sha384"; EncryptionConstants.EncryptionSpecNS + "sha256";
/** Message Digest - OPTIONAL SHA512*/ /** Message Digest - OPTIONAL SHA384*/
public static final String ALGO_ID_DIGEST_SHA512 = EncryptionConstants.EncryptionSpecNS + "sha512"; public static final String ALGO_ID_DIGEST_SHA384 =
/** Message Digest - OPTIONAL RIPEMD-160*/ Constants.MoreAlgorithmsSpecNS + "sha384";
public static final String ALGO_ID_DIGEST_RIPEMD160 = EncryptionConstants.EncryptionSpecNS + "ripemd160"; /** Message Digest - OPTIONAL SHA512*/
public static final String ALGO_ID_DIGEST_SHA512 =
/** Field algorithm stores the actual {@link java.security.MessageDigest} */ EncryptionConstants.EncryptionSpecNS + "sha512";
java.security.MessageDigest algorithm = null; /** Message Digest - OPTIONAL RIPEMD-160*/
public static final String ALGO_ID_DIGEST_RIPEMD160 =
/** EncryptionConstants.EncryptionSpecNS + "ripemd160";
* Constructor for the brave who pass their own message digest algorithms and the corresponding URI.
* @param doc /** Field algorithm stores the actual {@link java.security.MessageDigest} */
* @param messageDigest private final MessageDigest algorithm;
* @param algorithmURI
*/ /**
private MessageDigestAlgorithm(Document doc, MessageDigest messageDigest, * Constructor for the brave who pass their own message digest algorithms and the
String algorithmURI) { * corresponding URI.
* @param doc
super(doc, algorithmURI); * @param algorithmURI
*/
this.algorithm = messageDigest; private MessageDigestAlgorithm(Document doc, String algorithmURI)
} throws XMLSignatureException {
super(doc, algorithmURI);
static ThreadLocal<Map<String, MessageDigest>> instances=new
ThreadLocal<Map<String, MessageDigest>>() { algorithm = getDigestInstance(algorithmURI);
protected Map<String, MessageDigest> initialValue() { }
return new HashMap<String, MessageDigest>();
}; /**
}; * Factory method for constructing a message digest algorithm by name.
*
/** * @param doc
* Factory method for constructing a message digest algorithm by name. * @param algorithmURI
* * @return The MessageDigestAlgorithm element to attach in document and to digest
* @param doc * @throws XMLSignatureException
* @param algorithmURI */
* @return The MessageDigestAlgorithm element to attach in document and to digest public static MessageDigestAlgorithm getInstance(
* @throws XMLSignatureException Document doc, String algorithmURI
*/ ) throws XMLSignatureException {
public static MessageDigestAlgorithm getInstance( return new MessageDigestAlgorithm(doc, algorithmURI);
Document doc, String algorithmURI) throws XMLSignatureException { }
MessageDigest md = getDigestInstance(algorithmURI);
return new MessageDigestAlgorithm(doc, md, algorithmURI); private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
} String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException { if (algorithmID == null) {
MessageDigest result= instances.get().get(algorithmURI); Object[] exArgs = { algorithmURI };
if (result!=null) throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
return result; }
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
if (algorithmID == null) {
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
}
MessageDigest md; MessageDigest md;
String provider=JCEMapper.getProviderId(); String provider = JCEMapper.getProviderId();
try { try {
if (provider==null) { if (provider == null) {
md = MessageDigest.getInstance(algorithmID); md = MessageDigest.getInstance(algorithmID);
} else { } else {
md = MessageDigest.getInstance(algorithmID,provider); md = MessageDigest.getInstance(algorithmID, provider);
} }
} catch (java.security.NoSuchAlgorithmException ex) { } catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) { } catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID, Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} }
instances.get().put(algorithmURI, md);
return md;
}
/**
* Returns the actual {@link java.security.MessageDigest} algorithm object
*
* @return the actual {@link java.security.MessageDigest} algorithm object
*/
public java.security.MessageDigest getAlgorithm() {
return this.algorithm;
}
/**
* Proxy method for {@link java.security.MessageDigest#isEqual}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param digesta
* @param digestb
* @return the result of the {@link java.security.MessageDigest#isEqual} method
*/
public static boolean isEqual(byte[] digesta, byte[] digestb) {
return java.security.MessageDigest.isEqual(digesta, digestb);
}
/**
* Proxy method for {@link java.security.MessageDigest#digest()}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#digest()} method
*/
public byte[] digest() {
return this.algorithm.digest();
}
/**
* Proxy method for {@link java.security.MessageDigest#digest(byte[])}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
* @return the result of the {@link java.security.MessageDigest#digest(byte[])} method
*/
public byte[] digest(byte input[]) {
return this.algorithm.digest(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#digest(byte[], int, int)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param buf
* @param offset
* @param len
* @return the result of the {@link java.security.MessageDigest#digest(byte[], int, int)} method
* @throws java.security.DigestException
*/
public int digest(byte buf[], int offset, int len)
throws java.security.DigestException {
return this.algorithm.digest(buf, offset, len);
}
/**
* Proxy method for {@link java.security.MessageDigest#getAlgorithm}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getAlgorithm} method
*/
public String getJCEAlgorithmString() {
return this.algorithm.getAlgorithm();
}
/**
* Proxy method for {@link java.security.MessageDigest#getProvider}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getProvider} method
*/
public java.security.Provider getJCEProvider() {
return this.algorithm.getProvider();
}
/** return md;
* Proxy method for {@link java.security.MessageDigest#getDigestLength} }
* which is executed on the internal {@link java.security.MessageDigest} object.
* /**
* @return the result of the {@link java.security.MessageDigest#getDigestLength} method * Returns the actual {@link java.security.MessageDigest} algorithm object
*/ *
public int getDigestLength() { * @return the actual {@link java.security.MessageDigest} algorithm object
return this.algorithm.getDigestLength(); */
} public java.security.MessageDigest getAlgorithm() {
return algorithm;
/** }
* Proxy method for {@link java.security.MessageDigest#reset}
* which is executed on the internal {@link java.security.MessageDigest} object. /**
* * Proxy method for {@link java.security.MessageDigest#isEqual}
*/ * which is executed on the internal {@link java.security.MessageDigest} object.
public void reset() { *
this.algorithm.reset(); * @param digesta
} * @param digestb
* @return the result of the {@link java.security.MessageDigest#isEqual} method
/** */
* Proxy method for {@link java.security.MessageDigest#update(byte[])} public static boolean isEqual(byte[] digesta, byte[] digestb) {
* which is executed on the internal {@link java.security.MessageDigest} object. return java.security.MessageDigest.isEqual(digesta, digestb);
* }
* @param input
*/ /**
public void update(byte[] input) { * Proxy method for {@link java.security.MessageDigest#digest()}
this.algorithm.update(input); * which is executed on the internal {@link java.security.MessageDigest} object.
} *
* @return the result of the {@link java.security.MessageDigest#digest()} method
/** */
* Proxy method for {@link java.security.MessageDigest#update(byte)} public byte[] digest() {
* which is executed on the internal {@link java.security.MessageDigest} object. return algorithm.digest();
* }
* @param input
*/ /**
public void update(byte input) { * Proxy method for {@link java.security.MessageDigest#digest(byte[])}
this.algorithm.update(input); * which is executed on the internal {@link java.security.MessageDigest} object.
} *
* @param input
/** * @return the result of the {@link java.security.MessageDigest#digest(byte[])} method
* Proxy method for {@link java.security.MessageDigest#update(byte[], int, int)} */
* which is executed on the internal {@link java.security.MessageDigest} object. public byte[] digest(byte input[]) {
* return algorithm.digest(input);
* @param buf }
* @param offset
* @param len /**
*/ * Proxy method for {@link java.security.MessageDigest#digest(byte[], int, int)}
public void update(byte buf[], int offset, int len) { * which is executed on the internal {@link java.security.MessageDigest} object.
this.algorithm.update(buf, offset, len); *
} * @param buf
* @param offset
/** @inheritDoc */ * @param len
public String getBaseNamespace() { * @return the result of the {@link java.security.MessageDigest#digest(byte[], int, int)} method
return Constants.SignatureSpecNS; * @throws java.security.DigestException
} */
public int digest(byte buf[], int offset, int len) throws java.security.DigestException {
/** @inheritDoc */ return algorithm.digest(buf, offset, len);
public String getBaseLocalName() { }
return Constants._TAG_DIGESTMETHOD;
} /**
* Proxy method for {@link java.security.MessageDigest#getAlgorithm}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getAlgorithm} method
*/
public String getJCEAlgorithmString() {
return algorithm.getAlgorithm();
}
/**
* Proxy method for {@link java.security.MessageDigest#getProvider}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getProvider} method
*/
public java.security.Provider getJCEProvider() {
return algorithm.getProvider();
}
/**
* Proxy method for {@link java.security.MessageDigest#getDigestLength}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getDigestLength} method
*/
public int getDigestLength() {
return algorithm.getDigestLength();
}
/**
* Proxy method for {@link java.security.MessageDigest#reset}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
*/
public void reset() {
algorithm.reset();
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte[])}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
*/
public void update(byte[] input) {
algorithm.update(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
*/
public void update(byte input) {
algorithm.update(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte[], int, int)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param buf
* @param offset
* @param len
*/
public void update(byte buf[], int offset, int len) {
algorithm.update(buf, offset, len);
}
/** @inheritDoc */
public String getBaseNamespace() {
return Constants.SignatureSpecNS;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DIGESTMETHOD;
}
} }
...@@ -74,7 +74,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -74,7 +74,7 @@ public class SignatureAlgorithm extends Algorithm {
this.algorithmURI = algorithmURI; this.algorithmURI = algorithmURI;
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI); signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement); signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
} }
/** /**
...@@ -92,10 +92,10 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -92,10 +92,10 @@ public class SignatureAlgorithm extends Algorithm {
this.algorithmURI = algorithmURI; this.algorithmURI = algorithmURI;
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI); signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement); signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
signatureAlgorithm.engineSetHMACOutputLength(hmacOutputLength); signatureAlgorithm.engineSetHMACOutputLength(hmacOutputLength);
((IntegrityHmac)signatureAlgorithm).engineAddContextToElement(_constructionElement); ((IntegrityHmac)signatureAlgorithm).engineAddContextToElement(constructionElement);
} }
/** /**
...@@ -136,7 +136,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -136,7 +136,7 @@ public class SignatureAlgorithm extends Algorithm {
} }
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI); signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement); signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
} }
/** /**
...@@ -310,7 +310,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -310,7 +310,7 @@ public class SignatureAlgorithm extends Algorithm {
* @return the URI representation of Transformation algorithm * @return the URI representation of Transformation algorithm
*/ */
public final String getURI() { public final String getURI() {
return _constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM); return constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
} }
/** /**
...@@ -380,9 +380,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -380,9 +380,7 @@ public class SignatureAlgorithm extends Algorithm {
* This method registers the default algorithms. * This method registers the default algorithms.
*/ */
public static void registerDefaultAlgorithms() { public static void registerDefaultAlgorithms() {
algorithmHash.put( algorithmHash.put(SignatureDSA.URI, SignatureDSA.class);
XMLSignature.ALGO_ID_SIGNATURE_DSA, SignatureDSA.class
);
algorithmHash.put( algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, SignatureBaseRSA.SignatureRSASHA1.class XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, SignatureBaseRSA.SignatureRSASHA1.class
); );
...@@ -409,6 +407,15 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -409,6 +407,15 @@ public class SignatureAlgorithm extends Algorithm {
algorithmHash.put( algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1, SignatureECDSA.SignatureECDSASHA1.class XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1, SignatureECDSA.SignatureECDSASHA1.class
); );
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256, SignatureECDSA.SignatureECDSASHA256.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384, SignatureECDSA.SignatureECDSASHA384.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512, SignatureECDSA.SignatureECDSASHA512.class
);
algorithmHash.put( algorithmHash.put(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5, IntegrityHmac.IntegrityHmacMD5.class XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5, IntegrityHmac.IntegrityHmacMD5.class
); );
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.algorithms; package com.sun.org.apache.xml.internal.security.algorithms;
...@@ -27,157 +29,149 @@ import java.security.spec.AlgorithmParameterSpec; ...@@ -27,157 +29,149 @@ import java.security.spec.AlgorithmParameterSpec;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureAlgorithmSpi { public abstract class SignatureAlgorithmSpi {
/** /**
* Returns the URI representation of <code>Transformation algorithm</code> * Returns the URI representation of <code>Transformation algorithm</code>
* *
* @return the URI representation of <code>Transformation algorithm</code> * @return the URI representation of <code>Transformation algorithm</code>
*/ */
protected abstract String engineGetURI(); protected abstract String engineGetURI();
/** /**
* Proxy method for {@link java.security.Signature#getAlgorithm} * Proxy method for {@link java.security.Signature#getAlgorithm}
* which is executed on the internal {@link java.security.Signature} object. * which is executed on the internal {@link java.security.Signature} object.
* *
* @return the result of the {@link java.security.Signature#getAlgorithm} method * @return the result of the {@link java.security.Signature#getAlgorithm} method
*/ */
protected abstract String engineGetJCEAlgorithmString(); protected abstract String engineGetJCEAlgorithmString();
/** /**
* Method engineGetJCEProviderName * Method engineGetJCEProviderName
* *
* @return the JCE ProviderName * @return the JCE ProviderName
*/ */
protected abstract String engineGetJCEProviderName(); protected abstract String engineGetJCEProviderName();
/** /**
* Proxy method for {@link java.security.Signature#update(byte[])} * Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object. * which is executed on the internal {@link java.security.Signature} object.
* *
* @param input * @param input
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
protected abstract void engineUpdate(byte[] input) protected abstract void engineUpdate(byte[] input) throws XMLSignatureException;
throws XMLSignatureException;
/**
/** * Proxy method for {@link java.security.Signature#update(byte[])}
* Proxy method for {@link java.security.Signature#update(byte[])} * which is executed on the internal {@link java.security.Signature} object.
* which is executed on the internal {@link java.security.Signature} object. *
* * @param input
* @param input * @throws XMLSignatureException
* @throws XMLSignatureException */
*/ protected abstract void engineUpdate(byte input) throws XMLSignatureException;
protected abstract void engineUpdate(byte input)
throws XMLSignatureException; /**
* Proxy method for {@link java.security.Signature#update(byte[], int, int)}
/** * which is executed on the internal {@link java.security.Signature} object.
* Proxy method for {@link java.security.Signature#update(byte[], int, int)} *
* which is executed on the internal {@link java.security.Signature} object. * @param buf
* * @param offset
* @param buf * @param len
* @param offset * @throws XMLSignatureException
* @param len */
* @throws XMLSignatureException protected abstract void engineUpdate(byte buf[], int offset, int len)
*/ throws XMLSignatureException;
protected abstract void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException; /**
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)}
/** * which is executed on the internal {@link java.security.Signature} object.
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)} *
* which is executed on the internal {@link java.security.Signature} object. * @param signingKey
* * @throws XMLSignatureException if this method is called on a MAC
* @param signingKey */
* @throws XMLSignatureException if this method is called on a MAC protected abstract void engineInitSign(Key signingKey) throws XMLSignatureException;
*/
protected abstract void engineInitSign(Key signingKey) /**
throws XMLSignatureException; * Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey,
* java.security.SecureRandom)}
/** * which is executed on the internal {@link java.security.Signature} object.
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey, java.security.SecureRandom)} *
* which is executed on the internal {@link java.security.Signature} object. * @param signingKey
* * @param secureRandom
* @param signingKey * @throws XMLSignatureException if this method is called on a MAC
* @param secureRandom */
* @throws XMLSignatureException if this method is called on a MAC protected abstract void engineInitSign(Key signingKey, SecureRandom secureRandom)
*/ throws XMLSignatureException;
protected abstract void engineInitSign(
Key signingKey, SecureRandom secureRandom) throws XMLSignatureException; /**
* Proxy method for {@link javax.crypto.Mac}
/** * which is executed on the internal {@link javax.crypto.Mac#init(Key)} object.
* Proxy method for {@link javax.crypto.Mac} *
* which is executed on the internal {@link javax.crypto.Mac#init(Key)} object. * @param signingKey
* * @param algorithmParameterSpec
* @param signingKey * @throws XMLSignatureException if this method is called on a Signature
* @param algorithmParameterSpec */
* @throws XMLSignatureException if this method is called on a Signature protected abstract void engineInitSign(
*/ Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
protected abstract void engineInitSign( ) throws XMLSignatureException;
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException; /**
* Proxy method for {@link java.security.Signature#sign()}
/** * which is executed on the internal {@link java.security.Signature} object.
* Proxy method for {@link java.security.Signature#sign()} *
* which is executed on the internal {@link java.security.Signature} object. * @return the result of the {@link java.security.Signature#sign()} method
* * @throws XMLSignatureException
* @return the result of the {@link java.security.Signature#sign()} method */
* @throws XMLSignatureException protected abstract byte[] engineSign() throws XMLSignatureException;
*/
protected abstract byte[] engineSign() throws XMLSignatureException; /**
* Method engineInitVerify
/** *
* Method engineInitVerify * @param verificationKey
* * @throws XMLSignatureException
* @param verificationKey */
* @throws XMLSignatureException protected abstract void engineInitVerify(Key verificationKey) throws XMLSignatureException;
*/
protected abstract void engineInitVerify(Key verificationKey) /**
throws XMLSignatureException; * Proxy method for {@link java.security.Signature#verify(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
/** *
* Proxy method for {@link java.security.Signature#verify(byte[])} * @param signature
* which is executed on the internal {@link java.security.Signature} object. * @return true if the signature is correct
* * @throws XMLSignatureException
* @param signature */
* @return true if the signature is correct protected abstract boolean engineVerify(byte[] signature) throws XMLSignatureException;
* @throws XMLSignatureException
*/ /**
protected abstract boolean engineVerify(byte[] signature) * Proxy method for {@link java.security.Signature#setParameter(
throws XMLSignatureException; * java.security.spec.AlgorithmParameterSpec)}
* which is executed on the internal {@link java.security.Signature} object.
/** *
* Proxy method for {@link java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)} * @param params
* which is executed on the internal {@link java.security.Signature} object. * @throws XMLSignatureException
* */
* @param params protected abstract void engineSetParameter(AlgorithmParameterSpec params)
* @throws XMLSignatureException throws XMLSignatureException;
*/
protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException; /**
* Method engineGetContextFromElement
*
/** * @param element
* Method engineGetContextFromElement */
* protected void engineGetContextFromElement(Element element) {
* @param element }
*/
protected void engineGetContextFromElement(Element element) { /**
} * Method engineSetHMACOutputLength
*
/** * @param HMACOutputLength
* Method engineSetHMACOutputLength * @throws XMLSignatureException
* */
* @param HMACOutputLength protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
* @throws XMLSignatureException throws XMLSignatureException;
*/
protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException;
public void reset() { public void reset() {
} }
} }
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2007 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.algorithms.implementations; package com.sun.org.apache.xml.internal.security.algorithms.implementations;
...@@ -36,22 +38,17 @@ import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi ...@@ -36,22 +38,17 @@ import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi
import com.sun.org.apache.xml.internal.security.signature.XMLSignature; import com.sun.org.apache.xml.internal.security.signature.XMLSignature;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */ /** {@link org.apache.commons.logging} logging facility */
static java.util.logging.Logger log = private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger java.util.logging.Logger.getLogger(SignatureBaseRSA.class.getName());
(SignatureBaseRSA.class.getName());
/** @inheritDoc */ /** @inheritDoc */
public abstract String engineGetURI(); public abstract String engineGetURI();
/** Field algorithm */ /** Field algorithm */
private java.security.Signature _signatureAlgorithm = null; private java.security.Signature signatureAlgorithm = null;
/** /**
* Constructor SignatureRSA * Constructor SignatureRSA
...@@ -59,17 +56,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -59,17 +56,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
public SignatureBaseRSA() throws XMLSignatureException { public SignatureBaseRSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI()); String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (log.isLoggable(java.util.logging.Level.FINE)) if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Created SignatureRSA using " + algorithmID); log.log(java.util.logging.Level.FINE, "Created SignatureRSA using " + algorithmID);
String provider=JCEMapper.getProviderId(); }
String provider = JCEMapper.getProviderId();
try { try {
if (provider==null) { if (provider == null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID); this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else { } else {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider); this.signatureAlgorithm = Signature.getInstance(algorithmID,provider);
} }
} catch (java.security.NoSuchAlgorithmException ex) { } catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() }; Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
...@@ -85,20 +82,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -85,20 +82,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params) protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException { throws XMLSignatureException {
try { try {
this._signatureAlgorithm.setParameter(params); this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) { } catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
} }
/** @inheritDoc */ /** @inheritDoc */
protected boolean engineVerify(byte[] signature) protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
throws XMLSignatureException {
try { try {
return this._signatureAlgorithm.verify(signature); return this.signatureAlgorithm.verify(signature);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -106,32 +100,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -106,32 +100,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException { protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) { if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName(); String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName(); String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey); this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK // reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555 // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm; Signature sig = this.signatureAlgorithm;
try { try {
this._signatureAlgorithm = Signature.getInstance this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
(_signatureAlgorithm.getAlgorithm());
} catch (Exception e) { } catch (Exception e) {
// this shouldn't occur, but if it does, restore previous // this shouldn't occur, but if it does, restore previous
// Signature // Signature
if (log.isLoggable(java.util.logging.Level.FINE)) { if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e); log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
} }
this._signatureAlgorithm = sig; this.signatureAlgorithm = sig;
} }
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -140,7 +131,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -140,7 +131,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException { protected byte[] engineSign() throws XMLSignatureException {
try { try {
return this._signatureAlgorithm.sign(); return this.signatureAlgorithm.sign();
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -149,19 +140,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -149,19 +140,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom) protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException { throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) { if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName(); String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initSign this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -169,18 +157,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -169,18 +157,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineInitSign(Key privateKey) throws XMLSignatureException { protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) { if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName(); String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey); this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -189,7 +175,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -189,7 +175,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException { protected void engineUpdate(byte[] input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this.signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -198,17 +184,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -198,17 +184,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException { protected void engineUpdate(byte input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this.signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
} }
/** @inheritDoc */ /** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len) protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(buf, offset, len); this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -216,34 +201,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -216,34 +201,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected String engineGetJCEAlgorithmString() { protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm(); return this.signatureAlgorithm.getAlgorithm();
} }
/** @inheritDoc */ /** @inheritDoc */
protected String engineGetJCEProviderName() { protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName(); return this.signatureAlgorithm.getProvider().getName();
} }
/** @inheritDoc */ /** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength) protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException { throws XMLSignatureException {
throw new XMLSignatureException throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
("algorithms.HMACOutputLengthOnlyForHMAC");
} }
/** @inheritDoc */ /** @inheritDoc */
protected void engineInitSign( protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec) Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
throws XMLSignatureException { ) throws XMLSignatureException {
throw new XMLSignatureException( throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnRSA");
"algorithms.CannotUseAlgorithmParameterSpecOnRSA");
} }
/** /**
* Class SignatureRSASHA1 * Class SignatureRSASHA1
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA1 extends SignatureBaseRSA { public static class SignatureRSASHA1 extends SignatureBaseRSA {
...@@ -264,9 +244,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -264,9 +244,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA256 * Class SignatureRSASHA256
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA256 extends SignatureBaseRSA { public static class SignatureRSASHA256 extends SignatureBaseRSA {
...@@ -287,9 +264,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -287,9 +264,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA384 * Class SignatureRSASHA384
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA384 extends SignatureBaseRSA { public static class SignatureRSASHA384 extends SignatureBaseRSA {
...@@ -310,9 +284,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -310,9 +284,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA512 * Class SignatureRSASHA512
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA512 extends SignatureBaseRSA { public static class SignatureRSASHA512 extends SignatureBaseRSA {
...@@ -333,9 +304,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -333,9 +304,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSARIPEMD160 * Class SignatureRSARIPEMD160
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSARIPEMD160 extends SignatureBaseRSA { public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
...@@ -356,9 +324,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -356,9 +324,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSAMD5 * Class SignatureRSAMD5
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSAMD5 extends SignatureBaseRSA { public static class SignatureRSAMD5 extends SignatureBaseRSA {
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.algorithms.implementations; package com.sun.org.apache.xml.internal.security.algorithms.implementations;
...@@ -37,21 +39,17 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; ...@@ -37,21 +39,17 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Base64; import com.sun.org.apache.xml.internal.security.utils.Base64;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
/**
*
* @author $Author: mullan $
*/
public class SignatureDSA extends SignatureAlgorithmSpi { public class SignatureDSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */ /** {@link org.apache.commons.logging} logging facility */
static java.util.logging.Logger log = private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureDSA.class.getName()); java.util.logging.Logger.getLogger(SignatureDSA.class.getName());
/** Field _URI */ /** Field URI */
public static final String _URI = Constants.SignatureSpecNS + "dsa-sha1"; public static final String URI = Constants.SignatureSpecNS + "dsa-sha1";
/** Field algorithm */ /** Field algorithm */
private java.security.Signature _signatureAlgorithm = null; private java.security.Signature signatureAlgorithm = null;
/** /**
* Method engineGetURI * Method engineGetURI
...@@ -59,7 +57,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -59,7 +57,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected String engineGetURI() { protected String engineGetURI() {
return SignatureDSA._URI; return SignatureDSA.URI;
} }
/** /**
...@@ -68,17 +66,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -68,17 +66,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
public SignatureDSA() throws XMLSignatureException { public SignatureDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA.URI);
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI); if (log.isLoggable(java.util.logging.Level.FINE)) {
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID); log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
}
String provider = JCEMapper.getProviderId(); String provider = JCEMapper.getProviderId();
try { try {
if (provider == null) { if (provider == null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID); this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else { } else {
this._signatureAlgorithm = this.signatureAlgorithm =
Signature.getInstance(algorithmID, provider); Signature.getInstance(algorithmID, provider);
} }
} catch (java.security.NoSuchAlgorithmException ex) { } catch (java.security.NoSuchAlgorithmException ex) {
...@@ -95,9 +93,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -95,9 +93,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/ */
protected void engineSetParameter(AlgorithmParameterSpec params) protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException { throws XMLSignatureException {
try { try {
this._signatureAlgorithm.setParameter(params); this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) { } catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -107,15 +104,15 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -107,15 +104,15 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected boolean engineVerify(byte[] signature) protected boolean engineVerify(byte[] signature)
throws XMLSignatureException { throws XMLSignatureException {
try { try {
if (log.isLoggable(java.util.logging.Level.FINE)) if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature)); log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature));
}
byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature); byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
return this._signatureAlgorithm.verify(jcebytes); return this.signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} catch (IOException ex) { } catch (IOException ex) {
...@@ -127,32 +124,29 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -127,32 +124,29 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException { protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) { if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName(); String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName(); String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey); this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK // reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555 // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm; Signature sig = this.signatureAlgorithm;
try { try {
this._signatureAlgorithm = Signature.getInstance this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
(_signatureAlgorithm.getAlgorithm());
} catch (Exception e) { } catch (Exception e) {
// this shouldn't occur, but if it does, restore previous // this shouldn't occur, but if it does, restore previous
// Signature // Signature
if (log.isLoggable(java.util.logging.Level.FINE)) { if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e); log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
} }
this._signatureAlgorithm = sig; this.signatureAlgorithm = sig;
} }
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -162,9 +156,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -162,9 +156,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected byte[] engineSign() throws XMLSignatureException { protected byte[] engineSign() throws XMLSignatureException {
try { try {
byte jcebytes[] = this._signatureAlgorithm.sign(); byte jcebytes[] = this.signatureAlgorithm.sign();
return SignatureDSA.convertASN1toXMLDSIG(jcebytes); return SignatureDSA.convertASN1toXMLDSIG(jcebytes);
} catch (IOException ex) { } catch (IOException ex) {
...@@ -178,20 +171,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -178,20 +171,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom) protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException { throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) { if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName(); String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey, this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
secureRandom);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -201,18 +191,16 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -201,18 +191,16 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected void engineInitSign(Key privateKey) throws XMLSignatureException { protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) { if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName(); String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey); this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -223,7 +211,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -223,7 +211,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/ */
protected void engineUpdate(byte[] input) throws XMLSignatureException { protected void engineUpdate(byte[] input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this.signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -234,7 +222,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -234,7 +222,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/ */
protected void engineUpdate(byte input) throws XMLSignatureException { protected void engineUpdate(byte input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this.signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -243,10 +231,9 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -243,10 +231,9 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected void engineUpdate(byte buf[], int offset, int len) protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(buf, offset, len); this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) { } catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -258,7 +245,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -258,7 +245,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected String engineGetJCEAlgorithmString() { protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm(); return this.signatureAlgorithm.getAlgorithm();
} }
/** /**
...@@ -267,7 +254,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -267,7 +254,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected String engineGetJCEProviderName() { protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName(); return this.signatureAlgorithm.getProvider().getName();
} }
/** /**
...@@ -282,8 +269,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -282,8 +269,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws IOException * @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A> * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/ */
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
throws IOException {
byte rLength = asn1Bytes[3]; byte rLength = asn1Bytes[3];
int i; int i;
...@@ -294,19 +280,18 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -294,19 +280,18 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
int j; int j;
for (j = sLength; for (j = sLength;
(j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--); (j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2) if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
|| (asn1Bytes[2] != 2) || (i > 20) || (asn1Bytes[2] != 2) || (i > 20)
|| (asn1Bytes[4 + rLength] != 2) || (j > 20)) { || (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
throw new IOException("Invalid ASN.1 format of DSA signature"); throw new IOException("Invalid ASN.1 format of DSA signature");
} }
byte xmldsigBytes[] = new byte[40]; byte xmldsigBytes[] = new byte[40];
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, i);
i);
System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes, System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
40 - j, j); 40 - j, j);
return xmldsigBytes; return xmldsigBytes;
} }
...@@ -323,8 +308,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -323,8 +308,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws IOException * @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A> * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/ */
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
throws IOException {
if (xmldsigBytes.length != 40) { if (xmldsigBytes.length != 40) {
throw new IOException("Invalid XMLDSIG format of DSA signature"); throw new IOException("Invalid XMLDSIG format of DSA signature");
...@@ -337,7 +321,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -337,7 +321,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
int j = i; int j = i;
if (xmldsigBytes[20 - i] < 0) { if (xmldsigBytes[20 - i] < 0) {
j += 1; j += 1;
} }
int k; int k;
...@@ -373,10 +357,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -373,10 +357,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @param HMACOutputLength * @param HMACOutputLength
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
protected void engineSetHMACOutputLength(int HMACOutputLength) protected void engineSetHMACOutputLength(int HMACOutputLength) throws XMLSignatureException {
throws XMLSignatureException { throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
throw new XMLSignatureException(
"algorithms.HMACOutputLengthOnlyForHMAC");
} }
/** /**
...@@ -387,9 +369,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -387,9 +369,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
protected void engineInitSign( protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec) Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
throws XMLSignatureException { ) throws XMLSignatureException {
throw new XMLSignatureException( throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnDSA");
"algorithms.CannotUseAlgorithmParameterSpecOnDSA");
} }
} }
...@@ -2,29 +2,28 @@ ...@@ -2,29 +2,28 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n; package com.sun.org.apache.xml.internal.security.c14n;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/** /**
* Class CanonicalizationException * Class CanonicalizationException
* *
...@@ -32,57 +31,58 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; ...@@ -32,57 +31,58 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
*/ */
public class CanonicalizationException extends XMLSecurityException { public class CanonicalizationException extends XMLSecurityException {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Constructor CanonicalizationException * Constructor CanonicalizationException
* *
*/ */
public CanonicalizationException() { public CanonicalizationException() {
super(); super();
} }
/** /**
* Constructor CanonicalizationException * Constructor CanonicalizationException
* *
* @param _msgID * @param msgID
*/ */
public CanonicalizationException(String _msgID) { public CanonicalizationException(String msgID) {
super(_msgID); super(msgID);
} }
/** /**
* Constructor CanonicalizationException * Constructor CanonicalizationException
* *
* @param _msgID * @param msgID
* @param exArgs * @param exArgs
*/ */
public CanonicalizationException(String _msgID, Object exArgs[]) { public CanonicalizationException(String msgID, Object exArgs[]) {
super(_msgID, exArgs); super(msgID, exArgs);
} }
/** /**
* Constructor CanonicalizationException * Constructor CanonicalizationException
* *
* @param _msgID * @param msgID
* @param _originalException * @param originalException
*/ */
public CanonicalizationException(String _msgID, Exception _originalException) { public CanonicalizationException(String msgID, Exception originalException) {
super(_msgID, _originalException); super(msgID, originalException);
} }
/** /**
* Constructor CanonicalizationException * Constructor CanonicalizationException
* *
* @param _msgID * @param msgID
* @param exArgs * @param exArgs
* @param _originalException * @param originalException
*/ */
public CanonicalizationException(String _msgID, Object exArgs[], public CanonicalizationException(
Exception _originalException) { String msgID, Object exArgs[], Exception originalException
super(_msgID, exArgs, _originalException); ) {
} super(msgID, exArgs, originalException);
}
} }
...@@ -39,6 +39,7 @@ import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicaliz ...@@ -39,6 +39,7 @@ import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicaliz
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments; import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments; import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315WithComments; import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315WithComments;
import com.sun.org.apache.xml.internal.security.c14n.implementations.CanonicalizerPhysical;
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException; import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
...@@ -91,6 +92,11 @@ public class Canonicalizer { ...@@ -91,6 +92,11 @@ public class Canonicalizer {
*/ */
public static final String ALGO_ID_C14N11_WITH_COMMENTS = public static final String ALGO_ID_C14N11_WITH_COMMENTS =
ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments"; ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
/**
* Non-standard algorithm to serialize the physical representation for XML Encryption
*/
public static final String ALGO_ID_C14N_PHYSICAL =
"http://santuario.apache.org/c14n/physical";
private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash = private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash =
new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>(); new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
...@@ -202,6 +208,10 @@ public class Canonicalizer { ...@@ -202,6 +208,10 @@ public class Canonicalizer {
Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS, Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
Canonicalizer11_WithComments.class Canonicalizer11_WithComments.class
); );
canonicalizerHash.put(
Canonicalizer.ALGO_ID_C14N_PHYSICAL,
CanonicalizerPhysical.class
);
} }
/** /**
......
...@@ -2,26 +2,26 @@ ...@@ -2,26 +2,26 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n; package com.sun.org.apache.xml.internal.security.c14n;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Set; import java.util.Set;
...@@ -29,7 +29,6 @@ import java.util.Set; ...@@ -29,7 +29,6 @@ import java.util.Set;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils; import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;
...@@ -37,166 +36,134 @@ import org.w3c.dom.Node; ...@@ -37,166 +36,134 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
/** /**
* Base class which all Caninicalization algorithms extend. * Base class which all Canonicalization algorithms extend.
* *
* $todo$ cange JavaDoc
* @author Christian Geuer-Pollmann * @author Christian Geuer-Pollmann
*/ */
public abstract class CanonicalizerSpi { public abstract class CanonicalizerSpi {
/** /** Reset the writer after a c14n */
* Method canonicalize protected boolean reset = false;
*
* /**
* @param inputBytes * Method canonicalize
* @return the c14n bytes. *
* * @param inputBytes
* * @return the c14n bytes.
* @throws CanonicalizationException *
* @throws java.io.IOException * @throws CanonicalizationException
* @throws javax.xml.parsers.ParserConfigurationException * @throws java.io.IOException
* @throws org.xml.sax.SAXException * @throws javax.xml.parsers.ParserConfigurationException
* * @throws org.xml.sax.SAXException
*/ */
public byte[] engineCanonicalize(byte[] inputBytes) public byte[] engineCanonicalize(byte[] inputBytes)
throws javax.xml.parsers.ParserConfigurationException, throws javax.xml.parsers.ParserConfigurationException, java.io.IOException,
java.io.IOException, org.xml.sax.SAXException, org.xml.sax.SAXException, CanonicalizationException {
CanonicalizationException {
java.io.InputStream bais = new ByteArrayInputStream(inputBytes);
java.io.ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes); InputSource in = new InputSource(bais);
InputSource in = new InputSource(bais); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
// needs to validate for ID attribute normalization
// needs to validate for ID attribute nomalization dfactory.setNamespaceAware(true);
dfactory.setNamespaceAware(true);
DocumentBuilder db = dfactory.newDocumentBuilder();
DocumentBuilder db = dfactory.newDocumentBuilder();
Document document = db.parse(in);
/* return this.engineCanonicalizeSubTree(document);
* for some of the test vectors from the specification, }
* there has to be a validatin parser for ID attributes, default
* attribute values, NMTOKENS, etc. /**
* Unfortunaltely, the test vectors do use different DTDs or * Method engineCanonicalizeXPathNodeSet
* even no DTD. So Xerces 1.3.1 fires many warnings about using *
* ErrorHandlers. * @param xpathNodeSet
* * @return the c14n bytes
* Text from the spec: * @throws CanonicalizationException
* */
* The input octet stream MUST contain a well-formed XML document, public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet)
* but the input need not be validated. However, the attribute throws CanonicalizationException {
* value normalization and entity reference resolution MUST be return this.engineCanonicalizeXPathNodeSet(
* performed in accordance with the behaviors of a validating XMLUtils.convertNodelistToSet(xpathNodeSet)
* XML processor. As well, nodes for default attributes (declared );
* in the ATTLIST with an AttValue but not specified) are created }
* in each element. Thus, the declarations in the document type
* declaration are used to help create the canonical form, even /**
* though the document type declaration is not retained in the * Method engineCanonicalizeXPathNodeSet
* canonical form. *
* * @param xpathNodeSet
*/ * @param inclusiveNamespaces
* @return the c14n bytes
// ErrorHandler eh = new C14NErrorHandler(); * @throws CanonicalizationException
// db.setErrorHandler(eh); */
Document document = db.parse(in); public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet, String inclusiveNamespaces)
byte result[] = this.engineCanonicalizeSubTree(document); throws CanonicalizationException {
return result; return this.engineCanonicalizeXPathNodeSet(
} XMLUtils.convertNodelistToSet(xpathNodeSet), inclusiveNamespaces
);
/** }
* Method engineCanonicalizeXPathNodeSet
* /**
* @param xpathNodeSet * Returns the URI of this engine.
* @return the c14n bytes * @return the URI
* @throws CanonicalizationException */
*/ public abstract String engineGetURI();
public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet)
throws CanonicalizationException { /**
* Returns true if comments are included
return this * @return true if comments are included
.engineCanonicalizeXPathNodeSet(XMLUtils */
.convertNodelistToSet(xpathNodeSet)); public abstract boolean engineGetIncludeComments();
}
/**
/** * C14n a nodeset
* Method engineCanonicalizeXPathNodeSet *
* * @param xpathNodeSet
* @param xpathNodeSet * @return the c14n bytes
* @param inclusiveNamespaces * @throws CanonicalizationException
* @return the c14n bytes */
* @throws CanonicalizationException public abstract byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
*/ throws CanonicalizationException;
public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException { /**
* C14n a nodeset
return this *
.engineCanonicalizeXPathNodeSet(XMLUtils * @param xpathNodeSet
.convertNodelistToSet(xpathNodeSet), inclusiveNamespaces); * @param inclusiveNamespaces
} * @return the c14n bytes
* @throws CanonicalizationException
//J- */
/** Returns the URI of this engine. public abstract byte[] engineCanonicalizeXPathNodeSet(
* @return the URI Set<Node> xpathNodeSet, String inclusiveNamespaces
*/ ) throws CanonicalizationException;
public abstract String engineGetURI();
/**
/** Returns the URI if include comments * C14n a node tree.
* @return true if include. *
*/ * @param rootNode
public abstract boolean engineGetIncludeComments(); * @return the c14n bytes
* @throws CanonicalizationException
/** */
* C14n a nodeset public abstract byte[] engineCanonicalizeSubTree(Node rootNode)
* throws CanonicalizationException;
* @param xpathNodeSet
* @return the c14n bytes /**
* @throws CanonicalizationException * C14n a node tree.
*/ *
public abstract byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet) * @param rootNode
throws CanonicalizationException; * @param inclusiveNamespaces
* @return the c14n bytes
/** * @throws CanonicalizationException
* C14n a nodeset */
* public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
* @param xpathNodeSet throws CanonicalizationException;
* @param inclusiveNamespaces
* @return the c14n bytes /**
* @throws CanonicalizationException * Sets the writer where the canonicalization ends. ByteArrayOutputStream if
*/ * none is set.
public abstract byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces) * @param os
throws CanonicalizationException; */
public abstract void setWriter(OutputStream os);
/**
* C14n a node tree.
*
* @param rootNode
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeSubTree(Node rootNode)
throws CanonicalizationException;
/**
* C14n a node tree.
*
* @param rootNode
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
throws CanonicalizationException;
/**
* Sets the writter where the cannocalization ends. ByteArrayOutputStream if
* none is setted.
* @param os
*/
public abstract void setWriter(OutputStream os);
/** Reset the writter after a c14n */
protected boolean reset=false;
//J+
} }
...@@ -2,87 +2,82 @@ ...@@ -2,87 +2,82 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n; package com.sun.org.apache.xml.internal.security.c14n;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
*
* @author Christian Geuer-Pollmann
*/
public class InvalidCanonicalizerException extends XMLSecurityException { public class InvalidCanonicalizerException extends XMLSecurityException {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Constructor InvalidCanonicalizerException * Constructor InvalidCanonicalizerException
* *
*/ */
public InvalidCanonicalizerException() { public InvalidCanonicalizerException() {
super(); super();
} }
/** /**
* Constructor InvalidCanonicalizerException * Constructor InvalidCanonicalizerException
* *
* @param _msgID * @param msgID
*/ */
public InvalidCanonicalizerException(String _msgID) { public InvalidCanonicalizerException(String msgID) {
super(_msgID); super(msgID);
} }
/** /**
* Constructor InvalidCanonicalizerException * Constructor InvalidCanonicalizerException
* *
* @param _msgID * @param msgID
* @param exArgs * @param exArgs
*/ */
public InvalidCanonicalizerException(String _msgID, Object exArgs[]) { public InvalidCanonicalizerException(String msgID, Object exArgs[]) {
super(_msgID, exArgs); super(msgID, exArgs);
} }
/** /**
* Constructor InvalidCanonicalizerException * Constructor InvalidCanonicalizerException
* *
* @param _msgID * @param msgID
* @param _originalException * @param originalException
*/ */
public InvalidCanonicalizerException(String _msgID, public InvalidCanonicalizerException(String msgID, Exception originalException) {
Exception _originalException) { super(msgID, originalException);
super(_msgID, _originalException); }
}
/** /**
* Constructor InvalidCanonicalizerException * Constructor InvalidCanonicalizerException
* *
* @param _msgID * @param msgID
* @param exArgs * @param exArgs
* @param _originalException * @param originalException
*/ */
public InvalidCanonicalizerException(String _msgID, Object exArgs[], public InvalidCanonicalizerException(
Exception _originalException) { String msgID, Object exArgs[], Exception originalException
super(_msgID, exArgs, _originalException); ) {
} super(msgID, exArgs, originalException);
}
} }
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n.helper; package com.sun.org.apache.xml.internal.security.c14n.helper;
...@@ -43,10 +45,10 @@ import java.util.Comparator; ...@@ -43,10 +45,10 @@ import java.util.Comparator;
*/ */
public class AttrCompare implements Comparator<Attr>, Serializable { public class AttrCompare implements Comparator<Attr>, Serializable {
private final static long serialVersionUID = -7113259629930576230L; private static final long serialVersionUID = -7113259629930576230L;
private final static int ATTR0_BEFORE_ATTR1 = -1; private static final int ATTR0_BEFORE_ATTR1 = -1;
private final static int ATTR1_BEFORE_ATTR0 = 1; private static final int ATTR1_BEFORE_ATTR0 = 1;
private final static String XMLNS=Constants.NamespaceSpecNS; private static final String XMLNS = Constants.NamespaceSpecNS;
/** /**
* Compares two attributes based on the C14n specification. * Compares two attributes based on the C14n specification.
...@@ -69,12 +71,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable { ...@@ -69,12 +71,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
* *
*/ */
public int compare(Attr attr0, Attr attr1) { public int compare(Attr attr0, Attr attr1) {
String namespaceURI0 = attr0.getNamespaceURI(); String namespaceURI0 = attr0.getNamespaceURI();
String namespaceURI1 = attr1.getNamespaceURI(); String namespaceURI1 = attr1.getNamespaceURI();
boolean isNamespaceAttr0 = XMLNS==namespaceURI0; boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
boolean isNamespaceAttr1 = XMLNS==namespaceURI1; boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);
if (isNamespaceAttr0) { if (isNamespaceAttr0) {
if (isNamespaceAttr1) { if (isNamespaceAttr1) {
...@@ -82,11 +83,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable { ...@@ -82,11 +83,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
String localname0 = attr0.getLocalName(); String localname0 = attr0.getLocalName();
String localname1 = attr1.getLocalName(); String localname1 = attr1.getLocalName();
if (localname0.equals("xmlns")) { if ("xmlns".equals(localname0)) {
localname0 = ""; localname0 = "";
} }
if (localname1.equals("xmlns")) { if ("xmlns".equals(localname1)) {
localname1 = ""; localname1 = "";
} }
...@@ -94,9 +95,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable { ...@@ -94,9 +95,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
} }
// attr0 is a namespace, attr1 is not // attr0 is a namespace, attr1 is not
return ATTR0_BEFORE_ATTR1; return ATTR0_BEFORE_ATTR1;
} } else if (isNamespaceAttr1) {
if (isNamespaceAttr1) {
// attr1 is a namespace, attr0 is not // attr1 is a namespace, attr0 is not
return ATTR1_BEFORE_ATTR0; return ATTR1_BEFORE_ATTR0;
} }
...@@ -109,9 +108,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable { ...@@ -109,9 +108,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
return name0.compareTo(name1); return name0.compareTo(name1);
} }
return ATTR0_BEFORE_ATTR1; return ATTR0_BEFORE_ATTR1;
} } else if (namespaceURI1 == null) {
if (namespaceURI1 == null) {
return ATTR1_BEFORE_ATTR0; return ATTR1_BEFORE_ATTR0;
} }
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 2008 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n.implementations; package com.sun.org.apache.xml.internal.security.c14n.implementations;
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 2008 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n.implementations; package com.sun.org.apache.xml.internal.security.c14n.implementations;
......
...@@ -2,48 +2,44 @@ ...@@ -2,48 +2,44 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /**
* Copyright 1999-2004 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* Licensed under the Apache License, Version 2.0 (the "License"); * distributed with this work for additional information
* you may not use this file except in compliance with the License. * regarding copyright ownership. The ASF licenses this file
* You may obtain a copy of the License at * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* http://www.apache.org/licenses/LICENSE-2.0 * with the License. You may obtain a copy of the License at
* *
* Unless required by applicable law or agreed to in writing, software * http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ */
package com.sun.org.apache.xml.internal.security.c14n.implementations; package com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/** public class Canonicalizer20010315ExclOmitComments extends Canonicalizer20010315Excl {
*
*
*/
public class Canonicalizer20010315ExclOmitComments
extends Canonicalizer20010315Excl {
/** /**
* *
*/ */
public Canonicalizer20010315ExclOmitComments() { public Canonicalizer20010315ExclOmitComments() {
super(false); super(false);
} }
/** @inheritDoc */ /** @inheritDoc */
public final String engineGetURI() { public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS; return Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
} }
/** @inheritDoc */ /** @inheritDoc */
public final boolean engineGetIncludeComments() { public final boolean engineGetIncludeComments() {
return false; return false;
} }
} }
...@@ -31,10 +31,13 @@ import java.util.concurrent.CopyOnWriteArrayList; ...@@ -31,10 +31,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.DEREncodedKeyValueResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.DSAKeyValueResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.DSAKeyValueResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.KeyInfoReferenceResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.RSAKeyValueResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.RSAKeyValueResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.RetrievalMethodResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.RetrievalMethodResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509CertificateResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509CertificateResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509DigestResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509IssuerSerialResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509IssuerSerialResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509SKIResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509SKIResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509SubjectNameResolver; import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509SubjectNameResolver;
...@@ -277,6 +280,9 @@ public class KeyResolver { ...@@ -277,6 +280,9 @@ public class KeyResolver {
keyResolverList.add(new KeyResolver(new RetrievalMethodResolver())); keyResolverList.add(new KeyResolver(new RetrievalMethodResolver()));
keyResolverList.add(new KeyResolver(new X509SubjectNameResolver())); keyResolverList.add(new KeyResolver(new X509SubjectNameResolver()));
keyResolverList.add(new KeyResolver(new X509IssuerSerialResolver())); keyResolverList.add(new KeyResolver(new X509IssuerSerialResolver()));
keyResolverList.add(new KeyResolver(new DEREncodedKeyValueResolver()));
keyResolverList.add(new KeyResolver(new KeyInfoReferenceResolver()));
keyResolverList.add(new KeyResolver(new X509DigestResolver()));
resolverVector.addAll(keyResolverList); resolverVector.addAll(keyResolverList);
} }
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册