Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
53   243   15   4.82
24   94   0.47   11
11     2.27  
1    
 
 
  AttributeAuthorityInformationAccess       Line # 64 53 15 38.6% 0.38636363
 
  (1)
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
44    */
45   
46    /*
47    * AttributeAuthorityInformationAccess.java
48    *
49    * Created on July 11, 2005, 4:29 PM
50    */
51   
52    package issrg.ac.extensions;
53   
54    import iaik.asn1.*;
55    import iaik.asn1.structures.*;
56   
57    import java.util.Enumeration;
58    import java.util.Vector;
59   
60    /**
61    *
62    * @author anhnt
63    */
 
64    public class AttributeAuthorityInformationAccess extends issrg.ac.Extension {
65   
66    /**
67    *The string stores the OID for the Attribute authority information access: 1.2.826.0.1.3344810.10.0
68    */
69    public static final String ATTRIBUTE_AUTHORITY_INFORMATION_ACCESS = "1.2.826.0.1.3344810.10.0";
70   
71    /**
72    *This string stores the standard OID for id_ad_caIssuer: 1.3.6.1.5.5.7.48.2
73    */
74    private static final String id_ad_caIssuer = "1.3.6.1.5.5.7.48.2";
75   
76    /**
77    *This string stores the standard OID for id_ad_oscp: 1.3.6.1.5.5.7.48.1
78    */
79   
80    private static final String id_ad_oscp = "1.3.6.1.5.5.7.48.1";
81   
82    private static final ObjectID ID_AD_CAISSUER_OID = new ObjectID(AttributeAuthorityInformationAccess.id_ad_caIssuer);
83   
84    private String [] locations;
85   
86    /**
87    * This method registers this extension as an extension with a specific
88    * OID. After it has been registered, Extensions can recognise
89    * the extension with this OID.
90    */
91   
 
92  19 toggle public static void registerMe() {
93  19 issrg.ac.Extensions.registerExtension(ATTRIBUTE_AUTHORITY_INFORMATION_ACCESS, AttributeAuthorityInformationAccess.class);
94    }
95   
96   
97    /** Creates a new instance of AttributeAuthorityInformationAccess based on an
98    *existing AAIA extension
99    *
100    *@param e is an AAIA extension
101    */
102   
 
103  0 toggle public AttributeAuthorityInformationAccess(AttributeAuthorityInformationAccess e) throws CodingException {
104  0 super(ATTRIBUTE_AUTHORITY_INFORMATION_ACCESS, false, e.getExtensionValue());
105    }
106   
107    /**
108    *This method constructs an AAIA extension based on an extension value
109    *@param extnValue is an array of strings. It indicates the locations of
110    *the ACs of the AC's issuer
111    */
112   
 
113  0 toggle public AttributeAuthorityInformationAccess(String [] extnValue) {
114  0 super(ATTRIBUTE_AUTHORITY_INFORMATION_ACCESS, false);
115  0 setLocations(extnValue);
116    }
117   
118    /**
119    * This method constructs an AAIA extension based on an ASN1Object object
120    *@param ao is the ASN1Object object that is used to construct the AAIA object.
121    */
122   
 
123  506 toggle public AttributeAuthorityInformationAccess(ASN1Object ao) throws CodingException {
124  506 super(ao);
125    }
126   
 
127  0 toggle public Object clone() {
128  0 try {
129  0 return new AttributeAuthorityInformationAccess(this);
130  0 } catch (CodingException ce) {return null;}
131    }
132   
133    /**
134    * This method decodes a given ASN1Object and upon successful decoding sets
135    * the AAIA extension for the AC.
136    *
137    * @param ao - ASN1Object to decode
138    */
139   
 
140  506 toggle public void decode(ASN1Object ao) throws CodingException {
141  506 super.decode(ao);
142  0 if (isCritical()) throw new CodingException("AttributeAuthorityInformationAccess extension MUST be non-critical");
143    }
144   
145    /**
146    * This method decodes an ASN1Object to get the extension value of an AAIA
147    *extension.
148    *
149    *@param ao is an ASN1Object that is going to be decoded.
150    */
151   
 
152  506 toggle public void decodeValue(ASN1Object ao) throws CodingException {
153  506 Vector location = new Vector();
154    // we may want to check that ao is a SEQUENCE first
155  506 int j = ao.countComponents();
156  1012 for (int i=0; i<j; i++) {
157  506 ASN1Object accessDescription = ao.getComponentAt(i);
158  506 try{
159  0 if (!(accessDescription instanceof SEQUENCE)) throw new CodingException("Wrong extension value format: SEQUENCE expected");
160   
161  506 ASN1Object oid = (ASN1Object) accessDescription.getComponentAt(0);
162  0 if (!(oid instanceof ObjectID)) throw new CodingException("Wrong extension value format: OBJECT IDENTIFIER expected");
163   
164  506 String id = (String) ((ObjectID) oid).getValue();
165  506 if (!id.equals(id_ad_caIssuer)) { //only id-ad-caIssuers objectIdentifier is supported by now
166  0 throw new CodingException("Unsupported OID found in AAIA extension: "+id);
167    }
168   
169  506 ASN1Object generalName = (ASN1Object) accessDescription.getComponentAt(1);
170  506 if (!(generalName instanceof CON_SPEC)) {
171  0 throw new CodingException("GeneralName was expected as the extension value");
172    }
173  506 GeneralName gn = new GeneralName(generalName);
174  506 if (gn.getType()!=GeneralName.uniformResourceIdentifier){
175  0 continue; // skip the General Names that are not URLs
176    }
177  506 location.add(gn.getName().toString());
178    }catch(CodingException ce){
179    // the extension is not critical - ignore the errors
180    }
181    }
182  506 setLocations((String [])location.toArray(new String[0]));
183    }
184   
185   
 
186  0 toggle public String[] getLocations() {
187  0 return locations;
188    }
189   
190    /**
191    * This method sets the locations to an array of Strings, each representing the individual URL
192    *
193    *@param s is an array of strings that represent the ACs' locations.
194    */
195   
 
196  506 toggle public void setLocations(String [] s){
197  506 locations=s;
198    }
199   
200    /**
201    *This method encodes the ACs' locations to an ASN1Object object.
202    *@return an ASN1Object that represents the ACs's locations
203    */
 
204  0 toggle public ASN1Object encodeValue() throws CodingException{
205  0 String [] urls=getLocations();
206  0 SEQUENCE extnV = new SEQUENCE();
207   
208  0 if (urls!=null){
209  0 for (int i=0; i<urls.length; i++){
210  0 GeneralName name = new GeneralName(GeneralName.uniformResourceIdentifier, urls[i]);
211   
212  0 SEQUENCE accessDesc = new SEQUENCE();
213  0 accessDesc.addComponent(ID_AD_CAISSUER_OID, 0);
214  0 accessDesc.addComponent(name.toASN1Object(), 1);
215  0 extnV.addComponent(accessDesc);
216    }
217    }
218   
219  0 return extnV;
220    }
221   
222    /**
223    *This method creates a string that represents all the issuer AC locations
224    *@param ident is a string used to separate the locations
225    *@return a string that represents all the issuer AC locations
226    */
227   
 
228  0 toggle public String extensionValueToString(String ident){
229  0 String[] b = getLocations();
230   
231  0 String a= "";
232   
233  0 if (b!=null){
234  0 for (int i = 0; i < b.length; i++) {
235  0 if (i>0) a = a.concat(" ");
236  0 a = a.concat((String)b[i]);
237    }
238    }else{
239  0 a="(no locations set)";
240    }
241  0 return a;
242    }
243    }