提交 67579c6e 编写于 作者: L lana

Merge

......@@ -219,3 +219,6 @@ a2a2a91075ad85becbe10a39d7fd04ef9bea8df5 jdk8-b92
42aa9f1828852bb8b77e98ec695211493ae0759d jdk8-b95
4a5d3cf2b3af1660db0237e8da324c140e534fa4 jdk8-b96
978a95239044f26dcc8a6d59246be07ad6ca6be2 jdk8-b97
c4908732fef5235f1b98cafe0ce507771ef7892c jdk8-b98
6a099a36589bd933957272ba63e5263bede29971 jdk8-b99
5be9c5bfcfe9b2a40412b4fb364377d49de014eb jdk8-b100
......@@ -102,7 +102,7 @@ SUNWprivate_1.1 {
Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle;
Java_sun_security_pkcs11_Secmod_nssLoadLibrary;
Java_sun_security_pkcs11_Secmod_nssVersionCheck;
Java_sun_security_pkcs11_Secmod_nssInit;
Java_sun_security_pkcs11_Secmod_nssInitialize;
Java_sun_security_pkcs11_Secmod_nssGetModuleList;
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.
#
# This code is free software; you can redistribute it and/or modify it
......@@ -102,7 +102,7 @@ SUNWprivate_1.1 {
Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle;
Java_sun_security_pkcs11_Secmod_nssLoadLibrary;
Java_sun_security_pkcs11_Secmod_nssVersionCheck;
Java_sun_security_pkcs11_Secmod_nssInit;
Java_sun_security_pkcs11_Secmod_nssInitialize;
Java_sun_security_pkcs11_Secmod_nssGetModuleList;
local:
......
......@@ -32,6 +32,7 @@ import java.util.List;
import javax.swing.RootPaneContainer;
import com.apple.eawt.AppEvent.FullScreenEvent;
import sun.awt.SunToolkit;
import java.lang.annotation.Native;
......@@ -75,7 +76,7 @@ final class FullScreenHandler {
static void handleFullScreenEventFromNative(final Window window, final int type) {
if (!(window instanceof RootPaneContainer)) return; // handles null
EventQueue.invokeLater(new Runnable() {
SunToolkit.executeOnEventHandlerThread(window, new Runnable() {
public void run() {
final FullScreenHandler handler = getHandlerFor((RootPaneContainer)window);
if (handler != null) handler.notifyListener(new FullScreenEvent(window), type);
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -31,6 +31,8 @@ import java.io.File;
import java.net.*;
import java.util.*;
import java.util.List;
import sun.awt.AppContext;
import sun.awt.SunToolkit;
import com.apple.eawt.AppEvent.*;
......@@ -269,11 +271,9 @@ class _AppEventHandler {
}
class _AppReOpenedDispatcher extends _AppEventMultiplexor<AppReOpenedListener> {
void performOnListeners(final List<AppReOpenedListener> listeners, final _NativeEvent event) {
void performOnListener(AppReOpenedListener listener, final _NativeEvent event) {
final AppReOpenedEvent e = new AppReOpenedEvent();
for (final AppReOpenedListener listener : listeners) {
listener.appReOpened(e);
}
listener.appReOpened(e);
}
}
......@@ -415,50 +415,67 @@ class _AppEventHandler {
}
abstract class _AppEventMultiplexor<L> {
final List<L> _listeners = new ArrayList<L>(0);
private final Map<L, AppContext> listenerToAppContext =
new IdentityHashMap<L, AppContext>();
boolean nativeListenerRegistered;
// called from AppKit Thread-0
void dispatch(final _NativeEvent event, final Object... args) {
// grab a local ref to the listeners
final List<L> localListeners;
// grab a local ref to the listeners and its contexts as an array of the map's entries
final ArrayList<Map.Entry<L, AppContext>> localEntries;
synchronized (this) {
if (_listeners.size() == 0) return;
localListeners = new ArrayList<L>(_listeners);
if (listenerToAppContext.size() == 0) {
return;
}
localEntries = new ArrayList<Map.Entry<L, AppContext>>(listenerToAppContext.size());
localEntries.addAll(listenerToAppContext.entrySet());
}
EventQueue.invokeLater(new Runnable() {
public void run() {
performOnListeners(localListeners, event);
}
});
for (final Map.Entry<L, AppContext> e : localEntries) {
final L listener = e.getKey();
final AppContext listenerContext = e.getValue();
SunToolkit.invokeLaterOnAppContext(listenerContext, new Runnable() {
public void run() {
performOnListener(listener, event);
}
});
}
}
synchronized void addListener(final L listener) {
setListenerContext(listener, AppContext.getAppContext());
if (!nativeListenerRegistered) {
registerNativeListener();
nativeListenerRegistered = true;
}
_listeners.add(listener);
}
synchronized void removeListener(final L listener) {
_listeners.remove(listener);
listenerToAppContext.remove(listener);
}
abstract void performOnListeners(final List<L> listeners, final _NativeEvent event);
abstract void performOnListener(L listener, final _NativeEvent event);
void registerNativeListener() { }
private void setListenerContext(L listener, AppContext listenerContext) {
if (listenerContext == null) {
throw new RuntimeException(
"Attempting to add a listener from a thread group without AppContext");
}
listenerToAppContext.put(listener, AppContext.getAppContext());
}
}
abstract class _BooleanAppEventMultiplexor<L, E> extends _AppEventMultiplexor<L> {
@Override
void performOnListeners(final List<L> listeners, final _NativeEvent event) {
void performOnListener(L listener, final _NativeEvent event) {
final boolean isTrue = Boolean.TRUE.equals(event.get(0));
final E e = createEvent(isTrue);
if (isTrue) {
for (final L listener : listeners) performTrueEventOn(listener, e);
performTrueEventOn(listener, e);
} else {
for (final L listener : listeners) performFalseEventOn(listener, e);
performFalseEventOn(listener, e);
}
}
......@@ -479,30 +496,34 @@ class _AppEventHandler {
*/
abstract class _AppEventDispatcher<H> {
H _handler;
AppContext handlerContext;
// called from AppKit Thread-0
void dispatch(final _NativeEvent event) {
EventQueue.invokeLater(new Runnable() {
public void run() {
// grab a local ref to the handler
final H localHandler;
synchronized (_AppEventDispatcher.this) {
localHandler = _handler;
}
// grab a local ref to the handler
final H localHandler;
final AppContext localHandlerContext;
synchronized (_AppEventDispatcher.this) {
localHandler = _handler;
localHandlerContext = handlerContext;
}
// invoke the handler outside of the synchronized block
if (localHandler == null) {
performDefaultAction(event);
} else {
if (localHandler == null) {
performDefaultAction(event);
} else {
SunToolkit.invokeLaterOnAppContext(localHandlerContext, new Runnable() {
public void run() {
performUsing(localHandler, event);
}
}
});
});
}
}
synchronized void setHandler(final H handler) {
this._handler = handler;
setHandlerContext(AppContext.getAppContext());
// if a new handler is installed, block addition of legacy ApplicationListeners
if (handler == legacyHandler) return;
legacyHandler.blockLegacyAPI();
......@@ -510,6 +531,15 @@ class _AppEventHandler {
void performDefaultAction(final _NativeEvent event) { } // by default, do nothing
abstract void performUsing(final H handler, final _NativeEvent event);
protected void setHandlerContext(AppContext ctx) {
if (ctx == null) {
throw new RuntimeException(
"Attempting to set a handler from a thread group without AppContext");
}
handlerContext = ctx;
}
}
abstract class _QueuingAppEventDispatcher<H> extends _AppEventDispatcher<H> {
......@@ -531,6 +561,8 @@ class _AppEventHandler {
synchronized void setHandler(final H handler) {
this._handler = handler;
setHandlerContext(AppContext.getAppContext());
// dispatch any events in the queue
if (queuedEvents != null) {
// grab a local ref to the queue, so the real one can be nulled out
......
......@@ -25,6 +25,8 @@
package com.apple.eawt.event;
import sun.awt.SunToolkit;
import java.awt.*;
import java.util.*;
import java.util.List;
......@@ -70,7 +72,7 @@ final class GestureHandler {
static void handleGestureFromNative(final Window window, final int type, final double x, final double y, final double a, final double b) {
if (window == null) return; // should never happen...
EventQueue.invokeLater(new Runnable() {
SunToolkit.executeOnEventHandlerThread(window, new Runnable() {
public void run() {
final Component component = SwingUtilities.getDeepestComponentAt(window, (int)x, (int)y);
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -32,6 +32,7 @@ import java.util.Hashtable;
import javax.swing.*;
import sun.awt.SunToolkit;
import sun.lwawt.LWToolkit;
import sun.lwawt.macosx.*;
......@@ -144,7 +145,7 @@ class ScreenMenu extends Menu implements ContainerListener, ComponentListener, S
updateItems();
fItemBounds = new Rectangle[invoker.getMenuComponentCount()];
}
}, null);
}, invoker);
} catch (final Exception e) {
System.err.println(e);
e.printStackTrace();
......@@ -172,7 +173,7 @@ class ScreenMenu extends Menu implements ContainerListener, ComponentListener, S
fItemBounds = null;
}
}, null);
}, invoker);
} catch (final Exception e) {
e.printStackTrace();
}
......@@ -200,7 +201,7 @@ class ScreenMenu extends Menu implements ContainerListener, ComponentListener, S
if (kind == 0) return;
if (fItemBounds == null) return;
SwingUtilities.invokeLater(new Runnable() {
SunToolkit.executeOnEventHandlerThread(fInvoker, new Runnable() {
@Override
public void run() {
Component target = null;
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -53,7 +53,7 @@ public class CCheckboxMenuItem extends CMenuItem implements CheckboxMenuItemPeer
public void handleAction(final boolean state) {
final CheckboxMenuItem target = (CheckboxMenuItem)getTarget();
EventQueue.invokeLater(new Runnable() {
SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
public void run() {
target.setState(state);
}
......
......@@ -107,10 +107,6 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
loc = rootComponent.getLocation();
}
//It sure will be LWComponentPeer instance as rootComponent is a Window
PlatformWindow platformWindow = ((LWComponentPeer)rootComponent.getPeer()).getPlatformWindow();
long nativeViewPtr = CPlatformWindow.getNativeViewPtr(platformWindow);
// If there isn't any drag image make one of default appearance:
if (fDragImage == null)
this.setDefaultDragImage(component);
......@@ -137,6 +133,11 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
}
try {
//It sure will be LWComponentPeer instance as rootComponent is a Window
PlatformWindow platformWindow = ((LWComponentPeer)rootComponent.getPeer()).getPlatformWindow();
long nativeViewPtr = CPlatformWindow.getNativeViewPtr(platformWindow);
if (nativeViewPtr == 0L) throw new InvalidDnDOperationException("Unsupported platform window implementation");
// Create native dragging source:
final long nativeDragSource = createNativeDragSource(component, nativeViewPtr, transferable, triggerEvent,
(int) (dragOrigin.getX()), (int) (dragOrigin.getY()), extModifiers,
......
......@@ -52,6 +52,8 @@ public final class CDropTarget {
fPeer = peer;
long nativePeer = CPlatformWindow.getNativeViewPtr(((LWComponentPeer) peer).getPlatformWindow());
if (nativePeer == 0L) return; // Unsupported for a window without a native view (plugin)
// Create native dragging destination:
fNativeDropTarget = this.createNativeDropTarget(dropTarget, component, peer, nativePeer);
if (fNativeDropTarget == 0) {
......
......@@ -479,12 +479,14 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
deliverZoom(true);
this.normalBounds = peer.getBounds();
long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
Rectangle toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
// Flip the y coordinate
Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
toBounds.y = frame.height - toBounds.y - toBounds.height;
setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
GraphicsConfiguration config = getPeer().getGraphicsConfiguration();
Insets i = ((CGraphicsDevice)config.getDevice()).getScreenInsets();
Rectangle toBounds = config.getBounds();
setBounds(toBounds.x + i.left,
toBounds.y + i.top,
toBounds.width - i.left - i.right,
toBounds.height - i.top - i.bottom);
}
}
......@@ -751,13 +753,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// the move/size notification from the underlying system comes
// but it contains a bounds smaller than the whole screen
// and therefore we need to create the synthetic notifications
Rectangle screenBounds;
final long screenPtr = CWrapper.NSWindow.screen(getNSWindowPtr());
try {
screenBounds = CWrapper.NSScreen.frame(screenPtr).getBounds();
} finally {
CWrapper.NSObject.release(screenPtr);
}
Rectangle screenBounds = getPeer().getGraphicsConfiguration().getBounds();
peer.notifyReshape(screenBounds.x, screenBounds.y, screenBounds.width,
screenBounds.height);
}
......@@ -900,8 +896,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
nativePeer = ((CPlatformWindow) platformWindow).getContentView().getAWTView();
} else if (platformWindow instanceof CViewPlatformEmbeddedFrame){
nativePeer = ((CViewPlatformEmbeddedFrame) platformWindow).getNSViewPtr();
} else {
throw new IllegalArgumentException("Unsupported platformWindow implementation");
}
return nativePeer;
}
......@@ -932,25 +926,19 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
final Rectangle oldB = nativeBounds;
nativeBounds = new Rectangle(x, y, width, height);
final GraphicsConfiguration oldGC = peer.getGraphicsConfiguration();
final GraphicsConfiguration newGC = peer.getGraphicsConfiguration();
// System-dependent appearance optimization.
if (peer != null) {
peer.notifyReshape(x, y, width, height);
}
if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
|| isFullScreenAnimationOn || !Objects.equals(newGC, oldGC)) {
flushBuffers();
// System-dependent appearance optimization.
if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
|| isFullScreenAnimationOn) {
flushBuffers();
}
}
}
private void deliverWindowClosingEvent() {
if (peer != null) {
if (peer.getBlocker() == null) {
peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
}
if (peer != null && peer.getBlocker() == null) {
peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
}
}
......
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -96,7 +96,7 @@ public class CViewEmbeddedFrame extends EmbeddedFrame {
validate();
setVisible(true);
}
}, null);
}, this);
} catch (InterruptedException | InvocationTargetException ex) {}
}
}
......@@ -71,8 +71,6 @@ public final class CWrapper {
public static native void zoom(long window);
public static native void makeFirstResponder(long window, long responder);
public static native long screen(long window);
}
public static final class NSView {
......@@ -95,12 +93,6 @@ public final class CWrapper {
public static native void release(long object);
}
public static final class NSScreen {
public static native Rectangle2D frame(long screen);
public static native Rectangle2D visibleFrame(long screen);
public static native long screenByDisplayId(int displayID);
}
public static final class NSColor {
public static native long clearColor();
}
......
......@@ -382,7 +382,7 @@ static unichar NsGetDeadKeyChar(unsigned short keyCode)
{
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
if (uchr == nil) { return; }
if (uchr == nil) { return 0; }
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
// Carbon modifiers should be used instead of NSEvent modifiers
UInt32 modifierKeyState = (GetCurrentEventKeyModifiers() >> 8) & 0xFF;
......
......@@ -82,8 +82,13 @@ JNF_COCOA_ENTER(env);
// keys, so we need to do the same translation here that we do
// for the regular key down events
if ([eventKey length] == 1) {
unichar ch = NsCharToJavaChar([eventKey characterAtIndex:0], 0);
eventKey = [NSString stringWithCharacters: &ch length: 1];
unichar origChar = [eventKey characterAtIndex:0];
unichar newChar = NsCharToJavaChar(origChar, 0);
if (newChar == java_awt_event_KeyEvent_CHAR_UNDEFINED) {
newChar = origChar;
}
eventKey = [NSString stringWithCharacters: &newChar length: 1];
}
if ([menuKey isEqualToString:eventKey]) {
......
......@@ -396,31 +396,6 @@ JNF_COCOA_ENTER(env);
JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CWrapper$NSWindow
* Method: screen
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL
Java_sun_lwawt_macosx_CWrapper_00024NSWindow_screen
(JNIEnv *env, jclass cls, jlong windowPtr)
{
__block jlong screenPtr = 0L;
JNF_COCOA_ENTER(env);
AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
const NSScreen *screen = [window screen];
CFRetain(screen); // GC
screenPtr = ptr_to_jlong(screen);
}];
JNF_COCOA_EXIT(env);
return screenPtr;
}
/*
* Method: miniaturize
* Signature: (J)V
......@@ -690,92 +665,6 @@ JNF_COCOA_ENTER(env);
JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CWrapper$NSScreen
* Method: frame
* Signature: (J)Ljava/awt/Rectangle;
*/
JNIEXPORT jobject JNICALL
Java_sun_lwawt_macosx_CWrapper_00024NSScreen_frame
(JNIEnv *env, jclass cls, jlong screenPtr)
{
jobject jRect = NULL;
JNF_COCOA_ENTER(env);
__block NSRect rect = NSZeroRect;
NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
rect = [screen frame];
}];
jRect = NSToJavaRect(env, rect);
JNF_COCOA_EXIT(env);
return jRect;
}
/*
* Class: sun_lwawt_macosx_CWrapper_NSScreen
* Method: visibleFrame
* Signature: (J)Ljava/awt/geom/Rectangle2D;
*/
JNIEXPORT jobject JNICALL
Java_sun_lwawt_macosx_CWrapper_00024NSScreen_visibleFrame
(JNIEnv *env, jclass cls, jlong screenPtr)
{
jobject jRect = NULL;
JNF_COCOA_ENTER(env);
__block NSRect rect = NSZeroRect;
NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
rect = [screen visibleFrame];
}];
jRect = NSToJavaRect(env, rect);
JNF_COCOA_EXIT(env);
return jRect;
}
/*
* Class: sun_lwawt_macosx_CWrapper_NSScreen
* Method: screenByDisplayId
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL
Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screenByDisplayId
(JNIEnv *env, jclass cls, jint displayID)
{
__block jlong screenPtr = 0L;
JNF_COCOA_ENTER(env);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
NSArray *screens = [NSScreen screens];
for (NSScreen *screen in screens) {
NSDictionary *screenInfo = [screen deviceDescription];
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
if ([screenID intValue] == displayID){
CFRetain(screen); // GC
screenPtr = ptr_to_jlong(screen);
break;
}
}
}];
JNF_COCOA_EXIT(env);
return screenPtr;
}
/*
* Class: sun_lwawt_macosx_CWrapper$NSColor
* Method: clearColor
......
......@@ -102,7 +102,7 @@ horizontal=horizontal
#
# accessible actions
#
toggle expand=toggle expand
toggleexpand=toggle expand
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=horizontal
#
# accessible actions
#
toggle expand=ein-/ausblenden
toggleexpand=ein-/ausblenden
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=horizontal
#
# accessible actions
#
toggle expand=activar/desactivar ampliaci\u00F3n
toggleexpand=activar/desactivar ampliaci\u00F3n
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=horizontal
#
# accessible actions
#
toggle expand=basculer le d\u00E9veloppement
toggleexpand=basculer le d\u00E9veloppement
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=orizzontale
#
# accessible actions
#
toggle expand=abilita/disabilita espansione
toggleexpand=abilita/disabilita espansione
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=\u6C34\u5E73
#
# accessible actions
#
toggle expand=\u5C55\u958B\u306E\u30C8\u30B0\u30EB
toggleexpand=\u5C55\u958B\u306E\u30C8\u30B0\u30EB
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=\uAC00\uB85C
#
# accessible actions
#
toggle expand=\uD1A0\uAE00 \uD655\uC7A5
toggleexpand=\uD1A0\uAE00 \uD655\uC7A5
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=horizontal
#
# accessible actions
#
toggle expand=alternar expans\u00E3o
toggleexpand=alternar expans\u00E3o
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=horisontell
#
# accessible actions
#
toggle expand=v\u00E4xla ut\u00F6ka
toggleexpand=v\u00E4xla ut\u00F6ka
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=\u6C34\u5E73
#
# accessible actions
#
toggle expand=\u5207\u6362\u5C55\u5F00
toggleexpand=\u5207\u6362\u5C55\u5F00
# new relations, roles and states for J2SE 1.5.0
......
......@@ -102,7 +102,7 @@ horizontal=\u6C34\u5E73
#
# accessible actions
#
toggle expand=\u5207\u63DB\u64F4\u5C55
toggleexpand=\u5207\u63DB\u64F4\u5C55
# new relations, roles and states for J2SE 1.5.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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -31,6 +31,7 @@ import javax.crypto.spec.DESKeySpec;
import java.security.InvalidKeyException;
import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.SecretKeySpec;
/**
* This class implements the DES key factory of the Sun provider.
......@@ -60,20 +61,22 @@ public final class DESKeyFactory extends SecretKeyFactorySpi {
*/
protected SecretKey engineGenerateSecret(KeySpec keySpec)
throws InvalidKeySpecException {
DESKey desKey = null;
try {
if (!(keySpec instanceof DESKeySpec)) {
throw new InvalidKeySpecException
("Inappropriate key specification");
if (keySpec instanceof DESKeySpec) {
return new DESKey(((DESKeySpec)keySpec).getKey());
}
else {
DESKeySpec desKeySpec = (DESKeySpec)keySpec;
desKey = new DESKey(desKeySpec.getKey());
if (keySpec instanceof SecretKeySpec) {
return new DESKey(((SecretKeySpec)keySpec).getEncoded());
}
throw new InvalidKeySpecException(
"Inappropriate key specification");
} 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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -31,6 +31,7 @@ import javax.crypto.spec.DESedeKeySpec;
import java.security.InvalidKeyException;
import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.SecretKeySpec;
/**
* This class implements the DES-EDE key factory of the Sun provider.
......@@ -60,20 +61,20 @@ public final class DESedeKeyFactory extends SecretKeyFactorySpi {
*/
protected SecretKey engineGenerateSecret(KeySpec keySpec)
throws InvalidKeySpecException {
DESedeKey desEdeKey = null;
try {
if (keySpec instanceof DESedeKeySpec) {
DESedeKeySpec desEdeKeySpec = (DESedeKeySpec)keySpec;
desEdeKey = new DESedeKey(desEdeKeySpec.getKey());
return new DESedeKey(((DESedeKeySpec)keySpec).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) {
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -83,7 +83,7 @@ public final class DHKeyFactory extends KeyFactorySpi {
}
} catch (InvalidKeyException e) {
throw new InvalidKeySpecException
("Inappropriate key specification");
("Inappropriate key specification", e);
}
}
......@@ -118,7 +118,7 @@ public final class DHKeyFactory extends KeyFactorySpi {
}
} catch (InvalidKeyException e) {
throw new InvalidKeySpecException
("Inappropriate key specification");
("Inappropriate key specification", e);
}
}
......@@ -227,7 +227,7 @@ public final class DHKeyFactory extends KeyFactorySpi {
}
} 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 {
BigInteger pMinus2 = p.subtract(BigInteger.valueOf(2));
//
// Handbook of Applied Cryptography: Menezes, et.al.
// Repeat if the following does not hold:
// 1 <= x <= p-2
// PKCS#3 section 7.1 "Private-value generation"
// Repeat if either of the followings does not hold:
// 0 < x < p-1
// 2^(lSize-1) <= x < 2^(lSize)
//
do {
// generate random x up to 2^lSize bits long
x = new BigInteger(lSize, random);
} while ((x.compareTo(BigInteger.ONE) < 0) ||
((x.compareTo(pMinus2) > 0)));
((x.compareTo(pMinus2) > 0)) || (x.bitLength() != lSize));
// calculate public value y
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -26,6 +26,7 @@
package com.sun.crypto.provider;
import java.io.*;
import java.util.Objects;
import java.math.BigInteger;
import java.security.KeyRep;
import java.security.PrivateKey;
......@@ -67,7 +68,7 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
// the base generator
private BigInteger g;
// the private-value length
// the private-value length (optional)
private int l;
private int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 };
......@@ -179,20 +180,9 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
this.key = val.data.getOctetString();
parseKeyBits();
// ignore OPTIONAL attributes
this.encodedKey = encodedKey.clone();
} catch (NumberFormatException 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;
} catch (IOException | NumberFormatException e) {
throw new InvalidKeyException("Error parsing key encoding", e);
}
}
......@@ -234,8 +224,9 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
DerOutputStream params = new DerOutputStream();
params.putInteger(this.p);
params.putInteger(this.g);
if (this.l != 0)
if (this.l != 0) {
params.putInteger(this.l);
}
// wrap parameters into SEQUENCE
DerValue paramSequence = new DerValue(DerValue.tag_Sequence,
params.toByteArray());
......@@ -273,10 +264,11 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
* @return the key parameters
*/
public DHParameterSpec getParams() {
if (this.l != 0)
if (this.l != 0) {
return new DHParameterSpec(this.p, this.g, this.l);
else
} else {
return new DHParameterSpec(this.p, this.g);
}
}
public String toString() {
......@@ -312,26 +304,21 @@ javax.crypto.interfaces.DHPrivateKey, Serializable {
* Objects that are equal will also have the same hashcode.
*/
public int hashCode() {
int retval = 0;
byte[] enc = getEncoded();
for (int i = 1; i < enc.length; i++) {
retval += enc[i] * i;
}
return(retval);
return Objects.hash(x, p, g);
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (this == obj) return true;
if (!(obj instanceof PrivateKey))
if (!(obj instanceof javax.crypto.interfaces.DHPrivateKey)) {
return false;
byte[] thisEncoded = this.getEncoded();
byte[] thatEncoded = ((PrivateKey)obj).getEncoded();
return java.util.Arrays.equals(thisEncoded, thatEncoded);
}
javax.crypto.interfaces.DHPrivateKey other =
(javax.crypto.interfaces.DHPrivateKey) obj;
DHParameterSpec otherParams = other.getParams();
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -26,6 +26,7 @@
package com.sun.crypto.provider;
import java.io.*;
import java.util.Objects;
import java.math.BigInteger;
import java.security.KeyRep;
import java.security.InvalidKeyException;
......@@ -64,7 +65,7 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
// the base generator
private BigInteger g;
// the private-value length
// the private-value length (optional)
private int l;
private int DH_data[] = { 1, 2, 840, 113549, 1, 3, 1 };
......@@ -173,13 +174,8 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
}
this.encodedKey = encodedKey.clone();
} catch (NumberFormatException e) {
throw new InvalidKeyException("Private-value length too big");
} catch (IOException e) {
throw new InvalidKeyException(
"Error parsing key encoding: " + e.toString());
} catch (IOException | NumberFormatException e) {
throw new InvalidKeyException("Error parsing key encoding", e);
}
}
......@@ -212,8 +208,9 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
DerOutputStream params = new DerOutputStream();
params.putInteger(this.p);
params.putInteger(this.g);
if (this.l != 0)
if (this.l != 0) {
params.putInteger(this.l);
}
// wrap parameters into SEQUENCE
DerValue paramSequence = new DerValue(DerValue.tag_Sequence,
params.toByteArray());
......@@ -253,10 +250,11 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
* @return the key parameters
*/
public DHParameterSpec getParams() {
if (this.l != 0)
if (this.l != 0) {
return new DHParameterSpec(this.p, this.g, this.l);
else
} else {
return new DHParameterSpec(this.p, this.g);
}
}
public String toString() {
......@@ -290,26 +288,22 @@ javax.crypto.interfaces.DHPublicKey, Serializable {
* Objects that are equal will also have the same hashcode.
*/
public int hashCode() {
int retval = 0;
byte[] enc = getEncoded();
for (int i = 1; i < enc.length; i++) {
retval += enc[i] * i;
}
return(retval);
return Objects.hash(y, p, g);
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (this == obj) return true;
if (!(obj instanceof PublicKey))
if (!(obj instanceof javax.crypto.interfaces.DHPublicKey)) {
return false;
}
byte[] thisEncoded = this.getEncoded();
byte[] thatEncoded = ((PublicKey)obj).getEncoded();
return java.util.Arrays.equals(thisEncoded, thatEncoded);
javax.crypto.interfaces.DHPublicKey other =
(javax.crypto.interfaces.DHPublicKey) obj;
DHParameterSpec otherParams = other.getParams();
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 {
} else {
try {
(new NativeUnpack(this)).run(in0, out);
} catch (UnsatisfiedLinkError ule) {
} catch (UnsatisfiedLinkError | NoClassDefFoundError ex) {
// failover to java implementation
(new DoUnpack()).run(in0, out);
}
......
......@@ -52,6 +52,7 @@ import javax.management.NotCompliantMBeanException;
import com.sun.jmx.remote.util.EnvHelp;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import javax.management.AttributeNotFoundException;
import javax.management.openmbean.CompositeData;
import sun.reflect.misc.MethodUtil;
......@@ -64,7 +65,11 @@ import sun.reflect.misc.ReflectUtil;
* @since 1.5
*/
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 {
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)
throws NotCompliantMBeanException {
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)
throws NotCompliantMBeanException{
StandardMBeanIntrospector.getInstance().getAnalyzer(interfaceClass);
......@@ -299,18 +320,18 @@ public class Introspector {
* not a JMX compliant Standard MBean.
*/
public static <T> Class<? super T> getStandardMBeanInterface(Class<T> baseClass)
throws NotCompliantMBeanException {
Class<? super T> current = baseClass;
Class<? super T> mbeanInterface = null;
while (current != null) {
mbeanInterface =
findMBeanInterface(current, current.getName());
if (mbeanInterface != null) break;
current = current.getSuperclass();
}
if (mbeanInterface != null) {
return mbeanInterface;
} else {
throws NotCompliantMBeanException {
Class<? super T> current = baseClass;
Class<? super T> mbeanInterface = null;
while (current != null) {
mbeanInterface =
findMBeanInterface(current, current.getName());
if (mbeanInterface != null) break;
current = current.getSuperclass();
}
if (mbeanInterface != null) {
return mbeanInterface;
} else {
final String msg =
"Class " + baseClass.getName() +
" is not a JMX compliant Standard MBean";
......@@ -507,8 +528,11 @@ public class Introspector {
}
Class<?>[] interfaces = c.getInterfaces();
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 null;
......
......@@ -28,6 +28,8 @@ package com.sun.jmx.mbeanserver;
import static com.sun.jmx.mbeanserver.Util.*;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
......@@ -50,7 +52,6 @@ import javax.management.NotCompliantMBeanException;
* @since 1.6
*/
class MBeanAnalyzer<M> {
static interface MBeanVisitor<M> {
public void visitAttribute(String attributeName,
M getter,
......@@ -107,6 +108,10 @@ class MBeanAnalyzer<M> {
if (!mbeanType.isInterface()) {
throw new NotCompliantMBeanException("Not an interface: " +
mbeanType.getName());
} else if (!Modifier.isPublic(mbeanType.getModifiers()) &&
!Introspector.ALLOW_NONPUBLIC_MBEAN) {
throw new NotCompliantMBeanException("Interface is not public: " +
mbeanType.getName());
}
try {
......
......@@ -2,82 +2,78 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
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.SignatureElementProxy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* The Algorithm class which stores the Algorithm URI as a string.
*
*/
public abstract class Algorithm extends SignatureElementProxy {
/**
*
* @param doc
* @param algorithmURI is the URI of the algorithm as String
*/
public Algorithm(Document doc, String algorithmURI) {
super(doc);
this.setAlgorithmURI(algorithmURI);
}
/**
*
* @param doc
* @param algorithmURI is the URI of the algorithm as String
*/
public Algorithm(Document doc, String algorithmURI) {
super(doc);
/**
* Constructor Algorithm
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public Algorithm(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
this.setAlgorithmURI(algorithmURI);
}
/**
* Method getAlgorithmURI
*
* @return The URI of the alogrithm
*/
public String getAlgorithmURI() {
return this._constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
/**
* Constructor Algorithm
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public Algorithm(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Sets the algorithm's URI as used in the signature.
*
* @param algorithmURI is the URI of the algorithm as String
*/
protected void setAlgorithmURI(String algorithmURI) {
/**
* Method getAlgorithmURI
*
* @return The URI of the algorithm
*/
public String getAlgorithmURI() {
return this.constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
if ( (algorithmURI != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM,
algorithmURI);
}
}
/**
* Sets the algorithm's URI as used in the signature.
*
* @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 {
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1,
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(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5,
new Algorithm("", "HmacMD5", "Mac")
......@@ -154,6 +166,18 @@ public class JCEMapper {
XMLCipher.AES_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(
XMLCipher.RSA_v1dot5,
new Algorithm("RSA", "RSA/ECB/PKCS1Padding", "KeyTransport")
......@@ -162,6 +186,10 @@ public class JCEMapper {
XMLCipher.RSA_OAEP,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
);
algorithmsMap.put(
XMLCipher.RSA_OAEP_11,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
);
algorithmsMap.put(
XMLCipher.DIFFIE_HELLMAN,
new Algorithm("", "", "KeyAgreement")
......
......@@ -2,265 +2,254 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
import java.security.MessageDigest;
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.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants;
import org.w3c.dom.Document;
/**
* Digest Message wrapper & selector class.
*
* <pre>
* MessageDigestAlgorithm.getInstance()
* </pre>
*
*/
public class MessageDigestAlgorithm extends Algorithm {
/** Message Digest - NOT RECOMMENDED MD5*/
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 = Constants.MoreAlgorithmsSpecNS + "md5";
/** Digest - Required SHA1*/
public static final String ALGO_ID_DIGEST_SHA1 = Constants.SignatureSpecNS + "sha1";
/** Message Digest - RECOMMENDED SHA256*/
public static final String ALGO_ID_DIGEST_SHA256 = EncryptionConstants.EncryptionSpecNS + "sha256";
/** Message Digest - OPTIONAL SHA384*/
public static final String ALGO_ID_DIGEST_SHA384 = Constants.MoreAlgorithmsSpecNS + "sha384";
/** Message Digest - OPTIONAL SHA512*/
public static final String ALGO_ID_DIGEST_SHA512 = EncryptionConstants.EncryptionSpecNS + "sha512";
/** Message Digest - OPTIONAL RIPEMD-160*/
public static final String ALGO_ID_DIGEST_RIPEMD160 = EncryptionConstants.EncryptionSpecNS + "ripemd160";
/** Field algorithm stores the actual {@link java.security.MessageDigest} */
java.security.MessageDigest algorithm = null;
/**
* Constructor for the brave who pass their own message digest algorithms and the corresponding URI.
* @param doc
* @param messageDigest
* @param algorithmURI
*/
private MessageDigestAlgorithm(Document doc, MessageDigest messageDigest,
String algorithmURI) {
super(doc, algorithmURI);
this.algorithm = messageDigest;
}
static ThreadLocal<Map<String, MessageDigest>> instances=new
ThreadLocal<Map<String, MessageDigest>>() {
protected Map<String, MessageDigest> initialValue() {
return new HashMap<String, MessageDigest>();
};
};
/**
* Factory method for constructing a message digest algorithm by name.
*
* @param doc
* @param algorithmURI
* @return The MessageDigestAlgorithm element to attach in document and to digest
* @throws XMLSignatureException
*/
public static MessageDigestAlgorithm getInstance(
Document doc, String algorithmURI) throws XMLSignatureException {
MessageDigest md = getDigestInstance(algorithmURI);
return new MessageDigestAlgorithm(doc, md, algorithmURI);
}
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
MessageDigest result= instances.get().get(algorithmURI);
if (result!=null)
return result;
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
if (algorithmID == null) {
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
}
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 =
Constants.MoreAlgorithmsSpecNS + "md5";
/** Digest - Required SHA1*/
public static final String ALGO_ID_DIGEST_SHA1 = Constants.SignatureSpecNS + "sha1";
/** Message Digest - RECOMMENDED SHA256*/
public static final String ALGO_ID_DIGEST_SHA256 =
EncryptionConstants.EncryptionSpecNS + "sha256";
/** Message Digest - OPTIONAL SHA384*/
public static final String ALGO_ID_DIGEST_SHA384 =
Constants.MoreAlgorithmsSpecNS + "sha384";
/** Message Digest - OPTIONAL SHA512*/
public static final String ALGO_ID_DIGEST_SHA512 =
EncryptionConstants.EncryptionSpecNS + "sha512";
/** Message Digest - OPTIONAL RIPEMD-160*/
public static final String ALGO_ID_DIGEST_RIPEMD160 =
EncryptionConstants.EncryptionSpecNS + "ripemd160";
/** Field algorithm stores the actual {@link java.security.MessageDigest} */
private final MessageDigest algorithm;
/**
* Constructor for the brave who pass their own message digest algorithms and the
* corresponding URI.
* @param doc
* @param algorithmURI
*/
private MessageDigestAlgorithm(Document doc, String algorithmURI)
throws XMLSignatureException {
super(doc, algorithmURI);
algorithm = getDigestInstance(algorithmURI);
}
/**
* Factory method for constructing a message digest algorithm by name.
*
* @param doc
* @param algorithmURI
* @return The MessageDigestAlgorithm element to attach in document and to digest
* @throws XMLSignatureException
*/
public static MessageDigestAlgorithm getInstance(
Document doc, String algorithmURI
) throws XMLSignatureException {
return new MessageDigestAlgorithm(doc, algorithmURI);
}
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
if (algorithmID == null) {
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
}
MessageDigest md;
String provider=JCEMapper.getProviderId();
try {
if (provider==null) {
MessageDigest md;
String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
md = MessageDigest.getInstance(algorithmID);
} else {
md = MessageDigest.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
} else {
md = MessageDigest.getInstance(algorithmID, provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID, 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();
}
/**
* 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 this.algorithm.getDigestLength();
}
/**
* Proxy method for {@link java.security.MessageDigest#reset}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
*/
public void reset() {
this.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) {
this.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) {
this.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) {
this.algorithm.update(buf, offset, len);
}
/** @inheritDoc */
public String getBaseNamespace() {
return Constants.SignatureSpecNS;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DIGESTMETHOD;
}
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 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 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 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 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 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 {
this.algorithmURI = algorithmURI;
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
}
/**
......@@ -92,10 +92,10 @@ public class SignatureAlgorithm extends Algorithm {
this.algorithmURI = algorithmURI;
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
signatureAlgorithm.engineSetHMACOutputLength(hmacOutputLength);
((IntegrityHmac)signatureAlgorithm).engineAddContextToElement(_constructionElement);
((IntegrityHmac)signatureAlgorithm).engineAddContextToElement(constructionElement);
}
/**
......@@ -136,7 +136,7 @@ public class SignatureAlgorithm extends Algorithm {
}
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
}
/**
......@@ -310,7 +310,7 @@ public class SignatureAlgorithm extends Algorithm {
* @return the URI representation of Transformation algorithm
*/
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 {
* This method registers the default algorithms.
*/
public static void registerDefaultAlgorithms() {
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_DSA, SignatureDSA.class
);
algorithmHash.put(SignatureDSA.URI, SignatureDSA.class);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, SignatureBaseRSA.SignatureRSASHA1.class
);
......@@ -409,6 +407,15 @@ public class SignatureAlgorithm extends Algorithm {
algorithmHash.put(
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(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5, IntegrityHmac.IntegrityHmacMD5.class
);
......
......@@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
......@@ -27,157 +29,149 @@ import java.security.spec.AlgorithmParameterSpec;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureAlgorithmSpi {
/**
* Returns the URI representation of <code>Transformation algorithm</code>
*
* @return the URI representation of <code>Transformation algorithm</code>
*/
protected abstract String engineGetURI();
/**
* Proxy method for {@link java.security.Signature#getAlgorithm}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#getAlgorithm} method
*/
protected abstract String engineGetJCEAlgorithmString();
/**
* Method engineGetJCEProviderName
*
* @return the JCE ProviderName
*/
protected abstract String engineGetJCEProviderName();
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param input
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte[] input)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param 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.
*
* @param buf
* @param offset
* @param 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.
*
* @param signingKey
* @throws XMLSignatureException if this method is called on a MAC
*/
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.
*
* @param signingKey
* @param secureRandom
* @throws XMLSignatureException if this method is called on a MAC
*/
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.
*
* @param signingKey
* @param algorithmParameterSpec
* @throws XMLSignatureException if this method is called on a Signature
*/
protected abstract void engineInitSign(
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.
*
* @return the result of the {@link java.security.Signature#sign()} method
* @throws XMLSignatureException
*/
protected abstract byte[] engineSign() throws XMLSignatureException;
/**
* Method engineInitVerify
*
* @param 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.
*
* @param signature
* @return true if the signature is correct
* @throws XMLSignatureException
*/
protected abstract boolean engineVerify(byte[] signature)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param params
* @throws XMLSignatureException
*/
protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException;
/**
* Method engineGetContextFromElement
*
* @param element
*/
protected void engineGetContextFromElement(Element element) {
}
/**
* Method engineSetHMACOutputLength
*
* @param HMACOutputLength
* @throws XMLSignatureException
*/
protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException;
/**
* Returns the URI representation of <code>Transformation algorithm</code>
*
* @return the URI representation of <code>Transformation algorithm</code>
*/
protected abstract String engineGetURI();
/**
* Proxy method for {@link java.security.Signature#getAlgorithm}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#getAlgorithm} method
*/
protected abstract String engineGetJCEAlgorithmString();
/**
* Method engineGetJCEProviderName
*
* @return the JCE ProviderName
*/
protected abstract String engineGetJCEProviderName();
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param input
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte[] input) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param 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.
*
* @param buf
* @param offset
* @param 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.
*
* @param signingKey
* @throws XMLSignatureException if this method is called on a MAC
*/
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.
*
* @param signingKey
* @param secureRandom
* @throws XMLSignatureException if this method is called on a MAC
*/
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.
*
* @param signingKey
* @param algorithmParameterSpec
* @throws XMLSignatureException if this method is called on a Signature
*/
protected abstract void engineInitSign(
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.
*
* @return the result of the {@link java.security.Signature#sign()} method
* @throws XMLSignatureException
*/
protected abstract byte[] engineSign() throws XMLSignatureException;
/**
* Method engineInitVerify
*
* @param 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.
*
* @param signature
* @return true if the signature is correct
* @throws XMLSignatureException
*/
protected abstract boolean engineVerify(byte[] signature) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#setParameter(
* java.security.spec.AlgorithmParameterSpec)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param params
* @throws XMLSignatureException
*/
protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException;
/**
* Method engineGetContextFromElement
*
* @param element
*/
protected void engineGetContextFromElement(Element element) {
}
/**
* Method engineSetHMACOutputLength
*
* @param HMACOutputLength
* @throws XMLSignatureException
*/
protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException;
public void reset() {
}
}
}
......@@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2007 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
......@@ -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.XMLSignatureException;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger
(SignatureBaseRSA.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureBaseRSA.class.getName());
/** @inheritDoc */
public abstract String engineGetURI();
/** Field algorithm */
private java.security.Signature _signatureAlgorithm = null;
private java.security.Signature signatureAlgorithm = null;
/**
* Constructor SignatureRSA
......@@ -59,17 +56,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException
*/
public SignatureBaseRSA() throws XMLSignatureException {
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);
String provider=JCEMapper.getProviderId();
}
String provider = JCEMapper.getProviderId();
try {
if (provider==null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
if (provider == null) {
this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
this.signatureAlgorithm = Signature.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
......@@ -85,20 +82,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
try {
this._signatureAlgorithm.setParameter(params);
this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
try {
return this._signatureAlgorithm.verify(signature);
return this.signatureAlgorithm.verify(signature);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -106,32 +100,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey);
this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
Signature sig = this.signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
......@@ -140,7 +131,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException {
try {
return this._signatureAlgorithm.sign();
return this.signatureAlgorithm.sign();
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -149,19 +140,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign
((PrivateKey) privateKey, secureRandom);
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -169,18 +157,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey);
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -189,7 +175,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -198,17 +184,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException {
protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(buf, offset, len);
this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -216,34 +201,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm();
return this.signatureAlgorithm.getAlgorithm();
}
/** @inheritDoc */
protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName();
return this.signatureAlgorithm.getProvider().getName();
}
/** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException
("algorithms.HMACOutputLengthOnlyForHMAC");
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/** @inheritDoc */
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.CannotUseAlgorithmParameterSpecOnRSA");
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnRSA");
}
/**
* Class SignatureRSASHA1
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA1 extends SignatureBaseRSA {
......@@ -264,9 +244,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSASHA256
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA256 extends SignatureBaseRSA {
......@@ -287,9 +264,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSASHA384
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA384 extends SignatureBaseRSA {
......@@ -310,9 +284,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSASHA512
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA512 extends SignatureBaseRSA {
......@@ -333,9 +304,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSARIPEMD160
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
......@@ -356,9 +324,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSAMD5
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSAMD5 extends SignatureBaseRSA {
......
......@@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
......@@ -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.Constants;
/**
*
* @author $Author: mullan $
*/
public class SignatureDSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureDSA.class.getName());
/** Field _URI */
public static final String _URI = Constants.SignatureSpecNS + "dsa-sha1";
/** Field URI */
public static final String URI = Constants.SignatureSpecNS + "dsa-sha1";
/** Field algorithm */
private java.security.Signature _signatureAlgorithm = null;
private java.security.Signature signatureAlgorithm = null;
/**
* Method engineGetURI
......@@ -59,7 +57,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected String engineGetURI() {
return SignatureDSA._URI;
return SignatureDSA.URI;
}
/**
......@@ -68,17 +66,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException
*/
public SignatureDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI);
if (log.isLoggable(java.util.logging.Level.FINE))
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA.URI);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
}
String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm =
this.signatureAlgorithm =
Signature.getInstance(algorithmID, provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
......@@ -95,9 +93,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
try {
this._signatureAlgorithm.setParameter(params);
this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -107,15 +104,15 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
throws XMLSignatureException {
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));
}
byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
return this._signatureAlgorithm.verify(jcebytes);
return this.signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
......@@ -127,32 +124,29 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey);
this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
Signature sig = this.signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
......@@ -162,9 +156,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected byte[] engineSign() throws XMLSignatureException {
try {
byte jcebytes[] = this._signatureAlgorithm.sign();
byte jcebytes[] = this.signatureAlgorithm.sign();
return SignatureDSA.convertASN1toXMLDSIG(jcebytes);
} catch (IOException ex) {
......@@ -178,20 +171,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey,
secureRandom);
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -201,18 +191,16 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey);
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -223,7 +211,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -234,7 +222,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -243,10 +231,9 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
/**
* @inheritDoc
*/
protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException {
protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(buf, offset, len);
this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
......@@ -258,7 +245,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm();
return this.signatureAlgorithm.getAlgorithm();
}
/**
......@@ -267,7 +254,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName();
return this.signatureAlgorithm.getProvider().getName();
}
/**
......@@ -282,8 +269,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
throws IOException {
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
byte rLength = asn1Bytes[3];
int i;
......@@ -294,19 +280,18 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
int j;
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)
|| (asn1Bytes[2] != 2) || (i > 20)
|| (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
|| (asn1Bytes[2] != 2) || (i > 20)
|| (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
throw new IOException("Invalid ASN.1 format of DSA signature");
}
byte xmldsigBytes[] = new byte[40];
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i,
i);
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, i);
System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
40 - j, j);
40 - j, j);
return xmldsigBytes;
}
......@@ -323,8 +308,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
throws IOException {
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
if (xmldsigBytes.length != 40) {
throw new IOException("Invalid XMLDSIG format of DSA signature");
......@@ -337,7 +321,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
int j = i;
if (xmldsigBytes[20 - i] < 0) {
j += 1;
j += 1;
}
int k;
......@@ -373,10 +357,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @param HMACOutputLength
* @throws XMLSignatureException
*/
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.HMACOutputLengthOnlyForHMAC");
protected void engineSetHMACOutputLength(int HMACOutputLength) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/**
......@@ -387,9 +369,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException
*/
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.CannotUseAlgorithmParameterSpecOnDSA");
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnDSA");
}
}
......@@ -2,29 +2,28 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
* Class CanonicalizationException
*
......@@ -32,57 +31,58 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
*/
public class CanonicalizationException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor CanonicalizationException
*
*/
public CanonicalizationException() {
super();
}
/**
* Constructor CanonicalizationException
*
*/
public CanonicalizationException() {
super();
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
*/
public CanonicalizationException(String _msgID) {
super(_msgID);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
*/
public CanonicalizationException(String msgID) {
super(msgID);
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
* @param exArgs
*/
public CanonicalizationException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
* @param exArgs
*/
public CanonicalizationException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
* @param _originalException
*/
public CanonicalizationException(String _msgID, Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
* @param originalException
*/
public CanonicalizationException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public CanonicalizationException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public CanonicalizationException(
String msgID, Object exArgs[], Exception originalException
) {
super(msgID, exArgs, originalException);
}
}
......@@ -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.Canonicalizer20010315OmitComments;
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 org.w3c.dom.Document;
import org.w3c.dom.Node;
......@@ -91,6 +92,11 @@ public class Canonicalizer {
*/
public static final String ALGO_ID_C14N11_WITH_COMMENTS =
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 =
new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
......@@ -202,6 +208,10 @@ public class Canonicalizer {
Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
Canonicalizer11_WithComments.class
);
canonicalizerHash.put(
Canonicalizer.ALGO_ID_C14N_PHYSICAL,
CanonicalizerPhysical.class
);
}
/**
......
......@@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
......@@ -43,10 +45,10 @@ import java.util.Comparator;
*/
public class AttrCompare implements Comparator<Attr>, Serializable {
private final static long serialVersionUID = -7113259629930576230L;
private final static int ATTR0_BEFORE_ATTR1 = -1;
private final static int ATTR1_BEFORE_ATTR0 = 1;
private final static String XMLNS=Constants.NamespaceSpecNS;
private static final long serialVersionUID = -7113259629930576230L;
private static final int ATTR0_BEFORE_ATTR1 = -1;
private static final int ATTR1_BEFORE_ATTR0 = 1;
private static final String XMLNS = Constants.NamespaceSpecNS;
/**
* Compares two attributes based on the C14n specification.
......@@ -69,12 +71,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
*
*/
public int compare(Attr attr0, Attr attr1) {
String namespaceURI0 = attr0.getNamespaceURI();
String namespaceURI1 = attr1.getNamespaceURI();
boolean isNamespaceAttr0 = XMLNS==namespaceURI0;
boolean isNamespaceAttr1 = XMLNS==namespaceURI1;
boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);
if (isNamespaceAttr0) {
if (isNamespaceAttr1) {
......@@ -82,11 +83,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
String localname0 = attr0.getLocalName();
String localname1 = attr1.getLocalName();
if (localname0.equals("xmlns")) {
if ("xmlns".equals(localname0)) {
localname0 = "";
}
if (localname1.equals("xmlns")) {
if ("xmlns".equals(localname1)) {
localname1 = "";
}
......@@ -94,9 +95,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
}
// attr0 is a namespace, attr1 is not
return ATTR0_BEFORE_ATTR1;
}
if (isNamespaceAttr1) {
} else if (isNamespaceAttr1) {
// attr1 is a namespace, attr0 is not
return ATTR1_BEFORE_ATTR0;
}
......@@ -109,9 +108,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
return name0.compareTo(name1);
}
return ATTR0_BEFORE_ATTR1;
}
if (namespaceURI1 == null) {
} else if (namespaceURI1 == null) {
return ATTR1_BEFORE_ATTR0;
}
......
......@@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2008 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* 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.
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册