author | chegar |
Mon, 14 Dec 2015 19:24:33 +0000 | |
changeset 34687 | d302ed125dc9 |
parent 32032 | 22badc53802f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
32032 | 2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.provider.certpath; |
|
27 |
||
28 |
import java.io.IOException; |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
29 |
import java.security.cert.Extension; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
30 |
import java.util.Collections; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
31 |
import java.util.List; |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
32 |
|
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
32032
diff
changeset
|
33 |
import sun.security.util.HexDumpEncoder; |
2 | 34 |
import sun.security.util.*; |
32032 | 35 |
import sun.security.x509.PKIXExtensions; |
2 | 36 |
|
37 |
/** |
|
38 |
* This class can be used to generate an OCSP request and send it over |
|
32032 | 39 |
* an output stream. Currently we do not support signing requests. |
2 | 40 |
* The OCSP Request is specified in RFC 2560 and |
41 |
* the ASN.1 definition is as follows: |
|
42 |
* <pre> |
|
43 |
* |
|
44 |
* OCSPRequest ::= SEQUENCE { |
|
45 |
* tbsRequest TBSRequest, |
|
46 |
* optionalSignature [0] EXPLICIT Signature OPTIONAL } |
|
47 |
* |
|
48 |
* TBSRequest ::= SEQUENCE { |
|
49 |
* version [0] EXPLICIT Version DEFAULT v1, |
|
50 |
* requestorName [1] EXPLICIT GeneralName OPTIONAL, |
|
51 |
* requestList SEQUENCE OF Request, |
|
52 |
* requestExtensions [2] EXPLICIT Extensions OPTIONAL } |
|
53 |
* |
|
54 |
* Signature ::= SEQUENCE { |
|
55 |
* signatureAlgorithm AlgorithmIdentifier, |
|
56 |
* signature BIT STRING, |
|
57 |
* certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL |
|
58 |
* } |
|
59 |
* |
|
60 |
* Version ::= INTEGER { v1(0) } |
|
61 |
* |
|
62 |
* Request ::= SEQUENCE { |
|
63 |
* reqCert CertID, |
|
64 |
* singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } |
|
65 |
* |
|
66 |
* CertID ::= SEQUENCE { |
|
67 |
* hashAlgorithm AlgorithmIdentifier, |
|
68 |
* issuerNameHash OCTET STRING, -- Hash of Issuer's DN |
|
69 |
* issuerKeyHash OCTET STRING, -- Hash of Issuers public key |
|
70 |
* serialNumber CertificateSerialNumber |
|
71 |
* } |
|
72 |
* |
|
73 |
* </pre> |
|
74 |
* |
|
75 |
* @author Ram Marti |
|
76 |
*/ |
|
77 |
||
78 |
class OCSPRequest { |
|
79 |
||
21819
8cd757e836d8
8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents:
12860
diff
changeset
|
80 |
private static final Debug debug = Debug.getInstance("certpath"); |
8cd757e836d8
8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents:
12860
diff
changeset
|
81 |
private static final boolean dump = debug != null && Debug.isOn("ocsp"); |
2 | 82 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
83 |
// List of request CertIds |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
84 |
private final List<CertId> certIds; |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
85 |
private final List<Extension> extensions; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
86 |
private byte[] nonce; |
2 | 87 |
|
88 |
/* |
|
89 |
* Constructs an OCSPRequest. This constructor is used |
|
90 |
* to construct an unsigned OCSP Request for a single user cert. |
|
91 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
92 |
OCSPRequest(CertId certId) { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
93 |
this(Collections.singletonList(certId)); |
2 | 94 |
} |
95 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
96 |
OCSPRequest(List<CertId> certIds) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
97 |
this.certIds = certIds; |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
98 |
this.extensions = Collections.<Extension>emptyList(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
99 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
100 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
101 |
OCSPRequest(List<CertId> certIds, List<Extension> extensions) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
102 |
this.certIds = certIds; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
103 |
this.extensions = extensions; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
104 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
105 |
|
2 | 106 |
byte[] encodeBytes() throws IOException { |
107 |
||
108 |
// encode tbsRequest |
|
109 |
DerOutputStream tmp = new DerOutputStream(); |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
110 |
DerOutputStream requestsOut = new DerOutputStream(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
111 |
for (CertId certId : certIds) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
112 |
DerOutputStream certIdOut = new DerOutputStream(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
113 |
certId.encode(certIdOut); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
114 |
requestsOut.write(DerValue.tag_Sequence, certIdOut); |
2 | 115 |
} |
116 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
117 |
tmp.write(DerValue.tag_Sequence, requestsOut); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
118 |
if (!extensions.isEmpty()) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
119 |
DerOutputStream extOut = new DerOutputStream(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
120 |
for (Extension ext : extensions) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
121 |
ext.encode(extOut); |
32032 | 122 |
if (ext.getId().equals( |
123 |
PKIXExtensions.OCSPNonce_Id.toString())) { |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
124 |
nonce = ext.getValue(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
125 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
126 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
127 |
DerOutputStream extsOut = new DerOutputStream(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
128 |
extsOut.write(DerValue.tag_Sequence, extOut); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
129 |
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
130 |
true, (byte)2), extsOut); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
131 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
132 |
|
2 | 133 |
DerOutputStream tbsRequest = new DerOutputStream(); |
134 |
tbsRequest.write(DerValue.tag_Sequence, tmp); |
|
135 |
||
136 |
// OCSPRequest without the signature |
|
137 |
DerOutputStream ocspRequest = new DerOutputStream(); |
|
138 |
ocspRequest.write(DerValue.tag_Sequence, tbsRequest); |
|
139 |
||
140 |
byte[] bytes = ocspRequest.toByteArray(); |
|
141 |
||
142 |
if (dump) { |
|
143 |
HexDumpEncoder hexEnc = new HexDumpEncoder(); |
|
21819
8cd757e836d8
8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents:
12860
diff
changeset
|
144 |
debug.println("OCSPRequest bytes...\n\n" + |
8cd757e836d8
8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents:
12860
diff
changeset
|
145 |
hexEnc.encode(bytes) + "\n"); |
2 | 146 |
} |
147 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
148 |
return bytes; |
2 | 149 |
} |
150 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
151 |
List<CertId> getCertIds() { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
2
diff
changeset
|
152 |
return certIds; |
2 | 153 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
154 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
155 |
byte[] getNonce() { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
156 |
return nonce; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
5506
diff
changeset
|
157 |
} |
2 | 158 |
} |