author | mbalao |
Wed, 12 Sep 2018 13:09:51 +0200 | |
changeset 51800 | bccd9966f1ed |
parent 47216 | 71c04702a3d5 |
child 55332 | f492567244ab |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
*/ |
4 |
||
5 |
/* Copyright (c) 2002 Graz University of Technology. All rights reserved. |
|
6 |
* |
|
7 |
* Redistribution and use in source and binary forms, with or without |
|
8 |
* modification, are permitted provided that the following conditions are met: |
|
9 |
* |
|
10 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
11 |
* this list of conditions and the following disclaimer. |
|
12 |
* |
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer in the documentation |
|
15 |
* and/or other materials provided with the distribution. |
|
16 |
* |
|
17 |
* 3. The end-user documentation included with the redistribution, if any, must |
|
18 |
* include the following acknowledgment: |
|
19 |
* |
|
20 |
* "This product includes software developed by IAIK of Graz University of |
|
21 |
* Technology." |
|
22 |
* |
|
23 |
* Alternately, this acknowledgment may appear in the software itself, if |
|
24 |
* and wherever such third-party acknowledgments normally appear. |
|
25 |
* |
|
26 |
* 4. The names "Graz University of Technology" and "IAIK of Graz University of |
|
27 |
* Technology" must not be used to endorse or promote products derived from |
|
28 |
* this software without prior written permission. |
|
29 |
* |
|
30 |
* 5. Products derived from this software may not be called |
|
31 |
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior |
|
32 |
* written permission of Graz University of Technology. |
|
33 |
* |
|
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
|
35 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
36 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
37 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE |
|
38 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
39 |
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
40 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
|
41 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
42 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
43 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
45 |
* POSSIBILITY OF SUCH DAMAGE. |
|
46 |
*/ |
|
47 |
||
48 |
package sun.security.pkcs11.wrapper; |
|
49 |
||
50 |
import java.math.BigInteger; |
|
8542 | 51 |
import static sun.security.pkcs11.wrapper.PKCS11Constants.*; |
2 | 52 |
|
53 |
/** |
|
54 |
* class CK_MECHANISM specifies a particular mechanism and any parameters it |
|
55 |
* requires.<p> |
|
56 |
* <B>PKCS#11 structure:</B> |
|
57 |
* <PRE> |
|
58 |
* typedef struct CK_MECHANISM { |
|
59 |
* CK_MECHANISM_TYPE mechanism; |
|
60 |
* CK_VOID_PTR pParameter; |
|
61 |
* CK_ULONG ulParameterLen; |
|
62 |
* } CK_MECHANISM; |
|
63 |
* </PRE> |
|
64 |
* |
|
65 |
* @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at> |
|
66 |
* @author Martin Schlaeffer <schlaeff@sbox.tugraz.at> |
|
67 |
*/ |
|
68 |
public class CK_MECHANISM { |
|
69 |
||
70 |
/** |
|
71 |
* <B>PKCS#11:</B> |
|
72 |
* <PRE> |
|
73 |
* CK_MECHANISM_TYPE mechanism; |
|
74 |
* </PRE> |
|
75 |
*/ |
|
76 |
public long mechanism; |
|
77 |
||
78 |
/** |
|
79 |
* <B>PKCS#11:</B> |
|
80 |
* <PRE> |
|
81 |
* CK_VOID_PTR pParameter; |
|
82 |
* CK_ULONG ulParameterLen; |
|
83 |
* </PRE> |
|
84 |
*/ |
|
85 |
public Object pParameter; |
|
86 |
||
87 |
public CK_MECHANISM() { |
|
88 |
// empty |
|
89 |
} |
|
90 |
||
91 |
public CK_MECHANISM(long mechanism) { |
|
92 |
this.mechanism = mechanism; |
|
93 |
} |
|
94 |
||
95 |
// We don't have a (long,Object) constructor to force type checking. |
|
96 |
// This makes sure we don't accidentally pass a class that the native |
|
97 |
// code cannot handle. |
|
98 |
||
99 |
public CK_MECHANISM(long mechanism, byte[] pParameter) { |
|
100 |
init(mechanism, pParameter); |
|
101 |
} |
|
102 |
||
103 |
public CK_MECHANISM(long mechanism, BigInteger b) { |
|
104 |
init(mechanism, sun.security.pkcs11.P11Util.getMagnitude(b)); |
|
105 |
} |
|
106 |
||
107 |
public CK_MECHANISM(long mechanism, CK_VERSION version) { |
|
108 |
init(mechanism, version); |
|
109 |
} |
|
110 |
||
111 |
public CK_MECHANISM(long mechanism, CK_SSL3_MASTER_KEY_DERIVE_PARAMS params) { |
|
112 |
init(mechanism, params); |
|
113 |
} |
|
114 |
||
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
115 |
public CK_MECHANISM(long mechanism, CK_TLS12_MASTER_KEY_DERIVE_PARAMS params) { |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
116 |
init(mechanism, params); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
117 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
118 |
|
2 | 119 |
public CK_MECHANISM(long mechanism, CK_SSL3_KEY_MAT_PARAMS params) { |
120 |
init(mechanism, params); |
|
121 |
} |
|
122 |
||
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
123 |
public CK_MECHANISM(long mechanism, CK_TLS12_KEY_MAT_PARAMS params) { |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
124 |
init(mechanism, params); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
125 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
126 |
|
2 | 127 |
public CK_MECHANISM(long mechanism, CK_TLS_PRF_PARAMS params) { |
128 |
init(mechanism, params); |
|
129 |
} |
|
130 |
||
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
131 |
public CK_MECHANISM(long mechanism, CK_TLS_MAC_PARAMS params) { |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
132 |
init(mechanism, params); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
133 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
134 |
|
2 | 135 |
public CK_MECHANISM(long mechanism, CK_ECDH1_DERIVE_PARAMS params) { |
136 |
init(mechanism, params); |
|
137 |
} |
|
138 |
||
139 |
public CK_MECHANISM(long mechanism, Long params) { |
|
140 |
init(mechanism, params); |
|
141 |
} |
|
142 |
||
8542 | 143 |
public CK_MECHANISM(long mechanism, CK_AES_CTR_PARAMS params) { |
144 |
init(mechanism, params); |
|
145 |
} |
|
146 |
||
2 | 147 |
private void init(long mechanism, Object pParameter) { |
148 |
this.mechanism = mechanism; |
|
149 |
this.pParameter = pParameter; |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Returns the string representation of CK_MECHANISM. |
|
154 |
* |
|
155 |
* @return the string representation of CK_MECHANISM |
|
156 |
*/ |
|
157 |
public String toString() { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
158 |
StringBuilder sb = new StringBuilder(); |
2 | 159 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
160 |
sb.append(Constants.INDENT); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
161 |
sb.append("mechanism: "); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
162 |
sb.append(mechanism); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
163 |
sb.append(Constants.NEWLINE); |
2 | 164 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
165 |
sb.append(Constants.INDENT); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
166 |
sb.append("pParameter: "); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
167 |
sb.append(pParameter.toString()); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
168 |
sb.append(Constants.NEWLINE); |
2 | 169 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
170 |
sb.append(Constants.INDENT); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
171 |
sb.append("ulParameterLen: ??"); |
2 | 172 |
//buffer.append(pParameter.length); |
173 |
//buffer.append(Constants.NEWLINE); |
|
174 |
||
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
8542
diff
changeset
|
175 |
return sb.toString() ; |
2 | 176 |
} |
177 |
||
178 |
} |