Package eu.europa.esig.dss.jades
Class DSSJsonUtils
java.lang.Object
eu.europa.esig.dss.jades.DSSJsonUtils
public class DSSJsonUtils extends Object
Utility class for working with JSON objects
-
Field Summary
Fields Modifier and Type Field Description static StringCONTENT_ENCODING_BINARYThe binary content encoding (RFC 2045)static StringHTTP_HEADER_DIGESTThe HttpHeader defining the Digest value of a signed message bodystatic StringMIME_TYPE_APPLICATION_PREFIXThe MimeType application prefix -
Method Summary
Modifier and Type Method Description static booleanareAllBase64UrlComponents(List<Object> components)Checks if the all components are base64Url encodedstatic booleancheckComponentsUnicity(List<Object> components)Checks if all components have one type (strings or objects)static Stringconcatenate(String... strings)Concatenates the given strings with a '.'static byte[]concatenateDSSDocuments(List<DSSDocument> documents)Concatenates document octets to a single byte arraystatic JAdESSignatureextractJAdESCounterSignature(EtsiUComponent cSigAttribute, JAdESSignature masterSignature)Extracts a counter signature from 'cSig' value with respect to the found formatstatic byte[]fromBase64Url(String base64UrlEncoded)Returns the decoded binary for a base64url encoded stringstatic StringgenerateKid(CertificateToken signingCertificate)Generates the 'kid' value as in IETF RFC 5035static byte[]getAsciiBytes(String str)Returns ASCII-encoded arraystatic Set<String>getCriticalHeaderExceptions()Returns set of critical header exceptions (see RFC 7515)static DategetDate(String dateTimeString)Parses a IETF RFC 3339 dateTime Stringstatic DigestgetDigest(Map<?,?> digestValueAndAlgo)Creates aDigestobject from a JSON structurestatic List<Object>getEtsiU(JWS jws)This method returns the etsiU container with the unsigned properties or an empty Liststatic org.bouncycastle.asn1.x509.IssuerSerialgetIssuerSerial(String value)Parses the 'kid' header value as in IETF RFC 5035static JsonObjectgetOidObject(ObjectIdentifier objectIdentifier)Creates an 'oid' LinkedJSONObject according to EN 119-182 ch. 5.4.1 The oId data typestatic JsonObjectgetOidObject(String uri, String desc, String[] docRefs)Creates an 'oid' JsonObject according to EN 119-182 ch. 5.4.1 The oId data typestatic Set<String>getSupportedCriticalHeaders()Returns set of supported critical headersstatic JsonObjectgetTstContainer(List<TimestampBinary> timestampBinaries, String canonicalizationMethodUri)Creates a 'tstContainer' JsonObject according to EN 119-182 ch. 5.4.3.3 The tstContainer typestatic List<EtsiUComponent>getUnsignedPropertiesWithHeaderName(JAdESEtsiUHeader etsiUHeader, String headerName)Returns a list of unsigned 'etsiU' properties matching theheaderNamefrom thejwsstatic booleanisAllowedSignatureDocumentType(DSSDocument document)Checks if the signature document has an allowed type (bytes can be extracted)static booleanisBase64UrlEncoded(byte b)Checks if the byte is Base64Url encodedstatic booleanisBase64UrlEncoded(String str)Checks if the provided string is base64Url encodedstatic booleanisJsonDocument(DSSDocument document)Checks if the provided document is JSON documentstatic booleanisStringFormat(Object object)Checks of the object is an instance of a String classstatic booleanisUrlSafe(byte b)Checks if the given byte is url safe See RFC 7797 : 5.2.static booleanisUrlSafePayload(String payloadString)Checks if the payload is JWS URL safe See RFC 7797 : 5.2.static Map<String,Object>parseEtsiUComponent(Object etsiUComponent)Parses 'etsiU' component as it is (base64url-encoded or JSON), and returns the resulting Mapstatic StringtoBase64Url(byte[] binary)Returns a base64Url encoded stringstatic StringtoBase64Url(DSSDocument document)Returns a base64Url encoded stringstatic StringtoBase64Url(Object object)Returns a base64Url encoded string from the provided JSON Object or JSON Arraystatic JWSJsonSerializationObjecttoJWSJsonSerializationObject(JWS jws)Converts theJWStoJWSJsonSerializationObjectstatic JWSJsonSerializationObjecttoJWSJsonSerializationObject(DSSDocument jadesDocument)Converts theDSSDocumenttoJWSJsonSerializationObject, if not possible returns nullstatic List<String>validateAgainstJAdESSchema(JWS jws)ValidatesJWSagainst a JAdES schema (ETSI TS 119 182-1)
-
Field Details
-
MIME_TYPE_APPLICATION_PREFIX
The MimeType application prefix- See Also:
- Constant Field Values
-
HTTP_HEADER_DIGEST
The HttpHeader defining the Digest value of a signed message body- See Also:
- Constant Field Values
-
CONTENT_ENCODING_BINARY
The binary content encoding (RFC 2045)- See Also:
- Constant Field Values
-
-
Method Details
-
getAsciiBytes
Returns ASCII-encoded array- Parameters:
str-Stringto encode to ASCII- Returns:
- byte array
-
toBase64Url
Returns a base64Url encoded string- Parameters:
binary- a byte array to encode- Returns:
- base64Url encoded
String
-
toBase64Url
Returns a base64Url encoded string- Parameters:
document-DSSDocumentto encode- Returns:
- base64Url encoded
String
-
toBase64Url
Returns a base64Url encoded string from the provided JSON Object or JSON Array- Parameters:
object- JSON Object or JSON Array to encode- Returns:
- base64Url encoded
String
-
fromBase64Url
Returns the decoded binary for a base64url encoded string- Parameters:
base64UrlEncoded- the tring to decoded- Returns:
- the decoded binary
-
isBase64UrlEncoded
Checks if the provided string is base64Url encoded- Parameters:
str-Stringto check- Returns:
- TRUE if the String is base64Url encoded, FALSE otherwise
-
isBase64UrlEncoded
public static boolean isBase64UrlEncoded(byte b)Checks if the byte is Base64Url encoded- Parameters:
b- a byte to check- Returns:
- TRUE if the byte is Base64Url encoded, FALSE otherwise
-
isUrlSafePayload
Checks if the payload is JWS URL safe See RFC 7797 : 5.2. Unencoded JWS Compact Serialization Payload- Parameters:
payloadString-Stringrepresenting a payload- Returns:
- TRUE if the payload is URL safe, FALSE otherwise
-
isUrlSafe
public static boolean isUrlSafe(byte b)Checks if the given byte is url safe See RFC 7797 : 5.2. Unencoded JWS Compact Serialization Payload- Parameters:
b- a byte to check- Returns:
- TRUE if the byte is url-safe, FALSE otherwise
-
concatenate
Concatenates the given strings with a '.' (dot) between. Example: "xxx", "yyy", "zzz" to "xxx.yyy.zzz"- Parameters:
strings- a list ofStrings to concatenate- Returns:
- a concatenation string result
-
getSupportedCriticalHeaders
Returns set of supported critical headers- Returns:
- set of supported critical header strings
-
getCriticalHeaderExceptions
Returns set of critical header exceptions (see RFC 7515)- Returns:
- set of critical header exception strings
-
getDigest
Creates aDigestobject from a JSON structure- Parameters:
digestValueAndAlgo- a Map with digAlg and digVal values- Returns:
- an instance of Digest or null
-
getOidObject
Creates an 'oid' LinkedJSONObject according to EN 119-182 ch. 5.4.1 The oId data type- Parameters:
objectIdentifier-ObjectIdentifierto create an 'oid' from- Returns:
- 'oid'
JsonObject
-
getOidObject
Creates an 'oid' JsonObject according to EN 119-182 ch. 5.4.1 The oId data type- Parameters:
uri-StringURI defining the object. The property is REQUIRED.desc-Stringthe object description. The property is OPTIONAL.docRefs- an array ofStringURIs containing any other additional information about the object. The property is OPTIONAL.- Returns:
- 'oid'
JsonObject
-
getTstContainer
public static JsonObject getTstContainer(List<TimestampBinary> timestampBinaries, String canonicalizationMethodUri)Creates a 'tstContainer' JsonObject according to EN 119-182 ch. 5.4.3.3 The tstContainer type- Parameters:
timestampBinaries- a list ofTimestampBinarys to incorporatecanonicalizationMethodUri- a canonicalization method (OPTIONAL, e.g. shall not be present for content timestamps)- Returns:
- 'tstContainer'
JsonObject
-
concatenateDSSDocuments
Concatenates document octets to a single byte array- Parameters:
documents- a list ofDSSDocuments to concatenate- Returns:
- a byte array of document octets
-
isJsonDocument
Checks if the provided document is JSON document- Parameters:
document-DSSDocumentto check- Returns:
- TRUE of the document is JSON, FALSE otherwise
-
isAllowedSignatureDocumentType
Checks if the signature document has an allowed type (bytes can be extracted)- Parameters:
document-DSSDocumentto check- Returns:
- TRUE if the document is of an allowed signature type, FALSE otherwise
-
getEtsiU
This method returns the etsiU container with the unsigned properties or an empty List- Parameters:
jws- the signature- Returns:
- etsiU content or an empty List
-
getUnsignedPropertiesWithHeaderName
public static List<EtsiUComponent> getUnsignedPropertiesWithHeaderName(JAdESEtsiUHeader etsiUHeader, String headerName)Returns a list of unsigned 'etsiU' properties matching theheaderNamefrom thejws- Parameters:
etsiUHeader-JAdESEtsiUHeaderto extract values fromheaderName-Stringname of the unsigned header- Returns:
- a list of
EtsiUComponents
-
getDate
Parses a IETF RFC 3339 dateTime String -
getIssuerSerial
Parses the 'kid' header value as in IETF RFC 5035- Parameters:
value-StringIssuerSerial to parse- Returns:
IssuerSerial
-
generateKid
Generates the 'kid' value as in IETF RFC 5035- Parameters:
signingCertificate-CertificateTokenrepresenting the singing certificate- Returns:
String'kid' header value
-
extractJAdESCounterSignature
public static JAdESSignature extractJAdESCounterSignature(EtsiUComponent cSigAttribute, JAdESSignature masterSignature)Extracts a counter signature from 'cSig' value with respect to the found format- Parameters:
cSigAttribute- an attribute containing the 'cSig' elementmasterSignature-JAdESSignaturethe master signature- Returns:
JAdESSignature
-
validateAgainstJAdESSchema
ValidatesJWSagainst a JAdES schema (ETSI TS 119 182-1) -
checkComponentsUnicity
Checks if all components have one type (strings or objects)- Parameters:
components- a list of objects to check- Returns:
- TRUE if all components are uniform (strings or objects), FALSE otherwise
-
isStringFormat
Checks of the object is an instance of a String class- Parameters:
object- to check- Returns:
- TRUE if the object is an instance of
Stringclass, FALSE otherwise
-
areAllBase64UrlComponents
Checks if the all components are base64Url encoded- Parameters:
components- a list of components to check- Returns:
- TRUE if all of the components are base64Url encoded, FALSE otherwise
-
parseEtsiUComponent
Parses 'etsiU' component as it is (base64url-encoded or JSON), and returns the resulting Map- Parameters:
etsiUComponent- object to parse (base64url-encoded or JSON)- Returns:
- map representing the object
-
toJWSJsonSerializationObject
Converts theJWStoJWSJsonSerializationObject- Parameters:
jws-JWSto convert- Returns:
JWSJsonSerializationObject
-
toJWSJsonSerializationObject
Converts theDSSDocumenttoJWSJsonSerializationObject, if not possible returns null- Parameters:
jadesDocument- CompactDSSDocumentto convert- Returns:
JWSJsonSerializationObjectif able to convert, null otherwise
-