libdigidocpp
Signature.h
Go to the documentation of this file.
1 /*
2  * libdigidocpp
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #pragma once
21 
22 #include "SignatureAttributes.h"
23 #include "crypto/signer/Signer.h"
24 #include "xml/xmldsig-core-schema.hxx"
25 
26 namespace digidoc
27 {
28  class Digest;
29  class X509Cert;
30 
32  {
33  friend class BDoc;
34 
35  public:
36  enum CertStatus { GOOD, REVOKED, UNKNOWN };
37 
38  virtual ~Signature();
39  virtual std::string getMediaType() const = 0;
40  virtual void validateOffline() const throw(SignatureException) = 0;
41  virtual CertStatus validateOnline() const throw(SignatureException) = 0;
42  std::string saveToXml() throw(IOException);
43 
44  std::string getId() const;
45  SignatureProductionPlace getProductionPlace() const;
46  SignerRole getSignerRole() const;
47  std::string getSigningTime() const;
48  X509Cert getSigningCertificate() const throw(SignatureException);
49  std::string getSignatureMethod() const;
50 
51  protected:
52  Signature(unsigned int id);
53  Signature(const std::string& path) throw(SignatureException);
54  virtual void sign(Signer* signer) throw(SignatureException, SignException) = 0;
55 
56  void addReference(const std::string& uri, const std::string& digestUri,
57  const std::vector<unsigned char> &digestValue, const std::string& type = "") throw(SignatureException);
58  void setSigningCertificate(const X509Cert& cert);
59  void setSignatureProductionPlace(const SignatureProductionPlace& signatureProductionPlace);
60  void setSignerRole(const SignerRole& signerRole);
61  void setSigningTime(const xml_schema::DateTime& signingTime);
62  std::vector<unsigned char> getSignatureValue() const;
63  void setSignatureValue(Signer::Signature signatureValue);
64 
65  xades::SignedSignaturePropertiesType& getSignedSignatureProperties() const throw(SignatureException);
66  dsig::X509DataType::X509CertificateType& getSigningX509CertificateType() const throw(SignatureException);
67 
68  std::vector<unsigned char> calcDigestOnNode(Digest* calc, const std::string& ns, const std::string& tagName)
69  const throw(SignatureException);
70 
71  dsig::SignatureType *signature;
72 
73  static const std::string XADES_NAMESPACE;
74 
75  private:
76  void saveToXml(const std::string &path) const throw(IOException);
77 
78  std::string path;
79 
80  };
81 }