Package org.apache.xml.security.keys
Class KeyInfo
- java.lang.Object
-
- org.apache.xml.security.utils.ElementProxy
-
- org.apache.xml.security.utils.SignatureElementProxy
-
- org.apache.xml.security.keys.KeyInfo
-
public class KeyInfo extends SignatureElementProxy
This class stand for KeyInfo Element that may contain keys, names, certificates and other public key management information, such as in-band key distribution or key agreement data. KeyInfo Element has two basic functions: One is KeyResolve for getting the public key in signature validation processing. the other one is toElement for getting the element in signature generation processing. ThelengthXXX()
methods provide access to the internal Key objects:- If the
KeyInfo
was constructed from an Element (Signature verification), thelengthXXX()
methods searches for child elements ofds:KeyInfo
for known types. - If the
KeyInfo
was constructed from scratch (during Signature generation), thelengthXXX()
methods return the number ofXXXs
objects already passed to the KeyInfo
addXXX()
methods are used for adding Objects of the appropriate type to theKeyInfo
. This is used during signature generation. TheitemXXX(int i)
methods return the i'th object of the corresponding type. ThecontainsXXX()
methods return whether the KeyInfo contains the corresponding type. - If the
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<EncryptedKey>
encryptedKeys
private java.util.List<KeyResolverSpi>
internalKeyResolvers
Stores the individual (per-KeyInfo)KeyResolverSpi
sprivate static org.slf4j.Logger
LOG
private static java.util.List<StorageResolver>
nullList
private boolean
secureValidation
private java.util.List<StorageResolver>
storageResolvers
Field storageResolversprivate java.util.List<X509Data>
x509Datas
-
Fields inherited from class org.apache.xml.security.utils.ElementProxy
baseURI
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.security.PublicKey pk)
Method addvoid
add(EncryptedKey encryptedKey)
Method addEncryptedKeyvoid
add(DEREncodedKeyValue derEncodedKeyValue)
Method addvoid
add(KeyInfoReference keyInfoReference)
Method addvoid
add(KeyName keyname)
Method addvoid
add(KeyValue keyvalue)
Method addvoid
add(DSAKeyValue dsakeyvalue)
Method addvoid
add(RSAKeyValue rsakeyvalue)
Method addvoid
add(MgmtData mgmtdata)
Method addvoid
add(PGPData pgpdata)
Method addPGPDatavoid
add(RetrievalMethod retrievalmethod)
Method addvoid
add(SPKIData spkidata)
Method addvoid
add(X509Data x509data)
Method addX509Datavoid
addDEREncodedKeyValue(java.security.PublicKey pk)
Method addDEREncodedKeyValuevoid
addKeyInfoReference(java.lang.String URI)
Method addKeyInfoReferencevoid
addKeyName(java.lang.String keynameString)
Method addKeyNamevoid
addKeyValue(java.security.PublicKey pk)
Method addKeyValuevoid
addKeyValue(org.w3c.dom.Element unknownKeyValueElement)
Method addKeyValuevoid
addMgmtData(java.lang.String mgmtdata)
Method addMgmtDatavoid
addRetrievalMethod(java.lang.String uri, Transforms transforms, java.lang.String Type)
Method addRetrievalMethodvoid
addStorageResolver(StorageResolver storageResolver)
Method addStorageResolvervoid
addUnknownElement(org.w3c.dom.Element element)
Method addUnknownElementprivate java.security.cert.X509Certificate
applyCurrentResolver(java.lang.String uri, KeyResolverSpi keyResolver)
boolean
containsDEREncodedKeyValue()
Method containsDEREncodedKeyValueboolean
containsKeyInfoReference()
Method containsKeyInfoReferenceboolean
containsKeyName()
Method containsKeyNameboolean
containsKeyValue()
Method containsKeyValueboolean
containsMgmtData()
Method containsMgmtDataboolean
containsPGPData()
Method containsPGPDataboolean
containsRetrievalMethod()
Method containsRetrievalMethodboolean
containsSPKIData()
Method containsSPKIDataboolean
containsUnknownElement()
Method containsUnknownElementboolean
containsX509Data()
Method containsX509Datajava.lang.String
getBaseLocalName()
Returns the localname of the Elements of the sub-class.java.lang.String
getId()
Returns theId
attributejava.security.PrivateKey
getPrivateKey()
This method returns a private key.(package private) java.security.PrivateKey
getPrivateKeyFromInternalResolvers()
Searches the per-KeyInfo KeyResolvers for private keys(package private) java.security.PrivateKey
getPrivateKeyFromStaticResolvers()
Searches the library wide KeyResolvers for Private keysjava.security.PublicKey
getPublicKey()
This method returns the public key.(package private) java.security.PublicKey
getPublicKeyFromInternalResolvers()
Searches the per-KeyInfo KeyResolvers for public keys(package private) java.security.PublicKey
getPublicKeyFromStaticResolvers()
Searches the library wide KeyResolvers for public keysjavax.crypto.SecretKey
getSecretKey()
This method returns a secret (symmetric) key.(package private) javax.crypto.SecretKey
getSecretKeyFromInternalResolvers()
Searches the per-KeyInfo KeyResolvers for secret keys(package private) javax.crypto.SecretKey
getSecretKeyFromStaticResolvers()
Searches the library wide KeyResolvers for Secret keysjava.security.cert.X509Certificate
getX509Certificate()
Method getX509Certificate(package private) java.security.cert.X509Certificate
getX509CertificateFromInternalResolvers()
Method getX509CertificateFromInternalResolvers(package private) java.security.cert.X509Certificate
getX509CertificateFromStaticResolvers()
This method uses each System-wideKeyResolver
to search the child elements.boolean
isEmpty()
Method isEmptyDEREncodedKeyValue
itemDEREncodedKeyValue(int i)
Method itemDEREncodedKeyValueEncryptedKey
itemEncryptedKey(int i)
Method itemEncryptedKey(package private) KeyResolverSpi
itemInternalKeyResolver(int i)
Method itemInternalKeyResolverKeyInfoReference
itemKeyInfoReference(int i)
Method itemKeyInfoReferenceKeyName
itemKeyName(int i)
Method itemKeyNameKeyValue
itemKeyValue(int i)
Method itemKeyValueMgmtData
itemMgmtData(int i)
Method itemMgmtDataPGPData
itemPGPData(int i)
Method itemPGPDataRetrievalMethod
itemRetrievalMethod(int i)
Method itemRetrievalMethodSPKIData
itemSPKIData(int i)
Method itemSPKIDataorg.w3c.dom.Element
itemUnknownElement(int i)
Method itemUnknownElementX509Data
itemX509Data(int i)
Method itemX509Dataint
lengthDEREncodedKeyValue()
Method lengthDEREncodedKeyValue(package private) int
lengthInternalKeyResolver()
Method lengthInternalKeyResolverint
lengthKeyInfoReference()
Method lengthKeyInfoReferenceint
lengthKeyName()
Method lengthKeyNameint
lengthKeyValue()
Method lengthKeyValueint
lengthMgmtData()
Method lengthMgmtDataint
lengthPGPData()
Method lengthPGPDataint
lengthRetrievalMethod()
Method lengthRetrievalMethodint
lengthSPKIData()
Method lengthSPKIDataint
lengthUnknownElement()
Method lengthUnknownElement NOTE possibly buggy.int
lengthX509Data()
Method lengthX509Datavoid
registerInternalKeyResolver(KeyResolverSpi realKeyResolver)
This method is used to add a customKeyResolverSpi
to a KeyInfo object.void
setId(java.lang.String id)
Sets theId
attributevoid
setSecureValidation(boolean secureValidation)
Set whether secure processing is enabled or not.-
Methods inherited from class org.apache.xml.security.utils.SignatureElementProxy
getBaseNamespace
-
Methods inherited from class org.apache.xml.security.utils.ElementProxy
addBase64Element, addBase64Text, addBigIntegerElement, addReturnToSelf, addText, addTextElement, appendOther, appendSelf, appendSelf, createElementForFamily, createElementForFamilyLocal, createText, getBaseURI, getBigIntegerFromChildElement, getBytesFromTextChild, getDefaultPrefix, getDocument, getElement, getElementPlusReturns, getFirstChild, getLocalAttribute, getTextFromChildElement, getTextFromTextChild, length, registerDefaultPrefixes, setDefaultPrefix, setDocument, setElement, setElement, setLocalAttribute, setLocalIdAttribute, setXPathNamespaceContext
-
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
x509Datas
private java.util.List<X509Data> x509Datas
-
encryptedKeys
private java.util.List<EncryptedKey> encryptedKeys
-
nullList
private static final java.util.List<StorageResolver> nullList
-
storageResolvers
private java.util.List<StorageResolver> storageResolvers
Field storageResolvers
-
internalKeyResolvers
private java.util.List<KeyResolverSpi> internalKeyResolvers
Stores the individual (per-KeyInfo)KeyResolverSpi
s
-
secureValidation
private boolean secureValidation
-
-
Constructor Detail
-
KeyInfo
public KeyInfo(org.w3c.dom.Document doc)
Constructor KeyInfo- Parameters:
doc
-
-
KeyInfo
public KeyInfo(org.w3c.dom.Element element, java.lang.String baseURI) throws XMLSecurityException
Constructor KeyInfo- Parameters:
element
-baseURI
-- Throws:
XMLSecurityException
-
-
Method Detail
-
setSecureValidation
public void setSecureValidation(boolean secureValidation)
Set whether secure processing is enabled or not. The default is false.
-
setId
public void setId(java.lang.String id)
Sets theId
attribute- Parameters:
id
- ID
-
getId
public java.lang.String getId()
Returns theId
attribute- Returns:
- the
Id
attribute
-
addKeyName
public void addKeyName(java.lang.String keynameString)
Method addKeyName- Parameters:
keynameString
-
-
add
public void add(KeyName keyname)
Method add- Parameters:
keyname
-
-
addKeyValue
public void addKeyValue(java.security.PublicKey pk)
Method addKeyValue- Parameters:
pk
-
-
addKeyValue
public void addKeyValue(org.w3c.dom.Element unknownKeyValueElement)
Method addKeyValue- Parameters:
unknownKeyValueElement
-
-
add
public void add(DSAKeyValue dsakeyvalue)
Method add- Parameters:
dsakeyvalue
-
-
add
public void add(RSAKeyValue rsakeyvalue)
Method add- Parameters:
rsakeyvalue
-
-
add
public void add(java.security.PublicKey pk)
Method add- Parameters:
pk
-
-
add
public void add(KeyValue keyvalue)
Method add- Parameters:
keyvalue
-
-
addMgmtData
public void addMgmtData(java.lang.String mgmtdata)
Method addMgmtData- Parameters:
mgmtdata
-
-
add
public void add(MgmtData mgmtdata)
Method add- Parameters:
mgmtdata
-
-
add
public void add(PGPData pgpdata)
Method addPGPData- Parameters:
pgpdata
-
-
addRetrievalMethod
public void addRetrievalMethod(java.lang.String uri, Transforms transforms, java.lang.String Type)
Method addRetrievalMethod- Parameters:
uri
-transforms
-Type
-
-
add
public void add(RetrievalMethod retrievalmethod)
Method add- Parameters:
retrievalmethod
-
-
add
public void add(SPKIData spkidata)
Method add- Parameters:
spkidata
-
-
add
public void add(X509Data x509data)
Method addX509Data- Parameters:
x509data
-
-
add
public void add(EncryptedKey encryptedKey) throws XMLEncryptionException
Method addEncryptedKey- Parameters:
encryptedKey
-- Throws:
XMLEncryptionException
-
addDEREncodedKeyValue
public void addDEREncodedKeyValue(java.security.PublicKey pk) throws XMLSecurityException
Method addDEREncodedKeyValue- Parameters:
pk
-- Throws:
XMLSecurityException
-
add
public void add(DEREncodedKeyValue derEncodedKeyValue)
Method add- Parameters:
derEncodedKeyValue
-
-
addKeyInfoReference
public void addKeyInfoReference(java.lang.String URI) throws XMLSecurityException
Method addKeyInfoReference- Parameters:
URI
-- Throws:
XMLSecurityException
-
add
public void add(KeyInfoReference keyInfoReference)
Method add- Parameters:
keyInfoReference
-
-
addUnknownElement
public void addUnknownElement(org.w3c.dom.Element element)
Method addUnknownElement- Parameters:
element
-
-
lengthKeyName
public int lengthKeyName()
Method lengthKeyName- Returns:
- the number of the KeyName tags
-
lengthKeyValue
public int lengthKeyValue()
Method lengthKeyValue- Returns:
- the number of the KeyValue tags
-
lengthMgmtData
public int lengthMgmtData()
Method lengthMgmtData- Returns:
- the number of the MgmtData tags
-
lengthPGPData
public int lengthPGPData()
Method lengthPGPData- Returns:
- the number of the PGPDat. tags
-
lengthRetrievalMethod
public int lengthRetrievalMethod()
Method lengthRetrievalMethod- Returns:
- the number of the RetrievalMethod tags
-
lengthSPKIData
public int lengthSPKIData()
Method lengthSPKIData- Returns:
- the number of the SPKIData tags
-
lengthX509Data
public int lengthX509Data()
Method lengthX509Data- Returns:
- the number of the X509Data tags
-
lengthDEREncodedKeyValue
public int lengthDEREncodedKeyValue()
Method lengthDEREncodedKeyValue- Returns:
- the number of the DEREncodedKeyValue tags
-
lengthKeyInfoReference
public int lengthKeyInfoReference()
Method lengthKeyInfoReference- Returns:
- the number of the KeyInfoReference tags
-
lengthUnknownElement
public int lengthUnknownElement()
Method lengthUnknownElement NOTE possibly buggy.- Returns:
- the number of the UnknownElement tags
-
itemKeyName
public KeyName itemKeyName(int i) throws XMLSecurityException
Method itemKeyName- Parameters:
i
-- Returns:
- the asked KeyName element, null if the index is too big
- Throws:
XMLSecurityException
-
itemKeyValue
public KeyValue itemKeyValue(int i) throws XMLSecurityException
Method itemKeyValue- Parameters:
i
-- Returns:
- the asked KeyValue element, null if the index is too big
- Throws:
XMLSecurityException
-
itemMgmtData
public MgmtData itemMgmtData(int i) throws XMLSecurityException
Method itemMgmtData- Parameters:
i
-- Returns:
- the asked MgmtData element, null if the index is too big
- Throws:
XMLSecurityException
-
itemPGPData
public PGPData itemPGPData(int i) throws XMLSecurityException
Method itemPGPData- Parameters:
i
-- Returns:
- the asked PGPData element, null if the index is too big
- Throws:
XMLSecurityException
-
itemRetrievalMethod
public RetrievalMethod itemRetrievalMethod(int i) throws XMLSecurityException
Method itemRetrievalMethod- Parameters:
i
-- Returns:
- the asked RetrievalMethod element, null if the index is too big
- Throws:
XMLSecurityException
-
itemSPKIData
public SPKIData itemSPKIData(int i) throws XMLSecurityException
Method itemSPKIData- Parameters:
i
-- Returns:
- the asked SPKIData element, null if the index is too big
- Throws:
XMLSecurityException
-
itemX509Data
public X509Data itemX509Data(int i) throws XMLSecurityException
Method itemX509Data- Parameters:
i
-- Returns:
- the asked X509Data element, null if the index is too big
- Throws:
XMLSecurityException
-
itemEncryptedKey
public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException
Method itemEncryptedKey- Parameters:
i
-- Returns:
- the asked EncryptedKey element, null if the index is too big
- Throws:
XMLSecurityException
-
itemDEREncodedKeyValue
public DEREncodedKeyValue itemDEREncodedKeyValue(int i) throws XMLSecurityException
Method itemDEREncodedKeyValue- Parameters:
i
-- Returns:
- the asked DEREncodedKeyValue element, null if the index is too big
- Throws:
XMLSecurityException
-
itemKeyInfoReference
public KeyInfoReference itemKeyInfoReference(int i) throws XMLSecurityException
Method itemKeyInfoReference- Parameters:
i
-- Returns:
- the asked KeyInfoReference element, null if the index is too big
- Throws:
XMLSecurityException
-
itemUnknownElement
public org.w3c.dom.Element itemUnknownElement(int i)
Method itemUnknownElement- Parameters:
i
- index- Returns:
- the element number of the unknown elements
-
isEmpty
public boolean isEmpty()
Method isEmpty- Returns:
- true if the element has no descendants.
-
containsKeyName
public boolean containsKeyName()
Method containsKeyName- Returns:
- If the KeyInfo contains a KeyName node
-
containsKeyValue
public boolean containsKeyValue()
Method containsKeyValue- Returns:
- If the KeyInfo contains a KeyValue node
-
containsMgmtData
public boolean containsMgmtData()
Method containsMgmtData- Returns:
- If the KeyInfo contains a MgmtData node
-
containsPGPData
public boolean containsPGPData()
Method containsPGPData- Returns:
- If the KeyInfo contains a PGPData node
-
containsRetrievalMethod
public boolean containsRetrievalMethod()
Method containsRetrievalMethod- Returns:
- If the KeyInfo contains a RetrievalMethod node
-
containsSPKIData
public boolean containsSPKIData()
Method containsSPKIData- Returns:
- If the KeyInfo contains a SPKIData node
-
containsUnknownElement
public boolean containsUnknownElement()
Method containsUnknownElement- Returns:
- If the KeyInfo contains a UnknownElement node
-
containsX509Data
public boolean containsX509Data()
Method containsX509Data- Returns:
- If the KeyInfo contains a X509Data node
-
containsDEREncodedKeyValue
public boolean containsDEREncodedKeyValue()
Method containsDEREncodedKeyValue- Returns:
- If the KeyInfo contains a DEREncodedKeyValue node
-
containsKeyInfoReference
public boolean containsKeyInfoReference()
Method containsKeyInfoReference- Returns:
- If the KeyInfo contains a KeyInfoReference node
-
getPublicKey
public java.security.PublicKey getPublicKey() throws KeyResolverException
This method returns the public key.- Returns:
- If the KeyInfo contains a PublicKey node
- Throws:
KeyResolverException
-
getPublicKeyFromStaticResolvers
java.security.PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException
Searches the library wide KeyResolvers for public keys- Returns:
- The public key contained in this Node.
- Throws:
KeyResolverException
-
getPublicKeyFromInternalResolvers
java.security.PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException
Searches the per-KeyInfo KeyResolvers for public keys- Returns:
- The public key contained in this Node.
- Throws:
KeyResolverException
-
getX509Certificate
public java.security.cert.X509Certificate getX509Certificate() throws KeyResolverException
Method getX509Certificate- Returns:
- The certificate contained in this KeyInfo
- Throws:
KeyResolverException
-
getX509CertificateFromStaticResolvers
java.security.cert.X509Certificate getX509CertificateFromStaticResolvers() throws KeyResolverException
This method uses each System-wideKeyResolver
to search the child elements. Each combination ofKeyResolver
and child element is checked against allStorageResolver
s.- Returns:
- The certificate contained in this KeyInfo
- Throws:
KeyResolverException
-
applyCurrentResolver
private java.security.cert.X509Certificate applyCurrentResolver(java.lang.String uri, KeyResolverSpi keyResolver) throws KeyResolverException
- Throws:
KeyResolverException
-
getX509CertificateFromInternalResolvers
java.security.cert.X509Certificate getX509CertificateFromInternalResolvers() throws KeyResolverException
Method getX509CertificateFromInternalResolvers- Returns:
- The certificate contained in this KeyInfo
- Throws:
KeyResolverException
-
getSecretKey
public javax.crypto.SecretKey getSecretKey() throws KeyResolverException
This method returns a secret (symmetric) key. This is for XML Encryption.- Returns:
- the secret key contained in this KeyInfo
- Throws:
KeyResolverException
-
getSecretKeyFromStaticResolvers
javax.crypto.SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException
Searches the library wide KeyResolvers for Secret keys- Returns:
- the secret key contained in this KeyInfo
- Throws:
KeyResolverException
-
getSecretKeyFromInternalResolvers
javax.crypto.SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException
Searches the per-KeyInfo KeyResolvers for secret keys- Returns:
- the secret key contained in this KeyInfo
- Throws:
KeyResolverException
-
getPrivateKey
public java.security.PrivateKey getPrivateKey() throws KeyResolverException
This method returns a private key. This is for Key Transport in XML Encryption.- Returns:
- the private key contained in this KeyInfo
- Throws:
KeyResolverException
-
getPrivateKeyFromStaticResolvers
java.security.PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException
Searches the library wide KeyResolvers for Private keys- Returns:
- the private key contained in this KeyInfo
- Throws:
KeyResolverException
-
getPrivateKeyFromInternalResolvers
java.security.PrivateKey getPrivateKeyFromInternalResolvers() throws KeyResolverException
Searches the per-KeyInfo KeyResolvers for private keys- Returns:
- the private key contained in this KeyInfo
- Throws:
KeyResolverException
-
registerInternalKeyResolver
public void registerInternalKeyResolver(KeyResolverSpi realKeyResolver)
This method is used to add a customKeyResolverSpi
to a KeyInfo object.- Parameters:
realKeyResolver
-
-
lengthInternalKeyResolver
int lengthInternalKeyResolver()
Method lengthInternalKeyResolver- Returns:
- the length of the key
-
itemInternalKeyResolver
KeyResolverSpi itemInternalKeyResolver(int i)
Method itemInternalKeyResolver- Parameters:
i
- the index- Returns:
- the KeyResolverSpi for the index.
-
addStorageResolver
public void addStorageResolver(StorageResolver storageResolver)
Method addStorageResolver- Parameters:
storageResolver
-
-
getBaseLocalName
public java.lang.String getBaseLocalName()
Returns the localname of the Elements of the sub-class.- Specified by:
getBaseLocalName
in classElementProxy
- Returns:
- the localname of the Elements of the sub-class.
-
-