History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/security/provider/certpath/OCSPRequest.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/provider/certpath/OCSPRequest.java+129−0
@@ -0,0 +1,129 @@
1/*
2 * Copyright (c) 2003, 2009, 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
26package sun.security.provider.certpath;
27
28import java.io.IOException;
29import java.util.Collections;
30import java.util.List;
31import sun.misc.HexDumpEncoder;
32import sun.security.util.*;
33
34/**
35 * This class can be used to generate an OCSP request and send it over
36 * an outputstream. Currently we do not support signing requests
37 * The OCSP Request is specified in RFC 2560 and
38 * the ASN.1 definition is as follows:
39 * <pre>
40 *
41 * OCSPRequest ::= SEQUENCE {
42 * tbsRequest TBSRequest,
43 * optionalSignature [0] EXPLICIT Signature OPTIONAL }
44 *
45 * TBSRequest ::= SEQUENCE {
46 * version [0] EXPLICIT Version DEFAULT v1,
47 * requestorName [1] EXPLICIT GeneralName OPTIONAL,
48 * requestList SEQUENCE OF Request,
49 * requestExtensions [2] EXPLICIT Extensions OPTIONAL }
50 *
51 * Signature ::= SEQUENCE {
52 * signatureAlgorithm AlgorithmIdentifier,
53 * signature BIT STRING,
54 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL
55 * }
56 *
57 * Version ::= INTEGER { v1(0) }
58 *
59 * Request ::= SEQUENCE {
60 * reqCert CertID,
61 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL }
62 *
63 * CertID ::= SEQUENCE {
64 * hashAlgorithm AlgorithmIdentifier,
65 * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
66 * issuerKeyHash OCTET STRING, -- Hash of Issuers public key
67 * serialNumber CertificateSerialNumber
68 * }
69 *
70 * </pre>
71 *
72 * @author Ram Marti
73 */
74
75class OCSPRequest {
76
77 private static final Debug debug = Debug.getInstance("certpath");
78 private static final boolean dump = false;
79
80 // List of request CertIds
81 private final List<CertId> certIds;
82
83 /*
84 * Constructs an OCSPRequest. This constructor is used
85 * to construct an unsigned OCSP Request for a single user cert.
86 */
87 OCSPRequest(CertId certId) {
88 this.certIds = Collections.singletonList(certId);
89 }
90
91 OCSPRequest(List<CertId> certIds) {
92 this.certIds = certIds;
93 }
94
95 byte[] encodeBytes() throws IOException {
96
97 // encode tbsRequest
98 DerOutputStream tmp = new DerOutputStream();
99 DerOutputStream requestsOut = new DerOutputStream();
100 for (CertId certId : certIds) {
101 DerOutputStream certIdOut = new DerOutputStream();
102 certId.encode(certIdOut);
103 requestsOut.write(DerValue.tag_Sequence, certIdOut);
104 }
105
106 tmp.write(DerValue.tag_Sequence, requestsOut);
107 // No extensions supported
108 DerOutputStream tbsRequest = new DerOutputStream();
109 tbsRequest.write(DerValue.tag_Sequence, tmp);
110
111 // OCSPRequest without the signature
112 DerOutputStream ocspRequest = new DerOutputStream();
113 ocspRequest.write(DerValue.tag_Sequence, tbsRequest);
114
115 byte[] bytes = ocspRequest.toByteArray();
116
117 if (dump) {
118 HexDumpEncoder hexEnc = new HexDumpEncoder();
119 System.out.println("OCSPRequest bytes are... ");
120 System.out.println(hexEnc.encode(bytes));
121 }
122
123 return bytes;
124 }
125
126 List<CertId> getCertIds() {
127 return certIds;
128 }
129}