harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r478549 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/x509/tsp/ test/impl/java/org/apache/harmony/security/tests/x509/tsp/
Date Thu, 23 Nov 2006 12:32:35 GMT
Author: mloenko
Date: Thu Nov 23 04:32:33 2006
New Revision: 478549

URL: http://svn.apache.org/viewvc?view=rev&rev=478549
Log:
applied patch for HARMONY-2260
[classlib][security] Add time-stamp protocol implementation to org.apache.harmony.security.x509 package

Added:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/PKIStatusInfoTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TSTInfoTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampReqTest.java   (with props)
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampRespTest.java   (with props)

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java Thu Nov 23 04:32:33 2006
@@ -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;
+        }
+    };
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/MessageImprint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java Thu Nov 23 04:32:33 2006
@@ -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");
+    }
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIFailureInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java Thu Nov 23 04:32:33 2006
@@ -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");
+    }
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java Thu Nov 23 04:32:33 2006
@@ -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));
+        }
+    };
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/PKIStatusInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java Thu Nov 23 04:32:33 2006
@@ -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;
+        }
+    };
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TSTInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java Thu Nov 23 04:32:33 2006
@@ -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;
+        }
+    };
+
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampReq.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java Thu Nov 23 04:32:33 2006
@@ -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;
+        }    
+    };
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/tsp/TimeStampResp.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/PKIStatusInfoTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/PKIStatusInfoTest.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/PKIStatusInfoTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/PKIStatusInfoTest.java Thu Nov 23 04:32:33 2006
@@ -0,0 +1,54 @@
+/*
+ *  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.tests.x509.tsp;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.harmony.security.x509.tsp.PKIFailureInfo;
+import org.apache.harmony.security.x509.tsp.PKIStatus;
+import org.apache.harmony.security.x509.tsp.PKIStatusInfo;
+
+import junit.framework.TestCase;
+
+public class PKIStatusInfoTest extends TestCase {
+
+    /**
+     * @throws IOException 
+     * @tests 'org.apache.harmony.security.x509.tsp.PKIStatusInfo.getEncoded()'
+     */
+    public void testGetEncoded() throws IOException {
+        ArrayList statusStr = new ArrayList(2);
+        statusStr.add("one");
+        statusStr.add("two");
+        PKIStatusInfo info = new PKIStatusInfo(PKIStatus.REJECTION, statusStr,
+                PKIFailureInfo.BAD_DATA_FORMAT);
+        byte [] encoding = PKIStatusInfo.ASN1.encode(info);
+        PKIStatusInfo decoded = (PKIStatusInfo) PKIStatusInfo.ASN1
+                .decode(encoding);
+        
+        assertEquals(info.getStatus(), decoded.getStatus());
+        List decodedStString = decoded.getStatusString();
+        assertNotNull(decodedStString);
+        assertEquals("one", decodedStString.get(0));
+        assertEquals("two", decodedStString.get(1));
+        assertEquals(info.getFailInfo(), decoded.getFailInfo());
+    }
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/PKIStatusInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TSTInfoTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TSTInfoTest.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TSTInfoTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TSTInfoTest.java Thu Nov 23 04:32:33 2006
@@ -0,0 +1,86 @@
+/*
+ *  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.tests.x509.tsp;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.x501.Name;
+import org.apache.harmony.security.x509.AlgorithmIdentifier;
+import org.apache.harmony.security.x509.Extension;
+import org.apache.harmony.security.x509.Extensions;
+import org.apache.harmony.security.x509.GeneralName;
+import org.apache.harmony.security.x509.tsp.MessageImprint;
+import org.apache.harmony.security.x509.tsp.TSTInfo;
+
+public class TSTInfoTest extends TestCase {
+
+    /**
+     * @throws IOException 
+     * @tests 'org.apache.harmony.security.x509.tsp.TSTInfo.getEncoded()'
+     */
+    public void testGetEncoded() throws IOException {
+        // Unizeto CETRUM policy
+        String policy = "1.2.3.4.5";
+        // SHA1 OID as defined in RFC 3161
+        String sha1 = "1.3.14.3.2.26";
+        MessageImprint msgImprint = new MessageImprint(new AlgorithmIdentifier(
+                sha1), new byte[20]);
+        Date genTime = new Date();
+        BigInteger nonce = BigInteger.valueOf(1234567890L);
+        int[] accuracy = new int[] { 1, 0, 0 };
+        GeneralName tsa = new GeneralName(new Name("CN=AnAuthority"));
+        Extensions exts = new Extensions();
+        // Time-Stamping extension OID: as defined in RFC 3161
+        int[] timeStampingExtOID = new int[] { 1, 3, 6, 1, 5, 5, 7, 3, 8 };
+        byte[] timeStampingExtValue = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
+        Extension ext = new Extension(timeStampingExtOID, true,
+                timeStampingExtValue);
+        exts.addExtension(ext);
+
+        TSTInfo info = new TSTInfo(1, policy, msgImprint, BigInteger.TEN,
+                genTime, accuracy, Boolean.FALSE, nonce, tsa, exts);
+
+        byte[] encoding = TSTInfo.ASN1.encode(info);
+        TSTInfo decoded = (TSTInfo) TSTInfo.ASN1.decode(encoding);
+
+        assertEquals("Decoded version is incorrect", info.getVersion(), decoded
+                .getVersion());
+        assertEquals("Decoded policy is incorrect", policy, decoded.getPolicy());
+        assertTrue("Decoded messageImprint is incorrect", Arrays.equals(
+                MessageImprint.ASN1.encode(msgImprint), MessageImprint.ASN1
+                        .encode(decoded.getMessageImprint())));
+        assertEquals("Decoded serialNumber is incorrect", BigInteger.TEN,
+                decoded.getSerialNumber());
+        assertEquals("Decoded genTime is incorrect", genTime, decoded
+                .getGenTime());
+        assertTrue("Decoded accuracy is incorrect", Arrays.equals(accuracy,
+                decoded.getAccuracy()));
+        assertFalse("Decoded ordering is incorrect", decoded.getOrdering()
+                .booleanValue());
+        assertEquals("Decoded nonce is incorrect", nonce, decoded.getNonce());
+        assertEquals("Decoded tsa is incorrect", tsa, decoded.getTsa());
+        assertEquals("Decoded extensions is incorrect", exts, decoded
+                .getExtensions());
+    }
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TSTInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampReqTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampReqTest.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampReqTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampReqTest.java Thu Nov 23 04:32:33 2006
@@ -0,0 +1,69 @@
+/*
+ *  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.tests.x509.tsp;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.x509.AlgorithmIdentifier;
+import org.apache.harmony.security.x509.Extension;
+import org.apache.harmony.security.x509.Extensions;
+import org.apache.harmony.security.x509.tsp.MessageImprint;
+import org.apache.harmony.security.x509.tsp.TimeStampReq;
+
+public class TimeStampReqTest extends TestCase {
+
+    /**
+     * @throws IOException 
+     * @tests 'org.apache.harmony.security.x509.tsp.TimeStampReq.getEncoded()'
+     */
+    public void testTimeStampReq() throws IOException {
+        // SHA1 OID
+        MessageImprint msgImprint = new MessageImprint(new AlgorithmIdentifier(
+                "1.3.14.3.2.26"), new byte[20]);
+        String reqPolicy = "1.2.3.4.5";
+        BigInteger nonce = BigInteger.valueOf(1234567890L); 
+        Extensions exts = new Extensions();
+        int[] extOID = new int[] { 1, 2, 3, 2, 1 };
+        byte[] extValue = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
+        Extension ext = new Extension(extOID, false, extValue);
+        exts.addExtension(ext);
+
+        TimeStampReq req = new TimeStampReq(1, msgImprint, reqPolicy,
+                nonce, Boolean.FALSE, exts);
+        byte[] encoding = req.getEncoded();
+        TimeStampReq decoded = (TimeStampReq) TimeStampReq.ASN1
+                .decode(encoding);
+        assertEquals("Decoded version is incorrect", req.getVersion(), decoded
+                .getVersion());
+        assertTrue("Decoded messageImprint is incorrect", Arrays.equals(
+                MessageImprint.ASN1.encode(msgImprint), MessageImprint.ASN1
+                        .encode(decoded.getMessageImprint())));
+        assertEquals("Decoded reqPolicy is incorrect", reqPolicy, decoded
+                .getReqPolicy());
+        assertEquals("Decoded nonce is incorrect", nonce, decoded.getNonce());
+        assertFalse("Decoded certReq is incorrect", decoded.getCertReq()
+                .booleanValue());
+        assertEquals("Decoded extensions is incorrect", exts, decoded
+                .getExtensions());
+    }
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampReqTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampRespTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampRespTest.java?view=auto&rev=478549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampRespTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampRespTest.java Thu Nov 23 04:32:33 2006
@@ -0,0 +1,112 @@
+/*
+ *  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.tests.x509.tsp;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1OctetString;
+import org.apache.harmony.security.pkcs7.ContentInfo;
+import org.apache.harmony.security.pkcs7.SignedData;
+import org.apache.harmony.security.pkcs7.SignerInfo;
+import org.apache.harmony.security.x501.Name;
+import org.apache.harmony.security.x509.AlgorithmIdentifier;
+import org.apache.harmony.security.x509.Extension;
+import org.apache.harmony.security.x509.Extensions;
+import org.apache.harmony.security.x509.GeneralName;
+import org.apache.harmony.security.x509.tsp.MessageImprint;
+import org.apache.harmony.security.x509.tsp.PKIFailureInfo;
+import org.apache.harmony.security.x509.tsp.PKIStatus;
+import org.apache.harmony.security.x509.tsp.PKIStatusInfo;
+import org.apache.harmony.security.x509.tsp.TSTInfo;
+import org.apache.harmony.security.x509.tsp.TimeStampResp;
+
+public class TimeStampRespTest extends TestCase {
+
+    /**
+     * @throws IOException 
+     * @tests 'org.apache.harmony.security.x509.tsp.TimeStampResp.getEncoded()'
+     */
+    public void testGetEncoded() throws IOException {
+        String statusString = "statusString";
+        PKIStatusInfo status = new PKIStatusInfo(PKIStatus.REJECTION,
+                Collections.singletonList(statusString),
+                PKIFailureInfo.BAD_REQUEST);
+        
+        
+        // creating TimeStampToken
+        String policy = "1.2.3.4.5";
+        String sha1 = "1.3.14.3.2.26";
+        MessageImprint msgImprint = new MessageImprint(new AlgorithmIdentifier(
+                sha1), new byte[20]);
+        Date genTime = new Date();
+        BigInteger nonce = BigInteger.valueOf(1234567890L);
+        // accuracy is 1 second
+        int[] accuracy = new int[] { 1, 0, 0 };
+        GeneralName tsa = new GeneralName(new Name("CN=AnAuthority"));
+        Extensions exts = new Extensions();
+        // Time-Stamping extension OID: as defined in RFC 3161
+        int[] timeStampingExtOID = new int[] { 1, 3, 6, 1, 5, 5, 7, 3, 8 };
+        byte[] timeStampingExtValue = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
+        Extension ext = new Extension(timeStampingExtOID, true,
+                timeStampingExtValue);
+        exts.addExtension(ext);
+
+        TSTInfo tSTInfo = new TSTInfo(1, policy, msgImprint, BigInteger.TEN,
+                genTime, accuracy, Boolean.FALSE, nonce, tsa, exts);
+        
+        Object[] issuerAndSerialNumber = new Object[] { new Name("CN=issuer"),
+                ASN1Integer.fromIntValue(12345) };
+        // SHA1withDSA OID
+        String sha1dsa = "1.2.840.10040.4.3";
+        SignerInfo sigInfo = new SignerInfo(1, issuerAndSerialNumber,
+                new AlgorithmIdentifier(sha1), null, new AlgorithmIdentifier(
+                        sha1dsa), new byte[20], null);
+        // TSTInfo OID according to RFC 3161
+        int[] tSTInfoOid = new int[] { 1, 2, 840, 113549, 1, 9, 16, 1, 4 };
+        ContentInfo tSTInfoEncoded = new ContentInfo(tSTInfoOid,
+                ASN1OctetString.getInstance().encode(
+                        TSTInfo.ASN1.encode(tSTInfo)));
+        SignedData tokenContent = new SignedData(1, Collections
+                .singletonList(new AlgorithmIdentifier(sha1)), tSTInfoEncoded,
+                null, null, Collections.singletonList(sigInfo));
+        ContentInfo timeStampToken = new ContentInfo(ContentInfo.SIGNED_DATA,
+                tokenContent);
+        
+        TimeStampResp response = new TimeStampResp(status, timeStampToken);
+        
+        byte [] encoding = TimeStampResp.ASN1.encode(response);
+        TimeStampResp decoded = (TimeStampResp) TimeStampResp.ASN1
+                .decode(encoding);
+
+        // deeper checks are performed in the corresponding unit tests
+        assertTrue("Decoded status is incorrect", Arrays.equals(
+                PKIStatusInfo.ASN1.encode(status), PKIStatusInfo.ASN1
+                        .encode(decoded.getStatus())));
+        assertTrue("Decoded timeStampToken is incorrect", Arrays.equals(
+                timeStampToken.getEncoded(), decoded.getTimeStampToken()
+                        .getEncoded()));
+    }
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/tsp/TimeStampRespTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message