|
TrueLicense XML 1.33 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectde.schlichtherle.xml.GenericCertificate
public final class GenericCertificate
This non-visual JavaBean is a factory for authenticated runtime objects
whose integrity cannot be compromised without being detected.
The idea and the design of this class is inspired by both
SignedObject and
Certificate.
More specifically, a GenericCertificate contains an XML string
encoded representation of an arbitrary object in the "encoded"
property and a Base64 immutable string representation of the object's
corresponding digital signature in the "signature" property.
The selection of this representation form and the design of this class
as a plain JavaBean allows its instances to be serialized using either
this package's PersistenceService, JDK's
XMLEncoder, or the vanilla ObjectOutputStream.
For an object to be successfully digitally signed, it must support
serialization via JDK's XMLEncoder, for which this package
provides the class PersistenceService.
This easy-to-use class allows you to provide custom
PersistenceDelegate instances for the serialisation of any
classes which do not implement the JavaBean design pattern and are not
supported by XMLEncoder as a default.
Whenever an instance of this GenericCertificate class is created, you can arbitrarily set and get its "encoded" and "signature" properties, allowing you to provide even custom deserialisation methods other than this class already provides via the aforementioned classes. However, once this instance is used to either sign or verify another object it gets locked, allowing subsequent read access to its properties only.
The underlying signing algorithm is designated by the Signature
object passed to the sign and the verify methods.
A typical usage for signing is the following:
<pre>
GenericCertificate cert = new GenericCertificate();
Signature signingEngine = Signature.getInstance(algorithm,
provider);
try {
cert.sign(myObject, signingKey, signingEngine);
} catch (PropertyVetoException signingVetoed) {
// ...
} catch (PersistenceServiceException serialisationFailed) {
// ...
} catch (InvalidKeyException invalidKey) {
// ...
} catch (SignatureException signingEngineBroken) {
// ...
}
</pre>
A typical usage for verification is the following (having
received GenericCertificate cert):
<pre>
Signature verificationEngine =
Signature.getInstance(algorithm, provider);
try {
cert.verify(publicKey, verificationEngine));
} catch (PropertyVetoException verificationVetoed) {
// ...
} catch (InvalidKeyException invalidKey) {
// ...
} catch (SignatureException verificationEngineBroken) {
// ...
} catch (GenericCertificateException integrityCompromised) {
// ...
}
Object myObject = cert.getContent();
</pre>
Several points are worth noting:
sign(java.lang.Object, java.security.PrivateKey, java.security.Signature) and verify(java.security.PublicKey, java.security.Signature)
methods. Secondly, for verification to succeed, the specified
public key must be the public key corresponding to the private key
used to sign the GenericCertificate.SignedObject.verify(java.security.PublicKey, java.security.Signature)
method before retrieving the signed object by calling
SignedObject.getObject().Signature engine is being
used, as its own implementation of the Signature.verify(byte[]) method
is invoked to verify a signature. In other words, a malicious
Signature engine may choose to always return true on
verification in an attempt to bypass a security check.ObjectOutputStream or XMLEncoder.Object.equals(Object) and Object.hashCode() are
not overridden by this class because different JVMs will produce
different literal encodings of the same object and we cannot rely on a proper
equals(...) implementation in the class of a signed object.GenericCertificate include:
GenericCertificates can be used to construct a logical
sequence of signatures, resembling a chain of authorization and
delegation.This class is thread-safe.
Signature,
SignedObject,
Certificate,
Serialized Form| Field Summary | |
|---|---|
private static String |
BASE64_CHARSET
|
private String |
encoded
Holds value of property encoded. |
private boolean |
locked
Holds value of property locked - is not serializable!!! |
private PropertyChangeSupport |
propertyChangeSupport
Utility field used by bound properties. |
private static long |
serialVersionUID
|
private String |
signature
Holds value of property signature. |
private static String |
SIGNATURE_ENCODING
|
private String |
signatureAlgorithm
Holds value of property signatureAlgorithm. |
private String |
signatureEncoding
Holds value of property signatureEncoding. |
private VetoableChangeSupport |
vetoableChangeSupport
Utility field used by constrained properties. |
| Fields inherited from interface de.schlichtherle.xml.XMLConstants |
|---|
DEFAULT_BUFSIZE, XML_CHARSET |
| Constructor Summary | |
|---|---|
GenericCertificate()
Constructs a new generic certificate. |
|
GenericCertificate(GenericCertificate cert)
Copy constructor for the given generic certificate. |
|
| Method Summary | |
|---|---|
private static boolean |
equals(Object a,
Object b)
|
Object |
getContent()
Returns a clone of the certificate's content as it was signed or verified before. |
String |
getEncoded()
The value of the property encoded. |
String |
getSignature()
Getter for the property signature. |
String |
getSignatureAlgorithm()
Getter for the property signatureAlgorithm. |
String |
getSignatureEncoding()
Getter for the property signatureEncoding. |
boolean |
isLocked()
Returns the value of the property locked. |
void |
setEncoded(String encoded)
Setter for the bound property encoded. |
void |
setSignature(String signature)
Setter for the bound property signature. |
void |
setSignatureAlgorithm(String signatureAlgorithm)
Setter for the bound property signatureAlgorithm. |
void |
sign(Object content,
PrivateKey signingKey,
Signature signingEngine)
Encodes and signs the given content in this certificate and
locks it. |
void |
verify(PublicKey verificationKey,
Signature verificationEngine)
Verifies the digital signature of the encoded content in this certificate and locks it. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final String BASE64_CHARSET
private String encoded
private transient volatile boolean locked
private transient PropertyChangeSupport propertyChangeSupport
private static final long serialVersionUID
private String signature
private static final String SIGNATURE_ENCODING
private String signatureAlgorithm
private String signatureEncoding
private transient VetoableChangeSupport vetoableChangeSupport
| Constructor Detail |
|---|
public GenericCertificate()
public GenericCertificate(GenericCertificate cert)
cert - the generic certificate to copy.| Method Detail |
|---|
private static boolean equals(Object a,
Object b)
public Object getContent()
throws GenericCertificateNotLockedException,
PersistenceServiceException
null if this has been
signed before.
GenericCertificateNotLockedException - If no content has been
signed or verified before.
Note that this is ultimately a RuntimeException.
PersistenceServiceException - If the signed object cannot get
reinstantiated from its XML representation for some reason.
This may happen for example if the signed object was created
by a more recent version of its class which contains additional
properties which are not supported by earlier versions.public String getEncoded()
encoded.
The default is null.
encoded.public String getSignature()
signature.
The default is null.
public String getSignatureAlgorithm()
signatureAlgorithm.
The default is null.
public String getSignatureEncoding()
signatureEncoding.
The default is null.
public boolean isLocked()
locked.
If true, an object was successfully signed or verified
before and a clone can be safely retrieved using
getContent().
locked.
public void setEncoded(String encoded)
throws GenericCertificateIsLockedException
encoded.
encoded - The new encoded representation of the signed object
- may be null.
GenericCertificateIsLockedException - If this certificate is
already locked by signing or verifying it before.
Note that this is actually a subclass of
PropertyVetoException.
public void setSignature(String signature)
throws GenericCertificateIsLockedException
signature.
signature - The signature encoded as a string
- may be null.
GenericCertificateIsLockedException - If this certificate is
already locked by signing or verifying it before.
Note that this is actually a subclass of
PropertyVetoException.
public void setSignatureAlgorithm(String signatureAlgorithm)
throws GenericCertificateIsLockedException
signatureAlgorithm.
signatureAlgorithm - The string identifying the signature algorithm
- may be null.
GenericCertificateIsLockedException - If this certificate is
already locked by signing or verifying it before.
Note that this is actually a subclass of
PropertyVetoException.
public void sign(Object content,
PrivateKey signingKey,
Signature signingEngine)
throws NullPointerException,
GenericCertificateIsLockedException,
PropertyVetoException,
PersistenceServiceException,
InvalidKeyException
content in this certificate and
locks it.
Please note the following:
PropertyVetoException if this
certificate is already locked, i.e. if it has been signed or
verified before.sign(Object, PrivateKey, Signature) or
verify(PublicKey, Signature) is redundant
and will throw a PropertyVetoException.
Use isLocked() to detect whether a
generic certificate has been successfuly signed or verified before
or call getContent() and expect an
Exception to be thrown if it hasn't.GenericCertificate if you
need an unlocked copy of the certificate.
content - The object to sign. This must either be a JavaBean or an
instance of any other class which is supported by
{@link PersistenceService}
- maybe null.signingKey - The private key for signing
- may not be null.signingEngine - The signature signing engine
- may not be null.
NullPointerException - If the preconditions for the parameters
do not hold.
GenericCertificateIsLockedException - If this certificate is
already locked by signing or verifying it before.
Note that this is actually a subclass of
PropertyVetoException.
PropertyVetoException - If locking the certifificate (and thus
signing the object) is vetoed by any listener.
PersistenceServiceException - If the object cannot be serialised.
InvalidKeyException - If the verification key is invalid.
public void verify(PublicKey verificationKey,
Signature verificationEngine)
throws NullPointerException,
GenericCertificateIsLockedException,
PropertyVetoException,
InvalidKeyException,
SignatureException,
GenericCertificateIntegrityException
Please note the following:
PropertyVetoException if this
certificate is already locked, i.e. if it has been signed or
verified before.sign(Object, PrivateKey, Signature) or
verify(PublicKey, Signature) is redundant
and will throw a PropertyVetoException.
Use isLocked() to detect whether a
generic certificate has been successfuly signed or verified before
or call getContent() and expect an
Exception to be thrown if it hasn't.GenericCertificate if you
need an unlocked copy of the certificate.
verificationKey - The public key for verification
- may not be null.verificationEngine - The signature verification engine
- may not be null.
NullPointerException - If the preconditions for the parameters
do not hold.
GenericCertificateIsLockedException - If this certificate is
already locked by signing or verifying it before.
Note that this is actually a subclass of
PropertyVetoException.
PropertyVetoException - If locking the certifificate (and thus
verifying the object) is vetoed by any listener.
InvalidKeyException - If the verification key is invalid.
SignatureException - If signature verification failed.
GenericCertificateIntegrityException - If the integrity of this
certificate has been compromised.
|
TrueLicense XML 1.33 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||