1 /*
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
46 * <p>This class supports the CKM_TLS_PRF mechanism from PKCS#11 v2.20 and
47 * the older NSS private mechanism.
48 *
49 * @author Andreas Sterbenz
50 * @since 1.6
51 */
52 final class P11TlsPrfGenerator extends KeyGeneratorSpi {
53
54 private final static String MSG =
55 "TlsPrfGenerator must be initialized using a TlsPrfParameterSpec";
56
57 // token instance
58 private final Token token;
59
60 // algorithm name
61 private final String algorithm;
62
63 // mechanism id
64 private final long mechanism;
65
66 private TlsPrfParameterSpec spec;
67
68 private P11Key p11Key;
69
70 P11TlsPrfGenerator(Token token, String algorithm, long mechanism)
71 throws PKCS11Exception {
72 super();
73 this.token = token;
74 this.algorithm = algorithm;
75 this.mechanism = mechanism;
76 }
77
78 protected void engineInit(SecureRandom random) {
79 throw new InvalidParameterException(MSG);
80 }
81
82 protected void engineInit(AlgorithmParameterSpec params,
83 SecureRandom random) throws InvalidAlgorithmParameterException {
84 if (params instanceof TlsPrfParameterSpec == false) {
85 throw new InvalidAlgorithmParameterException(MSG);
86 }
87 this.spec = (TlsPrfParameterSpec)params;
88 SecretKey key = spec.getSecret();
89 if (key == null) {
90 key = NULL_KEY;
91 }
92 try {
93 p11Key = P11SecretKeyFactory.convertKey(token, key, null);
94 } catch (InvalidKeyException e) {
95 throw new InvalidAlgorithmParameterException("init() failed", e);
96 }
97 }
98
99 // SecretKeySpec does not allow zero length keys, so we define our
100 // own class.
101 //
|
1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
46 * <p>This class supports the CKM_TLS_PRF mechanism from PKCS#11 v2.20 and
47 * the older NSS private mechanism.
48 *
49 * @author Andreas Sterbenz
50 * @since 1.6
51 */
52 final class P11TlsPrfGenerator extends KeyGeneratorSpi {
53
54 private final static String MSG =
55 "TlsPrfGenerator must be initialized using a TlsPrfParameterSpec";
56
57 // token instance
58 private final Token token;
59
60 // algorithm name
61 private final String algorithm;
62
63 // mechanism id
64 private final long mechanism;
65
66 @SuppressWarnings("deprecation")
67 private TlsPrfParameterSpec spec;
68
69 private P11Key p11Key;
70
71 P11TlsPrfGenerator(Token token, String algorithm, long mechanism)
72 throws PKCS11Exception {
73 super();
74 this.token = token;
75 this.algorithm = algorithm;
76 this.mechanism = mechanism;
77 }
78
79 protected void engineInit(SecureRandom random) {
80 throw new InvalidParameterException(MSG);
81 }
82
83 @SuppressWarnings("deprecation")
84 protected void engineInit(AlgorithmParameterSpec params,
85 SecureRandom random) throws InvalidAlgorithmParameterException {
86 if (params instanceof TlsPrfParameterSpec == false) {
87 throw new InvalidAlgorithmParameterException(MSG);
88 }
89 this.spec = (TlsPrfParameterSpec)params;
90 SecretKey key = spec.getSecret();
91 if (key == null) {
92 key = NULL_KEY;
93 }
94 try {
95 p11Key = P11SecretKeyFactory.convertKey(token, key, null);
96 } catch (InvalidKeyException e) {
97 throw new InvalidAlgorithmParameterException("init() failed", e);
98 }
99 }
100
101 // SecretKeySpec does not allow zero length keys, so we define our
102 // own class.
103 //
|