Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java
41159 views
1
/*
2
* Copyright (c) 1999, 2021, 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
23
* questions.
24
*/
25
26
package sun.security.ssl;
27
28
import java.util.List;
29
import java.util.Collections;
30
31
import java.security.*;
32
import java.security.KeyStore.*;
33
34
import javax.net.ssl.*;
35
36
abstract class KeyManagerFactoryImpl extends KeyManagerFactorySpi {
37
38
X509ExtendedKeyManager keyManager;
39
boolean isInitialized;
40
41
KeyManagerFactoryImpl() {
42
// empty
43
}
44
45
/**
46
* Returns one key manager for each type of key material.
47
*/
48
@Override
49
protected KeyManager[] engineGetKeyManagers() {
50
if (!isInitialized) {
51
throw new IllegalStateException(
52
"KeyManagerFactoryImpl is not initialized");
53
}
54
return new KeyManager[] { keyManager };
55
}
56
57
// Factory for the SunX509 keymanager
58
public static final class SunX509 extends KeyManagerFactoryImpl {
59
60
@Override
61
protected void engineInit(KeyStore ks, char[] password) throws
62
KeyStoreException, NoSuchAlgorithmException,
63
UnrecoverableKeyException {
64
keyManager = new SunX509KeyManagerImpl(ks, password);
65
isInitialized = true;
66
}
67
68
@Override
69
protected void engineInit(ManagerFactoryParameters spec) throws
70
InvalidAlgorithmParameterException {
71
throw new InvalidAlgorithmParameterException(
72
"SunX509KeyManager does not use ManagerFactoryParameters");
73
}
74
75
}
76
77
// Factory for the X509 keymanager
78
public static final class X509 extends KeyManagerFactoryImpl {
79
80
@Override
81
protected void engineInit(KeyStore ks, char[] password) throws
82
KeyStoreException, NoSuchAlgorithmException,
83
UnrecoverableKeyException {
84
if (ks == null) {
85
keyManager = new X509KeyManagerImpl(
86
Collections.<Builder>emptyList());
87
} else {
88
try {
89
Builder builder = Builder.newInstance(ks,
90
new PasswordProtection(password));
91
keyManager = new X509KeyManagerImpl(builder);
92
} catch (RuntimeException e) {
93
throw new KeyStoreException("initialization failed", e);
94
}
95
}
96
isInitialized = true;
97
}
98
99
@Override
100
protected void engineInit(ManagerFactoryParameters params) throws
101
InvalidAlgorithmParameterException {
102
if (!(params instanceof KeyStoreBuilderParameters)) {
103
throw new InvalidAlgorithmParameterException(
104
"Parameters must be instance of KeyStoreBuilderParameters");
105
}
106
107
List<Builder> builders =
108
((KeyStoreBuilderParameters)params).getParameters();
109
keyManager = new X509KeyManagerImpl(builders);
110
isInitialized = true;
111
}
112
113
}
114
115
}
116
117