Package org.wildfly.security.sasl.entity
Class EntityUtil
- java.lang.Object
-
- org.wildfly.security.sasl.entity.EntityUtil
-
class EntityUtil extends Object
- Author:
- Farah Juma
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]
randomCharDictionary
-
Constructor Summary
Constructors Constructor Description EntityUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static GeneralName
convertToGeneralName(List<?> generalName)
private static List<GeneralName>
convertToGeneralNames(Collection<List<?>> generalNames)
static X509Certificate[]
decodeCertificateData(DERDecoder decoder)
Decode the next element from the given DER decoder as aCertData
element, which is defined as follows:static List<GeneralName>
decodeGeneralNames(DERDecoder decoder)
Decode the next element from the given DER decoder as aGeneralNames
element.static List<TrustedAuthority>
decodeTrustedAuthorities(DERDecoder decoder)
Decode the next element from the given DER decoder as a trusted authorities element.static X509Certificate[]
decodeX509CertificateChain(DERDecoder decoder)
Decode the next element from the given DER decoder as an X.509 certificate chain.static void
encodeAlgorithmIdentifier(DEREncoder encoder, String algorithm)
Encode anAlgorithmIdentifier
using the given DER encoder, whereAlgorithmIdentifier
is defined as:static void
encodeAlgorithmIdentifier(DEREncoder encoder, String objectIdentifier, boolean omitParametersField)
Encode anAlgorithmIdentifier
without any parameters using the given DER encoder and object identifier, whereAlgorithmIdentifier
is defined as:static void
encodeGeneralNames(DEREncoder encoder, String subjectName, Collection<List<?>> subjectAltNames)
static void
encodeGeneralNames(DEREncoder encoder, List<GeneralName> generalNames)
Encode aGeneralNames
element using the given DER encoder, whereGeneralNames
is defined as:static void
encodeGeneralNames(DEREncoder encoder, GeneralName generalName)
Encode aGeneralNames
element consisting of one general name using the given DER encoder.static byte[]
encodeRandomNumber(DEREncoder encoder, SecureRandom secureRandom)
Encode aRandomNumber
element using the given DER encoder, whereRandomNumber
is defined as:static void
encodeTrustedAuthorities(DEREncoder encoder, List<TrustedAuthority> trustedAuthorities)
Encode an ASN.1 sequence of trusted authorities using the given DER encoder.static void
encodeX509CertificateChain(DEREncoder encoder, X509Certificate[] certChain)
Encode an ASN.1 set of certificates using the given DER encoder and the givenX509Certificate
chain.static byte[]
generateRandomString(int length, Random random)
static String
getDistinguishedNameFromGeneralNames(List<GeneralName> generalNames)
static boolean
matchGeneralName(GeneralName generalName, GeneralName actualGeneralName)
static boolean
matchGeneralNames(List<GeneralName> generalNames, X509Certificate cert)
static boolean
matchGeneralNames(List<GeneralName> generalNames, List<GeneralName> actualGeneralNames)
-
-
-
Method Detail
-
encodeX509CertificateChain
public static void encodeX509CertificateChain(DEREncoder encoder, X509Certificate[] certChain) throws ASN1Exception
Encode an ASN.1 set of certificates using the given DER encoder and the givenX509Certificate
chain.- Parameters:
encoder
- the DER encodercertChain
- the X.509 certificate chain to encode- Throws:
ASN1Exception
- if an error occurs while encoding the given certificate chain
-
encodeAlgorithmIdentifier
public static void encodeAlgorithmIdentifier(DEREncoder encoder, String objectIdentifier, boolean omitParametersField) throws ASN1Exception
Encode an
AlgorithmIdentifier
without any parameters using the given DER encoder and object identifier, whereAlgorithmIdentifier
is defined as:AlgorithmIdentifier ::= SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL }
- Parameters:
encoder
- the DER encoderobjectIdentifier
- the object identifier for the algorithmomitParametersField
-true
if the parameters field should be ommitted in the encoding andfalse
otherwise- Throws:
ASN1Exception
- if the given object identifier is invalid
-
encodeAlgorithmIdentifier
public static void encodeAlgorithmIdentifier(DEREncoder encoder, String algorithm) throws ASN1Exception
Encode an
AlgorithmIdentifier
using the given DER encoder, whereAlgorithmIdentifier
is defined as:AlgorithmIdentifier ::= SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL }
- Parameters:
encoder
- the DER encoderalgorithm
- the algorithm name- Throws:
ASN1Exception
- if the given algorithm name is unrecognised
-
encodeGeneralNames
public static void encodeGeneralNames(DEREncoder encoder, List<GeneralName> generalNames) throws ASN1Exception
Encode a
GeneralNames
element using the given DER encoder, whereGeneralNames
is defined as:GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
- Parameters:
encoder
- the DER encodergeneralNames
- the general names, as aList
where each entry is aGeneralName
- Throws:
ASN1Exception
- if any of the general names are invalid
-
encodeGeneralNames
public static void encodeGeneralNames(DEREncoder encoder, GeneralName generalName) throws ASN1Exception
Encode aGeneralNames
element consisting of one general name using the given DER encoder.- Parameters:
encoder
- the DER encodergeneralName
- the general name- Throws:
ASN1Exception
- if the general name is invalid
-
encodeGeneralNames
public static void encodeGeneralNames(DEREncoder encoder, String subjectName, Collection<List<?>> subjectAltNames) throws ASN1Exception
- Throws:
ASN1Exception
-
encodeRandomNumber
public static byte[] encodeRandomNumber(DEREncoder encoder, SecureRandom secureRandom)
Encode a
RandomNumber
element using the given DER encoder, whereRandomNumber
is defined as:RandomNumber ::= OCTET STRING (SIZE(8..MAX))
- Parameters:
encoder
- the DER encodersecureRandom
- the secure random to use (may be null)
-
generateRandomString
public static byte[] generateRandomString(int length, Random random)
-
encodeTrustedAuthorities
public static void encodeTrustedAuthorities(DEREncoder encoder, List<TrustedAuthority> trustedAuthorities) throws ASN1Exception
Encode an ASN.1 sequence of trusted authorities using the given DER encoder.- Parameters:
encoder
- the DER encodertrustedAuthorities
- the trusted authorities as aList
where each entry must be aTrustedAuthority.NameTrustedAuthority
, aTrustedAuthority.CertificateTrustedAuthority
, or aTrustedAuthority.HashTrustedAuthority
- Throws:
ASN1Exception
- if any of the trusted authorities are invalid
-
decodeGeneralNames
public static List<GeneralName> decodeGeneralNames(DERDecoder decoder) throws ASN1Exception
Decode the next element from the given DER decoder as aGeneralNames
element.- Parameters:
decoder
- the DER decoder- Returns:
- the general names
- Throws:
ASN1Exception
- if the next element from the given decoder is not a general names element
-
decodeX509CertificateChain
public static X509Certificate[] decodeX509CertificateChain(DERDecoder decoder) throws ASN1Exception
Decode the next element from the given DER decoder as an X.509 certificate chain.- Parameters:
decoder
- the DER decoder- Returns:
- the X.509 certificate chain
- Throws:
ASN1Exception
- if the next element from the given decoder is not an X.509 certificate chain or if an error occurs while decoding the X.509 certificate chain
-
decodeCertificateData
public static X509Certificate[] decodeCertificateData(DERDecoder decoder) throws ASN1Exception
Decode the next element from the given DER decoder as a
CertData
element, which is defined as follows:CertData ::= CHOICE { certificateSet SET SIZE (1..MAX) OF Certificate, certURL IA5String (Note: No support for certificate URL) }
- Parameters:
decoder
- the DER decoder- Returns:
- the X.509 certificate or certificate chain
- Throws:
ASN1Exception
- if the next element from the given decoder is not aCertData
element or if an error occurs while decoding the certificate data
-
decodeTrustedAuthorities
public static List<TrustedAuthority> decodeTrustedAuthorities(DERDecoder decoder) throws ASN1Exception
Decode the next element from the given DER decoder as a trusted authorities element.- Parameters:
decoder
- the DER decoder- Returns:
- the trusted authorities
- Throws:
ASN1Exception
- if the next element from the given decoder is not a trusted authorities element or if an error occurs while decoding the trusted authorities element
-
matchGeneralNames
public static boolean matchGeneralNames(List<GeneralName> generalNames, List<GeneralName> actualGeneralNames)
-
matchGeneralName
public static boolean matchGeneralName(GeneralName generalName, GeneralName actualGeneralName)
-
matchGeneralNames
public static boolean matchGeneralNames(List<GeneralName> generalNames, X509Certificate cert)
-
getDistinguishedNameFromGeneralNames
public static String getDistinguishedNameFromGeneralNames(List<GeneralName> generalNames)
-
convertToGeneralName
private static GeneralName convertToGeneralName(List<?> generalName) throws ASN1Exception
- Throws:
ASN1Exception
-
convertToGeneralNames
private static List<GeneralName> convertToGeneralNames(Collection<List<?>> generalNames) throws ASN1Exception
- Throws:
ASN1Exception
-
-