Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
26bc4f44
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
26bc4f44
编写于
3月 06, 2009
作者:
T
tbell
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
ec53ca8f
e8cf47d0
变更
39
展开全部
隐藏空白更改
内联
并排
Showing
39 changed file
with
1945 addition
and
951 deletion
+1945
-951
make/common/shared/Defs-java.gmk
make/common/shared/Defs-java.gmk
+5
-0
make/docs/Makefile
make/docs/Makefile
+1
-0
make/javax/swing/beaninfo/SwingBeans.gmk
make/javax/swing/beaninfo/SwingBeans.gmk
+1
-1
src/share/classes/com/sun/servicetag/resources/register.html
src/share/classes/com/sun/servicetag/resources/register.html
+1
-1
src/share/classes/com/sun/servicetag/resources/register_ja.html
...are/classes/com/sun/servicetag/resources/register_ja.html
+1
-1
src/share/classes/com/sun/servicetag/resources/register_zh_CN.html
.../classes/com/sun/servicetag/resources/register_zh_CN.html
+1
-1
src/share/classes/java/lang/Class.java
src/share/classes/java/lang/Class.java
+2
-4
src/share/classes/java/lang/reflect/Constructor.java
src/share/classes/java/lang/reflect/Constructor.java
+1
-3
src/share/classes/java/lang/reflect/Field.java
src/share/classes/java/lang/reflect/Field.java
+1
-3
src/share/classes/java/lang/reflect/Method.java
src/share/classes/java/lang/reflect/Method.java
+1
-3
src/share/classes/java/net/SocketPermission.java
src/share/classes/java/net/SocketPermission.java
+0
-1
src/share/classes/java/security/Permission.java
src/share/classes/java/security/Permission.java
+6
-6
src/share/classes/java/util/ArrayList.java
src/share/classes/java/util/ArrayList.java
+0
-1
src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
...util/concurrent/locks/AbstractQueuedLongSynchronizer.java
+4
-2
src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
...ava/util/concurrent/locks/AbstractQueuedSynchronizer.java
+4
-2
src/share/classes/sun/launcher/LauncherHelper.java
src/share/classes/sun/launcher/LauncherHelper.java
+10
-5
src/share/classes/sun/misc/ClassLoaderUtil.java
src/share/classes/sun/misc/ClassLoaderUtil.java
+0
-2
src/share/classes/sun/misc/FloatingDecimal.java
src/share/classes/sun/misc/FloatingDecimal.java
+8
-2
src/share/classes/sun/reflect/annotation/AnnotationParser.java
...hare/classes/sun/reflect/annotation/AnnotationParser.java
+12
-0
src/share/classes/sun/security/pkcs11/P11Key.java
src/share/classes/sun/security/pkcs11/P11Key.java
+68
-24
src/share/classes/sun/security/pkcs11/P11RSACipher.java
src/share/classes/sun/security/pkcs11/P11RSACipher.java
+6
-3
src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java
...hare/classes/sun/security/pkcs11/P11SecretKeyFactory.java
+1
-1
src/share/classes/sun/security/provider/SeedGenerator.java
src/share/classes/sun/security/provider/SeedGenerator.java
+25
-5
src/share/classes/sun/security/tools/KeyTool.java
src/share/classes/sun/security/tools/KeyTool.java
+6
-2
src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
+598
-293
src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c
src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c
+63
-1
src/share/native/sun/security/pkcs11/wrapper/p11_digest.c
src/share/native/sun/security/pkcs11/wrapper/p11_digest.c
+37
-25
src/share/native/sun/security/pkcs11/wrapper/p11_dual.c
src/share/native/sun/security/pkcs11/wrapper/p11_dual.c
+61
-28
src/share/native/sun/security/pkcs11/wrapper/p11_general.c
src/share/native/sun/security/pkcs11/wrapper/p11_general.c
+79
-47
src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c
src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c
+152
-111
src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c
src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c
+53
-26
src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c
src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c
+45
-45
src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c
src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c
+50
-21
src/share/native/sun/security/pkcs11/wrapper/p11_sign.c
src/share/native/sun/security/pkcs11/wrapper/p11_sign.c
+114
-44
src/share/native/sun/security/pkcs11/wrapper/p11_util.c
src/share/native/sun/security/pkcs11/wrapper/p11_util.c
+320
-233
src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
+19
-4
test/java/security/Permission/ToString.java
test/java/security/Permission/ToString.java
+101
-0
test/java/util/zip/ZipFile/LargeZipFile.java
test/java/util/zip/ZipFile/LargeZipFile.java
+23
-0
test/sun/security/tools/keytool/NoExtNPE.sh
test/sun/security/tools/keytool/NoExtNPE.sh
+65
-0
未找到文件。
make/common/shared/Defs-java.gmk
浏览文件 @
26bc4f44
...
...
@@ -129,6 +129,9 @@ JAVACFLAGS += $(OTHER_JAVACFLAGS)
# Needed for javah
JAVAHFLAGS += -bootclasspath $(CLASSBINDIR)
# Needed for JAVADOC and BOOT_JAVACFLAGS
NO_PROPRIETARY_API_WARNINGS = -XDignore.symbol.file=true
# Langtools
ifdef LANGTOOLS_DIST
JAVAC_JAR = $(LANGTOOLS_DIST)/bootstrap/lib/javac.jar
...
...
@@ -192,6 +195,8 @@ endif
BOOT_JAVACFLAGS += -encoding ascii
BOOT_JAR_JFLAGS += $(JAR_JFLAGS)
BOOT_JAVACFLAGS += $(NO_PROPRIETARY_API_WARNINGS)
BOOT_JAVA_CMD = $(BOOTDIR)/bin/java $(JAVA_TOOLS_FLAGS)
BOOT_JAVAC_CMD = $(BOOTDIR)/bin/javac $(JAVAC_JVM_FLAGS) $(BOOT_JAVACFLAGS)
BOOT_JAR_CMD = $(BOOTDIR)/bin/jar
...
...
make/docs/Makefile
浏览文件 @
26bc4f44
...
...
@@ -45,6 +45,7 @@ endif
DOCSTMPDIR
=
$(TEMPDIR)
/doctmp
COMMON_JAVADOCFLAGS
=
\
$(NO_PROPRIETARY_API_WARNINGS)
\
-source
1.5
\
-quiet
\
-use
\
...
...
make/javax/swing/beaninfo/SwingBeans.gmk
浏览文件 @
26bc4f44
...
...
@@ -47,7 +47,7 @@ swing-1.2-beans-debug:
LOCAL_JAVADOC = $(JAVADOC_CMD) $(JAVADOCFLAGS)
# get the absolute path to the jar command.
PREFIX = 1.2
JAVADOCFLAGS = $(LANGUAGE_VERSION)
JAVADOCFLAGS = $(
NO_PROPRIETARY_API_WARNINGS) $(
LANGUAGE_VERSION)
SWINGPKG = javax/swing
LOCAL_JAVAC_FLAGS = $(OTHER_JAVACFLAGS)
...
...
src/share/classes/com/sun/servicetag/resources/register.html
浏览文件 @
26bc4f44
...
...
@@ -68,7 +68,7 @@ a:visited,a:visited code{color:#917E9C}
<table
width=
"708"
border=
"0"
cellspacing=
"0"
cellpadding=
"3"
>
<tr
valign=
"top"
>
<td
width=
"126"
height=
"35"
>
<form
name=
"form1"
method=
"post"
action=
"@@REGISTRATION_URL@@"
enctype=
"text/xml"
>
<form
name=
"form1"
method=
"post"
action=
"@@REGISTRATION_URL@@"
>
<input
type=
"hidden"
name=
"servicetag_payload"
value=
"@@REGISTRATION_PAYLOAD@@"
>
<input
type=
"submit"
name=
"Submit"
border=
"0"
class=
"buttonblue"
onmouseover=
"this.style.color='#fbe249';"
onmouseout=
"this.style.color='#FFF';"
value=
"Register My JDK"
>
</form></td>
...
...
src/share/classes/com/sun/servicetag/resources/register_ja.html
浏览文件 @
26bc4f44
...
...
@@ -62,7 +62,7 @@ a:visited,a:visited code{color:#917E9C}
<p
class=
"style1"
>
必要になるのは、Sun 開発者向けネットワークアカウントまたはその他の Sun オンラインアカウントだけです。 まだアカウントがない場合は、アカウントの作成が求められます。
</p>
<table
width=
"708"
border=
"0"
cellspacing=
"0"
cellpadding=
"3"
>
<tr
valign=
"top"
>
<td
width=
"126"
height=
"35"
><form
name=
"form1"
method=
"post"
action=
"@@REGISTRATION_URL@@"
enctype=
"text/xml"
>
<td
width=
"126"
height=
"35"
><form
name=
"form1"
method=
"post"
action=
"@@REGISTRATION_URL@@"
>
<input
type=
"hidden"
name=
"servicetag_payload"
value=
"@@REGISTRATION_PAYLOAD@@"
>
<input
type=
"submit"
name=
"Submit"
border=
"0"
class=
"buttonblue"
onmouseover=
"this.style.color='#fbe249';"
onmouseout=
"this.style.color='#FFF';"
value=
"JDK 製品登録"
>
</form></td>
...
...
src/share/classes/com/sun/servicetag/resources/register_zh_CN.html
浏览文件 @
26bc4f44
...
...
@@ -63,7 +63,7 @@ a:visited,a:visited code{color:#917E9C}
<p
class=
"style1"
>
您需要具有 Sun 开发者网络或其他 Sun 联机帐户。如果您没有,系统将提示您创建一个。
</p>
<table
width=
"708"
border=
"0"
cellspacing=
"0"
cellpadding=
"3"
>
<tr
valign=
"top"
>
<td
width=
"126"
height=
"35"
><form
name=
"form1"
method=
"post"
action=
"@@REGISTRATION_URL@@"
enctype=
"text/xml"
>
<td
width=
"126"
height=
"35"
><form
name=
"form1"
method=
"post"
action=
"@@REGISTRATION_URL@@"
>
<input
type=
"hidden"
name=
"servicetag_payload"
value=
"@@REGISTRATION_PAYLOAD@@"
>
<input
type=
"submit"
name=
"Submit"
border=
"0"
class=
"buttonblue"
onmouseover=
"this.style.color='#fbe249';"
onmouseout=
"this.style.color='#FFF';"
value=
"注册我的 JDK"
>
</form></td>
...
...
src/share/classes/java/lang/Class.java
浏览文件 @
26bc4f44
...
...
@@ -3059,14 +3059,12 @@ public final
}
private
static
Annotation
[]
EMPTY_ANNOTATIONS_ARRAY
=
new
Annotation
[
0
];
/**
* @since 1.5
*/
public
Annotation
[]
getAnnotations
()
{
initAnnotationsIfNecessary
();
return
annotations
.
values
().
toArray
(
EMPTY_ANNOTATIONS_ARRAY
);
return
AnnotationParser
.
toArray
(
annotations
);
}
/**
...
...
@@ -3074,7 +3072,7 @@ public final
*/
public
Annotation
[]
getDeclaredAnnotations
()
{
initAnnotationsIfNecessary
();
return
declaredAnnotations
.
values
().
toArray
(
EMPTY_ANNOTATIONS_ARRAY
);
return
AnnotationParser
.
toArray
(
declaredAnnotations
);
}
// Annotations cache
...
...
src/share/classes/java/lang/reflect/Constructor.java
浏览文件 @
26bc4f44
...
...
@@ -626,13 +626,11 @@ public final
return
(
T
)
declaredAnnotations
().
get
(
annotationClass
);
}
private
static
final
Annotation
[]
EMPTY_ANNOTATION_ARRAY
=
new
Annotation
[
0
];
/**
* @since 1.5
*/
public
Annotation
[]
getDeclaredAnnotations
()
{
return
declaredAnnotations
().
values
().
toArray
(
EMPTY_ANNOTATION_ARRAY
);
return
AnnotationParser
.
toArray
(
declaredAnnotations
()
);
}
private
transient
Map
<
Class
,
Annotation
>
declaredAnnotations
;
...
...
src/share/classes/java/lang/reflect/Field.java
浏览文件 @
26bc4f44
...
...
@@ -1018,13 +1018,11 @@ class Field extends AccessibleObject implements Member {
return
(
T
)
declaredAnnotations
().
get
(
annotationClass
);
}
private
static
final
Annotation
[]
EMPTY_ANNOTATION_ARRAY
=
new
Annotation
[
0
];
/**
* @since 1.5
*/
public
Annotation
[]
getDeclaredAnnotations
()
{
return
declaredAnnotations
().
values
().
toArray
(
EMPTY_ANNOTATION_ARRAY
);
return
AnnotationParser
.
toArray
(
declaredAnnotations
()
);
}
private
transient
Map
<
Class
,
Annotation
>
declaredAnnotations
;
...
...
src/share/classes/java/lang/reflect/Method.java
浏览文件 @
26bc4f44
...
...
@@ -705,13 +705,11 @@ public final
return
(
T
)
declaredAnnotations
().
get
(
annotationClass
);
}
private
static
final
Annotation
[]
EMPTY_ANNOTATION_ARRAY
=
new
Annotation
[
0
];
/**
* @since 1.5
*/
public
Annotation
[]
getDeclaredAnnotations
()
{
return
declaredAnnotations
().
values
().
toArray
(
EMPTY_ANNOTATION_ARRAY
);
return
AnnotationParser
.
toArray
(
declaredAnnotations
()
);
}
private
transient
Map
<
Class
,
Annotation
>
declaredAnnotations
;
...
...
src/share/classes/java/net/SocketPermission.java
浏览文件 @
26bc4f44
...
...
@@ -113,7 +113,6 @@ import sun.security.util.SecurityConstants;
* <p>Similarly, if the following permission:
*
* <pre>
* p1 = new SocketPermission("puffin.eng.sun.com:7777", "connect,accept");
* p2 = new SocketPermission("localhost:1024-", "accept,connect,listen");
* </pre>
*
...
...
src/share/classes/java/security/Permission.java
浏览文件 @
26bc4f44
/*
* Copyright 1997-200
3
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-200
9
Sun Microsystems, Inc. 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
...
...
@@ -214,18 +214,18 @@ public abstract class Permission implements Guard, java.io.Serializable {
/**
* Returns a string describing this Permission. The convention is to
* specify the class name, the permission name, and the actions in
* the following format: '("ClassName" "name" "actions")'.
* the following format: '("ClassName" "name" "actions")', or
* '("ClassName" "name")' if actions list is null or empty.
*
* @return information about this Permission.
*/
public
String
toString
()
{
String
actions
=
getActions
();
if
((
actions
==
null
)
||
(
actions
.
length
()
==
0
))
{
// OPTIONAL
return
"(
"
+
getClass
().
getName
()
+
" "
+
name
+
")"
;
return
"(
\""
+
getClass
().
getName
()
+
"\" \""
+
name
+
"\
")"
;
}
else
{
return
"(
"
+
getClass
().
getName
()
+
" "
+
name
+
" "
+
actions
+
")"
;
return
"(
\""
+
getClass
().
getName
()
+
"\" \""
+
name
+
"\" \""
+
actions
+
"\
")"
;
}
}
}
src/share/classes/java/util/ArrayList.java
浏览文件 @
26bc4f44
...
...
@@ -179,7 +179,6 @@ public class ArrayList<E> extends AbstractList<E>
modCount
++;
int
oldCapacity
=
elementData
.
length
;
if
(
minCapacity
>
oldCapacity
)
{
Object
oldData
[]
=
elementData
;
int
newCapacity
=
(
oldCapacity
*
3
)/
2
+
1
;
if
(
newCapacity
<
minCapacity
)
newCapacity
=
minCapacity
;
...
...
src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
浏览文件 @
26bc4f44
...
...
@@ -1222,8 +1222,10 @@ public abstract class AbstractQueuedLongSynchronizer
// The correctness of this depends on head being initialized
// before tail and on head.next being accurate if the current
// thread is first in queue.
Node
h
,
s
;
return
(
h
=
head
)
!=
tail
&&
Node
t
=
tail
;
// Read fields in reverse initialization order
Node
h
=
head
;
Node
s
;
return
h
!=
t
&&
((
s
=
h
.
next
)
==
null
||
s
.
thread
!=
Thread
.
currentThread
());
}
...
...
src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
浏览文件 @
26bc4f44
...
...
@@ -1445,8 +1445,10 @@ public abstract class AbstractQueuedSynchronizer
// The correctness of this depends on head being initialized
// before tail and on head.next being accurate if the current
// thread is first in queue.
Node
h
,
s
;
return
(
h
=
head
)
!=
tail
&&
Node
t
=
tail
;
// Read fields in reverse initialization order
Node
h
=
head
;
Node
s
;
return
h
!=
t
&&
((
s
=
h
.
next
)
==
null
||
s
.
thread
!=
Thread
.
currentThread
());
}
...
...
src/share/classes/sun/launcher/LauncherHelper.java
浏览文件 @
26bc4f44
/*
* Copyright 2007-200
8
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2007-200
9
Sun Microsystems, Inc. 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
...
...
@@ -55,18 +54,24 @@ public enum LauncherHelper {
INSTANCE
;
private
static
final
String
defaultBundleName
=
"sun.launcher.resources.launcher"
;
private
static
ResourceBundle
javarb
=
ResourceBundle
.
getBundle
(
defaultBundleName
);
private
static
final
String
MAIN_CLASS
=
"Main-Class"
;
private
static
StringBuilder
outBuf
=
new
StringBuilder
();
private
static
ResourceBundle
javarb
=
null
;
private
static
synchronized
ResourceBundle
getLauncherResourceBundle
()
{
if
(
javarb
==
null
)
{
javarb
=
ResourceBundle
.
getBundle
(
defaultBundleName
);
}
return
javarb
;
}
/**
* A private helper method to get a localized message and also
* apply any arguments that we might pass.
*/
private
static
String
getLocalizedMessage
(
String
key
,
Object
...
args
)
{
String
msg
=
javarb
.
getString
(
key
);
String
msg
=
getLauncherResourceBundle
()
.
getString
(
key
);
return
(
args
!=
null
)
?
MessageFormat
.
format
(
msg
,
args
)
:
msg
;
}
...
...
src/share/classes/sun/misc/ClassLoaderUtil.java
浏览文件 @
26bc4f44
...
...
@@ -77,8 +77,6 @@ public class ClassLoaderUtil {
jarsClosed
.
clear
();
}
System
.
out
.
println
(
"classLoader = "
+
classLoader
);
System
.
out
.
println
(
"SharedSecrets.getJavaNetAccess()="
+
SharedSecrets
.
getJavaNetAccess
());
URLClassPath
ucp
=
SharedSecrets
.
getJavaNetAccess
()
.
getURLClassPath
(
classLoader
);
ArrayList
loaders
=
ucp
.
loaders
;
...
...
src/share/classes/sun/misc/FloatingDecimal.java
浏览文件 @
26bc4f44
...
...
@@ -1867,10 +1867,16 @@ public class FloatingDecimal{
* Grammar is compatible with hexadecimal floating-point constants
* described in section 6.4.4.2 of the C99 specification.
*/
private
static
Pattern
hexFloatPattern
=
Pattern
.
compile
(
private
static
Pattern
hexFloatPattern
=
null
;
private
static
synchronized
Pattern
getHexFloatPattern
()
{
if
(
hexFloatPattern
==
null
)
{
hexFloatPattern
=
Pattern
.
compile
(
//1 234 56 7 8 9
"([-+])?0[xX](((\\p{XDigit}+)\\.?)|((\\p{XDigit}*)\\.(\\p{XDigit}+)))[pP]([-+])?(\\p{Digit}+)[fFdD]?"
);
}
return
hexFloatPattern
;
}
/*
* Convert string s to a suitable floating decimal; uses the
...
...
@@ -1880,7 +1886,7 @@ public class FloatingDecimal{
static
FloatingDecimal
parseHexString
(
String
s
)
{
// Verify string is a member of the hexadecimal floating-point
// string language.
Matcher
m
=
hexFloatPattern
.
matcher
(
s
);
Matcher
m
=
getHexFloatPattern
()
.
matcher
(
s
);
boolean
validInput
=
m
.
matches
();
if
(!
validInput
)
{
...
...
src/share/classes/sun/reflect/annotation/AnnotationParser.java
浏览文件 @
26bc4f44
...
...
@@ -788,4 +788,16 @@ public class AnnotationParser {
for
(
int
i
=
0
;
i
<
length
;
i
++)
skipMemberValue
(
buf
);
}
/*
* This method converts the annotation map returned by the parseAnnotations()
* method to an array. It is called by Field.getDeclaredAnnotations(),
* Method.getDeclaredAnnotations(), and Constructor.getDeclaredAnnotations().
* This avoids the reflection classes to load the Annotation class until
* it is needed.
*/
private
static
final
Annotation
[]
EMPTY_ANNOTATION_ARRAY
=
new
Annotation
[
0
];
public
static
Annotation
[]
toArray
(
Map
<
Class
,
Annotation
>
annotations
)
{
return
annotations
.
values
().
toArray
(
EMPTY_ANNOTATION_ARRAY
);
}
}
src/share/classes/sun/security/pkcs11/P11Key.java
浏览文件 @
26bc4f44
/*
* Copyright 2003-200
6
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-200
9
Sun Microsystems, Inc. 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
sun.security.pkcs11
;
import
java.io.*
;
import
java.lang.ref.*
;
import
java.math.BigInteger
;
import
java.util.*
;
...
...
@@ -67,9 +68,6 @@ abstract class P11Key implements Key {
// type of key, one of (PUBLIC, PRIVATE, SECRET)
final
String
type
;
// session in which the key was created, relevant for session objects
final
Session
session
;
// token instance
final
Token
token
;
...
...
@@ -85,10 +83,12 @@ abstract class P11Key implements Key {
// flags indicating whether the key is a token object, sensitive, extractable
final
boolean
tokenObject
,
sensitive
,
extractable
;
// weak reference notification clean up for session keys
private
final
SessionKeyRef
sessionKeyRef
;
P11Key
(
String
type
,
Session
session
,
long
keyID
,
String
algorithm
,
int
keyLength
,
CK_ATTRIBUTE
[]
attributes
)
{
this
.
type
=
type
;
this
.
session
=
session
;
this
.
token
=
session
.
token
;
this
.
keyID
=
keyID
;
this
.
algorithm
=
algorithm
;
...
...
@@ -111,7 +111,9 @@ abstract class P11Key implements Key {
this
.
sensitive
=
sensitive
;
this
.
extractable
=
extractable
;
if
(
tokenObject
==
false
)
{
session
.
addObject
();
sessionKeyRef
=
new
SessionKeyRef
(
this
,
keyID
,
session
);
}
else
{
sessionKeyRef
=
null
;
}
}
...
...
@@ -236,24 +238,6 @@ abstract class P11Key implements Key {
}
}
protected
void
finalize
()
throws
Throwable
{
if
(
tokenObject
||
(
token
.
isValid
()
==
false
))
{
super
.
finalize
();
return
;
}
Session
newSession
=
null
;
try
{
newSession
=
token
.
getOpSession
();
token
.
p11
.
C_DestroyObject
(
newSession
.
id
(),
keyID
);
}
catch
(
PKCS11Exception
e
)
{
// ignore
}
finally
{
token
.
releaseSession
(
newSession
);
session
.
removeObject
();
super
.
finalize
();
}
}
private
final
static
CK_ATTRIBUTE
[]
A0
=
new
CK_ATTRIBUTE
[
0
];
private
static
CK_ATTRIBUTE
[]
getAttributes
(
Session
session
,
long
keyID
,
...
...
@@ -1055,5 +1039,65 @@ abstract class P11Key implements Key {
+
"\n parameters: "
+
params
;
}
}
}
final
class
SessionKeyRef
extends
WeakReference
<
P11Key
>
implements
Comparable
<
SessionKeyRef
>
{
private
static
ReferenceQueue
<
P11Key
>
refQueue
=
new
ReferenceQueue
<
P11Key
>();
private
static
Set
<
SessionKeyRef
>
refList
=
Collections
.
synchronizedSortedSet
(
new
TreeSet
<
SessionKeyRef
>());
static
ReferenceQueue
<
P11Key
>
referenceQueue
()
{
return
refQueue
;
}
static
final
private
int
MAX_ITERATIONS
=
2
;
private
static
void
drainRefQueueBounded
()
{
int
iterations
=
0
;
while
(
iterations
<
MAX_ITERATIONS
)
{
SessionKeyRef
next
=
(
SessionKeyRef
)
refQueue
.
poll
();
if
(
next
!=
null
)
next
.
dispose
();
++
iterations
;
}
}
// handle to the native key
private
long
keyID
;
private
Session
session
;
SessionKeyRef
(
P11Key
key
,
long
keyID
,
Session
session
)
{
super
(
key
,
refQueue
);
this
.
keyID
=
keyID
;
this
.
session
=
session
;
this
.
session
.
addObject
();
refList
.
add
(
this
);
// TBD: run at some interval and not every time?
drainRefQueueBounded
();
}
void
dispose
()
{
refList
.
remove
(
this
);
if
(
session
.
token
.
isValid
())
{
Session
newSession
=
null
;
try
{
newSession
=
session
.
token
.
getOpSession
();
session
.
token
.
p11
.
C_DestroyObject
(
newSession
.
id
(),
keyID
);
}
catch
(
PKCS11Exception
e
)
{
// ignore
}
finally
{
session
.
token
.
releaseSession
(
newSession
);
session
.
removeObject
();
}
}
}
public
int
compareTo
(
SessionKeyRef
other
)
{
if
(
this
.
keyID
==
other
.
keyID
)
{
return
0
;
}
else
{
return
(
this
.
keyID
<
other
.
keyID
)
?
-
1
:
1
;
}
}
}
src/share/classes/sun/security/pkcs11/P11RSACipher.java
浏览文件 @
26bc4f44
/*
* Copyright 2003-200
8
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-200
9
Sun Microsystems, Inc. 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
...
...
@@ -191,7 +191,9 @@ final class P11RSACipher extends CipherSpi {
throw
new
InvalidKeyException
(
"Unwrap has to be used with private keys"
);
}
encrypt
=
false
;
// No further setup needed for C_Unwrap(). We'll initialize later
// if we can't use C_Unwrap().
return
;
}
else
{
throw
new
InvalidKeyException
(
"Unsupported mode: "
+
opmode
);
}
...
...
@@ -452,7 +454,7 @@ final class P11RSACipher extends CipherSpi {
long
keyID
=
token
.
p11
.
C_UnwrapKey
(
s
.
id
(),
new
CK_MECHANISM
(
mechanism
),
p11Key
.
keyID
,
wrappedKey
,
attributes
);
return
P11Key
.
secretKey
(
s
ession
,
keyID
,
algorithm
,
48
<<
3
,
return
P11Key
.
secretKey
(
s
,
keyID
,
algorithm
,
48
<<
3
,
attributes
);
}
catch
(
PKCS11Exception
e
)
{
throw
new
InvalidKeyException
(
"unwrap() failed"
,
e
);
...
...
@@ -461,6 +463,7 @@ final class P11RSACipher extends CipherSpi {
}
}
// XXX implement unwrap using C_Unwrap() for all keys
implInit
(
Cipher
.
DECRYPT_MODE
,
p11Key
);
if
(
wrappedKey
.
length
>
maxInputSize
)
{
throw
new
InvalidKeyException
(
"Key is too long for unwrapping"
);
}
...
...
src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java
浏览文件 @
26bc4f44
...
...
@@ -151,7 +151,7 @@ final class P11SecretKeyFactory extends SecretKeyFactorySpi {
session
=
token
.
getObjSession
();
long
newKeyID
=
token
.
p11
.
C_CopyObject
(
session
.
id
(),
p11Key
.
keyID
,
extraAttrs
);
p11Key
=
(
P11Key
)
(
P11Key
.
secretKey
(
p11Key
.
session
,
p11Key
=
(
P11Key
)
(
P11Key
.
secretKey
(
session
,
newKeyID
,
p11Key
.
algorithm
,
p11Key
.
keyLength
,
extraAttrs
));
}
catch
(
PKCS11Exception
p11e
)
{
...
...
src/share/classes/sun/security/provider/SeedGenerator.java
浏览文件 @
26bc4f44
/*
* Copyright 1996-200
6
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-200
9
Sun Microsystems, Inc. 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
...
...
@@ -68,6 +68,9 @@ import java.io.*;
import
java.util.Properties
;
import
java.util.Enumeration
;
import
java.net.*
;
import
java.nio.file.DirectoryStream
;
import
java.nio.file.Path
;
import
java.util.Random
;
import
sun.security.util.Debug
;
abstract
class
SeedGenerator
{
...
...
@@ -180,10 +183,27 @@ abstract class SeedGenerator {
// The temporary dir
File
f
=
new
File
(
p
.
getProperty
(
"java.io.tmpdir"
));
String
[]
sa
=
f
.
list
();
for
(
int
i
=
0
;
i
<
sa
.
length
;
i
++)
md
.
update
(
sa
[
i
].
getBytes
());
int
count
=
0
;
DirectoryStream
<
Path
>
ds
=
f
.
toPath
().
newDirectoryStream
();
try
{
// We use a Random object to choose what file names
// should be used. Otherwise on a machine with too
// many files, the same first 1024 files always get
// used. Any, We make sure the first 512 files are
// always used.
Random
r
=
new
Random
();
for
(
Path
path:
ds
)
{
if
(
count
<
512
||
r
.
nextBoolean
())
{
md
.
update
(
path
.
getName
().
toString
().
getBytes
());
}
if
(
count
++
>
1024
)
{
break
;
}
}
}
finally
{
ds
.
close
();
}
}
catch
(
Exception
ex
)
{
md
.
update
((
byte
)
ex
.
hashCode
());
}
...
...
src/share/classes/sun/security/tools/KeyTool.java
浏览文件 @
26bc4f44
...
...
@@ -1910,7 +1910,9 @@ public final class KeyTool {
ObjectIdentifier
oid
=
attr
.
getAttributeId
();
if
(
oid
.
equals
(
PKCS9Attribute
.
EXTENSION_REQUEST_OID
))
{
CertificateExtensions
exts
=
(
CertificateExtensions
)
attr
.
getAttributeValue
();
printExtensions
(
rb
.
getString
(
"Extension Request:"
),
exts
,
out
);
if
(
exts
!=
null
)
{
printExtensions
(
rb
.
getString
(
"Extension Request:"
),
exts
,
out
);
}
}
else
{
out
.
println
(
attr
.
getAttributeId
());
out
.
println
(
attr
.
getAttributeValue
());
...
...
@@ -2495,7 +2497,9 @@ public final class KeyTool {
X509CertImpl
.
INFO
);
CertificateExtensions
exts
=
(
CertificateExtensions
)
certInfo
.
get
(
X509CertInfo
.
EXTENSIONS
);
printExtensions
(
rb
.
getString
(
"Extensions: "
),
exts
,
out
);
if
(
exts
!=
null
)
{
printExtensions
(
rb
.
getString
(
"Extensions: "
),
exts
,
out
);
}
}
}
...
...
src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
浏览文件 @
26bc4f44
此差异已折叠。
点击以展开。
src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003-200
7
Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003-200
9
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -81,6 +81,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptInit
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_EncryptInit
)(
ckSessionHandle
,
&
ckMechanism
,
ckKeyHandle
);
...
...
@@ -126,14 +127,29 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1Encrypt
if
(
jInLen
>
MAX_STACK_BUFFER_LEN
)
{
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
inBufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
inBufP
=
IBUF
;
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
inBufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
return
0
;
}
ckEncryptedPartLen
=
jOutLen
;
if
(
jOutLen
>
MAX_STACK_BUFFER_LEN
)
{
outBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jOutLen
);
if
(
outBufP
==
NULL
)
{
if
(
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
outBufP
=
OBUF
;
}
...
...
@@ -193,10 +209,18 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate
}
else
{
if
(
jInLen
>
MAX_STACK_BUFFER_LEN
)
{
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
inBufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
inBufP
=
IBUF
;
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
inBufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
directIn
==
0
&&
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
return
0
;
}
}
ckEncryptedPartLen
=
jOutLen
;
...
...
@@ -205,6 +229,13 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate
}
else
{
if
(
jOutLen
>
MAX_STACK_BUFFER_LEN
)
{
outBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jOutLen
);
if
(
outBufP
==
NULL
)
{
if
(
directIn
==
0
&&
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
outBufP
=
OBUF
;
}
...
...
@@ -317,6 +348,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptInit
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_DecryptInit
)(
ckSessionHandle
,
&
ckMechanism
,
ckKeyHandle
);
...
...
@@ -362,14 +394,29 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1Decrypt
if
(
jInLen
>
MAX_STACK_BUFFER_LEN
)
{
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
inBufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
inBufP
=
IBUF
;
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
inBufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
return
0
;
}
ckPartLen
=
jOutLen
;
if
(
jOutLen
>
MAX_STACK_BUFFER_LEN
)
{
outBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jOutLen
);
if
(
outBufP
==
NULL
)
{
if
(
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
outBufP
=
OBUF
;
}
...
...
@@ -429,10 +476,18 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate
}
else
{
if
(
jInLen
>
MAX_STACK_BUFFER_LEN
)
{
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
inBufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
inBufP
=
IBUF
;
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
inBufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
directIn
==
0
&&
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
return
0
;
}
}
ckDecryptedPartLen
=
jOutLen
;
...
...
@@ -441,6 +496,13 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate
}
else
{
if
(
jOutLen
>
MAX_STACK_BUFFER_LEN
)
{
outBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jOutLen
);
if
(
outBufP
==
NULL
)
{
if
(
directIn
==
0
&&
inBufP
!=
IBUF
)
{
free
(
inBufP
);
}
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
else
{
outBufP
=
OBUF
;
}
...
...
src/share/native/sun/security/pkcs11/wrapper/p11_digest.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003
-2009
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -75,6 +75,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestInit
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_DigestInit
)(
ckSessionHandle
,
&
ckMechanism
);
...
...
@@ -82,7 +83,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestInit
free
(
ckMechanism
.
pParameter
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -114,6 +115,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestSingle
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
0
;
}
rv
=
(
*
ckpFunctions
->
C_DigestInit
)(
ckSessionHandle
,
&
ckMechanism
);
...
...
@@ -121,29 +123,32 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestSingle
free
(
ckMechanism
.
pParameter
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0
;
}
if
(
jInLen
<=
MAX_STACK_BUFFER_LEN
)
{
bufP
=
BUF
;
}
else
{
/* always use single part op, even for large data */
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
bufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
bufP
);
rv
=
(
*
ckpFunctions
->
C_Digest
)(
ckSessionHandle
,
bufP
,
jInLen
,
DIGESTBUF
,
&
ckDigestLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
0
;
}
(
*
env
)
->
SetByteArrayRegion
(
env
,
jDigest
,
jDigestOfs
,
ckDigestLength
,
(
jbyte
*
)
DIGESTBUF
);
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
rv
=
(
*
ckpFunctions
->
C_Digest
)(
ckSessionHandle
,
bufP
,
jInLen
,
DIGESTBUF
,
&
ckDigestLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
(
*
env
)
->
SetByteArrayRegion
(
env
,
jDigest
,
jDigestOfs
,
ckDigestLength
,
(
jbyte
*
)
DIGESTBUF
);
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
ckDigestLength
;
}
#endif
...
...
@@ -183,17 +188,23 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestUpdate
bufP
=
BUF
;
}
else
{
bufLen
=
min
(
MAX_HEAP_BUFFER_LEN
,
jInLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
bufLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
bufLen
);
if
(
bufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
;
}
}
while
(
jInLen
>
0
)
{
jsize
chunkLen
=
min
(
bufLen
,
jInLen
);
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
chunkLen
,
(
jbyte
*
)
bufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
;
}
rv
=
(
*
ckpFunctions
->
C_DigestUpdate
)(
ckSessionHandle
,
bufP
,
chunkLen
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
;
}
jInOfs
+=
chunkLen
;
...
...
@@ -229,7 +240,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestKey
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
rv
=
(
*
ckpFunctions
->
C_DigestKey
)(
ckSessionHandle
,
ckKeyHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -257,10 +268,9 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestFinal
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
rv
=
(
*
ckpFunctions
->
C_DigestFinal
)(
ckSessionHandle
,
BUF
,
&
ckDigestLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0
;
}
(
*
env
)
->
SetByteArrayRegion
(
env
,
jDigest
,
jDigestOfs
,
ckDigestLength
,
(
jbyte
*
)
BUF
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
(
*
env
)
->
SetByteArrayRegion
(
env
,
jDigest
,
jDigestOfs
,
ckDigestLength
,
(
jbyte
*
)
BUF
);
}
return
ckDigestLength
;
}
#endif
...
...
@@ -288,12 +298,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SeedRandom
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jSeed
,
&
ckpSeed
,
&
ckSeedLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_SeedRandom
)(
ckSessionHandle
,
ckpSeed
,
ckSeedLength
);
free
(
ckpSeed
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -322,6 +333,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateRandom
jRandomBufferLength
=
(
*
env
)
->
GetArrayLength
(
env
,
jRandomData
);
jRandomBuffer
=
(
*
env
)
->
GetByteArrayElements
(
env
,
jRandomData
,
NULL
);
if
(
jRandomBuffer
==
NULL
)
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_GenerateRandom
)(
ckSessionHandle
,
(
CK_BYTE_PTR
)
jRandomBuffer
,
...
...
@@ -330,6 +342,6 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateRandom
/* copy back generated bytes */
(
*
env
)
->
ReleaseByteArrayElements
(
env
,
jRandomData
,
jRandomBuffer
,
0
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
src/share/native/sun/security/pkcs11/wrapper/p11_dual.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003-200
7
Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003-200
9
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -73,7 +73,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestEn
CK_SESSION_HANDLE
ckSessionHandle
;
CK_BYTE_PTR
ckpPart
=
NULL_PTR
,
ckpEncryptedPart
;
CK_ULONG
ckPartLength
,
ckEncryptedPartLength
=
0
;
jbyteArray
jEncryptedPart
;
jbyteArray
jEncryptedPart
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -81,20 +81,28 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestEn
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jPart
,
&
ckpPart
,
&
ckPartLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_DigestEncryptUpdate
)(
ckSessionHandle
,
ckpPart
,
ckPartLength
,
NULL_PTR
,
&
ckEncryptedPartLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
free
(
ckpPart
);
return
NULL
;
}
ckpEncryptedPart
=
(
CK_BYTE_PTR
)
malloc
(
ckEncryptedPartLength
*
sizeof
(
CK_BYTE
));
if
(
ckpEncryptedPart
==
NULL
)
{
free
(
ckpPart
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_DigestEncryptUpdate
)(
ckSessionHandle
,
ckpPart
,
ckPartLength
,
ckpEncryptedPart
,
&
ckEncryptedPartLength
);
jEncryptedPart
=
ckByteArrayToJByteArray
(
env
,
ckpEncryptedPart
,
ckEncryptedPartLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jEncryptedPart
=
ckByteArrayToJByteArray
(
env
,
ckpEncryptedPart
,
ckEncryptedPartLength
);
}
free
(
ckpPart
);
free
(
ckpEncryptedPart
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jEncryptedPart
;
}
#endif
...
...
@@ -117,7 +125,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptD
CK_SESSION_HANDLE
ckSessionHandle
;
CK_BYTE_PTR
ckpPart
,
ckpEncryptedPart
=
NULL_PTR
;
CK_ULONG
ckPartLength
=
0
,
ckEncryptedPartLength
;
jbyteArray
jPart
;
jbyteArray
jPart
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -125,19 +133,27 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptD
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jEncryptedPart
,
&
ckpEncryptedPart
,
&
ckEncryptedPartLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_DecryptDigestUpdate
)(
ckSessionHandle
,
ckpEncryptedPart
,
ckEncryptedPartLength
,
NULL_PTR
,
&
ckPartLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
free
(
ckpEncryptedPart
);
return
NULL
;
}
ckpPart
=
(
CK_BYTE_PTR
)
malloc
(
ckPartLength
*
sizeof
(
CK_BYTE
));
if
(
ckpPart
==
NULL
)
{
free
(
ckpEncryptedPart
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_DecryptDigestUpdate
)(
ckSessionHandle
,
ckpEncryptedPart
,
ckEncryptedPartLength
,
ckpPart
,
&
ckPartLength
);
jPart
=
ckByteArrayToJByteArray
(
env
,
ckpPart
,
ckPartLength
);
free
(
ckpPart
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jPart
=
ckByteArrayToJByteArray
(
env
,
ckpPart
,
ckPartLength
);
}
free
(
ckpEncryptedPart
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
free
(
ckpPart
);
return
jPart
;
}
...
...
@@ -161,7 +177,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignEncr
CK_SESSION_HANDLE
ckSessionHandle
;
CK_BYTE_PTR
ckpPart
=
NULL_PTR
,
ckpEncryptedPart
;
CK_ULONG
ckPartLength
,
ckEncryptedPartLength
=
0
;
jbyteArray
jEncryptedPart
;
jbyteArray
jEncryptedPart
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -169,20 +185,28 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignEncr
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jPart
,
&
ckpPart
,
&
ckPartLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_SignEncryptUpdate
)(
ckSessionHandle
,
ckpPart
,
ckPartLength
,
NULL_PTR
,
&
ckEncryptedPartLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
free
(
ckpPart
);
return
NULL
;
}
ckpEncryptedPart
=
(
CK_BYTE_PTR
)
malloc
(
ckEncryptedPartLength
*
sizeof
(
CK_BYTE
));
if
(
ckpEncryptedPart
==
NULL
)
{
free
(
ckpPart
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_SignEncryptUpdate
)(
ckSessionHandle
,
ckpPart
,
ckPartLength
,
ckpEncryptedPart
,
&
ckEncryptedPartLength
);
jEncryptedPart
=
ckByteArrayToJByteArray
(
env
,
ckpEncryptedPart
,
ckEncryptedPartLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jEncryptedPart
=
ckByteArrayToJByteArray
(
env
,
ckpEncryptedPart
,
ckEncryptedPartLength
);
}
free
(
ckpPart
);
free
(
ckpEncryptedPart
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jEncryptedPart
;
}
#endif
...
...
@@ -205,7 +229,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptV
CK_SESSION_HANDLE
ckSessionHandle
;
CK_BYTE_PTR
ckpPart
,
ckpEncryptedPart
=
NULL_PTR
;
CK_ULONG
ckPartLength
=
0
,
ckEncryptedPartLength
;
jbyteArray
jPart
;
jbyteArray
jPart
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -213,19 +237,28 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptV
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jEncryptedPart
,
&
ckpEncryptedPart
,
&
ckEncryptedPartLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_DecryptVerifyUpdate
)(
ckSessionHandle
,
ckpEncryptedPart
,
ckEncryptedPartLength
,
NULL_PTR
,
&
ckPartLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
free
(
ckpEncryptedPart
);
return
NULL
;
}
ckpPart
=
(
CK_BYTE_PTR
)
malloc
(
ckPartLength
*
sizeof
(
CK_BYTE
));
if
(
ckpPart
==
NULL
)
{
free
(
ckpEncryptedPart
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_DecryptVerifyUpdate
)(
ckSessionHandle
,
ckpEncryptedPart
,
ckEncryptedPartLength
,
ckpPart
,
&
ckPartLength
);
jPart
=
ckByteArrayToJByteArray
(
env
,
ckpPart
,
ckPartLength
);
free
(
ckpPart
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jPart
=
ckByteArrayToJByteArray
(
env
,
ckpPart
,
ckPartLength
);
}
free
(
ckpEncryptedPart
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
free
(
ckpPart
);
return
jPart
;
}
...
...
@@ -252,7 +285,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetFunctionSta
/* C_GetFunctionStatus should always return CKR_FUNCTION_NOT_PARALLEL */
rv
=
(
*
ckpFunctions
->
C_GetFunctionStatus
)(
ckSessionHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -277,6 +310,6 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CancelFunction
/* C_GetFunctionStatus should always return CKR_FUNCTION_NOT_PARALLEL */
rv
=
(
*
ckpFunctions
->
C_CancelFunction
)(
ckSessionHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
src/share/native/sun/security/pkcs11/wrapper/p11_general.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003-200
6
Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003-200
9
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -102,6 +102,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_initializeLibrary
jclass
fetchClass
(
JNIEnv
*
env
,
const
char
*
name
)
{
jclass
tmpClass
=
(
*
env
)
->
FindClass
(
env
,
name
);
if
(
tmpClass
==
NULL
)
{
return
NULL
;
}
return
(
*
env
)
->
NewGlobalRef
(
env
,
tmpClass
);
}
...
...
@@ -110,14 +111,18 @@ void prefetchFields(JNIEnv *env, jclass thisClass) {
/* PKCS11 */
pNativeDataID
=
(
*
env
)
->
GetFieldID
(
env
,
thisClass
,
"pNativeData"
,
"J"
);
if
(
pNativeDataID
==
NULL
)
{
return
;
}
/* CK_MECHANISM */
tmpClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_MECHANISM
);
if
(
tmpClass
==
NULL
)
{
return
;
}
mech_mechanismID
=
(
*
env
)
->
GetFieldID
(
env
,
tmpClass
,
"mechanism"
,
"J"
);
if
(
mech_mechanismID
==
NULL
)
{
return
;
}
mech_pParameterID
=
(
*
env
)
->
GetFieldID
(
env
,
tmpClass
,
"pParameter"
,
"Ljava/lang/Object;"
);
if
(
mech_pParameterID
==
NULL
)
{
return
;
}
jByteArrayClass
=
fetchClass
(
env
,
"[B"
);
if
(
jByteArrayClass
==
NULL
)
{
return
;
}
jLongClass
=
fetchClass
(
env
,
"java/lang/Long"
);
}
...
...
@@ -252,10 +257,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetInfo
if
(
ckpFunctions
==
NULL
)
{
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_GetInfo
)(
&
ckLibInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
jInfoObject
=
ckInfoPtrToJInfo
(
env
,
&
ckLibInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jInfoObject
=
ckInfoPtrToJInfo
(
env
,
&
ckLibInfo
);
}
return
jInfoObject
;
}
...
...
@@ -279,28 +283,31 @@ jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo)
/* load CK_INFO class */
jInfoClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_INFO
);
assert
(
jInfoClass
!=
0
)
;
if
(
jInfoClass
==
NULL
)
{
return
NULL
;
}
;
/* load CK_INFO constructor */
jCtrId
=
(
*
env
)
->
GetMethodID
(
env
,
jInfoClass
,
"<init>"
,
"(Lsun/security/pkcs11/wrapper/CK_VERSION;[CJ[CLsun/security/pkcs11/wrapper/CK_VERSION;)V"
);
assert
(
jCtrId
!=
0
);
if
(
jCtrId
==
NULL
)
{
return
NULL
;
}
/* prep all fields */
jCryptokiVer
=
ckVersionPtrToJVersion
(
env
,
&
(
ckpInfo
->
cryptokiVersion
));
if
(
jCryptokiVer
==
NULL
)
{
return
NULL
;
}
jVendor
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpInfo
->
manufacturerID
[
0
]),
32
);
if
(
jVendor
==
NULL
)
{
return
NULL
;
}
jFlags
=
ckULongToJLong
(
ckpInfo
->
flags
);
jLibraryDesc
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpInfo
->
libraryDescription
[
0
]),
32
);
if
(
jLibraryDesc
==
NULL
)
{
return
NULL
;
}
jLibraryVer
=
ckVersionPtrToJVersion
(
env
,
&
(
ckpInfo
->
libraryVersion
));
if
(
jLibraryVer
==
NULL
)
{
return
NULL
;
}
/* create new CK_INFO object */
jInfoObject
=
(
*
env
)
->
NewObject
(
env
,
jInfoClass
,
jCtrId
,
jCryptokiVer
,
jVendor
,
jFlags
,
jLibraryDesc
,
jLibraryVer
);
assert
(
jInfoObject
!=
0
);
if
(
jInfoObject
==
NULL
)
{
return
NULL
;
}
/* free local references */
(
*
env
)
->
DeleteLocalRef
(
env
,
jInfoClass
);
...
...
@@ -343,15 +350,18 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotList
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
ckpSlotList
=
(
CK_SLOT_ID_PTR
)
malloc
(
ckTokenNumber
*
sizeof
(
CK_SLOT_ID
));
if
(
ckpSlotList
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_GetSlotList
)(
ckTokenPresent
,
ckpSlotList
,
&
ckTokenNumber
);
jSlotList
=
ckULongArrayToJLongArray
(
env
,
ckpSlotList
,
ckTokenNumber
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jSlotList
=
ckULongArrayToJLongArray
(
env
,
ckpSlotList
,
ckTokenNumber
);
}
free
(
ckpSlotList
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jSlotList
;
}
#endif
...
...
@@ -380,10 +390,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotInfo
ckSlotID
=
jLongToCKULong
(
jSlotID
);
rv
=
(
*
ckpFunctions
->
C_GetSlotInfo
)(
ckSlotID
,
&
ckSlotInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
jSlotInfoObject
=
ckSlotInfoPtrToJSlotInfo
(
env
,
&
ckSlotInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jSlotInfoObject
=
ckSlotInfoPtrToJSlotInfo
(
env
,
&
ckSlotInfo
);
}
return
jSlotInfoObject
;
}
...
...
@@ -410,28 +419,32 @@ ckSlotInfoPtrToJSlotInfo
/* load CK_SLOT_INFO class */
jSlotInfoClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_SLOT_INFO
);
assert
(
jSlotInfoClass
!=
0
)
;
if
(
jSlotInfoClass
==
NULL
)
{
return
NULL
;
}
;
/* load CK_SLOT_INFO constructor */
jCtrId
=
(
*
env
)
->
GetMethodID
(
env
,
jSlotInfoClass
,
"<init>"
,
"([C[CJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;)V"
);
assert
(
jCtrId
!=
0
);
if
(
jCtrId
==
NULL
)
{
return
NULL
;
}
/* prep all fields */
jSlotDesc
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpSlotInfo
->
slotDescription
[
0
]),
64
);
if
(
jSlotDesc
==
NULL
)
{
return
NULL
;
}
jVendor
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpSlotInfo
->
manufacturerID
[
0
]),
32
);
if
(
jVendor
==
NULL
)
{
return
NULL
;
}
jFlags
=
ckULongToJLong
(
ckpSlotInfo
->
flags
);
jHardwareVer
=
ckVersionPtrToJVersion
(
env
,
&
(
ckpSlotInfo
->
hardwareVersion
));
if
(
jHardwareVer
==
NULL
)
{
return
NULL
;
}
jFirmwareVer
=
ckVersionPtrToJVersion
(
env
,
&
(
ckpSlotInfo
->
firmwareVersion
));
if
(
jFirmwareVer
==
NULL
)
{
return
NULL
;
}
/* create new CK_SLOT_INFO object */
jSlotInfoObject
=
(
*
env
)
->
NewObject
(
env
,
jSlotInfoClass
,
jCtrId
,
jSlotDesc
,
jVendor
,
jFlags
,
jHardwareVer
,
jFirmwareVer
);
assert
(
jSlotInfoObject
!=
0
);
if
(
jSlotInfoObject
==
NULL
)
{
return
NULL
;
}
/* free local references */
(
*
env
)
->
DeleteLocalRef
(
env
,
jSlotInfoClass
);
...
...
@@ -460,7 +473,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetTokenInfo
{
CK_SLOT_ID
ckSlotID
;
CK_TOKEN_INFO
ckTokenInfo
;
jobject
jInfoTokenObject
;
jobject
jInfoTokenObject
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -469,10 +482,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetTokenInfo
ckSlotID
=
jLongToCKULong
(
jSlotID
);
rv
=
(
*
ckpFunctions
->
C_GetTokenInfo
)(
ckSlotID
,
&
ckTokenInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
jInfoTokenObject
=
ckTokenInfoPtrToJTokenInfo
(
env
,
&
ckTokenInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jInfoTokenObject
=
ckTokenInfoPtrToJTokenInfo
(
env
,
&
ckTokenInfo
);
}
return
jInfoTokenObject
;
}
...
...
@@ -512,21 +524,25 @@ ckTokenInfoPtrToJTokenInfo
/* load CK_TOKEN_INFO class */
jTokenInfoClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_TOKEN_INFO
);
assert
(
jTokenInfoClass
!=
0
)
;
if
(
jTokenInfoClass
==
NULL
)
{
return
NULL
;
}
;
/* load CK_TOKEN_INFO constructor */
jCtrId
=
(
*
env
)
->
GetMethodID
(
env
,
jTokenInfoClass
,
"<init>"
,
"([C[C[C[CJJJJJJJJJJJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;[C)V"
);
assert
(
jCtrId
!=
0
)
;
if
(
jCtrId
==
NULL
)
{
return
NULL
;
}
;
/* prep all fields */
jLabel
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpTokenInfo
->
label
[
0
]),
32
);
if
(
jLabel
==
NULL
)
{
return
NULL
;
};
jVendor
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpTokenInfo
->
manufacturerID
[
0
]),
32
);
if
(
jVendor
==
NULL
)
{
return
NULL
;
};
jModel
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpTokenInfo
->
model
[
0
]),
16
);
if
(
jModel
==
NULL
)
{
return
NULL
;
};
jSerialNo
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpTokenInfo
->
serialNumber
[
0
]),
16
);
if
(
jSerialNo
==
NULL
)
{
return
NULL
;
};
jFlags
=
ckULongToJLong
(
ckpTokenInfo
->
flags
);
jMaxSnCnt
=
ckULongSpecialToJLong
(
ckpTokenInfo
->
ulMaxSessionCount
);
jSnCnt
=
ckULongSpecialToJLong
(
ckpTokenInfo
->
ulSessionCount
);
...
...
@@ -540,10 +556,13 @@ ckTokenInfoPtrToJTokenInfo
jFreePrivMem
=
ckULongSpecialToJLong
(
ckpTokenInfo
->
ulFreePrivateMemory
);
jHardwareVer
=
ckVersionPtrToJVersion
(
env
,
&
(
ckpTokenInfo
->
hardwareVersion
));
if
(
jHardwareVer
==
NULL
)
{
return
NULL
;
}
jFirmwareVer
=
ckVersionPtrToJVersion
(
env
,
&
(
ckpTokenInfo
->
firmwareVersion
));
if
(
jFirmwareVer
==
NULL
)
{
return
NULL
;
}
jUtcTime
=
ckUTF8CharArrayToJCharArray
(
env
,
&
(
ckpTokenInfo
->
utcTime
[
0
]),
16
);
if
(
jUtcTime
==
NULL
)
{
return
NULL
;
}
/* create new CK_TOKEN_INFO object */
jTokenInfoObject
=
...
...
@@ -553,7 +572,7 @@ ckTokenInfoPtrToJTokenInfo
jMaxPinLen
,
jMinPinLen
,
jTotalPubMem
,
jFreePubMem
,
jTotalPrivMem
,
jFreePrivMem
,
jHardwareVer
,
jFirmwareVer
,
jUtcTime
);
assert
(
jTokenInfoObject
!=
0
);
if
(
jTokenInfoObject
==
NULL
)
{
return
NULL
;
}
/* free local references */
(
*
env
)
->
DeleteLocalRef
(
env
,
jTokenInfoClass
);
...
...
@@ -584,7 +603,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1WaitForSlotEvent
{
CK_FLAGS
ckFlags
;
CK_SLOT_ID
ckSlotID
;
jlong
jSlotID
;
jlong
jSlotID
=
0L
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -593,9 +612,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1WaitForSlotEvent
ckFlags
=
jLongToCKULong
(
jFlags
);
rv
=
(
*
ckpFunctions
->
C_WaitForSlotEvent
)(
ckFlags
,
&
ckSlotID
,
NULL_PTR
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
jSlotID
=
ckULongToJLong
(
ckSlotID
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jSlotID
=
ckULongToJLong
(
ckSlotID
);
}
return
jSlotID
;
}
...
...
@@ -632,16 +651,19 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismList
ckpMechanismList
=
(
CK_MECHANISM_TYPE_PTR
)
malloc
(
ckMechanismNumber
*
sizeof
(
CK_MECHANISM_TYPE
));
if
(
ckpMechanismList
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_GetMechanismList
)(
ckSlotID
,
ckpMechanismList
,
&
ckMechanismNumber
);
jMechanismList
=
ckULongArrayToJLongArray
(
env
,
ckpMechanismList
,
ckMechanismNumber
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jMechanismList
=
ckULongArrayToJLongArray
(
env
,
ckpMechanismList
,
ckMechanismNumber
);
}
free
(
ckpMechanismList
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jMechanismList
;
}
#endif
...
...
@@ -663,7 +685,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismInfo
CK_SLOT_ID
ckSlotID
;
CK_MECHANISM_TYPE
ckMechanismType
;
CK_MECHANISM_INFO
ckMechanismInfo
;
jobject
jMechanismInfo
;
jobject
jMechanismInfo
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -674,10 +696,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismInfo
rv
=
(
*
ckpFunctions
->
C_GetMechanismInfo
)(
ckSlotID
,
ckMechanismType
,
&
ckMechanismInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
jMechanismInfo
=
ckMechanismInfoPtrToJMechanismInfo
(
env
,
&
ckMechanismInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jMechanismInfo
=
ckMechanismInfoPtrToJMechanismInfo
(
env
,
&
ckMechanismInfo
);
}
return
jMechanismInfo
;
}
...
...
@@ -703,11 +724,11 @@ ckMechanismInfoPtrToJMechanismInfo
/* load CK_MECHANISM_INFO class */
jMechanismInfoClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_MECHANISM_INFO
);
assert
(
jMechanismInfoClass
!=
0
)
;
if
(
jMechanismInfoClass
==
NULL
)
{
return
NULL
;
}
;
/* load CK_MECHANISM_INFO constructor */
jCtrId
=
(
*
env
)
->
GetMethodID
(
env
,
jMechanismInfoClass
,
"<init>"
,
"(JJJ)V"
);
assert
(
jCtrId
!=
0
)
;
if
(
jCtrId
==
NULL
)
{
return
NULL
;
}
;
/* prep all fields */
jMinKeySize
=
ckULongToJLong
(
ckpMechanismInfo
->
ulMinKeySize
);
...
...
@@ -717,7 +738,7 @@ ckMechanismInfoPtrToJMechanismInfo
/* create new CK_MECHANISM_INFO object */
jMechanismInfoObject
=
(
*
env
)
->
NewObject
(
env
,
jMechanismInfoClass
,
jCtrId
,
jMinKeySize
,
jMaxKeySize
,
jFlags
);
assert
(
jMechanismInfoObject
!=
0
)
;
if
(
jMechanismInfoObject
==
NULL
)
{
return
NULL
;
}
;
/* free local references */
(
*
env
)
->
DeleteLocalRef
(
env
,
jMechanismInfoClass
);
...
...
@@ -753,8 +774,13 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitToken
ckSlotID
=
jLongToCKULong
(
jSlotID
);
jCharArrayToCKCharArray
(
env
,
jPin
,
&
ckpPin
,
&
ckPinLength
);
jCharArrayToCKUTF8CharArray
(
env
,
jLabel
,
&
ckpLabel
,
&
ckLabelLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
/* ckLabelLength <= 32 !!! */
jCharArrayToCKUTF8CharArray
(
env
,
jLabel
,
&
ckpLabel
,
&
ckLabelLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
free
(
ckpPin
);
return
;
}
rv
=
(
*
ckpFunctions
->
C_InitToken
)(
ckSlotID
,
ckpPin
,
ckPinLength
,
ckpLabel
);
TRACE1
(
"InitToken return code: %d"
,
rv
);
...
...
@@ -790,6 +816,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitPIN
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jCharArrayToCKCharArray
(
env
,
jPin
,
&
ckpPin
,
&
ckPinLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_InitPIN
)(
ckSessionHandle
,
ckpPin
,
ckPinLength
);
...
...
@@ -828,7 +855,12 @@ jcharArray jNewPin)
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jCharArrayToCKCharArray
(
env
,
jOldPin
,
&
ckpOldPin
,
&
ckOldPinLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
jCharArrayToCKCharArray
(
env
,
jNewPin
,
&
ckpNewPin
,
&
ckNewPinLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
free
(
ckpOldPin
);
return
;
}
rv
=
(
*
ckpFunctions
->
C_SetPIN
)(
ckSessionHandle
,
ckpOldPin
,
ckOldPinLength
,
ckpNewPin
,
ckNewPinLength
);
...
...
src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c
浏览文件 @
26bc4f44
此差异已折叠。
点击以展开。
src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003
-2009
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -76,7 +76,7 @@ CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs;
CK_C_INITIALIZE_ARGS_PTR
makeCKInitArgsAdapter
(
JNIEnv
*
env
,
jobject
jInitArgs
)
{
CK_C_INITIALIZE_ARGS_PTR
ckpInitArgs
;
jclass
jInitArgsClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_C_INITIALIZE_ARGS
)
;
jclass
jInitArgsClass
;
jfieldID
fieldID
;
jlong
jFlags
;
jobject
jReserved
;
...
...
@@ -91,10 +91,20 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs)
/* convert the Java InitArgs object to a pointer to a CK_C_INITIALIZE_ARGS structure */
ckpInitArgs
=
(
CK_C_INITIALIZE_ARGS_PTR
)
malloc
(
sizeof
(
CK_C_INITIALIZE_ARGS
));
if
(
ckpInitArgs
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL_PTR
;
}
/* Set the mutex functions that will call the Java mutex functions, but
* only set it, if the field is not null.
*/
jInitArgsClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_C_INITIALIZE_ARGS
);
if
(
jInitArgsClass
==
NULL
)
{
free
(
ckpInitArgs
);
return
NULL
;
}
#ifdef NO_CALLBACKS
ckpInitArgs
->
CreateMutex
=
NULL_PTR
;
ckpInitArgs
->
DestroyMutex
=
NULL_PTR
;
...
...
@@ -102,22 +112,22 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs)
ckpInitArgs
->
UnlockMutex
=
NULL_PTR
;
#else
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"CreateMutex"
,
"Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
NULL
;
}
jMutexHandler
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgs
,
fieldID
);
ckpInitArgs
->
CreateMutex
=
(
jMutexHandler
!=
NULL
)
?
&
callJCreateMutex
:
NULL_PTR
;
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"DestroyMutex"
,
"Lsun/security/pkcs11/wrapper/CK_DESTROYMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
NULL
;
}
jMutexHandler
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgs
,
fieldID
);
ckpInitArgs
->
DestroyMutex
=
(
jMutexHandler
!=
NULL
)
?
&
callJDestroyMutex
:
NULL_PTR
;
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"LockMutex"
,
"Lsun/security/pkcs11/wrapper/CK_LOCKMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
NULL
;
}
jMutexHandler
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgs
,
fieldID
);
ckpInitArgs
->
LockMutex
=
(
jMutexHandler
!=
NULL
)
?
&
callJLockMutex
:
NULL_PTR
;
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"UnlockMutex"
,
"Lsun/security/pkcs11/wrapper/CK_UNLOCKMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
NULL
;
}
jMutexHandler
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgs
,
fieldID
);
ckpInitArgs
->
UnlockMutex
=
(
jMutexHandler
!=
NULL
)
?
&
callJUnlockMutex
:
NULL_PTR
;
...
...
@@ -129,19 +139,25 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs)
/* set the global object jInitArgs so that the right Java mutex functions will be called */
jInitArgsObject
=
(
*
env
)
->
NewGlobalRef
(
env
,
jInitArgs
);
ckpGlobalInitArgs
=
(
CK_C_INITIALIZE_ARGS_PTR
)
malloc
(
sizeof
(
CK_C_INITIALIZE_ARGS
));
if
(
ckpGlobalInitArgs
==
NULL
)
{
free
(
ckpInitArgs
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL_PTR
;
}
memcpy
(
ckpGlobalInitArgs
,
ckpInitArgs
,
sizeof
(
CK_C_INITIALIZE_ARGS
));
}
#endif
/* NO_CALLBACKS */
/* convert and set the flags field */
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"flags"
,
"J"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
NULL
;
}
jFlags
=
(
*
env
)
->
GetLongField
(
env
,
jInitArgs
,
fieldID
);
ckpInitArgs
->
flags
=
jLongToCKULong
(
jFlags
);
/* pReserved should be NULL_PTR in this version */
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"pReserved"
,
"Ljava/lang/Object;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
NULL
;
}
jReserved
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgs
,
fieldID
);
/* we try to convert the reserved parameter also */
...
...
@@ -201,20 +217,21 @@ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex)
wasAttached
=
1
;
}
jCreateMutexClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_CREATEMUTEX
);
if
(
jCreateMutexClass
==
NULL
)
{
return
rv
;
}
jInitArgsClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_C_INITIALIZE_ARGS
);
if
(
jInitArgsClass
==
NULL
)
{
return
rv
;
}
/* get the CreateMutex object out of the jInitArgs object */
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"CreateMutex"
,
"Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
rv
;
}
jCreateMutex
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgsObject
,
fieldID
);
assert
(
jCreateMutex
!=
0
);
/* call the CK_CREATEMUTEX function of the CreateMutex object */
/* and get the new Java mutex object */
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
jCreateMutexClass
,
"CK_CREATEMUTEX"
,
"()Ljava/lang/Object;"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
jMutex
=
(
*
env
)
->
CallObjectMethod
(
env
,
jCreateMutex
,
methodID
);
/* set a global reference on the Java mutex */
...
...
@@ -227,10 +244,13 @@ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex)
pkcs11Exception
=
(
*
env
)
->
ExceptionOccurred
(
env
);
if
(
pkcs11Exception
!=
NULL
)
{
/* TBD: clear the pending exception with ExceptionClear? */
/* The was an exception thrown, now we get the error-code from it */
pkcs11ExceptionClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_PKCS11EXCEPTION
);
if
(
pkcs11ExceptionClass
==
NULL
)
{
return
rv
;
}
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
pkcs11ExceptionClass
,
"getErrorCode"
,
"()J"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
errorCode
=
(
*
env
)
->
CallLongMethod
(
env
,
pkcs11Exception
,
methodID
);
rv
=
jLongToCKULong
(
errorCode
);
}
...
...
@@ -292,22 +312,23 @@ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex)
wasAttached
=
1
;
}
jDestroyMutexClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_DESTROYMUTEX
);
if
(
jDestroyMutexClass
==
NULL
)
{
return
rv
;
}
jInitArgsClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_C_INITIALIZE_ARGS
);
if
(
jInitArgsClass
==
NULL
)
{
return
rv
;
}
/* convert the CK mutex to a Java mutex */
jMutex
=
ckVoidPtrToJObject
(
pMutex
);
/* get the DestroyMutex object out of the jInitArgs object */
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"DestroyMutex"
,
"Lsun/security/pkcs11/wrapper/CK_DESTROYMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
rv
;
}
jDestroyMutex
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgsObject
,
fieldID
);
assert
(
jDestroyMutex
!=
0
);
/* call the CK_DESTROYMUTEX method of the DestroyMutex object */
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
jDestroyMutexClass
,
"CK_DESTROYMUTEX"
,
"(Ljava/lang/Object;)V"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
(
*
env
)
->
CallVoidMethod
(
env
,
jDestroyMutex
,
methodID
,
jMutex
);
/* delete the global reference on the Java mutex */
...
...
@@ -318,10 +339,12 @@ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex)
pkcs11Exception
=
(
*
env
)
->
ExceptionOccurred
(
env
);
if
(
pkcs11Exception
!=
NULL
)
{
/* TBD: clear the pending exception with ExceptionClear? */
/* The was an exception thrown, now we get the error-code from it */
pkcs11ExceptionClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_PKCS11EXCEPTION
);
if
(
pkcs11ExceptionClass
==
NULL
)
{
return
rv
;
}
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
pkcs11ExceptionClass
,
"getErrorCode"
,
"()J"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
errorCode
=
(
*
env
)
->
CallLongMethod
(
env
,
pkcs11Exception
,
methodID
);
rv
=
jLongToCKULong
(
errorCode
);
}
...
...
@@ -383,33 +406,35 @@ CK_RV callJLockMutex(CK_VOID_PTR pMutex)
wasAttached
=
1
;
}
jLockMutexClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_LOCKMUTEX
);
if
(
jLockMutexClass
==
NULL
)
{
return
rv
;
}
jInitArgsClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_C_INITIALIZE_ARGS
);
if
(
jInitArgsClass
==
NULL
)
{
return
rv
;
}
/* convert the CK mutex to a Java mutex */
jMutex
=
ckVoidPtrToJObject
(
pMutex
);
/* get the LockMutex object out of the jInitArgs object */
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"LockMutex"
,
"Lsun/security/pkcs11/wrapper/CK_LOCKMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
rv
;
}
jLockMutex
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgsObject
,
fieldID
);
assert
(
jLockMutex
!=
0
);
/* call the CK_LOCKMUTEX method of the LockMutex object */
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
jLockMutexClass
,
"CK_LOCKMUTEX"
,
"(Ljava/lang/Object;)V"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
(
*
env
)
->
CallVoidMethod
(
env
,
jLockMutex
,
methodID
,
jMutex
);
/* check, if callback threw an exception */
pkcs11Exception
=
(
*
env
)
->
ExceptionOccurred
(
env
);
if
(
pkcs11Exception
!=
NULL
)
{
/* TBD: clear the pending exception with ExceptionClear? */
/* The was an exception thrown, now we get the error-code from it */
pkcs11ExceptionClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_PKCS11EXCEPTION
);
if
(
pkcs11ExceptionClass
==
NULL
)
{
return
rv
;
}
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
pkcs11ExceptionClass
,
"getErrorCode"
,
"()J"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
errorCode
=
(
*
env
)
->
CallLongMethod
(
env
,
pkcs11Exception
,
methodID
);
rv
=
jLongToCKULong
(
errorCode
);
}
...
...
@@ -471,33 +496,35 @@ CK_RV callJUnlockMutex(CK_VOID_PTR pMutex)
wasAttached
=
1
;
}
jUnlockMutexClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_UNLOCKMUTEX
);
if
(
jUnlockMutexClass
==
NULL
)
{
return
rv
;
}
jInitArgsClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_C_INITIALIZE_ARGS
);
if
(
jInitArgsClass
==
NULL
)
{
return
rv
;
}
/* convert the CK-type mutex to a Java mutex */
jMutex
=
ckVoidPtrToJObject
(
pMutex
);
/* get the UnlockMutex object out of the jInitArgs object */
fieldID
=
(
*
env
)
->
GetFieldID
(
env
,
jInitArgsClass
,
"UnlockMutex"
,
"Lsun/security/pkcs11/wrapper/CK_UNLOCKMUTEX;"
);
assert
(
fieldID
!=
0
);
if
(
fieldID
==
NULL
)
{
return
rv
;
}
jUnlockMutex
=
(
*
env
)
->
GetObjectField
(
env
,
jInitArgsObject
,
fieldID
);
assert
(
jUnlockMutex
!=
0
);
/* call the CK_UNLOCKMUTEX method of the UnLockMutex object */
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
jUnlockMutexClass
,
"CK_UNLOCKMUTEX"
,
"(Ljava/lang/Object;)V"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
(
*
env
)
->
CallVoidMethod
(
env
,
jUnlockMutex
,
methodID
,
jMutex
);
/* check, if callback threw an exception */
pkcs11Exception
=
(
*
env
)
->
ExceptionOccurred
(
env
);
if
(
pkcs11Exception
!=
NULL
)
{
/* TBD: clear the pending exception with ExceptionClear? */
/* The was an exception thrown, now we get the error-code from it */
pkcs11ExceptionClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_PKCS11EXCEPTION
);
if
(
pkcs11ExceptionClass
==
NULL
)
{
return
rv
;
}
methodID
=
(
*
env
)
->
GetMethodID
(
env
,
pkcs11ExceptionClass
,
"getErrorCode"
,
"()J"
);
assert
(
methodID
!=
0
);
if
(
methodID
==
NULL
)
{
return
rv
;
}
errorCode
=
(
*
env
)
->
CallLongMethod
(
env
,
pkcs11Exception
,
methodID
);
rv
=
jLongToCKULong
(
errorCode
);
}
...
...
src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003
-2009
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -81,16 +81,14 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CreateObject
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jAttributeArrayToCKAttributeArray
(
env
,
jTemplate
,
&
ckpAttributes
,
&
ckAttributesLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
0L
;
}
rv
=
(
*
ckpFunctions
->
C_CreateObject
)(
ckSessionHandle
,
ckpAttributes
,
ckAttributesLength
,
&
ckObjectHandle
);
jObjectHandle
=
ckULongToJLong
(
ckObjectHandle
);
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
free
(
ckpAttributes
[
i
].
pValue
);
free
(
ckpAttributes
);
freeCKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
return
jObjectHandle
;
}
...
...
@@ -126,14 +124,12 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CopyObject
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
ckObjectHandle
=
jLongToCKULong
(
jObjectHandle
);
jAttributeArrayToCKAttributeArray
(
env
,
jTemplate
,
&
ckpAttributes
,
&
ckAttributesLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
0L
;
}
rv
=
(
*
ckpFunctions
->
C_CopyObject
)(
ckSessionHandle
,
ckObjectHandle
,
ckpAttributes
,
ckAttributesLength
,
&
ckNewObjectHandle
);
jNewObjectHandle
=
ckULongToJLong
(
ckNewObjectHandle
);
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
free
(
ckpAttributes
[
i
].
pValue
);
free
(
ckpAttributes
);
freeCKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
...
...
@@ -164,7 +160,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DestroyObject
ckObjectHandle
=
jLongToCKULong
(
jObjectHandle
);
rv
=
(
*
ckpFunctions
->
C_DestroyObject
)(
ckSessionHandle
,
ckObjectHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -194,7 +190,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetObjectSize
ckObjectHandle
=
jLongToCKULong
(
jObjectHandle
);
rv
=
(
*
ckpFunctions
->
C_GetObjectSize
)(
ckSessionHandle
,
ckObjectHandle
,
&
ckObjectSize
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
jObjectSize
=
ckULongToJLong
(
ckObjectSize
);
...
...
@@ -221,7 +217,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa
CK_ATTRIBUTE_PTR
ckpAttributes
=
NULL_PTR
;
CK_ULONG
ckAttributesLength
;
CK_ULONG
ckBufferLength
;
CK_ULONG
i
;
CK_ULONG
i
,
j
;
jobject
jAttribute
;
CK_RV
rv
;
...
...
@@ -238,19 +234,20 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa
ckObjectHandle
=
jLongToCKULong
(
jObjectHandle
);
TRACE1
(
"jAttributeArrayToCKAttributeArray now with jTemplate = %d"
,
jTemplate
);
jAttributeArrayToCKAttributeArray
(
env
,
jTemplate
,
&
ckpAttributes
,
&
ckAttributesLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
TRACE2
(
"DEBUG: jAttributeArrayToCKAttributeArray finished with ckpAttribute = %d, Length = %d
\n
"
,
ckpAttributes
,
ckAttributesLength
);
/* first set all pValue to NULL, to get the needed buffer length */
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
{
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
{
free
(
ckpAttributes
[
i
].
pValue
);
ckpAttributes
[
i
].
pValue
=
NULL_PTR
;
}
}
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
ckpAttributes
[
i
].
pValue
=
NULL_PTR
;
}
rv
=
(
*
ckpFunctions
->
C_GetAttributeValue
)(
ckSessionHandle
,
ckObjectHandle
,
ckpAttributes
,
ckAttributesLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
free
(
ckpAttributes
);
return
;
}
...
...
@@ -261,27 +258,34 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
ckBufferLength
=
sizeof
(
CK_BYTE
)
*
ckpAttributes
[
i
].
ulValueLen
;
ckpAttributes
[
i
].
pValue
=
(
void
*
)
malloc
(
ckBufferLength
);
if
(
ckpAttributes
[
i
].
pValue
==
NULL
)
{
freeCKAttributeArray
(
ckpAttributes
,
i
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
;
}
ckpAttributes
[
i
].
ulValueLen
=
ckBufferLength
;
}
/* now get the attributes with all values */
rv
=
(
*
ckpFunctions
->
C_GetAttributeValue
)(
ckSessionHandle
,
ckObjectHandle
,
ckpAttributes
,
ckAttributesLength
);
/* copy back the values to the Java attributes */
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
jAttribute
=
ckAttributePtrToJAttribute
(
env
,
&
(
ckpAttributes
[
i
]));
(
*
env
)
->
SetObjectArrayElement
(
env
,
jTemplate
,
i
,
jAttribute
);
}
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
{
free
(
ckpAttributes
[
i
].
pValue
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
/* copy back the values to the Java attributes */
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
jAttribute
=
ckAttributePtrToJAttribute
(
env
,
&
(
ckpAttributes
[
i
]));
if
(
jAttribute
==
NULL
)
{
freeCKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
return
;
}
(
*
env
)
->
SetObjectArrayElement
(
env
,
jTemplate
,
i
,
jAttribute
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
freeCKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
return
;
}
}
}
free
(
ckpAttributes
);
free
CKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
TRACE0
(
"FINISHED
\n
"
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -312,15 +316,11 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetAttributeVa
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
ckObjectHandle
=
jLongToCKULong
(
jObjectHandle
);
jAttributeArrayToCKAttributeArray
(
env
,
jTemplate
,
&
ckpAttributes
,
&
ckAttributesLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_SetAttributeValue
)(
ckSessionHandle
,
ckObjectHandle
,
ckpAttributes
,
ckAttributesLength
);
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
{
free
(
ckpAttributes
[
i
].
pValue
);
}
}
free
(
ckpAttributes
);
freeCKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
...
...
@@ -355,15 +355,11 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObjectsIni
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jAttributeArrayToCKAttributeArray
(
env
,
jTemplate
,
&
ckpAttributes
,
&
ckAttributesLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_FindObjectsInit
)(
ckSessionHandle
,
ckpAttributes
,
ckAttributesLength
);
for
(
i
=
0
;
i
<
ckAttributesLength
;
i
++
)
{
if
(
ckpAttributes
[
i
].
pValue
!=
NULL_PTR
)
{
free
(
ckpAttributes
[
i
].
pValue
);
}
}
free
(
ckpAttributes
);
freeCKAttributeArray
(
ckpAttributes
,
ckAttributesLength
);
TRACE0
(
"FINISHED
\n
"
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
...
...
@@ -397,14 +393,18 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObje
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
ckMaxObjectLength
=
jLongToCKULong
(
jMaxObjectCount
);
ckpObjectHandleArray
=
(
CK_OBJECT_HANDLE_PTR
)
malloc
(
sizeof
(
CK_OBJECT_HANDLE
)
*
ckMaxObjectLength
);
if
(
ckpObjectHandleArray
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_FindObjects
)(
ckSessionHandle
,
ckpObjectHandleArray
,
ckMaxObjectLength
,
&
ckActualObjectCount
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jObjectHandleArray
=
ckULongArrayToJLongArray
(
env
,
ckpObjectHandleArray
,
ckActualObjectCount
);
}
jObjectHandleArray
=
ckULongArrayToJLongArray
(
env
,
ckpObjectHandleArray
,
ckActualObjectCount
);
free
(
ckpObjectHandleArray
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jObjectHandleArray
;
}
#endif
...
...
src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003
-2009
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -97,6 +97,10 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1OpenSession
#ifndef NO_CALLBACKS
if
(
jNotify
!=
NULL
)
{
notifyEncapsulation
=
(
NotifyEncapsulation
*
)
malloc
(
sizeof
(
NotifyEncapsulation
));
if
(
notifyEncapsulation
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0L
;
}
notifyEncapsulation
->
jApplicationData
=
(
jApplication
!=
NULL
)
?
(
*
env
)
->
NewGlobalRef
(
env
,
jApplication
)
:
NULL
;
...
...
@@ -118,7 +122,18 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1OpenSession
TRACE0
(
" ... "
);
rv
=
(
*
ckpFunctions
->
C_OpenSession
)(
ckSlotID
,
ckFlags
,
ckpApplication
,
ckNotify
,
&
ckSessionHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
0L
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
#ifndef NO_CALLBACKS
if
(
notifyEncapsulation
!=
NULL
)
{
if
(
notifyEncapsulation
->
jApplicationData
!=
NULL
)
{
(
*
env
)
->
DeleteGlobalRef
(
env
,
jApplication
);
}
(
*
env
)
->
DeleteGlobalRef
(
env
,
jNotify
);
free
(
notifyEncapsulation
);
}
#endif
/* NO_CALLBACKS */
return
0L
;
}
TRACE0
(
"got session"
);
TRACE1
(
", SessionHandle=%u"
,
ckSessionHandle
);
...
...
@@ -163,7 +178,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CloseSession
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
rv
=
(
*
ckpFunctions
->
C_CloseSession
)(
ckSessionHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
#ifndef NO_CALLBACKS
notifyEncapsulation
=
removeNotifyEntry
(
env
,
ckSessionHandle
);
...
...
@@ -208,7 +223,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CloseAllSessio
ckSlotID
=
jLongToCKULong
(
jSlotID
);
rv
=
(
*
ckpFunctions
->
C_CloseAllSessions
)(
ckSlotID
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
#ifndef NO_CALLBACKS
/* Remove all notify callback helper objects. */
...
...
@@ -250,10 +265,9 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSessionI
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
rv
=
(
*
ckpFunctions
->
C_GetSessionInfo
)(
ckSessionHandle
,
&
ckSessionInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
jSessionInfo
=
ckSessionInfoPtrToJSessionInfo
(
env
,
&
ckSessionInfo
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jSessionInfo
=
ckSessionInfoPtrToJSessionInfo
(
env
,
&
ckSessionInfo
);
}
return
jSessionInfo
;
}
#endif
...
...
@@ -274,7 +288,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetOpera
CK_SESSION_HANDLE
ckSessionHandle
;
CK_BYTE_PTR
ckpState
;
CK_ULONG
ckStateLength
;
jbyteArray
jState
;
jbyteArray
jState
=
NULL
;
CK_RV
rv
;
CK_FUNCTION_LIST_PTR
ckpFunctions
=
getFunctionList
(
env
,
obj
);
...
...
@@ -283,17 +297,20 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetOpera
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
rv
=
(
*
ckpFunctions
->
C_GetOperationState
)(
ckSessionHandle
,
NULL_PTR
,
&
ckStateLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
ckpState
=
(
CK_BYTE_PTR
)
malloc
(
ckStateLength
);
if
(
ckpState
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_GetOperationState
)(
ckSessionHandle
,
ckpState
,
&
ckStateLength
);
jState
=
ckByteArrayToJByteArray
(
env
,
ckpState
,
ckStateLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jState
=
ckByteArrayToJByteArray
(
env
,
ckpState
,
ckStateLength
);
}
free
(
ckpState
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jState
;
}
#endif
...
...
@@ -325,6 +342,8 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetOperationSt
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jOperationState
,
&
ckpState
,
&
ckStateLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
ckEncryptionKeyHandle
=
jLongToCKULong
(
jEncryptionKeyHandle
);
ckAuthenticationKeyHandle
=
jLongToCKULong
(
jAuthenticationKeyHandle
);
...
...
@@ -332,7 +351,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetOperationSt
free
(
ckpState
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -362,12 +381,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Login
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
ckUserType
=
jLongToCKULong
(
jUserType
);
jCharArrayToCKCharArray
(
env
,
jPin
,
&
ckpPinArray
,
&
ckPinLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
rv
=
(
*
ckpFunctions
->
C_Login
)(
ckSessionHandle
,
ckUserType
,
ckpPinArray
,
ckPinLength
);
free
(
ckpPinArray
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -391,7 +411,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Logout
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
rv
=
(
*
ckpFunctions
->
C_Logout
)(
ckSessionHandle
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -410,10 +430,14 @@ void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation
NotifyListNode
*
currentNode
,
*
newNode
;
if
(
notifyEncapsulation
==
NULL
)
{
return
;
return
;
}
newNode
=
(
NotifyListNode
*
)
malloc
(
sizeof
(
NotifyListNode
));
if
(
newNode
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
;
}
newNode
->
hSession
=
hSession
;
newNode
->
notifyEncapsulation
=
notifyEncapsulation
;
newNode
->
next
=
NULL
;
...
...
@@ -578,9 +602,10 @@ CK_RV notifyCallback(
jEvent
=
ckULongToJLong
(
event
);
ckNotifyClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_NOTIFY
);
assert
(
ckNotifyClass
!=
0
);
if
(
ckNotifyClass
==
NULL
)
{
return
rv
;
}
jmethod
=
(
*
env
)
->
GetMethodID
(
env
,
ckNotifyClass
,
"CK_NOTIFY"
,
"(JJLjava/lang/Object;)V"
);
assert
(
jmethod
!=
0
);
if
(
jmethod
==
NULL
)
{
return
rv
;
}
(
*
env
)
->
CallVoidMethod
(
env
,
notifyEncapsulation
->
jNotifyObject
,
jmethod
,
jSessionHandle
,
jEvent
,
notifyEncapsulation
->
jApplicationData
);
...
...
@@ -588,10 +613,14 @@ CK_RV notifyCallback(
pkcs11Exception
=
(
*
env
)
->
ExceptionOccurred
(
env
);
if
(
pkcs11Exception
!=
NULL
)
{
/* TBD: clear the pending exception with ExceptionClear? */
/* The was an exception thrown, now we get the error-code from it */
pkcs11ExceptionClass
=
(
*
env
)
->
FindClass
(
env
,
CLASS_PKCS11EXCEPTION
);
if
(
pkcs11ExceptionClass
==
NULL
)
{
return
rv
;
}
jmethod
=
(
*
env
)
->
GetMethodID
(
env
,
pkcs11ExceptionClass
,
"getErrorCode"
,
"()J"
);
assert
(
jmethod
!=
0
);
if
(
jmethod
==
NULL
)
{
return
rv
;
}
errorCode
=
(
*
env
)
->
CallLongMethod
(
env
,
pkcs11Exception
,
jmethod
);
rv
=
jLongToCKULong
(
errorCode
);
}
...
...
src/share/native/sun/security/pkcs11/wrapper/p11_sign.c
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003-200
5
Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003-200
9
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -77,15 +77,16 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignInit
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
rv
=
(
*
ckpFunctions
->
C_SignInit
)(
ckSessionHandle
,
&
ckMechanism
,
ckKeyHandle
);
if
(
ckMechanism
.
pParameter
!=
NULL_PTR
)
{
if
(
ckMechanism
.
pParameter
!=
NULL_PTR
)
{
free
(
ckMechanism
.
pParameter
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -117,14 +118,23 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jData
,
&
ckpData
,
&
ckDataLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
NULL
;
}
/* START standard code */
/* first determine the length of the signature */
rv
=
(
*
ckpFunctions
->
C_Sign
)(
ckSessionHandle
,
ckpData
,
ckDataLength
,
NULL_PTR
,
&
ckSignatureLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
free
(
ckpData
);
return
NULL
;
}
ckpSignature
=
(
CK_BYTE_PTR
)
malloc
(
ckSignatureLength
*
sizeof
(
CK_BYTE
));
if
(
ckpSignature
==
NULL
)
{
free
(
ckpData
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
/* now get the signature */
rv
=
(
*
ckpFunctions
->
C_Sign
)(
ckSessionHandle
,
ckpData
,
ckDataLength
,
ckpSignature
,
&
ckSignatureLength
);
...
...
@@ -134,22 +144,31 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign
/* START workaround code for operation abort bug in pkcs#11 of Datakey and iButton */
/*
ckpSignature = (CK_BYTE_PTR) malloc(256 * sizeof(CK_BYTE));
if (ckpSignature == NULL) {
free(ckpData);
JNU_ThrowOutOfMemoryError(env, 0);
return NULL;
}
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength);
if (rv == CKR_BUFFER_TOO_SMALL) {
free(ckpSignature);
ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * sizeof(CK_BYTE));
if (ckpSignature == NULL) {
free(ckpData);
JNU_ThrowOutOfMemoryError(env, 0);
return NULL;
}
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength);
}
*/
/* END workaround code */
jSignature
=
ckByteArrayToJByteArray
(
env
,
ckpSignature
,
ckSignatureLength
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jSignature
=
ckByteArrayToJByteArray
(
env
,
ckpSignature
,
ckSignatureLength
);
}
free
(
ckpData
);
free
(
ckpSignature
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
NULL
;
}
return
jSignature
;
}
#endif
...
...
@@ -189,14 +208,22 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate
bufP
=
BUF
;
}
else
{
bufLen
=
min
(
MAX_HEAP_BUFFER_LEN
,
jInLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
bufLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
bufLen
);
if
(
bufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
;
}
}
while
(
jInLen
>
0
)
{
jsize
chunkLen
=
min
(
bufLen
,
jInLen
);
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
chunkLen
,
(
jbyte
*
)
bufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
;
}
rv
=
(
*
ckpFunctions
->
C_SignUpdate
)(
ckSessionHandle
,
bufP
,
chunkLen
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
...
...
@@ -206,9 +233,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate
jInLen
-=
chunkLen
;
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
}
#endif
...
...
@@ -244,15 +269,18 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignFina
rv
=
(
*
ckpFunctions
->
C_SignFinal
)(
ckSessionHandle
,
bufP
,
&
ckSignatureLength
);
if
(
rv
==
CKR_BUFFER_TOO_SMALL
)
{
bufP
=
(
CK_BYTE_PTR
)
malloc
(
ckSignatureLength
);
if
(
bufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
NULL
;
}
rv
=
(
*
ckpFunctions
->
C_SignFinal
)(
ckSessionHandle
,
bufP
,
&
ckSignatureLength
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
jSignature
=
ckByteArrayToJByteArray
(
env
,
bufP
,
ckSignatureLength
);
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
jSignature
;
}
#endif
...
...
@@ -280,11 +308,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecoverIni
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
rv
=
(
*
ckpFunctions
->
C_SignRecoverInit
)(
ckSessionHandle
,
&
ckMechanism
,
ckKeyHandle
);
if
(
ckMechanism
.
pParameter
!=
NULL_PTR
)
{
if
(
ckMechanism
.
pParameter
!=
NULL_PTR
)
{
free
(
ckMechanism
.
pParameter
);
}
...
...
@@ -323,26 +353,38 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecover
if
(
jInLen
<=
MAX_STACK_BUFFER_LEN
)
{
inBufP
=
INBUF
;
}
else
{
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
inBufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
inBufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
return
0
;
}
rv
=
(
*
ckpFunctions
->
C_SignRecover
)(
ckSessionHandle
,
inBufP
,
jInLen
,
outBufP
,
&
ckSignatureLength
);
/* re-alloc larger buffer if it fits into our Java buffer */
if
((
rv
==
CKR_BUFFER_TOO_SMALL
)
&&
(
ckSignatureLength
<=
jIntToCKULong
(
jOutLen
)))
{
outBufP
=
(
CK_BYTE_PTR
)
malloc
(
ckSignatureLength
);
if
(
outBufP
==
NULL
)
{
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
rv
=
(
*
ckpFunctions
->
C_SignRecover
)(
ckSessionHandle
,
inBufP
,
jInLen
,
outBufP
,
&
ckSignatureLength
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
(
*
env
)
->
SetByteArrayRegion
(
env
,
jOut
,
jOutOfs
,
ckSignatureLength
,
(
jbyte
*
)
outBufP
);
}
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
if
(
outBufP
!=
OUTBUF
)
{
free
(
outBufP
);
}
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
if
(
outBufP
!=
OUTBUF
)
{
free
(
outBufP
);
}
return
ckSignatureLength
;
}
#endif
...
...
@@ -370,6 +412,8 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyInit
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
rv
=
(
*
ckpFunctions
->
C_VerifyInit
)(
ckSessionHandle
,
&
ckMechanism
,
ckKeyHandle
);
...
...
@@ -378,7 +422,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyInit
free
(
ckMechanism
.
pParameter
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -409,7 +453,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Verify
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jData
,
&
ckpData
,
&
ckDataLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
jByteArrayToCKByteArray
(
env
,
jSignature
,
&
ckpSignature
,
&
ckSignatureLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
free
(
ckpData
);
return
;
}
/* verify the signature */
rv
=
(
*
ckpFunctions
->
C_Verify
)(
ckSessionHandle
,
ckpData
,
ckDataLength
,
ckpSignature
,
ckSignatureLength
);
...
...
@@ -417,7 +467,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Verify
free
(
ckpData
);
free
(
ckpSignature
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -456,26 +506,31 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyUpdate
bufP
=
BUF
;
}
else
{
bufLen
=
min
(
MAX_HEAP_BUFFER_LEN
,
jInLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
bufLen
);
bufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
bufLen
);
if
(
bufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
;
}
}
while
(
jInLen
>
0
)
{
jsize
chunkLen
=
min
(
bufLen
,
jInLen
);
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
chunkLen
,
(
jbyte
*
)
bufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
;
}
rv
=
(
*
ckpFunctions
->
C_VerifyUpdate
)(
ckSessionHandle
,
bufP
,
chunkLen
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
return
;
}
jInOfs
+=
chunkLen
;
jInLen
-=
chunkLen
;
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
if
(
bufP
!=
BUF
)
{
free
(
bufP
);
}
}
#endif
...
...
@@ -502,13 +557,14 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyFinal
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jByteArrayToCKByteArray
(
env
,
jSignature
,
&
ckpSignature
,
&
ckSignatureLength
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
/* verify the signature */
rv
=
(
*
ckpFunctions
->
C_VerifyFinal
)(
ckSessionHandle
,
ckpSignature
,
ckSignatureLength
);
free
(
ckpSignature
);
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -535,15 +591,17 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecoverI
ckSessionHandle
=
jLongToCKULong
(
jSessionHandle
);
jMechanismToCKMechanism
(
env
,
jMechanism
,
&
ckMechanism
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
return
;
}
ckKeyHandle
=
jLongToCKULong
(
jKeyHandle
);
rv
=
(
*
ckpFunctions
->
C_VerifyRecoverInit
)(
ckSessionHandle
,
&
ckMechanism
,
ckKeyHandle
);
if
(
ckMechanism
.
pParameter
!=
NULL_PTR
)
{
if
(
ckMechanism
.
pParameter
!=
NULL_PTR
)
{
free
(
ckMechanism
.
pParameter
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
!=
CK_ASSERT_OK
)
{
return
;
}
}
#endif
...
...
@@ -578,26 +636,38 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecover
if
(
jInLen
<=
MAX_STACK_BUFFER_LEN
)
{
inBufP
=
INBUF
;
}
else
{
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
inBufP
=
(
CK_BYTE_PTR
)
malloc
((
size_t
)
jInLen
);
if
(
inBufP
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
}
(
*
env
)
->
GetByteArrayRegion
(
env
,
jIn
,
jInOfs
,
jInLen
,
(
jbyte
*
)
inBufP
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
return
0
;
}
rv
=
(
*
ckpFunctions
->
C_VerifyRecover
)(
ckSessionHandle
,
inBufP
,
jInLen
,
outBufP
,
&
ckDataLength
);
/* re-alloc larger buffer if it fits into our Java buffer */
if
((
rv
==
CKR_BUFFER_TOO_SMALL
)
&&
(
ckDataLength
<=
jIntToCKULong
(
jOutLen
)))
{
outBufP
=
(
CK_BYTE_PTR
)
malloc
(
ckDataLength
);
if
(
outBufP
==
NULL
)
{
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
JNU_ThrowOutOfMemoryError
(
env
,
0
);
return
0
;
}
rv
=
(
*
ckpFunctions
->
C_VerifyRecover
)(
ckSessionHandle
,
inBufP
,
jInLen
,
outBufP
,
&
ckDataLength
);
}
if
(
ckAssertReturnValueOK
(
env
,
rv
)
==
CK_ASSERT_OK
)
{
(
*
env
)
->
SetByteArrayRegion
(
env
,
jOut
,
jOutOfs
,
ckDataLength
,
(
jbyte
*
)
outBufP
);
}
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
if
(
outBufP
!=
OUTBUF
)
{
free
(
outBufP
);
}
if
(
inBufP
!=
INBUF
)
{
free
(
inBufP
);
}
if
(
outBufP
!=
OUTBUF
)
{
free
(
outBufP
);
}
return
ckDataLength
;
}
#endif
src/share/native/sun/security/pkcs11/wrapper/p11_util.c
浏览文件 @
26bc4f44
此差异已折叠。
点击以展开。
src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
浏览文件 @
26bc4f44
/*
* Portions Copyright 2003-200
6
Sun Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2003-200
9
Sun Microsystems, Inc. All Rights Reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
...
...
@@ -154,6 +154,7 @@
#include "pkcs11.h"
#include <jni.h>
#include <jni_util.h>
#define MAX_STACK_BUFFER_LEN (4 * 1024)
#define MAX_HEAP_BUFFER_LEN (64 * 1024)
...
...
@@ -277,12 +278,14 @@
*/
jlong
ckAssertReturnValueOK
(
JNIEnv
*
env
,
CK_RV
returnValue
);
void
throwPKCS11RuntimeException
(
JNIEnv
*
env
,
jstring
jmessage
);
void
throwFileNotFoundException
(
JNIEnv
*
env
,
jstring
jmessage
);
void
throwIOException
(
JNIEnv
*
env
,
const
char
*
message
);
void
throw
IOExceptionUnicodeMessage
(
JNIEnv
*
env
,
const
short
*
message
);
void
throw
PKCS11RuntimeException
(
JNIEnv
*
env
,
const
char
*
message
);
void
throwDisconnectedRuntimeException
(
JNIEnv
*
env
);
/* function to free CK_ATTRIBUTE array
*/
void
freeCKAttributeArray
(
CK_ATTRIBUTE_PTR
attrPtr
,
int
len
);
/* funktions to convert Java arrays to a CK-type array and the array length */
void
jBooleanArrayToCKBBoolArray
(
JNIEnv
*
env
,
const
jbooleanArray
jArray
,
CK_BBOOL
**
ckpArray
,
CK_ULONG_PTR
ckLength
);
...
...
@@ -438,3 +441,15 @@ extern jobject notifyListLock;
extern
jobject
jInitArgsObject
;
extern
CK_C_INITIALIZE_ARGS_PTR
ckpGlobalInitArgs
;
#endif
/* NO_CALLBACKS */
#ifdef P11_MEMORYDEBUG
#include <stdlib.h>
/* Simple malloc/free dumper */
void
*
p11malloc
(
size_t
c
,
char
*
file
,
int
line
);
void
p11free
(
void
*
p
,
char
*
file
,
int
line
);
#define malloc(c) (p11malloc((c), __FILE__, __LINE__))
#define free(c) (p11free((c), __FILE__, __LINE__))
#endif
test/java/security/Permission/ToString.java
0 → 100644
浏览文件 @
26bc4f44
/*
* Copyright 2009 Sun Microsystems, Inc. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6549506
* @summary Specification of Permission.toString() method contradicts with
* JDK implementation
*/
import
java.security.*
;
public
class
ToString
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
DummyWritePermission
dummyPerm
=
new
DummyWritePermission
();
NullActionPermission
nullActionPerm
=
new
NullActionPermission
();
System
.
out
.
println
(
dummyPerm
.
toString
());
System
.
out
.
println
(
dummyPerm
.
getDescription
());
System
.
out
.
println
(
nullActionPerm
.
toString
());
System
.
out
.
println
(
nullActionPerm
.
getDescription
());
if
(!
dummyPerm
.
toString
().
equals
(
dummyPerm
.
getDescription
()))
{
throw
new
Exception
(
"The expected permission.toString() is "
+
dummyPerm
.
getDescription
()
+
", but "
+
dummyPerm
.
toString
()
+
" returned!"
);
}
if
(!
nullActionPerm
.
toString
().
equals
(
nullActionPerm
.
getDescription
()))
{
throw
new
Exception
(
"The expected permission.toString() is "
+
nullActionPerm
.
getDescription
()
+
", but "
+
nullActionPerm
.
toString
()
+
" returned!"
);
}
}
private
static
abstract
class
SimplePermission
extends
Permission
{
public
SimplePermission
(
String
name
)
{
super
(
name
);
}
public
boolean
implies
(
Permission
permission
)
{
return
false
;
}
public
boolean
equals
(
Object
obj
)
{
return
false
;
}
public
int
hashCode
()
{
return
13
;
}
}
private
static
class
DummyWritePermission
extends
SimplePermission
{
public
DummyWritePermission
()
{
super
(
"permit to"
);
}
public
String
getActions
()
{
return
"write"
;
}
public
String
getDescription
()
{
return
"(\"ToString$DummyWritePermission\" \"permit to\" \"write\")"
;
}
}
private
static
class
NullActionPermission
extends
SimplePermission
{
public
NullActionPermission
()
{
super
(
"permit to"
);
}
public
String
getActions
()
{
return
null
;
}
public
String
getDescription
()
{
return
"(\"ToString$NullActionPermission\" \"permit to\")"
;
}
}
}
test/java/util/zip/ZipFile/LargeZipFile.java
浏览文件 @
26bc4f44
/*
* Copyright 2009 Sun Microsystems, Inc. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import
java.io.*
;
import
java.nio.*
;
import
java.util.*
;
...
...
test/sun/security/tools/keytool/NoExtNPE.sh
0 → 100644
浏览文件 @
26bc4f44
#
# Copyright 2009 Sun Microsystems, Inc. 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
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# @test
# @bug 6813402
# @summary keytool cannot -printcert entries without extensions
#
# @run shell NoExtNPE.sh
# set a few environment variables so that the shell-script can run stand-alone
# in the source directory
if
[
"
${
TESTSRC
}
"
=
""
]
;
then
TESTSRC
=
"."
fi
if
[
"
${
TESTJAVA
}
"
=
""
]
;
then
echo
"TESTJAVA not set. Test cannot execute."
echo
"FAILED!!!"
exit
1
fi
# set platform-dependent variables
OS
=
`
uname
-s
`
case
"
$OS
"
in
SunOS
)
FILESEP
=
"/"
;;
Linux
)
FILESEP
=
"/"
;;
Windows
*
)
FILESEP
=
"
\\
"
;;
*
)
echo
"Unrecognized system!"
exit
1
;
;;
esac
${
TESTJAVA
}${
FILESEP
}
bin
${
FILESEP
}
keytool
\
-list
-v
\
-keystore
${
TESTSRC
}${
FILESEP
}
CloneKeyAskPassword.jks
\
-storepass
test123
exit
$?
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录