Package eu.europa.esig.dss.jades
Class DSSJsonUtils
java.lang.Object
eu.europa.esig.dss.jades.DSSJsonUtils
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAllBase64UrlComponents
(List<Object> components) Checks if the all components are base64Url encodedstatic boolean
checkComponentsUnicity
(List<Object> components) Checks if all components have one type (strings or objects)static String
concatenate
(String... strings) Concatenates the given strings with a '.'static byte[]
concatenateDSSDocuments
(List<DSSDocument> documents, boolean isBase64UrlEncoded) Concatenates document octets to a single byte arraystatic JAdESSignature
extractJAdESCounterSignature
(EtsiUComponent cSigAttribute, JAdESSignature masterSignature) Extracts a counter signature from 'cSig' value with respect to the found formatThis method extracts a key set used within a JOSE Header (protected + unprotected)static byte[]
fromBase64Url
(String base64UrlEncoded) Returns the decoded binary for a base64url encoded stringstatic String
generateKid
(CertificateToken signingCertificate) Generates the 'kid' value as in IETF RFC 5035static Boolean
getAsBoolean
(Map<?, ?> map, String key) Gets a value from themap
under the givenkey
asBoolean
static byte[]
getAsciiBytes
(String str) Returns ASCII-encoded arraystatic List
<?> Gets a value from themap
under the givenkey
asList
static Map
<?, ?> Gets a value from themap
under the givenkey
asMap
static String
getAsString
(Map<?, ?> map, String key) Gets a value from themap
under the givenkey
asString
static Date
Parses a IETF RFC 7519 dateTime NumericDatestatic Date
Parses a IETF RFC 3339 dateTime Stringstatic Digest
Creates aDigest
object from a JSON structurestatic byte[]
getDocumentOctets
(DSSDocument document, boolean isBase64UrlEncoded) This method returns binaries of thedocument
to be used for payload computation, depending on theisBase64UrlEncoded
parameter.This method returns the etsiU container with the unsigned properties or an empty Liststatic org.bouncycastle.asn1.x509.IssuerSerial
getIssuerSerial
(String value) Parses the 'kid' header value as in IETF RFC 5035static String
getMimeTypeString
(String mimeType) Returns a complete mime type string.static JsonObject
getOidObject
(ObjectIdentifier objectIdentifier) Creates an 'oid' LinkedJSONObject according to EN 119-182 ch. 5.4.1 The oId data typestatic JsonObject
getOidObject
(String uri, String desc, String[] docRefs) Creates an 'oid' JsonObject according to EN 119-182 ch. 5.4.1 The oId data typestatic byte[]
getSigningInputBytes
(JWS jws) This method computes the signing input bytes for a JWS signatureReturns set of supported protected critical headersstatic long
getTimeValueInMilliseconds
(long timeWithoutMillis) This method adds millis to the given time in secondsstatic long
getTimeValueInSeconds
(long timeInMillis) This method cleans millis from the given timestatic JsonObject
getTstContainer
(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 theheaderName
from thejws
static String
getUriOrUrnOid
(ObjectIdentifier objectIdentifier) Returns URI if present, otherwise URN encoded OID (see RFC 3061) Returns NULL if non of them is presentstatic boolean
isAllowedSignatureDocumentType
(DSSDocument document) Checks if the signature document has an allowed type (bytes can be extracted)static boolean
isBase64UrlEncoded
(byte b) Checks if the byte is Base64Url encodedstatic boolean
isBase64UrlEncoded
(String str) Checks if the provided string is base64Url encodedstatic boolean
isCriticalHeaderException
(String headerName) Checks if the givenheaderName
is a critical header exception (shall not be incorporated within 'crit' header).static boolean
isJsonDocument
(DSSDocument document) Checks if the provided document is JSON documentstatic boolean
isRequiredCriticalHeader
(String headerName) Checks if the givenheaderName
is required to be incorporated within 'crit' header, when usedstatic boolean
isStringFormat
(Object object) Checks of the object is an instance of a String classstatic boolean
isUrlSafe
(byte b) Checks if the given byte is url safe See RFC 7797 : 5.2.static boolean
isUrlSafePayload
(String payloadString) Checks if the payload is JWS URL safe See RFC 7797 : 5.2.static boolean
isUtf8
(byte[] binaries) Checks if the binaries contain a UTF-8 encoded stringparseEtsiUComponent
(Object etsiUComponent) Parses 'etsiU' component as it is (base64url-encoded or JSON), and returns the resulting Mapstatic SpDocSpecification
parseSPDocSpecification
(Object spDocSpecificationObject) This method buildsSpDocSpecification
from the provided JSON object elementstatic String
toBase64Url
(byte[] binary) Returns a base64Url encoded stringstatic String
toBase64Url
(DSSDocument document) Returns a base64Url encoded stringstatic String
toBase64Url
(Object object) Returns a base64Url encoded string from the provided JSON Object or JSON Arraystatic Boolean
Method safely convertsObject
toBoolean
if possible.static JWSJsonSerializationObject
Converts theJWS
toJWSJsonSerializationObject
static List
<?> Method safely convertsObject
toList
if possible.static List
<?> Method safely convertsObject
toList
if possible.toListOfNumbers
(List<?> list) Converts a list of objects to a list ofNumber
stoListOfStrings
(List<?> list) Converts a list of objects to a list ofString
sstatic Map
<?, ?> Method safely convertsObject
toMap
if possible.static Map
<?, ?> Method safely convertsObject
toMap
if possible.static Number
Method safely convertsObject
toNumber
if possiblestatic Number
Method safely convertsObject
toNumber
if possible.static String
Method safely convertsObject
toString
if possiblestatic String
Method safely convertsObject
toString
if possible.ValidatesJWS
against a JAdES schema (ETSI TS 119 182-1)static void
writeDocumentsDigest
(List<DSSDocument> documents, boolean isBase64UrlEncoded, DSSMessageDigestCalculator digestCalculator) Writes digest on a concatenated binaries of provideddocuments
-
Field Details
-
MIME_TYPE_APPLICATION_PREFIX
-
HTTP_HEADER_DIGEST
The HttpHeader defining the Digest value of a signed message body- See Also:
-
CONTENT_ENCODING_BINARY
-
-
Method Details
-
getAsciiBytes
-
toBase64Url
-
toBase64Url
Returns a base64Url encoded string- Parameters:
document
-DSSDocument
to encode- Returns:
- base64Url encoded
String
-
toBase64Url
-
fromBase64Url
Returns the decoded binary for a base64url encoded string- Parameters:
base64UrlEncoded
- the String to be decoded- Returns:
- the decoded binary
-
isBase64UrlEncoded
-
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
-
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
-
isUtf8
public static boolean isUtf8(byte[] binaries) Checks if the binaries contain a UTF-8 encoded string- Parameters:
binaries
- byte array to check- Returns:
- TRUE if binaries contain a UTF-8 encoded string, FALSE otherwise
-
concatenate
-
getSupportedProtectedCriticalHeaders
-
isCriticalHeaderException
Checks if the givenheaderName
is a critical header exception (shall not be incorporated within 'crit' header). See RFC 7515- Parameters:
headerName
-String
header name to check- Returns:
- TRUE if the header is critical header exception, FALSE otherwise
-
isRequiredCriticalHeader
Checks if the givenheaderName
is required to be incorporated within 'crit' header, when used- Parameters:
headerName
-String
header name to check- Returns:
- TRUE if the header is required within 'crit' header when used, FALSE otherwise
-
getDigest
-
getOidObject
Creates an 'oid' LinkedJSONObject according to EN 119-182 ch. 5.4.1 The oId data type- Parameters:
objectIdentifier
-ObjectIdentifier
to create an 'oid' from- Returns:
- 'oid'
JsonObject
-
getUriOrUrnOid
Returns URI if present, otherwise URN encoded OID (see RFC 3061) Returns NULL if non of them is present- Parameters:
objectIdentifier
-ObjectIdentifier
used to build an object of 'oid' type- Returns:
String
URI
-
getOidObject
Creates an 'oid' JsonObject according to EN 119-182 ch. 5.4.1 The oId data type- Parameters:
uri
-String
URI defining the object. The property is REQUIRED.desc
-String
the object description. The property is OPTIONAL.docRefs
- an array ofString
URIs 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 ofTimestampBinary
s to incorporatecanonicalizationMethodUri
- a canonicalization method (OPTIONAL, e.g. shall not be present for content timestamps)- Returns:
- 'tstContainer'
JsonObject
-
concatenateDSSDocuments
public static byte[] concatenateDSSDocuments(List<DSSDocument> documents, boolean isBase64UrlEncoded) Concatenates document octets to a single byte array- Parameters:
documents
- a list ofDSSDocument
s to concatenateisBase64UrlEncoded
- defines whether the document octets shall be base64url-encoded- Returns:
- a byte array of document octets
-
writeDocumentsDigest
public static void writeDocumentsDigest(List<DSSDocument> documents, boolean isBase64UrlEncoded, DSSMessageDigestCalculator digestCalculator) Writes digest on a concatenated binaries of provideddocuments
- Parameters:
documents
- list ofDSSDocument
s to be concatenatedisBase64UrlEncoded
- defines whether the document octets shall be base64url-encodeddigestCalculator
-DSSMessageDigestCalculator
to compute message-digest with
-
getDocumentOctets
This method returns binaries of thedocument
to be used for payload computation, depending on theisBase64UrlEncoded
parameter. WhenisBase64UrlEncoded
is set to TRUE, returns base64url-encoded binaries of thedocument
. WhenisBase64UrlEncoded
is set to FALSE, returns original octets of the document.- Parameters:
document
-DSSDocument
to get octets fromisBase64UrlEncoded
- defines whether return base64url-encoded octets- Returns:
- octets of the provided
DSSDocument
-
isJsonDocument
Checks if the provided document is JSON document- Parameters:
document
-DSSDocument
to 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
-DSSDocument
to check- Returns:
- TRUE if the document is of an allowed signature type, FALSE otherwise
-
getEtsiU
-
getUnsignedPropertiesWithHeaderName
public static List<EtsiUComponent> getUnsignedPropertiesWithHeaderName(JAdESEtsiUHeader etsiUHeader, String headerName) Returns a list of unsigned 'etsiU' properties matching theheaderName
from thejws
- Parameters:
etsiUHeader
-JAdESEtsiUHeader
to extract values fromheaderName
-String
name of the unsigned header- Returns:
- a list of
EtsiUComponent
s
-
getDate
-
getDate
-
getIssuerSerial
-
generateKid
Generates the 'kid' value as in IETF RFC 5035- Parameters:
signingCertificate
-CertificateToken
representing 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
-JAdESSignature
the master signature- Returns:
JAdESSignature
-
validateAgainstJAdESSchema
-
checkComponentsUnicity
-
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
String
class, FALSE otherwise
-
areAllBase64UrlComponents
-
parseEtsiUComponent
-
parseSPDocSpecification
This method buildsSpDocSpecification
from the provided JSON object element- Parameters:
spDocSpecificationObject
-Object
json object- Returns:
SpDocSpecification
-
toJWSJsonSerializationObject
Converts theJWS
toJWSJsonSerializationObject
- Parameters:
jws
-JWS
to convert- Returns:
JWSJsonSerializationObject
-
getSigningInputBytes
-
extractJOSEHeaderMembersSet
-
getAsBoolean
-
toBoolean
Method safely convertsObject
toBoolean
if possible. The method also provides a user-friendly message explaining the origin of the unexpected variable. -
getAsString
-
toString
-
toString
Method safely convertsObject
toString
if possible. The method also provides a user-friendly message explaining the origin of the unexpected variable. -
toNumber
-
toNumber
Method safely convertsObject
toNumber
if possible. The method also provides a user-friendly message explaining the origin of the unexpected variable. -
getAsMap
-
toMap
-
toMap
Method safely convertsObject
toMap
if possible. The method also provides a user-friendly message explaining the origin of the unexpected variable. -
getAsList
-
toList
-
toList
Method safely convertsObject
toList
if possible. The method also provides a user-friendly message explaining the origin of the unexpected variable. -
toListOfStrings
-
toListOfNumbers
-
getMimeTypeString
-
getTimeValueInSeconds
public static long getTimeValueInSeconds(long timeInMillis) This method cleans millis from the given time- Parameters:
timeInMillis
- time with millis- Returns:
- time without millis
-
getTimeValueInMilliseconds
public static long getTimeValueInMilliseconds(long timeWithoutMillis) This method adds millis to the given time in seconds- Parameters:
timeWithoutMillis
- time without millis- Returns:
- time with millis
-