author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 55530 | 6aa047de311b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2 | 4 |
* |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
15 |
* accompanied this code). |
2 | 16 |
* |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
20 |
* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
23 |
* questions. |
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.pkcs11.wrapper; |
|
27 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
28 |
import java.security.ProviderException; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
29 |
import java.security.spec.PSSParameterSpec; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
30 |
import java.security.spec.MGF1ParameterSpec; |
2 | 31 |
|
32 |
||
33 |
/** |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
34 |
* This class represents the necessary parameters required by the |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
35 |
* CKM_RSA_PKCS_PSS mechanism as defined in CK_RSA_PKCS_PSS_PARAMS structure.<p> |
2 | 36 |
* <B>PKCS#11 structure:</B> |
37 |
* <PRE> |
|
38 |
* typedef struct CK_RSA_PKCS_PSS_PARAMS { |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
39 |
* CK_MECHANISM_TYPE hashAlg; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
40 |
* CK_RSA_PKCS_MGF_TYPE mgf; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
41 |
* CK_ULONG sLen; |
2 | 42 |
* } CK_RSA_PKCS_PSS_PARAMS; |
43 |
* </PRE> |
|
44 |
* |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
45 |
* @since 13 |
2 | 46 |
*/ |
47 |
public class CK_RSA_PKCS_PSS_PARAMS { |
|
48 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
49 |
private final long hashAlg; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
50 |
private final long mgf; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
51 |
private final long sLen; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
52 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
53 |
public CK_RSA_PKCS_PSS_PARAMS(String hashAlg, String mgfAlg, |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
54 |
String mgfHash, int sLen) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
55 |
this.hashAlg = Functions.getHashMechId(hashAlg); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
56 |
if (!mgfAlg.equals("MGF1")) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
57 |
throw new ProviderException("Only MGF1 is supported"); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
58 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
59 |
// no dash in PKCS#11 mechanism names |
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
60 |
this.mgf = Functions.getMGFId("CKG_MGF1_" + mgfHash.replaceFirst("-", "")); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
61 |
this.sLen = sLen; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
62 |
} |
2 | 63 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
64 |
@Override |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
65 |
public boolean equals(Object o) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
66 |
if (o == this) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
67 |
return true; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
68 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
69 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
70 |
if (!(o instanceof CK_RSA_PKCS_PSS_PARAMS)) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
71 |
return false; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
72 |
} |
2 | 73 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
74 |
CK_RSA_PKCS_PSS_PARAMS other = (CK_RSA_PKCS_PSS_PARAMS) o; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
75 |
return ((other.hashAlg == hashAlg) && |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
76 |
(other.mgf == mgf) && |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
77 |
(other.sLen == sLen)); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
78 |
} |
2 | 79 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
80 |
@Override |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
81 |
public int hashCode() { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
82 |
return (int)(hashAlg << 2 + mgf << 1 + sLen); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
83 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
84 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
85 |
@Override |
2 | 86 |
public String toString() { |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
87 |
StringBuilder sb = new StringBuilder(); |
2 | 88 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
89 |
sb.append(Constants.INDENT); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
90 |
sb.append("hashAlg: "); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
91 |
sb.append(Functions.toFullHexString(hashAlg)); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
92 |
sb.append(Constants.NEWLINE); |
2 | 93 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
94 |
sb.append(Constants.INDENT); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
95 |
sb.append("mgf: "); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
96 |
sb.append(Functions.toFullHexString(mgf)); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
97 |
sb.append(Constants.NEWLINE); |
2 | 98 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
99 |
sb.append(Constants.INDENT); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
100 |
sb.append("sLen(in bytes): "); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
101 |
sb.append(sLen); |
2 | 102 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
103 |
return sb.toString(); |
2 | 104 |
} |
105 |
} |