-
Notifications
You must be signed in to change notification settings - Fork 361
/
CertificateIdentityResult.java
213 lines (199 loc) · 6.82 KB
/
CertificateIdentityResult.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*******************************************************************************
* Copyright (c) 2021 Bosch.IO GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Bosch.IO GmbH - initial creation
******************************************************************************/
package org.eclipse.californium.scandium.dtls;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.List;
import org.eclipse.californium.scandium.auth.ApplicationLevelInfoSupplier;
import org.eclipse.californium.scandium.dtls.x509.CertificateProvider;
/**
* Result of certificate identity provider.
*
* @see CertificateProvider
* @since 3.0
*/
public final class CertificateIdentityResult extends HandshakeResult {
private final PrivateKey privateKey;
private final PublicKey publicKey;
private final List<X509Certificate> certificateChain;
/**
* Create result with {@link X509Certificate}.
*
* @param cid connection id
* @param privateKey private key of identity.
* @param certificateChain certificate chain for identity
* @param customArgument custom argument. May be {@code null}. Passed to
* {@link ApplicationLevelInfoSupplier} by the
* {@link Handshaker}, if a {@link ApplicationLevelInfoSupplier}
* is available.
* @throws NullPointerException if cid, private key, or chain is
* {@code null}.
* @throws IllegalArgumentException if chain is empty.
* @deprecated obsolete, customArgument is not used
*/
@Deprecated
public CertificateIdentityResult(ConnectionId cid, PrivateKey privateKey, List<X509Certificate> certificateChain,
Object customArgument) {
super(cid, customArgument);
if (privateKey == null) {
throw new NullPointerException("Private key must not be null!");
}
if (certificateChain == null) {
throw new NullPointerException("Certificate chain must not be null!");
}
if (certificateChain.isEmpty()) {
throw new IllegalArgumentException("Certificate chain must not be empty!");
}
this.privateKey = privateKey;
this.publicKey = certificateChain.get(0).getPublicKey();
this.certificateChain = certificateChain;
}
/**
* Create result with RawPublicKey.
*
* @param cid connection id
* @param privateKey private key of identity.
* @param publicKey public key for identity
* @param customArgument custom argument. May be {@code null}. Passed to
* {@link ApplicationLevelInfoSupplier} by the
* {@link Handshaker}, if a {@link ApplicationLevelInfoSupplier}
* is available.
* @throws NullPointerException if cid, private key, or public key is
* {@code null}.
* @deprecated obsolete, customArgument is not used
*/
@Deprecated
public CertificateIdentityResult(ConnectionId cid, PrivateKey privateKey, PublicKey publicKey,
Object customArgument) {
super(cid, customArgument);
if (privateKey == null) {
throw new NullPointerException("Private key must not be null!");
}
if (publicKey == null) {
throw new NullPointerException("Public key must not be null!");
}
this.privateKey = privateKey;
this.publicKey = publicKey;
this.certificateChain = null;
}
/**
* Create result without matching identity.
*
* @param cid connection id
* @param customArgument custom argument. May be {@code null}. Passed to
* {@link ApplicationLevelInfoSupplier} by the
* {@link Handshaker}, if a {@link ApplicationLevelInfoSupplier}
* is available.
* @throws NullPointerException if cid is {@code null}.
* @deprecated obsolete, customArgument is not used
*/
@Deprecated
public CertificateIdentityResult(ConnectionId cid, Object customArgument) {
super(cid, customArgument);
this.privateKey = null;
this.publicKey = null;
this.certificateChain = null;
}
/**
* Create result with {@link X509Certificate}.
*
* @param cid connection id
* @param privateKey private key of identity.
* @param certificateChain certificate chain for identity
* @throws NullPointerException if cid, private key, or chain is
* {@code null}.
* @throws IllegalArgumentException if chain is empty.
* @since 3.12
*/
public CertificateIdentityResult(ConnectionId cid, PrivateKey privateKey, List<X509Certificate> certificateChain) {
super(cid, null);
if (privateKey == null) {
throw new NullPointerException("Private key must not be null!");
}
if (certificateChain == null) {
throw new NullPointerException("Certificate chain must not be null!");
}
if (certificateChain.isEmpty()) {
throw new IllegalArgumentException("Certificate chain must not be empty!");
}
this.privateKey = privateKey;
this.publicKey = certificateChain.get(0).getPublicKey();
this.certificateChain = certificateChain;
}
/**
* Create result with RawPublicKey.
*
* @param cid connection id
* @param privateKey private key of identity.
* @param publicKey public key for identity
* @throws NullPointerException if cid, private key, or public key is
* {@code null}.
* @since 3.12
*/
public CertificateIdentityResult(ConnectionId cid, PrivateKey privateKey, PublicKey publicKey) {
super(cid, null);
if (privateKey == null) {
throw new NullPointerException("Private key must not be null!");
}
if (publicKey == null) {
throw new NullPointerException("Public key must not be null!");
}
this.privateKey = privateKey;
this.publicKey = publicKey;
this.certificateChain = null;
}
/**
* Create result without matching identity.
*
* @param cid connection id
* @throws NullPointerException if cid is {@code null}.
* @since 3.12
*/
public CertificateIdentityResult(ConnectionId cid) {
super(cid, null);
this.privateKey = null;
this.publicKey = null;
this.certificateChain = null;
}
/**
* Get private key of certificate based identity
*
* @return private key, or {@code null}, if no matching identity is
* available.
*/
public PrivateKey getPrivateKey() {
return privateKey;
}
/**
* Get public key of certificate based identity
*
* @return public key, or {@code null}, if no matching identity is
* available.
*/
public PublicKey getPublicKey() {
return publicKey;
}
/**
* Get certificate chain of x509 based identity
*
* @return certificate chain, or {@code null}, if no x509 identity is
* available or used.
*/
public List<X509Certificate> getCertificateChain() {
return certificateChain;
}
}