View Javadoc
1 /* 2 * Copyright 2002 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this program for any 5 * purpose and without fee is hereby granted, provided that this 6 * copyright and permission notice appear on all copies and supporting 7 * documentation, the name of M.I.T. not be used in advertising or 8 * publicity pertaining to distribution of the program without specific 9 * prior permission, and notice be given in supporting documentation that 10 * copying and distribution is by permission of M.I.T. M.I.T. makes no 11 * representations about the suitability of this software for any 12 * purpose. It is provided "as is" without express or implied warranty. 13 */ 14 package jsdsi; 15 16 import java.security.InvalidAlgorithmParameterException; 17 import java.security.cert.CertStoreException; 18 import java.security.cert.CertStoreParameters; 19 import java.security.cert.CertStoreSpi; 20 import java.security.cert.CollectionCertStoreParameters; 21 import java.util.Collection; 22 import java.util.Iterator; 23 24 /*** 25 * A collection-based certificate store for SPKI/SDSI certificates. 26 * 27 * @author Sameer Ajmani 28 * @version $Revision: 1.1 $ $Date: 2004/02/28 15:49:34 $ 29 */ 30 public class CertStore extends CertStoreSpi { 31 /*** 32 * Contains the mappings from issuer to 33 * issuer -> (issuer -> RHS) 34 */ 35 MultiMap auth = new MultiMap(); 36 37 /*** 38 * name -> (name -> RHS) 39 */ 40 MultiMap name = new MultiMap(); 41 42 /*** 43 * name -> (LHS -> name+X) 44 */ 45 MultiMap compatible = new MultiMap(); 46 47 /*** 48 * subject -> (LHS -> subject) 49 */ 50 MultiMap subject = new MultiMap(); 51 52 /*** 53 * Adds new certificates to this <code>CertStore</code>. 54 * 55 * @param params collection of certificates to add to this 56 * <code>CertStore</code>. 57 */ 58 private void init(CollectionCertStoreParameters params) { 59 Iterator i = params.getCollection().iterator(); 60 while (i.hasNext()) { 61 jsdsi.Certificate c = (jsdsi.Certificate) i.next(); 62 if (c.getCert().getSubject() instanceof Name) { 63 Name n = (Name) c.getCert().getSubject(); 64 compatible.put(n.prefix(), c); 65 } else { 66 // subject is not a name 67 subject.put(c.getCert().getSubject(), c); 68 } 69 if (c.getCert() instanceof NameCert) { 70 NameCert nc = (NameCert) c.getCert(); 71 name.put(nc.getFullName(), c); 72 } 73 if (c.getCert() instanceof AuthCert) { 74 auth.put(c.getCert().getIssuer(), c); 75 } 76 } 77 } 78 79 /*** 80 * Creates a new <code>CertStore</code> using the given parameters. 81 * 82 * @see java.security.cert.CertStoreSpi#CertStoreSpi(java.security.cert.CertStoreParameters) 83 * 84 * @param params parameters to create the <code>CertStore</code> from. 85 * @throws InvalidAlgorithmParameterException if a problem occurs with 86 * <code>params</code>. 87 */ 88 public CertStore(CollectionCertStoreParameters params) 89 throws InvalidAlgorithmParameterException { 90 super(params); 91 init(params); 92 } 93 94 /*** 95 * @see java.security.cert.CertStoreSpi#CertStoreSpi(CertStoreParameters) 96 */ 97 public CertStore(CertStoreParameters params) 98 throws InvalidAlgorithmParameterException { 99 super(params); 100 try { 101 init((CollectionCertStoreParameters) params); 102 } catch (ClassCastException e) { 103 throw (InvalidAlgorithmParameterException) new InvalidAlgorithmParameterException() 104 .initCause( 105 e); 106 } 107 } 108 109 /*** 110 * @see java.security.cert.CertStoreSpi#engineGetCertificates(CertSelector) 111 */ 112 public Collection engineGetCertificates(java.security.cert.CertSelector s) 113 throws CertStoreException { 114 if (!(s instanceof jsdsi.CertSelector)) { 115 throw new CertStoreException("requires jsdsi.CertSelector"); 116 } 117 return engineGetCertificates((jsdsi.CertSelector) s); 118 } 119 120 /*** 121 * @see java.security.cert.CertStoreSpi#engineGetCertificates(CertSelector) 122 */ 123 public Collection engineGetCertificates(jsdsi.CertSelector s) 124 throws CertStoreException { 125 if (s instanceof SubjectCertSelector) { 126 return subject.get(((SubjectCertSelector) s).getSubject()); 127 } 128 if (s instanceof CompatibleCertSelector) { 129 return compatible.get(((CompatibleCertSelector) s).getFullName()); 130 } 131 if (s instanceof NameCertSelector) { 132 return name.get(((NameCertSelector) s).getFullName()); 133 } 134 if (s instanceof AuthCertSelector) { 135 return auth.get(((AuthCertSelector) s).getIssuer()); 136 } 137 throw new CertStoreException( 138 "unrecognized selector: " + s.getClass().getName()); 139 } 140 141 /*** 142 * @see java.security.cert.CertStoreSpi#engineGetCRLs(java.security.cert.CRLSelector) 143 */ 144 public Collection engineGetCRLs(java.security.cert.CRLSelector s) 145 throws CertStoreException { 146 throw new UnsupportedOperationException(); 147 } 148 }

This page was automatically generated by Maven