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 GeneralNameconvertToGeneralName(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 aCertDataelement, which is defined as follows:static List<GeneralName>decodeGeneralNames(DERDecoder decoder)Decode the next element from the given DER decoder as aGeneralNameselement.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 voidencodeAlgorithmIdentifier(DEREncoder encoder, String algorithm)Encode anAlgorithmIdentifierusing the given DER encoder, whereAlgorithmIdentifieris defined as:static voidencodeAlgorithmIdentifier(DEREncoder encoder, String objectIdentifier, boolean omitParametersField)Encode anAlgorithmIdentifierwithout any parameters using the given DER encoder and object identifier, whereAlgorithmIdentifieris defined as:static voidencodeGeneralNames(DEREncoder encoder, String subjectName, Collection<List<?>> subjectAltNames)static voidencodeGeneralNames(DEREncoder encoder, List<GeneralName> generalNames)Encode aGeneralNameselement using the given DER encoder, whereGeneralNamesis defined as:static voidencodeGeneralNames(DEREncoder encoder, GeneralName generalName)Encode aGeneralNameselement consisting of one general name using the given DER encoder.static byte[]encodeRandomNumber(DEREncoder encoder, SecureRandom secureRandom)Encode aRandomNumberelement using the given DER encoder, whereRandomNumberis defined as:static voidencodeTrustedAuthorities(DEREncoder encoder, List<TrustedAuthority> trustedAuthorities)Encode an ASN.1 sequence of trusted authorities using the given DER encoder.static voidencodeX509CertificateChain(DEREncoder encoder, X509Certificate[] certChain)Encode an ASN.1 set of certificates using the given DER encoder and the givenX509Certificatechain.static byte[]generateRandomString(int length, Random random)static StringgetDistinguishedNameFromGeneralNames(List<GeneralName> generalNames)static booleanmatchGeneralName(GeneralName generalName, GeneralName actualGeneralName)static booleanmatchGeneralNames(List<GeneralName> generalNames, X509Certificate cert)static booleanmatchGeneralNames(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 givenX509Certificatechain.- 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
AlgorithmIdentifierwithout any parameters using the given DER encoder and object identifier, whereAlgorithmIdentifieris defined as:AlgorithmIdentifier ::= SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL }- Parameters:
encoder- the DER encoderobjectIdentifier- the object identifier for the algorithmomitParametersField-trueif the parameters field should be ommitted in the encoding andfalseotherwise- Throws:
ASN1Exception- if the given object identifier is invalid
-
encodeAlgorithmIdentifier
public static void encodeAlgorithmIdentifier(DEREncoder encoder, String algorithm) throws ASN1Exception
Encode an
AlgorithmIdentifierusing the given DER encoder, whereAlgorithmIdentifieris 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
GeneralNameselement using the given DER encoder, whereGeneralNamesis defined as:GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName- Parameters:
encoder- the DER encodergeneralNames- the general names, as aListwhere 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 aGeneralNameselement 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
RandomNumberelement using the given DER encoder, whereRandomNumberis 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 aListwhere 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 aGeneralNameselement.- 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
CertDataelement, 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 aCertDataelement 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
-
-