Package org.apache.wss4j.common.crypto
Class CryptoBase
java.lang.Object
org.apache.wss4j.common.crypto.CryptoBase
- All Implemented Interfaces:
Crypto
- Direct Known Subclasses:
CertificateStore,Merlin
This Abstract Base Class implements the accessor and keystore-independent methods and
functionality of the Crypto interface.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CertificateFactorystatic final StringOID For the NameConstraints Extension to X.509 http://java.sun.com/j2se/1.4.2/docs/api/ http://www.ietf.org/rfc/rfc3280.txt (s. 4.2.1.11)static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Objectbyte[]getBytesFromCertificates(X509Certificate[] certs) Get a byte array given an array of X509 certificates.Get the CertificateFactory instance on this Crypto instancegetCertificatesFromBytes(byte[] data) Construct an array of X509Certificate's from the byte array.Get the crypto provider associated with this implementationRetrieves the identifier name of the default certificate.protected byte[]Extracts the NameConstraints sequence from the certificate.byte[]Reads the SubjectKeyIdentifier information from the certificate.Get the crypto provider used for truststore operation associated with this implementation.Load a X509Certificate from the input stream.protected booleanmatchesIssuerDnPattern(X509Certificate cert, Collection<Pattern> issuerDNPatterns) protected booleanmatchesName(String name, Collection<Pattern> patterns) protected booleanmatchesSubjectDnPattern(X509Certificate cert, Collection<Pattern> subjectDNPatterns) voidsetCertificateFactory(CertificateFactory certFactory) Sets the CertificateFactory instance on this Crypto instancevoidsetCryptoProvider(String provider) Set the crypto provider associated with this implementationvoidsetDefaultX509Identifier(String identifier) Sets the identifier name of the default certificate.voidsetTrustProvider(String provider) Set the crypto provider used for truststore operations associated with this implementationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.wss4j.common.crypto.Crypto
getPrivateKey, getPrivateKey, getPrivateKey, getX509Certificates, getX509Identifier, verifyTrust, verifyTrust
-
Field Details
-
SKI_OID
- See Also:
-
NAME_CONSTRAINTS_OID
OID For the NameConstraints Extension to X.509 http://java.sun.com/j2se/1.4.2/docs/api/ http://www.ietf.org/rfc/rfc3280.txt (s. 4.2.1.11)- See Also:
-
certificateFactory
-
-
Constructor Details
-
CryptoBase
protected CryptoBase()Constructor
-
-
Method Details
-
getCryptoProvider
Get the crypto provider associated with this implementation- Specified by:
getCryptoProviderin interfaceCrypto- Returns:
- the crypto provider
-
setCryptoProvider
Set the crypto provider associated with this implementation- Specified by:
setCryptoProviderin interfaceCrypto- Parameters:
provider- the crypto provider to set
-
setTrustProvider
Set the crypto provider used for truststore operations associated with this implementation- Specified by:
setTrustProviderin interfaceCrypto- Parameters:
provider- the name of the provider
-
getTrustProvider
Get the crypto provider used for truststore operation associated with this implementation.- Specified by:
getTrustProviderin interfaceCrypto- Returns:
- a crypto provider name
-
getDefaultX509Identifier
Retrieves the identifier name of the default certificate. This should be the certificate that is used for signature and encryption. This identifier corresponds to the certificate that should be used whenever KeyInfo is not present in a signed or an encrypted message. May return null. The identifier is implementation specific, e.g. it could be the KeyStore alias.- Specified by:
getDefaultX509Identifierin interfaceCrypto- Returns:
- name of the default X509 certificate.
- Throws:
WSSecurityException
-
setDefaultX509Identifier
Sets the identifier name of the default certificate. This should be the certificate that is used for signature and encryption. This identifier corresponds to the certificate that should be used whenever KeyInfo is not present in a signed or an encrypted message. The identifier is implementation specific, e.g. it could be the KeyStore alias.- Specified by:
setDefaultX509Identifierin interfaceCrypto- Parameters:
identifier- name of the default X509 certificate.
-
setCertificateFactory
Sets the CertificateFactory instance on this Crypto instance- Specified by:
setCertificateFactoryin interfaceCrypto- Parameters:
certFactory- the CertificateFactory the CertificateFactory instance to set
-
getCertificateFactory
Get the CertificateFactory instance on this Crypto instance- Specified by:
getCertificateFactoryin interfaceCrypto- Returns:
- Returns a
CertificateFactoryto construct X509 certificates - Throws:
WSSecurityException
-
loadCertificate
Load a X509Certificate from the input stream.- Specified by:
loadCertificatein interfaceCrypto- Parameters:
in- TheInputStreamcontaining the X509Certificate- Returns:
- An X509 certificate
- Throws:
WSSecurityException
-
getSKIBytesFromCert
Reads the SubjectKeyIdentifier information from the certificate. If the the certificate does not contain a SKI extension then try to compute the SKI according to RFC3280 using the SHA-1 hash value of the public key. The second method described in RFC3280 is not support. Also only RSA public keys are supported. If we cannot compute the SKI throw a WSSecurityException.- Specified by:
getSKIBytesFromCertin interfaceCrypto- Parameters:
cert- The certificate to read SKI- Returns:
- The byte array containing the binary SKI data
- Throws:
WSSecurityException
-
getBytesFromCertificates
Get a byte array given an array of X509 certificates.- Specified by:
getBytesFromCertificatesin interfaceCrypto- Parameters:
certs- The certificates to convert- Returns:
- The byte array for the certificates
- Throws:
WSSecurityException
-
getCertificatesFromBytes
Construct an array of X509Certificate's from the byte array.- Specified by:
getCertificatesFromBytesin interfaceCrypto- Parameters:
data- Thebytearray containing the X509 data- Returns:
- An array of X509 certificates
- Throws:
WSSecurityException
-
createBCX509Name
-
matchesSubjectDnPattern
protected boolean matchesSubjectDnPattern(X509Certificate cert, Collection<Pattern> subjectDNPatterns) - Returns:
- true if the certificate's SubjectDN matches the constraints defined in the subject DNConstraints; false, otherwise. The certificate subject DN only has to match ONE of the subject cert constraints (not all).
-
matchesIssuerDnPattern
protected boolean matchesIssuerDnPattern(X509Certificate cert, Collection<Pattern> issuerDNPatterns) - Returns:
- true if the certificate's Issuer DN matches the constraints defined in the subject DNConstraints; false, otherwise. The certificate subject DN only has to match ONE of the subject cert constraints (not all).
-
matchesName
- Returns:
- true if the provided name matches the constraints defined in the subject DNConstraints; false, otherwise. The certificate (subject) DN only has to match ONE of the (subject) cert constraints (not all).
-
getNameConstraints
Extracts the NameConstraints sequence from the certificate. Handles the case where the data is encoded directly asDERDecoder.TYPE_SEQUENCEor where the sequence has been encoded as anDERDecoder.TYPE_OCTET_STRING.By contract, the values retrieved from calls to
X509Extension.getExtensionValue(String)should always be DER-encoded OCTET strings; however, because of ambiguity in the RFC and the potential for a future breaking change to this contract, testing whether the bytes returned are tagged as a sequence or an encoded octet string is prudent. Considering the fact that it is a single byte comparison, the performance hit is negligible.- Parameters:
cert- the certificate to extract NameConstraints from- Returns:
- the NameConstraints, or null if not present
- Throws:
WSSecurityException- if a processing error occurs decoding the Octet String
-