Skip to content

Commit 8a293c9

Browse files
authored
Merge pull request #9482 from QualitativeDataRepository/QDR/checksumalg
IQSS/9431-support checksum alg in direct uploads
2 parents 0032f0e + 3413a4c commit 8a293c9

14 files changed

Lines changed: 2802 additions & 725 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Direct upload via the Dataverse UI will now support any algorithm configured via the :FileFixityChecksumAlgorithm setting.
2+
External apps using the direct upload API can now query Dataverse to discover which algorithm should be used.
3+
4+
Sites that have been using an algorithm other than MD5 and direct upload and/or dvwebloader may want to use the /api/admin/updateHashValues call (see https://guides.dataverse.org/en/latest/installation/config.html?highlight=updatehashvalues#filefixitychecksumalgorithm) to replace any MD5 hashes on existing files.

doc/sphinx-guides/source/api/native-api.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,22 @@ The response is a JSON object described in the :doc:`/api/external-tools` sectio
30073007
30083008
curl -H "X-Dataverse-key: $API_TOKEN" -H "Accept:application/json" "$SERVER_URL/api/files/$FILE_ID/metadata/$FILEMETADATA_ID/toolparams/$TOOL_ID
30093009
3010+
.. _get-fixity-algorithm:
3011+
3012+
Get Fixity Algorithm
3013+
~~~~~~~~~~~~~~~~~~~~~~
3014+
3015+
This API call can be used to discover the configured fixity/checksum algorithm being used by a Dataverse installation (as configured by - :ref:`:FileFixityChecksumAlgorithm`).
3016+
Currently, the possible values are MD5, SHA-1, SHA-256, and SHA-512.
3017+
This algorithm will be used when the Dataverse software manages a file upload and should be used by external clients uploading files to a Dataverse instance. (Existing files may or may not have checksums with this algorithm.)
3018+
3019+
.. code-block:: bash
3020+
3021+
export SERVER_URL=https://demo.dataverse.org
3022+
3023+
curl "$SERVER_URL/api/files/fixityAlgorithm
3024+
3025+
30103026
Users Token Management
30113027
----------------------
30123028
@@ -4395,6 +4411,26 @@ It will report the specific files that have failed the validation. For example::
43954411
43964412
These are only available to super users.
43974413

4414+
.. _UpdateChecksums:
4415+
4416+
Update Checksums To Use New Algorithm
4417+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4418+
4419+
The fixity algorithm used on existing files can be changed by a superuser using this API call. An optional query parameter (num) can be used to limit the number of updates attempted (i.e. to do processing in batches).
4420+
The API call will only update the algorithm and checksum for a file if the existing checksum can be validated against the file.
4421+
Statistics concerning the updates are returned in the response to the API call with details in the log.
4422+
The primary use for this API call is to update existing files after the algorithm used when uploading new files is changes - see - :ref:`:FileFixityChecksumAlgorithm`.
4423+
Allowed values are MD5, SHA-1, SHA-256, and SHA-512
4424+
4425+
.. code-block:: bash
4426+
4427+
export ALG=SHA-256
4428+
export BATCHSIZE=1
4429+
4430+
curl http://localhost:8080/api/admin/updateHashValues/$ALG
4431+
curl http://localhost:8080/api/admin/updateHashValues/$ALG?num=$BATCHSIZE
4432+
4433+
43984434
.. _dataset-validation-api:
43994435

44004436
Dataset Validation

doc/sphinx-guides/source/installation/config.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,6 +3112,8 @@ This curl command...
31123112

31133113
See also :doc:`oauth2`.
31143114

3115+
.. _:FileFixityChecksumAlgorithm:
3116+
31153117
:FileFixityChecksumAlgorithm
31163118
++++++++++++++++++++++++++++
31173119

@@ -3121,12 +3123,9 @@ The default checksum algorithm used is MD5 and should be sufficient for establis
31213123

31223124
``curl -X PUT -d 'SHA-512' http://localhost:8080/api/admin/settings/:FileFixityChecksumAlgorithm``
31233125

3124-
The fixity algorithm used on existing files can be changed by a superuser using the API. An optional query parameter (num) can be used to limit the number of updates attempted.
3125-
The API call will only update the algorithm and checksum for a file if the existing checksum can be validated against the file.
3126-
Statistics concerning the updates are returned in the response to the API call with details in the log.
3126+
To update the algorithm used for existing files, see :ref:`UpdateChecksums`
31273127

3128-
``curl http://localhost:8080/api/admin/updateHashValues/{alg}``
3129-
``curl http://localhost:8080/api/admin/updateHashValues/{alg}?num=1``
3128+
The fixity checksum algorithm in use can be discovered via API. See :ref:`get-fixity-algorithm` in the API Guide.
31303129

31313130
.. _:PVMinLength:
31323131

src/main/java/edu/harvard/iq/dataverse/api/Files.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,4 +812,10 @@ public Response getExternalToolFMParams(@Context ContainerRequestContext crc, @P
812812
eth = new ExternalToolHandler(externalTool, target.getDataFile(), apiToken, target, locale);
813813
return ok(eth.createPostBody(eth.getParams(JsonUtil.getJsonObject(externalTool.getToolParameters()))));
814814
}
815+
816+
@GET
817+
@Path("fixityAlgorithm")
818+
public Response getFixityAlgorithm() {
819+
return ok(systemConfig.getFileFixityChecksumAlgorithm().toString());
820+
}
815821
}

