Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java (revision 0) @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import java.math.BigInteger; +import java.util.List; + +import org.apache.harmony.security.asn1.ASN1BitString; +import org.apache.harmony.security.asn1.ASN1Integer; +import org.apache.harmony.security.asn1.ASN1Sequence; +import org.apache.harmony.security.asn1.ASN1SequenceOf; +import org.apache.harmony.security.asn1.ASN1StringType; +import org.apache.harmony.security.asn1.ASN1Type; +import org.apache.harmony.security.asn1.BerInputStream; +import org.apache.harmony.security.asn1.BitString; + + +/** + * As defined in Time-Stamp Protocol (TSP) + * (http://www.ietf.org/rfc/rfc3161.txt) + * + * PKIStatusInfo ::= SEQUENCE { + * status PKIStatus, + * statusString PKIFreeText OPTIONAL, + * failInfo PKIFailureInfo OPTIONAL + * } + * + */ +public class PKIStatusInfo { + + private final PKIStatus status; + + private final List statusString; + + private final PKIFailureInfo failInfo; + + public PKIStatusInfo(PKIStatus pKIStatus, List statusString, + PKIFailureInfo failInfo) { + this.status = pKIStatus; + this.statusString = statusString; + this.failInfo = failInfo; + } + + public String toString(){ + StringBuffer res = new StringBuffer(); + res.append("-- PKIStatusInfo:"); + res.append("\nPKIStatus : "); + res.append(status); + res.append("\nstatusString: "); + res.append(statusString); + res.append("\nfailInfo: "); + res.append(failInfo); + res.append("\n-- PKIStatusInfo End\n"); + return res.toString(); + } + + /** + * @return Returns the failInfo. + */ + public PKIFailureInfo getFailInfo() { + return failInfo; + } + + /** + * @return Returns the pKIStatus. + */ + public PKIStatus getStatus() { + return status; + } + + /** + * @return Returns the statusString. + */ + public List getStatusString() { + return statusString; + } + + public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { + ASN1Integer.getInstance(), // status + new ASN1SequenceOf(ASN1StringType.UTF8STRING), // statusString + ASN1BitString.getInstance() }) { // failInfo + { + setOptional(1); + setOptional(2); + } + + protected void getValues(Object object, Object[] values) { + PKIStatusInfo psi = (PKIStatusInfo) object; + values[0] = BigInteger.valueOf(psi.status.getStatus()) + .toByteArray(); + values[1] = psi.statusString; + if (psi.failInfo != null) { + // set the needed bit in the bit string + boolean[] failInfoBoolArray = new boolean[PKIFailureInfo + .getMaxValue()]; + failInfoBoolArray[psi.failInfo.getValue()] = true; + values[2] = new BitString(failInfoBoolArray); + } else { + values[2] = null; + } + } + + protected Object getDecodedObject(BerInputStream in) { + Object[] values = (Object[]) in.content; + + int failInfoValue = -1; + if (values[2] != null) { + boolean[] failInfoBoolArray = (values[2] == null) ? null + : ((BitString) values[2]).toBooleanArray(); + for (int i = 0; i < failInfoBoolArray.length; i++) { + if (failInfoBoolArray[i]) { + failInfoValue = i; + break; + } + } + } + return new PKIStatusInfo( + PKIStatus.getInstance(ASN1Integer.toIntValue(values[0])), + (List)values[1], + PKIFailureInfo.getInstance(failInfoValue)); + } + }; +} + Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java (revision 0) @@ -0,0 +1,306 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import java.math.BigInteger; +import java.util.Date; + +import org.apache.harmony.security.asn1.ASN1Boolean; +import org.apache.harmony.security.asn1.ASN1Explicit; +import org.apache.harmony.security.asn1.ASN1GeneralizedTime; +import org.apache.harmony.security.asn1.ASN1Implicit; +import org.apache.harmony.security.asn1.ASN1Integer; +import org.apache.harmony.security.asn1.ASN1Oid; +import org.apache.harmony.security.asn1.ASN1Sequence; +import org.apache.harmony.security.asn1.ASN1Type; +import org.apache.harmony.security.asn1.BerInputStream; +import org.apache.harmony.security.asn1.ObjectIdentifier; +import org.apache.harmony.security.internal.nls.Messages; +import org.apache.harmony.security.x509.Extensions; +import org.apache.harmony.security.x509.GeneralName; + +/** + * As defined in Time-Stamp Protocol (TSP) + * (http://www.ietf.org/rfc/rfc3161.txt) + * + * 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 + * } + * + * TSAPolicyId ::= OBJECT IDENTIFIER + * + * "tsa [0] GeneralName OPTIONAL" is EXPLICIT and the word EXPLICIT is omitted. + */ +public class TSTInfo { + + private final int version; + + private final String policy; + + private final MessageImprint messageImprint; + + private final BigInteger serialNumber; + + private final Date genTime; + + private final int [] accuracy; + + private final Boolean ordering; + + private final BigInteger nonce; + + private final GeneralName tsa; + + private final Extensions extensions; + + public TSTInfo(int version, String policy, MessageImprint messageImprint, + BigInteger serialNumber, Date genTime, int[] accuracy, + Boolean ordering, BigInteger nonce, GeneralName tsa, + Extensions extensions) { + this.version = version; + this.policy = policy; + this.messageImprint = messageImprint; + this.serialNumber = serialNumber; + this.genTime = genTime; + this.accuracy = accuracy; + this.ordering = ordering; + this.nonce = nonce; + this.tsa = tsa; + this.extensions = extensions; + } + + public String toString() { + StringBuffer res = new StringBuffer(); + res.append("-- TSTInfo:"); + res.append("\nversion: "); + res.append(version); + res.append("\npolicy: "); + res.append(policy); + res.append("\nmessageImprint: "); + res.append(messageImprint); + res.append("\nserialNumber: "); + res.append(serialNumber); + res.append("\ngenTime: "); + res.append(genTime); + res.append("\naccuracy: "); + if (accuracy != null) { + res.append(accuracy[0] + " sec, " + accuracy[1] + " millis, " + + accuracy[2] + " micros"); + } + res.append("\nordering: "); + res.append(ordering); + res.append("\nnonce: "); + res.append(nonce); + res.append("\ntsa: "); + res.append(tsa); + res.append("\nextensions: "); + res.append(extensions); + res.append("\n-- TSTInfo End\n"); + return res.toString(); + } + + /** + * @return Returns the accuracy. + */ + public int[] getAccuracy() { + return accuracy; + } + + /** + * @return Returns the extensions. + */ + public Extensions getExtensions() { + return extensions; + } + + /** + * @return Returns the genTime. + */ + public Date getGenTime() { + return genTime; + } + + /** + * @return Returns the messageImprint. + */ + public MessageImprint getMessageImprint() { + return messageImprint; + } + + /** + * @return Returns the nonce. + */ + public BigInteger getNonce() { + return nonce; + } + + /** + * @return Returns the ordering. + */ + public Boolean getOrdering() { + return ordering; + } + + /** + * @return Returns the policy. + */ + public String getPolicy() { + return policy; + } + + /** + * @return Returns the serialNumber. + */ + public BigInteger getSerialNumber() { + return serialNumber; + } + + /** + * @return Returns the tsa. + */ + public GeneralName getTsa() { + return tsa; + } + + /** + * @return Returns the version. + */ + public int getVersion() { + return version; + } + + /** + Accuracy ::= SEQUENCE { + seconds INTEGER OPTIONAL, + millis [0] INTEGER (1..999) OPTIONAL, + micros [1] INTEGER (1..999) OPTIONAL } + */ + public static final ASN1Sequence ACCURACY + = new ASN1Sequence(new ASN1Type[] { + ASN1Integer.getInstance(), + ASN1Integer.getInstance(), + ASN1Integer.getInstance() + }) { + { + setOptional(0); + setOptional(1); + setOptional(2); + } + + protected Object getDecodedObject(BerInputStream in) { + Object[] values = (Object[]) in.content; + + int [] accuracy = new int [3]; + for (int i = 0; i < 3; i++) { + if (values[i] != null) { + accuracy[i] = ASN1Integer.toIntValue(values[i]); + if (i > 0 && (accuracy[i] < 0 || accuracy[i] > 999)) { + throw new RuntimeException( + // Msg: "Time-stamp accuracy value is incorrect: {}" + Messages.getString("security.1A3", accuracy[i])); + } + } + } + return accuracy; + } + + protected void getValues(Object object, Object[] values) { + int [] accuracy = (int []) object; + for (int i = 0; i < 3; i++) { + if (i > 0 && (accuracy[i] < 0 || accuracy[i] > 999)) { + throw new RuntimeException( + // Msg: "Time-stamp accuracy value is incorrect: {0}" + Messages.getString("security.1A3", accuracy[i])); + } + values[i] = BigInteger.valueOf(accuracy[i]).toByteArray(); + } + } + }; + + public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { + ASN1Integer.getInstance(), // version + ASN1Oid.getInstance(), // policy + MessageImprint.ASN1, // messageImprint + ASN1Integer.getInstance(), // serialNumber + ASN1GeneralizedTime.getInstance(), // genTime + ACCURACY, // accuracy + ASN1Boolean.getInstance(), // ordering + ASN1Integer.getInstance(), // nonce + new ASN1Explicit(0, GeneralName.ASN1), // tsa + new ASN1Implicit(1, Extensions.ASN1) }) {// extensions + { + setOptional(5); + setDefault(Boolean.FALSE, 6); + setOptional(7); + setOptional(8); + setOptional(9); + } + + protected Object getDecodedObject(BerInputStream in) { + Object[] values = (Object[]) in.content; + + BigInteger nonce = (values[7] == null) ? null : new BigInteger( + (byte[]) values[7]); + + return new TSTInfo( + ASN1Integer.toIntValue(values[0]), + ObjectIdentifier.toString((int[]) values[1]), + (MessageImprint) values[2], + new BigInteger((byte[]) values[3]), + (Date) values[4], + (int []) values[5], + (Boolean) values[6], + nonce, + (GeneralName) values[8], + (Extensions) values[9]); + } + + protected void getValues(Object object, Object[] values) { + TSTInfo info = (TSTInfo) object; + + values[0] = ASN1Integer.fromIntValue(info.version); + values[1] = ObjectIdentifier.toIntArray(info.policy); + values[2] = info.messageImprint; + values[3] = info.serialNumber.toByteArray(); + values[4] = info.genTime; + values[5] = info.accuracy; + values[6] = info.ordering; + values[7] = (info.nonce == null) ? null : info.nonce.toByteArray(); + values[8] = info.tsa; + values[9] = info.extensions; + } + }; +} + Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java (revision 0) @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import java.security.InvalidParameterException; + +/** + Corresponds to PKIFailureInfo structure. + See RFC 3161 - + Internet X.509 Public Key Infrastructure + Time-Stamp Protocol (TSP) + http://www.ietf.org/rfc/rfc3161.txt) + + 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 } + + The value of PKIFailureInfo can take only one of the values, + so it is represenred by an integer here. + */ +public enum PKIFailureInfo { + /** + * Unrecognized algorithm ID + */ + BAD_ALG(0), + + /** + * Transaction is not supported + */ + BAD_REQUEST(2), + + /** + * Data format is wrong + */ + BAD_DATA_FORMAT(5), + + /** + * TSA cannot use the time source + */ + TIME_NOT_AVAILABLE(14), + + /** + * The policy is not supported + */ + UNACCEPTED_POLICY(15), + + /** + * The extension is not supported + */ + UNACCEPTED_EXTENSION(16), + + /** + * The requested additional info is not available + */ + ADD_INFO_NOT_AVAILABLE(17), + + /** + * System failure has occured + */ + SYSTEM_FAILURE(25); + + + private final int value; + + private static int maxValue; + + PKIFailureInfo(int value) { + this.value = value; + } + + /** + * @return int value of the failure + */ + public int getValue() { + return value; + } + + /** + * @return maximum of values in the enum + */ + public static int getMaxValue() { + if (maxValue == 0) { + for (PKIFailureInfo cur : values()) + if (cur.value > maxValue) { + maxValue = cur.value; + } + } + return maxValue; + } + + /** + * @param value + * @return + */ + public static PKIFailureInfo getInstance(int value) { + for (PKIFailureInfo info : values()){ + if (value == info.value) { + return info; + } + } + throw new InvalidParameterException("Unknown PKIFailureInfo value"); + } +} + Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java (revision 0) @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import org.apache.harmony.security.asn1.ASN1OctetString; +import org.apache.harmony.security.asn1.ASN1Sequence; +import org.apache.harmony.security.asn1.ASN1Type; +import org.apache.harmony.security.asn1.BerInputStream; +import org.apache.harmony.security.x509.AlgorithmIdentifier; + +/** + * As defined in Time-Stamp Protocol (TSP) + * (http://www.ietf.org/rfc/rfc3161.txt) + * + * MessageImprint ::= SEQUENCE { + * hashAlgorithm AlgorithmIdentifier, + * hashedMessage OCTET STRING + * } + * + */ +public class MessageImprint { + private final AlgorithmIdentifier algId; + private final byte [] hashedMessage; + + public MessageImprint(AlgorithmIdentifier algId, byte [] hashedMessage){ + this.algId = algId; + this.hashedMessage = hashedMessage; + } + + public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { + AlgorithmIdentifier.ASN1, + ASN1OctetString.getInstance()}) { + + protected Object getDecodedObject(BerInputStream in) { + Object[] values = (Object[]) in.content; + return new MessageImprint( + (AlgorithmIdentifier)values[0], + (byte[])values[1]); + } + + protected void getValues(Object object, Object[] values) { + MessageImprint mi = (MessageImprint) object; + values[0] = mi.algId; + values[1] = mi.hashedMessage; + } + }; +} + Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java (revision 0) @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import java.security.InvalidParameterException; + +/** + Corresponds to PKIStatus structure. + See RFC 3161 - + Internet X.509 Public Key Infrastructure + Time-Stamp Protocol (TSP) + http://www.ietf.org/rfc/rfc3161.txt) + + 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 } + */ +public enum PKIStatus { + /** + * TimeStampToken is present as requested + */ + GRANTED(0), + /** + * TimeStampToken is present with modifications + */ + GRANTED_WITH_MODS(1), + /** + * rejected + */ + REJECTION(2), + /** + * waiting + */ + WAITING(3), + /** + * revocation time comes soon + */ + REVOCATION_WARNING(4), + /** + * revoked + */ + REVOCATION_NOTIFICATION(5); + + private final int status; + PKIStatus(int status) { + this.status = status; + } + + /** + * @return int value of the status + */ + public int getStatus(){ + return status; + } + + public static PKIStatus getInstance(int status) { + for (PKIStatus curStatus : values()) { + if (status == curStatus.status) { + return curStatus; + } + } + throw new InvalidParameterException("Unknown PKIStatus value"); + } +} + Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java (revision 0) @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import java.math.BigInteger; + +import org.apache.harmony.security.asn1.ASN1Boolean; +import org.apache.harmony.security.asn1.ASN1Implicit; +import org.apache.harmony.security.asn1.ASN1Integer; +import org.apache.harmony.security.asn1.ASN1Oid; +import org.apache.harmony.security.asn1.ASN1Sequence; +import org.apache.harmony.security.asn1.ASN1Type; +import org.apache.harmony.security.asn1.BerInputStream; +import org.apache.harmony.security.asn1.ObjectIdentifier; +import org.apache.harmony.security.x509.Extensions; + +/** + * As defined in Time-Stamp Protocol (TSP) + * (http://www.ietf.org/rfc/rfc3161.txt) + * + * 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 + * } + * + * TSAPolicyId ::= OBJECT IDENTIFIER + */ +public class TimeStampReq { + private final int version; + + private final MessageImprint messageImprint; + + private final String reqPolicy; + + private final BigInteger nonce; + + private final Boolean certReq; + + private final Extensions extensions; + + private byte [] encoding; + + public TimeStampReq(int version, MessageImprint messageImprint, + String reqPolicy, BigInteger nonce, Boolean certReq, + Extensions extensions) { + this.version = version; + this.messageImprint = messageImprint; + this.reqPolicy = reqPolicy; + this.nonce = nonce; + this.certReq = certReq; + this.extensions = extensions; + } + + private TimeStampReq(int version, MessageImprint messageImprint, + String reqPolicy, BigInteger nonce, Boolean certReq, + Extensions extensions, byte [] encoding) { + this (version, messageImprint, reqPolicy, nonce, certReq, extensions); + this.encoding = encoding; + } + + public String toString() { + StringBuffer res = new StringBuffer(); + res.append("-- TimeStampReq:"); + res.append("\nversion : "); + res.append(version); + res.append("\nmessageImprint: "); + res.append(messageImprint); + res.append("\nreqPolicy: "); + res.append(reqPolicy); + res.append("\nnonce: "); + res.append(nonce); + res.append("\ncertReq: "); + res.append(certReq); + res.append("\nextensions: "); + res.append(extensions); + res.append("\n-- TimeStampReq End\n"); + return res.toString(); + } + + /** + * Returns ASN.1 encoded form of this TimeStampReq. + * @return a byte array containing ASN.1 encoded form. + */ + public byte [] getEncoded(){ + if (encoding == null) { + encoding = ASN1.encode(this); + } + return encoding; + } + + /** + * @return Returns the certReq. + */ + public Boolean getCertReq() { + return certReq; + } + + /** + * @return Returns the extensions. + */ + public Extensions getExtensions() { + return extensions; + } + + /** + * @return Returns the messageImprint. + */ + public MessageImprint getMessageImprint() { + return messageImprint; + } + + /** + * @return Returns the nonce. + */ + public BigInteger getNonce() { + return nonce; + } + + /** + * @return Returns the reqPolicy. + */ + public String getReqPolicy() { + return reqPolicy; + } + + /** + * @return Returns the version. + */ + public int getVersion() { + return version; + } + + public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { + ASN1Integer.getInstance(), // version + MessageImprint.ASN1, // messageImprint + ASN1Oid.getInstance(), // reqPolicy + ASN1Integer.getInstance(), // nonce + ASN1Boolean.getInstance(), // certReq + new ASN1Implicit(0, Extensions.ASN1)}) {// extensions + + { + setDefault(Boolean.FALSE, 4); + setOptional(2); + setOptional(3); + setOptional(5); + } + + protected Object getDecodedObject(BerInputStream in) { + Object[] values = (Object[]) in.content; + + String objID = (values[2] == null) ? null : ObjectIdentifier + .toString((int[]) values[2]); + BigInteger nonce = (values[3] == null) ? null : new BigInteger( + (byte[]) values[3]); + + if (values[5] == null) { + return new TimeStampReq( + ASN1Integer.toIntValue(values[0]), + (MessageImprint) values[1], + objID, + nonce, + (Boolean) values[4], + null, + in.getEncoded() + ); + } else { + return new TimeStampReq( + ASN1Integer.toIntValue(values[0]), + (MessageImprint) values[1], + objID, + nonce, + (Boolean) values[4], + (Extensions) values[5], + in.getEncoded() + ); + } + } + + protected void getValues(Object object, Object[] values) { + TimeStampReq req = (TimeStampReq) object; + values[0] = ASN1Integer.fromIntValue(req.version); + values[1] = req.messageImprint; + values[2] = (req.reqPolicy == null) ? null : ObjectIdentifier + .toIntArray(req.reqPolicy); + values[3] = (req.nonce == null) ? null : req.nonce.toByteArray(); + values[4] = (req.certReq == null) ? Boolean.FALSE : req.certReq; + values[5] = req.extensions; + } + }; + +} + Index: modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java (revision 0) +++ modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java (revision 0) @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.harmony.security.x509.tsp; + +import org.apache.harmony.security.asn1.ASN1Sequence; +import org.apache.harmony.security.asn1.ASN1Type; +import org.apache.harmony.security.asn1.BerInputStream; +import org.apache.harmony.security.pkcs7.ContentInfo; + +/** + * As defined in Time-Stamp Protocol (TSP) + * (http://www.ietf.org/rfc/rfc3161.txt) + * + * TimeStampResp ::= SEQUENCE { + * status PKIStatusInfo, + * timeStampToken TimeStampToken OPTIONAL + * } + * + */ +public class TimeStampResp { + + private final PKIStatusInfo status; + + private final ContentInfo timeStampToken; + + public TimeStampResp(PKIStatusInfo status, ContentInfo timeStampToken) { + this.status = status; + this.timeStampToken = timeStampToken; + } + + public String toString(){ + StringBuffer res = new StringBuffer(); + res.append("-- TimeStampResp:"); + res.append("\nstatus: "); + res.append(status); + res.append("\ntimeStampToken: "); + res.append(timeStampToken); + res.append("\n-- TimeStampResp End\n"); + return res.toString(); + } + + /** + * @return Returns the status. + */ + public PKIStatusInfo getStatus() { + return status; + } + + /** + * @return Returns the timeStampToken. + */ + public ContentInfo getTimeStampToken() { + return timeStampToken; + } + + public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { + PKIStatusInfo.ASN1, // status + ContentInfo.ASN1}) { // timeStampToken + + { + setOptional(1); + } + + protected Object getDecodedObject(BerInputStream in) { + Object[] values = (Object[]) in.content; + return new TimeStampResp( + (PKIStatusInfo) values[0], + (ContentInfo) values[1]); + } + + protected void getValues(Object object, Object[] values) { + TimeStampResp resp = (TimeStampResp) object; + + values[0] = resp.status; + values[1] = resp.timeStampToken; + } + }; +} +