feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
181
jdkSrc/jdk8/sun/security/timestamp/HttpTimestamper.java
Normal file
181
jdkSrc/jdk8/sun/security/timestamp/HttpTimestamper.java
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.security.timestamp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.*;
|
||||
|
||||
import sun.misc.IOUtils;
|
||||
import sun.security.util.Debug;
|
||||
|
||||
/**
|
||||
* A timestamper that communicates with a Timestamping Authority (TSA)
|
||||
* over HTTP.
|
||||
* It supports the Time-Stamp Protocol defined in:
|
||||
* <a href="http://www.ietf.org/rfc/rfc3161.txt">RFC 3161</a>.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Vincent Ryan
|
||||
*/
|
||||
|
||||
public class HttpTimestamper implements Timestamper {
|
||||
|
||||
private static final int CONNECT_TIMEOUT = 15000; // 15 seconds
|
||||
|
||||
// The MIME type for a timestamp query
|
||||
private static final String TS_QUERY_MIME_TYPE =
|
||||
"application/timestamp-query";
|
||||
|
||||
// The MIME type for a timestamp reply
|
||||
private static final String TS_REPLY_MIME_TYPE =
|
||||
"application/timestamp-reply";
|
||||
|
||||
private static final Debug debug = Debug.getInstance("ts");
|
||||
|
||||
/*
|
||||
* HTTP URI identifying the location of the TSA
|
||||
*/
|
||||
private URI tsaURI = null;
|
||||
|
||||
/**
|
||||
* Creates a timestamper that connects to the specified TSA.
|
||||
*
|
||||
* @param tsa The location of the TSA. It must be an HTTP or HTTPS URI.
|
||||
* @throws IllegalArgumentException if tsaURI is not an HTTP or HTTPS URI
|
||||
*/
|
||||
public HttpTimestamper(URI tsaURI) {
|
||||
if (!tsaURI.getScheme().equalsIgnoreCase("http") &&
|
||||
!tsaURI.getScheme().equalsIgnoreCase("https")) {
|
||||
throw new IllegalArgumentException(
|
||||
"TSA must be an HTTP or HTTPS URI");
|
||||
}
|
||||
this.tsaURI = tsaURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the TSA and requests a timestamp.
|
||||
*
|
||||
* @param tsQuery The timestamp query.
|
||||
* @return The result of the timestamp query.
|
||||
* @throws IOException The exception is thrown if a problem occurs while
|
||||
* communicating with the TSA.
|
||||
*/
|
||||
public TSResponse generateTimestamp(TSRequest tsQuery) throws IOException {
|
||||
|
||||
HttpURLConnection connection =
|
||||
(HttpURLConnection) tsaURI.toURL().openConnection();
|
||||
connection.setDoOutput(true);
|
||||
connection.setUseCaches(false); // ignore cache
|
||||
connection.setRequestProperty("Content-Type", TS_QUERY_MIME_TYPE);
|
||||
connection.setRequestMethod("POST");
|
||||
// Avoids the "hang" when a proxy is required but none has been set.
|
||||
connection.setConnectTimeout(CONNECT_TIMEOUT);
|
||||
|
||||
if (debug != null) {
|
||||
Set<Map.Entry<String, List<String>>> headers =
|
||||
connection.getRequestProperties().entrySet();
|
||||
debug.println(connection.getRequestMethod() + " " + tsaURI +
|
||||
" HTTP/1.1");
|
||||
for (Map.Entry<String, List<String>> e : headers) {
|
||||
debug.println(" " + e);
|
||||
}
|
||||
debug.println();
|
||||
}
|
||||
connection.connect(); // No HTTP authentication is performed
|
||||
|
||||
// Send the request
|
||||
DataOutputStream output = null;
|
||||
try {
|
||||
output = new DataOutputStream(connection.getOutputStream());
|
||||
byte[] request = tsQuery.encode();
|
||||
output.write(request, 0, request.length);
|
||||
output.flush();
|
||||
if (debug != null) {
|
||||
debug.println("sent timestamp query (length=" +
|
||||
request.length + ")");
|
||||
}
|
||||
} finally {
|
||||
if (output != null) {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Receive the reply
|
||||
BufferedInputStream input = null;
|
||||
byte[] replyBuffer = null;
|
||||
try {
|
||||
input = new BufferedInputStream(connection.getInputStream());
|
||||
if (debug != null) {
|
||||
String header = connection.getHeaderField(0);
|
||||
debug.println(header);
|
||||
int i = 1;
|
||||
while ((header = connection.getHeaderField(i)) != null) {
|
||||
String key = connection.getHeaderFieldKey(i);
|
||||
debug.println(" " + ((key==null) ? "" : key + ": ") +
|
||||
header);
|
||||
i++;
|
||||
}
|
||||
debug.println();
|
||||
}
|
||||
verifyMimeType(connection.getContentType());
|
||||
|
||||
int clen = connection.getContentLength();
|
||||
replyBuffer = IOUtils.readAllBytes(input);
|
||||
if (clen != -1 && replyBuffer.length != clen)
|
||||
throw new EOFException("Expected:" + clen +
|
||||
", read:" + replyBuffer.length);
|
||||
|
||||
if (debug != null) {
|
||||
debug.println("received timestamp response (length=" +
|
||||
replyBuffer.length + ")");
|
||||
}
|
||||
} finally {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
return new TSResponse(replyBuffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that the MIME content type is a timestamp reply.
|
||||
*
|
||||
* @param contentType The MIME content type to be checked.
|
||||
* @throws IOException The exception is thrown if a mismatch occurs.
|
||||
*/
|
||||
private static void verifyMimeType(String contentType) throws IOException {
|
||||
if (! TS_REPLY_MIME_TYPE.equalsIgnoreCase(contentType)) {
|
||||
throw new IOException("MIME Content-Type is not " +
|
||||
TS_REPLY_MIME_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
179
jdkSrc/jdk8/sun/security/timestamp/TSRequest.java
Normal file
179
jdkSrc/jdk8/sun/security/timestamp/TSRequest.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.security.timestamp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Extension;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.DerOutputStream;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
import sun.security.x509.AlgorithmId;
|
||||
|
||||
/**
|
||||
* This class provides a timestamp request, as defined in
|
||||
* <a href="http://www.ietf.org/rfc/rfc3161.txt">RFC 3161</a>.
|
||||
*
|
||||
* The TimeStampReq ASN.1 type has the following definition:
|
||||
* <pre>
|
||||
*
|
||||
* TimeStampReq ::= SEQUENCE {
|
||||
* version INTEGER { v1(1) },
|
||||
* messageImprint MessageImprint
|
||||
* -- a hash algorithm OID and the hash value of the data to be
|
||||
* -- time-stamped.
|
||||
* reqPolicy TSAPolicyId OPTIONAL,
|
||||
* nonce INTEGER OPTIONAL,
|
||||
* certReq BOOLEAN DEFAULT FALSE,
|
||||
* extensions [0] IMPLICIT Extensions OPTIONAL }
|
||||
*
|
||||
* MessageImprint ::= SEQUENCE {
|
||||
* hashAlgorithm AlgorithmIdentifier,
|
||||
* hashedMessage OCTET STRING }
|
||||
*
|
||||
* TSAPolicyId ::= OBJECT IDENTIFIER
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Vincent Ryan
|
||||
* @see Timestamper
|
||||
*/
|
||||
|
||||
public class TSRequest {
|
||||
|
||||
private int version = 1;
|
||||
|
||||
private AlgorithmId hashAlgorithmId = null;
|
||||
|
||||
private byte[] hashValue;
|
||||
|
||||
private String policyId = null;
|
||||
|
||||
private BigInteger nonce = null;
|
||||
|
||||
private boolean returnCertificate = false;
|
||||
|
||||
private X509Extension[] extensions = null;
|
||||
|
||||
/**
|
||||
* Constructs a timestamp request for the supplied data.
|
||||
*
|
||||
* @param toBeTimeStamped The data to be timestamped.
|
||||
* @param messageDigest The MessageDigest of the hash algorithm to use.
|
||||
* @throws NoSuchAlgorithmException if the hash algorithm is not supported
|
||||
*/
|
||||
public TSRequest(String tSAPolicyID, byte[] toBeTimeStamped, MessageDigest messageDigest)
|
||||
throws NoSuchAlgorithmException {
|
||||
|
||||
this.policyId = tSAPolicyID;
|
||||
this.hashAlgorithmId = AlgorithmId.get(messageDigest.getAlgorithm());
|
||||
this.hashValue = messageDigest.digest(toBeTimeStamped);
|
||||
}
|
||||
|
||||
public byte[] getHashedMessage() {
|
||||
return hashValue.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Time-Stamp Protocol version.
|
||||
*
|
||||
* @param version The TSP version.
|
||||
*/
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an object identifier for the Time-Stamp Protocol policy.
|
||||
*
|
||||
* @param version The policy object identifier.
|
||||
*/
|
||||
public void setPolicyId(String policyId) {
|
||||
this.policyId = policyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a nonce.
|
||||
* A nonce is a single-use random number.
|
||||
*
|
||||
* @param nonce The nonce value.
|
||||
*/
|
||||
public void setNonce(BigInteger nonce) {
|
||||
this.nonce = nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the TSA include its signing certificate in the response.
|
||||
*
|
||||
* @param returnCertificate True if the TSA should return its signing
|
||||
* certificate. By default it is not returned.
|
||||
*/
|
||||
public void requestCertificate(boolean returnCertificate) {
|
||||
this.returnCertificate = returnCertificate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Time-Stamp Protocol extensions.
|
||||
*
|
||||
* @param extensions The protocol extensions.
|
||||
*/
|
||||
public void setExtensions(X509Extension[] extensions) {
|
||||
this.extensions = extensions;
|
||||
}
|
||||
|
||||
public byte[] encode() throws IOException {
|
||||
|
||||
DerOutputStream request = new DerOutputStream();
|
||||
|
||||
// encode version
|
||||
request.putInteger(version);
|
||||
|
||||
// encode messageImprint
|
||||
DerOutputStream messageImprint = new DerOutputStream();
|
||||
hashAlgorithmId.encode(messageImprint);
|
||||
messageImprint.putOctetString(hashValue);
|
||||
request.write(DerValue.tag_Sequence, messageImprint);
|
||||
|
||||
// encode optional elements
|
||||
|
||||
if (policyId != null) {
|
||||
request.putOID(new ObjectIdentifier(policyId));
|
||||
}
|
||||
if (nonce != null) {
|
||||
request.putInteger(nonce);
|
||||
}
|
||||
if (returnCertificate) {
|
||||
request.putBoolean(true);
|
||||
}
|
||||
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
out.write(DerValue.tag_Sequence, request);
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
384
jdkSrc/jdk8/sun/security/timestamp/TSResponse.java
Normal file
384
jdkSrc/jdk8/sun/security/timestamp/TSResponse.java
Normal file
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.security.timestamp;
|
||||
|
||||
import java.io.IOException;
|
||||
import sun.security.pkcs.PKCS7;
|
||||
import sun.security.util.Debug;
|
||||
import sun.security.util.DerValue;
|
||||
|
||||
/**
|
||||
* This class provides the response corresponding to a timestamp request,
|
||||
* as defined in
|
||||
* <a href="http://www.ietf.org/rfc/rfc3161.txt">RFC 3161</a>.
|
||||
*
|
||||
* The TimeStampResp ASN.1 type has the following definition:
|
||||
* <pre>
|
||||
*
|
||||
* TimeStampResp ::= SEQUENCE {
|
||||
* status PKIStatusInfo,
|
||||
* timeStampToken TimeStampToken OPTIONAL ]
|
||||
*
|
||||
* PKIStatusInfo ::= SEQUENCE {
|
||||
* status PKIStatus,
|
||||
* statusString PKIFreeText OPTIONAL,
|
||||
* failInfo PKIFailureInfo OPTIONAL }
|
||||
*
|
||||
* PKIStatus ::= INTEGER {
|
||||
* granted (0),
|
||||
* -- when the PKIStatus contains the value zero a TimeStampToken, as
|
||||
* -- requested, is present.
|
||||
* grantedWithMods (1),
|
||||
* -- when the PKIStatus contains the value one a TimeStampToken,
|
||||
* -- with modifications, is present.
|
||||
* rejection (2),
|
||||
* waiting (3),
|
||||
* revocationWarning (4),
|
||||
* -- this message contains a warning that a revocation is
|
||||
* -- imminent
|
||||
* revocationNotification (5)
|
||||
* -- notification that a revocation has occurred }
|
||||
*
|
||||
* PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
|
||||
* -- text encoded as UTF-8 String (note: each UTF8String SHOULD
|
||||
* -- include an RFC 1766 language tag to indicate the language
|
||||
* -- of the contained text)
|
||||
*
|
||||
* PKIFailureInfo ::= BIT STRING {
|
||||
* badAlg (0),
|
||||
* -- unrecognized or unsupported Algorithm Identifier
|
||||
* badRequest (2),
|
||||
* -- transaction not permitted or supported
|
||||
* badDataFormat (5),
|
||||
* -- the data submitted has the wrong format
|
||||
* timeNotAvailable (14),
|
||||
* -- the TSA's time source is not available
|
||||
* unacceptedPolicy (15),
|
||||
* -- the requested TSA policy is not supported by the TSA
|
||||
* unacceptedExtension (16),
|
||||
* -- the requested extension is not supported by the TSA
|
||||
* addInfoNotAvailable (17)
|
||||
* -- the additional information requested could not be understood
|
||||
* -- or is not available
|
||||
* systemFailure (25)
|
||||
* -- the request cannot be handled due to system failure }
|
||||
*
|
||||
* TimeStampToken ::= ContentInfo
|
||||
* -- contentType is id-signedData
|
||||
* -- content is SignedData
|
||||
* -- eContentType within SignedData is id-ct-TSTInfo
|
||||
* -- eContent within SignedData is TSTInfo
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Vincent Ryan
|
||||
* @see Timestamper
|
||||
*/
|
||||
|
||||
public class TSResponse {
|
||||
|
||||
// Status codes (from RFC 3161)
|
||||
|
||||
/**
|
||||
* The requested timestamp was granted.
|
||||
*/
|
||||
public static final int GRANTED = 0;
|
||||
|
||||
/**
|
||||
* The requested timestamp was granted with some modifications.
|
||||
*/
|
||||
public static final int GRANTED_WITH_MODS = 1;
|
||||
|
||||
/**
|
||||
* The requested timestamp was not granted.
|
||||
*/
|
||||
public static final int REJECTION = 2;
|
||||
|
||||
/**
|
||||
* The requested timestamp has not yet been processed.
|
||||
*/
|
||||
public static final int WAITING = 3;
|
||||
|
||||
/**
|
||||
* A warning that a certificate revocation is imminent.
|
||||
*/
|
||||
public static final int REVOCATION_WARNING = 4;
|
||||
|
||||
/**
|
||||
* Notification that a certificate revocation has occurred.
|
||||
*/
|
||||
public static final int REVOCATION_NOTIFICATION = 5;
|
||||
|
||||
// Failure codes (from RFC 3161)
|
||||
|
||||
/**
|
||||
* Unrecognized or unsupported algorithm identifier.
|
||||
*/
|
||||
public static final int BAD_ALG = 0;
|
||||
|
||||
/**
|
||||
* The requested transaction is not permitted or supported.
|
||||
*/
|
||||
public static final int BAD_REQUEST = 2;
|
||||
|
||||
/**
|
||||
* The data submitted has the wrong format.
|
||||
*/
|
||||
public static final int BAD_DATA_FORMAT = 5;
|
||||
|
||||
/**
|
||||
* The TSA's time source is not available.
|
||||
*/
|
||||
public static final int TIME_NOT_AVAILABLE = 14;
|
||||
|
||||
/**
|
||||
* The requested TSA policy is not supported by the TSA.
|
||||
*/
|
||||
public static final int UNACCEPTED_POLICY = 15;
|
||||
|
||||
/**
|
||||
* The requested extension is not supported by the TSA.
|
||||
*/
|
||||
public static final int UNACCEPTED_EXTENSION = 16;
|
||||
|
||||
/**
|
||||
* The additional information requested could not be understood or is not
|
||||
* available.
|
||||
*/
|
||||
public static final int ADD_INFO_NOT_AVAILABLE = 17;
|
||||
|
||||
/**
|
||||
* The request cannot be handled due to system failure.
|
||||
*/
|
||||
public static final int SYSTEM_FAILURE = 25;
|
||||
|
||||
private static final Debug debug = Debug.getInstance("ts");
|
||||
|
||||
private int status;
|
||||
|
||||
private String[] statusString = null;
|
||||
|
||||
private boolean[] failureInfo = null;
|
||||
|
||||
private byte[] encodedTsToken = null;
|
||||
|
||||
private PKCS7 tsToken = null;
|
||||
|
||||
private TimestampToken tstInfo;
|
||||
|
||||
/**
|
||||
* Constructs an object to store the response to a timestamp request.
|
||||
*
|
||||
* @param status A buffer containing the ASN.1 BER encoded response.
|
||||
* @throws IOException The exception is thrown if a problem is encountered
|
||||
* parsing the timestamp response.
|
||||
*/
|
||||
TSResponse(byte[] tsReply) throws IOException {
|
||||
parse(tsReply);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the status code returned by the TSA.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the status messages returned by the TSA.
|
||||
*
|
||||
* @return If null then no status messages were received.
|
||||
*/
|
||||
public String[] getStatusMessages() {
|
||||
return statusString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the failure info returned by the TSA.
|
||||
*
|
||||
* @return the failure info, or null if no failure code was received.
|
||||
*/
|
||||
public boolean[] getFailureInfo() {
|
||||
return failureInfo;
|
||||
}
|
||||
|
||||
public String getStatusCodeAsText() {
|
||||
|
||||
switch (status) {
|
||||
case GRANTED:
|
||||
return "the timestamp request was granted.";
|
||||
|
||||
case GRANTED_WITH_MODS:
|
||||
return
|
||||
"the timestamp request was granted with some modifications.";
|
||||
|
||||
case REJECTION:
|
||||
return "the timestamp request was rejected.";
|
||||
|
||||
case WAITING:
|
||||
return "the timestamp request has not yet been processed.";
|
||||
|
||||
case REVOCATION_WARNING:
|
||||
return "warning: a certificate revocation is imminent.";
|
||||
|
||||
case REVOCATION_NOTIFICATION:
|
||||
return "notification: a certificate revocation has occurred.";
|
||||
|
||||
default:
|
||||
return ("unknown status code " + status + ".");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSet(int position) {
|
||||
return failureInfo[position];
|
||||
}
|
||||
|
||||
public String getFailureCodeAsText() {
|
||||
|
||||
if (failureInfo == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
if (isSet(BAD_ALG))
|
||||
return "Unrecognized or unsupported algorithm identifier.";
|
||||
if (isSet(BAD_REQUEST))
|
||||
return "The requested transaction is not permitted or " +
|
||||
"supported.";
|
||||
if (isSet(BAD_DATA_FORMAT))
|
||||
return "The data submitted has the wrong format.";
|
||||
if (isSet(TIME_NOT_AVAILABLE))
|
||||
return "The TSA's time source is not available.";
|
||||
if (isSet(UNACCEPTED_POLICY))
|
||||
return "The requested TSA policy is not supported by the TSA.";
|
||||
if (isSet(UNACCEPTED_EXTENSION))
|
||||
return "The requested extension is not supported by the TSA.";
|
||||
if (isSet(ADD_INFO_NOT_AVAILABLE))
|
||||
return "The additional information requested could not be " +
|
||||
"understood or is not available.";
|
||||
if (isSet(SYSTEM_FAILURE))
|
||||
return "The request cannot be handled due to system failure.";
|
||||
} catch (ArrayIndexOutOfBoundsException ex) {}
|
||||
|
||||
return ("unknown failure code");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the timestamp token returned by the TSA.
|
||||
*
|
||||
* @return If null then no token was received.
|
||||
*/
|
||||
public PKCS7 getToken() {
|
||||
return tsToken;
|
||||
}
|
||||
|
||||
public TimestampToken getTimestampToken() {
|
||||
return tstInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the ASN.1 BER encoded timestamp token returned by the TSA.
|
||||
*
|
||||
* @return If null then no token was received.
|
||||
*/
|
||||
public byte[] getEncodedToken() {
|
||||
return encodedTsToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses the timestamp response.
|
||||
*
|
||||
* @param status A buffer containing the ASN.1 BER encoded response.
|
||||
* @throws IOException The exception is thrown if a problem is encountered
|
||||
* parsing the timestamp response.
|
||||
*/
|
||||
private void parse(byte[] tsReply) throws IOException {
|
||||
// Decode TimeStampResp
|
||||
|
||||
DerValue derValue = new DerValue(tsReply);
|
||||
if (derValue.tag != DerValue.tag_Sequence) {
|
||||
throw new IOException("Bad encoding for timestamp response");
|
||||
}
|
||||
|
||||
// Parse status
|
||||
|
||||
DerValue statusInfo = derValue.data.getDerValue();
|
||||
this.status = statusInfo.data.getInteger();
|
||||
if (debug != null) {
|
||||
debug.println("timestamp response: status=" + this.status);
|
||||
}
|
||||
// Parse statusString, if present
|
||||
if (statusInfo.data.available() > 0) {
|
||||
byte tag = (byte)statusInfo.data.peekByte();
|
||||
if (tag == DerValue.tag_SequenceOf) {
|
||||
DerValue[] strings = statusInfo.data.getSequence(1);
|
||||
statusString = new String[strings.length];
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
statusString[i] = strings[i].getUTF8String();
|
||||
if (debug != null) {
|
||||
debug.println("timestamp response: statusString=" +
|
||||
statusString[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Parse failInfo, if present
|
||||
if (statusInfo.data.available() > 0) {
|
||||
this.failureInfo
|
||||
= statusInfo.data.getUnalignedBitString().toBooleanArray();
|
||||
}
|
||||
|
||||
// Parse timeStampToken, if present
|
||||
if (derValue.data.available() > 0) {
|
||||
DerValue timestampToken = derValue.data.getDerValue();
|
||||
encodedTsToken = timestampToken.toByteArray();
|
||||
tsToken = new PKCS7(encodedTsToken);
|
||||
tstInfo = new TimestampToken(tsToken.getContentInfo().getData());
|
||||
}
|
||||
|
||||
// Check the format of the timestamp response
|
||||
if (this.status == 0 || this.status == 1) {
|
||||
if (tsToken == null) {
|
||||
throw new TimestampException(
|
||||
"Bad encoding for timestamp response: " +
|
||||
"expected a timeStampToken element to be present");
|
||||
}
|
||||
} else if (tsToken != null) {
|
||||
throw new TimestampException(
|
||||
"Bad encoding for timestamp response: " +
|
||||
"expected no timeStampToken element to be present");
|
||||
}
|
||||
}
|
||||
|
||||
final static class TimestampException extends IOException {
|
||||
private static final long serialVersionUID = -1631631794891940953L;
|
||||
|
||||
TimestampException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
172
jdkSrc/jdk8/sun/security/timestamp/TimestampToken.java
Normal file
172
jdkSrc/jdk8/sun/security/timestamp/TimestampToken.java
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.security.timestamp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
import sun.security.x509.AlgorithmId;
|
||||
|
||||
/**
|
||||
* This class provides the timestamp token info resulting from a successful
|
||||
* timestamp request, as defined in
|
||||
* <a href="http://www.ietf.org/rfc/rfc3161.txt">RFC 3161</a>.
|
||||
*
|
||||
* The timestampTokenInfo ASN.1 type has the following definition:
|
||||
* <pre>
|
||||
*
|
||||
* TSTInfo ::= SEQUENCE {
|
||||
* version INTEGER { v1(1) },
|
||||
* policy TSAPolicyId,
|
||||
* messageImprint MessageImprint,
|
||||
* -- MUST have the same value as the similar field in
|
||||
* -- TimeStampReq
|
||||
* serialNumber INTEGER,
|
||||
* -- Time-Stamping users MUST be ready to accommodate integers
|
||||
* -- up to 160 bits.
|
||||
* genTime GeneralizedTime,
|
||||
* accuracy Accuracy OPTIONAL,
|
||||
* ordering BOOLEAN DEFAULT FALSE,
|
||||
* nonce INTEGER OPTIONAL,
|
||||
* -- MUST be present if the similar field was present
|
||||
* -- in TimeStampReq. In that case it MUST have the same value.
|
||||
* tsa [0] GeneralName OPTIONAL,
|
||||
* extensions [1] IMPLICIT Extensions OPTIONAL }
|
||||
*
|
||||
* Accuracy ::= SEQUENCE {
|
||||
* seconds INTEGER OPTIONAL,
|
||||
* millis [0] INTEGER (1..999) OPTIONAL,
|
||||
* micros [1] INTEGER (1..999) OPTIONAL }
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.5
|
||||
* @see Timestamper
|
||||
* @author Vincent Ryan
|
||||
*/
|
||||
|
||||
public class TimestampToken {
|
||||
|
||||
private int version;
|
||||
private ObjectIdentifier policy;
|
||||
private BigInteger serialNumber;
|
||||
private AlgorithmId hashAlgorithm;
|
||||
private byte[] hashedMessage;
|
||||
private Date genTime;
|
||||
private BigInteger nonce;
|
||||
|
||||
/**
|
||||
* Constructs an object to store a timestamp token.
|
||||
*
|
||||
* @param status A buffer containing the ASN.1 BER encoding of the
|
||||
* TSTInfo element defined in RFC 3161.
|
||||
*/
|
||||
public TimestampToken(byte[] timestampTokenInfo) throws IOException {
|
||||
if (timestampTokenInfo == null) {
|
||||
throw new IOException("No timestamp token info");
|
||||
}
|
||||
parse(timestampTokenInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the date and time from the timestamp token.
|
||||
*
|
||||
* @return The date and time when the timestamp was generated.
|
||||
*/
|
||||
public Date getDate() {
|
||||
return genTime;
|
||||
}
|
||||
|
||||
public AlgorithmId getHashAlgorithm() {
|
||||
return hashAlgorithm;
|
||||
}
|
||||
|
||||
// should only be used internally, otherwise return a clone
|
||||
public byte[] getHashedMessage() {
|
||||
return hashedMessage;
|
||||
}
|
||||
|
||||
public BigInteger getNonce() {
|
||||
return nonce;
|
||||
}
|
||||
|
||||
public String getPolicyID() {
|
||||
return policy.toString();
|
||||
}
|
||||
|
||||
public BigInteger getSerialNumber() {
|
||||
return serialNumber;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses the timestamp token info.
|
||||
*
|
||||
* @param timestampTokenInfo A buffer containing an ASN.1 BER encoded
|
||||
* TSTInfo.
|
||||
* @throws IOException The exception is thrown if a problem is encountered
|
||||
* while parsing.
|
||||
*/
|
||||
private void parse(byte[] timestampTokenInfo) throws IOException {
|
||||
|
||||
DerValue tstInfo = new DerValue(timestampTokenInfo);
|
||||
if (tstInfo.tag != DerValue.tag_Sequence) {
|
||||
throw new IOException("Bad encoding for timestamp token info");
|
||||
}
|
||||
// Parse version
|
||||
version = tstInfo.data.getInteger();
|
||||
|
||||
// Parse policy
|
||||
policy = tstInfo.data.getOID();
|
||||
|
||||
// Parse messageImprint
|
||||
DerValue messageImprint = tstInfo.data.getDerValue();
|
||||
hashAlgorithm = AlgorithmId.parse(messageImprint.data.getDerValue());
|
||||
hashedMessage = messageImprint.data.getOctetString();
|
||||
|
||||
// Parse serialNumber
|
||||
serialNumber = tstInfo.data.getBigInteger();
|
||||
|
||||
// Parse genTime
|
||||
genTime = tstInfo.data.getGeneralizedTime();
|
||||
|
||||
// Parse optional elements, if present
|
||||
while (tstInfo.data.available() > 0) {
|
||||
DerValue d = tstInfo.data.getDerValue();
|
||||
if (d.tag == DerValue.tag_Integer) { // must be the nonce
|
||||
nonce = d.getBigInteger();
|
||||
break;
|
||||
}
|
||||
|
||||
// Additional fields:
|
||||
// Parse accuracy
|
||||
// Parse ordering
|
||||
// Parse tsa
|
||||
// Parse extensions
|
||||
}
|
||||
}
|
||||
}
|
||||
52
jdkSrc/jdk8/sun/security/timestamp/Timestamper.java
Normal file
52
jdkSrc/jdk8/sun/security/timestamp/Timestamper.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.security.timestamp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A timestamping service which conforms to the Time-Stamp Protocol (TSP)
|
||||
* defined in:
|
||||
* <a href="http://www.ietf.org/rfc/rfc3161.txt">RFC 3161</a>.
|
||||
* Individual timestampers may communicate with a Timestamping Authority (TSA)
|
||||
* over different transport machanisms. TSP permits at least the following
|
||||
* transports: HTTP, Internet mail, file-based and socket-based.
|
||||
*
|
||||
* @author Vincent Ryan
|
||||
* @see HttpTimestamper
|
||||
*/
|
||||
public interface Timestamper {
|
||||
|
||||
/*
|
||||
* Connects to the TSA and requests a timestamp.
|
||||
*
|
||||
* @param tsQuery The timestamp query.
|
||||
* @return The result of the timestamp query.
|
||||
* @throws IOException The exception is thrown if a problem occurs while
|
||||
* communicating with the TSA.
|
||||
*/
|
||||
public TSResponse generateTimestamp(TSRequest tsQuery) throws IOException;
|
||||
}
|
||||
Reference in New Issue
Block a user