src/main/webapp/editFilesFragment.xhtml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@
1111
xmlns:o="http://omnifaces.org/ui"
1212
xmlns:iqbs="http://xmlns.jcp.org/jsf/composite/iqbs">
1313

14-
<script src="#{resource['js/fileupload.js']}?version=#{systemConfig.getVersion()}"></script>
15-
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core.js"></script>
16-
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/md5.js"></script>
14+
15+
<ui:param name="useDirectUpload" value="#{systemConfig.directUploadEnabled(dataset)}"/>
16+
<ui:param name="checksumAlgName" value="#{systemConfig.getFileFixityChecksumAlgorithm().toString()}"/>
17+
18+
<h:outputScript name='js/fileupload.js?version=#{systemConfig.getVersion()}' />
19+
<ui:fragment rendered = '#{useDirectUpload}'>
20+
<h:outputScript name='js/crypto-js/4.0.0/core.js' />
21+
<h:outputScript name='js/crypto-js/4.0.0/x64-core.js' rendered='#{(checksumAlgName eq "SHA-512")}'/>
22+
<h:outputScript name='js/crypto-js/4.0.0/md5.js' rendered='#{true or checksumAlgName eq "MD5"}'/>
23+
<h:outputScript name='js/crypto-js/4.0.0/sha1.js' rendered='#{checksumAlgName eq "SHA-1"}'/>
24+
<h:outputScript name='js/crypto-js/4.0.0/sha256.js' rendered='#{checksumAlgName eq "SHA-256"}'/>
25+
<h:outputScript name='js/crypto-js/4.0.0/sha512.js' rendered='#{checksumAlgName eq "SHA-512"}'/>
26+
</ui:fragment>
27+
1728
<!-- Static Tab Layout -->
1829
<div data-widget="content" class="ui-tabs ui-widget ui-widget-content ui-corner-all ui-hidden-container ui-tabs-top" id="datasetForm:tabView">
1930
<ul role="tablist" class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
@@ -109,7 +120,7 @@
109120

110121
$(document).ready(function () {
111122
uploadWidgetDropMsg();
112-
setupDirectUpload(#{systemConfig.directUploadEnabled(EditDatafilesPage.dataset)});
123+
#{useDirectUpload ? 'setupDirectUpload(true);':''}
113124
});
114125
//]]>
115126
</script>
@@ -584,7 +595,7 @@
584595
<p class="text-warning"><span class="glyphicon glyphicon-warning-sign"/> #{EditDatafilesPage.warningMessageForFileTypeDifferentPopUp}</p>
585596
<div class="button-block">
586597
<p:commandButton styleClass="btn btn-default" value="#{bundle['file.delete']}" onclick="PF('fileTypeDifferentPopup').hide()" oncomplete="uploadWidgetDropMsg();
587-
setupDirectUpload(#{systemConfig.directUploadEnabled(EditDatafilesPage.dataset)});"
598+
#{useDirectUpload ? 'setupDirectUpload(true);': ''}"
588599
action="#{EditDatafilesPage.deleteFiles()}"
589600
update=":#{p:resolveClientId('datasetForm:filesTable', view)},:messagePanel,:#{p:resolveClientId('datasetForm:fileUpload', view)},uploadMessage"/>
590601
<button class="btn btn-default" onclick="PF('fileTypeDifferentPopup').hide();" type="button">

src/main/webapp/provenance-popups-fragment.xhtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
xmlns:o="http://omnifaces.org/ui"
88
xmlns:jsf="http://xmlns.jcp.org/jsf"
99
xmlns:iqbs="http://xmlns.jcp.org/jsf/composite/iqbs">
10-
<script src="#{resource['js/fileupload.js']}"></script>
10+
11+
12+
<h:outputScript name='js/fileupload.js?version=#{systemConfig.getVersion()}' />
13+
1114
<p:dialog id="editProvenancePopup" styleClass="smallPopUp" header="#{bundle['file.editProvenanceDialog']}" widgetVar="editProvenancePopup" modal="true" >
1215
<p:fragment id="assignMessages">
1316
<div class="popupMessagePanel">

src/main/webapp/resources/css/fontcustom.css-e

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)