|
From: <pe...@us...> - 2003-10-01 17:05:44
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id
In directory sc8-pr-cvs1:/tmp/cvs-serv25143/src/java/org/neuclear/id
Modified Files:
Identity.java Named.java SignedNamedObject.java
Log Message:
Moved the NeuClearCertificate class to be an inner class of Identity.
Index: Identity.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/Identity.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Identity.java 29 Sep 2003 23:17:31 -0000 1.4
--- Identity.java 1 Oct 2003 17:05:37 -0000 1.5
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.5 2003/10/01 17:05:37 pelle
+ * Moved the NeuClearCertificate class to be an inner class of Identity.
+ *
* Revision 1.4 2003/09/29 23:17:31 pelle
* Changes to the senders. Now the senders only work with NamedObjectBuilders
***************
*** 172,176 ****
import org.neuclear.id.builders.NamedObjectBuilder;
! import java.security.PublicKey;
import java.util.Iterator;
import java.util.List;
--- 175,182 ----
import org.neuclear.id.builders.NamedObjectBuilder;
! import java.security.*;
! import java.security.cert.Certificate;
! import java.security.cert.CertificateEncodingException;
! import java.security.cert.CertificateException;
import java.util.Iterator;
import java.util.List;
***************
*** 193,197 ****
*/
! Identity(String name, Identity signatory, Timestamp timestamp, String digest, String repository, String signer, String logger, String receiver, PublicKey[] pubs) throws NeudistException {
super(name, signatory, timestamp, digest);
this.repository = repository;
--- 199,203 ----
*/
! Identity(String name, Identity signatory, Timestamp timestamp, String digest, String repository, String signer, String logger, String receiver, PublicKey pub) throws NeudistException {
super(name, signatory, timestamp, digest);
this.repository = repository;
***************
*** 199,203 ****
this.signer = signer;
this.receiver = receiver;
! this.pubs = pubs;
}
--- 205,209 ----
this.signer = signer;
this.receiver = receiver;
! this.pub = pub;
}
***************
*** 233,238 ****
return "Identity";
}
! public PublicKey[] getPublicKeys(){
! return pubs;
}
private final String repository;
--- 239,248 ----
return "Identity";
}
!
! public PublicKey getPublicKey(){
! return pub;
! }
! public Certificate getCertificate() {
! return new NeuClearCertificate();
}
private final String repository;
***************
*** 241,245 ****
private final String receiver;
! private final PublicKey pubs[];
private final static Identity createRootIdentity() {
--- 251,255 ----
private final String receiver;
! private final PublicKey pub;
private final static Identity createRootIdentity() {
***************
*** 248,252 ****
PublicKey rootpk=CryptoTools.createPK(NSROOTPKMOD, NSROOTPKEXP);
return new Identity("neu://",null,new Timestamp(0),null,NSResolver.NSROOTSTORE,
! null,null,null,new PublicKey[]{rootpk});
} catch (NeudistException e) {
e.printStackTrace();
--- 258,262 ----
PublicKey rootpk=CryptoTools.createPK(NSROOTPKMOD, NSROOTPKEXP);
return new Identity("neu://",null,new Timestamp(0),null,NSResolver.NSROOTSTORE,
! null,null,null,rootpk);
} catch (NeudistException e) {
e.printStackTrace();
***************
*** 259,262 ****
--- 269,273 ----
public static final Identity NEUROOT=createRootIdentity();
+
/**
* Returns the fixed Root PublicKey
***************
*** 268,271 ****
--- 279,326 ----
}
+ private class NeuClearCertificate extends Certificate {
+ public NeuClearCertificate() {
+ super("NeuClear");
+
+ }
+
+ /**
+ * For efficiency purposes we do not store the source material here but instead
+ * return the URI of the certificate which allows us to regenerate it from source.
+ * @return
+ * @throws CertificateEncodingException
+ */
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return getName().getBytes();
+ }
+
+ /**
+ * Since the Instance of Identity implies that it has already been verified in the
+ * creation process. I just check if the signers key is the same as the given.
+ * TODO: This almost certainly has bad security implications and needs to be though through
+ * @param publicKey
+ * @throws CertificateException
+ * @throws NoSuchAlgorithmException
+ * @throws InvalidKeyException
+ * @throws NoSuchProviderException
+ * @throws SignatureException
+ */
+ public void verify(PublicKey publicKey) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
+ if (!getSignatory().getPublicKey().equals(publicKey))
+ throw new SignatureException("Key didnt match Signature");
+ }
+
+ public void verify(PublicKey publicKey, String string) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
+ verify(publicKey);
+ }
+
+ public PublicKey getPublicKey() {
+ return pub;
+ }
+ public String toString() {
+ return getName();
+ }
+
+ }
//TODO I dont like this being public
public final static class Reader implements NamedObjectReader {
***************
*** 282,300 ****
Element allowElement=elem.element(DocumentHelper.createQName("allow",SignedNamedObject.NS_NSDL));
! List keys=allowElement.elements(XMLSecTools.createQName("KeyInfo"));
! PublicKey pubs[]=new PublicKey[keys.size()];
! int i=0;
! for (Iterator iter=keys.iterator();iter.hasNext();i++) {
! KeyInfo ki=new KeyInfo((Element)iter.next());
! pubs[i]=ki.getPublicKey();
! }
!
! return new Identity(name,signatory,timestamp,digest,repository,signer,logger,receiver,pubs);
}
}
- public static void main(String args[]){
- }
}
--- 337,347 ----
Element allowElement=elem.element(DocumentHelper.createQName("allow",SignedNamedObject.NS_NSDL));
! KeyInfo ki=new KeyInfo(allowElement.element(XMLSecTools.createQName("KeyInfo")));
! PublicKey pub=ki.getPublicKey();
! return new Identity(name,signatory,timestamp,digest,repository,signer,logger,receiver,pub);
}
}
}
Index: Named.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/Named.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Named.java 24 Sep 2003 23:56:48 -0000 1.1
--- Named.java 1 Oct 2003 17:05:37 -0000 1.2
***************
*** 23,26 ****
--- 23,29 ----
$Id$
$Log$
+ Revision 1.2 2003/10/01 17:05:37 pelle
+ Moved the NeuClearCertificate class to be an inner class of Identity.
+
Revision 1.1 2003/09/24 23:56:48 pelle
Refactoring nearly done. New model for creating signed objects.
***************
*** 41,46 ****
*/
public interface Named {
! String getName() throws NeudistException;
! String getLocalName() throws NeudistException;
}
--- 44,49 ----
*/
public interface Named {
! String getName() ;
! String getLocalName();
}
Index: SignedNamedObject.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/SignedNamedObject.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SignedNamedObject.java 30 Sep 2003 23:25:14 -0000 1.3
--- SignedNamedObject.java 1 Oct 2003 17:05:37 -0000 1.4
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.4 2003/10/01 17:05:37 pelle
+ * Moved the NeuClearCertificate class to be an inner class of Identity.
+ *
* Revision 1.3 2003/09/30 23:25:14 pelle
* Added new JCE Provider and java Certificate implementation for NeuClear Identity.
***************
*** 171,175 ****
* @return String containing the fully qualified URI of an object
*/
! public String getName() throws NeudistException {
return name;
}
--- 174,178 ----
* @return String containing the fully qualified URI of an object
*/
! public String getName() {
return name;
}
***************
*** 179,183 ****
* @return Parent Name
*/
! public String getLocalName() throws NeudistException {
String fullName = getName();
int i = fullName.lastIndexOf('/');
--- 182,186 ----
* @return Parent Name
*/
! public String getLocalName() {
String fullName = getName();
int i = fullName.lastIndexOf('/');
|