Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
54   183   14   4.5
20   101   0.46   12
12     2.08  
1    
 
 
  WebdavCertificate       Line # 65 54 14 2.3% 0.023255814
 
No Tests
 
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    * WebdavCertificate.java
48    *
49    * Created on 18. juni 2007, 11:52
50    *
51    * @author Rune Bjerk
52    */
53   
54    package issrg.ac.extensions;
55   
56   
57    import iaik.asn1.*;
58    import iaik.asn1.structures.*;
59    import issrg.pba.PbaException;
60    import issrg.utils.WebDAV_DIT;
61   
62    import java.math.BigInteger;
63    import java.util.*;
64   
 
65    public class WebdavCertificate extends issrg.ac.Extension{
66   
67    public static final String WEBDAV_CERTIFICATE_METHOD_OID = "1.2.826.0.1.3344810.10.2";
68   
69    String cert_loc;
70    /** Creates a new instance of WebdavCertificate */
71   
 
72  0 toggle public WebdavCertificate(ASN1Object ao)throws CodingException{
73  0 super(ao);
74    }
 
75  0 toggle public WebdavCertificate(String location,String subjectDN, BigInteger serial) {
76  0 super(WEBDAV_CERTIFICATE_METHOD_OID,false);
77  0 cert_loc=getProperLocation(location,subjectDN,serial);
78    }
79   
 
80  0 toggle public WebdavCertificate(WebdavCertificate webcert)throws CodingException{
81  0 super(WEBDAV_CERTIFICATE_METHOD_OID,false,webcert.getExtensionValue());
82    }
83   
 
84  0 toggle public String getExtensionOID() {
85  0 return WEBDAV_CERTIFICATE_METHOD_OID;
86    }
87   
 
88  0 toggle public String getLocation(){
89  0 return cert_loc;
90    }
91   
 
92  0 toggle public void setLocation(String location){
93  0 cert_loc=location;
94    }
95   
 
96  0 toggle public ASN1Object encodeValue() throws CodingException{
97  0 SEQUENCE seq = new SEQUENCE();
98   
99  0 if (cert_loc!=null){
100  0 GeneralName name = new GeneralName(GeneralName.uniformResourceIdentifier, cert_loc);
101   
102  0 SEQUENCE certificate = new SEQUENCE();
103  0 certificate.addComponent(new ObjectID(WEBDAV_CERTIFICATE_METHOD_OID), 0);
104  0 certificate.addComponent(name.toASN1Object(), 1);
105  0 seq.addComponent(certificate);
106    }
107   
108   
109  0 return seq;
110    }
111   
 
112  0 toggle public void decode(ASN1Object ao) throws CodingException {
113  0 super.decode(ao);
114  0 if (isCritical()) throw new CodingException("AttributeAuthorityInformationAccess extension MUST be non-critical");
115    }
116   
 
117  0 toggle public void decodeValue(ASN1Object ao )throws CodingException{
118    // we may want to check that ao is a SEQUENCE first
119  0 int j = ao.countComponents();
120  0 for (int i=0; i<j; i++) {
121  0 ASN1Object accessDescription = ao.getComponentAt(i);
122  0 try{
123  0 if ((accessDescription instanceof SEQUENCE)) { //SEQUENCE is expected
124  0 ASN1Object oid = (ASN1Object) accessDescription.getComponentAt(0);
125   
126  0 if ((oid instanceof ObjectID)) { //The first object of the SEQUENCE should be ObjectID
127   
128  0 String id = (String) ((ObjectID) oid).getValue();
129  0 if (id.equals(WEBDAV_CERTIFICATE_METHOD_OID)) { //only webdav objectIdentifier is supported by now
130  0 ASN1Object generalName = (ASN1Object) accessDescription.getComponentAt(1);
131  0 if ((generalName instanceof CON_SPEC)) {
132  0 GeneralName gn = new GeneralName(generalName);
133  0 if (gn.getType()!=GeneralName.uniformResourceIdentifier){
134  0 continue; // skip the General Names that are not URLs
135    }
136  0 setLocation((String)gn.getName()); //If everything is ok then set the location
137    }
138   
139   
140    }
141    }
142    }
143    }catch(CodingException ce){
144  0 if(isCritical()!=false){
145  0 throw new CodingException("Not possible to decode the ASN1Object values");
146    }
147  0 System.out.println("Feil:"+ce.getMessage());
148  0 ce.printStackTrace();
149    }
150    }
151   
152    }
153   
 
154  19 toggle public static void registerMe() {
155  19 issrg.ac.Extensions.registerExtension(WEBDAV_CERTIFICATE_METHOD_OID, WebdavCertificate.class);
156    }
 
157  0 toggle public String extensionValueToString(String indent){
158  0 String result="";
159  0 result =result.concat(indent+"Extension ID: "+extnID+"\n"+indent); //One the same line
160  0 result =result.concat(indent+"Location: "+getLocation()+"\n"+indent);
161  0 return result;
162    }
163   
164   
 
165  0 toggle private String getProperLocation(String loc, String holderDN, BigInteger serial){
166  0 System.err.println("location = " + loc +" holderDN = " + holderDN + "serial = " + serial);
167  0 String holderURL;
168  0 try{
169  0 holderURL= issrg.utils.WebdavUtil.convertDN2URI(holderDN);
170  0 System.err.println("Holder URL = " + holderURL);
171    }catch(PbaException pba){
172  0 return "";
173    }
174  0 System.err.println(loc);
175  0 if(loc.endsWith("/") && holderURL.startsWith("/")){ //That would mean: issrg-beta.cs.kent.ac.uk//c=gb/o=Permis
176  0 holderURL = holderURL.substring(1);
177    }
178  0 String name = holderURL.substring(holderURL.lastIndexOf('/'));
179  0 String location = loc+holderURL+name+"+SN="+serial+WebDAV_DIT.ace;
180   
181  0 return location;
182    }
183    }