1 /*
2  *
3  *  Copyright (C) 1998-2019, OFFIS e.V.
4  *  All rights reserved.  See COPYRIGHT file for details.
5  *
6  *  This software and supporting documentation were developed by
7  *
8  *    OFFIS e.V.
9  *    R&D Division Health
10  *    Escherweg 2
11  *    D-26121 Oldenburg, Germany
12  *
13  *
14  *  Module: dcmsign
15  *
16  *  Author: Marco Eichelberg
17  *
18  *  Purpose:
19  *    classes: SiTimeStampFS
20  *
21  */
22 
23 #ifndef SITSFS_H
24 #define SITSFS_H
25 
26 #include "dcmtk/config/osconfig.h"
27 
28 #ifdef WITH_OPENSSL
29 
30 #include "dcmtk/dcmsign/sitstamp.h" /* for class SiTimeStamp */
31 #include "dcmtk/ofstd/ofstring.h"   /* for class OFString */
32 
33 /** timestamp client based on filesystem interactions.
34  *  This timestamp client will write a timestamp query in DES encoding to file.
35  *  The interaction with the time stamp authority must then take place separately
36  *  (e.g. manually, using a command line tool like curl). This client then offers
37  *  functionality to import a timestamp reponse (i.e. a timestamp) from file
38  *  and place it into the signed DICOM file for which the timestamp was requested.
39  *  @remark this class is only available if DCMTK is compiled with OpenSSL support enabled.
40  */
41 class DCMTK_DCMSIGN_EXPORT SiTimeStampFS : public SiTimeStamp
42 {
43 public:
44 
45   /// default constructor
46   SiTimeStampFS();
47 
48   /// destructor
49   virtual ~SiTimeStampFS();
50 
51   /** takes a block of raw data, creates a time stamp query for a hash of this
52    *  raw data, and stores it locally in this object.
53    *  @param inputData pointer to raw data
54    *  @param inputDataSize length of raw data block in bytes
55    *  @return status code
56    */
57   virtual OFCondition stamp(
58     const unsigned char *inputData,
59     unsigned long inputDataSize);
60 
61   /** writes the time stamp query created with SiTimeStampFS::stamp() to a file.
62    *  Also writes a "UID file" that contains the Digital Signature UID of the signature
63    *  to which the timestamp request belongs. This file will be read later by the
64    *  import function. The filenames of timestamp query file and UID file must be
65    *  set prior to calling this method.
66    *  @param item item of the DigitalSignatureSQ to which the timestamp is written
67    *  @return dcmdata OFCondition status code
68    */
69   virtual OFCondition write(DcmItem& item);
70 
71   /** set the time stamp query filename to be written
72    *  @param fname filename
73    */
74   virtual void setTSQFilename(const char *fname);
75 
76   /** set the time stamp response filename to be read
77    *  @param fname filename
78    */
79   virtual void setTSRFilename(const char *fname);
80 
81   /** set the uid file filename to be written
82    *  @param fname filename
83    */
84   virtual void setUIDFilename(const char *fname);
85 
86   /** load UID file and retrieve digital signature UID
87    *  @param uid digital signature returned in this parameter if successful
88    * @return EC_Normal if successful, an error code otherwise.
89    */
90   virtual OFCondition getUIDFromFile(OFString& uid);
91 
92   /** load timestamp query from file
93    *  @return status code
94    */
95   virtual OFCondition load_ts_query_from_file();
96 
97   /** load timestamp response from file
98    *  @return status code
99    */
100   virtual OFCondition load_ts_response_from_file();
101 
102   /** check consistency between timestamp query (if available), timestamp
103    *  response and DICOM digital signature. Query and response files must have
104    *  been loaded prior to this method call.
105    *  @param ditem item of the DigitalSignaturesSequence to which this timestamp belongs
106    *  @return status code
107    */
108   virtual OFCondition check_ts_response(DcmItem& ditem);
109 
110   /** insert timestamp token into DICOM dataset
111    *  The response file must have been loaded and checked prior to this method call.
112    *  @param ditem item of the DigitalSignaturesSequence to which this timestamp is written
113    *  @return status code
114    */
115   virtual OFCondition write_ts_token(DcmItem& ditem);
116 
117 private:
118 
119   /// filename of the timestamp query file to be written
120   OFString tsqFilename_;
121 
122   /// filename of the timestamp response file to be read
123   OFString tsrFilename_;
124 
125   /// filename of the UID file to be written
126   OFString uidFilename_;
127 
128 };
129 
130 #endif
131 #endif
132